1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Support Bison 3

This commit is contained in:
Nobuyoshi Nakada 2019-06-17 03:09:52 +09:00
parent 53e9908d8a
commit a064e46762
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
3 changed files with 17 additions and 1 deletions

View file

@ -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

View file

@ -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

15
tool/pure_parser.rb Executable file
View file

@ -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')