Class: Yayaml::Handler
- Inherits:
-
Psych::Handler
- Object
- Psych::Handler
- Yayaml::Handler
- Defined in:
- lib/yayaml/handler.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
State transitions: branch -> start_map -> branch (no-op) leaf -> start_map -> branch (no-op) branch -> scalar -> leaf (push key) leaf -> scalar -> leaf (pop key, handle value) branch -> end_map -> branch (pop key) leaf -> end_map -> branch (pop key).
-
#matcher ⇒ Object
readonly
State transitions: branch -> start_map -> branch (no-op) leaf -> start_map -> branch (no-op) branch -> scalar -> leaf (push key) leaf -> scalar -> leaf (pop key, handle value) branch -> end_map -> branch (pop key) leaf -> end_map -> branch (pop key).
Instance Method Summary collapse
- #end_mapping ⇒ Object
- #event_location(start_line, start_column, end_line, end_column) ⇒ Object
-
#initialize(matcher, filename: nil) ⇒ Handler
constructor
A new instance of Handler.
- #scalar(value, *args) ⇒ Object
- #start_document(*args) ⇒ Object
- #start_mapping(*args) ⇒ Object
Constructor Details
#initialize(matcher, filename: nil) ⇒ Handler
Returns a new instance of Handler.
15 16 17 18 |
# File 'lib/yayaml/handler.rb', line 15 def initialize(matcher, filename: nil) @matcher = matcher @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
State transitions: branch -> start_map -> branch (no-op) leaf -> start_map -> branch (no-op) branch -> scalar -> leaf (push key) leaf -> scalar -> leaf (pop key, handle value) branch -> end_map -> branch (pop key) leaf -> end_map -> branch (pop key)
13 14 15 |
# File 'lib/yayaml/handler.rb', line 13 def filename @filename end |
#matcher ⇒ Object (readonly)
State transitions: branch -> start_map -> branch (no-op) leaf -> start_map -> branch (no-op) branch -> scalar -> leaf (push key) leaf -> scalar -> leaf (pop key, handle value) branch -> end_map -> branch (pop key) leaf -> end_map -> branch (pop key)
13 14 15 |
# File 'lib/yayaml/handler.rb', line 13 def matcher @matcher end |
Instance Method Details
#end_mapping ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/yayaml/handler.rb', line 41 def end_mapping transition("end map") do case @state when :branch, :leaf @state = :branch @keys.pop else panic("end_mapping") end end end |
#event_location(start_line, start_column, end_line, end_column) ⇒ Object
69 70 71 72 |
# File 'lib/yayaml/handler.rb', line 69 def event_location(start_line, start_column, end_line, end_column) @line = start_line + 1 @col = start_column + 1 end |
#scalar(value, *args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/yayaml/handler.rb', line 53 def scalar(value, *args) transition("scalar") do case @state when :branch @state = :leaf @keys.push(value) when :leaf @state = :branch matcher.on_node(@keys.dup, value) @keys.pop else panic("scalar") end end end |
#start_document(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/yayaml/handler.rb', line 20 def start_document(*args) debug "--> Start document #{filename}" @state = :branch @prev = nil @keys = [] @line = 0 @col = 0 end |
#start_mapping(*args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/yayaml/handler.rb', line 30 def start_mapping(*args) transition("start map") do case @state when :branch, :leaf @state = :branch else panic("start_mapping") end end end |