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

Parser: fix wrong/missing locations of various AST nodes #11798

Merged
merged 55 commits into from
Dec 20, 2022
Merged
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
9682141
Parser: fix end location of call name
FnControlOption Oct 23, 2021
92b3b20
Parser: fix location of implicit tuple literal of multi-return
FnControlOption Nov 6, 2021
41d371d
Parser: fix `else_location` of if statement without `else`
FnControlOption Feb 3, 2022
0662d52
Check the text between an AST node's start and end locations
FnControlOption Jan 24, 2022
4a1d081
Parser: fix location of multi-assign if expression
FnControlOption Jan 24, 2022
1fe58da
Parser: fix end location of def with parenthesized parameters
FnControlOption Jan 24, 2022
4e15582
Parser: fix location of global call
FnControlOption Jan 24, 2022
0eadd4a
Parser: fix end location of `#[]=` call
FnControlOption Jan 24, 2022
a6b063b
Parser: fix end location of var with type declaration
FnControlOption Jan 24, 2022
0f56113
Parser: fix end location of `#[]?` call
FnControlOption Jan 24, 2022
930be1c
Parser: fix end location of array literal
FnControlOption Feb 3, 2022
8e54f89
Parser: fix end location of multi-line call with block argument
FnControlOption Feb 3, 2022
c7b1e58
Parser: fix end location of call with receiver and block
FnControlOption Feb 3, 2022
94f5252
Parser: add end location of array literal
FnControlOption Feb 4, 2022
bc085a9
Parser: fix end location of multi-line macro if
FnControlOption Feb 4, 2022
a3dd73a
Parser: add end location of `out` parameter
FnControlOption Feb 4, 2022
84ff78d
Parser: add end location of nilable generic type
FnControlOption Feb 4, 2022
c5b8f8c
Parser: add end location of type with suffix
FnControlOption Feb 4, 2022
b6b1496
Parser: add end location of proc pointer
FnControlOption Feb 4, 2022
cd32b38
Parser: add end location of splat argument
FnControlOption Feb 4, 2022
79b62f8
Parser: add end location of custom array literal
FnControlOption Feb 4, 2022
a154a90
Parser: add end location of negation suffix
FnControlOption Jan 24, 2022
4792a84
Parser: add end location of attribute assignment
FnControlOption Jan 24, 2022
2e94f4f
Parser: add end location of proc type
FnControlOption Jan 24, 2022
7ee0dad
Comment out line to try and fix compiler error
FnControlOption Feb 4, 2022
8863963
Revert "Comment out line to try and fix compiler error"
FnControlOption Feb 4, 2022
9677086
Revert "Parser: add end location of array literal"
FnControlOption Feb 4, 2022
68aaff6
Run `crystal tool format`
FnControlOption Feb 4, 2022
0787432
Re-add end location of array literal
FnControlOption Feb 4, 2022
cab803f
Merge branch 'master' into ast
FnControlOption Nov 18, 2022
4e30c38
Fix error
FnControlOption Nov 18, 2022
db5697e
Apply suggestions from code review
FnControlOption Nov 21, 2022
502d63a
Merge branch 'master' into ast
FnControlOption Nov 21, 2022
5ec08de
Fix off-by-one error
FnControlOption Nov 21, 2022
aed506a
Refactor consume_def_equals_sign_skip_space
FnControlOption Nov 21, 2022
a5ceac7
Merge branch 'master' into ast2
FnControlOption Nov 22, 2022
19cf9b7
Add end location of `require`
FnControlOption Nov 22, 2022
536df1f
Add location of `begin ... end`
FnControlOption Nov 22, 2022
377aa74
Add end location of endless range literal
FnControlOption Nov 22, 2022
a75e424
Add end location of `.responds_to?`
FnControlOption Nov 22, 2022
839c307
Add end location of `.nil?`
FnControlOption Nov 22, 2022
8f76dd4
Add end location of uninitialized var
FnControlOption Nov 22, 2022
981215f
Add end location of trailing `rescue`/`ensure`
FnControlOption Nov 22, 2022
d1407ac
Add end location of property assignment with splat
FnControlOption Nov 22, 2022
89c1958
Don't set end_location in parse_atomic
FnControlOption Nov 22, 2022
0df6a12
Don't change location of exception handler body
FnControlOption Nov 22, 2022
a958e3c
Add end location of local var
FnControlOption Nov 22, 2022
a92f6d5
Merge branch 'master' into ast
FnControlOption Nov 24, 2022
af8d754
Delete `focus: true`
FnControlOption Nov 24, 2022
e3e29e0
Add location of array literal element
FnControlOption Nov 24, 2022
0032caf
Add location of trailing ensure
FnControlOption Nov 24, 2022
b511000
Add location of trailing rescue
FnControlOption Nov 24, 2022
0da7e2e
Delete pseudo `Var#end_location`
FnControlOption Nov 24, 2022
ccb84e3
Add back TypeDeclaration location
FnControlOption Nov 24, 2022
c52c105
Merge branch 'master' into ast
asterite Dec 19, 2022
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
Prev Previous commit
Next Next commit
Merge branch 'master' into ast
  • Loading branch information
FnControlOption committed Nov 18, 2022
commit cab803faaceee999c80bd648b3f363fbeb1d30d8
59 changes: 33 additions & 26 deletions src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
@@ -741,7 +741,7 @@ module Crystal
if current_char == '*'
next_token_skip_space
arg = parse_single_arg
check :")"
check :OP_RPAREN
end_location = token_end_location
next_token
else
@@ -957,7 +957,7 @@ module Crystal

