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

Fix location of MacroExpression nodes #15524

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2806,8 +2806,10 @@ module Crystal

then_node_location = then_node.expressions[1].location.should_not be_nil
then_node_location.line_number.should eq 2
then_node_location.column_number.should eq 5
then_node_location = then_node.expressions[1].end_location.should_not be_nil
then_node_location.line_number.should eq 2
then_node_location.column_number.should eq 13

else_node = node.else.should be_a Expressions
else_node_location = else_node.location.should_not be_nil
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3228,9 +3228,11 @@ module Crystal
when .macro_literal?
pieces << MacroLiteral.new(@token.value.to_s).at(@token.location).at_end(token_end_location)
when .macro_expression_start?
pieces << MacroExpression.new(parse_macro_expression).at(@token.location).at_end(token_end_location)
location = @token.location
exp = MacroExpression.new(parse_macro_expression).at(location)
check_macro_expression_end
skip_whitespace = check_macro_skip_whitespace
pieces << exp.at_end(token_end_location)
when .macro_control_start?
macro_control = parse_macro_control(start_location, macro_state)
if macro_control
Expand Down
Loading