mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2025-09-24 23:41:30 +02:00
pawarser(chore): split up files
This commit is contained in:
parent
ec2ff5778b
commit
34ddaacb58
5 changed files with 161 additions and 165 deletions
78
crates/pawarser/src/parser.rs
Normal file
78
crates/pawarser/src/parser.rs
Normal file
|
@ -0,0 +1,78 @@
|
|||
use std::cell::Cell;
|
||||
|
||||
use enumset::{EnumSet, EnumSetType};
|
||||
|
||||
use self::{error::SyntaxError, event::Event, input::Input};
|
||||
|
||||
mod error;
|
||||
mod event;
|
||||
pub mod input;
|
||||
|
||||
pub struct Parser<
|
||||
'src,
|
||||
'toks,
|
||||
SyntaxKind: EnumSetType + Into<rowan::SyntaxKind>,
|
||||
SyntaxErr: SyntaxError,
|
||||
> {
|
||||
input: Input<'src, 'toks, SyntaxKind>,
|
||||
pos: usize,
|
||||
events: Vec<Event<SyntaxKind, SyntaxErr>>,
|
||||
step_limit: u32,
|
||||
steps: Cell<u32>,
|
||||
}
|
||||
|
||||
pub struct ParserBuilder<
|
||||
'src,
|
||||
'toks,
|
||||
SyntaxKind: EnumSetType + Into<rowan::SyntaxKind>,
|
||||
// SyntaxErr: SyntaxError,
|
||||
> {
|
||||
raw_toks: &'toks Vec<(SyntaxKind, &'src str)>,
|
||||
meaningless_token_kinds: EnumSet<SyntaxKind>,
|
||||
step_limit: u32,
|
||||
}
|
||||
|
||||
impl<'src, 'toks, SyntaxKind: EnumSetType + Into<rowan::SyntaxKind>>
|
||||
ParserBuilder<'src, 'toks, SyntaxKind>
|
||||
{
|
||||
pub fn new(raw_toks: &'toks Vec<(SyntaxKind, &'src str)>) -> Self {
|
||||
Self {
|
||||
raw_toks,
|
||||
meaningless_token_kinds: EnumSet::new(),
|
||||
step_limit: 4096,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the parser step limit.
|
||||
/// Defaults to 4096
|
||||
pub fn step_limit(mut self, new: u32) -> Self {
|
||||
self.step_limit = new;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_meaningless(mut self, kind: SyntaxKind) -> Self {
|
||||
self.meaningless_token_kinds.insert(kind);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_meaningless_many(mut self, kind: Vec<SyntaxKind>) -> Self {
|
||||
self.meaningless_token_kinds
|
||||
.insert_all(kind.into_iter().collect());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build<SyntaxErr: SyntaxError>(self) -> Parser<'src, 'toks, SyntaxKind, SyntaxErr> {
|
||||
let Self {
|
||||
raw_toks,
|
||||
meaningless_token_kinds,
|
||||
step_limit,
|
||||
} = self;
|
||||
Parser {
|
||||
input: Input::new(raw_toks, Some(meaningless_token_kinds)),
|
||||
pos: 0,
|
||||
events: Vec::new(),
|
||||
step_limit,
|
||||
steps: Cell::new(0),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue