Remove Missing Parenthesis parser error

This commit is contained in:
LunaAmora 2024-02-16 10:06:50 -03:00
parent 0776b48781
commit 7dc78cac6f
9 changed files with 5 additions and 58 deletions

View File

@ -15,7 +15,6 @@ use chumsky::{
IterParser, Parser,
};
use indexmap::{map::Entry, IndexMap};
use itertools::fold;
use logos::{Logos, SpannedIter};
use std::{iter::Map, ops::Range, path::Path};
@ -414,8 +413,7 @@ where
)
}));
let paren_lhs =
just(Token::LParen)
let paren_lhs = just(Token::LParen)
.ignore_then(lhs.clone().map_err(|err| map_unexpected_eof::<I>(err, Token::Name("<Name>".into()))))
.then_ignore(just(Token::RParen))
.then_ignore(just(Token::Equals).map_err(|err| map_unexpected_eof::<I>(err, Token::Equals)));
@ -427,28 +425,7 @@ fn rule<'a, I>() -> impl Parser<'a, I, TopLevel, extra::Err<Rich<'a, Token>>>
where
I: ValueInput<'a, Token = Token, Span = SimpleSpan>,
{
let unclosed_terms = term()
.and_is(soft_keyword("data").not().rewind())
.and_is(rule_pattern().not().rewind())
.repeated()
.at_least(1)
.collect::<Vec<Term>>()
.boxed();
rule_pattern()
.then(term()
// FIXME: This is used to report a parsing error that would be unclear otherwise
// couldn't implement it in terms of `.recover(via_parser(...))`
.then(unclosed_terms.or_not()).validate(
|(body, unclosed_terms), span, emit| match unclosed_terms {
Some(t) => {
emit.emit(Rich::custom(span, "Missing Parenthesis around rule body"));
fold(t, body, Term::app)
}
None => body,
},
))
.map(move |((name, pats), body)| TopLevel::Rule((name, Rule { pats, body })))
rule_pattern().then(term()).map(move |((name, pats), body)| TopLevel::Rule((name, Rule { pats, body })))
}
fn datatype<'a, I>() -> impl Parser<'a, I, TopLevel, extra::Err<Rich<'a, Token>>>

View File

@ -1 +1,2 @@
main = *
(

View File

@ -1,5 +0,0 @@
Foo a b = a b
Bar a b = Foo * (+ a b)
Baz = * *
main = Foo Baz

View File

@ -1 +0,0 @@
main = * *

View File

@ -1,3 +0,0 @@
main = * * * *
data Foo = Bar

View File

@ -2,5 +2,5 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/compile_file/just_paren.hvm
---
At tests/golden_tests/compile_file/just_paren.hvm:1:1: found end of input expected <Name>
 1 | (
At tests/golden_tests/compile_file/just_paren.hvm:2:1: found end of input expected <Name>
 2 | (

View File

@ -1,10 +0,0 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/compile_file/missing_paren.hvm
---
At tests/golden_tests/compile_file/missing_paren.hvm:2:11: Missing Parenthesis around rule body
 2 | Bar a b = Foo * (+ a b)
At tests/golden_tests/compile_file/missing_paren.hvm:3:7: Missing Parenthesis around rule body
 3 | Baz = * *
At tests/golden_tests/compile_file/missing_paren.hvm:5:8: Missing Parenthesis around rule body
 5 | main = Foo Baz

View File

@ -1,6 +0,0 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/parse_file/missing_paren.hvm
---
At tests/golden_tests/parse_file/missing_paren.hvm:1:8: Missing Parenthesis around rule body
 1 | main = * *

View File

@ -1,6 +0,0 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/parse_file/missing_paren_then_adt.hvm
---
At tests/golden_tests/parse_file/missing_paren_then_adt.hvm:1:8: Missing Parenthesis around rule body
 1 | main = * * * *