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

ECR syntax error raises exception that includes line/column information #15222

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion 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 @@ -123,7 +132,11 @@ class ECR::Lexer

if is_end
setup_control_token(start_pos, is_escape, suppress_leading, true)
raise "Expecting '>' after '-%'" if current_char != '>'

if current_char != '>'
raise "Expecting '>' after '-%'"
end

Comment on lines -126 to +139
Copy link
Contributor

@Sija Sija Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be reverted for a cleaner diff.

next_char
break
end
Expand Down Expand Up @@ -198,4 +211,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