Fixed parse errors in prettyasserts.py caused by ternary operators

Because of course ternary operators would cause problems.

The two problem:

  LFS_ASSERT((exists) ? !err : err == LFS_ERR_NOENT);
  lfsr_file_sync(&lfs, &file) => (zombie) ? 0 : LFS_ERR_NOENT;

We could work around these with parentheses, but with different assert
parsers floating around this issue is likely to crop up again in the
future.

Fortunately this just required separate "sep" vs "term" rules and a bit
more strict parsing.
This commit is contained in:
Christopher Haster
2024-05-22 17:06:09 -05:00
parent ba81a2bcc9
commit 4d76551d6b
3 changed files with 9 additions and 8 deletions
+5 -4
View File
@@ -35,7 +35,8 @@ LEXEMES = {
'paren': ['\(', '\)'],
'cmp': list(CMP.keys()),
'logic': ['\&\&', '\|\|'],
'sep': [':', ';', '\{', '\}', ','],
'sep': ['\?', ':', ','],
'term': [';', '\{', '\}'],
# specifically ops that conflict with cmp
'op': ['->', '>>', '<<'],
}
@@ -346,7 +347,7 @@ def p_expr(p):
res.append(p.m)
while True:
res.append(p_exprs(p))
if p.accept('sep'):
if p.accept('sep', 'term'):
res.append(p.m)
else:
break
@@ -374,7 +375,7 @@ def p_exprs(p):
res = []
while True:
res.append(p_expr(p))
if p.accept('cmp', 'logic', ','):
if p.accept('cmp', 'logic', 'sep'):
res.append(p.m)
else:
return ''.join(res)
@@ -479,7 +480,7 @@ def main(input=None, output=None, *,
try:
while True:
f.write(p_stmt(p))
if p.accept('sep'):
if p.accept('term'):
f.write(p.m)
else:
break