diff --git a/CMakeLists.txt b/CMakeLists.txt index 89770b285..85e001fec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,8 @@ set(TRIESTE_BUILD_SAMPLES OFF) FetchContent_Declare( trieste GIT_REPOSITORY https://github.com/microsoft/trieste - GIT_TAG fac9e4c84de192ee53051be32c5426256cd1086e - GIT_SHALLOW TRUE + GIT_TAG 1e1448ca9e4ac158492bf8dbbd86b407c452fc0c + GIT_SHALLOW FALSE ) FetchContent_MakeAvailable(trieste) diff --git a/src/parse.cc b/src/parse.cc index d0a0e32c1..4d3fe880e 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,8 +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"); }, @@ -320,6 +324,7 @@ namespace verona p("comment", { + "[^/\\*]+" >> [](auto&) {}, "/\\*" >> [depth](auto&) { ++(*depth); }, "\\*/" >> @@ -328,12 +333,15 @@ namespace verona m.mode("start"); }, - "." >> [](auto&) {}, + "[/\\*]" >> [](auto&) {}, }); - p.done([](auto& m) { - if (m.mode() != "start") - m.error("unterminated comment at end of file"); + 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); m.term(terminators); }); 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 diff --git a/testsuite/verona_nostdlib/spec/comments.verona b/testsuite/verona_nostdlib/spec/comments.verona new file mode 100644 index 000000000..914fba31e --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments.verona @@ -0,0 +1,38 @@ +// Comment + +// Comment /* with nested comment */ + +// 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 */" + +/* Quotes don't affect the nesting. "/*" */ */ + +// Comment doesn't need a new line to terminate it \ No newline at end of file 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..c95483d74 --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest.verona @@ -0,0 +1 @@ +/* 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/00_parse.trieste b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/00_parse.trieste new file mode 100644 index 000000000..54dffdf9d --- /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 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 new file mode 100644 index 000000000..54dffdf9d --- /dev/null +++ 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/exit_code.txt b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/exit_code.txt new file mode 100644 index 000000000..56a6051ca --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/exit_code.txt @@ -0,0 +1 @@ +1 \ 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..84b889732 --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments_broken_nest_out/stdout.txt @@ -0,0 +1,8 @@ +Errors: +Unterminated comment starting at +-- comments_broken_nest.verona:1:1 +/* Nested comments /* like this need well bracketed termination */ +~~ + +Pass parse failed with 1 error! + 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..2c099537a --- /dev/null +++ b/testsuite/verona_nostdlib/spec/comments_out/00_parse.trieste @@ -0,0 +1,23 @@ +Verona +parse +(top + {} + (file + (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