global: snapshot

This commit is contained in:
nym21
2026-01-13 22:32:29 +01:00
parent 0c442b4a71
commit e77993fb76
61 changed files with 5047 additions and 5404 deletions
+21 -27
View File
@@ -1,6 +1,6 @@
//! JavaScript language syntax implementation.
use crate::{FieldNamePosition, GenericSyntax, LanguageSyntax, to_camel_case, to_pascal_case};
use crate::{GenericSyntax, LanguageSyntax, to_camel_case, to_pascal_case};
/// JavaScript-specific code generation syntax.
pub struct JavaScriptSyntax;
@@ -16,32 +16,26 @@ impl LanguageSyntax for JavaScriptSyntax {
format!("`${{{}}}{}`", var_name, suffix)
}
fn position_expr(&self, pos: &FieldNamePosition, base_var: &str) -> String {
// Convert base_var to camelCase for JavaScript
let var_name = to_camel_case(base_var);
match pos {
FieldNamePosition::Append(s) => {
// Use helper _m(acc, suffix) to build metric name
// e.g., _m(acc, "cap") produces: acc ? `${acc}_cap` : 'cap'
if let Some(suffix) = s.strip_prefix('_') {
format!("_m({}, '{}')", var_name, suffix)
} else {
format!("`${{{}}}{}`", var_name, s)
}
}
FieldNamePosition::Prepend(s) => {
// Handle empty acc case for prepend
if let Some(prefix) = s.strip_suffix('_') {
format!(
"({} ? `{}${{{}}}` : '{}')",
var_name, s, var_name, prefix
)
} else {
format!("`{}${{{}}}`", s, var_name)
}
}
FieldNamePosition::Identity => var_name,
FieldNamePosition::SetBase(s) => format!("'{}'", s),
fn suffix_expr(&self, acc_var: &str, relative: &str) -> String {
let var_name = to_camel_case(acc_var);
if relative.is_empty() {
// Identity: just return acc
var_name
} else {
// _m(acc, relative) -> acc ? `${acc}_relative` : 'relative'
format!("_m({}, '{}')", var_name, relative)
}
}
fn prefix_expr(&self, prefix: &str, acc_var: &str) -> String {
let var_name = to_camel_case(acc_var);
if prefix.is_empty() {
// Identity: just return acc
var_name
} else {
// _p(prefix, acc) -> acc ? `${prefix}${acc}` : 'prefix_without_underscore'
let prefix_base = prefix.trim_end_matches('_');
format!("_p('{}', {})", prefix_base, var_name)
}
}
+19 -25
View File
@@ -1,6 +1,6 @@
//! Python language syntax implementation.
use crate::{FieldNamePosition, GenericSyntax, LanguageSyntax, escape_python_keyword, to_snake_case};
use crate::{GenericSyntax, LanguageSyntax, escape_python_keyword, to_snake_case};
/// Python-specific code generation syntax.
pub struct PythonSyntax;
@@ -14,30 +14,24 @@ impl LanguageSyntax for PythonSyntax {
format!("f'{{{}}}{}'", base_var, suffix)
}
fn position_expr(&self, pos: &FieldNamePosition, base_var: &str) -> String {
match pos {
FieldNamePosition::Append(s) => {
// Use helper _m(acc, suffix) to build metric name
if let Some(suffix) = s.strip_prefix('_') {
format!("_m({}, '{}')", base_var, suffix)
} else {
format!("f'{{{}}}{}'", base_var, s)
}
}
FieldNamePosition::Prepend(s) => {
// Handle empty acc case for prepend
// Want to produce: (f'prefix_{acc}' if acc else 'prefix')
if let Some(prefix) = s.strip_suffix('_') {
format!(
"(f'{}{{{}}}' if {} else '{}')",
s, base_var, base_var, prefix
)
} else {
format!("f'{}{{{}}}'" , s, base_var)
}
}
FieldNamePosition::Identity => base_var.to_string(),
FieldNamePosition::SetBase(s) => format!("'{}'", s),
fn suffix_expr(&self, acc_var: &str, relative: &str) -> String {
if relative.is_empty() {
// Identity: just return acc
acc_var.to_string()
} else {
// _m(acc, relative) -> f'{acc}_{relative}' if acc else 'relative'
format!("_m({}, '{}')", acc_var, relative)
}
}
fn prefix_expr(&self, prefix: &str, acc_var: &str) -> String {
if prefix.is_empty() {
// Identity: just return acc
acc_var.to_string()
} else {
// _p(prefix, acc) -> f'{prefix}{acc}' if acc else 'prefix_base'
let prefix_base = prefix.trim_end_matches('_');
format!("_p('{}', {})", prefix_base, acc_var)
}
}
+19 -25
View File
@@ -1,6 +1,6 @@
//! Rust language syntax implementation.
use crate::{FieldNamePosition, GenericSyntax, LanguageSyntax, to_snake_case};
use crate::{GenericSyntax, LanguageSyntax, to_snake_case};
/// Rust-specific code generation syntax.
pub struct RustSyntax;
@@ -14,30 +14,24 @@ impl LanguageSyntax for RustSyntax {
format!("format!(\"{{{}}}{}\")", base_var, suffix)
}
fn position_expr(&self, pos: &FieldNamePosition, _base_var: &str) -> String {
match pos {
FieldNamePosition::Append(s) => {
// Use helper _m(&acc, suffix) to build metric name
if let Some(suffix) = s.strip_prefix('_') {
format!("_m(&acc, \"{}\")", suffix)
} else {
format!("format!(\"{{acc}}{}\")", s)
}
}
FieldNamePosition::Prepend(s) => {
// Handle empty acc case for prepend
if let Some(prefix) = s.strip_suffix('_') {
format!(
"if acc.is_empty() {{ \"{prefix}\".to_string() }} else {{ format!(\"{s}{{acc}}\") }}",
prefix = prefix,
s = s
)
} else {
format!("format!(\"{}{{acc}}\")", s)
}
}
FieldNamePosition::Identity => "acc.clone()".to_string(),
FieldNamePosition::SetBase(base) => format!("\"{}\".to_string()", base),
fn suffix_expr(&self, acc_var: &str, relative: &str) -> String {
if relative.is_empty() {
// Identity: just return acc
format!("{}.clone()", acc_var)
} else {
// _m(&acc, relative) -> if acc.is_empty() { relative } else { format!("{acc}_{relative}") }
format!("_m(&{}, \"{}\")", acc_var, relative)
}
}
fn prefix_expr(&self, prefix: &str, acc_var: &str) -> String {
if prefix.is_empty() {
// Identity: just return acc
format!("{}.clone()", acc_var)
} else {
// _p(prefix, &acc) -> if acc.is_empty() { prefix_base } else { format!("{prefix}{acc}") }
let prefix_base = prefix.trim_end_matches('_');
format!("_p(\"{}\", &{})", prefix_base, acc_var)
}
}