Start parsing

This commit is contained in:
greg 2017-09-08 16:42:42 -07:00
parent 16d9e3eb60
commit 7831cb8d8a
2 changed files with 38 additions and 15 deletions

View File

@ -23,13 +23,14 @@ impl ProgrammingLanguageInterface for Schala {
output.add_artifact(TraceArtifact::new("tokens", format!("{:?}", tokens))); output.add_artifact(TraceArtifact::new("tokens", format!("{:?}", tokens)));
} }
let token_errors: Vec<&String> = tokens.iter().filter_map(|t| t.get_error()).collect(); {
if token_errors.len() != 0 { let token_errors: Vec<&String> = tokens.iter().filter_map(|t| t.get_error()).collect();
output.add_output(format!("Tokenization error: {:?}\n", token_errors)); if token_errors.len() != 0 {
return output; output.add_output(format!("Tokenization error: {:?}\n", token_errors));
return output;
}
} }
/*
let ast = match parsing::parse(tokens) { let ast = match parsing::parse(tokens) {
Ok(ast) => { Ok(ast) => {
if options.debug_parse { if options.debug_parse {
@ -42,9 +43,8 @@ impl ProgrammingLanguageInterface for Schala {
return output; return output;
} }
}; };
*/
let evaluation_output = format!("{:?}", tokens); let evaluation_output = format!("{:?}", ast);
output.add_output(evaluation_output); output.add_output(evaluation_output);
return output; return output;
} }

View File

@ -7,7 +7,6 @@ use std::iter::{Enumerate, Peekable};
use self::itertools::Itertools; use self::itertools::Itertools;
use std::str::Chars; use std::str::Chars;
#[allow(dead_code)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum TokenType { pub enum TokenType {
Newline, Semicolon, Newline, Semicolon,
@ -276,11 +275,35 @@ postop := ε | LParen exprlist RParen | LBracket expression RBracket
op := '+', '-', etc. op := '+', '-', etc.
*/ */
#[allow(dead_code)] struct Parser {
#[derive(Debug)] tokens: Vec<Token>,
pub struct AST { } }
#[allow(dead_code)] #[derive(Debug)]
pub fn parse(_input: Vec<Token>) -> Result<AST, ParseError> { pub struct AST(Vec<Statement>);
Ok(AST { })
#[derive(Debug, PartialEq)]
pub enum Statement {
Expression(Expression),
Declaration(Declaration),
}
#[derive(Debug, PartialEq)]
pub enum Declaration {
FuncDecl,
TypeDecl
}
#[derive(Debug, PartialEq)]
pub enum Expression {
UnsignedIntLiteral(u64),
SignedIntLiteral(i64),
FloatLiteral(f64),
}
pub fn parse(input: Vec<Token>) -> Result<AST, ParseError> {
use self::Statement::*; use self::Declaration::*; use self::Expression::*;
let statements = vec![Expression(UnsignedIntLiteral(1))];
Ok(AST(statements))
} }