mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-11-05 04:51:40 +03:00
Revert to using soft_keyword instead of Token::Data
This commit is contained in:
parent
b6d44db080
commit
0776b48781
@ -127,9 +127,6 @@ pub enum Token {
|
||||
#[token("/*", comment)]
|
||||
MultiLineComment,
|
||||
|
||||
#[token("data")]
|
||||
Data,
|
||||
|
||||
Error(LexingError),
|
||||
}
|
||||
|
||||
@ -256,7 +253,6 @@ impl fmt::Display for Token {
|
||||
Self::Dollar => write!(f, "$"),
|
||||
Self::Let => write!(f, "let"),
|
||||
Self::Match => write!(f, "match"),
|
||||
Self::Data => write!(f, "data"),
|
||||
Self::Equals => write!(f, "="),
|
||||
Self::Num(num) => write!(f, "{num}"),
|
||||
Self::Str(s) => write!(f, "\"{s}\""),
|
||||
|
@ -111,6 +111,13 @@ fn token_stream(
|
||||
|
||||
// Parsers
|
||||
|
||||
fn soft_keyword<'a, I>(keyword: &'static str) -> impl Parser<'a, I, (), extra::Err<Rich<'a, Token>>>
|
||||
where
|
||||
I: ValueInput<'a, Token = Token, Span = SimpleSpan>,
|
||||
{
|
||||
any().filter(move |t| matches!(t, Token::Name(n) if n.as_str() == keyword)).to(()).labelled(keyword)
|
||||
}
|
||||
|
||||
fn name<'a, I>() -> impl Parser<'a, I, Name, extra::Err<Rich<'a, Token>>>
|
||||
where
|
||||
I: ValueInput<'a, Token = Token, Span = SimpleSpan>,
|
||||
@ -124,7 +131,6 @@ where
|
||||
let Token::Name(name) = t else { unreachable!() };
|
||||
Name::from(name)
|
||||
})
|
||||
.or(just(Token::Data).to(Name("data".into())))
|
||||
.labelled("<Name>")
|
||||
}
|
||||
|
||||
@ -134,7 +140,7 @@ where
|
||||
I: ValueInput<'a, Token = Token, Span = SimpleSpan>,
|
||||
{
|
||||
any()
|
||||
.filter(|t| matches!(t, Token::Name(_)))
|
||||
.filter(|t| matches!(t, Token::Name(n) if n.as_str() != "data"))
|
||||
.map(|t| {
|
||||
let Token::Name(name) = t else { unreachable!() };
|
||||
name
|
||||
@ -408,9 +414,10 @@ where
|
||||
)
|
||||
}));
|
||||
|
||||
let paren_lhs = lhs
|
||||
.clone()
|
||||
.delimited_by(just(Token::LParen), just(Token::RParen))
|
||||
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)));
|
||||
|
||||
choice((just_lhs, paren_lhs))
|
||||
@ -421,7 +428,7 @@ where
|
||||
I: ValueInput<'a, Token = Token, Span = SimpleSpan>,
|
||||
{
|
||||
let unclosed_terms = term()
|
||||
.and_is(just(Token::Data).not().rewind())
|
||||
.and_is(soft_keyword("data").not().rewind())
|
||||
.and_is(rule_pattern().not().rewind())
|
||||
.repeated()
|
||||
.at_least(1)
|
||||
@ -457,7 +464,7 @@ where
|
||||
let ctrs = arity_0.or(arity_n).separated_by(just(Token::Or)).at_least(1).collect();
|
||||
let data_name = tl_name().map_with_span(|name, span| (name, span));
|
||||
|
||||
just(Token::Data)
|
||||
soft_keyword("data")
|
||||
.ignore_then(data_name.map_err(|err| map_unexpected_eof::<I>(err, Token::Name("<Name>".to_string()))))
|
||||
.then_ignore(just(Token::Equals))
|
||||
.then(ctrs.map_err(|err| map_unexpected_eof::<I>(err, Token::Name("constructor".to_string()))))
|
||||
|
@ -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 '(' expected 'data', or <Name>
|
||||
At tests/golden_tests/compile_file/just_paren.hvm:1:1: found end of input expected <Name>
|
||||
[0m 1 | [4m[31m([0m
|
||||
|
@ -2,5 +2,5 @@
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/compile_file/unexpected_top_char.hvm
|
||||
---
|
||||
At tests/golden_tests/compile_file/unexpected_top_char.hvm:1:1: found '*' expected 'data', <Name>, or '('
|
||||
At tests/golden_tests/compile_file/unexpected_top_char.hvm:1:1: found end of input expected data, <Name>, or '('
|
||||
[0m 1 | [4m[31m*[0m
|
||||
|
Loading…
Reference in New Issue
Block a user