diff --git a/schala-lang/src/parsing/combinator.rs b/schala-lang/src/parsing/combinator.rs index 396b44a..a37c6db 100644 --- a/schala-lang/src/parsing/combinator.rs +++ b/schala-lang/src/parsing/combinator.rs @@ -3,10 +3,10 @@ use nom::{ branch::alt, bytes::complete::{take_till, tag}, character::complete::{alpha1, alphanumeric0, not_line_ending,none_of, char, one_of, space0, space1, multispace0, line_ending}, - combinator::{peek, not, value, map, recognize}, + combinator::{opt, peek, not, value, map, recognize}, error::{context, VerboseError, ParseError}, multi::{fold_many1, many1, many0, separated_list1, separated_list0}, - sequence::{tuple, preceded}, + sequence::{pair, tuple, preceded}, IResult, Parser, }; use std::rc::Rc; @@ -90,13 +90,37 @@ fn block(input: &str) -> ParseResult { fn statement(input: &str) -> ParseResult { context("Parsing-statement", - map(expression_kind, |kind| Statement { + map(expression, |expr| Statement { id: Default::default(), location: Default::default(), - kind: StatementKind::Expression(Expression::new(Default::default(), kind)), + kind: StatementKind::Expression(expr), }))(input) } +fn expression(input: &str) -> ParseResult { + map(pair(expression_kind, opt(type_anno)), |(kind, maybe_anno)| { + Expression::new(Default::default(), kind) + })(input) +} + +fn type_anno(input: &str) -> ParseResult { + preceded(kw(":"), type_identifier)(input) +} + +fn type_identifier(input: &str) -> ParseResult { + /* + alt(( + tuple((kw("("), separated_list0(kw(","), type_identifier), kw(")"))), + type_singleton_name + ))(input) + */ + unimplemented!() +} + +fn type_singleton_name(input: &str) -> ParseResult { + unimplemented!() +} + pub fn expression_kind(input: &str) -> ParseResult { context("expression-kind", primary_expr)(input) }