if @token.type.op_lparen?
next_token_skip_space_or_newline
check :")"
check :OP_RPAREN
end_location = token_end_location
next_token_skip_space
end
@@ -1565,7 +1565,7 @@ module Crystal

if check_paren
skip_space_or_newline
check :")"
check :OP_RPAREN
end_location = token_end_location
next_token_skip_space
else
@@ -1970,6 +1970,7 @@ module Crystal
case @token.type
when .ident?
name = @token.value.to_s
global_call = global
end_location = token_end_location
if equals_end_location = consume_def_equals_sign_skip_space
end_location = equals_end_location
@@ -1997,7 +1998,8 @@ module Crystal
end_location = equals_end_location
name = "#{name}="
end
when :INSTANCE_VAR
when .instance_var?
raise "ProcPointer of instance variable cannot be global", location if global
obj = InstanceVar.new(@token.value.to_s)
next_token_skip_space
check :OP_PERIOD
@@ -2007,7 +2009,8 @@ module Crystal
end_location = equals_end_location
name = "#{name}="
end
when :CLASS_VAR
when .class_var?
raise "ProcPointer of class variable cannot be global", location if global
obj = ClassVar.new(@token.value.to_s)
next_token_skip_space
check :OP_PERIOD
@@ -2027,15 +2030,15 @@ module Crystal

if @token.type.op_lparen?
next_token_skip_space
types = parse_union_types(:")")
check :")"
types = parse_union_types(:OP_RPAREN)
check :OP_RPAREN
end_location = token_end_location
next_token_skip_space
else
types = [] of ASTNode
end

ProcPointer.new(obj, name, types).at_end(end_location)
ProcPointer.new(obj, name, types, !!global_call).at_end(end_location)
end

record Piece,
@@ -2377,7 +2380,7 @@ module Crystal
case @token.type
when .string?
strings << klass.new(@token.value.to_s)
when :STRING_ARRAY_END
when .string_array_end?
end_location = token_end_location
next_token
break
@@ -4108,13 +4111,13 @@ module Crystal

else_location = nil
a_else = nil
if @token.type == :IDENT
if @token.type.ident?
case @token.value
when :else
when Keyword::ELSE
else_location = @token.location
next_token_skip_statement_end
a_else = parse_expressions
when :elsif
when Keyword::ELSIF
else_location = @token.location
a_else = parse_if check_end: false
end
@@ -4308,7 +4311,11 @@ module Crystal
if @no_type_declaration == 0 && @token.type.op_colon?
declare_var = parse_type_declaration(Var.new(name).at(location))
end_location = declare_var.end_location
push_var declare_var if @call_args_nest == 0

# Don't declare a local variable if it happens directly as an argument
# of a call, like `property foo : Int32` (we don't want `foo` to be a
# local variable afterwards.)
push_var declare_var unless @call_args_start_locations.includes?(location)
declare_var
elsif (!force_call && is_var)
if @block_arg_name && !@uses_block_arg && name == @block_arg_name
@@ -4824,12 +4831,12 @@ module Crystal
name = @token.value.to_s

case @token.type
when :IDENT
when .ident?
var = Var.new(name)
push_var var
when :INSTANCE_VAR
when .instance_var?
var = InstanceVar.new(name)
when :UNDERSCORE
when .underscore?
var = Underscore.new
else
raise "expecting variable or instance variable after out"
@@ -4845,9 +4852,9 @@ module Crystal
next_token_skip_space_or_newline

case @token.type
when :IDENT
when .ident?
set_visibility parse_var_or_call global: true, location: location
when :CONST
when .const?
ident = parse_generic global: true, location: location, expression: true
parse_custom_literal ident
else
@@ -5005,7 +5012,7 @@ module Crystal
# for expression represents nilable type. Typically such an expression
# is appeared in macro expression. (e.g. `{% if T <= Int32? %} ... {% end %}`)
# Note that the parser cannot consume any spaces because it conflicts ternary operator.
while expression && @token.type == :"?"
while expression && @token.type.op_question?
end_location = token_end_location
next_token
type = make_nilable_expression(type).at_end(end_location)
@@ -5164,20 +5171,20 @@ module Crystal
end_location = token_end_location
next_token_skip_space
type = Metaclass.new(type).at(type).at_end(end_location)
when :"?"
when .op_question?
next_token_skip_space
type = make_nilable_type(type).at_end(end_location)
when :"*"
when .op_star?
next_token_skip_space
type = make_pointer_type(type).at_end(end_location)
when :"**"
when .op_star_star?
next_token_skip_space
type = make_pointer_type(make_pointer_type(type)).at_end(end_location)
when :"["
when .op_lsquare?
next_token_skip_space_or_newline
size = parse_type_arg
skip_space_or_newline
check :"]"
check :OP_RSQUARE
end_location = token_end_location
next_token_skip_space
type = make_static_array_type(type, size).at_end(end_location)
@@ -5190,7 +5197,7 @@ module Crystal
def parse_proc_type_output(input_types, location)
has_output_type = type_start?(consume_newlines: false)

check :"->"
check :OP_MINUS_GT
end_location = token_end_location
next_token_skip_space

@@ -6123,7 +6130,7 @@ module Crystal
def consume_def_equals_sign_skip_space
next_token
end_location = token_end_location
if @token.type == :"="
if @token.type.op_eq?
next_token_skip_space
end_location
else
You are viewing a condensed version of this merge commit. You can view the full changes here.