From d3febb201b7d5ca0bc2157c0692bcca35b515a07 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 29 Aug 2017 05:08:09 -0700 Subject: [PATCH] More parsing --- src/schala_lang/mod.rs | 2 +- src/schala_lang/parsing.rs | 60 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/schala_lang/mod.rs b/src/schala_lang/mod.rs index 5f9eebb..2c09692 100644 --- a/src/schala_lang/mod.rs +++ b/src/schala_lang/mod.rs @@ -21,7 +21,7 @@ impl ProgrammingLanguage for Schala { } fn tokenize(input: &str) -> Result, TokenError> { - unimplemented!() + parsing::tokenize(input) } fn parse(input: Vec) -> Result { unimplemented!() diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 181da78..493e66b 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -1,8 +1,62 @@ use language::{TokenError, ParseError}; +use std::rc::Rc; + +#[derive(Debug)] +pub enum Token { + Newline, + Semicolon, + LParen, + RParen, + LSquareBracket, + RSquareBracket, + LCurlyBrace, + RCurlyBrace, + Comma, + Period, + Colon, + Digit(u8), + StrLiteral(Rc), + Identifier(Rc), + Operator(Rc), +} + +pub fn tokenize(input: &str) -> Result, TokenError> { + Ok(vec!()) +} + +/* +Schala grammar + +program := (statement delimiter ?)* +delimiter := Newline | Semicolon +statement := declaration | expression +declaration := FN prototype LCurlyBrace (statement)* RCurlyBrace +prototype := identifier LParen identlist RParen +identlist := Ident (Comma Ident)* | ε +exprlist := Expression (Comma Expression)* | ε +itemlist := Ident COLON Expression (Comma Ident COLON Expression)* | ε + +expression := postop_expression (op postop_expression)* +postop_expression := primary_expression postop +primary_expression := number_expr | String | identifier_expr | paren_expr | conditional_expr | while_expr | lambda_expr | list_expr | struct_expr +number_expr := (PLUS | MINUS ) number_expr | Number +identifier_expr := call_expression | Variable +list_expr := LSquareBracket exprlist RSquareBracket +struct_expr := LCurlyBrace itemlist RCurlyBrace +call_expression := Identifier LParen exprlist RParen +while_expr := WHILE primary_expression LCurlyBrace (expression delimiter)* RCurlyBrace +paren_expr := LParen expression RParen +conditional_expr := IF expression LCurlyBrace (expression delimiter)* RCurlyBrace (LCurlyBrace (expresion delimiter)* RCurlyBrace)? +lambda_expr := FN LParen identlist RParen LCurlyBrace (expression delimiter)* RCurlyBrace +lambda_call := | LParen exprlist RParen +postop := ε | LParen exprlist RParen | LBracket expression RBracket +op := '+', '-', etc. +*/ #[derive(Debug)] -pub enum Token { } +pub struct AST { } -#[derive(Debug)] -pub enum AST { } +pub fn parse(input: Vec) -> Result { + Ok(AST { }) +}