From 291fb61c8df73d4fb4af31491c120019eae36517 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 13 Sep 2017 20:10:06 -0700 Subject: [PATCH] Parse identifiers Some more complicted types of expression --- src/schala_lang/parsing.rs | 45 +++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index e030849..888b56a 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -286,19 +286,23 @@ statement := expression | declaration declaration := type_declaration | func_declaration -type_declaration := TYPE identifier -func_declaration := FN identifier LParen param_list RParen +type_declaration := TYPE IDENTIFIER +func_declaration := FN IDENTIFIER LParen param_list RParen -param_list := (identifier type_anno+ Comma)* +param_list := (IDENTIFIER type_anno+ Comma)* type_anno := Colon type expression := precedence_expr precedence_expr := primary -primary := literal +primary := literal | paren_expr | identifier_expr +paren_expr := LParen expression RParen +identifier_expr := call_expr | index_expr | IDENTIFIER literal := TRUE | FALSE | number_literal | str_literal -identifier := IDENTIFIER +call_expr := IDENTIFIER LParen expr_list RParen //TODO maybe make this optional? or no, have a bare identifier meant to be used as method taken care of in eval +index_expr := LBracket (expression, Comma+)* RBracket +expr_list := expression (Comma expression)* | ε // a float_literal can still be assigned to an int in type-checking number_literal := int_literal | float_literal @@ -374,7 +378,12 @@ pub enum TypeBody { pub enum Expression { IntLiteral(u64), FloatLiteral(f64), - BinExp(Operation, Box, Box) + BinExp(Operation, Box, Box), + Variable(Rc), + Call { + name: Rc, + params: Vec, + } } #[derive(Debug, PartialEq)] @@ -474,6 +483,7 @@ impl Parser { fn primary(&mut self) -> ParseResult { match self.peek() { LParen => self.paren_expr(), + Identifier(_) => self.identifier_expr(), _ => self.literal(), } } @@ -485,6 +495,29 @@ impl Parser { Ok(expr) } + fn identifier_expr(&mut self) -> ParseResult { + let identifier = self.identifier()?; + match self.peek() { + LParen => { + let call = self.call_expr()?; + unimplemented!() + }, + LSquareBracket => { + let bracket = self.index_expr()?; + unimplemented!() + }, + _ => Ok(Expression::Variable(identifier)) + } + } + + fn call_expr(&mut self) -> ParseResult { + unimplemented!() + } + + fn index_expr(&mut self) -> ParseResult { + unimplemented!() + } + fn identifier(&mut self) -> ParseResult> { match self.next() { Identifier(s) => Ok(s),