Class: Dms::Tier1::InlineValueParser
- Inherits:
-
Object
- Object
- Dms::Tier1::InlineValueParser
- Defined in:
- lib/dms/tier1.rb
Overview
── InlineValueParser ────────────────────────────────────────────────────
A thin wrapper that delegates value parsing to a real Dms::Parser instance, positioned at a specific offset in the source. We extract the source substring from the current position to end-of-line (plus the rest of the document for block values), parse one value, and map back the consumed bytes.
Instance Attribute Summary collapse
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#line_start ⇒ Object
readonly
Returns the value of attribute line_start.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
-
#initialize(src, start_pos, start_line, start_line_start, outer) ⇒ InlineValueParser
constructor
A new instance of InlineValueParser.
- #parse_one_value ⇒ Object
Constructor Details
#initialize(src, start_pos, start_line, start_line_start, outer) ⇒ InlineValueParser
Returns a new instance of InlineValueParser.
1632 1633 1634 1635 1636 1637 1638 1639 |
# File 'lib/dms/tier1.rb', line 1632 def initialize(src, start_pos, start_line, start_line_start, outer) @src = src @pos = start_pos @line = start_line @line_start = start_line_start @outer = outer @len = src.bytesize end |
Instance Attribute Details
#line ⇒ Object (readonly)
Returns the value of attribute line.
1630 1631 1632 |
# File 'lib/dms/tier1.rb', line 1630 def line @line end |
#line_start ⇒ Object (readonly)
Returns the value of attribute line_start.
1630 1631 1632 |
# File 'lib/dms/tier1.rb', line 1630 def line_start @line_start end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
1630 1631 1632 |
# File 'lib/dms/tier1.rb', line 1630 def pos @pos end |
Instance Method Details
#parse_one_value ⇒ Object
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 |
# File 'lib/dms/tier1.rb', line 1641 def parse_one_value # Build a sub-source from @pos onwards, but we need an offset trick. # We'll use Dms::Parser directly, padding the prefix with spaces so # line numbers are approximately correct. Since error messages in # parameter parsing use the outer parser's position, this is fine. sub_src = @src.byteslice(@pos, @len - @pos).force_encoding("UTF-8") # Use a real Parser in lite mode to parse one value. # We only need one token; the parser will stop at the right place. p = SingleValueParser.new(sub_src) val = p.parse_value_at_start consumed = p.consumed # Update position new_src_pos = @pos + consumed # Update line counts based on consumed newlines consumed_src = @src.byteslice(@pos, consumed) consumed_src.each_byte do |b| if b == 0x0A @line += 1 @line_start = @pos + (@src.byteslice(@pos, consumed).index("\n".force_encoding("UTF-8"), 0) || 0) + 1 end end # Recount properly @line = 1 + @src.byteslice(0, new_src_pos).count("\n") last_nl = @src.byteslice(0, new_src_pos).rindex("\n") @line_start = last_nl ? last_nl + 1 : 0 @pos = new_src_pos val end |