Removed a copious amount of premature Rc-s
This commit is contained in:
@@ -8,15 +8,14 @@ use super::context::Context;
|
||||
use super::decls::SimpleParser;
|
||||
use super::enum_filter::enum_filter;
|
||||
use super::lexer::{filter_map_lex, Entry, Lexeme};
|
||||
use crate::interner::Sym;
|
||||
use crate::representations::ast::{Clause, Expr};
|
||||
use crate::representations::location::Location;
|
||||
use crate::representations::Primitive;
|
||||
use crate::representations::{Primitive, VName};
|
||||
|
||||
/// Parses any number of expr wrapped in (), [] or {}
|
||||
fn sexpr_parser(
|
||||
expr: impl SimpleParser<Entry, Expr> + Clone,
|
||||
) -> impl SimpleParser<Entry, (Clause, Range<usize>)> + Clone {
|
||||
expr: impl SimpleParser<Entry, Expr<VName>> + Clone,
|
||||
) -> impl SimpleParser<Entry, (Clause<VName>, Range<usize>)> + Clone {
|
||||
let body = expr.repeated();
|
||||
choice((
|
||||
Lexeme::LP('(').parser().then(body.clone()).then(Lexeme::RP('(').parser()),
|
||||
@@ -40,9 +39,9 @@ fn sexpr_parser(
|
||||
/// and type and body are both expressions. Comments are allowed
|
||||
/// and ignored everywhere in between the tokens
|
||||
fn lambda_parser<'a>(
|
||||
expr: impl SimpleParser<Entry, Expr> + Clone + 'a,
|
||||
expr: impl SimpleParser<Entry, Expr<VName>> + Clone + 'a,
|
||||
ctx: impl Context + 'a,
|
||||
) -> impl SimpleParser<Entry, (Clause, Range<usize>)> + Clone + 'a {
|
||||
) -> impl SimpleParser<Entry, (Clause<VName>, Range<usize>)> + Clone + 'a {
|
||||
Lexeme::BS
|
||||
.parser()
|
||||
.ignore_then(expr.clone())
|
||||
@@ -56,9 +55,8 @@ fn lambda_parser<'a>(
|
||||
|
||||
/// Parses a sequence of names separated by :: <br/>
|
||||
/// Comments and line breaks are allowed and ignored in between
|
||||
pub fn ns_name_parser<'a>(
|
||||
ctx: impl Context + 'a,
|
||||
) -> impl SimpleParser<Entry, (Sym, Range<usize>)> + Clone + 'a {
|
||||
pub fn ns_name_parser<'a>()
|
||||
-> impl SimpleParser<Entry, (VName, Range<usize>)> + Clone + 'a {
|
||||
filter_map_lex(enum_filter!(Lexeme::Name))
|
||||
.separated_by(Lexeme::NS.parser())
|
||||
.at_least(1)
|
||||
@@ -66,32 +64,31 @@ pub fn ns_name_parser<'a>(
|
||||
let start = elements.first().expect("can never be empty").1.start;
|
||||
let end = elements.last().expect("can never be empty").1.end;
|
||||
let tokens = (elements.iter().map(|(t, _)| *t)).collect::<Vec<_>>();
|
||||
(ctx.interner().i(&tokens), start..end)
|
||||
(tokens, start..end)
|
||||
})
|
||||
.labelled("Namespaced name")
|
||||
}
|
||||
|
||||
pub fn namelike_parser<'a>(
|
||||
ctx: impl Context + 'a,
|
||||
) -> impl SimpleParser<Entry, (Clause, Range<usize>)> + Clone + 'a {
|
||||
pub fn namelike_parser<'a>()
|
||||
-> impl SimpleParser<Entry, (Clause<VName>, Range<usize>)> + Clone + 'a {
|
||||
choice((
|
||||
filter_map_lex(enum_filter!(Lexeme::PH))
|
||||
.map(|(ph, range)| (Clause::Placeh(ph), range)),
|
||||
ns_name_parser(ctx).map(|(token, range)| (Clause::Name(token), range)),
|
||||
ns_name_parser().map(|(token, range)| (Clause::Name(token), range)),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn clause_parser<'a>(
|
||||
expr: impl SimpleParser<Entry, Expr> + Clone + 'a,
|
||||
expr: impl SimpleParser<Entry, Expr<VName>> + Clone + 'a,
|
||||
ctx: impl Context + 'a,
|
||||
) -> impl SimpleParser<Entry, (Clause, Range<usize>)> + Clone + 'a {
|
||||
) -> impl SimpleParser<Entry, (Clause<VName>, Range<usize>)> + Clone + 'a {
|
||||
choice((
|
||||
filter_map_lex(enum_filter!(Lexeme >> Primitive; Literal))
|
||||
.map(|(p, s)| (Clause::P(p), s))
|
||||
.labelled("Literal"),
|
||||
sexpr_parser(expr.clone()),
|
||||
lambda_parser(expr, ctx.clone()),
|
||||
namelike_parser(ctx),
|
||||
lambda_parser(expr, ctx),
|
||||
namelike_parser(),
|
||||
))
|
||||
.labelled("Clause")
|
||||
}
|
||||
@@ -99,7 +96,7 @@ pub fn clause_parser<'a>(
|
||||
/// Parse an expression
|
||||
pub fn xpr_parser<'a>(
|
||||
ctx: impl Context + 'a,
|
||||
) -> impl SimpleParser<Entry, Expr> + 'a {
|
||||
) -> impl SimpleParser<Entry, Expr<VName>> + 'a {
|
||||
recursive(move |expr| {
|
||||
clause_parser(expr, ctx.clone()).map(move |(value, range)| Expr {
|
||||
value,
|
||||
|
||||
Reference in New Issue
Block a user