From 9bfe1f36502c701d33174293f71647e614e5797e Mon Sep 17 00:00:00 2001 From: NanoTech Date: Wed, 7 Dec 2016 00:14:15 -0600 Subject: Parse Const, lists, and records Also fix keyword parsing to always consume whole identifiers.--- src/grammar.lalrpop | 57 +++++++++++++++++++++++++++++- src/grammar_util.rs | 8 ++--- src/lexer.rs | 100 +++++++++++++++++++++++++++++++++++++--------------- src/parser.rs | 1 + 4 files changed, 133 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/grammar.lalrpop b/src/grammar.lalrpop index 8a4ad83..c2dc879 100644 --- a/src/grammar.lalrpop +++ b/src/grammar.lalrpop @@ -1,7 +1,11 @@ use core; use core::Expr::*; use grammar_util::*; -use lexer::{Builtin, Keyword, LexicalError, Tok}; +use lexer::*; + +use std::collections::HashMap; +use std::iter; +use std::iter::FromIterator; grammar; @@ -19,13 +23,20 @@ extern { Nat => Tok::Natural(), Bool => Tok::Bool(), Label => Tok::Identifier(), + Const => Tok::Const(), Let => Tok::Keyword(Keyword::Let), In => Tok::Keyword(Keyword::In), If => Tok::Keyword(Keyword::If), Then => Tok::Keyword(Keyword::Then), Else => Tok::Keyword(Keyword::Else), + List => Tok::ListLike(ListLike::List), + Optional => Tok::ListLike(ListLike::Optional), Builtin => Tok::Builtin(), + "{" => Tok::BraceL, + "}" => Tok::BraceR, + "[" => Tok::BracketL, + "]" => Tok::BracketR, "(" => Tok::ParenL, ")" => Tok::ParenR, "&&" => Tok::BoolAnd, @@ -35,6 +46,7 @@ extern { "++" => Tok::Append, "*" => Tok::Times, "+" => Tok::Plus, + "," => Tok::Comma, "." => Tok::Dot, ":" => Tok::Ascription, "=" => Tok::Equals, @@ -52,9 +64,15 @@ ExprB: BoxExpr = { If Then Else => bx(BoolIf(<>)), "->" => bx(Pi("_".to_owned(), <>)), Let