Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
vitstn committed Sep 7, 2024
1 parent e9c2717 commit 472cd5c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions ydb/library/yql/parser/proto_ast/proto_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ namespace antlr4 {
NProtoAST::IErrorCollector* errors;
bool* error;
public:
static ConsoleErrorListener INSTANCE;

YqlErrorListener(NProtoAST::IErrorCollector* errors, bool* error);

virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine,
Expand Down Expand Up @@ -137,8 +135,8 @@ namespace NProtoAST {
return Parser.Parse(Lexer, &errors);
} catch (const TTooManyErrors&) {
return nullptr;
} catch (const yexception& e) {
errors.Error(0, 0, e.what());
} catch (...) {
errors.Error(0, 0, CurrentExceptionMessage());
return nullptr;
}
}
Expand All @@ -159,7 +157,8 @@ namespace NProtoAST {
public:
TProtoASTBuilder(TStringBuf data, const TString& queryName = "query", google::protobuf::Arena* arena = nullptr)
: QueryName(queryName)
, InputStream(std::string(data)) // Why the hell antlr needs non-const ptr??
, Data(data)
, InputStream(Data) // Why the hell antlr needs non-const ptr??
, Lexer(&InputStream)
, TokenStream(&Lexer)
, Parser(&TokenStream, arena)
Expand All @@ -169,6 +168,7 @@ namespace NProtoAST {
google::protobuf::Message* BuildAST(IErrorCollector& errors) {
// TODO: find a better way to break on lexer errors
typename antlr4::YqlErrorListener listener(&errors, &Parser.error);
Parser.removeErrorListeners();
Parser.addErrorListener(&listener);
try {
auto result = Parser.Parse(&errors);
Expand All @@ -179,8 +179,8 @@ namespace NProtoAST {
Parser.removeErrorListener(&listener);
Parser.error = false;
return nullptr;
} catch (const yexception& e) {
errors.Error(0, 0, e.what());
} catch (...) {
errors.Error(0, 0, CurrentExceptionMessage());
Parser.removeErrorListener(&listener);
Parser.error = false;
return nullptr;
Expand All @@ -189,6 +189,7 @@ namespace NProtoAST {

private:
TString QueryName;
std::string Data;

antlr4::ANTLRInputStream InputStream;
TLexer Lexer;
Expand Down Expand Up @@ -232,8 +233,8 @@ namespace NProtoAST {
}
}
} catch (const TTooManyErrors&) {
} catch (const yexception& e) {
errors.Error(0, 0, e.what());
} catch (...) {
errors.Error(0, 0, CurrentExceptionMessage());
}
}

Expand Down Expand Up @@ -272,8 +273,8 @@ namespace NProtoAST {
}
}
} catch (const TTooManyErrors&) {
} catch (const yexception& e) {
errors.Error(0, 0, e.what());
} catch (...) {
errors.Error(0, 0, CurrentExceptionMessage());
}
}

Expand Down

0 comments on commit 472cd5c

Please sign in to comment.