From 192a7e611f483c1f43f3c4bab5dc171c6e178066 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 30 Aug 2017 04:28:52 -0700 Subject: [PATCH] Parsing BNF --- src/schala_lang/parsing.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 493e66b..eca748f 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -25,11 +25,40 @@ pub fn tokenize(input: &str) -> Result, TokenError> { } /* -Schala grammar +Schala EBNF grammar + + + type alias = + +type = struct { : ,* } +type = Variant1 | Variant2(type, type) | Variant3 struct { } + + +'' = literal, all other symbols are nonterminals program := (statement delimiter ?)* -delimiter := Newline | Semicolon +delimiter := 'Newline' | ';' statement := declaration | expression + +declaration := module | function | type_decl + +type_decl := 'type' type_format +type_format := 'alias' '=' type | type_constructor +type_constructor := capital_ident '=' type_rhs +type_rhs := struct_decl | type_variant ('|' type_variant)* +struct_decl := 'struct' '{' (ident ':' type)* '}' +type_variant := capital_ident | tuple_type | capital_ident struct_decl +tuple_type := // something like Variant(a,b) +type := // something like Type[A[b]] + +ascription := expression (':' type)+ + +function := 'fn' prototype '{' (statement)* '}' +prototype := identifier '(' identlist ')' +identlist := identifier (',' identifier)* | ε + + + declaration := FN prototype LCurlyBrace (statement)* RCurlyBrace prototype := identifier LParen identlist RParen identlist := Ident (Comma Ident)* | ε @@ -53,7 +82,6 @@ postop := ε | LParen exprlist RParen | LBracket expression RBracket op := '+', '-', etc. */ - #[derive(Debug)] pub struct AST { }