From 91f766c18ebd4da33cabf567256910717cf9574f Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Mon, 21 Oct 2024 15:11:08 +0200 Subject: [PATCH] pawarser: make raw_tokens vec owned in input --- crates/json-pawarser/src/grammar.rs | 2 +- crates/pawarser/src/parser.rs | 15 +++++++-------- crates/pawarser/src/parser/input.rs | 8 ++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/crates/json-pawarser/src/grammar.rs b/crates/json-pawarser/src/grammar.rs index 3ececd8..2f1745c 100644 --- a/crates/json-pawarser/src/grammar.rs +++ b/crates/json-pawarser/src/grammar.rs @@ -4,7 +4,7 @@ use crate::{syntax_error::SyntaxError, syntax_kind::SyntaxKind}; use self::object::object; -type Parser<'src, 'toks> = pawarser::Parser<'src, 'toks, SyntaxKind, SyntaxError>; +type Parser<'src> = pawarser::Parser<'src, SyntaxKind, SyntaxError>; type CompletedMarker = pawarser::CompletedMarker; const BASIC_VALUE_TOKENS: EnumSet = diff --git a/crates/pawarser/src/parser.rs b/crates/pawarser/src/parser.rs index 09b1bf4..91d44b8 100644 --- a/crates/pawarser/src/parser.rs +++ b/crates/pawarser/src/parser.rs @@ -21,8 +21,8 @@ where const ERROR: Self; } -pub struct Parser<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> { - input: Input<'src, 'toks, SyntaxKind>, +pub struct Parser<'src, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> { + input: Input<'src, SyntaxKind>, pos: usize, events: Vec>, step_limit: u32, @@ -30,7 +30,7 @@ pub struct Parser<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError } impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> - Parser<'src, 'toks, SyntaxKind, SyntaxErr> + Parser<'src, SyntaxKind, SyntaxErr> { /// eat all meaningless tokens at the end of the file. pub fn eat_succeeding_meaningless(&mut self) { @@ -97,17 +97,16 @@ impl<'src, 'toks, SyntaxKind: SyntaxElement, SyntaxErr: SyntaxError> pub struct ParserBuilder< 'src, - 'toks, SyntaxKind: SyntaxElement, // SyntaxErr: SyntaxError, > { - raw_toks: &'toks Vec<(SyntaxKind, &'src str)>, + raw_toks: Vec<(SyntaxKind, &'src str)>, meaningless_token_kinds: EnumSet, step_limit: u32, } -impl<'src, 'toks, SyntaxKind: SyntaxElement> ParserBuilder<'src, 'toks, SyntaxKind> { - pub fn new(raw_toks: &'toks Vec<(SyntaxKind, &'src str)>) -> Self { +impl<'src, SyntaxKind: SyntaxElement> ParserBuilder<'src, SyntaxKind> { + pub fn new(raw_toks: Vec<(SyntaxKind, &'src str)>) -> Self { Self { raw_toks, meaningless_token_kinds: EnumSet::new(), @@ -133,7 +132,7 @@ impl<'src, 'toks, SyntaxKind: SyntaxElement> ParserBuilder<'src, 'toks, SyntaxKi self } - pub fn build(self) -> Parser<'src, 'toks, SyntaxKind, SyntaxErr> { + pub fn build(self) -> Parser<'src, SyntaxKind, SyntaxErr> { let Self { raw_toks, meaningless_token_kinds, diff --git a/crates/pawarser/src/parser/input.rs b/crates/pawarser/src/parser/input.rs index ec2a243..0a5ff60 100644 --- a/crates/pawarser/src/parser/input.rs +++ b/crates/pawarser/src/parser/input.rs @@ -2,17 +2,17 @@ use enumset::{EnumSet, EnumSetType}; use super::SyntaxElement; -pub struct Input<'src, 'toks, SyntaxKind: SyntaxElement> { - raw: &'toks Vec<(SyntaxKind, &'src str)>, +pub struct Input<'src, SyntaxKind: SyntaxElement> { + raw: Vec<(SyntaxKind, &'src str)>, // enumset of meaningless tokens semantically_meaningless: EnumSet, // indices of non-meaningless tokens meaningful_toks: Vec, } -impl<'src, 'toks, SyntaxKind: SyntaxElement> Input<'src, 'toks, SyntaxKind> { +impl<'src, SyntaxKind: SyntaxElement> Input<'src, SyntaxKind> { pub fn new( - raw_toks: &'toks Vec<(SyntaxKind, &'src str)>, + raw_toks: Vec<(SyntaxKind, &'src str)>, meaningless: Option>, ) -> Self { let mut meaningful_toks = Vec::new();