Start to parse type annos

This commit is contained in:
greg 2020-03-07 04:31:55 -08:00
parent d034a99ac1
commit 9e898d86b3

View File

@ -222,19 +222,26 @@ fn expression_kind(text: &str) -> ParseResult<ExpressionKind> {
context("Expression kind", precedence_expr)(text)
}
/*
fn type_anno(text: &str) -> ParseResult<TypeIdentifier> {
use nom::character::complete::char;
preceded(ws(char(':')), ws(type_name))(text)
}
fn type_name(text: &str) -> ParseResult<TypeIdentifier> {
//TODO incomplete
let (text, name) = identifier(text)?;
let id = TypeIdentifier::Singleton(TypeSingletonName { name, params: vec![] });
Ok((text, id))
}
fn expression(text: &str) -> ParseResult<Expression> {
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<String, String> {
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)) => {