Sha256: cab86b82743458fc2c27bf4585f46dcf41bfa58a11c35d379e2df6359565b9a1
Contents?: true
Size: 1.48 KB
Versions: 50
Compression:
Stored size: 1.48 KB
Contents
#!/usr/bin/env ruby require "fileutils" require "antlr4-native" grammar_file = ARGV.shift # ANTLR does weird things if the grammar file isn't in the current working directory temp_grammar_file = File.join(FileUtils.pwd, File.basename(grammar_file)) FileUtils.cp(grammar_file, temp_grammar_file) # generate parser generator = Antlr4Native::Generator.new( grammar_files: [File.basename(temp_grammar_file)], output_dir: "ext", parser_root_method: "syntax", ) generator.generate # fix issues with generated parser parser_source_file = File.join("ext", "express_parser", "express_parser.cpp") parser_source_lines = File.read(parser_source_file).split("\n") # - add ParserProxy tokens method, simple compensation for missing exposed BufferedTokenStream i = parser_source_lines.index { |x| x == " Object syntax() {" } parser_source_lines[i + 6] += <<~CPP.split("\n").map { |x| x == "" ? x : " #{x}" }.join("\n") Array getTokens() { Array a; std::vector<Token*> tokens = this -> tokens -> getTokens(); for (auto &token : tokens) { a.push(token); } return a; } CPP i = parser_source_lines.index { |x| x == ' .define_method("syntax", &ParserProxy::syntax, Return().keepAlive())' } parser_source_lines[i] += <<~CPP.split("\n").map { |x| x == "" ? x : " #{x}" }.join("\n") .define_method("tokens", &ParserProxy::getTokens) CPP # write fixed parser file File.write(parser_source_file, "#{parser_source_lines.join("\n")}\n") # cleanup FileUtils.rm(temp_grammar_file)
Version data entries
50 entries across 50 versions & 1 rubygems