Skip to content

Commit 3cdc0da

Browse files
committed
remove input mutation
1 parent 1bdc9b7 commit 3cdc0da

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/dentaku/parser.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def initialize(tokens, options = {})
3737
@arities = options.fetch(:arities, [])
3838
@function_registry = options.fetch(:function_registry, nil)
3939
@case_sensitive = options.fetch(:case_sensitive, false)
40+
@skip_indices = []
4041
end
4142

4243
def consume(count = 2)
@@ -82,6 +83,10 @@ def parse
8283

8384
i = 0
8485
while i < input.length
86+
if @skip_indices.include?(i)
87+
i += 1
88+
next
89+
end
8590
token = input[i]
8691
lookahead = input[i + 1]
8792
process_token(token, lookahead, i, input)
@@ -251,7 +256,9 @@ def handle_grouping(token, lookahead, tokens)
251256
when :open
252257
if lookahead && lookahead.value == :close
253258
# empty grouping (e.g. function with zero arguments) — we trigger consume later
254-
tokens.delete_at(tokens.index(lookahead)) # remove the close to mimic previous shift behavior
259+
# skip to the end
260+
lookahead_index = tokens.index(lookahead)
261+
@skip_indices << lookahead_index if lookahead_index
255262
arities.pop
256263
consume(0)
257264
else

0 commit comments

Comments
 (0)