From 81b3985d506e66a8f000d8ae673e80f21eec3e6b Mon Sep 17 00:00:00 2001 From: Ludwig Stecher Date: Sat, 21 Dec 2024 21:18:12 +0100 Subject: [PATCH] feat: add help suggestion to disambiguate parsing order with intersection --- pomsky-lib/src/diagnose/help.rs | 5 +++++ pomsky-lib/tests/testcases/intersections/e_multiple.txt | 7 +++++++ .../tests/testcases/intersections/e_string_empty.txt | 7 +++++++ .../tests/testcases/intersections/e_string_too_long.txt | 7 +++++++ .../tests/testcases/intersections/e_with_assertions.txt | 7 +++++++ pomsky-lib/tests/testcases/intersections/strings.txt | 3 +++ 6 files changed, 36 insertions(+) create mode 100644 pomsky-lib/tests/testcases/intersections/e_multiple.txt create mode 100644 pomsky-lib/tests/testcases/intersections/e_string_empty.txt create mode 100644 pomsky-lib/tests/testcases/intersections/e_string_too_long.txt create mode 100644 pomsky-lib/tests/testcases/intersections/e_with_assertions.txt create mode 100644 pomsky-lib/tests/testcases/intersections/strings.txt diff --git a/pomsky-lib/src/diagnose/help.rs b/pomsky-lib/src/diagnose/help.rs index ed8045a..90ecbbe 100644 --- a/pomsky-lib/src/diagnose/help.rs +++ b/pomsky-lib/src/diagnose/help.rs @@ -175,6 +175,11 @@ pub(super) fn get_compiler_help(kind: &CompileErrorKind, _span: Span) -> Option< .to_string(), ) } + CompileErrorKind::BadIntersection => Some( + "One character sets can be intersected.\n\ + Parentheses may be required to clarify the parsing order." + .to_string(), + ), _ => None, } diff --git a/pomsky-lib/tests/testcases/intersections/e_multiple.txt b/pomsky-lib/tests/testcases/intersections/e_multiple.txt new file mode 100644 index 0000000..d6c9a29 --- /dev/null +++ b/pomsky-lib/tests/testcases/intersections/e_multiple.txt @@ -0,0 +1,7 @@ +#! expect=error +[w] & [d] [s] +----- +ERROR: Intersecting these expressions is not supported. Only character sets can be intersected. +HELP: One character sets can be intersected. +Parentheses may be required to clarify the parsing order. +SPAN: 0..13 \ No newline at end of file diff --git a/pomsky-lib/tests/testcases/intersections/e_string_empty.txt b/pomsky-lib/tests/testcases/intersections/e_string_empty.txt new file mode 100644 index 0000000..f108c9f --- /dev/null +++ b/pomsky-lib/tests/testcases/intersections/e_string_empty.txt @@ -0,0 +1,7 @@ +#! expect=error +'a' & '' +----- +ERROR: Intersecting these expressions is not supported. Only character sets can be intersected. +HELP: One character sets can be intersected. +Parentheses may be required to clarify the parsing order. +SPAN: 0..8 \ No newline at end of file diff --git a/pomsky-lib/tests/testcases/intersections/e_string_too_long.txt b/pomsky-lib/tests/testcases/intersections/e_string_too_long.txt new file mode 100644 index 0000000..23de708 --- /dev/null +++ b/pomsky-lib/tests/testcases/intersections/e_string_too_long.txt @@ -0,0 +1,7 @@ +#! expect=error +[w] & 'ab' +----- +ERROR: Intersecting these expressions is not supported. Only character sets can be intersected. +HELP: One character sets can be intersected. +Parentheses may be required to clarify the parsing order. +SPAN: 0..10 \ No newline at end of file diff --git a/pomsky-lib/tests/testcases/intersections/e_with_assertions.txt b/pomsky-lib/tests/testcases/intersections/e_with_assertions.txt new file mode 100644 index 0000000..03bbe92 --- /dev/null +++ b/pomsky-lib/tests/testcases/intersections/e_with_assertions.txt @@ -0,0 +1,7 @@ +#! expect=error +'a' & 'b' $ +----- +ERROR: Intersecting these expressions is not supported. Only character sets can be intersected. +HELP: One character sets can be intersected. +Parentheses may be required to clarify the parsing order. +SPAN: 0..11 \ No newline at end of file diff --git a/pomsky-lib/tests/testcases/intersections/strings.txt b/pomsky-lib/tests/testcases/intersections/strings.txt new file mode 100644 index 0000000..af34248 --- /dev/null +++ b/pomsky-lib/tests/testcases/intersections/strings.txt @@ -0,0 +1,3 @@ +'a' & 'b' +----- +[a&&b] \ No newline at end of file