Skip to content

Commit deb3709

Browse files
committed
use chainchomp
1 parent e0c09fe commit deb3709

File tree

3 files changed

+18
-32
lines changed

3 files changed

+18
-32
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repository = "https://github.com/zahash/csc"
1111
regex = { version = "1" }
1212
lazy_static = { version = "1" }
1313
rustyline = { version = "12" }
14+
chainchomp = { version = "0.1" }
1415

1516
[dev-dependencies]
1617
pretty_assertions = { version = "1" }
@@ -29,6 +30,11 @@ ci = ["github"]
2930
# The installers to generate for each app
3031
installers = []
3132
# Target platforms to build apps for (Rust target-triple syntax)
32-
targets = ["x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-pc-windows-msvc"]
33+
targets = [
34+
"x86_64-unknown-linux-gnu",
35+
"aarch64-apple-darwin",
36+
"x86_64-apple-darwin",
37+
"x86_64-pc-windows-msvc",
38+
]
3339
# Publish jobs to run in CI
3440
pr-run-mode = "plan"

src/parse.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::fmt::{self, Display, Formatter};
22

3+
use chainchomp::ctx_free::many_delimited;
4+
35
use crate::lex::Token;
46

57
#[derive(Debug)]
@@ -206,12 +208,8 @@ fn parse_postfix_expr<'text>(
206208
) -> Result<(PostfixExpr<'text>, usize), ParseError> {
207209
if let Some(Token::Ident(name)) = tokens.get(pos) {
208210
if let Some(Token::Symbol("(")) = tokens.get(pos + 1) {
209-
let (args, pos) = many(
210-
tokens,
211-
pos + 2,
212-
parse_assignment_expr,
213-
Some(Token::Symbol(",")),
214-
);
211+
let (args, pos) =
212+
many_delimited(tokens, pos + 2, parse_assignment_expr, &Token::Symbol(","));
215213

216214
let Some(Token::Symbol(")")) = tokens.get(pos) else {
217215
return Err(ParseError::Expected(Token::Symbol(")"), pos));
@@ -253,31 +251,6 @@ fn parse_primary_expr<'text>(
253251
}
254252
}
255253

256-
fn many<'text, Ast>(
257-
tokens: &[Token<'text>],
258-
mut pos: usize,
259-
parser: impl Fn(&[Token<'text>], usize) -> Result<(Ast, usize), ParseError>,
260-
delimiter: Option<Token>,
261-
) -> (Vec<Ast>, usize) {
262-
let mut list = vec![];
263-
264-
while let Ok((ast, next_pos)) = parser(tokens, pos) {
265-
list.push(ast);
266-
pos = next_pos;
267-
268-
if let Some(delimiter) = &delimiter {
269-
match tokens.get(pos) {
270-
Some(token) if token == delimiter => {
271-
pos += 1;
272-
}
273-
_ => break,
274-
};
275-
}
276-
}
277-
278-
(list, pos)
279-
}
280-
281254
impl<'text> Display for AssignmentExpr<'text> {
282255
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
283256
match self {

0 commit comments

Comments
 (0)