summaryrefslogtreecommitdiff
path: root/src/parser.rs
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-09-28 11:47:08 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-09-28 11:52:48 +0800
commit03d456f0119e80f611952eec5c1b2da90b55e913 (patch)
tree74126a9e50cbcad03f72ae293e9784c3e54659f2 /src/parser.rs
parent8306b2c99a6af2b22732c612cbd9b202ddc1251f (diff)
parser: make use of EXPRESSION_DELIMITERS
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs54
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<'_>> {