Improve: No crash when config file contains syntax error
This commit is contained in:
@ -135,11 +135,11 @@ class NeoLangLexer {
|
|||||||
|
|
||||||
var loop = true
|
var loop = true
|
||||||
while (loop && currentChar != NeoLangTokenValue.QUOTE.value.asString()[0]) {
|
while (loop && currentChar != NeoLangTokenValue.QUOTE.value.asString()[0]) {
|
||||||
// Skip escaped char
|
// NeoLang does not support escaped char
|
||||||
if (currentChar == '\\') {
|
// if (currentChar == '\\') {
|
||||||
builder.append('\\')
|
// builder.append('\\')
|
||||||
moveToNextChar(eofThrow = true)
|
// moveToNextChar(eofThrow = true)
|
||||||
}
|
// }
|
||||||
builder.append(currentChar)
|
builder.append(currentChar)
|
||||||
loop = moveToNextChar()
|
loop = moveToNextChar()
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ extra-key: {
|
|||||||
code: "/"
|
code: "/"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: "\\"
|
code: "\"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: "|"
|
code: "|"
|
||||||
|
@ -4,6 +4,7 @@ import io.neoterm.backend.TerminalColorScheme
|
|||||||
import io.neoterm.backend.TerminalColors
|
import io.neoterm.backend.TerminalColors
|
||||||
import io.neoterm.customize.config.ConfigureService
|
import io.neoterm.customize.config.ConfigureService
|
||||||
import io.neolang.visitor.ConfigVisitor
|
import io.neolang.visitor.ConfigVisitor
|
||||||
|
import io.neoterm.frontend.config.NeoConfigureFile
|
||||||
import io.neoterm.frontend.logging.NLog
|
import io.neoterm.frontend.logging.NLog
|
||||||
import io.neoterm.frontend.service.ServiceManager
|
import io.neoterm.frontend.service.ServiceManager
|
||||||
import io.neoterm.view.TerminalView
|
import io.neoterm.view.TerminalView
|
||||||
@ -76,11 +77,17 @@ open class NeoColorScheme {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun loadConfigure(file: File): Boolean {
|
fun loadConfigure(file: File): Boolean {
|
||||||
|
// TODO: Refactor with NeoExtraKey#loadConfigure
|
||||||
val loaderService = ServiceManager.getService<ConfigureService>()
|
val loaderService = ServiceManager.getService<ConfigureService>()
|
||||||
val configure = loaderService.newLoader(file).loadConfigure()
|
|
||||||
|
|
||||||
|
val configure: NeoConfigureFile?
|
||||||
|
try {
|
||||||
|
configure = loaderService.newLoader(file).loadConfigure()
|
||||||
if (configure == null) {
|
if (configure == null) {
|
||||||
NLog.e("ColorScheme", "Failed to load color config: ${file.absolutePath}")
|
throw RuntimeException("Parse configuration failed.")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
NLog.e("ExtraKey", "Failed to load extra key config: ${file.absolutePath}: ${e.localizedMessage}")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package io.neoterm.customize.eks
|
|||||||
|
|
||||||
import io.neolang.visitor.ConfigVisitor
|
import io.neolang.visitor.ConfigVisitor
|
||||||
import io.neoterm.customize.config.ConfigureService
|
import io.neoterm.customize.config.ConfigureService
|
||||||
|
import io.neoterm.frontend.config.NeoConfigureFile
|
||||||
import io.neoterm.frontend.logging.NLog
|
import io.neoterm.frontend.logging.NLog
|
||||||
import io.neoterm.frontend.service.ServiceManager
|
import io.neoterm.frontend.service.ServiceManager
|
||||||
import io.neoterm.view.eks.ExtraKeysView
|
import io.neoterm.view.eks.ExtraKeysView
|
||||||
@ -42,11 +43,17 @@ class NeoExtraKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun loadConfigure(file: File): Boolean {
|
fun loadConfigure(file: File): Boolean {
|
||||||
|
// TODO: Refactor with NeoColorScheme#loadConfigure
|
||||||
val loaderService = ServiceManager.getService<ConfigureService>()
|
val loaderService = ServiceManager.getService<ConfigureService>()
|
||||||
val configure = loaderService.newLoader(file).loadConfigure()
|
|
||||||
|
|
||||||
|
val configure: NeoConfigureFile?
|
||||||
|
try {
|
||||||
|
configure = loaderService.newLoader(file).loadConfigure()
|
||||||
if (configure == null) {
|
if (configure == null) {
|
||||||
NLog.e("ExtraKey", "Failed to load extra key config: ${file.absolutePath}")
|
throw RuntimeException("Parse configuration failed.")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
NLog.e("ExtraKey", "Failed to load extra key config: ${file.absolutePath}: ${e.localizedMessage}")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user