@@ -10,13 +10,13 @@ try {
1010}
1111
1212const util = require ( 'util' )
13- const { Query, Parser, NodeMethods, Tree, TreeCursor} = binding ;
13+ const { Query, Parser, NodeMethods, Tree, TreeCursor, LookaheadIterator } = binding ;
1414
1515/*
1616 * Tree
1717 */
1818
19- const { rootNode, edit} = Tree . prototype ;
19+ const { rootNode, rootNodeWithOffset , edit} = Tree . prototype ;
2020
2121Object . defineProperty ( Tree . prototype , 'rootNode' , {
2222 get ( ) {
@@ -36,9 +36,13 @@ Object.defineProperty(Tree.prototype, 'rootNode', {
3636 } ,
3737 // Jest worker pool may attempt to override property due to race condition,
3838 // we don't want to error on this
39- configurable : true
39+ configurable : true
4040} ) ;
4141
42+ Tree . prototype . rootNodeWithOffset = function ( offset_bytes , offset_extent ) {
43+ return unmarshalNode ( rootNodeWithOffset . call ( this , offset_bytes , offset_extent . row , offset_extent . column ) , this ) ;
44+ }
45+
4246Tree . prototype . edit = function ( arg ) {
4347 if ( this instanceof Tree && edit ) {
4448 edit . call (
@@ -75,21 +79,61 @@ class SyntaxNode {
7579 '}'
7680 }
7781
78- get type ( ) {
82+ get id ( ) {
7983 marshalNode ( this ) ;
80- return NodeMethods . type ( this . tree ) ;
84+ return NodeMethods . id ( this . tree ) ;
8185 }
8286
8387 get typeId ( ) {
8488 marshalNode ( this ) ;
8589 return NodeMethods . typeId ( this . tree ) ;
8690 }
8791
92+ get grammarId ( ) {
93+ marshalNode ( this ) ;
94+ return NodeMethods . grammarId ( this . tree ) ;
95+ }
96+
97+ get type ( ) {
98+ marshalNode ( this ) ;
99+ return NodeMethods . type ( this . tree ) ;
100+ }
101+
102+ get grammarName ( ) {
103+ marshalNode ( this ) ;
104+ return NodeMethods . grammarName ( this . tree ) ;
105+ }
106+
107+ get isExtra ( ) {
108+ marshalNode ( this ) ;
109+ return NodeMethods . isExtra ( this . tree ) ;
110+ }
111+
88112 get isNamed ( ) {
89113 marshalNode ( this ) ;
90114 return NodeMethods . isNamed ( this . tree ) ;
91115 }
92116
117+ get isMissing ( ) {
118+ marshalNode ( this ) ;
119+ return NodeMethods . isMissing ( this . tree ) ;
120+ }
121+
122+ get hasChanges ( ) {
123+ marshalNode ( this ) ;
124+ return NodeMethods . hasChanges ( this . tree ) ;
125+ }
126+
127+ get hasError ( ) {
128+ marshalNode ( this ) ;
129+ return NodeMethods . hasError ( this . tree ) ;
130+ }
131+
132+ get isError ( ) {
133+ marshalNode ( this ) ;
134+ return NodeMethods . isError ( this . tree ) ;
135+ }
136+
93137 get text ( ) {
94138 return this . tree . getText ( this ) ;
95139 }
@@ -181,19 +225,19 @@ class SyntaxNode {
181225 return unmarshalNode ( NodeMethods . previousNamedSibling ( this . tree ) , this . tree ) ;
182226 }
183227
184- hasChanges ( ) {
228+ get parseState ( ) {
185229 marshalNode ( this ) ;
186- return NodeMethods . hasChanges ( this . tree ) ;
230+ return NodeMethods . parseState ( this . tree ) ;
187231 }
188232
189- hasError ( ) {
233+ get nextParseState ( ) {
190234 marshalNode ( this ) ;
191- return NodeMethods . hasError ( this . tree ) ;
235+ return NodeMethods . nextParseState ( this . tree ) ;
192236 }
193237
194- isMissing ( ) {
238+ get descendantCount ( ) {
195239 marshalNode ( this ) ;
196- return NodeMethods . isMissing ( this . tree ) ;
240+ return NodeMethods . descendantCount ( this . tree ) ;
197241 }
198242
199243 toString ( ) {
@@ -211,6 +255,31 @@ class SyntaxNode {
211255 return unmarshalNode ( NodeMethods . namedChild ( this . tree , index ) , this . tree ) ;
212256 }
213257
258+ childForFieldName ( fieldName ) {
259+ marshalNode ( this ) ;
260+ return unmarshalNode ( NodeMethods . childForFieldName ( this . tree , fieldName ) , this . tree ) ;
261+ }
262+
263+ childForFieldId ( fieldId ) {
264+ marshalNode ( this ) ;
265+ return unmarshalNode ( NodeMethods . childForFieldId ( this . tree , fieldId ) , this . tree ) ;
266+ }
267+
268+ fieldNameForChild ( childIndex ) {
269+ marshalNode ( this ) ;
270+ return NodeMethods . fieldNameForChild ( this . tree , childIndex ) ;
271+ }
272+
273+ childrenForFieldName ( fieldName , cursor ) {
274+ marshalNode ( this ) ;
275+ return unmarshalNodes ( NodeMethods . childrenForFieldName ( this . tree , fieldName , cursor ) , this . tree ) ;
276+ }
277+
278+ childrenForFieldId ( fieldId ) {
279+ marshalNode ( this ) ;
280+ return unmarshalNodes ( NodeMethods . childrenForFieldId ( this . tree , fieldId ) , this . tree ) ;
281+ }
282+
214283 firstChildForIndex ( index ) {
215284 marshalNode ( this ) ;
216285 return unmarshalNode ( NodeMethods . firstChildForIndex ( this . tree , index ) , this . tree ) ;
@@ -302,7 +371,8 @@ Parser.prototype.parse = function(input, oldTree, {bufferSize, includedRanges}={
302371 input ,
303372 oldTree ,
304373 bufferSize ,
305- includedRanges )
374+ includedRanges ,
375+ )
306376 : undefined ;
307377
308378 if ( tree ) {
@@ -556,11 +626,22 @@ Query.prototype._init = function() {
556626 this . refutedProperties = Object . freeze ( refutedProperties ) ;
557627}
558628
559- Query . prototype . matches = function ( rootNode , startPosition = ZERO_POINT , endPosition = ZERO_POINT ) {
629+ Query . prototype . matches = function (
630+ rootNode ,
631+ {
632+ startPosition = ZERO_POINT ,
633+ endPosition = ZERO_POINT ,
634+ startIndex = 0 ,
635+ endIndex = 0 ,
636+ matchLimit = 0xFFFFFFFF ,
637+ maxStartDepth = 0xFFFFFFFF
638+ } = { }
639+ ) {
560640 marshalNode ( rootNode ) ;
561641 const [ returnedMatches , returnedNodes ] = _matches . call ( this , rootNode . tree ,
562642 startPosition . row , startPosition . column ,
563- endPosition . row , endPosition . column
643+ endPosition . row , endPosition . column ,
644+ startIndex , endIndex , matchLimit , maxStartDepth
564645 ) ;
565646 const nodes = unmarshalNodes ( returnedNodes , rootNode . tree ) ;
566647 const results = [ ] ;
@@ -798,3 +879,4 @@ module.exports.Query = Query;
798879module . exports . Tree = Tree ;
799880module . exports . SyntaxNode = SyntaxNode ;
800881module . exports . TreeCursor = TreeCursor ;
882+ module . exports . LookaheadIterator = LookaheadIterator ;
0 commit comments