Skip to content

Commit

Permalink
Better error reporting
Browse files Browse the repository at this point in the history
Updated dependencies versions
Fixed error in cursor positioning that masked grammar compiler error
  • Loading branch information
uaraven committed Jan 25, 2021
1 parent 5342b91 commit 3152f0e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.4.10'
id 'org.openjfx.javafxplugin' version '0.0.8'
id 'org.jetbrains.kotlin.jvm' version '1.4.21-2'
id 'org.openjfx.javafxplugin' version '0.0.9'
id 'com.github.johnrengelman.shadow' version '6.1.0'
id 'application'
}

mainClassName = 'net.ninjacat.antlrscope.AppKt'

group 'net.ninjacat'
version '0.4.4'
version '0.4.5'

repositories {
mavenCentral()
Expand All @@ -21,9 +21,9 @@ javafx {
}

ext {
graalJsVersion = '20.2.0'
graphvizJavaVersion = '0.17.0'
antlrVersion = '4.8-1'
graalJsVersion = '21.0.0'
graphvizJavaVersion = '0.18.0'
antlrVersion = '4.9.1'
richTextFxVersion = "0.10.5"
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/net/ninjacat/antlrscope/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class AntlrViewApp : Application() {
fileChooser.title = "Select grammar file"
fileChooser.extensionFilters.addAll(grammarExtensions)
val grammarFile = fileChooser.showOpenDialog(stage)
if (grammarFile != null) {
if (grammarFile != null) {
editors.loadGrammar(grammarFile.absolutePath)
}
}
Expand Down Expand Up @@ -250,7 +250,9 @@ class AntlrViewApp : Application() {
val editor = if (err.errorSource == ErrorSource.GRAMMAR) editors.grammar else editors.text
val line = if (err.errorSource == ErrorSource.CODE) err.line - 1 else err.line - 1
val pos = if (err.errorSource == ErrorSource.CODE) err.pos else err.pos - 1
editor.moveTo(line, pos)
if (pos > 0 && line > 0) {
editor.moveTo(line, pos)
}
editor.requestFocus()
}
}
Expand Down
11 changes: 1 addition & 10 deletions src/main/kotlin/net/ninjacat/antlrscope/antlr/AntlrGen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,7 @@ class ToolListener(private val errors: MutableList<ErrorMessage>) : ANTLRToolLis
errors.add(
ErrorMessage(
msg?.line!!, msg.charPosition + 1,
formatErrorArgs(msg.errorType.msg, msg.args), ErrorSource.GRAMMAR))
}

private fun formatErrorArgs(msg: String, args: Array<Any>): String? {
var result = msg
for (index in args.indices) {
val indexStr = if (index == 0) "" else index.toString()
result = result.replace("<arg${indexStr}>", args[index].toString())
}
return result
msg.getMessageTemplate(true).render(), ErrorSource.GRAMMAR))
}

override fun warning(msg: ANTLRMessage?) {
Expand Down

0 comments on commit 3152f0e

Please sign in to comment.