Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SKIP lexeme comments #27

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions parser/src/earley/lexerspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub struct LexemeSpec {
pub struct LexemeIdx(usize);

impl LexemeIdx {
// SKIP is a pseudo-lexeme, a "no-op" which it is sometimes
// convenient to insert in the lexeme stream. As the name
// suggests, it is skipped in parsing.
mmoskal marked this conversation as resolved.
Show resolved Hide resolved
// It is typically used for skipping whitespace.
pub const SKIP: LexemeIdx = LexemeIdx(0);

pub fn new(idx: usize) -> Self {
Expand Down
4 changes: 4 additions & 0 deletions parser/src/earley/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ impl ParserState {
} else {
self.stats.all_items += row_len;

// Always accept a SKIP lexeme
allowed_lexemes.set(LexemeIdx::SKIP.as_usize(), true);

if self.scratch.definitive {
Expand Down Expand Up @@ -1613,8 +1614,11 @@ impl ParserState {
};

let scan_res = if lexeme.idx == LexemeIdx::SKIP {
// If this is the SKIP lexeme, then skip it
self.scan_skip_lexeme(&lexeme)
} else {
// For all but the SKIP lexeme, process this lexeme
// with the parser
self.scan(&lexeme)
};

Expand Down
Loading