Class: Ibex::Runtime::CST::SyntaxToken
- Inherits:
-
Object
- Object
- Ibex::Runtime::CST::SyntaxToken
- Defined in:
- lib/ibex/runtime/cst/syntax_token.rb
Overview
Lightweight Red facade for one Green token occurrence.
Instance Attribute Summary collapse
-
#green ⇒ Object
readonly
: GreenToken.
-
#index ⇒ Object
readonly
: Integer.
-
#offset ⇒ Object
readonly
: Integer.
-
#parent ⇒ Object
readonly
: SyntaxNode.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #children ⇒ Object
- #contains_error? ⇒ Boolean
- #deconstruct ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #error? ⇒ Boolean
- #full_span ⇒ Object
- #full_text ⇒ Object (also: #to_source)
-
#initialize(green:, parent:, index:, offset:) ⇒ SyntaxToken
constructor
A new instance of SyntaxToken.
- #kind ⇒ Object
- #kind_name ⇒ Object
- #leading_trivia ⇒ Object
- #location ⇒ Object
- #missing? ⇒ Boolean
- #next_sibling ⇒ Object
- #prev_sibling ⇒ Object
- #replace_with(replacement) ⇒ Object
- #root ⇒ Object
- #same_node?(other) ⇒ Boolean
- #span ⇒ Object
- #symbol ⇒ Object
- #text ⇒ Object
- #to_h ⇒ Object
-
#value ⇒ Object
Compatibility projection for the legacy token API.
- #with_leading(trivia) ⇒ Object
- #with_text(value) ⇒ Object
- #with_trailing(trivia) ⇒ Object
Constructor Details
#initialize(green:, parent:, index:, offset:) ⇒ SyntaxToken
Returns a new instance of SyntaxToken.
20 21 22 23 24 25 26 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 20 def initialize(green:, parent:, index:, offset:) @green = green @parent = parent @index = index @offset = offset freeze end |
Instance Attribute Details
#green ⇒ Object (readonly)
: GreenToken
14 15 16 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 14 def green @green end |
#index ⇒ Object (readonly)
: Integer
16 17 18 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 16 def index @index end |
#offset ⇒ Object (readonly)
: Integer
17 18 19 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 17 def offset @offset end |
#parent ⇒ Object (readonly)
: SyntaxNode
15 16 17 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 15 def parent @parent end |
Instance Method Details
#==(other) ⇒ Object
131 132 133 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 131 def ==(other) other.is_a?(SyntaxToken) && @green == other.green end |
#children ⇒ Object
49 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 49 def children = [] |
#contains_error? ⇒ Boolean
77 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 77 def contains_error? = @green.flags.anybits?(Flags::CONTAINS_ERROR) |
#deconstruct ⇒ Object
136 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 136 def deconstruct = [] |
#deconstruct_keys(_keys) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 139 def deconstruct_keys(_keys) { kind: :token, symbol: symbol, value: value, location: location, leading_trivia: leading_trivia }.freeze end |
#error? ⇒ Boolean
71 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 71 def error? = @parent.kinds.error?(kind) |
#full_span ⇒ Object
56 57 58 59 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 56 def full_span ensure_coordinates! @offset...(@offset + @green.full_width) end |
#full_text ⇒ Object Also known as: to_source
52 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 52 def full_text = @green.to_source |
#kind ⇒ Object
29 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 29 def kind = @green.kind |
#kind_name ⇒ Object
32 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 32 def kind_name = @parent.kinds.name(kind) |
#leading_trivia ⇒ Object
46 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 46 def leading_trivia = @green.leading |
#location ⇒ Object
68 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 68 def location = @parent.source_text.location(span) |
#missing? ⇒ Boolean
74 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 74 def missing? = @green.flags.anybits?(Flags::CONTAINS_MISSING) |
#next_sibling ⇒ Object
113 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 113 def next_sibling = @parent.children[@index + 1] |
#prev_sibling ⇒ Object
116 117 118 119 120 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 116 def prev_sibling return if @index.zero? @parent.children[@index - 1] end |
#replace_with(replacement) ⇒ Object
80 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 80 def replace_with(replacement) = Editing.replace(self, replacement) |
#same_node?(other) ⇒ Boolean
126 127 128 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 126 def same_node?(other) root.equal?(other.root) && @green.equal?(other.green) && @offset == other.offset end |
#span ⇒ Object
62 63 64 65 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 62 def span ensure_coordinates! (@offset + @green.leading_width)...(@offset + @green.full_width - @green.trailing_width) end |
#symbol ⇒ Object
35 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 35 def symbol = kind_name |
#text ⇒ Object
38 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 38 def text = @green.text |
#to_h ⇒ Object
147 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 147 def to_h = deconstruct_keys(nil) |
#value ⇒ Object
Compatibility projection for the legacy token API. Semantic lexer values remain on the parser value path; syntax exposes source bytes.
43 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 43 def value = text |
#with_leading(trivia) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 93 def with_leading(trivia) replace_with( GreenToken.new( kind: @green.kind, text: @green.text, leading: trivia, trailing: @green.trailing, flags: @green.flags, expected_kind: @green.expected_kind ) ) end |
#with_text(value) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 83 def with_text(value) replace_with( GreenToken.new( kind: @green.kind, text: value, leading: @green.leading, trailing: @green.trailing, flags: @green.flags, expected_kind: @green.expected_kind ) ) end |
#with_trailing(trivia) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/ibex/runtime/cst/syntax_token.rb', line 103 def with_trailing(trivia) replace_with( GreenToken.new( kind: @green.kind, text: @green.text, leading: @green.leading, trailing: trivia, flags: @green.flags, expected_kind: @green.expected_kind ) ) end |