@@ -99,9 +99,9 @@ class SyntaxNode {
9999 return NodeMethods . type ( this . tree ) ;
100100 }
101101
102- get grammarName ( ) {
102+ get grammarType ( ) {
103103 marshalNode ( this ) ;
104- return NodeMethods . grammarName ( this . tree ) ;
104+ return NodeMethods . grammarType ( this . tree ) ;
105105 }
106106
107107 get isExtra ( ) {
@@ -270,9 +270,9 @@ class SyntaxNode {
270270 return NodeMethods . fieldNameForChild ( this . tree , childIndex ) ;
271271 }
272272
273- childrenForFieldName ( fieldName , cursor ) {
273+ childrenForFieldName ( fieldName ) {
274274 marshalNode ( this ) ;
275- return unmarshalNodes ( NodeMethods . childrenForFieldName ( this . tree , fieldName , cursor ) , this . tree ) ;
275+ return unmarshalNodes ( NodeMethods . childrenForFieldName ( this . tree , fieldName ) , this . tree ) ;
276276 }
277277
278278 childrenForFieldId ( fieldId ) {
@@ -330,6 +330,7 @@ class SyntaxNode {
330330 marshalNode ( this ) ;
331331 const cursor = NodeMethods . walk ( this . tree ) ;
332332 cursor . tree = this . tree ;
333+ unmarshalNode ( cursor . currentNode , this . tree ) ;
333334 return cursor ;
334335 }
335336}
@@ -352,15 +353,15 @@ Parser.prototype.setLanguage = function(language) {
352353 return this ;
353354} ;
354355
355- Parser . prototype . getLanguage = function ( language ) {
356+ Parser . prototype . getLanguage = function ( _language ) {
356357 return this [ languageSymbol ] || null ;
357358} ;
358359
359360Parser . prototype . parse = function ( input , oldTree , { bufferSize, includedRanges} = { } ) {
360361 let getText , treeInput = input
361362 if ( typeof input === 'string' ) {
362363 const inputString = input ;
363- input = ( offset , position ) => inputString . slice ( offset )
364+ input = ( offset , _position ) => inputString . slice ( offset )
364365 getText = getTextFromString
365366 } else {
366367 getText = getTextFromFunction
@@ -387,7 +388,7 @@ Parser.prototype.parse = function(input, oldTree, {bufferSize, includedRanges}={
387388 * TreeCursor
388389 */
389390
390- const { startPosition, endPosition, currentNode, reset } = TreeCursor . prototype ;
391+ const { startPosition, endPosition, currentNode} = TreeCursor . prototype ;
391392
392393Object . defineProperties ( TreeCursor . prototype , {
393394 currentNode : {
@@ -424,13 +425,6 @@ Object.defineProperties(TreeCursor.prototype, {
424425 }
425426} ) ;
426427
427- TreeCursor . prototype . reset = function ( node ) {
428- marshalNode ( node ) ;
429- if ( this instanceof TreeCursor && reset ) {
430- reset . call ( this ) ;
431- }
432- }
433-
434428/*
435429 * Query
436430 */
@@ -627,7 +621,7 @@ Query.prototype._init = function() {
627621}
628622
629623Query . prototype . matches = function (
630- rootNode ,
624+ node ,
631625 {
632626 startPosition = ZERO_POINT ,
633627 endPosition = ZERO_POINT ,
@@ -637,13 +631,13 @@ Query.prototype.matches = function(
637631 maxStartDepth = 0xFFFFFFFF
638632 } = { }
639633) {
640- marshalNode ( rootNode ) ;
641- const [ returnedMatches , returnedNodes ] = _matches . call ( this , rootNode . tree ,
634+ marshalNode ( node ) ;
635+ const [ returnedMatches , returnedNodes ] = _matches . call ( this , node . tree ,
642636 startPosition . row , startPosition . column ,
643637 endPosition . row , endPosition . column ,
644638 startIndex , endIndex , matchLimit , maxStartDepth
645639 ) ;
646- const nodes = unmarshalNodes ( returnedNodes , rootNode . tree ) ;
640+ const nodes = unmarshalNodes ( returnedNodes , node . tree ) ;
647641 const results = [ ] ;
648642
649643 let i = 0
@@ -675,13 +669,24 @@ Query.prototype.matches = function(
675669 return results ;
676670}
677671
678- Query . prototype . captures = function ( rootNode , startPosition = ZERO_POINT , endPosition = ZERO_POINT ) {
679- marshalNode ( rootNode ) ;
680- const [ returnedMatches , returnedNodes ] = _captures . call ( this , rootNode . tree ,
672+ Query . prototype . captures = function (
673+ node ,
674+ {
675+ startPosition = ZERO_POINT ,
676+ endPosition = ZERO_POINT ,
677+ startIndex = 0 ,
678+ endIndex = 0 ,
679+ matchLimit = 0xFFFFFFFF ,
680+ maxStartDepth = 0xFFFFFFFF
681+ } = { }
682+ ) {
683+ marshalNode ( node ) ;
684+ const [ returnedMatches , returnedNodes ] = _captures . call ( this , node . tree ,
681685 startPosition . row , startPosition . column ,
682- endPosition . row , endPosition . column
686+ endPosition . row , endPosition . column ,
687+ startIndex , endIndex , matchLimit , maxStartDepth
683688 ) ;
684- const nodes = unmarshalNodes ( returnedNodes , rootNode . tree ) ;
689+ const nodes = unmarshalNodes ( returnedNodes , node . tree ) ;
685690 const results = [ ] ;
686691
687692 let i = 0
@@ -714,6 +719,23 @@ Query.prototype.captures = function(rootNode, startPosition = ZERO_POINT, endPos
714719 return results ;
715720}
716721
722+ /*
723+ * LookaheadIterator
724+ */
725+
726+ LookaheadIterator . prototype [ Symbol . iterator ] = function ( ) {
727+ const self = this ;
728+ return {
729+ next ( ) {
730+ if ( self . _next ( ) ) {
731+ return { done : false , value : self . currentType } ;
732+ }
733+
734+ return { done : true , value : '' } ;
735+ } ,
736+ } ;
737+ }
738+
717739/*
718740 * Other functions
719741 */
@@ -730,7 +752,7 @@ function getTextFromFunction ({startIndex, endIndex}) {
730752 const text = input ( startIndex + result . length ) ;
731753 result += text ;
732754 }
733- return result . substr ( 0 , goalLength ) ;
755+ return result . slice ( 0 , goalLength ) ;
734756}
735757
736758const { pointTransferArray} = binding ;
@@ -869,7 +891,7 @@ function initializeLanguageNodeClasses(language) {
869891}
870892
871893function camelCase ( name , upperCase ) {
872- name = name . replace ( / _ ( \w ) / g, ( match , letter ) => letter . toUpperCase ( ) ) ;
894+ name = name . replace ( / _ ( \w ) / g, ( _match , letter ) => letter . toUpperCase ( ) ) ;
873895 if ( upperCase ) name = name [ 0 ] . toUpperCase ( ) + name . slice ( 1 ) ;
874896 return name ;
875897}
0 commit comments