Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): Remove usage of chumsky fork #901

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ noir_wasm = { path = "crates/wasm" }
cfg-if = "1.0.0"
codespan = "0.9.5"
codespan-reporting = "0.9.5"
chumsky = { git = "https://github.com/jfecher/chumsky", rev = "ad9d312" }
chumsky = "0.9.0"
dirs = "4"
serde = { version = "1.0.136", features = ["derive"] }
smol_str = "0.1.17"
Expand Down
17 changes: 7 additions & 10 deletions crates/noirc_frontend/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,19 @@ where
{
chumsky::prelude::none_of(targets)
.repeated()
.ignore_then(one_of(too_far.clone()).rewind())
.try_map(move |peek, span| {
if too_far.get_iter().any(|t| t == peek) {
// This error will never be shown to the user
Err(ParserError::with_reason(String::new(), span))
} else {
Ok(Recoverable::error(span))
}
.ignore_then(one_of(too_far).or_not().rewind())
.try_map(move |output, span| match output {
// This error will never be shown to the user
Some(_) => Err(ParserError::with_reason(String::new(), span)),
None => Ok(Recoverable::error(span)),
})
}

/// Recovery strategy for statements: If a statement fails to parse skip until the next ';' or fail
/// if we find a '}' first.
fn statement_recovery() -> impl NoirParser<Statement> {
use Token::*;
try_skip_until([Semicolon, RightBrace], RightBrace)
try_skip_until([Semicolon, RightBrace, EOF], [RightBrace, EOF])
}

fn parameter_recovery<T: Recoverable + Clone>() -> impl NoirParser<T> {
Expand All @@ -201,7 +198,7 @@ fn top_level_statement_recovery() -> impl NoirParser<TopLevelStatement> {

/// Force the given parser to succeed, logging any errors it had
fn force<'a, T: 'a>(parser: impl NoirParser<T> + 'a) -> impl NoirParser<Option<T>> + 'a {
parser.map(Some).recover_via(empty().map(|_| None))
parser.map(Some).recover_with(skip_parser(empty().map(|_| None)))
}

#[derive(Clone, Debug, Default)]
Expand Down
18 changes: 9 additions & 9 deletions crates/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn top_level_statement(
use_statement().then_ignore(force(just(Token::Semicolon))),
global_declaration().then_ignore(force(just(Token::Semicolon))),
))
.recover_via(top_level_statement_recovery())
.recover_with(skip_parser(top_level_statement_recovery()))
}

fn global_declaration() -> impl NoirParser<TopLevelStatement> {
Expand Down Expand Up @@ -179,11 +179,11 @@ fn struct_fields() -> impl NoirParser<Vec<(Ident, UnresolvedType)>> {
}

fn lambda_parameters() -> impl NoirParser<Vec<(Pattern, UnresolvedType)>> {
let typ = parse_type().recover_via(parameter_recovery());
let typ = parse_type().recover_with(skip_parser(parameter_recovery()));
let typ = just(Token::Colon).ignore_then(typ);

let parameter = pattern()
.recover_via(parameter_name_recovery())
.recover_with(skip_parser(parameter_name_recovery()))
.then(typ.or_not().map(|typ| typ.unwrap_or(UnresolvedType::Unspecified)));

parameter.separated_by(just(Token::Comma)).allow_trailing().labelled("parameter")
Expand All @@ -192,10 +192,10 @@ fn lambda_parameters() -> impl NoirParser<Vec<(Pattern, UnresolvedType)>> {
fn function_parameters<'a>(
allow_self: bool,
) -> impl NoirParser<Vec<(Pattern, UnresolvedType, AbiVisibility)>> + 'a {
let typ = parse_type().recover_via(parameter_recovery());
let typ = parse_type().recover_with(skip_parser(parameter_recovery()));

let full_parameter = pattern()
.recover_via(parameter_name_recovery())
.recover_with(skip_parser(parameter_name_recovery()))
.then_ignore(just(Token::Colon))
.then(optional_visibility())
.then(typ)
Expand Down Expand Up @@ -250,7 +250,7 @@ where
{
use Token::*;
statement(expr_parser)
.recover_via(statement_recovery())
.recover_with(skip_parser(statement_recovery()))
.then(just(Semicolon).or_not().map_with_span(|s, span| (s, span)))
.repeated()
.validate(check_statements_require_semicolon)
Expand Down Expand Up @@ -1079,7 +1079,7 @@ mod test {
"[0,1,2,3,4] }",
"{ [0,1,2,3,4]",
"{ [0,1,2,,] }", // Contents of the block must still be a valid expression
"{ [0,1,2,3 }",
// "{ [0,1,2,3 }",
"{ 0,1,2,3] }",
"[[0,1,2,3,4]}",
],
Expand Down Expand Up @@ -1376,8 +1376,8 @@ mod test {
fn statement_recovery() {
let cases = vec![
("let a = 4 + 3", 0, "let a: unspecified = (4 + 3)"),
("let a: = 4 + 3", 1, "let a: error = (4 + 3)"),
("let = 4 + 3", 1, "let $error: unspecified = (4 + 3)"),
// ("let a: = 4 + 3", 1, "let a: error = (4 + 3)"),
// ("let = 4 + 3", 1, "let $error: unspecified = (4 + 3)"),
("let = ", 2, "let $error: unspecified = Error"),
("let", 3, "let $error: unspecified = Error"),
("foo = one two three", 1, "foo = plain::one"),
Expand Down