Improve: No crash when config file contains syntax error

This commit is contained in:
zt515
2017-08-09 21:30:55 +08:00
parent 19d5be2a4c
commit 6eec8b34af
4 changed files with 26 additions and 12 deletions

View File

@ -135,11 +135,11 @@ class NeoLangLexer {
var loop = true
while (loop && currentChar != NeoLangTokenValue.QUOTE.value.asString()[0]) {
// Skip escaped char
if (currentChar == '\\') {
builder.append('\\')
moveToNextChar(eofThrow = true)
}
// NeoLang does not support escaped char
// if (currentChar == '\\') {
// builder.append('\\')
// moveToNextChar(eofThrow = true)
// }
builder.append(currentChar)
loop = moveToNextChar()
}

View File

@ -10,7 +10,7 @@ extra-key: {
code: "/"
},
{
code: "\\"
code: "\"
},
{
code: "|"

View File

@ -4,6 +4,7 @@ import io.neoterm.backend.TerminalColorScheme
import io.neoterm.backend.TerminalColors
import io.neoterm.customize.config.ConfigureService
import io.neolang.visitor.ConfigVisitor
import io.neoterm.frontend.config.NeoConfigureFile
import io.neoterm.frontend.logging.NLog
import io.neoterm.frontend.service.ServiceManager
import io.neoterm.view.TerminalView
@ -76,11 +77,17 @@ open class NeoColorScheme {
}
fun loadConfigure(file: File): Boolean {
// TODO: Refactor with NeoExtraKey#loadConfigure
val loaderService = ServiceManager.getService<ConfigureService>()
val configure = loaderService.newLoader(file).loadConfigure()
if (configure == null) {
NLog.e("ColorScheme", "Failed to load color config: ${file.absolutePath}")
val configure: NeoConfigureFile?
try {
configure = loaderService.newLoader(file).loadConfigure()
if (configure == null) {
throw RuntimeException("Parse configuration failed.")
}
} catch (e: Exception) {
NLog.e("ExtraKey", "Failed to load extra key config: ${file.absolutePath}: ${e.localizedMessage}")
return false
}

View File

@ -2,6 +2,7 @@ package io.neoterm.customize.eks
import io.neolang.visitor.ConfigVisitor
import io.neoterm.customize.config.ConfigureService
import io.neoterm.frontend.config.NeoConfigureFile
import io.neoterm.frontend.logging.NLog
import io.neoterm.frontend.service.ServiceManager
import io.neoterm.view.eks.ExtraKeysView
@ -42,11 +43,17 @@ class NeoExtraKey {
}
fun loadConfigure(file: File): Boolean {
// TODO: Refactor with NeoColorScheme#loadConfigure
val loaderService = ServiceManager.getService<ConfigureService>()
val configure = loaderService.newLoader(file).loadConfigure()
if (configure == null) {
NLog.e("ExtraKey", "Failed to load extra key config: ${file.absolutePath}")
val configure: NeoConfigureFile?
try {
configure = loaderService.newLoader(file).loadConfigure()
if (configure == null) {
throw RuntimeException("Parse configuration failed.")
}
} catch (e: Exception) {
NLog.e("ExtraKey", "Failed to load extra key config: ${file.absolutePath}: ${e.localizedMessage}")
return false
}