diff --git a/schala-lang/language/src/parser.rs b/schala-lang/language/src/parser.rs index b6e5eb8..9f5c73a 100644 --- a/schala-lang/language/src/parser.rs +++ b/schala-lang/language/src/parser.rs @@ -222,19 +222,26 @@ fn expression_kind(text: &str) -> ParseResult { context("Expression kind", precedence_expr)(text) } -/* fn type_anno(text: &str) -> ParseResult { + use nom::character::complete::char; + preceded(ws(char(':')), ws(type_name))(text) +} +fn type_name(text: &str) -> ParseResult { + //TODO incomplete + let (text, name) = identifier(text)?; + let id = TypeIdentifier::Singleton(TypeSingletonName { name, params: vec![] }); + Ok((text, id)) } fn expression(text: &str) -> ParseResult { - let (rest, (kind, type_anno)) = pair(expression_kind, type_anno)(text)?; - Ok((rest, Expression::with_anno(ItemId::new(0), kind, type_anno))) + let (rest, (kind, type_anno)) = pair(expression_kind, opt(type_anno))(text)?; + let expr = Expression { id: ItemId::new(0), kind, type_anno }; + Ok((rest, expr)) } -*/ pub fn perform_parsing(input: &str) -> Result { - let output = match expression_kind(input) { + let output = match expression(input) { Ok((rest, ast)) => format!("{:?} (rest: {})", ast, rest), Err(nom::Err::Incomplete(needed)) => format!("Incomplete: {:?}" ,needed), Err(nom::Err::Error(verbose_error) | nom::Err::Failure(verbose_error)) => {