cybrid_api_organization_ruby 0.73.1 → 0.73.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -2
- data/README.md +5 -5
- data/cybrid_api_organization_ruby.gemspec +1 -1
- data/lib/cybrid_api_organization_ruby/api/organizations_organization_api.rb +1 -1
- data/lib/cybrid_api_organization_ruby/api_client.rb +1 -1
- data/lib/cybrid_api_organization_ruby/api_error.rb +1 -1
- data/lib/cybrid_api_organization_ruby/configuration.rb +1 -1
- data/lib/cybrid_api_organization_ruby/models/error_response_organization_model.rb +1 -1
- data/lib/cybrid_api_organization_ruby/models/organization_organization_model.rb +1 -1
- data/lib/cybrid_api_organization_ruby/models/patch_organization_organization_model.rb +1 -1
- data/lib/cybrid_api_organization_ruby/version.rb +2 -2
- data/lib/cybrid_api_organization_ruby.rb +1 -1
- data/spec/api/organizations_organization_api_spec.rb +1 -1
- data/spec/api_client_spec.rb +1 -1
- data/spec/configuration_spec.rb +1 -1
- data/spec/models/error_response_organization_model_spec.rb +1 -1
- data/spec/models/organization_organization_model_spec.rb +1 -1
- data/spec/models/patch_organization_organization_model_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/vendor/bundle/ruby/3.2.0/bin/racc +29 -0
- data/vendor/bundle/ruby/3.2.0/cache/parser-3.2.2.3.gem +0 -0
- data/vendor/bundle/ruby/3.2.0/cache/racc-1.7.0.gem +0 -0
- data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/byebug-11.1.3/gem_make.out +5 -5
- data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/ffi-1.15.5/gem_make.out +5 -5
- data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/jaro_winkler-1.5.6/gem_make.out +5 -5
- data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/psych-5.1.0/gem_make.out +5 -5
- data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/racc-1.7.0/gem.build_complete +0 -0
- data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/racc-1.7.0/gem_make.out +28 -0
- data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/racc-1.7.0/mkmf.log +57 -0
- data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/racc-1.7.0/racc/cparse.so +0 -0
- data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/stringio-3.0.7/gem_make.out +5 -5
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/macruby.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby18.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby19.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby20.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby21.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby22.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby23.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby24.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby25.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby26.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby27.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby30.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby31.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby32.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby33.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/rubymotion.rb +3 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/version.rb +1 -1
- data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/parser.gemspec +1 -1
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/COPYING +22 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/ChangeLog +846 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/README.ja.rdoc +94 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/README.rdoc +79 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/TODO +5 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/bin/racc +320 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/doc/en/NEWS.en.rdoc +282 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/doc/en/grammar.en.rdoc +226 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/doc/en/grammar2.en.rdoc +219 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/doc/ja/NEWS.ja.rdoc +307 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/doc/ja/command.ja.html +94 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/doc/ja/debug.ja.rdoc +36 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/doc/ja/grammar.ja.rdoc +348 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/doc/ja/index.ja.html +10 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/doc/ja/parser.ja.rdoc +125 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/doc/ja/usage.ja.html +414 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/ext/racc/MANIFEST +4 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/ext/racc/cparse/Makefile +269 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/ext/racc/cparse/cparse.c +861 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/ext/racc/cparse/extconf.rb +9 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/compat.rb +33 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/cparse.so +0 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/debugflags.rb +60 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/exception.rb +16 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/grammar.rb +1114 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/grammarfileparser.rb +561 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/info.rb +17 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/iset.rb +92 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/logfilegenerator.rb +212 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/parser-text.rb +658 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/parser.rb +632 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/parserfilegenerator.rb +470 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/sourcetext.rb +35 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/state.rb +972 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/statetransitiontable.rb +311 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc/static.rb +5 -0
- data/vendor/bundle/ruby/3.2.0/gems/racc-1.7.0/lib/racc.rb +6 -0
- data/vendor/bundle/ruby/3.2.0/specifications/{parser-3.2.2.1.gemspec → parser-3.2.2.3.gemspec} +5 -5
- data/vendor/bundle/ruby/3.2.0/specifications/racc-1.7.0.gemspec +27 -0
- metadata +127 -83
- data/vendor/bundle/ruby/3.2.0/cache/parser-3.2.2.1.gem +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/LICENSE.txt +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/bin/ruby-parse +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/bin/ruby-rewrite +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/gauntlet_parser.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/all.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ast/node.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ast/processor.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/base.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/builders/default.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/clobbering_error.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/color.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/context.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/current.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/current_arg_stack.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/deprecation.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/diagnostic/engine.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/diagnostic.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/lexer/dedenter.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/lexer/explanation.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/lexer/literal.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/lexer/stack_state.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/lexer-F0.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/lexer-F1.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/lexer-strings.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/max_numparam_stack.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/messages.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/meta.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/rewriter.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/ruby28.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/runner/ruby_parse.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/runner/ruby_rewrite.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/runner.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/buffer.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/comment/associator.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/comment.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/collection.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/condition.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/constant.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/definition.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/for.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/heredoc.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/index.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/keyword.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/method_definition.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/objc_kwarg.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/operator.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/rescue_body.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/send.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/ternary.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map/variable.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/map.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/range.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/rewriter/action.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/rewriter.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/tree_rewriter/action.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/source/tree_rewriter.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/static_environment.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/syntax_error.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/tree_rewriter.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser/variables_stack.rb +0 -0
- /data/vendor/bundle/ruby/3.2.0/gems/{parser-3.2.2.1 → parser-3.2.2.3}/lib/parser.rb +0 -0
@@ -0,0 +1,1114 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# Copyright (c) 1999-2006 Minero Aoki
|
6
|
+
#
|
7
|
+
# This program is free software.
|
8
|
+
# You can distribute/modify this program under the same terms of ruby.
|
9
|
+
# see the file "COPYING".
|
10
|
+
#
|
11
|
+
#++
|
12
|
+
|
13
|
+
require 'racc/compat'
|
14
|
+
require 'racc/iset'
|
15
|
+
require 'racc/sourcetext'
|
16
|
+
require 'racc/logfilegenerator'
|
17
|
+
require 'racc/exception'
|
18
|
+
require 'forwardable'
|
19
|
+
|
20
|
+
module Racc
|
21
|
+
|
22
|
+
class Grammar
|
23
|
+
|
24
|
+
def initialize(debug_flags = DebugFlags.new)
|
25
|
+
@symboltable = SymbolTable.new
|
26
|
+
@debug_symbol = debug_flags.token
|
27
|
+
@rules = [] # :: [Rule]
|
28
|
+
@start = nil
|
29
|
+
@n_expected_srconflicts = nil
|
30
|
+
@prec_table = []
|
31
|
+
@prec_table_closed = false
|
32
|
+
@closed = false
|
33
|
+
@states = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :start
|
37
|
+
attr_reader :symboltable
|
38
|
+
attr_accessor :n_expected_srconflicts
|
39
|
+
|
40
|
+
def [](x)
|
41
|
+
@rules[x]
|
42
|
+
end
|
43
|
+
|
44
|
+
def each_rule(&block)
|
45
|
+
@rules.each(&block)
|
46
|
+
end
|
47
|
+
|
48
|
+
alias each each_rule
|
49
|
+
|
50
|
+
def each_index(&block)
|
51
|
+
@rules.each_index(&block)
|
52
|
+
end
|
53
|
+
|
54
|
+
def each_with_index(&block)
|
55
|
+
@rules.each_with_index(&block)
|
56
|
+
end
|
57
|
+
|
58
|
+
def size
|
59
|
+
@rules.size
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_s
|
63
|
+
"<Racc::Grammar>"
|
64
|
+
end
|
65
|
+
|
66
|
+
extend Forwardable
|
67
|
+
|
68
|
+
def_delegator "@symboltable", :each, :each_symbol
|
69
|
+
def_delegator "@symboltable", :each_terminal
|
70
|
+
def_delegator "@symboltable", :each_nonterminal
|
71
|
+
|
72
|
+
def intern(value, dummy = false)
|
73
|
+
@symboltable.intern(value, dummy)
|
74
|
+
end
|
75
|
+
|
76
|
+
def symbols
|
77
|
+
@symboltable.symbols
|
78
|
+
end
|
79
|
+
|
80
|
+
def nonterminal_base
|
81
|
+
@symboltable.nt_base
|
82
|
+
end
|
83
|
+
|
84
|
+
def useless_nonterminal_exist?
|
85
|
+
n_useless_nonterminals() != 0
|
86
|
+
end
|
87
|
+
|
88
|
+
def n_useless_nonterminals
|
89
|
+
@n_useless_nonterminals ||= each_useless_nonterminal.count
|
90
|
+
end
|
91
|
+
|
92
|
+
def each_useless_nonterminal
|
93
|
+
return to_enum __method__ unless block_given?
|
94
|
+
|
95
|
+
@symboltable.each_nonterminal do |sym|
|
96
|
+
yield sym if sym.useless?
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def useless_rule_exist?
|
101
|
+
n_useless_rules() != 0
|
102
|
+
end
|
103
|
+
|
104
|
+
def n_useless_rules
|
105
|
+
@n_useless_rules ||= each_useless_rule.count
|
106
|
+
end
|
107
|
+
|
108
|
+
def each_useless_rule
|
109
|
+
return to_enum __method__ unless block_given?
|
110
|
+
|
111
|
+
each do |r|
|
112
|
+
yield r if r.useless?
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def nfa
|
117
|
+
(@states ||= States.new(self)).nfa
|
118
|
+
end
|
119
|
+
|
120
|
+
def dfa
|
121
|
+
(@states ||= States.new(self)).dfa
|
122
|
+
end
|
123
|
+
|
124
|
+
alias states dfa
|
125
|
+
|
126
|
+
def state_transition_table
|
127
|
+
states().state_transition_table
|
128
|
+
end
|
129
|
+
|
130
|
+
def parser_class
|
131
|
+
states = states() # cache
|
132
|
+
if $DEBUG
|
133
|
+
srcfilename = caller(1).first.slice(/\A(.*?):/, 1)
|
134
|
+
begin
|
135
|
+
write_log srcfilename + ".output"
|
136
|
+
rescue SystemCallError
|
137
|
+
end
|
138
|
+
report = lambda {|s| $stderr.puts "racc: #{srcfilename}: #{s}" }
|
139
|
+
if states.should_report_srconflict?
|
140
|
+
report["#{states.n_srconflicts} shift/reduce conflicts"]
|
141
|
+
end
|
142
|
+
if states.rrconflict_exist?
|
143
|
+
report["#{states.n_rrconflicts} reduce/reduce conflicts"]
|
144
|
+
end
|
145
|
+
g = states.grammar
|
146
|
+
if g.useless_nonterminal_exist?
|
147
|
+
report["#{g.n_useless_nonterminals} useless nonterminals"]
|
148
|
+
end
|
149
|
+
if g.useless_rule_exist?
|
150
|
+
report["#{g.n_useless_rules} useless rules"]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
states.state_transition_table.parser_class
|
154
|
+
end
|
155
|
+
|
156
|
+
def write_log(path)
|
157
|
+
File.open(path, 'w') {|f|
|
158
|
+
LogFileGenerator.new(states()).output f
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
#
|
163
|
+
# Grammar Definition Interface
|
164
|
+
#
|
165
|
+
|
166
|
+
def add(rule)
|
167
|
+
raise ArgumentError, "rule added after the Grammar closed" if @closed
|
168
|
+
@rules.push rule
|
169
|
+
end
|
170
|
+
|
171
|
+
def added?(sym)
|
172
|
+
@rules.detect {|r| r.target == sym }
|
173
|
+
end
|
174
|
+
|
175
|
+
def start_symbol=(s)
|
176
|
+
raise CompileError, "start symbol set twice'" if @start
|
177
|
+
@start = s
|
178
|
+
end
|
179
|
+
|
180
|
+
def declare_precedence(assoc, syms)
|
181
|
+
raise CompileError, "precedence table defined twice" if @prec_table_closed
|
182
|
+
@prec_table.push [assoc, syms]
|
183
|
+
end
|
184
|
+
|
185
|
+
def end_precedence_declaration(reverse)
|
186
|
+
@prec_table_closed = true
|
187
|
+
return if @prec_table.empty?
|
188
|
+
table = reverse ? @prec_table.reverse : @prec_table
|
189
|
+
table.each_with_index do |(assoc, syms), idx|
|
190
|
+
syms.each do |sym|
|
191
|
+
sym.assoc = assoc
|
192
|
+
sym.precedence = idx
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
#
|
198
|
+
# Dynamic Generation Interface
|
199
|
+
#
|
200
|
+
|
201
|
+
def Grammar.define(&block)
|
202
|
+
env = DefinitionEnv.new
|
203
|
+
env.instance_eval(&block)
|
204
|
+
env.grammar
|
205
|
+
end
|
206
|
+
|
207
|
+
class DefinitionEnv
|
208
|
+
def initialize
|
209
|
+
@grammar = Grammar.new
|
210
|
+
@seqs = Hash.new(0)
|
211
|
+
@delayed = []
|
212
|
+
end
|
213
|
+
|
214
|
+
def grammar
|
215
|
+
flush_delayed
|
216
|
+
@grammar.each do |rule|
|
217
|
+
if rule.specified_prec
|
218
|
+
rule.specified_prec = @grammar.intern(rule.specified_prec)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
@grammar.init
|
222
|
+
@grammar
|
223
|
+
end
|
224
|
+
|
225
|
+
def precedence_table(&block)
|
226
|
+
env = PrecedenceDefinitionEnv.new(@grammar)
|
227
|
+
env.instance_eval(&block)
|
228
|
+
@grammar.end_precedence_declaration env.reverse
|
229
|
+
end
|
230
|
+
|
231
|
+
def method_missing(mid, *args, &block)
|
232
|
+
unless mid.to_s[-1,1] == '='
|
233
|
+
super # raises NoMethodError
|
234
|
+
end
|
235
|
+
target = @grammar.intern(mid.to_s.chop.intern)
|
236
|
+
unless args.size == 1
|
237
|
+
raise ArgumentError, "too many arguments for #{mid} (#{args.size} for 1)"
|
238
|
+
end
|
239
|
+
_add target, args.first
|
240
|
+
end
|
241
|
+
|
242
|
+
def _add(target, x)
|
243
|
+
case x
|
244
|
+
when Sym
|
245
|
+
@delayed.each do |rule|
|
246
|
+
rule.replace x, target if rule.target == x
|
247
|
+
end
|
248
|
+
@grammar.symboltable.delete x
|
249
|
+
else
|
250
|
+
x.each_rule do |r|
|
251
|
+
r.target = target
|
252
|
+
@grammar.add r
|
253
|
+
end
|
254
|
+
end
|
255
|
+
flush_delayed
|
256
|
+
end
|
257
|
+
|
258
|
+
def _delayed_add(rule)
|
259
|
+
@delayed.push rule
|
260
|
+
end
|
261
|
+
|
262
|
+
def _added?(sym)
|
263
|
+
@grammar.added?(sym) or @delayed.detect {|r| r.target == sym }
|
264
|
+
end
|
265
|
+
|
266
|
+
def flush_delayed
|
267
|
+
return if @delayed.empty?
|
268
|
+
@delayed.each do |rule|
|
269
|
+
@grammar.add rule
|
270
|
+
end
|
271
|
+
@delayed.clear
|
272
|
+
end
|
273
|
+
|
274
|
+
def seq(*list, &block)
|
275
|
+
Rule.new(nil, list.map {|x| _intern(x) }, UserAction.proc(block))
|
276
|
+
end
|
277
|
+
|
278
|
+
def null(&block)
|
279
|
+
seq(&block)
|
280
|
+
end
|
281
|
+
|
282
|
+
def action(&block)
|
283
|
+
id = "@#{@seqs["action"] += 1}".intern
|
284
|
+
_delayed_add Rule.new(@grammar.intern(id), [], UserAction.proc(block))
|
285
|
+
id
|
286
|
+
end
|
287
|
+
|
288
|
+
alias _ action
|
289
|
+
|
290
|
+
def option(sym, default = nil, &block)
|
291
|
+
_defmetasyntax("option", _intern(sym), block) {|target|
|
292
|
+
seq() { default } | seq(sym)
|
293
|
+
}
|
294
|
+
end
|
295
|
+
|
296
|
+
def many(sym, &block)
|
297
|
+
_defmetasyntax("many", _intern(sym), block) {|target|
|
298
|
+
seq() { [] }\
|
299
|
+
| seq(target, sym) {|list, x| list.push x; list }
|
300
|
+
}
|
301
|
+
end
|
302
|
+
|
303
|
+
def many1(sym, &block)
|
304
|
+
_defmetasyntax("many1", _intern(sym), block) {|target|
|
305
|
+
seq(sym) {|x| [x] }\
|
306
|
+
| seq(target, sym) {|list, x| list.push x; list }
|
307
|
+
}
|
308
|
+
end
|
309
|
+
|
310
|
+
def separated_by(sep, sym, &block)
|
311
|
+
option(separated_by1(sep, sym), [], &block)
|
312
|
+
end
|
313
|
+
|
314
|
+
def separated_by1(sep, sym, &block)
|
315
|
+
_defmetasyntax("separated_by1", _intern(sym), block) {|target|
|
316
|
+
seq(sym) {|x| [x] }\
|
317
|
+
| seq(target, sep, sym) {|list, _, x| list.push x; list }
|
318
|
+
}
|
319
|
+
end
|
320
|
+
|
321
|
+
def _intern(x)
|
322
|
+
case x
|
323
|
+
when Symbol, String
|
324
|
+
@grammar.intern(x)
|
325
|
+
when Racc::Sym
|
326
|
+
x
|
327
|
+
else
|
328
|
+
raise TypeError, "wrong type #{x.class} (expected Symbol/String/Racc::Sym)"
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
private
|
333
|
+
|
334
|
+
def _defmetasyntax(type, id, action, &block)
|
335
|
+
if action
|
336
|
+
idbase = "#{type}@#{id}-#{@seqs[type] += 1}"
|
337
|
+
target = _wrap(idbase, "#{idbase}-core", action)
|
338
|
+
_register("#{idbase}-core", &block)
|
339
|
+
else
|
340
|
+
target = _register("#{type}@#{id}", &block)
|
341
|
+
end
|
342
|
+
@grammar.intern(target)
|
343
|
+
end
|
344
|
+
|
345
|
+
def _register(target_name)
|
346
|
+
target = target_name.intern
|
347
|
+
unless _added?(@grammar.intern(target))
|
348
|
+
yield(target).each_rule do |rule|
|
349
|
+
rule.target = @grammar.intern(target)
|
350
|
+
_delayed_add rule
|
351
|
+
end
|
352
|
+
end
|
353
|
+
target
|
354
|
+
end
|
355
|
+
|
356
|
+
def _wrap(target_name, sym, block)
|
357
|
+
target = target_name.intern
|
358
|
+
_delayed_add Rule.new(@grammar.intern(target),
|
359
|
+
[@grammar.intern(sym.intern)],
|
360
|
+
UserAction.proc(block))
|
361
|
+
target
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
class PrecedenceDefinitionEnv
|
366
|
+
def initialize(g)
|
367
|
+
@grammar = g
|
368
|
+
@prechigh_seen = false
|
369
|
+
@preclow_seen = false
|
370
|
+
@reverse = false
|
371
|
+
end
|
372
|
+
|
373
|
+
attr_reader :reverse
|
374
|
+
|
375
|
+
def higher
|
376
|
+
if @prechigh_seen
|
377
|
+
raise CompileError, "prechigh used twice"
|
378
|
+
end
|
379
|
+
@prechigh_seen = true
|
380
|
+
end
|
381
|
+
|
382
|
+
def lower
|
383
|
+
if @preclow_seen
|
384
|
+
raise CompileError, "preclow used twice"
|
385
|
+
end
|
386
|
+
if @prechigh_seen
|
387
|
+
@reverse = true
|
388
|
+
end
|
389
|
+
@preclow_seen = true
|
390
|
+
end
|
391
|
+
|
392
|
+
def left(*syms)
|
393
|
+
@grammar.declare_precedence :Left, syms.map {|s| @grammar.intern(s) }
|
394
|
+
end
|
395
|
+
|
396
|
+
def right(*syms)
|
397
|
+
@grammar.declare_precedence :Right, syms.map {|s| @grammar.intern(s) }
|
398
|
+
end
|
399
|
+
|
400
|
+
def nonassoc(*syms)
|
401
|
+
@grammar.declare_precedence :Nonassoc, syms.map {|s| @grammar.intern(s)}
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
#
|
406
|
+
# Computation
|
407
|
+
#
|
408
|
+
|
409
|
+
def init
|
410
|
+
return if @closed
|
411
|
+
@closed = true
|
412
|
+
@start ||= @rules.map {|r| r.target }.detect {|sym| not sym.dummy? }
|
413
|
+
raise CompileError, 'no rule in input' if @rules.empty?
|
414
|
+
add_start_rule
|
415
|
+
@rules.freeze
|
416
|
+
fix_ident
|
417
|
+
compute_hash
|
418
|
+
compute_heads
|
419
|
+
determine_terminals
|
420
|
+
compute_nullable_0
|
421
|
+
@symboltable.fix
|
422
|
+
compute_locate
|
423
|
+
@symboltable.each_nonterminal {|t| compute_expand t }
|
424
|
+
compute_nullable
|
425
|
+
compute_useless
|
426
|
+
end
|
427
|
+
|
428
|
+
private
|
429
|
+
|
430
|
+
def add_start_rule
|
431
|
+
r = Rule.new(@symboltable.dummy,
|
432
|
+
[@start, @symboltable.anchor, @symboltable.anchor],
|
433
|
+
UserAction.empty)
|
434
|
+
r.ident = 0
|
435
|
+
r.hash = 0
|
436
|
+
r.precedence = nil
|
437
|
+
@rules.unshift r
|
438
|
+
end
|
439
|
+
|
440
|
+
# Rule#ident
|
441
|
+
# LocationPointer#ident
|
442
|
+
def fix_ident
|
443
|
+
@rules.each_with_index do |rule, idx|
|
444
|
+
rule.ident = idx
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
# Rule#hash
|
449
|
+
def compute_hash
|
450
|
+
hash = 4 # size of dummy rule
|
451
|
+
@rules.each do |rule|
|
452
|
+
rule.hash = hash
|
453
|
+
hash += (rule.size + 1)
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
# Sym#heads
|
458
|
+
def compute_heads
|
459
|
+
@rules.each do |rule|
|
460
|
+
rule.target.heads.push rule.ptrs[0]
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
# Sym#terminal?
|
465
|
+
def determine_terminals
|
466
|
+
@symboltable.each do |s|
|
467
|
+
s.term = s.heads.empty?
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
# Sym#self_null?
|
472
|
+
def compute_nullable_0
|
473
|
+
@symboltable.each do |s|
|
474
|
+
if s.terminal?
|
475
|
+
s.snull = false
|
476
|
+
else
|
477
|
+
s.snull = s.heads.any? {|loc| loc.reduce? }
|
478
|
+
end
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
# Sym#locate
|
483
|
+
def compute_locate
|
484
|
+
@rules.each do |rule|
|
485
|
+
t = nil
|
486
|
+
rule.ptrs.each do |ptr|
|
487
|
+
unless ptr.reduce?
|
488
|
+
tok = ptr.dereference
|
489
|
+
tok.locate.push ptr
|
490
|
+
t = tok if tok.terminal?
|
491
|
+
end
|
492
|
+
end
|
493
|
+
rule.precedence = t
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
# Sym#expand
|
498
|
+
def compute_expand(t)
|
499
|
+
puts "expand> #{t.to_s}" if @debug_symbol
|
500
|
+
t.expand = _compute_expand(t, ISet.new, [])
|
501
|
+
puts "expand< #{t.to_s}: #{t.expand.to_s}" if @debug_symbol
|
502
|
+
end
|
503
|
+
|
504
|
+
def _compute_expand(t, set, lock)
|
505
|
+
if tmp = t.expand
|
506
|
+
set.update tmp
|
507
|
+
return set
|
508
|
+
end
|
509
|
+
tok = nil
|
510
|
+
set.update_a t.heads
|
511
|
+
t.heads.each do |ptr|
|
512
|
+
tok = ptr.dereference
|
513
|
+
if tok and tok.nonterminal?
|
514
|
+
unless lock[tok.ident]
|
515
|
+
lock[tok.ident] = true
|
516
|
+
_compute_expand tok, set, lock
|
517
|
+
end
|
518
|
+
end
|
519
|
+
end
|
520
|
+
set
|
521
|
+
end
|
522
|
+
|
523
|
+
# Sym#nullable?, Rule#nullable?
|
524
|
+
def compute_nullable
|
525
|
+
@rules.each {|r| r.null = false }
|
526
|
+
@symboltable.each {|t| t.null = false }
|
527
|
+
r = @rules.dup
|
528
|
+
s = @symboltable.nonterminals
|
529
|
+
begin
|
530
|
+
rs = r.size
|
531
|
+
ss = s.size
|
532
|
+
check_rules_nullable r
|
533
|
+
check_symbols_nullable s
|
534
|
+
end until rs == r.size and ss == s.size
|
535
|
+
end
|
536
|
+
|
537
|
+
def check_rules_nullable(rules)
|
538
|
+
rules.delete_if do |rule|
|
539
|
+
rule.null = true
|
540
|
+
rule.symbols.each do |t|
|
541
|
+
unless t.nullable?
|
542
|
+
rule.null = false
|
543
|
+
break
|
544
|
+
end
|
545
|
+
end
|
546
|
+
rule.nullable?
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
def check_symbols_nullable(symbols)
|
551
|
+
symbols.delete_if do |sym|
|
552
|
+
sym.heads.each do |ptr|
|
553
|
+
if ptr.rule.nullable?
|
554
|
+
sym.null = true
|
555
|
+
break
|
556
|
+
end
|
557
|
+
end
|
558
|
+
sym.nullable?
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
# Sym#useless?, Rule#useless?
|
563
|
+
# FIXME: what means "useless"?
|
564
|
+
def compute_useless
|
565
|
+
@symboltable.each_terminal {|sym| sym.useless = false }
|
566
|
+
@symboltable.each_nonterminal {|sym| sym.useless = true }
|
567
|
+
@rules.each {|rule| rule.useless = true }
|
568
|
+
r = @rules.dup
|
569
|
+
s = @symboltable.nonterminals
|
570
|
+
begin
|
571
|
+
rs = r.size
|
572
|
+
ss = s.size
|
573
|
+
check_rules_useless r
|
574
|
+
check_symbols_useless s
|
575
|
+
end until r.size == rs and s.size == ss
|
576
|
+
end
|
577
|
+
|
578
|
+
def check_rules_useless(rules)
|
579
|
+
rules.delete_if do |rule|
|
580
|
+
rule.useless = false
|
581
|
+
rule.symbols.each do |sym|
|
582
|
+
if sym.useless?
|
583
|
+
rule.useless = true
|
584
|
+
break
|
585
|
+
end
|
586
|
+
end
|
587
|
+
not rule.useless?
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
def check_symbols_useless(s)
|
592
|
+
s.delete_if do |t|
|
593
|
+
t.heads.each do |ptr|
|
594
|
+
unless ptr.rule.useless?
|
595
|
+
t.useless = false
|
596
|
+
break
|
597
|
+
end
|
598
|
+
end
|
599
|
+
not t.useless?
|
600
|
+
end
|
601
|
+
end
|
602
|
+
|
603
|
+
end # class Grammar
|
604
|
+
|
605
|
+
|
606
|
+
class Rule
|
607
|
+
|
608
|
+
def initialize(target, syms, act)
|
609
|
+
@target = target
|
610
|
+
@symbols = syms
|
611
|
+
@action = act
|
612
|
+
@alternatives = []
|
613
|
+
|
614
|
+
@ident = nil
|
615
|
+
@hash = nil
|
616
|
+
@ptrs = nil
|
617
|
+
@precedence = nil
|
618
|
+
@specified_prec = nil
|
619
|
+
@null = nil
|
620
|
+
@useless = nil
|
621
|
+
end
|
622
|
+
|
623
|
+
attr_accessor :target
|
624
|
+
attr_reader :symbols
|
625
|
+
attr_reader :action
|
626
|
+
|
627
|
+
def |(x)
|
628
|
+
@alternatives.push x.rule
|
629
|
+
self
|
630
|
+
end
|
631
|
+
|
632
|
+
def rule
|
633
|
+
self
|
634
|
+
end
|
635
|
+
|
636
|
+
def each_rule(&block)
|
637
|
+
yield self
|
638
|
+
@alternatives.each(&block)
|
639
|
+
end
|
640
|
+
|
641
|
+
attr_accessor :ident
|
642
|
+
|
643
|
+
attr_reader :hash
|
644
|
+
attr_reader :ptrs
|
645
|
+
|
646
|
+
def hash=(n)
|
647
|
+
@hash = n
|
648
|
+
ptrs = []
|
649
|
+
@symbols.each_with_index do |sym, idx|
|
650
|
+
ptrs.push LocationPointer.new(self, idx, sym)
|
651
|
+
end
|
652
|
+
ptrs.push LocationPointer.new(self, @symbols.size, nil)
|
653
|
+
@ptrs = ptrs
|
654
|
+
end
|
655
|
+
|
656
|
+
def precedence
|
657
|
+
@specified_prec || @precedence
|
658
|
+
end
|
659
|
+
|
660
|
+
def precedence=(sym)
|
661
|
+
@precedence ||= sym
|
662
|
+
end
|
663
|
+
|
664
|
+
def prec(sym, &block)
|
665
|
+
@specified_prec = sym
|
666
|
+
if block
|
667
|
+
unless @action.empty?
|
668
|
+
raise CompileError, 'both of rule action block and prec block given'
|
669
|
+
end
|
670
|
+
@action = UserAction.proc(block)
|
671
|
+
end
|
672
|
+
self
|
673
|
+
end
|
674
|
+
|
675
|
+
attr_accessor :specified_prec
|
676
|
+
|
677
|
+
def nullable?() @null end
|
678
|
+
def null=(n) @null = n end
|
679
|
+
|
680
|
+
def useless?() @useless end
|
681
|
+
def useless=(u) @useless = u end
|
682
|
+
|
683
|
+
def inspect
|
684
|
+
"#<Racc::Rule id=#{@ident} (#{@target})>"
|
685
|
+
end
|
686
|
+
|
687
|
+
def ==(other)
|
688
|
+
other.kind_of?(Rule) and @ident == other.ident
|
689
|
+
end
|
690
|
+
|
691
|
+
def [](idx)
|
692
|
+
@symbols[idx]
|
693
|
+
end
|
694
|
+
|
695
|
+
def size
|
696
|
+
@symbols.size
|
697
|
+
end
|
698
|
+
|
699
|
+
def empty?
|
700
|
+
@symbols.empty?
|
701
|
+
end
|
702
|
+
|
703
|
+
def to_s
|
704
|
+
"#<rule#{@ident}>"
|
705
|
+
end
|
706
|
+
|
707
|
+
def accept?
|
708
|
+
if tok = @symbols[-1]
|
709
|
+
tok.anchor?
|
710
|
+
else
|
711
|
+
false
|
712
|
+
end
|
713
|
+
end
|
714
|
+
|
715
|
+
def each(&block)
|
716
|
+
@symbols.each(&block)
|
717
|
+
end
|
718
|
+
|
719
|
+
def replace(src, dest)
|
720
|
+
@target = dest
|
721
|
+
@symbols = @symbols.map {|s| s == src ? dest : s }
|
722
|
+
end
|
723
|
+
|
724
|
+
end # class Rule
|
725
|
+
|
726
|
+
|
727
|
+
class UserAction
|
728
|
+
|
729
|
+
def UserAction.source_text(src)
|
730
|
+
new(src, nil)
|
731
|
+
end
|
732
|
+
|
733
|
+
def UserAction.proc(pr = nil, &block)
|
734
|
+
if pr and block
|
735
|
+
raise ArgumentError, "both of argument and block given"
|
736
|
+
end
|
737
|
+
new(nil, pr || block)
|
738
|
+
end
|
739
|
+
|
740
|
+
def UserAction.empty
|
741
|
+
new(nil, nil)
|
742
|
+
end
|
743
|
+
|
744
|
+
private_class_method :new
|
745
|
+
|
746
|
+
def initialize(src, proc)
|
747
|
+
@source = src
|
748
|
+
@proc = proc
|
749
|
+
end
|
750
|
+
|
751
|
+
attr_reader :source
|
752
|
+
attr_reader :proc
|
753
|
+
|
754
|
+
def source?
|
755
|
+
not @proc
|
756
|
+
end
|
757
|
+
|
758
|
+
def proc?
|
759
|
+
not @source
|
760
|
+
end
|
761
|
+
|
762
|
+
def empty?
|
763
|
+
not @proc and not @source
|
764
|
+
end
|
765
|
+
|
766
|
+
def name
|
767
|
+
"{action type=#{@source || @proc || 'nil'}}"
|
768
|
+
end
|
769
|
+
|
770
|
+
alias inspect name
|
771
|
+
|
772
|
+
end
|
773
|
+
|
774
|
+
|
775
|
+
class OrMark
|
776
|
+
def initialize(lineno)
|
777
|
+
@lineno = lineno
|
778
|
+
end
|
779
|
+
|
780
|
+
def name
|
781
|
+
'|'
|
782
|
+
end
|
783
|
+
|
784
|
+
alias inspect name
|
785
|
+
|
786
|
+
attr_reader :lineno
|
787
|
+
end
|
788
|
+
|
789
|
+
|
790
|
+
class Prec
|
791
|
+
def initialize(symbol, lineno)
|
792
|
+
@symbol = symbol
|
793
|
+
@lineno = lineno
|
794
|
+
end
|
795
|
+
|
796
|
+
def name
|
797
|
+
"=#{@symbol}"
|
798
|
+
end
|
799
|
+
|
800
|
+
alias inspect name
|
801
|
+
|
802
|
+
attr_reader :symbol
|
803
|
+
attr_reader :lineno
|
804
|
+
end
|
805
|
+
|
806
|
+
|
807
|
+
#
|
808
|
+
# A set of rule and position in it's RHS.
|
809
|
+
# Note that the number of pointers is more than rule's RHS array,
|
810
|
+
# because pointer points right edge of the final symbol when reducing.
|
811
|
+
#
|
812
|
+
class LocationPointer
|
813
|
+
|
814
|
+
def initialize(rule, i, sym)
|
815
|
+
@rule = rule
|
816
|
+
@index = i
|
817
|
+
@symbol = sym
|
818
|
+
@ident = @rule.hash + i
|
819
|
+
@reduce = sym.nil?
|
820
|
+
end
|
821
|
+
|
822
|
+
attr_reader :rule
|
823
|
+
attr_reader :index
|
824
|
+
attr_reader :symbol
|
825
|
+
|
826
|
+
alias dereference symbol
|
827
|
+
|
828
|
+
attr_reader :ident
|
829
|
+
alias hash ident
|
830
|
+
attr_reader :reduce
|
831
|
+
alias reduce? reduce
|
832
|
+
|
833
|
+
def to_s
|
834
|
+
sprintf('(%d,%d %s)',
|
835
|
+
@rule.ident, @index, (reduce?() ? '#' : @symbol.to_s))
|
836
|
+
end
|
837
|
+
|
838
|
+
alias inspect to_s
|
839
|
+
|
840
|
+
def eql?(ot)
|
841
|
+
@hash == ot.hash
|
842
|
+
end
|
843
|
+
|
844
|
+
alias == eql?
|
845
|
+
|
846
|
+
def head?
|
847
|
+
@index == 0
|
848
|
+
end
|
849
|
+
|
850
|
+
def next
|
851
|
+
@rule.ptrs[@index + 1] or ptr_bug!
|
852
|
+
end
|
853
|
+
|
854
|
+
alias increment next
|
855
|
+
|
856
|
+
def before(len)
|
857
|
+
@rule.ptrs[@index - len] or ptr_bug!
|
858
|
+
end
|
859
|
+
|
860
|
+
private
|
861
|
+
|
862
|
+
def ptr_bug!
|
863
|
+
raise "racc: fatal: pointer not exist: self: #{to_s}"
|
864
|
+
end
|
865
|
+
|
866
|
+
end # class LocationPointer
|
867
|
+
|
868
|
+
|
869
|
+
class SymbolTable
|
870
|
+
|
871
|
+
include Enumerable
|
872
|
+
|
873
|
+
def initialize
|
874
|
+
@symbols = [] # :: [Racc::Sym]
|
875
|
+
@cache = {} # :: {(String|Symbol) => Racc::Sym}
|
876
|
+
@dummy = intern(:$start, true)
|
877
|
+
@anchor = intern(false, true) # Symbol ID = 0
|
878
|
+
@error = intern(:error, false) # Symbol ID = 1
|
879
|
+
end
|
880
|
+
|
881
|
+
attr_reader :dummy
|
882
|
+
attr_reader :anchor
|
883
|
+
attr_reader :error
|
884
|
+
|
885
|
+
def [](id)
|
886
|
+
@symbols[id]
|
887
|
+
end
|
888
|
+
|
889
|
+
def intern(val, dummy = false)
|
890
|
+
@cache[val] ||=
|
891
|
+
begin
|
892
|
+
sym = Sym.new(val, dummy)
|
893
|
+
@symbols.push sym
|
894
|
+
sym
|
895
|
+
end
|
896
|
+
end
|
897
|
+
|
898
|
+
attr_reader :symbols
|
899
|
+
alias to_a symbols
|
900
|
+
|
901
|
+
def delete(sym)
|
902
|
+
@symbols.delete sym
|
903
|
+
@cache.delete sym.value
|
904
|
+
end
|
905
|
+
|
906
|
+
attr_reader :nt_base
|
907
|
+
|
908
|
+
def nt_max
|
909
|
+
@symbols.size
|
910
|
+
end
|
911
|
+
|
912
|
+
def each(&block)
|
913
|
+
@symbols.each(&block)
|
914
|
+
end
|
915
|
+
|
916
|
+
def terminals(&block)
|
917
|
+
@symbols[0, @nt_base]
|
918
|
+
end
|
919
|
+
|
920
|
+
def each_terminal(&block)
|
921
|
+
@terms.each(&block)
|
922
|
+
end
|
923
|
+
|
924
|
+
def nonterminals
|
925
|
+
@symbols[@nt_base, @symbols.size - @nt_base]
|
926
|
+
end
|
927
|
+
|
928
|
+
def each_nonterminal(&block)
|
929
|
+
@nterms.each(&block)
|
930
|
+
end
|
931
|
+
|
932
|
+
def fix
|
933
|
+
terms, nterms = @symbols.partition {|s| s.terminal? }
|
934
|
+
@symbols = terms + nterms
|
935
|
+
@terms = terms
|
936
|
+
@nterms = nterms
|
937
|
+
@nt_base = terms.size
|
938
|
+
fix_ident
|
939
|
+
check_terminals
|
940
|
+
end
|
941
|
+
|
942
|
+
private
|
943
|
+
|
944
|
+
def fix_ident
|
945
|
+
@symbols.each_with_index do |t, i|
|
946
|
+
t.ident = i
|
947
|
+
end
|
948
|
+
end
|
949
|
+
|
950
|
+
def check_terminals
|
951
|
+
return unless @symbols.any? {|s| s.should_terminal? }
|
952
|
+
@anchor.should_terminal
|
953
|
+
@error.should_terminal
|
954
|
+
each_terminal do |t|
|
955
|
+
t.should_terminal if t.string_symbol?
|
956
|
+
end
|
957
|
+
each do |s|
|
958
|
+
s.should_terminal if s.assoc
|
959
|
+
end
|
960
|
+
terminals().reject {|t| t.should_terminal? }.each do |t|
|
961
|
+
raise CompileError, "terminal #{t} not declared as terminal"
|
962
|
+
end
|
963
|
+
nonterminals().select {|n| n.should_terminal? }.each do |n|
|
964
|
+
raise CompileError, "symbol #{n} declared as terminal but is not terminal"
|
965
|
+
end
|
966
|
+
end
|
967
|
+
|
968
|
+
end # class SymbolTable
|
969
|
+
|
970
|
+
|
971
|
+
# Stands terminal and nonterminal symbols.
|
972
|
+
class Sym
|
973
|
+
|
974
|
+
def initialize(value, dummyp)
|
975
|
+
@ident = nil
|
976
|
+
@value = value
|
977
|
+
@dummyp = dummyp
|
978
|
+
|
979
|
+
@term = nil
|
980
|
+
@nterm = nil
|
981
|
+
@should_terminal = false
|
982
|
+
@precedence = nil
|
983
|
+
case value
|
984
|
+
when Symbol
|
985
|
+
@to_s = value.to_s
|
986
|
+
@serialized = value.inspect
|
987
|
+
@string = false
|
988
|
+
when String
|
989
|
+
@to_s = value.inspect
|
990
|
+
@serialized = value.dump
|
991
|
+
@string = true
|
992
|
+
when false
|
993
|
+
@to_s = '$end'
|
994
|
+
@serialized = 'false'
|
995
|
+
@string = false
|
996
|
+
else
|
997
|
+
raise ArgumentError, "unknown symbol value: #{value.class}"
|
998
|
+
end
|
999
|
+
|
1000
|
+
@heads = []
|
1001
|
+
@locate = []
|
1002
|
+
@snull = nil
|
1003
|
+
@null = nil
|
1004
|
+
@expand = nil
|
1005
|
+
@useless = nil
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
class << self
|
1009
|
+
def once_writer(nm)
|
1010
|
+
nm = nm.id2name
|
1011
|
+
module_eval(<<-EOS)
|
1012
|
+
def #{nm}=(v)
|
1013
|
+
raise 'racc: fatal: @#{nm} != nil' unless @#{nm}.nil?
|
1014
|
+
@#{nm} = v
|
1015
|
+
end
|
1016
|
+
EOS
|
1017
|
+
end
|
1018
|
+
end
|
1019
|
+
|
1020
|
+
once_writer :ident
|
1021
|
+
attr_reader :ident
|
1022
|
+
|
1023
|
+
alias hash ident
|
1024
|
+
|
1025
|
+
attr_reader :value
|
1026
|
+
|
1027
|
+
def dummy?
|
1028
|
+
@dummyp
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
def terminal?
|
1032
|
+
@term
|
1033
|
+
end
|
1034
|
+
|
1035
|
+
def nonterminal?
|
1036
|
+
@nterm
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
def term=(t)
|
1040
|
+
raise 'racc: fatal: term= called twice' unless @term.nil?
|
1041
|
+
@term = t
|
1042
|
+
@nterm = !t
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
def should_terminal
|
1046
|
+
@should_terminal = true
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
def should_terminal?
|
1050
|
+
@should_terminal
|
1051
|
+
end
|
1052
|
+
|
1053
|
+
def string_symbol?
|
1054
|
+
@string
|
1055
|
+
end
|
1056
|
+
|
1057
|
+
def serialize
|
1058
|
+
@serialized
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
attr_writer :serialized
|
1062
|
+
|
1063
|
+
attr_accessor :precedence
|
1064
|
+
attr_accessor :assoc
|
1065
|
+
|
1066
|
+
def to_s
|
1067
|
+
@to_s.dup
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
alias inspect to_s
|
1071
|
+
|
1072
|
+
def |(x)
|
1073
|
+
rule() | x.rule
|
1074
|
+
end
|
1075
|
+
|
1076
|
+
def rule
|
1077
|
+
Rule.new(nil, [self], UserAction.empty)
|
1078
|
+
end
|
1079
|
+
|
1080
|
+
#
|
1081
|
+
# cache
|
1082
|
+
#
|
1083
|
+
|
1084
|
+
attr_reader :heads
|
1085
|
+
attr_reader :locate
|
1086
|
+
|
1087
|
+
def self_null?
|
1088
|
+
@snull
|
1089
|
+
end
|
1090
|
+
|
1091
|
+
once_writer :snull
|
1092
|
+
|
1093
|
+
def nullable?
|
1094
|
+
@null
|
1095
|
+
end
|
1096
|
+
|
1097
|
+
def null=(n)
|
1098
|
+
@null = n
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
attr_reader :expand
|
1102
|
+
once_writer :expand
|
1103
|
+
|
1104
|
+
def useless?
|
1105
|
+
@useless
|
1106
|
+
end
|
1107
|
+
|
1108
|
+
def useless=(f)
|
1109
|
+
@useless = f
|
1110
|
+
end
|
1111
|
+
|
1112
|
+
end # class Sym
|
1113
|
+
|
1114
|
+
end # module Racc
|