From a064e46762ec0bfd40e6a04242d9e62fdd21e1f0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 17 Jun 2019 03:09:52 +0900 Subject: [PATCH] Support Bison 3 --- common.mk | 1 + parse.y | 2 +- tool/pure_parser.rb | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100755 tool/pure_parser.rb diff --git a/common.mk b/common.mk index d6e4d6acd7..f740f93af6 100755 --- a/common.mk +++ b/common.mk @@ -851,6 +851,7 @@ PHONY: {$(srcdir)}.y.c: $(ECHO) generating $@ $(Q)$(BASERUBY) $(srcdir)/tool/id2token.rb --path-separator=.$(PATH_SEPARATOR)./ --vpath=$(VPATH) id.h $(SRC_FILE) > parse.tmp.y + $(Q)$(BASERUBY) $(srcdir)/tool/pure_parser.rb parse.tmp.y $(YACC) $(Q)$(YACC) -d $(YFLAGS) -o y.tab.c parse.tmp.y $(Q)$(RM) parse.tmp.y $(Q)sed -f $(srcdir)/tool/ytab.sed -e "/^#/s|parse\.tmp\.[iy]|$(SRC_FILE)|" -e "/^#/s!y\.tab\.c!$@!" y.tab.c > $@.new diff --git a/parse.y b/parse.y index d76d3b2562..665067d3e6 100644 --- a/parse.y +++ b/parse.y @@ -910,7 +910,7 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in %} %expect 0 -%pure-parser +%define api.pure %lex-param {struct parser_params *p} %parse-param {struct parser_params *p} %initial-action diff --git a/tool/pure_parser.rb b/tool/pure_parser.rb new file mode 100755 index 0000000000..20d71079a0 --- /dev/null +++ b/tool/pure_parser.rb @@ -0,0 +1,15 @@ +#!/usr/bin/ruby -pi +BEGIN { + require_relative 'colorize' + + colorize = Colorize.new + file = ARGV.shift + unless /\Abison .* (\d+)\.\d+/ =~ IO.popen(ARGV+%w[--version], &:read) + puts colorize.fail("not bison") + exit + end + exit if $1.to_i >= 3 + ARGV.clear + ARGV.push(file) +} +$_.sub!(/^%define\s+api\.pure/, '%pure-parser')