From 4f632684a9a3e0d69502fedbc0fcecb12f3e3ff3 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 8 Apr 2024 11:25:05 +0100 Subject: [PATCH 01/12] Make warning more helpful. --- testsuite/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/CMakeLists.txt b/testsuite/CMakeLists.txt index 12489d6a3..dd4eb804c 100644 --- a/testsuite/CMakeLists.txt +++ b/testsuite/CMakeLists.txt @@ -91,7 +91,7 @@ foreach(TOOL ${TOOL_FOLDERS}) # Check if there are any files to compare for this test. list(LENGTH results res_length) if(res_length EQUAL 0) - message(WARNING "Test does not have results directory: ${golden_dir}") + message(WARNING "Test does not have results directory: ${golden_dir}\nRun `update-dump` to generate golden files.") # Add to generate golden output target add_custom_command(OUTPUT ${test_path} COMMAND From ac890f2d156f59cc0b490e8f80e6b47e0a5f9e83 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 8 Apr 2024 11:25:37 +0100 Subject: [PATCH 02/12] Add a broken nesting example --- .../verona_nostdlib/spec/comments_broken_nest.verona | 1 + .../spec/comments_broken_nest_out/00_parse.trieste | 9 +++++++++ .../verona_nostdlib/spec/comments_broken_nest_out/ast | 9 +++++++++ .../spec/comments_broken_nest_out/exit_code.txt | 1 + .../spec/comments_broken_nest_out/stderr.txt | 0 .../spec/comments_broken_nest_out/stdout.txt | 6 ++++++ 6 files changed, 26 insertions(+) create mode 100644 testsuite/verona_nostdlib/spec/comments_broken_nest.verona create mode 100644 testsuite/verona_nostdlib/spec/comments_broken_nest_out/00_parse.trieste create mode 100644 testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast create mode 100644 testsuite/verona_nostdlib/spec/comments_broken_nest_out/exit_code.txt create mode 100644 testsuite/verona_nostdlib/spec/comments_broken_nest_out/stderr.txt create mode 100644 testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest.verona b/testsuite/verona_nostdlib/spec/comments_broken_nest.verona new file mode 100644 index 000000000..e20d11235 --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest.verona @@ -0,0 +1 @@ +/* Nested comments /* like this work */ \ No newline at end of file diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/00_parse.trieste b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/00_parse.trieste new file mode 100644 index 000000000..75e598921 --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/00_parse.trieste @@ -0,0 +1,9 @@ +Verona +parse +(top + {} + (file + (group + (error + (errormsg 35:unterminated comment at end of file) + (errorast))))) diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast new file mode 100644 index 000000000..8232b1e77 --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast @@ -0,0 +1,9 @@ +Verona +defaultargs +(top + {} + (file + (group + (error + (errormsg 35:unterminated comment at end of file) + (errorast))))) diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/exit_code.txt b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/exit_code.txt new file mode 100644 index 000000000..b8e817d4f --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/exit_code.txt @@ -0,0 +1 @@ +255 \ No newline at end of file diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stderr.txt b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stderr.txt new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt new file mode 100644 index 000000000..60014f301 --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt @@ -0,0 +1,6 @@ +Errors: +unterminated comment at end of file/home/mjp41/verona/testsuite/verona_nostdlib/spec/comments_broken_nest.verona:1:38 +/* Nested comments /* like this work */ + ~~ +Pass parse failed with 1 errors + From eb7d482508d1d8cda95627d639be7fb7920b3b75 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 8 Apr 2024 11:29:28 +0100 Subject: [PATCH 03/12] Add some comment examples --- .../verona_nostdlib/spec/comments.verona | 28 ++++++++++++++++ .../spec/comments_out/00_parse.trieste | 33 +++++++++++++++++++ .../spec/comments_out/exit_code.txt | 1 + .../spec/comments_out/stderr.txt | 0 .../spec/comments_out/stdout.txt | 0 5 files changed, 62 insertions(+) create mode 100644 testsuite/verona_nostdlib/spec/comments.verona create mode 100644 testsuite/verona_nostdlib/spec/comments_out/00_parse.trieste create mode 100644 testsuite/verona_nostdlib/spec/comments_out/exit_code.txt create mode 100644 testsuite/verona_nostdlib/spec/comments_out/stderr.txt create mode 100644 testsuite/verona_nostdlib/spec/comments_out/stdout.txt diff --git a/testsuite/verona_nostdlib/spec/comments.verona b/testsuite/verona_nostdlib/spec/comments.verona new file mode 100644 index 000000000..4fdf90a83 --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments.verona @@ -0,0 +1,28 @@ +// Comment +class A { + /* comment + class B { + // comment + } + */ +} + +class B { + // Comment +} + +// /* comment opening inside comment ignored + +/* // line comment inside comment ignored */ + +let a = "// not a comment!" + +let b = "/* not a comment start" + +let c = "not a comment end */" + +/* Nested comments /* like this work */ as you would expect.*/ + +/* Quotes don't affect the nesting. "/*" */ */ + +// \ No newline at end of file diff --git a/testsuite/verona_nostdlib/spec/comments_out/00_parse.trieste b/testsuite/verona_nostdlib/spec/comments_out/00_parse.trieste new file mode 100644 index 000000000..04f4e60a5 --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments_out/00_parse.trieste @@ -0,0 +1,33 @@ +Verona +parse +(top + {} + (file + (group + (class + {}) + (ident 1:A) + (brace)) + (group + (class + {}) + (ident 1:B) + (brace)) + (equals + (group + (let) + (ident 1:a)) + (group + (escaped 17:// not a comment!))) + (equals + (group + (let) + (ident 1:b)) + (group + (escaped 22:/* not a comment start))) + (equals + (group + (let) + (ident 1:c)) + (group + (escaped 20:not a comment end */))))) diff --git a/testsuite/verona_nostdlib/spec/comments_out/exit_code.txt b/testsuite/verona_nostdlib/spec/comments_out/exit_code.txt new file mode 100644 index 000000000..c22708346 --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments_out/exit_code.txt @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/testsuite/verona_nostdlib/spec/comments_out/stderr.txt b/testsuite/verona_nostdlib/spec/comments_out/stderr.txt new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/verona_nostdlib/spec/comments_out/stdout.txt b/testsuite/verona_nostdlib/spec/comments_out/stdout.txt new file mode 100644 index 000000000..e69de29bb From 207756d4c88f82c5021fe2861bc084c60e968dd9 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 8 Apr 2024 13:36:45 +0100 Subject: [PATCH 04/12] Multi-line comments should be RE2 `.` does not match newlines by default. This allows newlines inside multi-line comments. --- src/parse.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/parse.cc b/src/parse.cc index d0a0e32c1..393e23bf5 100644 --- a/src/parse.cc +++ b/src/parse.cc @@ -221,6 +221,7 @@ namespace verona // Nested comment. "/\\*" >> [depth](auto& m) { + assert(*depth == 0); ++(*depth); m.mode("comment"); }, @@ -329,6 +330,8 @@ namespace verona }, "." >> [](auto&) {}, + + "\r?\n" >> [](auto&) {}, }); p.done([](auto& m) { From 5476bea8afe63f0296c2bb95d9800ef7eef5239d Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 8 Apr 2024 13:49:15 +0100 Subject: [PATCH 05/12] Update test --- .../verona_nostdlib/spec/comments.verona | 38 ++++++++++++------- .../spec/comments_out/00_parse.trieste | 10 ----- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/testsuite/verona_nostdlib/spec/comments.verona b/testsuite/verona_nostdlib/spec/comments.verona index 4fdf90a83..914fba31e 100644 --- a/testsuite/verona_nostdlib/spec/comments.verona +++ b/testsuite/verona_nostdlib/spec/comments.verona @@ -1,28 +1,38 @@ // Comment -class A { - /* comment - class B { - // comment - } - */ -} -class B { - // Comment -} +// Comment /* with nested comment */ -// /* comment opening inside comment ignored +// Comment with "quotes" + +// Comment with "quotes /* and nested comment */" + +// Comment with "quotes /* and nested comment */" and more text + +/* Single-line comment */ +/**/ +/* Single-line comment with /*Nested comment*/ */ + +/* Multi-line + comment */ +/* + +*/ +/* Multi-line + comment /* with nested comment */ +*/ + + +// /* Comment opening inside comment ignored /* // line comment inside comment ignored */ +// Interaction with strings: let a = "// not a comment!" let b = "/* not a comment start" let c = "not a comment end */" -/* Nested comments /* like this work */ as you would expect.*/ - /* Quotes don't affect the nesting. "/*" */ */ -// \ No newline at end of file +// Comment doesn't need a new line to terminate it \ No newline at end of file diff --git a/testsuite/verona_nostdlib/spec/comments_out/00_parse.trieste b/testsuite/verona_nostdlib/spec/comments_out/00_parse.trieste index 04f4e60a5..2c099537a 100644 --- a/testsuite/verona_nostdlib/spec/comments_out/00_parse.trieste +++ b/testsuite/verona_nostdlib/spec/comments_out/00_parse.trieste @@ -3,16 +3,6 @@ parse (top {} (file - (group - (class - {}) - (ident 1:A) - (brace)) - (group - (class - {}) - (ident 1:B) - (brace)) (equals (group (let) From 9ddd28ed0f7bf2d826d0eb1959fb078001c0977e Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 8 Apr 2024 14:00:43 +0100 Subject: [PATCH 06/12] Try to fix FetchContent. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89770b285..985a2df53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ FetchContent_Declare( trieste GIT_REPOSITORY https://github.com/microsoft/trieste GIT_TAG fac9e4c84de192ee53051be32c5426256cd1086e - GIT_SHALLOW TRUE + GIT_SHALLOW FALSE ) FetchContent_MakeAvailable(trieste) From 63990b28a2a3a31240bc5f7d0723d49087f97d21 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 8 Apr 2024 14:15:06 +0100 Subject: [PATCH 07/12] Make error message handle unterminated strings. --- src/parse.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/parse.cc b/src/parse.cc index 393e23bf5..5dc5b260f 100644 --- a/src/parse.cc +++ b/src/parse.cc @@ -335,9 +335,12 @@ namespace verona }); p.done([](auto& m) { - if (m.mode() != "start") + if (m.mode() == "comment") m.error("unterminated comment at end of file"); + if (m.mode() == "string") + m.error("unterminated string at end of file"); + m.term(terminators); }); From 5e5a1b0df3a9d465a6c8d63f11fe414dfc7c1a35 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 11 Apr 2024 11:16:41 +0100 Subject: [PATCH 08/12] Pulled in latest Trieste This pull in various fixes to Trieste that Verona needed from a recent refactor. These also help with printing error messages more nicely. --- CMakeLists.txt | 2 +- src/parse.cc | 15 +++++++++------ .../comments_broken_nest_out/00_parse.trieste | 2 +- .../spec/comments_broken_nest_out/ast | 9 --------- .../spec/comments_broken_nest_out/exit_code.txt | 2 +- .../spec/comments_broken_nest_out/stdout.txt | 6 ++++-- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 985a2df53..28d5ea5ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ set(TRIESTE_BUILD_SAMPLES OFF) FetchContent_Declare( trieste GIT_REPOSITORY https://github.com/microsoft/trieste - GIT_TAG fac9e4c84de192ee53051be32c5426256cd1086e + GIT_TAG 61678d80ffd239e23338ef9d002f2eef9badce67 GIT_SHALLOW FALSE ) diff --git a/src/parse.cc b/src/parse.cc index 5dc5b260f..f0abc7c2c 100644 --- a/src/parse.cc +++ b/src/parse.cc @@ -49,6 +49,7 @@ namespace verona auto depth = std::make_shared(0); auto str = std::make_shared(); auto indent = std::make_shared>(); + auto start_location = std::make_shared(); indent->push_back(restart); p.prefile([](auto&, auto& path) { return path.extension() == ".verona"; }); @@ -202,10 +203,11 @@ namespace verona // Unescaped string. "([']+)\"([^\"]*)" >> - [str](auto& m) { + [str, start_location](auto& m) { str->start = m.match(1).len; str->end = 0; m.add(String, 2); + *start_location = m.match(1); m.mode("string"); }, @@ -220,9 +222,10 @@ namespace verona // Nested comment. "/\\*" >> - [depth](auto& m) { + [depth, start_location](auto& m) { assert(*depth == 0); ++(*depth); + *start_location = m.match(); m.mode("comment"); }, @@ -334,12 +337,12 @@ namespace verona "\r?\n" >> [](auto&) {}, }); - p.done([](auto& m) { + p.done([start_location](auto& m) { if (m.mode() == "comment") - m.error("unterminated comment at end of file"); - + m.error("Unterminated comment starting at ", *start_location); + if (m.mode() == "string") - m.error("unterminated string at end of file"); + m.error("Unterminated string starting at ", *start_location); m.term(terminators); }); diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/00_parse.trieste b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/00_parse.trieste index 75e598921..54dffdf9d 100644 --- a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/00_parse.trieste +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/00_parse.trieste @@ -5,5 +5,5 @@ parse (file (group (error - (errormsg 35:unterminated comment at end of file) + (errormsg 33:Unterminated comment starting at ) (errorast))))) diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast index 8232b1e77..e69de29bb 100644 --- a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast @@ -1,9 +0,0 @@ -Verona -defaultargs -(top - {} - (file - (group - (error - (errormsg 35:unterminated comment at end of file) - (errorast))))) diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/exit_code.txt b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/exit_code.txt index b8e817d4f..56a6051ca 100644 --- a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/exit_code.txt +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/exit_code.txt @@ -1 +1 @@ -255 \ No newline at end of file +1 \ No newline at end of file diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt index 60014f301..1ed9618da 100644 --- a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt @@ -1,6 +1,8 @@ Errors: -unterminated comment at end of file/home/mjp41/verona/testsuite/verona_nostdlib/spec/comments_broken_nest.verona:1:38 +Unterminated comment starting at +-- comments_broken_nest.verona:1:1 /* Nested comments /* like this work */ - ~~ +~~ + Pass parse failed with 1 errors From 8a5fdcf62dd2c6c29c1b14805125f04195bd5aaf Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 11 Apr 2024 13:22:38 +0100 Subject: [PATCH 09/12] Small fixes. --- CMakeLists.txt | 2 +- .../verona_nostdlib/spec/comments_broken_nest_out/ast | 9 +++++++++ .../spec/comments_broken_nest_out/stdout.txt | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 28d5ea5ca..85e001fec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ set(TRIESTE_BUILD_SAMPLES OFF) FetchContent_Declare( trieste GIT_REPOSITORY https://github.com/microsoft/trieste - GIT_TAG 61678d80ffd239e23338ef9d002f2eef9badce67 + GIT_TAG 1e1448ca9e4ac158492bf8dbbd86b407c452fc0c GIT_SHALLOW FALSE ) diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast index e69de29bb..54dffdf9d 100644 --- a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/ast @@ -0,0 +1,9 @@ +Verona +parse +(top + {} + (file + (group + (error + (errormsg 33:Unterminated comment starting at ) + (errorast))))) diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt index 1ed9618da..f7c0ec119 100644 --- a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt @@ -4,5 +4,5 @@ Unterminated comment starting at /* Nested comments /* like this work */ ~~ -Pass parse failed with 1 errors +Pass parse failed with 1 error! From 2ff79bd6664c88ac5267bcd59758b1d6caedabb6 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 11 Apr 2024 13:24:09 +0100 Subject: [PATCH 10/12] Clangformat --- src/parse.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse.cc b/src/parse.cc index f0abc7c2c..48bf77741 100644 --- a/src/parse.cc +++ b/src/parse.cc @@ -340,7 +340,7 @@ namespace verona p.done([start_location](auto& m) { if (m.mode() == "comment") m.error("Unterminated comment starting at ", *start_location); - + if (m.mode() == "string") m.error("Unterminated string starting at ", *start_location); From d526a2424331c85ad927c74b3a77ff7f991914d0 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 11 Apr 2024 13:33:27 +0100 Subject: [PATCH 11/12] Improve comment parsing --- src/parse.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/parse.cc b/src/parse.cc index 48bf77741..4d3fe880e 100644 --- a/src/parse.cc +++ b/src/parse.cc @@ -324,6 +324,7 @@ namespace verona p("comment", { + "[^/\\*]+" >> [](auto&) {}, "/\\*" >> [depth](auto&) { ++(*depth); }, "\\*/" >> @@ -332,9 +333,7 @@ namespace verona m.mode("start"); }, - "." >> [](auto&) {}, - - "\r?\n" >> [](auto&) {}, + "[/\\*]" >> [](auto&) {}, }); p.done([start_location](auto& m) { From 13db4de6da9d03672543911848f5c9b2f6726e8e Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Thu, 11 Apr 2024 13:39:18 +0100 Subject: [PATCH 12/12] Made comment more informative --- testsuite/verona_nostdlib/spec/comments_broken_nest.verona | 2 +- .../verona_nostdlib/spec/comments_broken_nest_out/stdout.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest.verona b/testsuite/verona_nostdlib/spec/comments_broken_nest.verona index e20d11235..c95483d74 100644 --- a/testsuite/verona_nostdlib/spec/comments_broken_nest.verona +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest.verona @@ -1 +1 @@ -/* Nested comments /* like this work */ \ No newline at end of file +/* Nested comments /* like this need well bracketed termination */ \ No newline at end of file diff --git a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt index f7c0ec119..84b889732 100644 --- a/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt @@ -1,7 +1,7 @@ Errors: Unterminated comment starting at -- comments_broken_nest.verona:1:1 -/* Nested comments /* like this work */ +/* Nested comments /* like this need well bracketed termination */ ~~ Pass parse failed with 1 error!