Public API and docs

This commit is contained in:
2023-05-26 15:23:15 +01:00
parent 3c1a6e2be2
commit fdf18e6ff8
99 changed files with 503 additions and 406 deletions

View File

@@ -3,10 +3,13 @@ use std::hash::Hash;
use chumsky::prelude::Simple;
use chumsky::recursive::Recursive;
use chumsky::{BoxedParser, Parser};
use trait_set::trait_set;
/// Wrapper around [Parser] with [Simple] error to avoid repeating the input
pub trait SimpleParser<I: Eq + Hash + Clone, O> =
Parser<I, O, Error = Simple<I>>;
trait_set! {
/// Wrapper around [Parser] with [Simple] error to avoid repeating the input
pub trait SimpleParser<I: Eq + Hash + Clone, O> =
Parser<I, O, Error = Simple<I>>;
}
/// Boxed version of [SimpleParser]
pub type BoxedSimpleParser<'a, I, O> = BoxedParser<'a, I, O, Simple<I>>;
/// [Recursive] specialization of [SimpleParser] to parameterize calls to

View File

@@ -8,7 +8,6 @@
/// // Foo::Bar(T) into Quz::Bar(T)
/// // Foo::Baz(U) into Quz::Baz(U)
/// ```
#[macro_export]
macro_rules! enum_filter {
($p:path | $m:tt) => {
{
@@ -48,3 +47,5 @@ macro_rules! enum_filter {
enum_filter!($p | {concat!("Expected ", stringify!($p))})
};
}
pub(crate) use enum_filter;

View File

@@ -6,8 +6,8 @@ use chumsky::{self, Parser};
use super::context::Context;
use super::decls::SimpleParser;
use super::enum_filter::enum_filter;
use super::lexer::{filter_map_lex, Entry, Lexeme};
use crate::enum_filter;
use crate::interner::Sym;
use crate::representations::ast::{Clause, Expr};
use crate::representations::location::Location;

View File

@@ -4,18 +4,17 @@ use itertools::Itertools;
use super::context::Context;
use super::decls::{SimpleParser, SimpleRecursive};
use super::enum_filter::enum_filter;
use super::lexer::{filter_map_lex, Lexeme};
use super::Entry;
use crate::interner::Tok;
use crate::representations::sourcefile::Import;
use crate::utils::iter::{
box_flatten, box_once, into_boxed_iter, BoxedIterIter,
box_chain, box_flatten, box_once, into_boxed_iter, BoxedIterIter,
};
use crate::{box_chain, enum_filter};
/// initialize a BoxedIter<BoxedIter<String>> with a single element.
/// initialize an iterator of iterator with a single element.
fn init_table(name: Tok<String>) -> BoxedIterIter<'static, Tok<String>> {
// I'm not at all confident that this is a good approach.
box_once(box_once(name))
}
@@ -24,7 +23,7 @@ fn init_table(name: Tok<String>) -> BoxedIterIter<'static, Tok<String>> {
/// semi and the delimiters are plain parentheses. Namespaces should
/// preferably contain crossplatform filename-legal characters but the
/// symbols are explicitly allowed to go wild.
/// There's a blacklist in [name]
/// There's a blacklist in [crate::parse::name::NOT_NAME_CHAR]
pub fn import_parser<'a>(
ctx: impl Context + 'a,
) -> impl SimpleParser<Entry, Vec<Import>> + 'a {

View File

@@ -24,7 +24,7 @@ fn op_parser<'a>(
/// Characters that cannot be parsed as part of an operator
///
/// The initial operator list overrides this.
static NOT_NAME_CHAR: &[char] = &[
pub static NOT_NAME_CHAR: &[char] = &[
':', // used for namespacing and type annotations
'\\', '@', // parametric expression starters
'"', '\'', // parsed as primitives and therefore would never match

View File

@@ -7,12 +7,12 @@ use itertools::Itertools;
use super::context::Context;
use super::decls::{SimpleParser, SimpleRecursive};
use super::enum_filter::enum_filter;
use super::expression::xpr_parser;
use super::import::import_parser;
use super::lexer::{filter_map_lex, Lexeme};
use super::Entry;
use crate::ast::{Clause, Constant, Expr, Rule};
use crate::enum_filter;
use crate::representations::location::Location;
use crate::representations::sourcefile::{FileEntry, Member, Namespace};
@@ -24,10 +24,10 @@ fn rule_parser<'a>(
.at_least(1)
.then(filter_map_lex(enum_filter!(Lexeme::Rule)))
.then(xpr_parser(ctx).repeated().at_least(1))
.map(|((s, (prio, _)), t)| Rule {
source: Rc::new(s),
.map(|((p, (prio, _)), t)| Rule {
pattern: Rc::new(p),
prio,
target: Rc::new(t),
template: Rc::new(t),
})
.labelled("Rule")
}