@papercraftgames/estragon 0.1.0-beta.3 → 0.1.0-beta.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/CHANGELOG.md +7 -3
  2. package/README.md +11 -8
  3. package/addons/estragon/compiler/bindable.gd +3 -3
  4. package/addons/estragon/compiler/compiler.gd +8 -8
  5. package/addons/estragon/compiler/composition.gd +15 -10
  6. package/addons/estragon/compiler/emitter.gd +224 -19
  7. package/addons/estragon/compiler/frontend.gd +14 -8
  8. package/addons/estragon/compiler/import_aliases.gd +64 -0
  9. package/addons/estragon/compiler/import_aliases.gd.uid +1 -0
  10. package/addons/estragon/compiler/layouts.gd +412 -0
  11. package/addons/estragon/compiler/layouts.gd.uid +1 -0
  12. package/addons/estragon/compiler/lexer.gd +3 -2
  13. package/addons/estragon/compiler/model.gd +43 -0
  14. package/addons/estragon/compiler/native/resolver.gd +166 -66
  15. package/addons/estragon/compiler/parser.gd +102 -13
  16. package/addons/estragon/compiler/project_sources.gd +91 -0
  17. package/addons/estragon/compiler/project_sources.gd.uid +1 -0
  18. package/addons/estragon/compiler/render_calls.gd +354 -0
  19. package/addons/estragon/compiler/render_calls.gd.uid +1 -0
  20. package/addons/estragon/compiler/script_validation.gd +3 -3
  21. package/addons/estragon/compiler/source.gd +19 -2
  22. package/addons/estragon/compiler/source_map.gd +3 -3
  23. package/addons/estragon/compiler/validator.gd +193 -40
  24. package/addons/estragon/editor/build_service.gd +91 -72
  25. package/addons/estragon/editor/color_property.gd +37 -0
  26. package/addons/estragon/editor/color_property.gd.uid +1 -0
  27. package/addons/estragon/editor/completion.gd +585 -0
  28. package/addons/estragon/editor/completion.gd.uid +1 -0
  29. package/addons/estragon/editor/completion_edit.gd +7 -0
  30. package/addons/estragon/editor/completion_edit.gd.uid +1 -0
  31. package/addons/estragon/editor/components.gd +22 -0
  32. package/addons/estragon/editor/components.gd.uid +1 -0
  33. package/addons/estragon/editor/creation_menu.gd.txt +14 -0
  34. package/addons/estragon/editor/format_edit.gd +54 -0
  35. package/addons/estragon/editor/format_edit.gd.uid +1 -0
  36. package/addons/estragon/editor/formatter.gd +166 -0
  37. package/addons/estragon/editor/formatter.gd.uid +1 -0
  38. package/addons/estragon/editor/generated_editors.gd +256 -0
  39. package/addons/estragon/editor/generated_editors.gd.uid +1 -0
  40. package/addons/estragon/editor/highlighter.gd +62 -103
  41. package/addons/estragon/editor/highlighter_association.gd +11 -2
  42. package/addons/estragon/editor/imports.gd +51 -0
  43. package/addons/estragon/editor/imports.gd.uid +1 -0
  44. package/addons/estragon/editor/language_services.gd +331 -0
  45. package/addons/estragon/editor/language_services.gd.uid +1 -0
  46. package/addons/estragon/editor/length_property.gd +22 -0
  47. package/addons/estragon/editor/length_property.gd.uid +1 -0
  48. package/addons/estragon/editor/lexical_context.gd +163 -0
  49. package/addons/estragon/editor/lexical_context.gd.uid +1 -0
  50. package/addons/estragon/editor/navigation.gd +30 -0
  51. package/addons/estragon/editor/navigation.gd.uid +1 -0
  52. package/addons/estragon/editor/new_script.gd +77 -0
  53. package/addons/estragon/editor/new_script.gd.uid +1 -0
  54. package/addons/estragon/editor/plugin.cfg +1 -1
  55. package/addons/estragon/editor/plugin.gd +120 -40
  56. package/addons/estragon/editor/scene_components.gd +267 -0
  57. package/addons/estragon/editor/scene_components.gd.uid +1 -0
  58. package/addons/estragon/editor/scene_inspector.gd +42 -0
  59. package/addons/estragon/editor/scene_inspector.gd.uid +1 -0
  60. package/addons/estragon/editor/script_dependencies.gd +5 -3
  61. package/addons/estragon/runtime/composition/binding.gd +39 -7
  62. package/addons/estragon/runtime/composition/computation.gd +403 -52
  63. package/addons/estragon/runtime/composition/element.gd +74 -1
  64. package/addons/estragon/runtime/composition/layout_host.gd +58 -0
  65. package/addons/estragon/runtime/composition/layout_host.gd.uid +1 -0
  66. package/addons/estragon/runtime/composition/native_attributes.gd +29 -0
  67. package/addons/estragon/runtime/composition/native_attributes.gd.uid +1 -0
  68. package/addons/estragon/runtime/composition/preset.gd +102 -0
  69. package/addons/estragon/runtime/composition/preset.gd.uid +1 -0
  70. package/addons/estragon/runtime/composition/profile.tres +1 -1
  71. package/addons/estragon/runtime/composition/projection.gd +32 -0
  72. package/addons/estragon/runtime/composition/projection.gd.uid +1 -0
  73. package/addons/estragon/runtime/composition/render_cache.gd +36 -0
  74. package/addons/estragon/runtime/composition/render_cache.gd.uid +1 -0
  75. package/addons/estragon/runtime/composition/state.gd +171 -3
  76. package/addons/estragon/runtime/composition/state.tres +1 -1
  77. package/addons/estragon/runtime/node/box.gd +80 -0
  78. package/addons/estragon/runtime/node/box.gd.uid +1 -0
  79. package/addons/estragon/runtime/node/button.gd +90 -16
  80. package/addons/estragon/runtime/node/checkbox.gd +33 -0
  81. package/addons/estragon/runtime/node/checkbox.gd.uid +1 -0
  82. package/addons/estragon/runtime/node/component_2d.gd +348 -23
  83. package/addons/estragon/runtime/node/component_3d.gd +54 -18
  84. package/addons/estragon/runtime/node/estragon_2d.gd +18 -11
  85. package/addons/estragon/runtime/node/estragon_3d.gd +1 -10
  86. package/addons/estragon/runtime/node/grid.gd +77 -0
  87. package/addons/estragon/runtime/node/grid.gd.uid +1 -0
  88. package/addons/estragon/runtime/node/hbox.gd +4 -1
  89. package/addons/estragon/runtime/node/internal/component_2d_icon.tres +4 -0
  90. package/addons/estragon/runtime/node/internal/composition_hosts.gd +196 -0
  91. package/addons/estragon/runtime/node/internal/composition_hosts.gd.uid +1 -0
  92. package/addons/estragon/runtime/node/internal/composition_hosts.tres +6 -0
  93. package/addons/estragon/runtime/node/internal/control_participant.gd +164 -0
  94. package/addons/estragon/runtime/node/internal/control_participant.gd.uid +1 -0
  95. package/addons/estragon/runtime/node/internal/coordinator.gd +94 -27
  96. package/addons/estragon/runtime/node/internal/focus.gd +138 -0
  97. package/addons/estragon/runtime/node/internal/focus.gd.uid +1 -0
  98. package/addons/estragon/runtime/node/internal/focus.tres +6 -0
  99. package/addons/estragon/runtime/node/internal/focus_control.gd +48 -0
  100. package/addons/estragon/runtime/node/internal/focus_control.gd.uid +1 -0
  101. package/addons/estragon/runtime/node/internal/grid_definition.gd +177 -0
  102. package/addons/estragon/runtime/node/internal/grid_definition.gd.uid +1 -0
  103. package/addons/estragon/runtime/node/internal/grid_policy.gd +69 -0
  104. package/addons/estragon/runtime/node/internal/grid_policy.gd.uid +1 -0
  105. package/addons/estragon/runtime/node/internal/layout_core.gd +444 -24
  106. package/addons/estragon/runtime/node/internal/length.gd +106 -0
  107. package/addons/estragon/runtime/node/internal/length.gd.uid +1 -0
  108. package/addons/estragon/runtime/node/internal/native_bounds.gd +5 -2
  109. package/addons/estragon/runtime/node/internal/pointer_2d.gd +30 -5
  110. package/addons/estragon/runtime/node/internal/scroll_2d.gd +179 -0
  111. package/addons/estragon/runtime/node/internal/scroll_2d.gd.uid +1 -0
  112. package/addons/estragon/runtime/node/internal/scroll_input.gd +59 -0
  113. package/addons/estragon/runtime/node/internal/scroll_input.gd.uid +1 -0
  114. package/addons/estragon/runtime/node/internal/stack_contract.gd +43 -0
  115. package/addons/estragon/runtime/node/internal/stack_contract.gd.uid +1 -0
  116. package/addons/estragon/runtime/node/internal/stack_policy.gd +95 -0
  117. package/addons/estragon/runtime/node/internal/stack_policy.gd.uid +1 -0
  118. package/addons/estragon/runtime/node/internal/visual_style_2d.gd +265 -0
  119. package/addons/estragon/runtime/node/internal/visual_style_2d.gd.uid +1 -0
  120. package/addons/estragon/runtime/node/internal/wrap_policy.gd +59 -0
  121. package/addons/estragon/runtime/node/internal/wrap_policy.gd.uid +1 -0
  122. package/addons/estragon/runtime/node/native_2d.gd +6 -7
  123. package/addons/estragon/runtime/node/native_3d.gd +5 -5
  124. package/addons/estragon/runtime/node/rect.gd +13 -13
  125. package/addons/estragon/runtime/node/spacer.gd +4 -0
  126. package/addons/estragon/runtime/node/spacer.gd.uid +1 -0
  127. package/addons/estragon/runtime/node/text.gd +5 -3
  128. package/addons/estragon/runtime/node/toggle.gd +27 -8
  129. package/addons/estragon/runtime/node/vbox.gd +4 -1
  130. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # Release notes
