PrestonKnopp / tree-sitter-godot-resource

Godot resource grammar for tree-sitter. Parses tscn, tres, and project.godot files.
https://www.npmjs.com/package/tree-sitter-godot-resource
MIT License
12 stars 2 forks source link

Parsing mistake for arrays in resource files #3

Open MathrimC opened 4 months ago

MathrimC commented 4 months ago

The square brackets used for the array type incorrectly trigger a new section in the language tree.

Here's an example. I defined a custom resource type containing an array:

class_name TestResource
extends Resource

@export var test_array: Array[int]

This is an example of what the resource file looks like:

[gd_resource type="Resource" script_class="TestResource" load_steps=2 format=3 uid="uid://8w1p11bcyooo"]

[ext_resource type="Script" path="res://test_resource.gd" id="1_rtd2s"]

[resource]
script = ExtResource("1_rtd2s")
test_array = Array[int]([42, 76])

This is what the tree looks like:

(section) ; [1:1 - 104]
 (identifier) ; [1:2 - 12]
 (attribute) ; [1:14 - 28]
  (identifier) ; [1:14 - 17]
  (string) ; [1:19 - 28]
 (attribute) ; [1:30 - 56]
  (identifier) ; [1:30 - 41]
  (string) ; [1:43 - 56]
 (attribute) ; [1:58 - 69]
  (identifier) ; [1:58 - 67]
  (integer) ; [1:69 - 69]
 (attribute) ; [1:71 - 78]
  (identifier) ; [1:71 - 76]
  (integer) ; [1:78 - 78]
 (attribute) ; [1:80 - 103]
  (identifier) ; [1:80 - 82]
  (string) ; [1:84 - 103]
(section) ; [3:1 - 71]
 (identifier) ; [3:2 - 13]
 (attribute) ; [3:15 - 27]
  (identifier) ; [3:15 - 18]
  (string) ; [3:20 - 27]
 (attribute) ; [3:29 - 57]
  (identifier) ; [3:29 - 32]
  (string) ; [3:34 - 57]
 (attribute) ; [3:59 - 70]
  (identifier) ; [3:59 - 60]
  (string) ; [3:62 - 70]
(section) ; [5:1 - 7:18]
 (identifier) ; [5:2 - 9]
 (property) ; [6:1 - 31]
  (path) ; [6:1 - 6]
  (constructor) ; [6:10 - 31]
   (identifier) ; [6:10 - 20]
   (arguments) ; [6:21 - 31]
    (string) ; [6:22 - 30]
 (property) ; [7:1 - 18]
  (path) ; [7:1 - 10]
  (identifier) ; [7:14 - 18]
(section) ; [7:19 - 23]
 (identifier) ; [7:20 - 22]
(ERROR) ; [7:24 - 33]
 (integer) ; [7:26 - 27]
 (integer) ; [7:30 - 31]

[int] is wrongly parsed as (section) ; [7:19 - 23]. Also, it results in an (ERROR) node for what follows after.

PrestonKnopp commented 4 months ago

Thanks for posting an issue.

Looks like (constructor) node needs to parse generic type arguments.