Skip to content

Commit e2e5c5b

Browse files
authored
Merge pull request #538 from ratmice/issue_473_empty_prec
Allow %empty followed by %prec
2 parents cc50d7f + ecb81c1 commit e2e5c5b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cfgrammar/src/lib/yacc/parser.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,8 @@ impl YaccParser {
867867
if !syms.is_empty()
868868
| !(self.lookahead_is("|", k).is_some()
869869
|| self.lookahead_is(";", k).is_some()
870-
|| self.lookahead_is("{", k).is_some())
870+
|| self.lookahead_is("{", k).is_some()
871+
|| self.lookahead_is("%prec", k).is_some())
871872
{
872873
return Err(self.mk_error(YaccGrammarErrorKind::NonEmptyProduction, i));
873874
}
@@ -1909,6 +1910,20 @@ x"
19091910
assert_eq!(grm.prods[grm.rules["expr"].pidxs[4]].precedence, Some("*".to_string()));
19101911
}
19111912

1913+
#[test]
1914+
fn test_prec_empty() {
1915+
let src = "
1916+
%%
1917+
expr : 'a'
1918+
| %empty %prec 'a';
1919+
";
1920+
let grm = parse(YaccKind::Original(YaccOriginalActionKind::NoAction), src).unwrap();
1921+
assert_eq!(
1922+
grm.prods[grm.rules["expr"].pidxs[1]].precedence,
1923+
Some("a".to_string())
1924+
);
1925+
}
1926+
19121927
#[test]
19131928
fn test_bad_prec_overrides() {
19141929
let src = "

0 commit comments

Comments
 (0)