diff --git a/Cargo.lock b/Cargo.lock index 7b1695a..d0ebf8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -132,10 +132,6 @@ dependencies = [ "logos-codegen", ] -[[package]] -name = "lopal" -version = "0.1.0" - [[package]] name = "lopal_core" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index e9300b4..810b8e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [workspace] members = [ - "crates/lopal", "crates/lopal_core", "crates/lopal_json" ] @@ -23,7 +22,7 @@ if_then_some_else_none = "warn" integer_division = "warn" let_underscore_must_use = "warn" manual_clamp = "warn" -pedantic = { level = "warn", priority = -1 } +pedantic = "warn" str_to_string = "warn" unneeded_field_pattern = "warn" unnested_or_patterns = "warn" @@ -32,8 +31,7 @@ allow_attributes_without_reason = "deny" cast_lossless = "deny" fallible_impl_from = "deny" unnecessary_cast = "deny" -# TODO: reenable -# unwrap_used = "deny" +unwrap_used = "deny" # allowed, since you can give reasons expect_used = "allow" diff --git a/crates/lopal/Cargo.toml b/crates/lopal/Cargo.toml deleted file mode 100644 index 6aa670f..0000000 --- a/crates/lopal/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "lopal" -version = "0.1.0" -edition = "2024" - -[dependencies] - -[lints] -workspace = true diff --git a/crates/lopal/README.md b/crates/lopal/README.md deleted file mode 100644 index 691a63b..0000000 --- a/crates/lopal/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# LOssless PArser Library - -Yeah :3 - -Reserved for the main crate, work is currently happening over in [lopal_core] diff --git a/crates/lopal/src/main.rs b/crates/lopal/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/crates/lopal/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/crates/lopal_core/README.md b/crates/lopal_core/README.md deleted file mode 100644 index 2e3cba3..0000000 --- a/crates/lopal_core/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# LoPaL Core - -Currently most development is happening here, until i get to a lot of rewriting and stuff. diff --git a/crates/lopal_core/src/GreenNodeBuilder; b/crates/lopal_core/src/GreenNodeBuilder; deleted file mode 100644 index 8b13789..0000000 --- a/crates/lopal_core/src/GreenNodeBuilder; +++ /dev/null @@ -1 +0,0 @@ - diff --git a/crates/lopal_core/src/lib.rs b/crates/lopal_core/src/lib.rs index 7ab35eb..26d8679 100644 --- a/crates/lopal_core/src/lib.rs +++ b/crates/lopal_core/src/lib.rs @@ -1,10 +1,4 @@ -//! Heavily in-dev parser library. -//! -//! Inspired by rust-analyzer. -//! -//! 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::{ diff --git a/crates/lopal_core/src/parser.rs b/crates/lopal_core/src/parser.rs index dd45dfe..c592cdb 100644 --- a/crates/lopal_core/src/parser.rs +++ b/crates/lopal_core/src/parser.rs @@ -1,7 +1,7 @@ use std::{cell::Cell, fmt, marker::PhantomData, mem}; use enumset::{EnumSet, EnumSetType}; -use rowan::GreenNodeBuilder; +use rowan::{GreenNode, GreenNodeBuilder}; use crate::parser::event::NodeKind; @@ -14,8 +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 -/// These should be different, idk what happens if they're the same. +/// this is used to define some required SyntaxKinds like an EOF token or an error token pub trait SyntaxElement where Self: EnumSetType @@ -33,10 +32,6 @@ where const SYNTAX_ROOT: Self; } -/// The core parser that you interact with. -/// Should be passed to all parser functions as first argument. -/// Currently very minimal/bare-bones. -/// See the [`lopal_json`](https://forge.katzen.cafe/schrottkatze/lopal/src/branch/main/crates/lopal_json) source code for reference. pub struct Parser<'src, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> { input: Input<'src, SyntaxKind>, pos: usize, @@ -45,7 +40,9 @@ pub struct Parser<'src, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> { steps: Cell, } -impl Parser<'_, SyntaxKind, SyntaxErr> { +impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> + Parser<'src, SyntaxKind, SyntaxErr> +{ /// eat all meaningless tokens at the end of the file. pub fn eat_succeeding_meaningless(&mut self) { self.push_ev(Event::Eat { @@ -110,7 +107,11 @@ impl Parser<'_, SyntaxKind, S pub fn finish(self) -> ParserOutput { let Self { - input, mut events, .. + input, + pos, + mut events, + step_limit, + steps, } = self; let (mut raw_toks, meaningless_tokens) = input.dissolve(); let mut builder = GreenNodeBuilder::new(); @@ -138,7 +139,7 @@ impl Parser<'_, SyntaxKind, S let mut idx = i; let mut fp = forward_parent; while let Some(fwd) = fp { - idx += fwd; + idx += fwd as usize; fp = match mem::replace(&mut events[idx], Event::tombstone()) { Event::Start { kind, @@ -173,9 +174,9 @@ impl Parser<'_, SyntaxKind, S 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 => {} + _ => {} } } } @@ -209,7 +210,6 @@ 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, @@ -220,19 +220,16 @@ 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) -> Self { self.meaningless_token_kinds .insert_all(kind.into_iter().collect()); diff --git a/crates/lopal_core/src/parser/error.rs b/crates/lopal_core/src/parser/error.rs index 65c383c..9c9d893 100644 --- a/crates/lopal_core/src/parser/error.rs +++ b/crates/lopal_core/src/parser/error.rs @@ -1,10 +1,7 @@ use std::fmt; /// A marker trait... for now! -/// -/// Marks a type as, well, an error type. -/// -/// TODO: constrain that conversion to `NodeKind::Error` is enforced to be possible +// TODO: constrain that conversion to `NodeKind::Error` is enforced to be possible pub trait SyntaxError where Self: fmt::Debug + Clone + PartialEq + Eq, diff --git a/crates/lopal_core/src/parser/event.rs b/crates/lopal_core/src/parser/event.rs index f33dede..1b71d8e 100644 --- a/crates/lopal_core/src/parser/event.rs +++ b/crates/lopal_core/src/parser/event.rs @@ -1,6 +1,8 @@ +use enumset::EnumSetType; + use super::{error::SyntaxError, SyntaxElement}; -pub(crate) enum Event { +pub enum Event { Start { kind: NodeKind, forward_parent: Option, @@ -21,7 +23,7 @@ impl Event { +pub enum NodeKind { Tombstone, Syntax(SyntaxKind), Error(SyntaxErr), diff --git a/crates/lopal_core/src/parser/input.rs b/crates/lopal_core/src/parser/input.rs index 549732e..d7e14b3 100644 --- a/crates/lopal_core/src/parser/input.rs +++ b/crates/lopal_core/src/parser/input.rs @@ -1,4 +1,4 @@ -use enumset::EnumSet; +use enumset::{EnumSet, EnumSetType}; 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 { - raw_toks + let meaningful_toks = raw_toks .iter() .enumerate() .filter_map(|(i, tok)| (!meaningless.contains(tok.0)).then_some(i)) diff --git a/crates/lopal_core/src/parser/marker.rs b/crates/lopal_core/src/parser/marker.rs index 95cad4e..2e1244d 100644 --- a/crates/lopal_core/src/parser/marker.rs +++ b/crates/lopal_core/src/parser/marker.rs @@ -1,4 +1,5 @@ use drop_bomb::DropBomb; +use rowan::SyntaxKind; use super::{ error::SyntaxError, @@ -86,7 +87,7 @@ impl CompletedMarker { // 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!(), } diff --git a/crates/lopal_core/src/parser/output.rs b/crates/lopal_core/src/parser/output.rs index de4eb66..76c3cf7 100644 --- a/crates/lopal_core/src/parser/output.rs +++ b/crates/lopal_core/src/parser/output.rs @@ -1,4 +1,4 @@ -use std::marker::PhantomData; +use std::{fmt, marker::PhantomData}; use rowan::{GreenNode, GreenNodeData, GreenTokenData, NodeOrToken}; @@ -41,14 +41,14 @@ fn debug_print_output( match node { NodeOrToken::Node(n) => { let kind: SyntaxKind = node.kind().into(); - if kind == SyntaxKind::SYNTAX_ERROR { + if kind != SyntaxKind::SYNTAX_ERROR { + write!(f, "{:?} {{{maybe_newline}", kind)?; + } else { let err = errs .pop() .expect("all error syntax nodes should correspond to an error"); - write!(f, "{kind:?}: {err:?} {{{maybe_newline}")?; - } else { - write!(f, "{kind:?} {{{maybe_newline}")?; + write!(f, "{:?}: {err:?} {{{maybe_newline}", kind)?; } for c in n.children() { debug_print_output::(c, f, lvl + 1, errs)?; diff --git a/crates/lopal_json/src/grammar.rs b/crates/lopal_json/src/grammar.rs index b8787e1..3011e03 100644 --- a/crates/lopal_json/src/grammar.rs +++ b/crates/lopal_json/src/grammar.rs @@ -1,7 +1,11 @@ use array::array; use enumset::{enum_set, EnumSet}; +use lopal_core::parser::ParserBuilder; -use crate::{syntax_error::SyntaxError, syntax_kind::SyntaxKind}; +use crate::{ + syntax_error::SyntaxError, + syntax_kind::{lex, SyntaxKind}, +}; use self::object::object; diff --git a/crates/lopal_json/src/syntax_kind.rs b/crates/lopal_json/src/syntax_kind.rs index b3184da..dda5b8d 100644 --- a/crates/lopal_json/src/syntax_kind.rs +++ b/crates/lopal_json/src/syntax_kind.rs @@ -14,7 +14,7 @@ pub fn lex(src: &str) -> Vec<(SyntaxKind, &str)> { #[derive(enumset::EnumSetType, Debug, Logos, PartialEq, Eq, Clone, Copy, Hash)] #[repr(u16)] #[enumset(no_super_impls)] -#[allow(non_camel_case_types, reason = "convention")] +#[allow(non_camel_case_types)] pub enum SyntaxKind { OBJECT, MEMBER, diff --git a/flake.nix b/flake.nix index eabfc74..1519a03 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,6 @@ { default = pkgs.mkShell rec { buildInputs = with pkgs; [ - cargo-watch toolchain ]; LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;