lib/rbs/parser.y in rbs-0.16.0 vs lib/rbs/parser.y in rbs-0.17.0
- old
+ new
@@ -1166,18 +1166,25 @@
end
end
def new_token(type, value = input.matched)
charpos = charpos(input)
- start_index = charpos - input.matched.size
- end_index = charpos
+ matched = input.matched
- location = RBS::Location.new(buffer: buffer,
- start_pos: start_index,
- end_pos: end_index)
+ if matched
+ start_index = charpos - matched.size
+ end_index = charpos
- [type, LocatedValue.new(location: location, value: value)]
+ location = RBS::Location.new(buffer: buffer,
+ start_pos: start_index,
+ end_pos: end_index)
+
+ [type, LocatedValue.new(location: location, value: value)]
+ else
+ # scanner hasn't matched yet
+ [false, nil]
+ end
end
def charpos(scanner)
if @ascii_only
scanner.pos
@@ -1292,13 +1299,13 @@
type = @type
@type = nil
return [:"type_#{type}", nil]
end
- return if @eof
+ return new_token(false, '') if @eof
while true
- return if input.eos?
+ return new_token(false, '') if input.eos?
case
when input.scan(/\s+/)
# skip
when input.scan(/#(( *)|( ?(?<string>.*)))\n/)