Skip to content

Comment indentation is parsed incorrectly and affects following lines #85

Description

@NathanLovato

The indentation of comments is currently parsed according to preceding and relative to other statements to try to place comments at the right level but it ends up affecting following lines of code.

For example this code:

func _if_test() -> void:
	if true:
	#if false:
		print("Execution Block for if statement - indented")

produces this AST. The common placement is correct, but notice how the expression statement is lacking one indentation level.

(source [0, 0] - [4, 0]
  (function_definition [0, 0] - [3, 54]
    name: (name [0, 5] - [0, 13])
    parameters: (parameters [0, 13] - [0, 15])
    return_type: (type [0, 19] - [0, 23]
      (identifier [0, 19] - [0, 23]))
    body: (body [0, 24] - [3, 54]
      (if_statement [1, 1] - [1, 9]
        condition: (true [1, 4] - [1, 8])
        body: (body [1, 9] - [1, 9]))
      (comment [2, 1] - [2, 11])
      (expression_statement [3, 2] - [3, 54]
        (call [3, 2] - [3, 54]
          (identifier [3, 2] - [3, 7])
          arguments: (arguments [3, 7] - [3, 54]
            (string [3, 8] - [3, 53])))))))

Then this:

#func _input(event: InputEvent) -> void:
	#if event is InputEventMouseButton:
		#if event.pressed:
			#if event.button_index == MOUSE_BUTTON_RIGHT:
				#print('test')

Places all the comments at zero indentation level, while they should be respectively at 0, 1, 2, 3, and 4.

Related issues:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions