File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed
core/common/src/internal/format/parser Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -178,11 +178,13 @@ internal fun <T> List<ParserStructure<T>>.concat(): ParserStructure<T> {
178178 }
179179 }
180180
181+ // Combine parsers in reverse order, batching operations from parsers without followedBy.
181182 var result = ParserStructure <T >(emptyList(), emptyList())
182183 val accumulatedOperations = mutableListOf<List <ParserOperation <T >>>()
183184
184185 fun flushAccumulatedOperations () {
185186 if (accumulatedOperations.isNotEmpty()) {
187+ // Reverse to restore the original order (since parsers are processed in reverse).
186188 val operations = buildList {
187189 for (parserOperations in accumulatedOperations.asReversed()) {
188190 addAll(parserOperations)
@@ -195,13 +197,16 @@ internal fun <T> List<ParserStructure<T>>.concat(): ParserStructure<T> {
195197
196198 for (parser in this .asReversed()) {
197199 if (parser.followedBy.isEmpty()) {
200+ // No followedBy: accumulate for batch processing.
198201 accumulatedOperations.add(parser.operations)
199202 } else {
203+ // Has followedBy: flush accumulated operations, then process individually.
200204 flushAccumulatedOperations()
201205 result = parser.simplifyAndAppend(result)
202206 }
203207 }
204208
209+ // Flush remaining accumulated operations.
205210 flushAccumulatedOperations()
206211 return result
207212}
You can’t perform that action at this time.
0 commit comments