Start parsing
This commit is contained in:
parent
16d9e3eb60
commit
7831cb8d8a
@ -23,13 +23,14 @@ impl ProgrammingLanguageInterface for Schala {
|
||||
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 {
|
||||
output.add_output(format!("Tokenization error: {:?}\n", token_errors));
|
||||
return output;
|
||||
{
|
||||
let token_errors: Vec<&String> = tokens.iter().filter_map(|t| t.get_error()).collect();
|
||||
if token_errors.len() != 0 {
|
||||
output.add_output(format!("Tokenization error: {:?}\n", token_errors));
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
let ast = match parsing::parse(tokens) {
|
||||
Ok(ast) => {
|
||||
if options.debug_parse {
|
||||
@ -42,9 +43,8 @@ impl ProgrammingLanguageInterface for Schala {
|
||||
return output;
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
let evaluation_output = format!("{:?}", tokens);
|
||||
let evaluation_output = format!("{:?}", ast);
|
||||
output.add_output(evaluation_output);
|
||||
return output;
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ use std::iter::{Enumerate, Peekable};
|
||||
use self::itertools::Itertools;
|
||||
use std::str::Chars;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum TokenType {
|
||||
Newline, Semicolon,
|
||||
@ -276,11 +275,35 @@ postop := ε | LParen exprlist RParen | LBracket expression RBracket
|
||||
op := '+', '-', etc.
|
||||
*/
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub struct AST { }
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn parse(_input: Vec<Token>) -> Result<AST, ParseError> {
|
||||
Ok(AST { })
|
||||
struct Parser {
|
||||
tokens: Vec<Token>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AST(Vec<Statement>);
|
||||
|
||||
#[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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user