2
2
 
3
- ## Next automated prerelease
3
+ ## Gogo editor experience — upcoming beta
4
4
 
5
- No compiler/runtime behavior changes are introduced by the packaging and version-source correction. The **one** release version is set in the Godot plugin configuration; the npm manifest is generated from it during packaging. The owner-controlled GitHub prerelease will exercise npm OIDC trusted publishing, provenance, byte-for-byte package verification and the approved Linux Godot consumer checks. These publication checks remain pending until the release actually runs.
5
+ The native Gogo editor now provides theme-aware GDScript/GGX syntax highlighting, context-sensitive CodeEdit completion and insertion/undo, source-positioned diagnostics/navigation, and **Project > Tools > New Gogo Script** templates for 2D/3D. No external compiler, language server or custom Godot build is needed for editing and Play. Dedicated native editor and Play checks passed on the two approved Linux Godot engines. Completion intentionally supports bounded lexical/ClassDB information rather than full GDScript type inference; the documented hidden, never-associated tab exception remains.
6
+
7
+ ## Previous direct Yarn installation beta
8
+
9
+ P02 made compiler/runtime/editor dependencies location-independent: packages work directly from Yarn `node_modules` without addon copying/symlinks. Internal references and generated dependencies resolve against installed Resources and actual destinations; Godot's enabled-plugin project setting accepts the full addon configuration path. That previous beta was published using the owner-controlled GitHub prerelease, with npm trusted-publisher OIDC, provenance/byte checks and native registry consumers. CI02 subsequently reduced mandatory certification to bounded direct-install validation; the full native regression suite remains opt-in.
6
10
 
7
11
  ## Initial public beta
8
12
 
9
13
  The first curated `@papercraftgames/estragon` addon artifact was published locally after merged F01–F06. It includes the bundled Gogo/GGX compiler/editor, typed/class-wide bindables, a signal-driven description reconciler, conditional/keyed retained Nodes, a native boolean two-way toggle, layout-first 2D widgets, bounded 3D adapters, opt-in profiling and measured LIS/preflight improvements.
10
14
 
11
- No JavaScript compiler/runtime or lifecycle scripts. Yarn dependency acquisition requires an explicit copy to the Godot project's `addons/estragon` and a `node_modules/.gdignore`. This is an early beta, not complete UI framework or release certification. Verified source/engines/artifact evidence and limitations remain in issue #104.
15
+ No JavaScript compiler/runtime or lifecycle scripts. The initial artifact used the former relocated-addon install contract; P02 replaces it with direct Yarn consumption. This is an early beta, not complete UI framework or release certification. Verified source/engines/artifact evidence and limitations remain in issue #104.
package/README.md CHANGED
@@ -2,25 +2,28 @@
2
2
 
3
3
  Pre-1.0 Godot addon: native Gogo/GGX compilation/editor, signal-driven descriptions reconciled with retained Nodes, layout-first Node2D UI and bounded Node3D adapters. Godot owns rendering, physics and scene lifetime. No Node/Bun compiler or runtime is required for authoring or Play.
