@@ -47,6 +47,9 @@ export interface StreamParser<State> {
4747 /// token name that exists as a property in this object, the
4848 /// corresponding tags will be assigned to the token.
4949 tokenTable ?: { [ name : string ] : Tag | readonly Tag [ ] }
50+ /// By default, adjacent tokens of the same type are merged in the
51+ /// output tree. Set this to false to disable that.
52+ mergeTokens ?: boolean
5053}
5154
5255function fullParser < State > ( spec : StreamParser < State > ) : Required < StreamParser < State > > {
@@ -58,7 +61,8 @@ function fullParser<State>(spec: StreamParser<State>): Required<StreamParser<Sta
5861 copyState : spec . copyState || defaultCopyState ,
5962 indent : spec . indent || ( ( ) => null ) ,
6063 languageData : spec . languageData || { } ,
61- tokenTable : spec . tokenTable || noTokens
64+ tokenTable : spec . tokenTable || noTokens ,
65+ mergeTokens : spec . mergeTokens !== false
6266 }
6367}
6468
@@ -288,7 +292,8 @@ class Parse<State> implements PartialParse {
288292 size += this . chunk . length - len0
289293 }
290294 let last = this . chunk . length - 4
291- if ( size == 4 && last >= 0 && this . chunk [ last ] == id && this . chunk [ last + 2 ] == from )
295+ if ( this . lang . streamParser . mergeTokens && size == 4 && last >= 0 &&
296+ this . chunk [ last ] == id && this . chunk [ last + 2 ] == from )
292297 this . chunk [ last + 2 ] = to
293298 else
294299 this . chunk . push ( id , from , to , size )
0 commit comments