From 4d76551d6b11f1b7ce459bcfbd8850de5d45ac58 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 22 May 2024 17:06:09 -0500 Subject: [PATCH] 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. --- scripts/prettyasserts.py | 9 +++++---- tests/test_forphans.toml | 4 ++-- tests/test_wl.toml | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/prettyasserts.py b/scripts/prettyasserts.py index d1d193ad..3ea39100 100755 --- a/scripts/prettyasserts.py +++ b/scripts/prettyasserts.py @@ -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 diff --git a/tests/test_forphans.toml b/tests/test_forphans.toml index 6281777c..e1563c99 100644 --- a/tests/test_forphans.toml +++ b/tests/test_forphans.toml @@ -6085,7 +6085,7 @@ code = ''' } lfsr_file_write(&lfs, &sim_files[j]->file, wbuf, SIZE) => SIZE; lfsr_file_sync(&lfs, &sim_files[j]->file) - => ((!sim_files[j]->zombie) ? 0 : LFS_ERR_NOENT); + => (!sim_files[j]->zombie) ? 0 : LFS_ERR_NOENT; // close a file? } else if (op == 2) { @@ -6430,7 +6430,7 @@ code = ''' } lfsr_file_write(&lfs, &sim_files[j]->file, wbuf, SIZE) => SIZE; lfsr_file_sync(&lfs, &sim_files[j]->file) - => ((!sim_files[j]->zombie) ? 0 : LFS_ERR_NOENT); + => (!sim_files[j]->zombie) ? 0 : LFS_ERR_NOENT; // close a file? } else if (op == 2) { diff --git a/tests/test_wl.toml b/tests/test_wl.toml index 4c942b41..0e9ac9c6 100644 --- a/tests/test_wl.toml +++ b/tests/test_wl.toml @@ -513,7 +513,7 @@ code = ''' } lfsr_file_write(&lfs, &sim_files[j]->file, wbuf, SIZE) => SIZE; lfsr_file_sync(&lfs, &sim_files[j]->file) - => ((!sim_files[j]->zombie) ? 0 : LFS_ERR_NOENT); + => (!sim_files[j]->zombie) ? 0 : LFS_ERR_NOENT; // close a file? } else if (op == 2) { @@ -859,7 +859,7 @@ code = ''' } lfsr_file_write(&lfs, &sim_files[j]->file, wbuf, SIZE) => SIZE; lfsr_file_sync(&lfs, &sim_files[j]->file) - => ((!sim_files[j]->zombie) ? 0 : LFS_ERR_NOENT); + => (!sim_files[j]->zombie) ? 0 : LFS_ERR_NOENT; // close a file? } else if (op == 2) {