Class: PositionHandler
- Inherits:
-
Psych::TreeBuilder
- Object
- Psych::TreeBuilder
- PositionHandler
- Defined in:
- lib/traceable.rb
Overview
Extend the parser to remember the position of each object.
Instance Attribute Summary collapse
-
#parser ⇒ Object
The handler needs access to the parser in order to call mark.
Instance Method Summary collapse
-
#initialize(filename) ⇒ PositionHandler
constructor
filenameis the name of the source file the YAML structure will be parsed from. -
#record_position(node, mark) ⇒ Object
Copy a parser position from a
Psych::Parser::Markto a parse tree node. - #scalar(value, anchor, tag, plain, quoted, style) ⇒ Object
- #start_mapping(anchor, tag, implicit, style) ⇒ Object
- #start_sequence(anchor, tag, implicit, style) ⇒ Object
Constructor Details
#initialize(filename) ⇒ PositionHandler
filename is the name of the source file the YAML structure will be parsed from. It is only copied into parsed objects, not interpreted.
128 129 130 131 |
# File 'lib/traceable.rb', line 128 def initialize(filename) super() @file = filename end |
Instance Attribute Details
#parser ⇒ Object
The handler needs access to the parser in order to call mark
123 124 125 |
# File 'lib/traceable.rb', line 123 def parser @parser end |
Instance Method Details
#record_position(node, mark) ⇒ Object
Copy a parser position from a Psych::Parser::Mark to a parse tree node.
135 136 137 138 139 140 141 142 |
# File 'lib/traceable.rb', line 135 def record_position(node, mark) node.extend Traceable node.file = @file node.byte = mark.index node.line = mark.line node.column = mark.column node end |
#scalar(value, anchor, tag, plain, quoted, style) ⇒ Object
152 153 154 |
# File 'lib/traceable.rb', line 152 def scalar(value, anchor, tag, plain, quoted, style) record_position(super, parser.mark) end |
#start_mapping(anchor, tag, implicit, style) ⇒ Object
144 145 146 |
# File 'lib/traceable.rb', line 144 def start_mapping(anchor, tag, implicit, style) record_position(super, parser.mark) end |
#start_sequence(anchor, tag, implicit, style) ⇒ Object
148 149 150 |
# File 'lib/traceable.rb', line 148 def start_sequence(anchor, tag, implicit, style) record_position(super, parser.mark) end |