fix(frontend): 规范一下前端实现

This commit is contained in:
jing
2026-03-10 23:03:14 +08:00
parent d2b54a9849
commit c72ffa6e39
8 changed files with 100 additions and 17 deletions

View File

@@ -12,6 +12,10 @@
namespace {
bool HasParsePrefix(const std::string& msg) {
return msg.rfind("[parse]", 0) == 0;
}
class ParseErrorListener : public antlr4::BaseErrorListener {
public:
void syntaxError(antlr4::Recognizer* /*recognizer*/, antlr4::Token* /*offendingSymbol*/,
@@ -49,6 +53,9 @@ AntlrResult ParseFileWithAntlr(const std::string& path) {
} catch (const std::exception& ex) {
const std::string msg = ex.what();
if (!msg.empty()) {
if (HasParsePrefix(msg)) {
throw;
}
throw std::runtime_error("[parse] 暂不支持的语法/词法 - " + msg);
}
if (auto* tok = parser->getCurrentToken()) {