@papercraftgames/estragon 0.1.0-beta.2 → 0.1.0-beta.21
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.
- package/CHANGELOG.md +7 -3
- package/README.md +11 -8
- package/addons/estragon/compiler/bindable.gd +3 -3
- package/addons/estragon/compiler/compiler.gd +8 -8
- package/addons/estragon/compiler/composition.gd +5 -4
- package/addons/estragon/compiler/emitter.gd +34 -8
- package/addons/estragon/compiler/frontend.gd +8 -8
- package/addons/estragon/compiler/lexer.gd +2 -2
- package/addons/estragon/compiler/model.gd +2 -0
- package/addons/estragon/compiler/native/resolver.gd +125 -29
- package/addons/estragon/compiler/parser.gd +3 -3
- package/addons/estragon/compiler/project_sources.gd +91 -0
- package/addons/estragon/compiler/project_sources.gd.uid +1 -0
- package/addons/estragon/compiler/script_validation.gd +3 -3
- package/addons/estragon/compiler/source.gd +19 -2
- package/addons/estragon/compiler/source_map.gd +3 -3
- package/addons/estragon/compiler/validator.gd +74 -10
- package/addons/estragon/editor/build_service.gd +91 -72
- package/addons/estragon/editor/color_property.gd +37 -0
- package/addons/estragon/editor/color_property.gd.uid +1 -0
- package/addons/estragon/editor/completion.gd +531 -0
- package/addons/estragon/editor/completion.gd.uid +1 -0
- package/addons/estragon/editor/completion_edit.gd +7 -0
- package/addons/estragon/editor/completion_edit.gd.uid +1 -0
- package/addons/estragon/editor/components.gd +20 -0
- package/addons/estragon/editor/components.gd.uid +1 -0
- package/addons/estragon/editor/creation_menu.gd.txt +14 -0
- package/addons/estragon/editor/generated_editors.gd +256 -0
- package/addons/estragon/editor/generated_editors.gd.uid +1 -0
- package/addons/estragon/editor/highlighter.gd +62 -103
- package/addons/estragon/editor/highlighter_association.gd +11 -2
- package/addons/estragon/editor/imports.gd +47 -0
- package/addons/estragon/editor/imports.gd.uid +1 -0
- package/addons/estragon/editor/language_services.gd +288 -0
- package/addons/estragon/editor/language_services.gd.uid +1 -0
- package/addons/estragon/editor/length_property.gd +22 -0
- package/addons/estragon/editor/length_property.gd.uid +1 -0
- package/addons/estragon/editor/lexical_context.gd +159 -0
- package/addons/estragon/editor/lexical_context.gd.uid +1 -0
- package/addons/estragon/editor/navigation.gd +30 -0
- package/addons/estragon/editor/navigation.gd.uid +1 -0
- package/addons/estragon/editor/new_script.gd +77 -0
- package/addons/estragon/editor/new_script.gd.uid +1 -0
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/editor/plugin.gd +113 -40
- package/addons/estragon/editor/scene_components.gd +267 -0
- package/addons/estragon/editor/scene_components.gd.uid +1 -0
- package/addons/estragon/editor/scene_inspector.gd +42 -0
- package/addons/estragon/editor/scene_inspector.gd.uid +1 -0
- package/addons/estragon/editor/script_dependencies.gd +5 -3
- package/addons/estragon/runtime/composition/binding.gd +1 -1
- package/addons/estragon/runtime/composition/computation.gd +141 -9
- package/addons/estragon/runtime/composition/element.gd +3 -1
- package/addons/estragon/runtime/composition/layout_host.gd +58 -0
- package/addons/estragon/runtime/composition/layout_host.gd.uid +1 -0
- package/addons/estragon/runtime/composition/profile.tres +1 -1
- package/addons/estragon/runtime/composition/projection.gd +32 -0
- package/addons/estragon/runtime/composition/projection.gd.uid +1 -0
- package/addons/estragon/runtime/composition/state.gd +13 -2
- package/addons/estragon/runtime/composition/state.tres +1 -1
- package/addons/estragon/runtime/node/box.gd +57 -0
- package/addons/estragon/runtime/node/box.gd.uid +1 -0
- package/addons/estragon/runtime/node/button.gd +44 -15
- package/addons/estragon/runtime/node/component_2d.gd +167 -24
- package/addons/estragon/runtime/node/component_3d.gd +54 -18
- package/addons/estragon/runtime/node/estragon_2d.gd +2 -11
- package/addons/estragon/runtime/node/estragon_3d.gd +1 -10
- package/addons/estragon/runtime/node/hbox.gd +4 -1
- package/addons/estragon/runtime/node/internal/component_2d_icon.tres +4 -0
- package/addons/estragon/runtime/node/internal/composition_hosts.gd +159 -0
- package/addons/estragon/runtime/node/internal/composition_hosts.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/composition_hosts.tres +6 -0
- package/addons/estragon/runtime/node/internal/control_participant.gd +164 -0
- package/addons/estragon/runtime/node/internal/control_participant.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/coordinator.gd +79 -27
- package/addons/estragon/runtime/node/internal/grid_definition.gd +75 -0
- package/addons/estragon/runtime/node/internal/grid_definition.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd +205 -22
- package/addons/estragon/runtime/node/internal/length.gd +94 -0
- package/addons/estragon/runtime/node/internal/length.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/stack_contract.gd +21 -0
- package/addons/estragon/runtime/node/internal/stack_contract.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/stack_policy.gd +59 -0
- package/addons/estragon/runtime/node/internal/stack_policy.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/visual_style_2d.gd +75 -0
- package/addons/estragon/runtime/node/internal/visual_style_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/native_2d.gd +5 -5
- package/addons/estragon/runtime/node/native_3d.gd +5 -5
- package/addons/estragon/runtime/node/rect.gd +13 -13
- package/addons/estragon/runtime/node/spacer.gd +4 -0
- package/addons/estragon/runtime/node/spacer.gd.uid +1 -0
- package/addons/estragon/runtime/node/text.gd +5 -3
- package/addons/estragon/runtime/node/toggle.gd +18 -5
- package/addons/estragon/runtime/node/vbox.gd +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# Release notes
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Gogo editor experience — upcoming beta
|
|
4
4
|
|
|
5
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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("
|
|
5
|
-
const Source = preload("
|
|
6
|
-
const Lexer = preload("
|
|
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("
|
|
5
|
-
const Source = preload("
|
|
6
|
-
const Frontend = preload("
|
|
7
|
-
const Emitter = preload("
|
|
8
|
-
const SourceMap = preload("
|
|
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
|
|
5
|
-
const
|
|
6
|
-
const
|
|
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
|
|
@@ -31,7 +32,7 @@ func apply(module) -> void:
|
|
|
31
32
|
return
|
|
32
33
|
continue
|
|
33
34
|
var type: String = tokens[index+5].text
|
|
34
|
-
if resolver.aliases.get(type,"")!=
|
|
35
|
+
if resolver.aliases.get(type,"")!=(Element as Script).resource_path:
|
|
35
36
|
if has_ggx and type in ["Node","Node2D","Node3D"]:
|
|
36
37
|
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
38
|
return
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends RefCounted
|
|
3
3
|
## Typed frontend -> ordinary GDScript. All output is range-mapped, never rewritten.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const Element = preload("../runtime/composition/element.gd")
|
|
5
|
+
const State = preload("../runtime/composition/state.tres")
|
|
6
|
+
const Binding = preload("../runtime/composition/binding.gd")
|
|
7
|
+
const Model = preload("model.gd")
|
|
8
|
+
const Source = preload("source.gd")
|
|
9
|
+
const MappedWriter = preload("source_map.gd")
|
|
7
10
|
|
|
8
11
|
class Argument extends RefCounted:
|
|
9
12
|
var expression: Model.GdExpression
|
|
@@ -16,6 +19,7 @@ class Factory extends RefCounted:
|
|
|
16
19
|
var root: Model.Component
|
|
17
20
|
var arguments: Array[Argument] = []
|
|
18
21
|
|
|
22
|
+
var _output_directory: String
|
|
19
23
|
var _module: Model.Module
|
|
20
24
|
var _file: Source
|
|
21
25
|
var _writer: MappedWriter
|
|
@@ -27,6 +31,10 @@ var _factory_class: String
|
|
|
27
31
|
var _element_class: String
|
|
28
32
|
|
|
29
33
|
func _init(module: Model.Module, file: Source) -> void:
|
|
34
|
+
# Paths are relative to the actual generated file, derived from installed Resources.
|
|
35
|
+
# Pathless in-memory callers use the project root, as native GDScript does.
|
|
36
|
+
_output_directory = file.generated_path().get_base_dir()
|
|
37
|
+
if not _output_directory.is_absolute_path(): _output_directory = "res://" + _output_directory
|
|
30
38
|
_module = module
|
|
31
39
|
_file = file
|
|
32
40
|
_writer = MappedWriter.new(file)
|
|
@@ -40,14 +48,20 @@ func _init(module: Model.Module, file: Source) -> void:
|
|
|
40
48
|
_element_class = "_GogoElement_0"
|
|
41
49
|
while _module.identifiers.has(_element_class): _element_class += "_"
|
|
42
50
|
|
|
51
|
+
func _resource(resource: Resource) -> String:
|
|
52
|
+
return _string(Source.relative_path(_output_directory,resource.resource_path))
|
|
53
|
+
|
|
43
54
|
func emit() -> MappedWriter:
|
|
44
55
|
_parts(_module.parts)
|
|
45
56
|
_writer.append("\n")
|
|
57
|
+
for path in _module.project_imports:
|
|
58
|
+
var imported: Dictionary = _module.project_imports[path]
|
|
59
|
+
_writer.append("\nconst "+imported.alias+" = preload("+_string(Source.relative_path(_output_directory,path))+")\n",imported.span)
|
|
46
60
|
if _module.composition:
|
|
47
|
-
_writer.append("\nfunc _notification(_gogo_what: int) -> void:\n"+_module.indentation+"preload(
|
|
61
|
+
_writer.append("\nfunc _notification(_gogo_what: int) -> void:\n"+_module.indentation+"preload("+_resource(State)+").lifecycle(self, _gogo_what)\n")
|
|
48
62
|
if not _factories.is_empty():
|
|
49
63
|
_writer.append("\n\nclass " + _factory_class + ":", _factories[0].root.span)
|
|
50
|
-
_writer.append("\n"+_module.indentation+"const "+_element_class+" = preload(
|
|
64
|
+
_writer.append("\n"+_module.indentation+"const "+_element_class+" = preload("+_resource(Element)+")\n")
|
|
51
65
|
# Calls in argument expressions may append additional factories.
|
|
52
66
|
var index: int = 0
|
|
53
67
|
while index < _factories.size():
|
|
@@ -93,10 +107,22 @@ func _collect(node: Model.Component, factory: Factory) -> void:
|
|
|
93
107
|
|
|
94
108
|
func _parts(parts: Array[Model.SyntaxNode]) -> void:
|
|
95
109
|
for part in parts:
|
|
96
|
-
if part is Model.Code:
|
|
110
|
+
if part is Model.Code: _code(part.span)
|
|
97
111
|
elif part is Model.Bindable: _bindable(part)
|
|
98
112
|
else: _call(part)
|
|
99
113
|
|
|
114
|
+
func _code(span: Model.Span) -> void:
|
|
115
|
+
var cursor: int = span.start.index
|
|
116
|
+
for imported in _module.resource_imports:
|
|
117
|
+
var literal_span: Model.Span = imported.span
|
|
118
|
+
if literal_span.start.index < cursor or literal_span.end.index > span.end.index: continue
|
|
119
|
+
var before := _file.span(cursor,literal_span.start.index)
|
|
120
|
+
_writer.append(_file.slice(before),before,true)
|
|
121
|
+
_writer.append(_string(Source.relative_path(_output_directory,imported.path)),literal_span)
|
|
122
|
+
cursor = literal_span.end.index
|
|
123
|
+
var rest := _file.span(cursor,span.end.index)
|
|
124
|
+
_writer.append(_file.slice(rest),rest,true)
|
|
125
|
+
|
|
100
126
|
func _call(node: Model.Component) -> void:
|
|
101
127
|
var factory := Factory.new()
|
|
102
128
|
while true:
|
|
@@ -190,7 +216,7 @@ func _bindable(property: Model.Bindable) -> void:
|
|
|
190
216
|
_writer.append(indent.repeat(2)+"var "+previous+": "+property.type_name+" = "+property.name+"\n",property.name_span)
|
|
191
217
|
_writer.append(indent.repeat(2)+property.name+" = "+incoming+"\n",property.name_span)
|
|
192
218
|
_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(
|
|
219
|
+
_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
220
|
|
|
195
221
|
func _binding_argument(argument: Argument) -> void:
|
|
196
222
|
var path := argument.binding_path.duplicate()
|
|
@@ -206,4 +232,4 @@ func _binding_argument(argument: Argument) -> void:
|
|
|
206
232
|
for name in path:
|
|
207
233
|
endpoint += "."+str(name)
|
|
208
234
|
checks.append(endpoint+" != null")
|
|
209
|
-
_writer.append("preload(
|
|
235
|
+
_writer.append("preload("+_resource(Binding)+").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)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends RefCounted
|
|
3
3
|
## Native source -> typed frontend result. No emitter, subprocess or editor state.
|
|
4
|
-
const Model = preload("
|
|
5
|
-
const Source = preload("
|
|
6
|
-
const Parser = preload("
|
|
7
|
-
const Bindable = preload("
|
|
8
|
-
const Validator = preload("
|
|
9
|
-
const Composition = preload("
|
|
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
10
|
|
|
11
|
-
static func analyze(text: String, source_name: String = "<source>") -> Model.Result:
|
|
12
|
-
var file := Source.new(text, source_name)
|
|
11
|
+
static func analyze(text: String, source_name: String = "<source>", output_path: String = "", project_sources = null) -> Model.Result:
|
|
12
|
+
var file := Source.new(text, source_name, output_path, project_sources)
|
|
13
13
|
var parser := Parser.new(file)
|
|
14
14
|
var result := Model.Result.new()
|
|
15
15
|
var module := parser.parse()
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
extends RefCounted
|
|
3
3
|
## Re-entrant token scanner: caller supplies the offset and lexical context.
|
|
4
4
|
## Regexes classify Unicode characters only; no source rewriting/evaluation.
|
|
5
|
-
const Model = preload("
|
|
6
|
-
const Source = preload("
|
|
5
|
+
const Model = preload("model.gd")
|
|
6
|
+
const Source = preload("source.gd")
|
|
7
7
|
const OPERATORS := ["**=", "<<=", ">>=", ":=", "==", "!=", "<=", ">=", "<<", ">>", "**", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "&&", "||", "->"]
|
|
8
8
|
var file: Source
|
|
9
9
|
var tokens: Array[Model.Token] = []
|
|
@@ -74,6 +74,8 @@ class Component extends SyntaxNode:
|
|
|
74
74
|
kind = "component-expression"
|
|
75
75
|
|
|
76
76
|
class Module extends RefCounted:
|
|
77
|
+
var project_imports: Dictionary = {}
|
|
78
|
+
var resource_imports: Array = []
|
|
77
79
|
var composition: bool = false
|
|
78
80
|
var parts: Array[SyntaxNode] = []
|
|
79
81
|
var identifiers: PackedStringArray = []
|
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends RefCounted
|
|
3
3
|
## Static Node type metadata. Never instantiate authored classes or use editor/tree.
|
|
4
|
-
const Model = preload("
|
|
5
|
-
const Lexer = preload("
|
|
6
|
-
const Source = preload("
|
|
7
|
-
const Parser = preload("
|
|
8
|
-
const Bindable = preload("
|
|
4
|
+
const Model = preload("../model.gd")
|
|
5
|
+
const Lexer = preload("../lexer.gd")
|
|
6
|
+
const Source = preload("../source.gd")
|
|
7
|
+
const Parser = preload("../parser.gd")
|
|
8
|
+
const Bindable = preload("../bindable.gd")
|
|
9
|
+
const ProjectSources = preload("../project_sources.gd")
|
|
9
10
|
var visiting: Dictionary = {}
|
|
10
11
|
var file
|
|
11
12
|
var aliases: Dictionary = {}
|
|
13
|
+
var native_aliases: Dictionary = {}
|
|
12
14
|
var globals: Dictionary = {}
|
|
15
|
+
var symbols: Dictionary = {}
|
|
16
|
+
var project
|
|
17
|
+
var _module
|
|
18
|
+
var source_only := false
|
|
13
19
|
|
|
14
20
|
func _init(source) -> void:
|
|
15
21
|
file = source
|
|
16
|
-
|
|
22
|
+
project = source.project
|
|
23
|
+
# Native filesystem refresh can retain a deleted class cache entry. Never
|
|
24
|
+
# let a missing Script reserve a name or fall back to its cached executable.
|
|
25
|
+
for item in ProjectSettings.get_global_class_list():
|
|
26
|
+
if FileAccess.file_exists(str(item.path)): globals[str(item["class"])] = str(item.path)
|
|
17
27
|
|
|
18
28
|
func scan(module: Model.Module) -> void:
|
|
29
|
+
_module = module
|
|
19
30
|
# Only top-level lexical declarations in authored Code ranges are imports.
|
|
20
31
|
# No evaluation or regex parsing of mixed source.
|
|
21
32
|
for part in module.parts:
|
|
@@ -28,6 +39,9 @@ func scan(module: Model.Module) -> void:
|
|
|
28
39
|
if token == null: return
|
|
29
40
|
cursor = token.span.end.index
|
|
30
41
|
if token.kind not in ["whitespace", "comment", "newline", "continuation"]: tokens.append(token)
|
|
42
|
+
for index in range(tokens.size()-1):
|
|
43
|
+
if tokens[index].text in ["var","const","func","signal","class","class_name","for"] and tokens[index+1].kind == "identifier": symbols[tokens[index+1].text] = true
|
|
44
|
+
if index>0 and tokens[index].text == ":" and tokens[index-1].kind == "identifier": symbols[tokens[index-1].text] = true
|
|
31
45
|
for index in range(tokens.size() - 5):
|
|
32
46
|
var token = tokens[index]
|
|
33
47
|
if token.text != "const" or file.text.substr(file.line_start(token.span.start.line), token.span.start.index - file.line_start(token.span.start.line)) != "": continue
|
|
@@ -47,43 +61,109 @@ func scan(module: Model.Module) -> void:
|
|
|
47
61
|
file.fail("Invalid preload path literal", tokens[next + 3].span.start.index)
|
|
48
62
|
return
|
|
49
63
|
var path: String = literal.call("value")
|
|
50
|
-
if
|
|
51
|
-
var
|
|
64
|
+
if path.begins_with("uid://"):
|
|
65
|
+
var uid := ResourceUID.text_to_id(path)
|
|
66
|
+
if not ResourceUID.has_id(uid):
|
|
67
|
+
file.fail("Unknown preload UID: "+path,tokens[next+3].span.start.index)
|
|
68
|
+
return
|
|
69
|
+
path = ResourceUID.get_id_path(uid)
|
|
70
|
+
# Baseline Godot resolves ResourceUIDs but cannot preload Scripts by
|
|
71
|
+
# UID. Emit the resolved path at this exact lexical literal on both
|
|
72
|
+
# engines; authored source and native Resource identity stay intact.
|
|
73
|
+
module.resource_imports.append({"span":tokens[next+3].span,"path":path})
|
|
74
|
+
elif not path.is_absolute_path():
|
|
75
|
+
var output: String = file.generated_path()
|
|
52
76
|
path = output.get_base_dir().path_join(path).simplify_path()
|
|
53
|
-
if not path.
|
|
54
|
-
aliases[name] = path
|
|
77
|
+
if not path.is_absolute_path(): path = "res://" + path
|
|
78
|
+
aliases[name] = path.simplify_path()
|
|
79
|
+
for index in range(tokens.size()-3):
|
|
80
|
+
if tokens[index].text!="const" or tokens[index].span.start.column!=1 or tokens[index+2].text!="=": continue
|
|
81
|
+
var target: String = tokens[index+3].text
|
|
82
|
+
if index+4<tokens.size() and tokens[index+4].span.start.line==tokens[index+3].span.start.line: continue
|
|
83
|
+
if ClassDB.class_exists(target): native_aliases[tokens[index+1].text] = target
|
|
55
84
|
|
|
56
|
-
func
|
|
85
|
+
func scope():
|
|
86
|
+
if project == null: project = ProjectSources.new()
|
|
87
|
+
return project
|
|
88
|
+
|
|
89
|
+
func resolve(name: String, span: Model.Span, project_tags: bool = true) -> Dictionary:
|
|
90
|
+
if native_aliases.has(name):
|
|
91
|
+
var native: String = native_aliases[name]
|
|
92
|
+
if not ClassDB.is_parent_class(native,"Node") or not ClassDB.can_instantiate(native): return _fail("Non-constructible native alias "+name,span)
|
|
93
|
+
return {"native":native,"script":null,"native_alias":native}
|
|
57
94
|
if aliases.has(name):
|
|
58
|
-
if ClassDB.class_exists(name)
|
|
95
|
+
if ClassDB.class_exists(name):
|
|
59
96
|
return _fail("Ambiguous GGX preload alias " + name, span)
|
|
60
|
-
|
|
61
|
-
|
|
97
|
+
var explicit := _script(name,aliases[name],span,project_tags)
|
|
98
|
+
return _import(name,explicit,explicit.get("gogo_path",""),span) if project_tags else explicit
|
|
99
|
+
if project_tags:
|
|
100
|
+
var candidates: Array = scope().named(name)
|
|
101
|
+
if not project.errors.is_empty(): return _fail("Cannot index project Gogo sources: "+str(project.errors),span)
|
|
102
|
+
if not candidates.is_empty():
|
|
103
|
+
var same_global: bool = candidates.size()==1 and globals.get(name,"")==project.resource(ProjectSources.output_for(candidates[0]))
|
|
104
|
+
if candidates.size()!=1 or symbols.has(name) or ClassDB.class_exists(name) or globals.has(name) and not same_global:
|
|
105
|
+
return _fail("Ambiguous project Gogo component "+name+": "+", ".join(candidates)+"; select a source with an explicit uniquely named preload alias",span)
|
|
106
|
+
var source: String = candidates[0]
|
|
107
|
+
var path: String = project.resource(ProjectSources.output_for(source))
|
|
108
|
+
if project.authored(file.name) == source: return _fail("Self-reference in Gogo component "+source,span)
|
|
109
|
+
var result := _gogo(name,path,project.resource(source),span)
|
|
110
|
+
return _import(name,result,path,span)
|
|
111
|
+
if globals.has(name):
|
|
112
|
+
var global := _script(name,globals[name],span,project_tags)
|
|
113
|
+
return _import(name,global,global.get("gogo_path",""),span) if project_tags else global
|
|
62
114
|
if not ClassDB.class_exists(name): return _fail("Unknown Node GGX component %s; use a native class or explicit preload alias" % JSON.stringify(name), span)
|
|
63
115
|
if not ClassDB.is_parent_class(name, "Node") or not ClassDB.can_instantiate(name):
|
|
64
116
|
return _fail("Unknown or non-constructible Node GGX type " + name, span)
|
|
65
117
|
return {"native": name, "script": null}
|
|
66
118
|
|
|
67
|
-
func
|
|
119
|
+
func _import(name: String, result: Dictionary, path: String, span: Model.Span) -> Dictionary:
|
|
120
|
+
if result.is_empty() or path.is_empty(): return result
|
|
121
|
+
var alias: String
|
|
122
|
+
if _module.project_imports.has(path): alias = _module.project_imports[path].alias
|
|
123
|
+
else:
|
|
124
|
+
alias = "_GogoProject_"+str(_module.project_imports.size())
|
|
125
|
+
while _module.identifiers.has(alias): alias += "_"
|
|
126
|
+
_module.identifiers.append(alias)
|
|
127
|
+
_module.project_imports[path] = {"alias":alias,"span":span}
|
|
128
|
+
result.project_alias = alias
|
|
129
|
+
for property in result.get("properties",{}).values():
|
|
130
|
+
if str(property.get("class_name",""))==name or str(property.get("class_name","")).begins_with(name+"."): property["class_name"] = alias+str(property["class_name"]).trim_prefix(name)
|
|
131
|
+
return result
|
|
132
|
+
|
|
133
|
+
func _script(name: String, path: String, span: Model.Span, check_constructor: bool = true) -> Dictionary:
|
|
68
134
|
var authored := path.get_base_dir().get_base_dir().path_join(path.get_file().get_basename()+".gogo")
|
|
69
|
-
if path.get_base_dir().get_file()=="generated"
|
|
135
|
+
if path.get_base_dir().get_file()=="generated":
|
|
136
|
+
if FileAccess.file_exists(authored): return _gogo(name,path,authored,span,check_constructor)
|
|
137
|
+
if FileAccess.file_exists(path+".map.json"): return _fail("Missing authored Gogo source for "+path,span)
|
|
138
|
+
# Completion uses the same lexical metadata walk for ordinary Script bases;
|
|
139
|
+
# it must not load authored scripts (including their static initializers).
|
|
140
|
+
if source_only and FileAccess.file_exists(path): return _gogo(name,path,path,span,check_constructor)
|
|
70
141
|
if not ResourceLoader.exists(path, "GDScript"): return _fail("GGX script import not found: " + path, span)
|
|
71
142
|
var script: Script = load(path)
|
|
72
143
|
# CACHE_MODE_IGNORE still changes GDScript's internal cache on tested Godot.
|
|
73
144
|
# Never mutate an application's live Script during metadata analysis.
|
|
74
145
|
if script is GDScript and script.source_code.replace("\r\n","\n") != FileAccess.get_file_as_string(path).replace("\r\n","\n"):
|
|
75
146
|
return _fail("Imported Script has unsynchronized disk/cache source; reload it in Godot before compiling GGX: " + path, span)
|
|
76
|
-
if not script is GDScript or not script.
|
|
147
|
+
if not script is GDScript or not ClassDB.is_parent_class(script.get_instance_base_type(), "Node") or not ClassDB.can_instantiate(script.get_instance_base_type()):
|
|
77
148
|
return _fail("GGX hierarchy script must be a constructible Node: " + name, span)
|
|
149
|
+
if not Engine.is_editor_hint() and not script.can_instantiate(): return _fail("GGX hierarchy script must be a constructible Node: "+name,span)
|
|
150
|
+
if script.has_method("is_abstract") and script.call("is_abstract"): return _fail("Abstract GGX component: "+name,span)
|
|
151
|
+
var required := false
|
|
78
152
|
for method in script.get_script_method_list():
|
|
79
|
-
if method.name == "_init"
|
|
80
|
-
|
|
81
|
-
|
|
153
|
+
if method.name == "_init":
|
|
154
|
+
required = method.args.size() > method.default_args.size()
|
|
155
|
+
break
|
|
156
|
+
if check_constructor and required: return _fail("GGX construction requires a zero-argument initializer: " + name, span)
|
|
157
|
+
return {"native": script.get_instance_base_type(), "script": script,"required_initializer":required}
|
|
82
158
|
|
|
83
|
-
func _gogo(name: String, path: String, authored: String, span: Model.Span) -> Dictionary:
|
|
159
|
+
func _gogo(name: String, path: String, authored: String, span: Model.Span, check_constructor: bool = true) -> Dictionary:
|
|
84
160
|
if visiting.has(path): return _fail("Cyclic Gogo component inheritance: "+path,span)
|
|
85
161
|
visiting[path] = true
|
|
86
|
-
|
|
162
|
+
# Explicit imports can reach this path before project-tag lookup initializes
|
|
163
|
+
# the optional scope. Initialize it before testing its source index.
|
|
164
|
+
scope()
|
|
165
|
+
var text: String = scope().read(project.authored(authored)) if project.sources.has(project.authored(authored)) else FileAccess.get_file_as_string(authored)
|
|
166
|
+
var source := Source.new(text,authored,path,project)
|
|
87
167
|
var module = Parser.new(source).parse()
|
|
88
168
|
if module != null: Bindable.new(source).apply(module)
|
|
89
169
|
if module == null or not source.diagnostics.is_empty():
|
|
@@ -91,6 +171,7 @@ func _gogo(name: String, path: String, authored: String, span: Model.Span) -> Di
|
|
|
91
171
|
return _fail("Invalid authored Gogo component metadata: "+authored,span)
|
|
92
172
|
var imported = get_script().new(source)
|
|
93
173
|
imported.visiting = visiting
|
|
174
|
+
imported.source_only = source_only
|
|
94
175
|
imported.scan(module)
|
|
95
176
|
var lexer := Lexer.new(source)
|
|
96
177
|
var tokens: Array = []
|
|
@@ -101,23 +182,30 @@ func _gogo(name: String, path: String, authored: String, span: Model.Span) -> Di
|
|
|
101
182
|
cursor = token.span.end.index
|
|
102
183
|
if token.kind not in ["whitespace","comment","newline","continuation"]: tokens.append(token)
|
|
103
184
|
var base := {}
|
|
185
|
+
var declared_name := ""
|
|
186
|
+
for index in range(tokens.size()-1):
|
|
187
|
+
if tokens[index].text=="class_name" and tokens[index].span.start.column==1: declared_name = tokens[index+1].text
|
|
104
188
|
for index in range(tokens.size()-1):
|
|
105
189
|
if tokens[index].text!="extends" or tokens[index].span.start.column!=1: continue
|
|
106
190
|
var target = tokens[index+1]
|
|
107
191
|
if target.kind=="string":
|
|
108
192
|
var literal: String = target.text.substr(1,target.text.length()-2)
|
|
109
193
|
if not literal.is_absolute_path(): literal = path.get_base_dir().path_join(literal).simplify_path()
|
|
110
|
-
base = imported._script(name,literal,span)
|
|
111
|
-
else: base = imported.resolve(target.text,span)
|
|
194
|
+
base = imported._script(name,literal,span,false)
|
|
195
|
+
else: base = imported.resolve(target.text,span,false)
|
|
112
196
|
break
|
|
113
197
|
visiting.erase(path)
|
|
114
198
|
if base.is_empty(): return _fail("Gogo component requires an explicit constructible Node base: "+authored,span)
|
|
199
|
+
if not ClassDB.is_parent_class(base.native,"Node"): return _fail("GGX hierarchy script must be a constructible Node: "+name,span)
|
|
200
|
+
var required: bool = base.get("required_initializer",false)
|
|
115
201
|
var properties: Dictionary = base.get("properties",{}).duplicate()
|
|
116
202
|
var signals: Dictionary = base.get("signals",{}).duplicate()
|
|
117
203
|
var declarations: Array = []
|
|
118
204
|
for index in range(tokens.size()-3):
|
|
119
205
|
var token = tokens[index]
|
|
206
|
+
if token.text == "@" and token.span.start.column == 1 and tokens[index+1].text == "abstract": return _fail("Abstract Gogo component: "+authored,span)
|
|
120
207
|
if token.text=="func" and token.span.start.column==1 and tokens[index+1].text=="_init":
|
|
208
|
+
required = false
|
|
121
209
|
var depth := 1
|
|
122
210
|
var parameter := false
|
|
123
211
|
var optional := false
|
|
@@ -126,17 +214,19 @@ func _gogo(name: String, path: String, authored: String, span: Model.Span) -> Di
|
|
|
126
214
|
elif item.text in [")","]","}"]:
|
|
127
215
|
depth -= 1
|
|
128
216
|
if depth==0:
|
|
129
|
-
if parameter and not optional:
|
|
217
|
+
if parameter and not optional: required = true
|
|
130
218
|
break
|
|
131
219
|
elif depth==1:
|
|
132
220
|
if item.text=="=": optional = true
|
|
133
221
|
elif item.text==",":
|
|
134
|
-
if parameter and not optional:
|
|
222
|
+
if parameter and not optional: required = true
|
|
135
223
|
parameter = false
|
|
136
224
|
optional = false
|
|
137
225
|
else: parameter = true
|
|
138
226
|
if token.text=="signal" and token.span.start.column==1: signals[tokens[index+1].text] = {"name":tokens[index+1].text}
|
|
139
|
-
|
|
227
|
+
var start: int = source.line_start(token.span.start.line)
|
|
228
|
+
if token.text!="var" or source.text.substr(start,1) in [" ","\t"] or tokens[index+2].text!=":": continue
|
|
229
|
+
if index>0 and tokens[index-1].text=="static" and tokens[index-1].span.start.line==token.span.start.line: continue
|
|
140
230
|
var end: int = index+3
|
|
141
231
|
while end+1<tokens.size() and tokens[end+1].span.start.line==token.span.start.line and tokens[end+1].text not in ["=",":"]: end += 1
|
|
142
232
|
declarations.append({"name":tokens[index+1].text,"type_name":source.text.substr(tokens[index+3].span.start.index,tokens[end].span.end.index-tokens[index+3].span.start.index),"signal_name":""})
|
|
@@ -146,9 +236,15 @@ func _gogo(name: String, path: String, authored: String, span: Model.Span) -> Di
|
|
|
146
236
|
var type: String = part.type_name
|
|
147
237
|
var kind: int = {"bool":TYPE_BOOL,"int":TYPE_INT,"float":TYPE_FLOAT,"String":TYPE_STRING,"StringName":TYPE_STRING_NAME,"Vector2":TYPE_VECTOR2,"Vector2i":TYPE_VECTOR2I,"Rect2":TYPE_RECT2,"Rect2i":TYPE_RECT2I,"Vector3":TYPE_VECTOR3,"Vector3i":TYPE_VECTOR3I,"Transform2D":TYPE_TRANSFORM2D,"Vector4":TYPE_VECTOR4,"Vector4i":TYPE_VECTOR4I,"Plane":TYPE_PLANE,"Quaternion":TYPE_QUATERNION,"AABB":TYPE_AABB,"Basis":TYPE_BASIS,"Transform3D":TYPE_TRANSFORM3D,"Projection":TYPE_PROJECTION,"Color":TYPE_COLOR,"NodePath":TYPE_NODE_PATH,"RID":TYPE_RID,"Callable":TYPE_CALLABLE,"Signal":TYPE_SIGNAL,"Dictionary":TYPE_DICTIONARY,"Array":TYPE_ARRAY,"PackedByteArray":TYPE_PACKED_BYTE_ARRAY,"PackedInt32Array":TYPE_PACKED_INT32_ARRAY,"PackedInt64Array":TYPE_PACKED_INT64_ARRAY,"PackedFloat32Array":TYPE_PACKED_FLOAT32_ARRAY,"PackedFloat64Array":TYPE_PACKED_FLOAT64_ARRAY,"PackedStringArray":TYPE_PACKED_STRING_ARRAY,"PackedVector2Array":TYPE_PACKED_VECTOR2_ARRAY,"PackedVector3Array":TYPE_PACKED_VECTOR3_ARRAY,"PackedColorArray":TYPE_PACKED_COLOR_ARRAY}.get(type,TYPE_OBJECT)
|
|
148
238
|
if type.begins_with("Array["): kind = TYPE_ARRAY
|
|
149
|
-
|
|
239
|
+
var qualified := ""
|
|
240
|
+
if kind==TYPE_OBJECT:
|
|
241
|
+
if type==declared_name: qualified = name
|
|
242
|
+
elif ClassDB.class_exists(type.get_slice(".",0)) or imported.globals.has(type.get_slice(".",0)): qualified = type
|
|
243
|
+
else: qualified = name+"."+type
|
|
244
|
+
properties[part.name] = {"name":part.name,"type":kind,"class_name":qualified,"usage":PROPERTY_USAGE_DEFAULT}
|
|
150
245
|
if not part.signal_name.is_empty(): signals[part.signal_name] = {"name":part.signal_name}
|
|
151
|
-
return
|
|
246
|
+
if check_constructor and required: return _fail("GGX construction requires a zero-argument initializer: "+name,span)
|
|
247
|
+
return {"native":base.native,"script":base.script,"properties":properties,"signals":signals,"required_initializer":required,"gogo_path":path}
|
|
152
248
|
|
|
153
249
|
func _fail(message: String, span: Model.Span) -> Dictionary:
|
|
154
250
|
file.fail(message, span.start.index, span.end.index)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends RefCounted
|
|
3
3
|
## Recursive-descent component islands composed with lexically retained GDScript.
|
|
4
|
-
const Model = preload("
|
|
5
|
-
const Source = preload("
|
|
6
|
-
const Lexer = preload("
|
|
4
|
+
const Model = preload("model.gd")
|
|
5
|
+
const Source = preload("source.gd")
|
|
6
|
+
const Lexer = preload("lexer.gd")
|
|
7
7
|
const OPERANDS := ["return", "yield", "await", "if", "elif", "else", "while", "in", "and", "or", "not", "assert", "match"]
|
|
8
8
|
const OPEN := {"(": ")", "[": "]", "{": "}"}
|
|
9
9
|
var file: Source
|