4
4
 
5
+ Tagged npm packages carry the exact GitHub prerelease-tag version in both npm and Godot plugin metadata. Git source checkouts use a development marker; a local development pack is not a tagged release.
6
+
5
7
  ## Install into a Godot project
6
8
 
7
- Install the currently published beta with Yarn. The `beta` dist-tag resolves to the published package; `--exact` pins its resolved version in the consumer's manifest:
9
+ P02 direct-install support is pending an owner-published release; earlier public betas may not contain this fix. The following contract applies to a package containing P02. Install the current beta in the Godot project root:
8
10
 
9
11
  ```sh
10
12
  yarn add --exact --ignore-scripts @papercraftgames/estragon@beta
11
13
  ```
12
14
 
13
- Yarn alone installs into `node_modules`; it does not register a Godot plugin. From the project root, with no existing `addons/estragon` directory:
15
+ Keep the package where Yarn installs it. Do not copy, symlink or ignore the addon. Before opening the editor, add its full configuration path to the existing `editor_plugins/enabled` list in `project.godot` (preserve other enabled plugins):
14
16
 
15
- ```sh
16
- touch node_modules/.gdignore
17
- mkdir -p addons
18
- cp -R node_modules/@papercraftgames/estragon/addons/estragon addons/estragon
17
+ ```ini
18
+ [editor_plugins]
19
+ enabled=PackedStringArray("res://node_modules/@papercraftgames/estragon/addons/estragon/editor/plugin.cfg")
19
20
  ```
20
21
 
21
- The `.gdignore` prevents Godot importing a duplicate copy from node_modules. Use a copy, not a source/output symlink. For upgrades, back up local addon modifications and deliberately replace the previous addon directory; do not nest/merge two addon versions. Commit the copied addon and its `.gd.uid` sidecars. A teammate receiving that project can edit/run with Godot alone; node_modules is not needed at runtime.
22
+ Godot's Plugins panel discovers candidates under `addons/`; the enabled-plugin project setting accepts a full `res://` configuration path outside that directory. Yarn installation alone does not enable the plugin. Install dependencies before opening Godot; keep only one Estragon tree to avoid duplicate classes/UIDs. Commit the package manifest/lockfile and plugin setting, retaining the package's stable `.gd.uid` sidecars. Godot alone handles editing and Play after installation.
23
+
24
+ Explicit authored preload aliases reference the chosen installation, for example `preload("../../../node_modules/@papercraftgames/estragon/addons/estragon/runtime/composition/element.gd")` in a Gogo file whose generated script lives three directories below the project root. As with ordinary GDScript, relative authored imports resolve from the **generated script's directory**. Canonical registered widget class names also work after Godot indexes the project. Internal dependencies are script-relative; compiler-injected dependencies are calculated from installed Resources and the actual output directory. A different project-relative installation needs only matching authored imports and the plugin configuration setting; no production source edits. Standard `addons/estragon` placement remains supported.
22
25
 
23
- Open Godot → Project Settings → Plugins and enable **Estragon** at `res://addons/estragon/editor/plugin.cfg`. Author `.gogo` files and normal `.tscn` hosts referencing the generated script. Optionally put `{"version":1,"source_roots":["src"]}` in project `gogo.config.json`. Normal save and both main/current Play paths compile and validate natively; invalid or unsavable source blocks stale Play and recovers after repair.
26
+ Author `.gogo` files and normal `.tscn` hosts referencing generated scripts. Optional `gogo.config.json`: `{"version":1,"source_roots":["src"]}`. Native save and main/current Play compile with actual-path validation, invalid/unsavable-source rejection, rollback and repair. Generated files must be rebuilt after relocating an installed addon, just as authored imports must be updated.
24
27
 
