From ed68b577368b8e5d3e04f8b8e35689362ca6e6db Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 14 Mar 2020 02:28:46 -0700 Subject: [PATCH] Hack new-style parsing into tests Messy - clean this up later! --- schala-lang/language/src/parser.rs | 2 +- schala-lang/language/src/parsing/test.rs | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/schala-lang/language/src/parser.rs b/schala-lang/language/src/parser.rs index 74c98b8..4990190 100644 --- a/schala-lang/language/src/parser.rs +++ b/schala-lang/language/src/parser.rs @@ -426,7 +426,7 @@ fn type_name(text: &str) -> ParseResult { Ok((text, id)) } -fn expression(text: &str) -> ParseResult { +pub fn expression(text: &str) -> ParseResult { let (rest, (kind, type_anno)) = ws(pair(expression_kind, opt(type_anno)))(text)?; let expr = Expression { id: ItemId::new(0), kind, type_anno }; Ok((rest, expr)) diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index 50c4c09..0dc8475 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -3,7 +3,7 @@ use std::cell::RefCell; use std::rc::Rc; use std::str::FromStr; -use super::{Parser, ParseResult, tokenize}; +use super::{Parser, ParseResult, tokenize, ParseError}; use crate::ast::*; use super::Declaration::*; use super::Signature; @@ -13,6 +13,7 @@ use super::ExpressionKind::*; use super::Variant::*; use super::ForBody::*; +/* fn make_parser(input: &str) -> Parser { let source_map = crate::source_map::SourceMap::new(); let source_map_handle = Rc::new(RefCell::new(source_map)); @@ -21,10 +22,19 @@ fn make_parser(input: &str) -> Parser { parser.add_new_tokens(tokens); parser } +*/ fn parse(input: &str) -> ParseResult { + use crate::tokenizing::*; + crate::parser::parse_ast(input).map_err(|err| { + let token = Token { kind: TokenKind::Newline, location: crate::source_map::Location { line_num: 0, char_num: 0 } }; + ParseError { production_name: None, msg: "".to_string(), token } + }) + .map(|(rest, s)| s) + /* let mut parser = make_parser(input); parser.parse() + */ } macro_rules! parse_test { @@ -82,8 +92,11 @@ macro_rules! ex { ($expr_type:expr, $type_anno:expr) => { Expression::with_anno(ItemIdStore::new_id(), $expr_type, $type_anno) }; (s $expr_text:expr) => { { + /* let mut parser = make_parser($expr_text); parser.expression().unwrap() + */ + crate::parser::expression($expr_text).unwrap().1 } }; } @@ -105,8 +118,16 @@ macro_rules! exst { }; (s $statement_text:expr) => { { + /* let mut parser = make_parser($statement_text); parser.statement().unwrap() + */ + Statement { + kind: StatementKind::Expression( + crate::parser::expression($statement_text).unwrap().1 + ), + id: ItemIdStore::new_id() + } } } }