Class: Ibex::Frontend::CST::Document
- Inherits:
-
Object
- Object
- Ibex::Frontend::CST::Document
- Includes:
- Enumerable, Enumerable[Segment]
- Defined in:
- lib/ibex/frontend/source_document.rb,
sig/ibex/frontend/source_document.rbs
Overview
The immutable lexical root of a grammar source document.
Instance Attribute Summary collapse
- #segments ⇒ Array[Segment] readonly
Instance Method Summary collapse
- #each {|arg0| ... } ⇒ Object
-
#initialize(segments) ⇒ Document
constructor
A new instance of Document.
- #render ⇒ String
- #validate_contiguous(segments) ⇒ void
Constructor Details
#initialize(segments) ⇒ Document
Returns a new instance of Document.
60 61 62 63 64 |
# File 'lib/ibex/frontend/source_document.rb', line 60 def initialize(segments) validate_contiguous(segments) @segments = segments.dup.freeze freeze end |
Instance Attribute Details
#segments ⇒ Array[Segment] (readonly)
57 58 59 |
# File 'lib/ibex/frontend/source_document.rb', line 57 def segments @segments end |
Instance Method Details
#each ⇒ Enumerator[Segment, Document] #each ⇒ Document
70 71 72 73 74 75 |
# File 'lib/ibex/frontend/source_document.rb', line 70 def each(&block) return enum_for(:each) unless block segments.each(&block) self end |
#render ⇒ String
78 79 80 |
# File 'lib/ibex/frontend/source_document.rb', line 78 def render segments.map(&:render).join end |
#validate_contiguous(segments) ⇒ void
This method returns an undefined value.
85 86 87 88 89 90 91 92 |
# File 'lib/ibex/frontend/source_document.rb', line 85 def validate_contiguous(segments) segments.each_cons(2) do |left, right| next unless left && right next if left.span.end_byte == right.span.start_byte raise ArgumentError, "concrete syntax tree segments must be contiguous" end end |