fix some clippy stuff
This commit is contained in:
parent
fdfff2c33a
commit
a56df7c41c
10 changed files with 26 additions and 32 deletions
1
crates/lopal_core/src/GreenNodeBuilder;
Normal file
1
crates/lopal_core/src/GreenNodeBuilder;
Normal file
|
@ -0,0 +1 @@
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
//!
|
||||
//! See [_Modern Parser Generator_](https://matklad.github.io/2018/06/06/modern-parser-generator.html) by Matklad
|
||||
#![feature(iter_collect_into)]
|
||||
#![allow(dead_code, reason = "This is an unfinished library.")]
|
||||
pub mod parser;
|
||||
|
||||
pub use parser::{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{cell::Cell, fmt, marker::PhantomData, mem};
|
||||
|
||||
use enumset::{EnumSet, EnumSetType};
|
||||
use rowan::{GreenNode, GreenNodeBuilder};
|
||||
use rowan::GreenNodeBuilder;
|
||||
|
||||
use crate::parser::event::NodeKind;
|
||||
|
||||
|
@ -14,7 +14,7 @@ mod input;
|
|||
pub mod marker;
|
||||
pub mod output;
|
||||
|
||||
/// this is used to define some required SyntaxKinds like an EOF token or an error token
|
||||
/// this is used to define some required `SyntaxKinds` like an EOF token or an error token
|
||||
/// These should be different, idk what happens if they're the same.
|
||||
pub trait SyntaxElement
|
||||
where
|
||||
|
@ -45,9 +45,7 @@ pub struct Parser<'src, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> {
|
|||
steps: Cell<u32>,
|
||||
}
|
||||
|
||||
impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError>
|
||||
Parser<'src, SyntaxKind, SyntaxErr>
|
||||
{
|
||||
impl<SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> Parser<'_, SyntaxKind, SyntaxErr> {
|
||||
/// eat all meaningless tokens at the end of the file.
|
||||
pub fn eat_succeeding_meaningless(&mut self) {
|
||||
self.push_ev(Event::Eat {
|
||||
|
@ -112,11 +110,7 @@ impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError>
|
|||
|
||||
pub fn finish(self) -> ParserOutput<SyntaxKind, SyntaxErr> {
|
||||
let Self {
|
||||
input,
|
||||
pos,
|
||||
mut events,
|
||||
step_limit,
|
||||
steps,
|
||||
input, mut events, ..
|
||||
} = self;
|
||||
let (mut raw_toks, meaningless_tokens) = input.dissolve();
|
||||
let mut builder = GreenNodeBuilder::new();
|
||||
|
@ -144,7 +138,7 @@ impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError>
|
|||
let mut idx = i;
|
||||
let mut fp = forward_parent;
|
||||
while let Some(fwd) = fp {
|
||||
idx += fwd as usize;
|
||||
idx += fwd;
|
||||
fp = match mem::replace(&mut events[idx], Event::tombstone()) {
|
||||
Event::Start {
|
||||
kind,
|
||||
|
@ -179,9 +173,9 @@ impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError>
|
|||
NodeKind::Syntax(kind) => builder.start_node(kind.into()),
|
||||
NodeKind::Error(err) => {
|
||||
errors.push(err);
|
||||
builder.start_node(SyntaxKind::SYNTAX_ERROR.into())
|
||||
builder.start_node(SyntaxKind::SYNTAX_ERROR.into());
|
||||
}
|
||||
_ => {}
|
||||
NodeKind::Tombstone => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,6 +209,7 @@ pub struct ParserBuilder<
|
|||
}
|
||||
|
||||
impl<'src, SyntaxKind: SyntaxElement> ParserBuilder<'src, SyntaxKind> {
|
||||
#[must_use]
|
||||
pub fn new(raw_toks: Vec<(SyntaxKind, &'src str)>) -> Self {
|
||||
Self {
|
||||
raw_toks,
|
||||
|
@ -225,16 +220,19 @@ impl<'src, SyntaxKind: SyntaxElement> ParserBuilder<'src, SyntaxKind> {
|
|||
|
||||
/// Sets the parser step limit.
|
||||
/// Defaults to 4096
|
||||
#[must_use]
|
||||
pub fn step_limit(mut self, new: u32) -> Self {
|
||||
self.step_limit = new;
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn add_meaningless(mut self, kind: SyntaxKind) -> Self {
|
||||
self.meaningless_token_kinds.insert(kind);
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn add_meaningless_many(mut self, kind: Vec<SyntaxKind>) -> Self {
|
||||
self.meaningless_token_kinds
|
||||
.insert_all(kind.into_iter().collect());
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use enumset::EnumSetType;
|
||||
|
||||
use super::{error::SyntaxError, SyntaxElement};
|
||||
|
||||
pub(crate) enum Event<SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use enumset::{EnumSet, EnumSetType};
|
||||
use enumset::EnumSet;
|
||||
|
||||
use super::SyntaxElement;
|
||||
|
||||
|
@ -18,7 +18,7 @@ impl<'src, SyntaxKind: SyntaxElement> Input<'src, SyntaxKind> {
|
|||
let mut meaningful_toks = Vec::new();
|
||||
|
||||
if let Some(meaningless) = meaningless {
|
||||
let meaningful_toks = raw_toks
|
||||
raw_toks
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, tok)| (!meaningless.contains(tok.0)).then_some(i))
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use drop_bomb::DropBomb;
|
||||
use rowan::SyntaxKind;
|
||||
|
||||
use super::{
|
||||
error::SyntaxError,
|
||||
|
@ -87,7 +86,7 @@ impl<SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> CompletedMarker<SyntaxKi
|
|||
Event::Start { forward_parent, .. } => {
|
||||
// point forward parent of the node this marker completed to the new node
|
||||
// will later be used to make the new node a parent of the current node.
|
||||
*forward_parent = Some(new_pos.pos - self.pos)
|
||||
*forward_parent = Some(new_pos.pos - self.pos);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{fmt, marker::PhantomData};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use rowan::{GreenNode, GreenNodeData, GreenTokenData, NodeOrToken};
|
||||
|
||||
|
@ -41,14 +41,14 @@ fn debug_print_output<SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError>(
|
|||
match node {
|
||||
NodeOrToken::Node(n) => {
|
||||
let kind: SyntaxKind = node.kind().into();
|
||||
if kind != SyntaxKind::SYNTAX_ERROR {
|
||||
write!(f, "{:?} {{{maybe_newline}", kind)?;
|
||||
} else {
|
||||
if kind == SyntaxKind::SYNTAX_ERROR {
|
||||
let err = errs
|
||||
.pop()
|
||||
.expect("all error syntax nodes should correspond to an error");
|
||||
|
||||
write!(f, "{:?}: {err:?} {{{maybe_newline}", kind)?;
|
||||
write!(f, "{kind:?}: {err:?} {{{maybe_newline}")?;
|
||||
} else {
|
||||
write!(f, "{kind:?} {{{maybe_newline}")?;
|
||||
}
|
||||
for c in n.children() {
|
||||
debug_print_output::<SyntaxKind, SyntaxErr>(c, f, lvl + 1, errs)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue