summaryrefslogtreecommitdiff
path: root/ext/ripper/lib
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-06-12 15:23:47 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-06-12 15:25:06 +0900
commit9593e76ac2cfd9366b8b904df3fc3e1047af3aee (patch)
treeae2db800ff4bc1e7235f4efd3aaf9f801f7352c0 /ext/ripper/lib
parent8354cfd03b1e9961266e1fe56fca481450679b98 (diff)
Ripper::Lexer: fallback parse error token to the previous one
Diffstat (limited to 'ext/ripper/lib')
-rw-r--r--ext/ripper/lib/ripper/lexer.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb
index 696471a75d1..3a2138f310c 100644
--- a/ext/ripper/lib/ripper/lexer.rb
+++ b/ext/ripper/lib/ripper/lexer.rb
@@ -103,7 +103,17 @@ class Ripper
# parse the code and returns elements including errors.
def scan
- (parse() + errors + @stack.flatten).uniq.sort_by {|e| [*e.pos, (e.message ? -1 : 0)]}
+ result = (parse() + errors + @stack.flatten).uniq.sort_by {|e| [*e.pos, (e.message ? -1 : 0)]}
+ result.each_with_index do |e, i|
+ if e.event == :on_parse_error and e.tok.empty? and (pre = result[i-1]) and
+ pre.pos[0] == e.pos[0] and (pre.pos[1] + pre.tok.size) == e.pos[1]
+ e.tok = pre.tok
+ e.pos[1] = pre.pos[1]
+ result[i-1] = e
+ result[i] = pre
+ end
+ end
+ result
end
def parse