#!/usr/bin/python # ----------------------------------------------------------------------------- # # This file is the copyrighted property of Tableau Software and is protected # by registered patents and other applicable U.S. and international laws and # regulations. # # Unlicensed use of the contents of this file is prohibited. Please refer to # the NOTICES.txt file for further details. # # ----------------------------------------------------------------------------- import os import sys def processFile(input_file, output_file): f = open(input_file, "r") targetData = [] customHandler = "" errorTrigger = "error (yyla.location, yysyntax_error_ (yystack_[0].state," replacement = "" for line in f: if customHandler == "": if line in ["// A Bison parser, made by GNU Bison 3.0.4.\n", "// A Bison parser, made by GNU Bison 3.3.2.\n", "// A Bison parser, made by GNU Bison 3.4.1.\n"]: customHandler = """ #define customErrorReporting(location_ARG,state_ARG,yyla_ARG) \\ {\\ hyper::SQLLexer::Token token;\\ auto yystate=state_ARG;\\ auto yylaTmp=yyla_ARG;auto yyla=yylaTmp;\\ const char* got=nullptr;\\ std::vector possibilities;\\ if (!yyla.empty()) {\\ auto& astToken=hyper::astql::Token::ref(*yyla.value);\\ token={astToken.begin(),astToken.end(),static_cast(astToken.decoding)};\\ int yytoken=yyla.type_get();\\ int ident=SQLParser::yytranslate_(token::IDENT);\\ int abort_p=SQLParser::yytranslate_(token::ABORT_P);\\ got = yytname_[yytoken]; if ((yytoken=abort_p)) continue;\\ const char* p=yytname_[yyx]; if ((yyx 0: line = line[0:pos] + replacement + line[pos:] targetData.append(line) f.close() f = open(output_file, "w") f.write("".join(targetData)) # Process the arguments if __name__ == "__main__": import sys processFile(sys.argv[1], sys.argv[2])