Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add ECR::Lexer::SyntaxException with location info #15222

Merged
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
13 changes: 13 additions & 0 deletions src/ecr/lexer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class ECR::Lexer
end
end

class SyntaxException < Exception
getter line_number : Int32
getter column_number : Int32

def initialize(message, @line_number, @column_number)
super(message)
end
end

def initialize(string)
@reader = Char::Reader.new(string)
@token = Token.new
Expand Down Expand Up @@ -198,4 +207,8 @@ class ECR::Lexer
private def string_range(start_pos, end_pos)
@reader.string.byte_slice(start_pos, end_pos - start_pos)
end

private def raise(message : String)
raise SyntaxException.new(message, @line_number, @column_number)
end
end
Loading