@@ -40,33 +40,38 @@ shorthand_range = {
4040 | range_full
4141}
4242
43+ // Argument parsing - requires escaping for special characters
44+ argument = { (escaped_char | normal_char)* }
45+ normal_char = { !("|" | "}" | "{" | ":" | "\\") ~ ANY }
46+ escaped_char = { "\\" ~ ANY }
47+
4348// Main operations - using specific arg types where needed
44- regex_extract = { "regex_extract" ~ ":" ~ regex_arg ~ (":" ~ number)? }
45- filter_not = { "filter_not" ~ ":" ~ regex_arg }
46- filter = { "filter" ~ ":" ~ regex_arg }
49+ regex_extract = { "regex_extract" ~ ":" ~ argument ~ (":" ~ number)? }
50+ filter_not = { "filter_not" ~ ":" ~ argument }
51+ filter = { "filter" ~ ":" ~ argument }
4752strip_ansi = @{ "strip_ansi" }
48- map = { "map" ~ ":" ~ map_operation }
49- split = { "split" ~ ":" ~ split_arg ~ ":" ~ range_spec? }
50- substring = { "substring" ~ ":" ~ range_spec }
51- replace = { "replace" ~ ":" ~ sed_string }
52- append = { "append" ~ ":" ~ simple_arg }
53- prepend = { "prepend" ~ ":" ~ simple_arg }
54- surround = { "surround" ~ ":" ~ simple_arg }
55- quote = { "quote" ~ ":" ~ simple_arg }
53+ map = { "map" ~ ":" ~ map_operation }
54+ split = { "split" ~ ":" ~ argument ~ ":" ~ range_spec? }
55+ substring = { "substring" ~ ":" ~ range_spec }
56+ replace = { "replace" ~ ":" ~ sed_string }
57+ append = { "append" ~ ":" ~ argument }
58+ prepend = { "prepend" ~ ":" ~ argument }
59+ surround = { "surround" ~ ":" ~ argument }
60+ quote = { "quote" ~ ":" ~ argument }
5661upper = @{ "upper" }
5762lower = @{ "lower" }
58- trim = { "trim" ~ (":" ~ simple_arg )? ~ (":" ~ direction)? }
59- join = { "join" ~ ":" ~ simple_arg }
60- slice = { "slice" ~ ":" ~ range_spec }
61- sort = { "sort" ~ (":" ~ sort_direction)? }
63+ trim = { "trim" ~ (":" ~ argument )? ~ (":" ~ direction)? }
64+ join = { "join" ~ ":" ~ argument }
65+ slice = { "slice" ~ ":" ~ range_spec }
66+ sort = { "sort" ~ (":" ~ sort_direction)? }
6267reverse = @{ "reverse" }
6368unique = @{ "unique" }
64- pad = { "pad" ~ ":" ~ number ~ (":" ~ pad_char)? ~ (":" ~ direction)? }
69+ pad = { "pad" ~ ":" ~ number ~ (":" ~ pad_char)? ~ (":" ~ direction)? }
6570
6671// Direction specifiers
6772direction = @{ "left" | "right" | "both" }
6873sort_direction = @{ "asc" | "desc" }
69- pad_char = @{ simple_arg_content+ }
74+ pad_char = @{ argument }
7075
7176// Map operation
7277map_operation = { "{" ~ map_operation_list ~ "}" }
@@ -95,68 +100,16 @@ map_inner_operation = {
95100}
96101
97102// Map-specific operations that need special handling
98- map_split = { "split" ~ ":" ~ split_arg ~ (":" ~ range_spec)? }
99- map_join = { "join" ~ ":" ~ simple_arg }
100- map_slice = { "slice" ~ ":" ~ range_spec }
101- map_sort = { "sort" ~ (":" ~ sort_direction)? }
103+ map_split = { "split" ~ ":" ~ argument ~ (":" ~ range_spec)? }
104+ map_join = { "join" ~ ":" ~ argument }
105+ map_slice = { "slice" ~ ":" ~ range_spec }
106+ map_sort = { "sort" ~ (":" ~ sort_direction)? }
102107map_unique = @{ "unique" }
103- map_filter = { "filter" ~ ":" ~ map_regex_arg }
104- map_filter_not = { "filter_not" ~ ":" ~ map_regex_arg }
108+ map_filter = { "filter" ~ ":" ~ argument }
109+ map_filter_not = { "filter_not" ~ ":" ~ argument }
105110
106111// Map-specific regex extract
107- map_regex_extract = { "regex_extract" ~ ":" ~ map_regex_arg ~ (":" ~ number)? }
108-
109- // Simplified argument handling - three types to handle specific cases
110- simple_arg = @{ simple_arg_content* }
111- simple_arg_content = { escaped_char | simple_normal_char }
112- simple_normal_char = { !(":" | "|" | "}" | "{" | "\\") ~ ANY }
113-
114- // Split args - need to handle pipes that aren't operations
115- split_arg = @{ (split_escaped_char | split_content)* }
116- split_content = { !(":" ~ (number | range_part)) ~ !("|" ~ operation_keyword) ~ !("}" ~ EOI) ~ ANY }
117- split_escaped_char = { "\\" ~ ANY }
118-
119- // Regex args - need to handle pipes and braces in regex patterns
120- regex_arg = @{ (regex_escaped_char | regex_content)* }
121- regex_content = { !(":" ~ (number | range_part)) ~ !("|" ~ operation_keyword) ~ !("}" ~ EOI) ~ ANY }
122- regex_escaped_char = { "\\" ~ ANY }
123-
124- // Map regex args - handle braces in regex patterns
125- map_regex_arg = @{ (map_regex_escaped_char | map_regex_brace | map_regex_content)* }
126- map_regex_brace = { "{" ~ (!"}" ~ ANY)* ~ "}" }
127- map_regex_content = { !(":" ~ number) ~ !("|" ~ operation_keyword) ~ !("{" | ("}" ~ ("|" | "}" | EOI))) ~ ANY }
128- map_regex_escaped_char = { "\\" ~ ANY }
129-
130- // Common escaped character handling
131- escaped_char = { "\\" ~ ANY }
132-
133- // Operation keywords for lookahead (simplified list)
134- operation_keyword = _{
135- "split"
136- | "upper"
137- | "lower"
138- | "trim"
139- | "append"
140- | "prepend"
141- | "surround"
142- | "quote"
143- | "join"
144- | "substring"
145- | "replace"
146- | "map"
147- | "filter"
148- | "filter_not"
149- | "slice"
150- | "sort"
151- | "reverse"
152- | "unique"
153- | "regex_extract"
154- | "strip_ansi"
155- | "pad"
156- }
157-
158- // Range parts for lookahead
159- range_part = _{ ".." | "..=" }
112+ map_regex_extract = { "regex_extract" ~ ":" ~ argument ~ (":" ~ number)? }
160113
161114// Sed strings
162115sed_string = { "s/" ~ sed_pattern ~ "/" ~ sed_replacement ~ "/" ~ sed_flags? }
0 commit comments