Class: Hjson::AST::Parser
- Inherits:
-
Object
- Object
- Hjson::AST::Parser
- Extended by:
- Forwardable
- Defined in:
- lib/hjson/ast/parser.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
- .declare(var, val = nil, &block) ⇒ Object
- .declared_vars ⇒ Object
- .parser(&parser) ⇒ Object
- .parsers ⇒ Object
- .rule(name, &block) ⇒ Object
Instance Method Summary collapse
-
#initialize(buffer, **options) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(buffer, **options) ⇒ Parser
Returns a new instance of Parser.
41 42 43 44 45 46 |
# File 'lib/hjson/ast/parser.rb', line 41 def initialize(buffer, **) @buffer = buffer @payload = nil @options = assign_declared_vars! end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
8 9 10 |
# File 'lib/hjson/ast/parser.rb', line 8 def buffer @buffer end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/hjson/ast/parser.rb', line 8 def @options end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
8 9 10 |
# File 'lib/hjson/ast/parser.rb', line 8 def payload @payload end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/hjson/ast/parser.rb', line 8 def source @source end |
Class Method Details
.declare(var, val = nil, &block) ⇒ Object
26 27 28 |
# File 'lib/hjson/ast/parser.rb', line 26 def self.declare(var, val = nil, &block) declared_vars[var] = block_given? ? block : val end |
.declared_vars ⇒ Object
22 23 24 |
# File 'lib/hjson/ast/parser.rb', line 22 def self.declared_vars @declared_vars ||= {} end |
.parser(&parser) ⇒ Object
18 19 20 |
# File 'lib/hjson/ast/parser.rb', line 18 def self.parser(&parser) parsers << parser end |
.parsers ⇒ Object
14 15 16 |
# File 'lib/hjson/ast/parser.rb', line 14 def self.parsers @parsers ||= [] end |
.rule(name, &block) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/hjson/ast/parser.rb', line 30 def self.rule(name, &block) define_method(:"#{name}?") do |c = nil| c = char unless c instance_exec(c, &block) end end |
Instance Method Details
#parse ⇒ Object
37 38 39 |
# File 'lib/hjson/ast/parser.rb', line 37 def parse catch(:halt) { parsers.reduce(nil) { |_, parser| instance_eval(&parser) } } end |