Class: Ibex::Frontend::Segment
- Inherits:
-
Object
- Object
- Ibex::Frontend::Segment
- Defined in:
- lib/ibex/frontend/source_document.rb
Overview
An immutable lexical unit or trivia slice in a concrete syntax tree.
Constant Summary collapse
- TRIVIA_KINDS =
: Array
%i[whitespace newline line_comment block_comment].freeze
- OPAQUE_KINDS =
: Array
%i[action user_code_body].freeze
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
: Symbol.
-
#span ⇒ Object
readonly
: SourceSpan.
-
#text ⇒ Object
readonly
: String.
-
#token_index ⇒ Object
readonly
: Integer?.
-
#token_type ⇒ Object
readonly
: Symbol?.
Instance Method Summary collapse
-
#initialize(kind:, span:, text:, token_type: nil, token_index: nil) ⇒ Segment
constructor
A new instance of Segment.
- #opaque? ⇒ Boolean
- #render ⇒ Object
- #token? ⇒ Boolean
- #trivia? ⇒ Boolean
Constructor Details
#initialize(kind:, span:, text:, token_type: nil, token_index: nil) ⇒ Segment
Returns a new instance of Segment.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ibex/frontend/source_document.rb', line 18 def initialize(kind:, span:, text:, token_type: nil, token_index: nil) raise ArgumentError, "segment text does not match its span" unless text.bytesize == span.length @kind = kind @span = span @text = text.dup.freeze @token_type = token_type @token_index = token_index freeze end |
Instance Attribute Details
#kind ⇒ Object (readonly)
: Symbol
10 11 12 |
# File 'lib/ibex/frontend/source_document.rb', line 10 def kind @kind end |
#span ⇒ Object (readonly)
: SourceSpan
11 12 13 |
# File 'lib/ibex/frontend/source_document.rb', line 11 def span @span end |
#text ⇒ Object (readonly)
: String
12 13 14 |
# File 'lib/ibex/frontend/source_document.rb', line 12 def text @text end |
#token_index ⇒ Object (readonly)
: Integer?
14 15 16 |
# File 'lib/ibex/frontend/source_document.rb', line 14 def token_index @token_index end |
#token_type ⇒ Object (readonly)
: Symbol?
13 14 15 |
# File 'lib/ibex/frontend/source_document.rb', line 13 def token_type @token_type end |
Instance Method Details
#opaque? ⇒ Boolean
35 36 37 |
# File 'lib/ibex/frontend/source_document.rb', line 35 def opaque? OPAQUE_KINDS.include?(kind) end |
#render ⇒ Object
45 46 47 |
# File 'lib/ibex/frontend/source_document.rb', line 45 def render text end |
#token? ⇒ Boolean
40 41 42 |
# File 'lib/ibex/frontend/source_document.rb', line 40 def token? !token_index.nil? end |
#trivia? ⇒ Boolean
30 31 32 |
# File 'lib/ibex/frontend/source_document.rb', line 30 def trivia? TRIVIA_KINDS.include?(kind) end |