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

Allow %prec to define a token in the grammar. #453

Merged
merged 1 commit into from
May 15, 2024
Merged
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
20 changes: 4 additions & 16 deletions cfgrammar/src/lib/yacc/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,11 @@ impl YaccParser {
syms.push(Symbol::Token(sym, span));
} else if let Some(j) = self.lookahead_is("%prec", i) {
i = self.parse_ws(j, true)?;
let (k, sym, _) = self.parse_token(i)?;
if self.ast.tokens.contains(&sym) {
prec = Some(sym);
} else {
return Err(self.mk_error(YaccGrammarErrorKind::PrecNotFollowedByToken, i));
let (k, sym, span) = self.parse_token(i)?;
if self.ast.tokens.insert(sym.clone()) {
self.ast.spans.push(span);
}
prec = Some(sym);
i = k;
} else if self.lookahead_is("{", i).is_some() {
let (j, a) = self.parse_action(i)?;
Expand Down Expand Up @@ -1736,17 +1735,6 @@ x"
src,
)
.expect_error_at_line(src, YaccGrammarErrorKind::IllegalString, 3);

let src = "
%%
S: 'A' %prec B;
B: ;
";
parse(
YaccKind::Original(YaccOriginalActionKind::GenericParseTree),
src,
)
.expect_error_at_line(src, YaccGrammarErrorKind::PrecNotFollowedByToken, 3);
}

#[test]
Expand Down