Hack new-style parsing into tests
Messy - clean this up later!
This commit is contained in:
parent
df99ff1e06
commit
ed68b57736
@ -426,7 +426,7 @@ fn type_name(text: &str) -> ParseResult<TypeIdentifier> {
|
|||||||
Ok((text, id))
|
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 (rest, (kind, type_anno)) = ws(pair(expression_kind, opt(type_anno)))(text)?;
|
||||||
let expr = Expression { id: ItemId::new(0), kind, type_anno };
|
let expr = Expression { id: ItemId::new(0), kind, type_anno };
|
||||||
Ok((rest, expr))
|
Ok((rest, expr))
|
||||||
|
@ -3,7 +3,7 @@ use std::cell::RefCell;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use super::{Parser, ParseResult, tokenize};
|
use super::{Parser, ParseResult, tokenize, ParseError};
|
||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
use super::Declaration::*;
|
use super::Declaration::*;
|
||||||
use super::Signature;
|
use super::Signature;
|
||||||
@ -13,6 +13,7 @@ use super::ExpressionKind::*;
|
|||||||
use super::Variant::*;
|
use super::Variant::*;
|
||||||
use super::ForBody::*;
|
use super::ForBody::*;
|
||||||
|
|
||||||
|
/*
|
||||||
fn make_parser(input: &str) -> Parser {
|
fn make_parser(input: &str) -> Parser {
|
||||||
let source_map = crate::source_map::SourceMap::new();
|
let source_map = crate::source_map::SourceMap::new();
|
||||||
let source_map_handle = Rc::new(RefCell::new(source_map));
|
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.add_new_tokens(tokens);
|
||||||
parser
|
parser
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
fn parse(input: &str) -> ParseResult<AST> {
|
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);
|
let mut parser = make_parser(input);
|
||||||
parser.parse()
|
parser.parse()
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! parse_test {
|
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) };
|
($expr_type:expr, $type_anno:expr) => { Expression::with_anno(ItemIdStore::new_id(), $expr_type, $type_anno) };
|
||||||
(s $expr_text:expr) => {
|
(s $expr_text:expr) => {
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
let mut parser = make_parser($expr_text);
|
let mut parser = make_parser($expr_text);
|
||||||
parser.expression().unwrap()
|
parser.expression().unwrap()
|
||||||
|
*/
|
||||||
|
crate::parser::expression($expr_text).unwrap().1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -105,8 +118,16 @@ macro_rules! exst {
|
|||||||
};
|
};
|
||||||
(s $statement_text:expr) => {
|
(s $statement_text:expr) => {
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
let mut parser = make_parser($statement_text);
|
let mut parser = make_parser($statement_text);
|
||||||
parser.statement().unwrap()
|
parser.statement().unwrap()
|
||||||
|
*/
|
||||||
|
Statement {
|
||||||
|
kind: StatementKind::Expression(
|
||||||
|
crate::parser::expression($statement_text).unwrap().1
|
||||||
|
),
|
||||||
|
id: ItemIdStore::new_id()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user