From 7d1c07c4815ea8ab95c44b0f3cc7776b968eb778 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 9 Sep 2017 00:31:15 -0700 Subject: [PATCH] Parsing infrastructure --- src/schala_lang/parsing.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index bf773f6..e19ecda 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -1,6 +1,5 @@ extern crate itertools; -use language::{ParseError}; use std::collections::HashMap; use std::rc::Rc; use std::iter::{Enumerate, Peekable}; @@ -279,6 +278,12 @@ struct Parser { tokens: Vec, } +pub struct ParseError { + pub msg: String, +} + +pub type ParseResult = Result; + #[derive(Debug)] pub struct AST(Vec); @@ -301,9 +306,19 @@ pub enum Expression { FloatLiteral(f64), } -pub fn parse(input: Vec) -> Result { - use self::Statement::*; use self::Declaration::*; use self::Expression::*; +impl Parser { + fn new(input: Vec) -> Parser { + Parser { tokens: input } + } - let statements = vec![Expression(UnsignedIntLiteral(1))]; - Ok(AST(statements)) + fn program(&mut self) -> ParseResult { + use self::Statement::*; use self::Declaration::*; use self::Expression::*; + let statements = vec![Expression(UnsignedIntLiteral(1))]; + Ok(AST(statements)) + } +} + +pub fn parse(input: Vec) -> Result { + let mut parser = Parser::new(input); + parser.program() }