1///|
2type LookaheadIterator
3
4///|
5extern "js" fn ts_lookahead_iterator_is_null(self : 
type LookaheadIterator
LookaheadIterator
) ->
Bool
Bool
=
6 #|(self) => { 7 #| return self === null || self === undefined; 8 #|} 9 10///| 11impl
trait Nullable {
  is_null(Self) -> Bool
  to_option(Self) -> Self?
}
Nullable
for
type LookaheadIterator
LookaheadIterator
with
(self : LookaheadIterator) -> Bool
is_null
(
LookaheadIterator
self
:
type LookaheadIterator
LookaheadIterator
) ->
Bool
Bool
{
12
(self : LookaheadIterator) -> Bool
ts_lookahead_iterator_is_null
(
LookaheadIterator
self
)
13} 14 15///| 16extern "js" fn ts_lookahead_iterator_new( 17 language :
type Language @tree_sitter_language.Language
Language
,
18 state :
type StateId UInt16
StateId
19) ->
type LookaheadIterator
LookaheadIterator
=
20 #|(language, state) => { 21 #| return language.lookaheadIterator(state); 22 #|} 23 24///| 25/// Create a new lookahead iterator for the given language and parse state. 26/// 27/// This returns `None` if state is invalid for the language. 28/// 29/// Repeatedly using `LookaheadIterator::next` and 30/// `LookaheadIterator::current_symbol` will generate valid symbols in the 31/// given parse state. Newly created lookahead iterators will contain the 32/// `ERROR` symbol. 33/// 34/// Lookahead iterators can be useful to generate suggestions and improve syntax 35/// error diagnostics. To get symbols valid in an ERROR node, use the lookahead 36/// iterator on its first leaf node state. For `MISSING` nodes, a lookahead 37/// iterator created on the previous non-extra leaf node may be appropriate. 38pub fn
type LookaheadIterator
LookaheadIterator
::
(language : Language, state : StateId) -> LookaheadIterator?

Create a new lookahead iterator for the given language and parse state.

This returns None if state is invalid for the language.

Repeatedly using LookaheadIterator::next and LookaheadIterator::current_symbol will generate valid symbols in the given parse state. Newly created lookahead iterators will contain the ERROR symbol.

Lookahead iterators can be useful to generate suggestions and improve syntax error diagnostics. To get symbols valid in an ERROR node, use the lookahead iterator on its first leaf node state. For MISSING nodes, a lookahead iterator created on the previous non-extra leaf node may be appropriate.

new
(
39
Language
language
:
type Language @tree_sitter_language.Language
Language
,
40
StateId
state
:
type StateId UInt16
StateId
41) ->
type LookaheadIterator
LookaheadIterator
? {
42
(language : Language, state : StateId) -> LookaheadIterator
ts_lookahead_iterator_new
(
Language
language
,
StateId
state
).
(self : LookaheadIterator) -> LookaheadIterator?
to_option
()
43} 44 45///| 46/// Reset the lookahead iterator to another state. 47/// 48/// This returns `true` if the iterator was reset to the given state and `false` 49/// otherwise. 50pub extern "js" fn
type LookaheadIterator
LookaheadIterator
::reset_state(
51 self :
type LookaheadIterator
LookaheadIterator
,
52 state :
type StateId UInt16
StateId
53) ->
Bool
Bool
=
54 #|(self, state) => { 55 #| return self.resetState(state); 56 #|} 57 58///| 59/// Reset the lookahead iterator. 60/// 61/// This returns `true` if the language was set successfully and `false` 62/// otherwise. 63pub extern "js" fn
type LookaheadIterator
LookaheadIterator
::reset(
64 self :
type LookaheadIterator
LookaheadIterator
,
65 language :
type Language @tree_sitter_language.Language
Language
,
66 state :
type StateId UInt16
StateId
67) ->
Bool
Bool
=
68 #|(self, language, state) => { 69 #| return self.reset(language, state); 70 #|} 71 72///| 73/// Get the current symbol of the lookahead iterator. 74pub extern "js" fn
type LookaheadIterator
LookaheadIterator
::current_symbol(
75 self :
type LookaheadIterator
LookaheadIterator
76) ->
type Symbol UInt
Symbol
=
77 #|(self) => { 78 #| return self.currentTypeId; 79 #|} 80 81///| 82extern "js" fn ts_lookahead_iterator_current_symbol_name( 83 self :
type LookaheadIterator
LookaheadIterator
84) ->
String
String
=
85 #|(self) => { 86 #| return self.currentType; 87 #|} 88 89///| 90/// Get the current symbol type of the lookahead iterator as a string. 91pub fn
type LookaheadIterator
LookaheadIterator
::
(self : LookaheadIterator) -> @string.StringView?

Get the current symbol type of the lookahead iterator as a string.

current_symbol_name
(
92
LookaheadIterator
self
:
type LookaheadIterator
LookaheadIterator
93) ->
type @string.StringView

A @string.View represents a view of a String that maintains proper Unicode character boundaries. It allows safe access to a substring while handling multi-byte characters correctly.

@string.View
? {
94 let
String?
bytes
=
(self : LookaheadIterator) -> String
ts_lookahead_iterator_current_symbol_name
(
LookaheadIterator
self
).
(self : String) -> String?
to_option
()
95 if
String?
bytes
is
(String) -> String?
Some
(
String
bytes
) {
96
(@string.StringView) -> @string.StringView?
Some
(
String
bytes
)
97 } else { 98
@string.StringView?
None
99 } 100} 101 102///| 103/// true <=> IterContinue 104/// false <=> IterEnd 105extern "js" fn ts_lookahead_iterator_symbol_names( 106 self :
type LookaheadIterator
LookaheadIterator
,
107 f : (
String
String
) ->
Bool
Bool
108) ->
Bool
Bool
=
109 #|(self, f) => { 110 #| for (const name of self) { 111 #| if (!f(name)) { 112 #| return false; 113 #| } else { 114 #| continue; 115 #| } 116 #| } 117 #| return true; 118 #|} 119 120///| 121pub fn
type LookaheadIterator
LookaheadIterator
::
(self : LookaheadIterator) -> Iter[String]
symbol_names
(
122
LookaheadIterator
self
:
type LookaheadIterator
LookaheadIterator
123) ->
type Iter[T]
Iter
[
String
String
] {
124
type Iter[T]
Iter
::
(((String) -> IterResult) -> IterResult) -> Iter[String]

Do not use this method, it is for internal use only.

new
(fn(
(String) -> IterResult
yield_
) {
125 if
(self : LookaheadIterator, f : (String) -> Bool) -> Bool

true <=> IterContinue false <=> IterEnd

ts_lookahead_iterator_symbol_names
(
LookaheadIterator
self
, fn(
String
name
) {
126 match
(String) -> IterResult
yield_
(
String
name
) {
127
IterResult
IterContinue
=> true
128
IterResult
IterEnd
=> false
129 } 130 }) { 131
IterResult
IterContinue
132 } else { 133
IterResult
IterEnd
134 } 135 }) 136} 137