Skip to content
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
7 changes: 7 additions & 0 deletions src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,13 @@ module Crystal
next_token.tap { @wants_symbol = true }
end

def wants_def_or_macro_name(& : ->)
@wants_def_or_macro_name = true
yield
ensure
@wants_def_or_macro_name = false
end

def current_char
@reader.current_char
end
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,9 @@ module Crystal

@wants_regex = false

@wants_def_or_macro_name = true
next_token_skip_space_or_newline
@wants_def_or_macro_name = false
wants_def_or_macro_name do
next_token_skip_space_or_newline
end

if @token.type.instance_var?
ivar_name = @token.value.to_s
Expand Down Expand Up @@ -6204,10 +6204,10 @@ module Crystal
# cases like: def `, def /, def //
# that in regular statements states for delimiters
# here must be treated as method names.
@wants_def_or_macro_name = true
next_token_skip_space_or_newline
check DefOrMacroCheck1
@wants_def_or_macro_name = false
wants_def_or_macro_name do
next_token_skip_space_or_newline
check DefOrMacroCheck1
end
@token.to_s
end

Expand Down
19 changes: 10 additions & 9 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1464,9 +1464,9 @@ module Crystal
write_token :OP_PERIOD
end

@lexer.wants_def_or_macro_name = true
skip_space_or_newline
@lexer.wants_def_or_macro_name = false
@lexer.wants_def_or_macro_name do
skip_space_or_newline
end

write node.name

Expand Down Expand Up @@ -2671,10 +2671,11 @@ module Crystal
return false
end

@lexer.wants_def_or_macro_name = true
next_token
@lexer.wants_def_or_macro_name = false
@lexer.wants_def_or_macro_name do
next_token
end
skip_space

if (@token.type.newline?) || @wrote_newline
base_indent = @indent + 2
indent(base_indent) { consume_newlines }
Expand Down Expand Up @@ -3106,9 +3107,9 @@ module Crystal
write_token :OP_AMP
skip_space_or_newline
write "."
@lexer.wants_def_or_macro_name = true
next_token_skip_space_or_newline
@lexer.wants_def_or_macro_name = false
@lexer.wants_def_or_macro_name do
next_token_skip_space_or_newline
end

body = node.body
case body
Expand Down