Class: Packcr::Generator
- Inherits:
-
Object
- Object
- Packcr::Generator
- Defined in:
- lib/packcr/generator.rb
Instance Attribute Summary collapse
-
#ascii ⇒ Object
readonly
Returns the value of attribute ascii.
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
- #generate_code(node, onfail, indent, bare) ⇒ Object
- #generate_code_str(node, onfail, indent, bare) ⇒ Object
-
#initialize(rule, ascii, location, lang = :c) ⇒ Generator
constructor
A new instance of Generator.
- #next_label ⇒ Object
- #write(str) ⇒ Object
Constructor Details
#initialize(rule, ascii, location, lang = :c) ⇒ Generator
Returns a new instance of Generator.
7 8 9 10 11 12 13 |
# File 'lib/packcr/generator.rb', line 7 def initialize(rule, ascii, location, lang = :c) @rule = rule @label = 0 @ascii = !!ascii @location = !!location @lang = lang end |
Instance Attribute Details
#ascii ⇒ Object (readonly)
Returns the value of attribute ascii.
5 6 7 |
# File 'lib/packcr/generator.rb', line 5 def ascii @ascii end |
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
5 6 7 |
# File 'lib/packcr/generator.rb', line 5 def lang @lang end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
5 6 7 |
# File 'lib/packcr/generator.rb', line 5 def location @location end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
5 6 7 |
# File 'lib/packcr/generator.rb', line 5 def rule @rule end |
Instance Method Details
#generate_code(node, onfail, indent, bare) ⇒ Object
19 20 21 |
# File 'lib/packcr/generator.rb', line 19 def generate_code(node, onfail, indent, ) node.generate_code(self, onfail, indent, ) end |
#generate_code_str(node, onfail, indent, bare) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/packcr/generator.rb', line 23 def generate_code_str(node, onfail, indent, ) @stream, stream = StringIO.new, @stream begin return generate_code(node, onfail, indent, ), @stream.string ensure @stream = stream end end |
#next_label ⇒ Object
15 16 17 |
# File 'lib/packcr/generator.rb', line 15 def next_label @label += 1 end |
#write(str) ⇒ Object
32 33 34 |
# File 'lib/packcr/generator.rb', line 32 def write(str) @stream.write(str) end |