Fix test for reserved words error
This commit is contained in:
parent
bb26d9e674
commit
ec5bf12a65
@ -123,7 +123,9 @@ pub fn program(input: Span) -> ParseResult<AST> {
|
|||||||
many0(statement_delimiter),
|
many0(statement_delimiter),
|
||||||
)),
|
)),
|
||||||
|(_, items, _)| items.into(),
|
|(_, items, _)| items.into(),
|
||||||
), tok(eof)),
|
),
|
||||||
|
tok(eof),
|
||||||
|
),
|
||||||
)(input)?;
|
)(input)?;
|
||||||
|
|
||||||
let ast = AST { id, statements };
|
let ast = AST { id, statements };
|
||||||
@ -528,9 +530,9 @@ fn invocation_argument(input: Span) -> ParseResult<InvocationArgument> {
|
|||||||
fn primary_expr(allow_struct: bool) -> impl FnMut(Span) -> ParseResult<ExpressionKind> {
|
fn primary_expr(allow_struct: bool) -> impl FnMut(Span) -> ParseResult<ExpressionKind> {
|
||||||
move |input: Span| {
|
move |input: Span| {
|
||||||
if allow_struct {
|
if allow_struct {
|
||||||
context("primary-expr", alt((named_struct, primary_expr_no_struct)))(input)
|
context("primary-expr", alt((primary_expr_no_struct, named_struct, identifier_expr)))(input)
|
||||||
} else {
|
} else {
|
||||||
context("primary-expr", primary_expr_no_struct)(input)
|
context("primary-expr", alt((primary_expr_no_struct, identifier_expr)))(input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -545,11 +547,10 @@ fn primary_expr_no_struct(input: Span) -> ParseResult<ExpressionKind> {
|
|||||||
lambda_expr,
|
lambda_expr,
|
||||||
list_expr,
|
list_expr,
|
||||||
paren_expr,
|
paren_expr,
|
||||||
string_literal,
|
bool_literal,
|
||||||
float_literal,
|
float_literal,
|
||||||
number_literal,
|
number_literal,
|
||||||
bool_literal,
|
string_literal,
|
||||||
identifier_expr,
|
|
||||||
)),
|
)),
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
@ -783,17 +784,16 @@ fn identifier(input: Span) -> ParseResult<Span> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn identifier_span(input: Span) -> ParseResult<Span> {
|
fn identifier_span(input: Span) -> ParseResult<Span> {
|
||||||
fn check(input: &Span) -> bool {
|
let (rest, parsed) = recognize(tuple((
|
||||||
!is_keyword(input.fragment())
|
|
||||||
}
|
|
||||||
|
|
||||||
verify(
|
|
||||||
recognize(tuple((
|
|
||||||
alt((tag("_"), alpha1)),
|
alt((tag("_"), alpha1)),
|
||||||
take_while(|ch: char| is_alphanumeric(ch as u8) || ch == '_'),
|
take_while(|ch: char| is_alphanumeric(ch as u8) || ch == '_'),
|
||||||
))),
|
)))(input.clone())?;
|
||||||
check,
|
|
||||||
)(input)
|
if is_keyword(parsed.fragment()) {
|
||||||
|
return Err(nom::Err::Failure(VerboseError::from_error_kind(input, nom::error::ErrorKind::Verify)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((rest, parsed))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bool_literal(input: Span) -> ParseResult<ExpressionKind> {
|
fn bool_literal(input: Span) -> ParseResult<ExpressionKind> {
|
||||||
|
@ -555,7 +555,10 @@ fn complex_lambdas() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reserved_words() {
|
fn reserved_words() {
|
||||||
assert_fail!("module::item::call()", "error at 1:7: expected ['a' ..= 'z' | 'A' ..= 'Z' | '_']");
|
let err = "0: at line 1, in Verify:\nmodule::item::call()\n^\n\n1: at line 1, in tok:\nmodule::item::call()\n^\n\n2: at line 1, in tok:\nmodule::item::call()\n^\n\n3: at line 1, in primary-expr-no-struct:\nmodule::item::call()\n^\n\n4: at line 1, in primary-expr:\nmodule::item::call()\n^\n\n5: at line 1, in extended-expr:\nmodule::item::call()\n^\n\n6: at line 1, in prefix-expr:\nmodule::item::call()\n^\n\n7: at line 1, in expression-kind:\nmodule::item::call()\n^\n\n8: at line 1, in Parsing-statement:\nmodule::item::call()\n^\n\n9: at line 1, in AST:\nmodule::item::call()\n^\n\n";
|
||||||
|
assert_fail_comb!("module::item::call()", err);
|
||||||
|
|
||||||
|
assert_expr!("modulek::item", expr(ExpressionKind::Value(qn!(modulek, item))));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user