Add context
This commit is contained in:
parent
8f3c982131
commit
de13e69769
@ -304,6 +304,7 @@ fn formal_param(input: Span) -> ParseResult<FormalParam> {
|
||||
}
|
||||
|
||||
fn type_decl(input: Span) -> ParseResult<Declaration> {
|
||||
context("type-decl",
|
||||
alt((
|
||||
map(
|
||||
tuple((kw("type"), kw("alias"), identifier, tok(char('=')), identifier)),
|
||||
@ -316,18 +317,19 @@ fn type_decl(input: Span) -> ParseResult<Declaration> {
|
||||
tuple((kw("type"), opt(kw("mut")), type_singleton_name, tok(char('=')), type_body)),
|
||||
|(_, mutable, name, _, body)| Declaration::TypeDecl { name, body, mutable: mutable.is_some() },
|
||||
),
|
||||
))(input)
|
||||
)))(input)
|
||||
}
|
||||
|
||||
fn type_body(input: Span) -> ParseResult<TypeBody> {
|
||||
let id = fresh_id(&input);
|
||||
context("type-body",
|
||||
alt((
|
||||
map(
|
||||
delimited(tok(char('{')), separated_list1(tok(char(',')), record_variant_item), tok(char('}'))),
|
||||
move |items| TypeBody::ImmediateRecord { id, fields: items },
|
||||
),
|
||||
map(separated_list0(tok(char('|')), variant_spec), TypeBody::Variants),
|
||||
))(input)
|
||||
)))(input)
|
||||
}
|
||||
|
||||
fn record_variant(input: Span) -> ParseResult<VariantKind> {
|
||||
@ -357,9 +359,10 @@ fn variant_spec(input: Span) -> ParseResult<Variant> {
|
||||
}
|
||||
|
||||
fn record_variant_item(input: Span) -> ParseResult<(Rc<String>, TypeIdentifier)> {
|
||||
context("record-variant-item",
|
||||
cut(map(tuple((identifier, tok(char(':')), type_identifier)), |(name, _, ty)| {
|
||||
(rc_string(name.fragment()), ty)
|
||||
}))(input)
|
||||
})))(input)
|
||||
}
|
||||
|
||||
fn binding(input: Span) -> ParseResult<Declaration> {
|
||||
@ -809,7 +812,8 @@ fn qualified_identifier(input: Span) -> ParseResult<QualifiedName> {
|
||||
}
|
||||
|
||||
fn identifier(input: Span) -> ParseResult<Span> {
|
||||
tok(identifier_span)(input)
|
||||
context("identifier",
|
||||
tok(identifier_span))(input)
|
||||
}
|
||||
|
||||
fn identifier_span(input: Span) -> ParseResult<Span> {
|
||||
|
@ -534,7 +534,7 @@ fn complex_lambdas() {
|
||||
|
||||
#[test]
|
||||
fn reserved_words() {
|
||||
let err = "0: at line 1, in Verify:\nmodule::item::call()\n^\n\n1: at line 1, in token:\nmodule::item::call()\n^\n\n2: at line 1, in token:\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";
|
||||
let err = "0: at line 1, in Verify:\nmodule::item::call()\n^\n\n1: at line 1, in token:\nmodule::item::call()\n^\n\n2: at line 1, in identifier:\nmodule::item::call()\n^\n\n3: at line 1, in token:\nmodule::item::call()\n^\n\n4: at line 1, in primary-expr-no-struct:\nmodule::item::call()\n^\n\n5: at line 1, in primary-expr:\nmodule::item::call()\n^\n\n6: at line 1, in extended-expr:\nmodule::item::call()\n^\n\n7: at line 1, in prefix-expr:\nmodule::item::call()\n^\n\n8: at line 1, in expression-kind:\nmodule::item::call()\n^\n\n9: at line 1, in Parsing-statement:\nmodule::item::call()\n^\n\n10: at line 1, in AST:\nmodule::item::call()\n^\n\n";
|
||||
assert_fail!("module::item::call()", err);
|
||||
|
||||
assert_expr!("modulek::item", expr(ExpressionKind::Value(qn!(modulek, item))));
|
||||
|
Loading…
Reference in New Issue
Block a user