25
28
  [Source-authored Counter example](https://github.com/papercraftgames/Estragon/tree/main/examples/counter), [language](https://github.com/papercraftgames/Estragon/blob/main/docs/GOGO_LANGUAGE.md), [native UI](https://github.com/papercraftgames/Estragon/blob/main/docs/NODE_UI.md), [editor](https://github.com/papercraftgames/Estragon/blob/main/docs/EDITOR.md), [package/release contract](https://github.com/papercraftgames/Estragon/blob/main/docs/PACKAGING.md).
26
29
 
@@ -1,9 +1,9 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## One lexical property lowering for explicit and class-wide Gogo annotations.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Source = preload("res://addons/estragon/compiler/source.gd")
6
- const Lexer = preload("res://addons/estragon/compiler/lexer.gd")
4
+ const Model = preload("model.gd")
5
+ const Source = preload("source.gd")
6
+ const Lexer = preload("lexer.gd")
7
7
  var file: Source
8
8
  var module: Model.Module
9
9
  var members: Dictionary = {}
@@ -1,11 +1,11 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Pure native compilation. Semantic validation/loading is an explicit next step.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Source = preload("res://addons/estragon/compiler/source.gd")
6
- const Frontend = preload("res://addons/estragon/compiler/frontend.gd")
7
- const Emitter = preload("res://addons/estragon/compiler/emitter.gd")
8
- const SourceMap = preload("res://addons/estragon/compiler/source_map.gd")
4
+ const Model = preload("model.gd")
5
+ const Source = preload("source.gd")
6
+ const Frontend = preload("frontend.gd")
7
+ const Emitter = preload("emitter.gd")
8
+ const SourceMap = preload("source_map.gd")
9
9
 
10
10
  class Compilation extends RefCounted:
11
11
  var code: String
@@ -14,11 +14,11 @@ class Compilation extends RefCounted:
14
14
  var ok: bool:
15
15
  get: return diagnostics.is_empty() and source_map != null
16
16
 
17
- static func compile(source: String, source_name: String = "<source>") -> Compilation:
17
+ static func compile(source: String, source_name: String = "<source>", output_path: String = "", project_sources = null) -> Compilation:
18
18
  var result := Compilation.new()
19
- var frontend := Frontend.analyze(source, source_name)
19
+ var frontend := Frontend.analyze(source, source_name, output_path, project_sources)
20
20
  result.diagnostics = frontend.diagnostics
21
21
  if not frontend.ok: return result
22
- result.source_map = Emitter.new(frontend.module, Source.new(source, source_name)).emit()
22
+ result.source_map = Emitter.new(frontend.module, Source.new(source, source_name, output_path)).emit()
23
23
  result.code = result.source_map.code
24
24
  return result
@@ -1,9 +1,10 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Detect the automatic host entry. Every GGX expression is a description.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Lexer = preload("res://addons/estragon/compiler/lexer.gd")
6
- const Resolver = preload("res://addons/estragon/compiler/native/resolver.gd")
4
+ const Element = preload("../runtime/composition/element.gd")
5
+ const Model = preload("model.gd")
6
+ const Lexer = preload("lexer.gd")
7
+ const Resolver = preload("native/resolver.gd")
7
8
  var file
8
9
  func _init(source) -> void:
9
10
  file = source
@@ -12,12 +13,16 @@ func apply(module) -> void:
12
13
  resolver.scan(module)
13
14
  var lexer := Lexer.new(file)
14
15
  var tokens: Array = []
15
- var cursor := 0
16
- while cursor < file.text.length():
17
- var token = lexer.next_token(cursor)
18
- if token == null: return
19
- cursor = token.span.end.index
20
- if token.kind not in ["whitespace","newline","comment","continuation"]: tokens.append(token)
16
+ # Only code spans contain declarations. Literal markup bodies are not GDScript
17
+ # (quotes, punctuation and Unicode must never enter its token scanner).
18
+ for part in module.parts:
19
+ if not part is Model.Code: continue
20
+ var cursor: int = part.span.start.index
21
+ while cursor<part.span.end.index:
22
+ var token = lexer.next_token(cursor)
23
+ if token==null: return
24
+ cursor = token.span.end.index
25
+ if token.kind not in ["whitespace","newline","comment","continuation"]: tokens.append(token)
21
26
  var has_ggx := false
22
27
  for part in module.parts:
23
28
  if part is Model.Component: has_ggx = true
@@ -31,7 +36,7 @@ func apply(module) -> void:
31
36
  return
32
37
  continue
33
38
  var type: String = tokens[index+5].text
34
- if resolver.aliases.get(type,"")!="res://addons/estragon/runtime/composition/element.gd":
39
+ if resolver.aliases.get(type,"")!=(Element as Script).resource_path:
35
40
  if has_ggx and type in ["Node","Node2D","Node3D"]:
36
41
  file.fail("build_view must return Element descriptions; eager Node-returning GGX is unsupported",tokens[index+5].span.start.index,tokens[index+5].span.end.index)
37
42
  return
@@ -1,11 +1,16 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Typed frontend -> ordinary GDScript. All output is range-mapped, never rewritten.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Source = preload("res://addons/estragon/compiler/source.gd")
6
- const MappedWriter = preload("res://addons/estragon/compiler/source_map.gd")
4
+ const Preset = preload("../runtime/composition/preset.gd")
5
+ const Element = preload("../runtime/composition/element.gd")
6
+ const State = preload("../runtime/composition/state.tres")
7
+ const Binding = preload("../runtime/composition/binding.gd")
8
+ const Model = preload("model.gd")
9
+ const Source = preload("source.gd")
10
+ const MappedWriter = preload("source_map.gd")
7
11
 
8
12
  class Argument extends RefCounted:
13
+ var spread := false
9
14
  var expression: Model.GdExpression
10
15
  var type_name: String
11
16
  var name: String
@@ -16,10 +21,12 @@ class Factory extends RefCounted:
16
21
  var root: Model.Component
17
22
  var arguments: Array[Argument] = []
18
23
 
24
+ var _output_directory: String
19
25
  var _module: Model.Module
20
26
  var _file: Source
21
27
  var _writer: MappedWriter
22
28
  var _factories: Array[Factory] = []
29
+ var _preset_methods: Array = []
23
30
  var _arguments: Dictionary = {}
24
31
  var _sequence: int = 0
25
32
  var _variable: int = 0
@@ -27,6 +34,10 @@ var _factory_class: String
27
34
  var _element_class: String
28
35
 
29
36
  func _init(module: Model.Module, file: Source) -> void:
37
+ # Paths are relative to the actual generated file, derived from installed Resources.
38
+ # Pathless in-memory callers use the project root, as native GDScript does.
39
+ _output_directory = file.generated_path().get_base_dir()
40
+ if not _output_directory.is_absolute_path(): _output_directory = "res://" + _output_directory
30
41
  _module = module
31
42
  _file = file
32
43
  _writer = MappedWriter.new(file)
@@ -40,14 +51,41 @@ func _init(module: Model.Module, file: Source) -> void:
40
51
  _element_class = "_GogoElement_0"
41
52
  while _module.identifiers.has(_element_class): _element_class += "_"
42
53
 
54
+ func _resource(resource: Resource) -> String:
55
+ return _string(Source.relative_path(_output_directory,resource.resource_path))
56
+
43
57
  func emit() -> MappedWriter:
44
58
  _parts(_module.parts)
59
+ var metadata := "_GOGO_RENDER_FUNCTIONS_"+_file.name.sha256_text().substr(0,16)
60
+ while _module.identifiers.has(metadata): metadata += "_"
61
+ _writer.append("\nconst "+metadata+" = "+var_to_str({"reactive":_module.render_functions,"ordinary":_module.ordinary_functions}))
45
62
  _writer.append("\n")
63
+ var observable := {}
64
+ for part in _module.parts:
65
+ if part is Model.Bindable: observable[part.name] = part.type_name
66
+ if not observable.is_empty():
67
+ var contract := "_GOGO_BINDABLE_PROPERTIES_"+_file.name.sha256_text().substr(0,16)
68
+ while _module.identifiers.has(contract): contract += "_"
69
+ _writer.append("const "+contract+" = "+var_to_str(observable)+"\n")
70
+ var exports := {}
71
+ for binding in _module.presets:
72
+ if binding.exported: exports[binding.name] = binding
73
+ for name in exports:
74
+ var binding = exports[name]
75
+ _writer.append("\nvar "+name+":\n"+_module.indentation+"get: return "+binding.symbol+"\n",binding.span)
76
+ if binding.mutable: _writer.append(_module.indentation+"set(value): "+binding.symbol+" = value\n",binding.span)
77
+ for path in _module.project_imports:
78
+ var imported: Dictionary = _module.project_imports[path]
79
+ _writer.append("\nconst "+imported.alias+" = preload("+_string(Source.relative_path(_output_directory,path))+")\n",imported.span)
80
+ for method in _preset_methods:
81
+ _writer.append("\nfunc "+method.name+"(): return ",method.binding.span)
82
+ _default_groups(method.binding)
83
+ _writer.append("\n",method.binding.span)
46
84
  if _module.composition:
47
- _writer.append("\nfunc _notification(_gogo_what: int) -> void:\n"+_module.indentation+"preload(\"res://addons/estragon/runtime/composition/state.tres\").lifecycle(self, _gogo_what)\n")
85
+ _writer.append("\nfunc _notification(_gogo_what: int) -> void:\n"+_module.indentation+"preload("+_resource(State)+").lifecycle(self, _gogo_what)\n")
48
86
  if not _factories.is_empty():
49
87
  _writer.append("\n\nclass " + _factory_class + ":", _factories[0].root.span)
50
- _writer.append("\n"+_module.indentation+"const "+_element_class+" = preload(\"res://addons/estragon/runtime/composition/element.gd\")\n")
88
+ _writer.append("\n"+_module.indentation+"const "+_element_class+" = preload("+_resource(Element)+")\n")
51
89
  # Calls in argument expressions may append additional factories.
52
90
  var index: int = 0
53
91
  while index < _factories.size():
@@ -72,7 +110,7 @@ static func _string(value: String) -> String:
72
110
  return output + '"'
73
111
 
74
112
  static func literal(value: Model.Literal) -> String:
75
- return _string(value.value)
113
+ return ("true" if value.value else "false") if value.value is bool else _string(value.value)
76
114
 
77
115
  func _argument(expression: Model.GdExpression, type_name: String, factory: Factory) -> void:
78
116
  var argument := Argument.new()
@@ -83,20 +121,53 @@ func _argument(expression: Model.GdExpression, type_name: String, factory: Facto
83
121
  _arguments[expression] = argument
84
122
 
85
123
  func _collect(node: Model.Component, factory: Factory) -> void:
124
+ if node.preset!=null:
125
+ var expression := Model.GdExpression.new()
126
+ expression.span = node.name_span
127
+ var reference := Model.Literal.new()
128
+ reference.kind = "preset-reference"
129
+ reference.value = node.preset.symbol
130
+ reference.span = node.name_span
131
+ expression.parts.append(reference)
132
+ node.preset_expression = expression
133
+ _argument(expression,"Variant",factory)
86
134
  for attribute in node.attributes:
87
135
  if attribute.value is Model.GdExpression:
88
136
  _argument(attribute.value, attribute.type_name, factory)
137
+ factory.arguments.back().spread = attribute.kind=="spread"
89
138
  if attribute.kind=="binding": factory.arguments.back().binding_path = attribute.binding_path
139
+ for part in node.text_body:
140
+ if part is Model.GdExpression: _argument(part,"Variant",factory)
90
141
  for child in node.children:
91
142
  if child is Model.GdExpression: _argument(child,"Variant",factory)
92
143
  else: _collect(child, factory)
93
144
 
94
145
  func _parts(parts: Array[Model.SyntaxNode]) -> void:
95
146
  for part in parts:
96
- if part is Model.Code: _writer.append(_file.slice(part.span), part.span, true)
147
+ if part is Model.Code: _code(part.span)
97
148
  elif part is Model.Bindable: _bindable(part)
149
+ elif part is Model.Layout: _layout(part)
150
+ elif part is Model.RenderCall: _render_call(part)
151
+ elif part is Model.Literal and part.kind=="preset-reference": _writer.append(str(part.value),part.span)
98
152
  else: _call(part)
99
153
 
154
+ func _code(span: Model.Span) -> void:
155
+ var cursor: int = span.start.index
156
+ var edits: Array = []
157
+ for imported in _module.resource_imports:
158
+ edits.append({"span":imported.span,"value":_string(Source.relative_path(_output_directory,imported.path))})
159
+ for imported in _module.identifier_imports: edits.append({"span":imported.span,"value":imported.alias})
160
+ edits.sort_custom(func(a,b): return a.span.start.index<b.span.start.index)
161
+ for edit in edits:
162
+ var literal_span: Model.Span = edit.span
163
+ if literal_span.start.index < cursor or literal_span.end.index > span.end.index: continue
164
+ var before := _file.span(cursor,literal_span.start.index)
165
+ _writer.append(_file.slice(before),before,true)
166
+ _writer.append(edit.value,literal_span)
167
+ cursor = literal_span.end.index
168
+ var rest := _file.span(cursor,span.end.index)
169
+ _writer.append(_file.slice(rest),rest,true)
170
+
100
171
  func _call(node: Model.Component) -> void:
101
172
  var factory := Factory.new()
102
173
  while true:
@@ -106,6 +177,16 @@ func _call(node: Model.Component) -> void:
106
177
  factory.root = node
107
178
  _factories.append(factory)
108
179
  _collect(node, factory)
180
+ var keyed: Model.Attribute
181
+ for attribute in node.attributes:
182
+ if attribute.kind=="key": keyed = attribute
183
+ var key_symbol := "_gogo_mount_key"
184
+ while _module.identifiers.has(key_symbol): key_symbol += "_"
185
+ if keyed!=null:
186
+ _writer.append("preload("+_resource(State)+").in_slot("+_string(_file.name+":"+str(node.span.start.offset))+", ",node.span)
187
+ if keyed.value is Model.GdExpression: _parts(keyed.value.parts)
188
+ else: _writer.append(literal(keyed.value),keyed.value.span)
189
+ _writer.append(", func("+key_symbol+"): return ",node.span)
109
190
  var multiline := factory.arguments.size() > 3
110
191
  var start := _file.line_start(node.span.start.line)
111
192
  var end := start
@@ -117,10 +198,14 @@ func _call(node: Model.Component) -> void:
117
198
  if index > 0: _writer.append("," if multiline else ", ", node.span)
118
199
  if multiline: _writer.append("\n" + base + _module.indentation, argument.expression.span)
119
200
  _writer.append("(", argument.expression.span)
120
- if argument.binding_path.is_empty(): _parts(argument.expression.parts)
201
+ if argument.spread: _writer.append("preload("+_resource(Element)+").snapshot(",argument.expression.span)
202
+ if keyed!=null and argument.expression==keyed.value: _writer.append(key_symbol,argument.expression.span)
203
+ elif argument.binding_path.is_empty(): _parts(argument.expression.parts)
121
204
  else: _binding_argument(argument)
205
+ if argument.spread: _writer.append(")",argument.expression.span)
122
206
  _writer.append(")", argument.expression.span)
123
207
  _writer.append(("\n" + base if multiline else "") + ")", node.span)
208
+ if keyed!=null: _writer.append(")",node.span)
124
209
 
125
210
  func _factory(factory: Factory) -> void:
126
211
  _writer.append("\n\n" + _module.indentation + "static func " + factory.name + "(", factory.root.span)
@@ -143,28 +228,80 @@ func _description(node: Model.Component, indentation: String) -> String:
143
228
  _variable += 1
144
229
  var props := PackedStringArray()
145
230
  var events := PackedStringArray()
146
- var bindings := PackedStringArray()
147
231
  var key := "null"
148
232
  var keyed := "false"
233
+ var expanded := node.attributes.any(func(item): return item.kind=="spread")
234
+ var ordered := PackedStringArray()
149
235
  for attribute in node.attributes:
150
236
  var value: String = _arguments[attribute.value].name if attribute.value is Model.GdExpression else literal(attribute.value)
151
- if attribute.kind == "binding":
152
- bindings.append(_string("value")+": "+value)
153
- continue
154
237
  if attribute.kind == "key":
155
238
  key = value
156
239
  keyed = "true"
157
240
  continue
241
+ if expanded:
242
+ ordered.append("[%s, %s, %s]" % ["null" if attribute.kind=="spread" else _string(attribute.name),value,_string("%s:%d:%d" % [_file.name,attribute.name_span.start.line,attribute.name_span.start.column])])
243
+ continue
158
244
  var target := events if attribute.kind == "signal" else props
159
245
  target.append(_string(attribute.name)+": "+value)
160
246
  var children := PackedStringArray()
161
247
  for child in node.children:
162
248
  children.append(_arguments[child].name if child is Model.GdExpression else _description(child,indentation))
163
249
  var native_type := _string(node.runtime_class) if ClassDB.class_exists(node.runtime_class) else node.runtime_class
250
+ if node.preset!=null: native_type = "preload("+_resource(Preset)+").type_of("+_arguments[node.preset_expression].name+")"
164
251
  _line("var %s := %s.new(%s, {%s}, {%s}, [%s], %s, %s, %s)" % [variable,_element_class,native_type,", ".join(props),", ".join(events),", ".join(children),_string("%s:%d:%d" % [_file.name,node.span.start.line,node.span.start.column]),key,keyed],node.span,indentation)
165
- if not bindings.is_empty(): _line(variable+".bindings = {"+", ".join(bindings)+"}",node.span,indentation)
252
+ for attribute in node.attributes:
253
+ if attribute.kind=="placement" and not expanded: _line(variable+".origins["+_string(attribute.name)+"] = "+_string("%s:%d:%d" % [_file.name,attribute.name_span.start.line,attribute.name_span.start.column]),attribute.name_span,indentation)
254
+ if attribute.kind=="binding": _line(variable+".origins[\"value\"] = "+_string("%s:%d:%d" % [_file.name,attribute.name_span.start.line,attribute.name_span.start.column]),attribute.name_span,indentation)
255
+
256
+ if expanded: _line(variable+".expand(["+", ".join(ordered)+"])",node.span,indentation)
257
+ _line(variable+".resolve_bindings()",node.span,indentation)
258
+ if not node.text_body.is_empty():
259
+ var parts := PackedStringArray()
260
+ for part in node.text_body:
261
+ var value: String = _arguments[part].name if part is Model.GdExpression else literal(part)
262
+ parts.append("[%s, %s]" % [value,_string("%s:%d:%d" % [_file.name,part.span.start.line,part.span.start.column])])
263
+ _line(variable+".set_text_body(["+", ".join(parts)+"])",node.span,indentation)
264
+ if node.preset!=null: _line(variable+" = preload("+_resource(Preset)+").apply("+_arguments[node.preset_expression].name+", "+variable+")",node.span,indentation)
166
265
  return variable
167
266
 
267
+ func _layout(layout: Model.Layout) -> void:
268
+ var indent := " ".repeat(layout.span.start.column-1)
269
+ # Preserve the file's indentation convention for native statements/closures.
270
+ if _module.indentation.begins_with("\t"): indent = "\t".repeat((layout.span.start.column-1)/_module.indentation.length())
271
+ for index in range(layout.bindings.size()):
272
+ var binding = layout.bindings[index]
273
+ if index>0: _writer.append("\n"+indent,binding.span)
274
+ _writer.append("var "+binding.symbol+" = preload("+_resource(Preset)+").new("+binding.base+", ",binding.span)
275
+ if binding.scope==0:
276
+ var method: String = binding.symbol+"_defaults"
277
+ while _module.identifiers.has(method): method += "_"
278
+ _module.identifiers.append(method)
279
+ _preset_methods.append({"name":method,"binding":binding})
280
+ _writer.append("Callable(self, "+_string(method)+")",binding.span)
281
+ else:
282
+ _writer.append("func(): return ",binding.span)
283
+ _default_groups(binding)
284
+ _writer.append(", "+var_to_str(binding.generated)+", "+_string("%s:%d:%d" % [_file.name,binding.span.start.line,binding.span.start.column])+")",binding.span)
285
+
286
+ func _default_groups(binding) -> void:
287
+ _writer.append("[",binding.span)
288
+ for group_index in range(binding.groups.size()):
289
+ if group_index>0: _writer.append(", ",binding.span)
290
+ _writer.append("[",binding.span)
291
+ var group = binding.groups[group_index]
292
+ for attr_index in range(group.attributes.size()):
293
+ var attr = group.attributes[attr_index]
294
+ if attr_index>0: _writer.append(", ",attr.span)
295
+ _writer.append("["+("null" if attr.kind=="spread" else _string(attr.name))+", ",attr.span)
296
+ if attr.kind=="spread": _writer.append("preload("+_resource(Element)+").snapshot(",attr.span)
297
+ if attr.value is Model.GdExpression: _parts(attr.value.parts)
298
+ else: _writer.append(literal(attr.value),attr.value.span)
299
+ if attr.kind=="spread": _writer.append(")",attr.span)
300
+ _writer.append(", "+_string("%s:%d:%d" % [_file.name,attr.name_span.start.line,attr.name_span.start.column])+"]",attr.span)
301
+ _writer.append("]",binding.span)
302
+ _writer.append("]",binding.span)
303
+
304
+
168
305
  func _bindable(property: Model.Bindable) -> void:
169
306
  var incoming := "_gogo_incoming_"+property.name
170
307
  while _module.identifiers.has(incoming): incoming += "_"
@@ -172,13 +309,13 @@ func _bindable(property: Model.Bindable) -> void:
172
309
  while _module.identifiers.has(previous): previous += "_"
173
310
  var indent := _module.indentation
174
311
  _writer.append("signal "+property.signal_name+"(previous: ",property.name_span)
175
- _writer.append(_file.slice(property.type_span),property.type_span,true)
312
+ _code(property.type_span)
176
313
  _writer.append(", value: ",property.name_span)
177
- _writer.append(_file.slice(property.type_span),property.type_span,true)
314
+ _code(property.type_span)
178
315
  _writer.append(")\n",property.name_span)
179
316
  if property.annotations_span != null:
180
317
  _writer.append(_file.slice(property.annotations_span),property.annotations_span,true)
181
- _writer.append(_file.slice(property.declaration_span),property.declaration_span,true)
318
+ _code(property.declaration_span)
182
319
  _writer.append(":",property.name_span)
183
320
  if property.comment_span != null:
184
321
  _writer.append(" ")
@@ -187,13 +324,16 @@ func _bindable(property: Model.Bindable) -> void:
187
324
  # Use the native property backing slot: accesses inside its own setter are
188
325
  # direct, and declaration initialization does not call the setter.
189
326
  _writer.append(indent.repeat(2)+"if is_same("+property.name+", "+incoming+"): return\n",property.name_span)
190
- _writer.append(indent.repeat(2)+"var "+previous+": "+property.type_name+" = "+property.name+"\n",property.name_span)
327
+ _writer.append(indent.repeat(2)+"var "+previous+": ",property.name_span)
328
+ _code(property.type_span)
329
+ _writer.append(" = "+property.name+"\n",property.name_span)
191
330
  _writer.append(indent.repeat(2)+property.name+" = "+incoming+"\n",property.name_span)
192
331
  _writer.append(indent.repeat(2)+property.signal_name+".emit("+previous+", "+incoming+")\n",property.name_span)
193
- _writer.append(indent+"get:\n"+indent.repeat(2)+"preload(\"res://addons/estragon/runtime/composition/state.tres\").observe(self, &"+_string(property.signal_name)+")\n"+indent.repeat(2)+"return "+property.name+"\n",property.name_span)
332
+ _writer.append(indent+"get:\n"+indent.repeat(2)+"preload("+_resource(State)+").observe(self, &"+_string(property.signal_name)+")\n"+indent.repeat(2)+"return "+property.name+"\n",property.name_span)
194
333
 
195
334
  func _binding_argument(argument: Argument) -> void:
196
335
  var path := argument.binding_path.duplicate()
336
+ var root: String = path.pop_front()
197
337
  var field: String = path.pop_back()
198
338
  var owner := "_gogo_root"
199
339
  var source := "_gogo_source"
@@ -206,4 +346,69 @@ func _binding_argument(argument: Argument) -> void:
206
346
  for name in path:
207
347
  endpoint += "."+str(name)
208
348
  checks.append(endpoint+" != null")
209
- _writer.append("preload(\"res://addons/estragon/runtime/composition/binding.gd\").new(self, func("+owner+"): return "+endpoint+" if "+" and ".join(checks)+" else null, "+_string(field)+", func("+source+", "+edit+": bool): "+source+"."+field+" = "+edit+", "+_string(".".join(argument.binding_path))+")",argument.expression.span)
349
+ _writer.append("preload("+_resource(Binding)+").new("+root+", func("+owner+"): return "+endpoint+" if "+" and ".join(checks)+" else null, "+_string(field)+", func("+source+", "+edit+": bool): "+source+"."+field+" = "+edit+", "+_string(".".join(argument.binding_path))+", (",argument.expression.span)
350
+ # Keep the original property read in authored scope: native semantic
351
+ # validation still rejects unknown members, and the getter runs once.
352
+ _parts(argument.expression.parts)
353
+ var original_checks: Array[String] = []
354
+ var original := root
355
+ original_checks.append(original+" != null")
356
+ for name in path:
357
+ original += "."+str(name)
358
+ original_checks.append(original+" != null")
359
+ _writer.append(") if "+" and ".join(original_checks)+" else null)",argument.expression.span)
360
+
361
+ func _render_call(node: Model.RenderCall) -> void:
362
+ var cast: String = node.result_type
363
+ if node.statement or cast in ["void","Variant"]: cast = ""
364
+ if not cast.is_empty(): _writer.append("(",node.span)
365
+ var member := not node.receiver.is_empty()
366
+ var base := member and node.receiver.size()==1 and node.receiver[0] is Model.Code and _file.text.substr(node.receiver[0].span.start.index,node.receiver[0].span.end.index-node.receiver[0].span.start.index).strip_edges()=="super"
367
+ _writer.append("preload("+_resource(State)+")."+("base_at" if base else "method_at" if member else "call_at")+"("+_string(_file.name+":"+str(node.span.start.offset))+", ",node.span)
368
+ if base:
369
+ _writer.append("self, "+_string(_output_directory.path_join(_file.generated_path().get_file()))+", "+_string(node.method),node.span)
370
+ elif member:
371
+ _parts(node.receiver)
372
+ _writer.append(", "+_string(node.method),node.span)
373
+ else: _parts(node.callee)
374
+ _writer.append(", [",node.span)
375
+ for index in range(node.arguments.size()):
376
+ if index>0: _writer.append(", ",node.span)
377
+ _parts(node.arguments[index].parts)
378
+ if member:
379
+ var receiver := "_gogo_receiver"
380
+ var args := "_gogo_arguments"
381
+ while _module.identifiers.has(receiver): receiver += "_"
382
+ while _module.identifiers.has(args): args += "_"
383
+ _writer.append("], func("+receiver+", "+args+"): "+("" if node.result_type=="void" or node.statement else "return ")+("super" if base else receiver)+"."+node.method+"(",node.span)
384
+ for index in range(node.arguments.size()):
385
+ if index>0: _writer.append(", ",node.span)
386
+ _writer.append(args+"["+str(index)+"]",node.span)
387
+ _writer.append(")",node.span)
388
+ else: _writer.append("]",node.span)
389
+ # Never run/retain the proof closure: native static checking still sees the
390
+ # authored call and its original argument types before source publication.
391
+ _writer.append(", func(): ",node.span)
392
+ if node.callable_value:
393
+ _parts(node.callee)
394
+ _writer.append(".call(",node.span)
395
+ for index in range(node.arguments.size()):
396
+ if index>0: _writer.append(", ",node.span)
397
+ _parts(node.arguments[index].parts)
398
+ _writer.append(")",node.span)
399
+ else: _parts(node.original)
400
+ if node.reactive_lambda: _writer.append(", true",node.span)
401
+ _writer.append(")",node.span)
402
+ if not cast.is_empty(): _writer.append(" as "+_memo_type(cast)+")",node.span)
403
+
404
+ func _memo_type(type: String) -> String:
405
+ var source := Source.new(type)
406
+ var lexer = preload("lexer.gd").new(source)
407
+ var cursor := 0
408
+ var result := ""
409
+ while cursor<type.length():
410
+ var token = lexer.next_token(cursor)
411
+ if token==null: return type
412
+ cursor = token.span.end.index
413
+ result += _module.import_aliases.get(token.text,token.text) if token.kind=="identifier" else token.text
414
+ return result
@@ -1,21 +1,27 @@
1
1
  @tool
2
2
  extends RefCounted
3
3
  ## Native source -> typed frontend result. No emitter, subprocess or editor state.
4
- const Model = preload("res://addons/estragon/compiler/model.gd")
5
- const Source = preload("res://addons/estragon/compiler/source.gd")
6
- const Parser = preload("res://addons/estragon/compiler/parser.gd")
7
- const Bindable = preload("res://addons/estragon/compiler/bindable.gd")
8
- const Validator = preload("res://addons/estragon/compiler/validator.gd")
9
- const Composition = preload("res://addons/estragon/compiler/composition.gd")
4
+ const Model = preload("model.gd")
5
+ const Source = preload("source.gd")
6
+ const Parser = preload("parser.gd")
7
+ const Bindable = preload("bindable.gd")
8
+ const Validator = preload("validator.gd")
9
+ const Composition = preload("composition.gd")
10
+ const Layouts = preload("layouts.gd")
11
+ const RenderCalls = preload("render_calls.gd")
12
+ const ImportAliases = preload("import_aliases.gd")
10
13
 
11
- static func analyze(text: String, source_name: String = "<source>") -> Model.Result:
12
- var file := Source.new(text, source_name)
14
+ static func analyze(text: String, source_name: String = "<source>", output_path: String = "", project_sources = null) -> Model.Result:
15
+ var file := Source.new(text, source_name, output_path, project_sources)
13
16
  var parser := Parser.new(file)
14
17
  var result := Model.Result.new()
15
18
  var module := parser.parse()
19
+ if module != null and file.diagnostics.is_empty(): Layouts.new(file).apply(module)
16
20
  if module != null: Bindable.new(file).apply(module)
17
21
  if module != null and file.diagnostics.is_empty(): Composition.new(file).apply(module)
18
22
  if module != null and file.diagnostics.is_empty(): Validator.new(file).validate(module)
23
+ if module != null and file.diagnostics.is_empty(): ImportAliases.new(file).apply(module)
24
+ if module != null and file.diagnostics.is_empty(): RenderCalls.new(file).apply(module)
19
25
  result.tokens = parser.lexer.tokens
20
26
  result.diagnostics = file.diagnostics
21
27
  result.module = module if result.diagnostics.is_empty() else null
@@ -0,0 +1,64 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Explicit native-name imports are lexical Gogo names, not native registrations.
4
+ ## Only lexer-proven identifier spans enter the existing mapped emitter.
5
+ const Model = preload("model.gd")
6
+ const Lexer = preload("lexer.gd")
7
+ var file
8
+ var module
9
+ var declarations: Dictionary = {}
10
+ func _init(source) -> void: file = source
11
+ func apply(value) -> void:
12
+ module = value
13
+ if module.import_aliases.is_empty(): return
14
+ _parts(module.parts)
15
+ func _parts(parts: Array) -> void:
16
+ for part in parts:
17
+ if part is Model.Code: _code(part.span)
18
+ elif part is Model.Bindable:
19
+ _code(part.declaration_span)
20
+ elif part is Model.GdExpression: _parts(part.parts)
21
+ elif part is Model.Layout:
22
+ for binding in part.bindings:
23
+ for group in binding.groups:
24
+ for attribute in group.attributes:
25
+ if attribute.value is Model.GdExpression: _parts(attribute.value.parts)
26
+ elif part is Model.Component:
27
+ for attribute in part.attributes:
28
+ if attribute.value is Model.GdExpression: _parts(attribute.value.parts)
29
+ _parts(part.children)
30
+ _parts(part.text_body)
31
+ func _code(span) -> void:
32
+ var lexer := Lexer.new(file)
33
+ var cursor: int = span.start.index
34
+ var tokens: Array = []
35
+ while cursor<span.end.index:
36
+ var token = lexer.next_token(cursor)
37
+ if token==null: return
38
+ cursor = token.span.end.index
39
+ if token.kind not in ["whitespace","newline","comment","continuation"]: tokens.append(token)
40
+ var parameter_depth := 0
41
+ var in_function := false
42
+ for index in range(tokens.size()):
43
+ var token = tokens[index]
44
+ if token.text=="func": in_function = true
45
+ elif in_function and token.text=="(": parameter_depth += 1
46
+ elif in_function and token.text==")":
47
+ parameter_depth -= 1
48
+ if parameter_depth==0: in_function = false
49
+ if token.kind!="identifier" or not module.import_aliases.has(token.text): continue
50
+ if module.identifier_imports.any(func(item): return item.span.start.index==token.span.start.index): continue
51
+ if in_function and parameter_depth==1 and index>0 and tokens[index-1].text in ["(",","] and index+1<tokens.size() and tokens[index+1].text in [":","=",",",")"]:
52
+ file.fail("Imported native-name alias cannot be a parameter: "+token.text,token.span.start.index,token.span.end.index)
53
+ return
54
+ # GDScript dictionary shorthand is a string key, not an expression.
55
+ if index+1<tokens.size() and tokens[index+1].text=="=" and index>0 and tokens[index-1].text in ["{",","]: continue
56
+ # Member access is a different name, except explicit self.constant.
57
+ if index>0 and tokens[index-1].text=="." and (index<2 or tokens[index-2].text!="self"): continue
58
+ if index>0 and tokens[index-1].text in ["var","const","func","signal","class","for"]:
59
+ var prefix: String = file.text.substr(file.line_start(token.span.start.line),tokens[index-1].span.start.index-file.line_start(token.span.start.line))
60
+ if tokens[index-1].text!="const" or not prefix.is_empty() or declarations.has(token.text):
61
+ file.fail("Imported native-name alias cannot be redeclared: "+token.text,token.span.start.index,token.span.end.index)
62
+ return
63
+ declarations[token.text] = true
64
+ module.identifier_imports.append({"span":token.span,"alias":module.import_aliases[token.text]})