Skip to content
Open
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
13 changes: 12 additions & 1 deletion lrlex/src/lib/ctbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ where
);
}

let (missing_from_lexer, missing_from_parser) = match self.rule_ids_map {
let (mut missing_from_lexer, missing_from_parser) = match self.rule_ids_map {
Some(ref rim) => {
// Convert from HashMap<String, _> to HashMap<&str, _>
let owned_map = rim
Expand All @@ -660,6 +660,17 @@ where
None => (None, None),
};

if let Some(mut mfl) = missing_from_lexer.take() {
for tok in &lexerdef.expected_missing_tokens {
mfl.remove(tok.as_str());
}
if mfl.is_empty() {
missing_from_lexer = None;
} else {
missing_from_lexer = Some(mfl);
}
}

let mut has_unallowed_missing = false;
let err_indent = " ".repeat(ERROR.len());
if !self.allow_missing_terms_in_lexer
Expand Down
4 changes: 4 additions & 0 deletions lrlex/src/lib/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ where
rules: Vec<Rule<LexerTypesT::StorageT>>,
start_states: Vec<StartState>,
lex_flags: LexFlags,
pub(crate) expected_missing_tokens: Vec<String>,
phantom: PhantomData<LexerTypesT>,
}

Expand All @@ -414,6 +415,7 @@ where
rules,
start_states,
lex_flags: DEFAULT_LEX_FLAGS,
expected_missing_tokens: vec![],
phantom: PhantomData,
}
}
Expand All @@ -430,6 +432,7 @@ where
rules: p.rules,
start_states: p.start_states,
lex_flags: flags,
expected_missing_tokens: p.expected_missing_tokens,
phantom: PhantomData,
}
})
Expand Down Expand Up @@ -547,6 +550,7 @@ where
rules: p.rules,
start_states: p.start_states,
lex_flags,
expected_missing_tokens: p.expected_missing_tokens,
phantom: PhantomData,
},
)
Expand Down
12 changes: 12 additions & 0 deletions lrlex/src/lib/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ where
pub(super) rules: Vec<Rule<LexerTypesT::StorageT>>,
pub(super) start_states: Vec<StartState>,
pub(super) lex_flags: LexFlags,
pub(super) expected_missing_tokens: Vec<String>,
}

fn add_duplicate_occurrence(
Expand Down Expand Up @@ -189,6 +190,7 @@ where
false,
Span::new(0, 0),
)],
expected_missing_tokens: vec![],
};
p.parse()?;
Ok(p)
Expand Down Expand Up @@ -293,6 +295,16 @@ where
self.declare_start_states(false, i, declaration_len, line_len, errs)
} else if RE_EXCLUSIVE_START_STATE_DECLARATION.is_match(declaration) {
self.declare_start_states(true, i, declaration_len, line_len, errs)
} else if declaration.starts_with("%expect-missing") {
for tok in self.src[i + declaration_len..i + line_len].split_ascii_whitespace() {
let tok_unquoted = tok.strip_prefix("\"").and_then(|s| s.strip_suffix("\""));
if let Some(tok_unquoted) = tok_unquoted {
self.expected_missing_tokens.push(tok_unquoted.to_string());
} else {
Err(self.mk_error(LexErrorKind::InvalidName, i))?;
}
}
Ok(i + line_len)
} else {
Err(self.mk_error(LexErrorKind::UnknownDeclaration, i))
}
Expand Down
16 changes: 16 additions & 0 deletions lrpar/cttests/src/expect_missing_tokens.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test the %expect-missing lex directive
yacckind: Original(YaccOriginalActionKind::NoAction)
grammar: |
%start meta_start
%token START_A START_B
%%

meta_start: START_A arule | START_B brule;
arule: 'A';
brule: 'B';
%%
lexer: |
%expect-missing "START_A" "START_B"
%%
aA "A"
bB "B"