Improve: No crash when config file contains syntax error
This commit is contained in:
@ -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()
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ extra-key: {
|
||||
code: "/"
|
||||
},
|
||||
{
|
||||
code: "\\"
|
||||
code: "\"
|
||||
},
|
||||
{
|
||||
code: "|"
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user