Commit bebc3f3
committed
Handle shorthand syntax in explanations
When performing a performance test on https://github.com/kddnewton/syntax_tree/blob/50f9fc1b815156bdde53f13d4f250d9522f15e64/test/syntax_tree_test.rb I noticed a strange output. The explain syntax indicated that it was missing a bracket when I had only deleted an `end`:
```
$ time DEAD_END_TIMEOUT=10 ./exe/dead_end spec/fixtures/syntax_tree.rb.txt
--> /Users/rschneeman/Documents/projects/dead_end/spec/fixtures/syntax_tree.rb.txt
Unmatched `]', missing `[' ?
Unmatched keyword, missing `end' ?
6 class SyntaxTree < Ripper
170 def self.parse(source)
174 end
176 private
❯ 754 def on_args_add(arguments, argument)
❯ 776 class ArgsAddBlock
❯ 810 end
9233 end
DEAD_END_TIMEOUT=10 ./exe/dead_end spec/fixtures/syntax_tree.rb.txt 1.63s user 0.07s system 99% cpu 1.703 total
```
The cause was this line:
```
node.is_a?(Op) && %w[| ||].include?(node.value) &&
```
With the `%w[]` syntax the lexer tokenizes `%w[` which *since it doesn't match `[`) is not counted.
This commit corrects that logic by explicitly looking for the last character of these events.1 parent da3596a commit bebc3f3
File tree
3 files changed
+25
-0
lines changed- lib/dead_end
- spec/unit
3 files changed
+25
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
64 | 75 | | |
65 | 76 | | |
66 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
7 | 19 | | |
8 | 20 | | |
9 | 21 | | |
| |||
0 commit comments