From cd189fa00160021295c87a35ce15e2a7b94794e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20Schu=CC=88tz?= Date: Tue, 30 May 2023 19:22:00 +0200 Subject: [PATCH] feat(diagnostic): Show regex error message --- .../src/main/kotlin/tools/samt/semantic/ConstraintBuilder.kt | 2 +- .../src/test/kotlin/tools/samt/semantic/SemanticModelTest.kt | 4 +++- specification/examples/debug/debug.samt | 5 +++++ specification/examples/debug/samt.yaml | 5 +++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 specification/examples/debug/debug.samt create mode 100644 specification/examples/debug/samt.yaml diff --git a/semantic/src/main/kotlin/tools/samt/semantic/ConstraintBuilder.kt b/semantic/src/main/kotlin/tools/samt/semantic/ConstraintBuilder.kt index d55b35cf..0bda554c 100644 --- a/semantic/src/main/kotlin/tools/samt/semantic/ConstraintBuilder.kt +++ b/semantic/src/main/kotlin/tools/samt/semantic/ConstraintBuilder.kt @@ -103,7 +103,7 @@ internal class ConstraintBuilder(private val controller: DiagnosticController) { try { Regex(pattern) } catch (e: Exception) { argument.reportError(controller) { - message("Invalid regex pattern") + message("Invalid regex pattern: '${e.message}'") highlight(argument.location) } return null diff --git a/semantic/src/test/kotlin/tools/samt/semantic/SemanticModelTest.kt b/semantic/src/test/kotlin/tools/samt/semantic/SemanticModelTest.kt index 1a31c8da..2baf6e80 100644 --- a/semantic/src/test/kotlin/tools/samt/semantic/SemanticModelTest.kt +++ b/semantic/src/test/kotlin/tools/samt/semantic/SemanticModelTest.kt @@ -345,7 +345,9 @@ class SemanticModelTest { """.trimIndent() parseAndCheck( source to listOf( - "Error: Invalid regex pattern" + "Error: Invalid regex pattern: 'Dangling meta character '+' near index 5\n" + + "fo/+++!hi\n" + + " ^'" ) ) } diff --git a/specification/examples/debug/debug.samt b/specification/examples/debug/debug.samt new file mode 100644 index 00000000..3b739358 --- /dev/null +++ b/specification/examples/debug/debug.samt @@ -0,0 +1,5 @@ +package debug.test + +record Foo { + name: String ("++") +} \ No newline at end of file diff --git a/specification/examples/debug/samt.yaml b/specification/examples/debug/samt.yaml new file mode 100644 index 00000000..96a38136 --- /dev/null +++ b/specification/examples/debug/samt.yaml @@ -0,0 +1,5 @@ +source: ./ + +generators: + - name: kotlin-ktor-consumer + output: ./out