@@ -54,30 +54,34 @@ export class CstNodeBuilder {
5454 }
5555 }
5656
57- addHiddenNode ( token : IToken ) : void {
58- const leafNode = new LeafCstNodeImpl ( token . startOffset , token . image . length , tokenToRange ( token ) , token . tokenType , true ) ;
59- leafNode . root = this . rootNode ;
57+ addHiddenNodes ( tokens : IToken [ ] ) : void {
58+ const nodes : LeafCstNode [ ] = [ ] ;
59+ for ( const token of tokens ) {
60+ const leafNode = new LeafCstNodeImpl ( token . startOffset , token . image . length , tokenToRange ( token ) , token . tokenType , true ) ;
61+ leafNode . root = this . rootNode ;
62+ nodes . push ( leafNode ) ;
63+ }
6064 let current : CompositeCstNode = this . current ;
6165 let added = false ;
62- // If we are within a composite node, we add the hidden node to the content
66+ // If we are within a composite node, we add the hidden nodes to the content
6367 if ( current . content . length > 0 ) {
64- current . content . push ( leafNode ) ;
68+ current . content . push ( ... nodes ) ;
6569 return ;
6670 }
6771 while ( current . container ) {
6872 const index = current . container . content . indexOf ( current ) ;
6973 if ( index > 0 ) {
70- // Add the hidden node before the current node
71- current . container . content . splice ( index , 0 , leafNode ) ;
74+ // Add the hidden nodes before the current node
75+ current . container . content . splice ( index , 0 , ... nodes ) ;
7276 added = true ;
7377 break ;
7478 }
7579 current = current . container ;
7680 }
77- // If we arrive at the root node, we add the hidden node at the beginning
78- // This is the case if the hidden node is the first node in the tree
81+ // If we arrive at the root node, we add the hidden nodes at the beginning
82+ // This is the case if the hidden nodes are the first nodes in the tree
7983 if ( ! added ) {
80- this . rootNode . content . unshift ( leafNode ) ;
84+ this . rootNode . content . unshift ( ... nodes ) ;
8185 }
8286 }
8387
0 commit comments