Hack new-style parsing into tests

Messy - clean this up later!
This commit is contained in:
greg 2020-03-14 02:28:46 -07:00
parent df99ff1e06
commit ed68b57736
2 changed files with 23 additions and 2 deletions

View File

@ -426,7 +426,7 @@ fn type_name(text: &str) -> ParseResult<TypeIdentifier> {
Ok((text, id))
}
fn expression(text: &str) -> ParseResult<Expression> {
pub fn expression(text: &str) -> ParseResult<Expression> {
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))

View File

@ -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<AST> {
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()
}
}
}
}