diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-09-28 11:47:08 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-09-28 11:52:48 +0800 |
| commit | 03d456f0119e80f611952eec5c1b2da90b55e913 (patch) | |
| tree | 74126a9e50cbcad03f72ae293e9784c3e54659f2 /src | |
| parent | 8306b2c99a6af2b22732c612cbd9b202ddc1251f (diff) | |
parser: make use of EXPRESSION_DELIMITERS
Diffstat (limited to 'src')
| -rw-r--r-- | src/parser.rs | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/src/parser.rs b/src/parser.rs index 8e2b63c..7e37376 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -33,38 +33,36 @@ pub struct Expr<'a> { } pub fn delimit(s: &str) -> SplitWithMetadata<'_> { - s.split_inclusive([ - ';', '{', '}', - ]) - .fold(Vec::new(), |mut acc, part| { - if let Some((i, ch)) = part - .char_indices() - .next_back() - { - acc.push(( - if ch == ';' || ch == '{' || ch == '}' { - part[..i].trim() - } else { - part.trim() - }, - None, - )); - match ch { - '{' => { - if let Some((_, meta)) = acc.last_mut() { - *meta = Some(Metadata::StartScope); + s.split_inclusive(EXPRESSION_DELIMITERS) + .fold(Vec::new(), |mut acc, part| { + if let Some((i, ch)) = part + .char_indices() + .next_back() + { + acc.push(( + if ch == ';' || ch == '{' || ch == '}' { + part[..i].trim() + } else { + part.trim() + }, + None, + )); + match ch { + '{' => { + if let Some((_, meta)) = acc.last_mut() { + *meta = Some(Metadata::StartScope); + } } - } - '}' => { - if let Some((_, meta)) = acc.last_mut() { - *meta = Some(Metadata::EndScope); + '}' => { + if let Some((_, meta)) = acc.last_mut() { + *meta = Some(Metadata::EndScope); + } } + _ => {} } - _ => {} } - } - acc - }) + acc + }) } pub fn process(strs: SplitWithMetadata<'_>) -> Vec<Expr<'_>> { |
