Class: Bison::GrammarFile
- Inherits:
-
Object
- Object
- Bison::GrammarFile
- Defined in:
- lib/bison/grammar_file.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#initialize(tokens, rules, code) ⇒ GrammarFile
constructor
A new instance of GrammarFile.
- #print_actions_module(out = $stdout) ⇒ Object
- #print_base_module(out = $stdout) ⇒ Object
- #print_bison(out = $stdout) ⇒ Object
- #print_class(out = $stdout) ⇒ Object
- #print_extconf(out = $stdout) ⇒ Object
- #uname ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(tokens, rules, code) ⇒ GrammarFile
Returns a new instance of GrammarFile.
9 10 11 |
# File 'lib/bison/grammar_file.rb', line 9 def initialize(tokens, rules, code) @tokens, @rules, @code = tokens, rules, code end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/bison/grammar_file.rb', line 7 def code @code end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/bison/grammar_file.rb', line 6 def name @name end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
7 8 9 |
# File 'lib/bison/grammar_file.rb', line 7 def rules @rules end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
7 8 9 |
# File 'lib/bison/grammar_file.rb', line 7 def tokens @tokens end |
Instance Method Details
#print_actions_module(out = $stdout) ⇒ Object
40 41 42 43 |
# File 'lib/bison/grammar_file.rb', line 40 def print_actions_module(out=$stdout) template = File.('../../../templates/actions.rb.erb', __FILE__) out.puts(ERB.new(File.read(template), nil, '-').result(binding)) end |
#print_base_module(out = $stdout) ⇒ Object
35 36 37 38 |
# File 'lib/bison/grammar_file.rb', line 35 def print_base_module(out=$stdout) template = File.('../../../templates/base.rb.erb', __FILE__) out.puts(ERB.new(File.read(template), nil, '-').result(binding)) end |
#print_bison(out = $stdout) ⇒ Object
45 46 47 48 |
# File 'lib/bison/grammar_file.rb', line 45 def print_bison(out=$stdout) template = File.('../../../templates/parser.y.erb', __FILE__) out.puts(ERB.new(File.read(template), nil, '-').result(binding)) end |
#print_class(out = $stdout) ⇒ Object
30 31 32 33 |
# File 'lib/bison/grammar_file.rb', line 30 def print_class(out=$stdout) template = File.('../../../templates/class.rb.erb', __FILE__) out.puts(ERB.new(File.read(template), nil, '-').result(binding)) end |
#print_extconf(out = $stdout) ⇒ Object
50 51 52 53 |
# File 'lib/bison/grammar_file.rb', line 50 def print_extconf(out=$stdout) template = File.('../../../templates/extconf.rb.erb', __FILE__) out.puts(ERB.new(File.read(template), nil, '-').result(binding)) end |
#uname ⇒ Object
55 56 57 |
# File 'lib/bison/grammar_file.rb', line 55 def uname name.gsub(/([a-z])([A-Z])/, '\1_\2').downcase end |
#validate ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bison/grammar_file.rb', line 13 def validate errors = [] symbols = tokens.map(&:names).flatten + rules.map(&:name) rules.map(&:components).flatten.map(&:elements).flatten.each do |el| unless !(Bison::Nonterminal === el) || symbols.include?(el.name) errors << "#{el.location.join('.')}: #{el.name} is not defined" end end rules.map(&:components).flatten.each do |seq| seq.elements.grep(Bison::Action).each do |action| err = action.errors errors << err unless err.nil? end end abort(errors.join("\n")) unless errors.empty? end |