diff --git a/schala-lang/src/parsing/combinator.rs b/schala-lang/src/parsing/combinator.rs index a44c133..0d112fa 100644 --- a/schala-lang/src/parsing/combinator.rs +++ b/schala-lang/src/parsing/combinator.rs @@ -91,6 +91,8 @@ pub fn program(input: Span) -> ParseResult { )), |(_, items, _)| items.into()) )(input)?; + println!("REST: {}", rest.fragment()); + let ast = AST { id, statements }; Ok((rest, ast)) } @@ -118,8 +120,8 @@ fn statement(input: Span) -> ParseResult { let (rest, kind) = context( "Parsing-statement", alt(( - map(expression, StatementKind::Expression), map(declaration, StatementKind::Declaration), + map(expression, StatementKind::Expression), )) )(input)?; Ok((rest, Statement { id, location, kind })) @@ -144,25 +146,33 @@ fn module(input: Span) -> ParseResult { pub fn expression(input: Span) -> ParseResult { let id = fresh_id(&input); - map(pair(expression_kind, opt(type_anno)), move |(kind, maybe_anno)| Expression::new(id, kind))(input) + map(pair(expression_kind, opt(type_anno)), move |(kind, type_anno)| Expression { id, type_anno, kind })(input) } fn type_anno(input: Span) -> ParseResult { - preceded(kw(":"), type_identifier)(input) + preceded(tok(char(':')), type_identifier)(input) } fn type_identifier(input: Span) -> ParseResult { - /* alt(( - tuple((kw("("), separated_list0(kw(","), type_identifier), kw(")"))), - type_singleton_name + map(delimited(tok(char('(')), separated_list0(tok(char(',')), type_identifier), tok(char(')'))), + TypeIdentifier::Tuple), + map(type_singleton_name, TypeIdentifier::Singleton), ))(input) - */ - unimplemented!() } fn type_singleton_name(input: Span) -> ParseResult { - unimplemented!() + map(pair(tok(identifier), opt(type_params)), |(name, params)| TypeSingletonName { + name: rc_string(name.fragment()), params: if let Some(params) = params { params } else { vec![] } + })(input) +} + +fn type_params(input: Span) -> ParseResult> { + delimited( + tok(char('<')), + separated_list1(tok(char(',')), type_identifier), + tok(char('>')) + )(input) } pub fn expression_kind(input: Span) -> ParseResult { diff --git a/schala-lang/src/parsing/mod.rs b/schala-lang/src/parsing/mod.rs index 72debf0..b4086ce 100644 --- a/schala-lang/src/parsing/mod.rs +++ b/schala-lang/src/parsing/mod.rs @@ -44,7 +44,9 @@ impl Parser { let id_store: IdStore = IdStore::new(); let span = Span::new_extra(input, Rc::new(RefCell::new(id_store))); - combinator::expression(span).map_err(|err| convert_err(input, err)).map(|(_, output)| output) + combinator::expression(span).map_err(|err| convert_err(input, err)).map(|(rest, output)| { + output + }) } #[cfg(test)] diff --git a/schala-lang/src/parsing/test.rs b/schala-lang/src/parsing/test.rs index 0e6e08b..829fe13 100644 --- a/schala-lang/src/parsing/test.rs +++ b/schala-lang/src/parsing/test.rs @@ -552,7 +552,7 @@ fn type_annotations() { use ExpressionKind::*; use TypeIdentifier::*; - assert_ast!( + assert_ast_comb!( "let a = b : Int", vec![decl(Declaration::Binding { name: rc("a"), @@ -562,11 +562,11 @@ fn type_annotations() { })] ); - assert_expr!( + assert_expr_comb!( "a: Int", expr_anno(Value(qn!(a)), Singleton(TypeSingletonName { name: rc("Int"), params: vec![] })) ); - assert_expr!( + assert_expr_comb!( "a: Option", expr_anno( Value(qn!(a)), @@ -576,7 +576,7 @@ fn type_annotations() { }) ) ); - assert_expr!( + assert_expr_comb!( "a: KoreanBBQSpecifier >", expr_anno( Value(qn!(a)), @@ -592,7 +592,7 @@ fn type_annotations() { }) ) ); - assert_expr!( + assert_expr_comb!( "a: (Int, Yolo)", expr_anno( Value(qn!(a)),