@papercraftgames/estragon 0.0.0-stage → 0.1.0-beta.10
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 +15 -0
- package/LICENSE +20 -0
- package/README.md +31 -2
- package/addons/estragon/compiler/bindable.gd +213 -0
- package/addons/estragon/compiler/bindable.gd.uid +1 -0
- package/addons/estragon/compiler/compiler.gd +24 -0
- package/addons/estragon/compiler/compiler.gd.uid +1 -0
- package/addons/estragon/compiler/composition.gd +52 -0
- package/addons/estragon/compiler/composition.gd.uid +1 -0
- package/addons/estragon/compiler/diagnostic_capture.gd.txt +18 -0
- package/addons/estragon/compiler/emitter.gd +235 -0
- package/addons/estragon/compiler/emitter.gd.uid +1 -0
- package/addons/estragon/compiler/frontend.gd +22 -0
- package/addons/estragon/compiler/frontend.gd.uid +1 -0
- package/addons/estragon/compiler/lexer.gd +78 -0
- package/addons/estragon/compiler/lexer.gd.uid +1 -0
- package/addons/estragon/compiler/model.gd +89 -0
- package/addons/estragon/compiler/model.gd.uid +1 -0
- package/addons/estragon/compiler/native/resolver.gd +293 -0
- package/addons/estragon/compiler/native/resolver.gd.uid +1 -0
- package/addons/estragon/compiler/parser.gd +252 -0
- package/addons/estragon/compiler/parser.gd.uid +1 -0
- 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 +80 -0
- package/addons/estragon/compiler/script_validation.gd.uid +1 -0
- package/addons/estragon/compiler/source.gd +82 -0
- package/addons/estragon/compiler/source.gd.uid +1 -0
- package/addons/estragon/compiler/source_map.gd +59 -0
- package/addons/estragon/compiler/source_map.gd.uid +1 -0
- package/addons/estragon/compiler/validator.gd +278 -0
- package/addons/estragon/compiler/validator.gd.uid +1 -0
- package/addons/estragon/editor/buffer_guard.gd +84 -0
- package/addons/estragon/editor/buffer_guard.gd.uid +1 -0
- package/addons/estragon/editor/build_service.gd +271 -0
- package/addons/estragon/editor/build_service.gd.uid +1 -0
- package/addons/estragon/editor/completion.gd +404 -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 +18 -0
- package/addons/estragon/editor/components.gd.uid +1 -0
- package/addons/estragon/editor/creation_menu.gd.txt +14 -0
- package/addons/estragon/editor/highlighter.gd +75 -0
- package/addons/estragon/editor/highlighter.gd.uid +1 -0
- package/addons/estragon/editor/highlighter_association.gd +89 -0
- package/addons/estragon/editor/highlighter_association.gd.uid +1 -0
- 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/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 +7 -0
- package/addons/estragon/editor/plugin.gd +313 -0
- package/addons/estragon/editor/plugin.gd.uid +1 -0
- package/addons/estragon/editor/scene_components.gd +265 -0
- package/addons/estragon/editor/scene_components.gd.uid +1 -0
- package/addons/estragon/editor/scene_inspector.gd +31 -0
- package/addons/estragon/editor/scene_inspector.gd.uid +1 -0
- package/addons/estragon/editor/script_dependencies.gd +47 -0
- package/addons/estragon/editor/script_dependencies.gd.uid +1 -0
- package/addons/estragon/runtime/composition/binding.gd +62 -0
- package/addons/estragon/runtime/composition/binding.gd.uid +1 -0
- package/addons/estragon/runtime/composition/computation.gd +477 -0
- package/addons/estragon/runtime/composition/computation.gd.uid +1 -0
- package/addons/estragon/runtime/composition/element.gd +23 -0
- package/addons/estragon/runtime/composition/element.gd.uid +1 -0
- package/addons/estragon/runtime/composition/profile.gd +21 -0
- package/addons/estragon/runtime/composition/profile.gd.uid +1 -0
- package/addons/estragon/runtime/composition/profile.tres +6 -0
- package/addons/estragon/runtime/composition/state.gd +65 -0
- package/addons/estragon/runtime/composition/state.gd.uid +1 -0
- package/addons/estragon/runtime/composition/state.tres +6 -0
- package/addons/estragon/runtime/node/button.gd +53 -0
- package/addons/estragon/runtime/node/button.gd.uid +1 -0
- package/addons/estragon/runtime/node/component_2d.gd +105 -0
- package/addons/estragon/runtime/node/component_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/component_3d.gd +91 -0
- package/addons/estragon/runtime/node/component_3d.gd.uid +1 -0
- package/addons/estragon/runtime/node/estragon_2d.gd +32 -0
- package/addons/estragon/runtime/node/estragon_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/estragon_3d.gd +15 -0
- package/addons/estragon/runtime/node/estragon_3d.gd.uid +1 -0
- package/addons/estragon/runtime/node/hbox.gd +6 -0
- package/addons/estragon/runtime/node/hbox.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/coordinator.gd +145 -0
- package/addons/estragon/runtime/node/internal/coordinator.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd +115 -0
- package/addons/estragon/runtime/node/internal/layout_core.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/native_bounds.gd +103 -0
- package/addons/estragon/runtime/node/internal/native_bounds.gd.uid +1 -0
- package/addons/estragon/runtime/node/internal/pointer_2d.gd +70 -0
- package/addons/estragon/runtime/node/internal/pointer_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/native_2d.gd +40 -0
- package/addons/estragon/runtime/node/native_2d.gd.uid +1 -0
- package/addons/estragon/runtime/node/native_3d.gd +40 -0
- package/addons/estragon/runtime/node/native_3d.gd.uid +1 -0
- package/addons/estragon/runtime/node/rect.gd +15 -0
- package/addons/estragon/runtime/node/rect.gd.uid +1 -0
- package/addons/estragon/runtime/node/text.gd +66 -0
- package/addons/estragon/runtime/node/text.gd.uid +1 -0
- package/addons/estragon/runtime/node/toggle.gd +23 -0
- package/addons/estragon/runtime/node/toggle.gd.uid +1 -0
- package/addons/estragon/runtime/node/vbox.gd +6 -0
- package/addons/estragon/runtime/node/vbox.gd.uid +1 -0
- package/package.json +31 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Release notes
|
|
2
|
+
|
|
3
|
+
## Gogo editor experience — upcoming beta
|
|
4
|
+
|
|
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.
|
|
10
|
+
|
|
11
|
+
## Initial public beta
|
|
12
|
+
|
|
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.
|
|
14
|
+
|
|
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/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Resist Design
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @papercraftgames/estragon
|
|
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
|
+
|
|
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
|
+
|
|
7
|
+
## Install into a Godot project
|
|
8
|
+
|
|
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:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
yarn add --exact --ignore-scripts @papercraftgames/estragon@beta
|
|
13
|
+
```
|
|
14
|
+
|
|
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):
|
|
16
|
+
|
|
17
|
+
```ini
|
|
18
|
+
[editor_plugins]
|
|
19
|
+
enabled=PackedStringArray("res://node_modules/@papercraftgames/estragon/addons/estragon/editor/plugin.cfg")
|
|
20
|
+
```
|
|
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.
|
|
25
|
+
|
|
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.
|
|
27
|
+
|
|
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).
|
|
29
|
+
|
|
30
|
+
Canonical widgets: EstragonRect/Text/Button/Toggle/HBox/VBox. Class-wide typed Gogo bindables, nested conditionals/keyed lists and bounded bool `bind:value` share one native manager. This is not a complete styling/focus/text/IME/accessibility suite. Target Godot 4.0+; fresh verification is only official Linux 4.0.4 and pinned 4.7.0, no untested platform/minor certification. Current documented older-engine diagnostics and #44 highlighter limitation remain.
|
|
31
|
+
|
|
32
|
+
MIT. Original copyright and attribution are retained in LICENSE; repository ownership transfer does not alter them. No install scripts, JavaScript compiler, tests, examples, raw Assets or contributor dependencies are shipped.
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## One lexical property lowering for explicit and class-wide Gogo annotations.
|
|
4
|
+
const Model = preload("model.gd")
|
|
5
|
+
const Source = preload("source.gd")
|
|
6
|
+
const Lexer = preload("lexer.gd")
|
|
7
|
+
var file: Source
|
|
8
|
+
var module: Model.Module
|
|
9
|
+
var members: Dictionary = {}
|
|
10
|
+
var properties: Dictionary = {}
|
|
11
|
+
var class_marker: Model.Span
|
|
12
|
+
func _init(source: Source) -> void:
|
|
13
|
+
file = source
|
|
14
|
+
func apply(value: Model.Module) -> void:
|
|
15
|
+
module = value
|
|
16
|
+
_class_scope(module.parts)
|
|
17
|
+
if not file.diagnostics.is_empty(): return
|
|
18
|
+
_collect(module.parts)
|
|
19
|
+
module.parts.assign(_parts(module.parts))
|
|
20
|
+
# A class marker is unambiguous only in the script preamble, directly
|
|
21
|
+
# before extends/class_name. Existing preceding-line property markers stay so.
|
|
22
|
+
func _class_scope(parts: Array) -> void:
|
|
23
|
+
var preamble := true
|
|
24
|
+
for part in parts:
|
|
25
|
+
if not part is Model.Code: continue
|
|
26
|
+
var lexer := Lexer.new(file)
|
|
27
|
+
var cursor: int = part.span.start.index
|
|
28
|
+
while cursor<part.span.end.index:
|
|
29
|
+
var token = lexer.next_token(cursor)
|
|
30
|
+
if token==null: return
|
|
31
|
+
cursor = token.span.end.index
|
|
32
|
+
if token.text in ["var","static","const","func","signal","class"] and (token.span.start.column==1 or file.text[file.line_start(token.span.start.line)]=="@"): preamble = false
|
|
33
|
+
if token.span.start.column!=1: continue
|
|
34
|
+
if token.text!="@": continue
|
|
35
|
+
var name = lexer.next_token(cursor)
|
|
36
|
+
if name==null or name.text.to_lower()!="bindable": continue
|
|
37
|
+
var following = _next(lexer,name.span.end.index,true)
|
|
38
|
+
if following==null or following.text not in ["extends","class_name"]: continue
|
|
39
|
+
if not preamble or following.span.start.column!=1 or following.span.start.line==token.span.start.line:
|
|
40
|
+
file.fail("Class @bindable must be a standalone preamble annotation before extends or class_name",token.span.start.index,name.span.end.index)
|
|
41
|
+
return
|
|
42
|
+
if class_marker!=null:
|
|
43
|
+
file.fail("Duplicate class @bindable annotation",token.span.start.index,name.span.end.index)
|
|
44
|
+
return
|
|
45
|
+
class_marker = file.span(token.span.start.index,name.span.end.index)
|
|
46
|
+
func _collect(parts: Array) -> void:
|
|
47
|
+
for part in parts:
|
|
48
|
+
if not part is Model.Code: continue
|
|
49
|
+
var lexer := Lexer.new(file)
|
|
50
|
+
var cursor: int = part.span.start.index
|
|
51
|
+
while cursor < part.span.end.index:
|
|
52
|
+
var token = lexer.next_token(cursor)
|
|
53
|
+
if token == null: return
|
|
54
|
+
cursor = token.span.end.index
|
|
55
|
+
if token.kind == "identifier" and token.text in ["var","signal","const","func","class"] and (token.span.start.column == 1 or file.text[file.line_start(token.span.start.line)] == "@" or file.text.substr(file.line_start(token.span.start.line),token.span.start.index-file.line_start(token.span.start.line)).strip_edges()=="static"):
|
|
56
|
+
var name = lexer.next_token(cursor)
|
|
57
|
+
while name != null and name.kind == "whitespace": name = lexer.next_token(name.span.end.index)
|
|
58
|
+
if name != null and name.kind == "identifier": members[name.text] = name.span
|
|
59
|
+
func _parts(parts: Array) -> Array[Model.SyntaxNode]:
|
|
60
|
+
var result: Array[Model.SyntaxNode] = []
|
|
61
|
+
for part in parts:
|
|
62
|
+
if not file.diagnostics.is_empty(): break
|
|
63
|
+
if part is Model.GdExpression:
|
|
64
|
+
part.parts.assign(_parts(part.parts))
|
|
65
|
+
elif part is Model.Component:
|
|
66
|
+
for attribute in part.attributes:
|
|
67
|
+
if attribute.value is Model.GdExpression: attribute.value.parts.assign(_parts(attribute.value.parts))
|
|
68
|
+
part.children.assign(_parts(part.children))
|
|
69
|
+
if not part is Model.Code:
|
|
70
|
+
result.append(part)
|
|
71
|
+
continue
|
|
72
|
+
var lexer := Lexer.new(file)
|
|
73
|
+
var cursor: int = part.span.start.index
|
|
74
|
+
var copied := cursor
|
|
75
|
+
var pending_annotation: bool = false
|
|
76
|
+
var annotations_start := -1
|
|
77
|
+
var onready := false
|
|
78
|
+
var static_field := false
|
|
79
|
+
while cursor < part.span.end.index and file.diagnostics.is_empty():
|
|
80
|
+
var token = lexer.next_token(cursor)
|
|
81
|
+
if token == null: break
|
|
82
|
+
cursor = token.span.end.index
|
|
83
|
+
if token.text == "@":
|
|
84
|
+
var name = lexer.next_token(cursor)
|
|
85
|
+
if name == null: break
|
|
86
|
+
if name.text.to_lower() == "bindable":
|
|
87
|
+
if file.name.get_extension().to_lower() in ["gd","bgd"]:
|
|
88
|
+
file.fail("@bindable is supported only in Gogo source",token.span.start.index,name.span.end.index)
|
|
89
|
+
break
|
|
90
|
+
if name.text != "bindable":
|
|
91
|
+
file.fail("Only lowercase @bindable is supported",token.span.start.index,name.span.end.index)
|
|
92
|
+
break
|
|
93
|
+
if class_marker!=null and token.span.start.index==class_marker.start.index:
|
|
94
|
+
if copied<token.span.start.index:
|
|
95
|
+
var before := Model.Code.new()
|
|
96
|
+
before.span = file.span(copied,token.span.start.index)
|
|
97
|
+
result.append(before)
|
|
98
|
+
cursor = name.span.end.index
|
|
99
|
+
copied = cursor
|
|
100
|
+
continue
|
|
101
|
+
if class_marker!=null and _next(lexer,name.span.end.index,true).text=="@":
|
|
102
|
+
file.fail("Duplicate/conflicting @bindable annotation",token.span.start.index,name.span.end.index)
|
|
103
|
+
break
|
|
104
|
+
if token.span.start.column != 1 or pending_annotation:
|
|
105
|
+
file.fail("@bindable requires a top-level instance property without annotation composition",token.span.start.index)
|
|
106
|
+
break
|
|
107
|
+
var property = _property(lexer,name.span.end.index,part.span.end.index,token.span.start.index)
|
|
108
|
+
if property == null: break
|
|
109
|
+
if copied < token.span.start.index:
|
|
110
|
+
var before := Model.Code.new()
|
|
111
|
+
before.span = file.span(copied,token.span.start.index)
|
|
112
|
+
result.append(before)
|
|
113
|
+
result.append(property)
|
|
114
|
+
cursor = property.span.end.index
|
|
115
|
+
copied = cursor
|
|
116
|
+
pending_annotation = false
|
|
117
|
+
continue
|
|
118
|
+
if token.span.start.column==1 and name.text not in ["tool","icon","static_unload"]:
|
|
119
|
+
pending_annotation = true
|
|
120
|
+
if annotations_start<0: annotations_start = token.span.start.index
|
|
121
|
+
onready = onready or name.text=="onready"
|
|
122
|
+
if token.text=="static": static_field = true
|
|
123
|
+
if class_marker!=null and not static_field and token.text=="var" and (token.span.start.column==1 or annotations_start>=0 and file.text[file.line_start(token.span.start.line)]=="@"):
|
|
124
|
+
var field = _next(lexer,token.span.end.index)
|
|
125
|
+
var colon = _next(lexer,field.span.end.index) if field!=null else null
|
|
126
|
+
# Untyped/inferred/static/local/inner fields are ordinary GDScript.
|
|
127
|
+
if colon!=null and colon.text==":":
|
|
128
|
+
if onready:
|
|
129
|
+
file.fail("Class @bindable does not support @onready fields; use selective property annotations",annotations_start,token.span.end.index)
|
|
130
|
+
break
|
|
131
|
+
var start: int = annotations_start if annotations_start>=0 else token.span.start.index
|
|
132
|
+
var property = _property(lexer,token.span.start.index,part.span.end.index,start)
|
|
133
|
+
if property==null: break
|
|
134
|
+
if start<token.span.start.index: property.annotations_span = file.span(start,token.span.start.index)
|
|
135
|
+
if copied<start:
|
|
136
|
+
var before := Model.Code.new()
|
|
137
|
+
before.span = file.span(copied,start)
|
|
138
|
+
result.append(before)
|
|
139
|
+
result.append(property)
|
|
140
|
+
cursor = property.span.end.index
|
|
141
|
+
copied = cursor
|
|
142
|
+
if token.text=="var" or token.span.start.column==1 and token.text in ["func","const","class","signal","extends","class_name"]:
|
|
143
|
+
pending_annotation = false
|
|
144
|
+
annotations_start = -1
|
|
145
|
+
onready = false
|
|
146
|
+
static_field = false
|
|
147
|
+
if copied < part.span.end.index:
|
|
148
|
+
var after := Model.Code.new()
|
|
149
|
+
after.span = file.span(copied,part.span.end.index)
|
|
150
|
+
result.append(after)
|
|
151
|
+
return result
|
|
152
|
+
func _next(lexer, cursor: int, lines: bool = false):
|
|
153
|
+
var token = lexer.next_token(cursor)
|
|
154
|
+
while token != null and (token.kind in ["whitespace","comment"] or lines and token.kind == "newline"):
|
|
155
|
+
token = lexer.next_token(token.span.end.index)
|
|
156
|
+
return token
|
|
157
|
+
func _property(lexer, cursor: int, limit: int, start: int):
|
|
158
|
+
var declaration = _next(lexer,cursor,true)
|
|
159
|
+
if declaration == null: return null
|
|
160
|
+
if declaration.text != "var" or declaration.span.start.column != 1 and declaration.span.start.line != file.position(start).line:
|
|
161
|
+
file.fail("@bindable requires var name: ExplicitType, with no arguments or other annotations",start,declaration.span.end.index)
|
|
162
|
+
return null
|
|
163
|
+
var name = _next(lexer,declaration.span.end.index)
|
|
164
|
+
var colon = _next(lexer,name.span.end.index) if name != null else null
|
|
165
|
+
if name == null or name.kind != "identifier" or colon == null or colon.text != ":":
|
|
166
|
+
file.fail("@bindable requires an explicit property type (var name: Type)",start)
|
|
167
|
+
return null
|
|
168
|
+
var token = _next(lexer,colon.span.end.index)
|
|
169
|
+
if token == null or token.kind != "identifier":
|
|
170
|
+
file.fail("@bindable requires an explicit property type",colon.span.end.index)
|
|
171
|
+
return null
|
|
172
|
+
var property := Model.Bindable.new()
|
|
173
|
+
property.name = name.text
|
|
174
|
+
property.name_span = name.span
|
|
175
|
+
property.type_span = token.span
|
|
176
|
+
property.signal_name = property.name+"_changed"
|
|
177
|
+
if properties.has(property.name) or members.has(property.signal_name):
|
|
178
|
+
file.fail("@bindable property/signal collision: "+property.signal_name,name.span.start.index,name.span.end.index)
|
|
179
|
+
return null
|
|
180
|
+
properties[property.name] = true
|
|
181
|
+
var depth: int = 0
|
|
182
|
+
var initialized: bool = false
|
|
183
|
+
var declaration_end: int = token.span.end.index
|
|
184
|
+
var comment_start: int = -1
|
|
185
|
+
cursor = token.span.start.index
|
|
186
|
+
while cursor < limit:
|
|
187
|
+
token = lexer.next_token(cursor)
|
|
188
|
+
if token == null: return null
|
|
189
|
+
if depth == 0 and token.kind in ["newline","eof"]: break
|
|
190
|
+
if token.text == ";" or depth == 0 and token.text == ":":
|
|
191
|
+
file.fail("@bindable does not support multiple declarations or custom accessors",token.span.start.index,token.span.end.index)
|
|
192
|
+
return null
|
|
193
|
+
if not initialized and depth == 0 and token.text == "=":
|
|
194
|
+
property.type_span = file.span(property.type_span.start.index,declaration_end)
|
|
195
|
+
initialized = true
|
|
196
|
+
if token.text in ["(","[","{"]: depth += 1
|
|
197
|
+
elif token.text in [")","]","}"]: depth -= 1
|
|
198
|
+
if token.kind == "comment" and depth == 0: comment_start = token.span.start.index
|
|
199
|
+
elif token.kind not in ["whitespace","comment","newline"]: declaration_end = token.span.end.index
|
|
200
|
+
cursor = token.span.end.index
|
|
201
|
+
if not initialized: property.type_span = file.span(property.type_span.start.index,declaration_end)
|
|
202
|
+
if depth != 0 or cursor == limit and limit < file.text.length() and file.text[limit] not in ["\r","\n"]:
|
|
203
|
+
file.fail("@bindable initializer must be native GDScript, not a GGX element",start,cursor)
|
|
204
|
+
return null
|
|
205
|
+
var following = _next(lexer,cursor,true)
|
|
206
|
+
if following != null and following.span.start.column > 1 and following.text in ["get","set"]:
|
|
207
|
+
file.fail("@bindable custom accessors are not supported",following.span.start.index,following.span.end.index)
|
|
208
|
+
return null
|
|
209
|
+
property.declaration_span = file.span(declaration.span.start.index,declaration_end)
|
|
210
|
+
if comment_start >= 0: property.comment_span = file.span(comment_start,cursor)
|
|
211
|
+
property.span = file.span(start,cursor)
|
|
212
|
+
property.type_name = file.slice(property.type_span)
|
|
213
|
+
return property
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://c3vrrhkb44gdr
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Pure native compilation. Semantic validation/loading is an explicit next step.
|
|
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
|
+
|
|
10
|
+
class Compilation extends RefCounted:
|
|
11
|
+
var code: String
|
|
12
|
+
var source_map: SourceMap
|
|
13
|
+
var diagnostics: Array[Model.Diagnostic] = []
|
|
14
|
+
var ok: bool:
|
|
15
|
+
get: return diagnostics.is_empty() and source_map != null
|
|
16
|
+
|
|
17
|
+
static func compile(source: String, source_name: String = "<source>", output_path: String = "", project_sources = null) -> Compilation:
|
|
18
|
+
var result := Compilation.new()
|
|
19
|
+
var frontend := Frontend.analyze(source, source_name, output_path, project_sources)
|
|
20
|
+
result.diagnostics = frontend.diagnostics
|
|
21
|
+
if not frontend.ok: return result
|
|
22
|
+
result.source_map = Emitter.new(frontend.module, Source.new(source, source_name, output_path)).emit()
|
|
23
|
+
result.code = result.source_map.code
|
|
24
|
+
return result
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://cvx6tiy2b0yme
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Detect the automatic host entry. Every GGX expression is a description.
|
|
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")
|
|
8
|
+
var file
|
|
9
|
+
func _init(source) -> void:
|
|
10
|
+
file = source
|
|
11
|
+
func apply(module) -> void:
|
|
12
|
+
var resolver := Resolver.new(file)
|
|
13
|
+
resolver.scan(module)
|
|
14
|
+
var lexer := Lexer.new(file)
|
|
15
|
+
var tokens: Array = []
|
|
16
|
+
var cursor := 0
|
|
17
|
+
while cursor < file.text.length():
|
|
18
|
+
var token = lexer.next_token(cursor)
|
|
19
|
+
if token == null: return
|
|
20
|
+
cursor = token.span.end.index
|
|
21
|
+
if token.kind not in ["whitespace","newline","comment","continuation"]: tokens.append(token)
|
|
22
|
+
var has_ggx := false
|
|
23
|
+
for part in module.parts:
|
|
24
|
+
if part is Model.Component: has_ggx = true
|
|
25
|
+
var start := -1
|
|
26
|
+
for index in range(tokens.size()-6):
|
|
27
|
+
var token = tokens[index]
|
|
28
|
+
if token.text!="func" or token.span.start.column!=1 or tokens[index+1].text!="build_view": continue
|
|
29
|
+
if tokens[index+2].text!="(" or tokens[index+3].text!=")" or tokens[index+4].text!="->":
|
|
30
|
+
if has_ggx:
|
|
31
|
+
file.fail("GGX hosts require zero-argument build_view() -> Element with an explicit preload alias",tokens[index+1].span.start.index,tokens[index+1].span.end.index)
|
|
32
|
+
return
|
|
33
|
+
continue
|
|
34
|
+
var type: String = tokens[index+5].text
|
|
35
|
+
if resolver.aliases.get(type,"")!=(Element as Script).resource_path:
|
|
36
|
+
if has_ggx and type in ["Node","Node2D","Node3D"]:
|
|
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)
|
|
38
|
+
return
|
|
39
|
+
if has_ggx:
|
|
40
|
+
file.fail("GGX build_view return type must preload composition/element.gd",tokens[index+5].span.start.index,tokens[index+5].span.end.index)
|
|
41
|
+
return
|
|
42
|
+
continue
|
|
43
|
+
if start>=0:
|
|
44
|
+
file.fail("Duplicate build_view composition function",token.span.start.index)
|
|
45
|
+
return
|
|
46
|
+
start = token.span.start.index
|
|
47
|
+
if start<0: return
|
|
48
|
+
module.composition = true
|
|
49
|
+
for index in range(tokens.size()-1):
|
|
50
|
+
if tokens[index].text=="func" and tokens[index].span.start.column==1 and tokens[index+1].text=="_notification":
|
|
51
|
+
file.fail("Composition owns _notification; use ordinary _ready/event methods",tokens[index+1].span.start.index)
|
|
52
|
+
return
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://db7qrj05peytx
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends Logger
|
|
3
|
+
## Loaded only when this engine exposes the native diagnostic API.
|
|
4
|
+
var path: String
|
|
5
|
+
var messages: Array[Dictionary] = []
|
|
6
|
+
var _mutex := Mutex.new()
|
|
7
|
+
|
|
8
|
+
func _log_error(_function: String, file: String, line: int, code: String, rationale: String, _notify: bool, error_type: int, _backtraces: Array[ScriptBacktrace]) -> void:
|
|
9
|
+
if file != path or error_type != ERROR_TYPE_SCRIPT: return
|
|
10
|
+
_mutex.lock()
|
|
11
|
+
messages.append({"line": line, "message": rationale if not rationale.is_empty() else code})
|
|
12
|
+
_mutex.unlock()
|
|
13
|
+
|
|
14
|
+
func snapshot() -> Array[Dictionary]:
|
|
15
|
+
_mutex.lock()
|
|
16
|
+
var copy: Array[Dictionary] = messages.duplicate()
|
|
17
|
+
_mutex.unlock()
|
|
18
|
+
return copy
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Typed frontend -> ordinary GDScript. All output is range-mapped, never rewritten.
|
|
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")
|
|
10
|
+
|
|
11
|
+
class Argument extends RefCounted:
|
|
12
|
+
var expression: Model.GdExpression
|
|
13
|
+
var type_name: String
|
|
14
|
+
var name: String
|
|
15
|
+
var binding_path: Array = []
|
|
16
|
+
|
|
17
|
+
class Factory extends RefCounted:
|
|
18
|
+
var name: String
|
|
19
|
+
var root: Model.Component
|
|
20
|
+
var arguments: Array[Argument] = []
|
|
21
|
+
|
|
22
|
+
var _output_directory: String
|
|
23
|
+
var _module: Model.Module
|
|
24
|
+
var _file: Source
|
|
25
|
+
var _writer: MappedWriter
|
|
26
|
+
var _factories: Array[Factory] = []
|
|
27
|
+
var _arguments: Dictionary = {}
|
|
28
|
+
var _sequence: int = 0
|
|
29
|
+
var _variable: int = 0
|
|
30
|
+
var _factory_class: String
|
|
31
|
+
var _element_class: String
|
|
32
|
+
|
|
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
|
|
38
|
+
_module = module
|
|
39
|
+
_file = file
|
|
40
|
+
_writer = MappedWriter.new(file)
|
|
41
|
+
# Explicit class lookup avoids old native lambda resolution of bare static
|
|
42
|
+
# methods. Arguments still use ordinary typed calls in authored scope.
|
|
43
|
+
var index := 0
|
|
44
|
+
while true:
|
|
45
|
+
_factory_class = "_GogoFactories_%d" % index
|
|
46
|
+
if not _module.identifiers.has(_factory_class): break
|
|
47
|
+
index += 1
|
|
48
|
+
_element_class = "_GogoElement_0"
|
|
49
|
+
while _module.identifiers.has(_element_class): _element_class += "_"
|
|
50
|
+
|
|
51
|
+
func _resource(resource: Resource) -> String:
|
|
52
|
+
return _string(Source.relative_path(_output_directory,resource.resource_path))
|
|
53
|
+
|
|
54
|
+
func emit() -> MappedWriter:
|
|
55
|
+
_parts(_module.parts)
|
|
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)
|
|
60
|
+
if _module.composition:
|
|
61
|
+
_writer.append("\nfunc _notification(_gogo_what: int) -> void:\n"+_module.indentation+"preload("+_resource(State)+").lifecycle(self, _gogo_what)\n")
|
|
62
|
+
if not _factories.is_empty():
|
|
63
|
+
_writer.append("\n\nclass " + _factory_class + ":", _factories[0].root.span)
|
|
64
|
+
_writer.append("\n"+_module.indentation+"const "+_element_class+" = preload("+_resource(Element)+")\n")
|
|
65
|
+
# Calls in argument expressions may append additional factories.
|
|
66
|
+
var index: int = 0
|
|
67
|
+
while index < _factories.size():
|
|
68
|
+
_factory(_factories[index])
|
|
69
|
+
index += 1
|
|
70
|
+
_writer.finish()
|
|
71
|
+
return _writer
|
|
72
|
+
|
|
73
|
+
## Escape a GDScript literal character-by-character; never touch authored code.
|
|
74
|
+
static func _string(value: String) -> String:
|
|
75
|
+
var output := '"'
|
|
76
|
+
for character in value:
|
|
77
|
+
match character:
|
|
78
|
+
'"': output += '\\"'
|
|
79
|
+
"\\": output += "\\\\"
|
|
80
|
+
"\n": output += "\\n"
|
|
81
|
+
"\r": output += "\\r"
|
|
82
|
+
"\t": output += "\\t"
|
|
83
|
+
_:
|
|
84
|
+
var point := character.unicode_at(0)
|
|
85
|
+
output += "\\u%04x" % point if point < 32 else character
|
|
86
|
+
return output + '"'
|
|
87
|
+
|
|
88
|
+
static func literal(value: Model.Literal) -> String:
|
|
89
|
+
return _string(value.value)
|
|
90
|
+
|
|
91
|
+
func _argument(expression: Model.GdExpression, type_name: String, factory: Factory) -> void:
|
|
92
|
+
var argument := Argument.new()
|
|
93
|
+
argument.expression = expression
|
|
94
|
+
argument.type_name = type_name
|
|
95
|
+
argument.name = "_gogo_value_%d" % factory.arguments.size()
|
|
96
|
+
factory.arguments.append(argument)
|
|
97
|
+
_arguments[expression] = argument
|
|
98
|
+
|
|
99
|
+
func _collect(node: Model.Component, factory: Factory) -> void:
|
|
100
|
+
for attribute in node.attributes:
|
|
101
|
+
if attribute.value is Model.GdExpression:
|
|
102
|
+
_argument(attribute.value, attribute.type_name, factory)
|
|
103
|
+
if attribute.kind=="binding": factory.arguments.back().binding_path = attribute.binding_path
|
|
104
|
+
for child in node.children:
|
|
105
|
+
if child is Model.GdExpression: _argument(child,"Variant",factory)
|
|
106
|
+
else: _collect(child, factory)
|
|
107
|
+
|
|
108
|
+
func _parts(parts: Array[Model.SyntaxNode]) -> void:
|
|
109
|
+
for part in parts:
|
|
110
|
+
if part is Model.Code: _code(part.span)
|
|
111
|
+
elif part is Model.Bindable: _bindable(part)
|
|
112
|
+
else: _call(part)
|
|
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
|
+
|
|
126
|
+
func _call(node: Model.Component) -> void:
|
|
127
|
+
var factory := Factory.new()
|
|
128
|
+
while true:
|
|
129
|
+
factory.name = "_gogo_build_%d" % _sequence
|
|
130
|
+
_sequence += 1
|
|
131
|
+
if not _module.identifiers.has(factory.name): break
|
|
132
|
+
factory.root = node
|
|
133
|
+
_factories.append(factory)
|
|
134
|
+
_collect(node, factory)
|
|
135
|
+
var multiline := factory.arguments.size() > 3
|
|
136
|
+
var start := _file.line_start(node.span.start.line)
|
|
137
|
+
var end := start
|
|
138
|
+
while end < _file.text.length() and _file.text[end] in [" ", "\t"]: end += 1
|
|
139
|
+
var base := _file.text.substr(start, end - start)
|
|
140
|
+
_writer.append(_factory_class + "." + factory.name + "(", node.span)
|
|
141
|
+
for index in range(factory.arguments.size()):
|
|
142
|
+
var argument := factory.arguments[index]
|
|
143
|
+
if index > 0: _writer.append("," if multiline else ", ", node.span)
|
|
144
|
+
if multiline: _writer.append("\n" + base + _module.indentation, argument.expression.span)
|
|
145
|
+
_writer.append("(", argument.expression.span)
|
|
146
|
+
if argument.binding_path.is_empty(): _parts(argument.expression.parts)
|
|
147
|
+
else: _binding_argument(argument)
|
|
148
|
+
_writer.append(")", argument.expression.span)
|
|
149
|
+
_writer.append(("\n" + base if multiline else "") + ")", node.span)
|
|
150
|
+
|
|
151
|
+
func _factory(factory: Factory) -> void:
|
|
152
|
+
_writer.append("\n\n" + _module.indentation + "static func " + factory.name + "(", factory.root.span)
|
|
153
|
+
var multiline := factory.arguments.size() > 3
|
|
154
|
+
for index in range(factory.arguments.size()):
|
|
155
|
+
var argument := factory.arguments[index]
|
|
156
|
+
if index > 0: _writer.append("," if multiline else ", ", argument.expression.span)
|
|
157
|
+
_writer.append(("\n" + _module.indentation.repeat(2) if multiline else "") + argument.name + ": " + argument.type_name, argument.expression.span)
|
|
158
|
+
_writer.append(("\n" + _module.indentation if multiline else "") + ") -> " + _element_class + ":\n", factory.root.span)
|
|
159
|
+
_variable = 0
|
|
160
|
+
var variable := _description(factory.root,_module.indentation.repeat(2))
|
|
161
|
+
_writer.append(_module.indentation.repeat(2) + "return " + variable + "\n", factory.root.span)
|
|
162
|
+
|
|
163
|
+
func _line(text: String, span: Model.Span, indentation: String) -> void:
|
|
164
|
+
_writer.append(indentation + text + "\n", span)
|
|
165
|
+
|
|
166
|
+
func _description(node: Model.Component, indentation: String) -> String:
|
|
167
|
+
var variable := "_gogo_element_%d" % _variable
|
|
168
|
+
while _module.identifiers.has(variable): variable += "_"
|
|
169
|
+
_variable += 1
|
|
170
|
+
var props := PackedStringArray()
|
|
171
|
+
var events := PackedStringArray()
|
|
172
|
+
var bindings := PackedStringArray()
|
|
173
|
+
var key := "null"
|
|
174
|
+
var keyed := "false"
|
|
175
|
+
for attribute in node.attributes:
|
|
176
|
+
var value: String = _arguments[attribute.value].name if attribute.value is Model.GdExpression else literal(attribute.value)
|
|
177
|
+
if attribute.kind == "binding":
|
|
178
|
+
bindings.append(_string("value")+": "+value)
|
|
179
|
+
continue
|
|
180
|
+
if attribute.kind == "key":
|
|
181
|
+
key = value
|
|
182
|
+
keyed = "true"
|
|
183
|
+
continue
|
|
184
|
+
var target := events if attribute.kind == "signal" else props
|
|
185
|
+
target.append(_string(attribute.name)+": "+value)
|
|
186
|
+
var children := PackedStringArray()
|
|
187
|
+
for child in node.children:
|
|
188
|
+
children.append(_arguments[child].name if child is Model.GdExpression else _description(child,indentation))
|
|
189
|
+
var native_type := _string(node.runtime_class) if ClassDB.class_exists(node.runtime_class) else node.runtime_class
|
|
190
|
+
_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)
|
|
191
|
+
if not bindings.is_empty(): _line(variable+".bindings = {"+", ".join(bindings)+"}",node.span,indentation)
|
|
192
|
+
return variable
|
|
193
|
+
|
|
194
|
+
func _bindable(property: Model.Bindable) -> void:
|
|
195
|
+
var incoming := "_gogo_incoming_"+property.name
|
|
196
|
+
while _module.identifiers.has(incoming): incoming += "_"
|
|
197
|
+
var previous := "_gogo_previous_"+property.name
|
|
198
|
+
while _module.identifiers.has(previous): previous += "_"
|
|
199
|
+
var indent := _module.indentation
|
|
200
|
+
_writer.append("signal "+property.signal_name+"(previous: ",property.name_span)
|
|
201
|
+
_writer.append(_file.slice(property.type_span),property.type_span,true)
|
|
202
|
+
_writer.append(", value: ",property.name_span)
|
|
203
|
+
_writer.append(_file.slice(property.type_span),property.type_span,true)
|
|
204
|
+
_writer.append(")\n",property.name_span)
|
|
205
|
+
if property.annotations_span != null:
|
|
206
|
+
_writer.append(_file.slice(property.annotations_span),property.annotations_span,true)
|
|
207
|
+
_writer.append(_file.slice(property.declaration_span),property.declaration_span,true)
|
|
208
|
+
_writer.append(":",property.name_span)
|
|
209
|
+
if property.comment_span != null:
|
|
210
|
+
_writer.append(" ")
|
|
211
|
+
_writer.append(_file.slice(property.comment_span),property.comment_span,true)
|
|
212
|
+
_writer.append("\n"+indent+"set("+incoming+"):\n",property.name_span)
|
|
213
|
+
# Use the native property backing slot: accesses inside its own setter are
|
|
214
|
+
# direct, and declaration initialization does not call the setter.
|
|
215
|
+
_writer.append(indent.repeat(2)+"if is_same("+property.name+", "+incoming+"): return\n",property.name_span)
|
|
216
|
+
_writer.append(indent.repeat(2)+"var "+previous+": "+property.type_name+" = "+property.name+"\n",property.name_span)
|
|
217
|
+
_writer.append(indent.repeat(2)+property.name+" = "+incoming+"\n",property.name_span)
|
|
218
|
+
_writer.append(indent.repeat(2)+property.signal_name+".emit("+previous+", "+incoming+")\n",property.name_span)
|
|
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)
|
|
220
|
+
|
|
221
|
+
func _binding_argument(argument: Argument) -> void:
|
|
222
|
+
var path := argument.binding_path.duplicate()
|
|
223
|
+
var field: String = path.pop_back()
|
|
224
|
+
var owner := "_gogo_root"
|
|
225
|
+
var source := "_gogo_source"
|
|
226
|
+
var edit := "_gogo_edit"
|
|
227
|
+
while _module.identifiers.has(owner): owner += "_"
|
|
228
|
+
while _module.identifiers.has(source): source += "_"
|
|
229
|
+
while _module.identifiers.has(edit): edit += "_"
|
|
230
|
+
var endpoint := owner
|
|
231
|
+
var checks: Array[String] = [owner+" != null"]
|
|
232
|
+
for name in path:
|
|
233
|
+
endpoint += "."+str(name)
|
|
234
|
+
checks.append(endpoint+" != null")
|
|
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)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://mitk32tju0g7
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Native source -> typed frontend result. No emitter, subprocess or editor state.
|
|
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
|
+
|
|
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
|
+
var parser := Parser.new(file)
|
|
14
|
+
var result := Model.Result.new()
|
|
15
|
+
var module := parser.parse()
|
|
16
|
+
if module != null: Bindable.new(file).apply(module)
|
|
17
|
+
if module != null and file.diagnostics.is_empty(): Composition.new(file).apply(module)
|
|
18
|
+
if module != null and file.diagnostics.is_empty(): Validator.new(file).validate(module)
|
|
19
|
+
result.tokens = parser.lexer.tokens
|
|
20
|
+
result.diagnostics = file.diagnostics
|
|
21
|
+
result.module = module if result.diagnostics.is_empty() else null
|
|
22
|
+
return result
|