From de13e69769b30200c8ec640523066ed120d6a3f7 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sat, 20 Nov 2021 22:21:10 -0800 Subject: [PATCH] Add context --- schala-lang/src/parsing/combinator.rs | 12 ++++++++---- schala-lang/src/parsing/test.rs | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/schala-lang/src/parsing/combinator.rs b/schala-lang/src/parsing/combinator.rs index 31e6719..4ec0baa 100644 --- a/schala-lang/src/parsing/combinator.rs +++ b/schala-lang/src/parsing/combinator.rs @@ -304,6 +304,7 @@ fn formal_param(input: Span) -> ParseResult { } fn type_decl(input: Span) -> ParseResult { + context("type-decl", alt(( map( tuple((kw("type"), kw("alias"), identifier, tok(char('=')), identifier)), @@ -316,18 +317,19 @@ fn type_decl(input: Span) -> ParseResult { 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 { 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 { @@ -357,9 +359,10 @@ fn variant_spec(input: Span) -> ParseResult { } fn record_variant_item(input: Span) -> ParseResult<(Rc, 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 { @@ -809,7 +812,8 @@ fn qualified_identifier(input: Span) -> ParseResult { } fn identifier(input: Span) -> ParseResult { - tok(identifier_span)(input) + context("identifier", + tok(identifier_span))(input) } fn identifier_span(input: Span) -> ParseResult { diff --git a/schala-lang/src/parsing/test.rs b/schala-lang/src/parsing/test.rs index 02cd750..a0bc7bc 100644 --- a/schala-lang/src/parsing/test.rs +++ b/schala-lang/src/parsing/test.rs @@ -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))));