2017-08-29 04:27:07 -07:00
|
|
|
use language::{TokenError, ParseError};
|
2017-08-29 05:08:09 -07:00
|
|
|
use std::rc::Rc;
|
2017-08-29 04:27:07 -07:00
|
|
|
|
2017-08-31 16:26:55 -07:00
|
|
|
#[allow(dead_code)]
|
2017-08-29 04:27:07 -07:00
|
|
|
#[derive(Debug)]
|
2017-08-29 05:08:09 -07:00
|
|
|
pub enum Token {
|
|
|
|
Newline,
|
|
|
|
Semicolon,
|
|
|
|
LParen,
|
|
|
|
RParen,
|
|
|
|
LSquareBracket,
|
|
|
|
RSquareBracket,
|
|
|
|
LCurlyBrace,
|
|
|
|
RCurlyBrace,
|
|
|
|
Comma,
|
|
|
|
Period,
|
|
|
|
Colon,
|
|
|
|
Digit(u8),
|
|
|
|
StrLiteral(Rc<String>),
|
|
|
|
Identifier(Rc<String>),
|
|
|
|
Operator(Rc<String>),
|
|
|
|
}
|
|
|
|
|
2017-08-31 19:18:56 -07:00
|
|
|
pub fn tokenize(_input: &str) -> Result<Vec<Token>, TokenError> {
|
2017-08-29 05:08:09 -07:00
|
|
|
Ok(vec!())
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-08-30 04:28:52 -07:00
|
|
|
Schala EBNF grammar
|
|
|
|
|
|
|
|
|
|
|
|
type alias <name> = <other type>
|
|
|
|
|
|
|
|
type <name> = struct { <field> : <type>,* }
|
|
|
|
type <name> = Variant1 | Variant2(type, type) | Variant3 struct { }
|
|
|
|
|
|
|
|
|
|
|
|
'' = literal, all other symbols are nonterminals
|
2017-08-29 05:08:09 -07:00
|
|
|
|
|
|
|
program := (statement delimiter ?)*
|
2017-08-30 04:28:52 -07:00
|
|
|
delimiter := 'Newline' | ';'
|
2017-08-29 05:08:09 -07:00
|
|
|
statement := declaration | expression
|
2017-08-30 04:28:52 -07:00
|
|
|
|
|
|
|
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)* | ε
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-29 05:08:09 -07:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-08-31 16:26:55 -07:00
|
|
|
#[allow(dead_code)]
|
2017-08-29 04:27:07 -07:00
|
|
|
#[derive(Debug)]
|
2017-08-29 05:08:09 -07:00
|
|
|
pub struct AST { }
|
|
|
|
|
2017-08-31 16:26:55 -07:00
|
|
|
#[allow(dead_code)]
|
2017-08-31 19:18:56 -07:00
|
|
|
pub fn parse(_input: Vec<Token>) -> Result<AST, ParseError> {
|
2017-08-29 05:08:09 -07:00
|
|
|
Ok(AST { })
|
|
|
|
}
|