Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 392538c

Browse files
UrhengulasVeykril
authored andcommitted
Add edition to parser struct
1 parent f3c7bd0 commit 392538c

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

crates/parser/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub use crate::{
4545
input::Input,
4646
lexed_str::LexedStr,
4747
output::{Output, Step},
48+
parser::Edition,
4849
shortcuts::StrStep,
4950
syntax_kind::SyntaxKind,
5051
};
@@ -98,7 +99,7 @@ impl TopEntryPoint {
9899
TopEntryPoint::MetaItem => grammar::entry::top::meta_item,
99100
TopEntryPoint::MacroEagerInput => grammar::entry::top::eager_macro_input,
100101
};
101-
let mut p = parser::Parser::new(input);
102+
let mut p = parser::Parser::new(input, Edition::Edition2021);
102103
entry_point(&mut p);
103104
let events = p.finish();
104105
let res = event::process(events);
@@ -163,7 +164,7 @@ impl PrefixEntryPoint {
163164
PrefixEntryPoint::Item => grammar::entry::prefix::item,
164165
PrefixEntryPoint::MetaItem => grammar::entry::prefix::meta_item,
165166
};
166-
let mut p = parser::Parser::new(input);
167+
let mut p = parser::Parser::new(input, Edition::Edition2021);
167168
entry_point(&mut p);
168169
let events = p.finish();
169170
event::process(events)
@@ -189,7 +190,7 @@ impl Reparser {
189190
/// sequence.
190191
pub fn parse(self, tokens: &Input) -> Output {
191192
let Reparser(r) = self;
192-
let mut p = parser::Parser::new(tokens);
193+
let mut p = parser::Parser::new(tokens, Edition::Edition2021);
193194
r(&mut p);
194195
let events = p.finish();
195196
event::process(events)

crates/parser/src/parser.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,27 @@ pub(crate) struct Parser<'t> {
2626
pos: usize,
2727
events: Vec<Event>,
2828
steps: Cell<u32>,
29+
edition: Edition,
30+
}
31+
32+
#[non_exhaustive]
33+
pub enum Edition {
34+
Edition2015,
35+
Edition2018,
36+
Edition2021,
2937
}
3038

3139
static PARSER_STEP_LIMIT: Limit = Limit::new(15_000_000);
3240

3341
impl<'t> Parser<'t> {
34-
pub(super) fn new(inp: &'t Input) -> Parser<'t> {
35-
Parser { inp, pos: 0, events: Vec::new(), steps: Cell::new(0) }
42+
pub(super) fn new(inp: &'t Input, edition: Edition) -> Parser<'t> {
43+
Parser {
44+
inp,
45+
pos: 0,
46+
events: Vec::new(),
47+
steps: Cell::new(0),
48+
edition,
49+
}
3650
}
3751

3852
pub(crate) fn finish(self) -> Vec<Event> {

0 commit comments

Comments
 (0)