Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Parser::LexerError #615

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/rbs/parser.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion lib/rbs/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,11 @@ def next_token
s = input.matched.yield_self {|s| s[1, s.length - 2] }.gsub(/\\'/, "'")
new_token(:tSTRING, s)
else
raise "Unexpected token: #{input.peek(10)}..."
text = input.peek(10)
start_index = charpos(input)
end_index = start_index + text.length
location = RBS::Location.new(buffer: buffer, start_pos: start_index, end_pos: end_index)
raise LexerError.new(input: text, location: location)
end
end

Expand Down Expand Up @@ -1457,4 +1461,15 @@ class SemanticsError < ParsingError
end
end

class LexerError < ParsingError
attr_reader :location, :input

def initialize(input:, location:)
@input = input
@location = location

super "Unexpected string: #{input}..."
end
end

---- footer
7 changes: 7 additions & 0 deletions sig/parser.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ module RBS
def initialize: (token_str: String, error_value: untyped, ?value_stack: untyped?) -> void
end

class LexerError < ParsingError
attr_reader input: String
attr_reader location: Location

def initialize: (input: String, location: Location) -> void
end

class SemanticsError < ParsingError
attr_reader subject: untyped
attr_reader location: Location
Expand Down