@@ -47,6 +47,9 @@ export interface StreamParser<State> {
47
47
/// token name that exists as a property in this object, the
48
48
/// corresponding tags will be assigned to the token.
49
49
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
50
53
}
51
54
52
55
function fullParser < State > ( spec : StreamParser < State > ) : Required < StreamParser < State > > {
@@ -58,7 +61,8 @@ function fullParser<State>(spec: StreamParser<State>): Required<StreamParser<Sta
58
61
copyState : spec . copyState || defaultCopyState ,
59
62
indent : spec . indent || ( ( ) => null ) ,
60
63
languageData : spec . languageData || { } ,
61
- tokenTable : spec . tokenTable || noTokens
64
+ tokenTable : spec . tokenTable || noTokens ,
65
+ mergeTokens : spec . mergeTokens !== false
62
66
}
63
67
}
64
68
@@ -288,7 +292,8 @@ class Parse<State> implements PartialParse {
288
292
size += this . chunk . length - len0
289
293
}
290
294
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 )
292
297
this . chunk [ last + 2 ] = to
293
298
else
294
299
this . chunk . push ( id , from , to , size )
0 commit comments