@papercraftgames/estragon 0.0.0-stage → 0.1.0-beta.2

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 (88) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +20 -0
  3. package/README.md +28 -2
  4. package/addons/estragon/compiler/bindable.gd +213 -0
  5. package/addons/estragon/compiler/bindable.gd.uid +1 -0
  6. package/addons/estragon/compiler/compiler.gd +24 -0
  7. package/addons/estragon/compiler/compiler.gd.uid +1 -0
  8. package/addons/estragon/compiler/composition.gd +51 -0
  9. package/addons/estragon/compiler/composition.gd.uid +1 -0
  10. package/addons/estragon/compiler/diagnostic_capture.gd.txt +18 -0
  11. package/addons/estragon/compiler/emitter.gd +209 -0
  12. package/addons/estragon/compiler/emitter.gd.uid +1 -0
  13. package/addons/estragon/compiler/frontend.gd +22 -0
  14. package/addons/estragon/compiler/frontend.gd.uid +1 -0
  15. package/addons/estragon/compiler/lexer.gd +78 -0
  16. package/addons/estragon/compiler/lexer.gd.uid +1 -0
  17. package/addons/estragon/compiler/model.gd +87 -0
  18. package/addons/estragon/compiler/model.gd.uid +1 -0
  19. package/addons/estragon/compiler/native/resolver.gd +200 -0
  20. package/addons/estragon/compiler/native/resolver.gd.uid +1 -0
  21. package/addons/estragon/compiler/parser.gd +252 -0
  22. package/addons/estragon/compiler/parser.gd.uid +1 -0
  23. package/addons/estragon/compiler/script_validation.gd +80 -0
  24. package/addons/estragon/compiler/script_validation.gd.uid +1 -0
  25. package/addons/estragon/compiler/source.gd +65 -0
  26. package/addons/estragon/compiler/source.gd.uid +1 -0
  27. package/addons/estragon/compiler/source_map.gd +59 -0
  28. package/addons/estragon/compiler/source_map.gd.uid +1 -0
  29. package/addons/estragon/compiler/validator.gd +277 -0
  30. package/addons/estragon/compiler/validator.gd.uid +1 -0
  31. package/addons/estragon/editor/buffer_guard.gd +84 -0
  32. package/addons/estragon/editor/buffer_guard.gd.uid +1 -0
  33. package/addons/estragon/editor/build_service.gd +252 -0
  34. package/addons/estragon/editor/build_service.gd.uid +1 -0
  35. package/addons/estragon/editor/highlighter.gd +116 -0
  36. package/addons/estragon/editor/highlighter.gd.uid +1 -0
  37. package/addons/estragon/editor/highlighter_association.gd +80 -0
  38. package/addons/estragon/editor/highlighter_association.gd.uid +1 -0
  39. package/addons/estragon/editor/plugin.cfg +7 -0
  40. package/addons/estragon/editor/plugin.gd +225 -0
  41. package/addons/estragon/editor/plugin.gd.uid +1 -0
  42. package/addons/estragon/editor/script_dependencies.gd +45 -0
  43. package/addons/estragon/editor/script_dependencies.gd.uid +1 -0
  44. package/addons/estragon/runtime/composition/binding.gd +62 -0
  45. package/addons/estragon/runtime/composition/binding.gd.uid +1 -0
  46. package/addons/estragon/runtime/composition/computation.gd +477 -0
  47. package/addons/estragon/runtime/composition/computation.gd.uid +1 -0
  48. package/addons/estragon/runtime/composition/element.gd +23 -0
  49. package/addons/estragon/runtime/composition/element.gd.uid +1 -0
  50. package/addons/estragon/runtime/composition/profile.gd +21 -0
  51. package/addons/estragon/runtime/composition/profile.gd.uid +1 -0
  52. package/addons/estragon/runtime/composition/profile.tres +6 -0
  53. package/addons/estragon/runtime/composition/state.gd +65 -0
  54. package/addons/estragon/runtime/composition/state.gd.uid +1 -0
  55. package/addons/estragon/runtime/composition/state.tres +6 -0
  56. package/addons/estragon/runtime/node/button.gd +53 -0
  57. package/addons/estragon/runtime/node/button.gd.uid +1 -0
  58. package/addons/estragon/runtime/node/component_2d.gd +105 -0
  59. package/addons/estragon/runtime/node/component_2d.gd.uid +1 -0
  60. package/addons/estragon/runtime/node/component_3d.gd +91 -0
  61. package/addons/estragon/runtime/node/component_3d.gd.uid +1 -0
  62. package/addons/estragon/runtime/node/estragon_2d.gd +32 -0
  63. package/addons/estragon/runtime/node/estragon_2d.gd.uid +1 -0
  64. package/addons/estragon/runtime/node/estragon_3d.gd +15 -0
  65. package/addons/estragon/runtime/node/estragon_3d.gd.uid +1 -0
  66. package/addons/estragon/runtime/node/hbox.gd +6 -0
  67. package/addons/estragon/runtime/node/hbox.gd.uid +1 -0
  68. package/addons/estragon/runtime/node/internal/coordinator.gd +145 -0
  69. package/addons/estragon/runtime/node/internal/coordinator.gd.uid +1 -0
  70. package/addons/estragon/runtime/node/internal/layout_core.gd +115 -0
  71. package/addons/estragon/runtime/node/internal/layout_core.gd.uid +1 -0
  72. package/addons/estragon/runtime/node/internal/native_bounds.gd +103 -0
  73. package/addons/estragon/runtime/node/internal/native_bounds.gd.uid +1 -0
  74. package/addons/estragon/runtime/node/internal/pointer_2d.gd +70 -0
  75. package/addons/estragon/runtime/node/internal/pointer_2d.gd.uid +1 -0
  76. package/addons/estragon/runtime/node/native_2d.gd +40 -0
  77. package/addons/estragon/runtime/node/native_2d.gd.uid +1 -0
  78. package/addons/estragon/runtime/node/native_3d.gd +40 -0
  79. package/addons/estragon/runtime/node/native_3d.gd.uid +1 -0
  80. package/addons/estragon/runtime/node/rect.gd +15 -0
  81. package/addons/estragon/runtime/node/rect.gd.uid +1 -0
  82. package/addons/estragon/runtime/node/text.gd +66 -0
  83. package/addons/estragon/runtime/node/text.gd.uid +1 -0
  84. package/addons/estragon/runtime/node/toggle.gd +23 -0
  85. package/addons/estragon/runtime/node/toggle.gd.uid +1 -0
  86. package/addons/estragon/runtime/node/vbox.gd +6 -0
  87. package/addons/estragon/runtime/node/vbox.gd.uid +1 -0
  88. package/package.json +31 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Release notes
2
+
3
+ ## Next automated prerelease
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.
6
+
7
+ ## Initial public beta
8
+
9
+ 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
+
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.
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,29 @@
1
- # Temporary Holding Version
1
+ # @papercraftgames/estragon
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+ ## Install into a Godot project
6
+
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:
8
+
9
+ ```sh
10
+ yarn add --exact --ignore-scripts @papercraftgames/estragon@beta
11
+ ```
12
+
13
+ Yarn alone installs into `node_modules`; it does not register a Godot plugin. From the project root, with no existing `addons/estragon` directory:
14
+
15
+ ```sh
16
+ touch node_modules/.gdignore
17
+ mkdir -p addons
18
+ cp -R node_modules/@papercraftgames/estragon/addons/estragon addons/estragon
19
+ ```
20
+
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
+
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.
24
+
25
+ [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
+
27
+ 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.
28
+
29
+ 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("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")
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("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")
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>") -> Compilation:
18
+ var result := Compilation.new()
19
+ var frontend := Frontend.analyze(source, source_name)
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)).emit()
23
+ result.code = result.source_map.code
24
+ return result
@@ -0,0 +1 @@
1
+ uid://cvx6tiy2b0yme
@@ -0,0 +1,51 @@
1
+ @tool
2
+ extends RefCounted
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")
7
+ var file
8
+ func _init(source) -> void:
9
+ file = source
10
+ func apply(module) -> void:
11
+ var resolver := Resolver.new(file)
12
+ resolver.scan(module)
13
+ var lexer := Lexer.new(file)
14
+ 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)
21
+ var has_ggx := false
22
+ for part in module.parts:
23
+ if part is Model.Component: has_ggx = true
24
+ var start := -1
25
+ for index in range(tokens.size()-6):
26
+ var token = tokens[index]
27
+ if token.text!="func" or token.span.start.column!=1 or tokens[index+1].text!="build_view": continue
28
+ if tokens[index+2].text!="(" or tokens[index+3].text!=")" or tokens[index+4].text!="->":
29
+ if has_ggx:
30
+ 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)
31
+ return
32
+ continue
33
+ var type: String = tokens[index+5].text
34
+ if resolver.aliases.get(type,"")!="res://addons/estragon/runtime/composition/element.gd":
35
+ if has_ggx and type in ["Node","Node2D","Node3D"]:
36
+ 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
+ return
38
+ if has_ggx:
39
+ file.fail("GGX build_view return type must preload composition/element.gd",tokens[index+5].span.start.index,tokens[index+5].span.end.index)
40
+ return
41
+ continue
42
+ if start>=0:
43
+ file.fail("Duplicate build_view composition function",token.span.start.index)
44
+ return
45
+ start = token.span.start.index
46
+ if start<0: return
47
+ module.composition = true
48
+ for index in range(tokens.size()-1):
49
+ if tokens[index].text=="func" and tokens[index].span.start.column==1 and tokens[index+1].text=="_notification":
50
+ file.fail("Composition owns _notification; use ordinary _ready/event methods",tokens[index+1].span.start.index)
51
+ 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,209 @@
1
+ @tool
2
+ extends RefCounted
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")
7
+
8
+ class Argument extends RefCounted:
9
+ var expression: Model.GdExpression
10
+ var type_name: String
11
+ var name: String
12
+ var binding_path: Array = []
13
+
14
+ class Factory extends RefCounted:
15
+ var name: String
16
+ var root: Model.Component
17
+ var arguments: Array[Argument] = []
18
+
19
+ var _module: Model.Module
20
+ var _file: Source
21
+ var _writer: MappedWriter
22
+ var _factories: Array[Factory] = []
23
+ var _arguments: Dictionary = {}
24
+ var _sequence: int = 0
25
+ var _variable: int = 0
26
+ var _factory_class: String
27
+ var _element_class: String
28
+
29
+ func _init(module: Model.Module, file: Source) -> void:
30
+ _module = module
31
+ _file = file
32
+ _writer = MappedWriter.new(file)
33
+ # Explicit class lookup avoids old native lambda resolution of bare static
34
+ # methods. Arguments still use ordinary typed calls in authored scope.
35
+ var index := 0
36
+ while true:
37
+ _factory_class = "_GogoFactories_%d" % index
38
+ if not _module.identifiers.has(_factory_class): break
39
+ index += 1
40
+ _element_class = "_GogoElement_0"
41
+ while _module.identifiers.has(_element_class): _element_class += "_"
42
+
43
+ func emit() -> MappedWriter:
44
+ _parts(_module.parts)
45
+ _writer.append("\n")
46
+ 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")
48
+ if not _factories.is_empty():
49
+ _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")
51
+ # Calls in argument expressions may append additional factories.
52
+ var index: int = 0
53
+ while index < _factories.size():
54
+ _factory(_factories[index])
55
+ index += 1
56
+ _writer.finish()
57
+ return _writer
58
+
59
+ ## Escape a GDScript literal character-by-character; never touch authored code.
60
+ static func _string(value: String) -> String:
61
+ var output := '"'
62
+ for character in value:
63
+ match character:
64
+ '"': output += '\\"'
65
+ "\\": output += "\\\\"
66
+ "\n": output += "\\n"
67
+ "\r": output += "\\r"
68
+ "\t": output += "\\t"
69
+ _:
70
+ var point := character.unicode_at(0)
71
+ output += "\\u%04x" % point if point < 32 else character
72
+ return output + '"'
73
+
74
+ static func literal(value: Model.Literal) -> String:
75
+ return _string(value.value)
76
+
77
+ func _argument(expression: Model.GdExpression, type_name: String, factory: Factory) -> void:
78
+ var argument := Argument.new()
79
+ argument.expression = expression
80
+ argument.type_name = type_name
81
+ argument.name = "_gogo_value_%d" % factory.arguments.size()
82
+ factory.arguments.append(argument)
83
+ _arguments[expression] = argument
84
+
85
+ func _collect(node: Model.Component, factory: Factory) -> void:
86
+ for attribute in node.attributes:
87
+ if attribute.value is Model.GdExpression:
88
+ _argument(attribute.value, attribute.type_name, factory)
89
+ if attribute.kind=="binding": factory.arguments.back().binding_path = attribute.binding_path
90
+ for child in node.children:
91
+ if child is Model.GdExpression: _argument(child,"Variant",factory)
92
+ else: _collect(child, factory)
93
+
94
+ func _parts(parts: Array[Model.SyntaxNode]) -> void:
95
+ for part in parts:
96
+ if part is Model.Code: _writer.append(_file.slice(part.span), part.span, true)
97
+ elif part is Model.Bindable: _bindable(part)
98
+ else: _call(part)
99
+
100
+ func _call(node: Model.Component) -> void:
101
+ var factory := Factory.new()
102
+ while true:
103
+ factory.name = "_gogo_build_%d" % _sequence
104
+ _sequence += 1
105
+ if not _module.identifiers.has(factory.name): break
106
+ factory.root = node
107
+ _factories.append(factory)
108
+ _collect(node, factory)
109
+ var multiline := factory.arguments.size() > 3
110
+ var start := _file.line_start(node.span.start.line)
111
+ var end := start
112
+ while end < _file.text.length() and _file.text[end] in [" ", "\t"]: end += 1
113
+ var base := _file.text.substr(start, end - start)
114
+ _writer.append(_factory_class + "." + factory.name + "(", node.span)
115
+ for index in range(factory.arguments.size()):
116
+ var argument := factory.arguments[index]
117
+ if index > 0: _writer.append("," if multiline else ", ", node.span)
118
+ if multiline: _writer.append("\n" + base + _module.indentation, argument.expression.span)
119
+ _writer.append("(", argument.expression.span)
120
+ if argument.binding_path.is_empty(): _parts(argument.expression.parts)
121
+ else: _binding_argument(argument)
122
+ _writer.append(")", argument.expression.span)
123
+ _writer.append(("\n" + base if multiline else "") + ")", node.span)
124
+
125
+ func _factory(factory: Factory) -> void:
126
+ _writer.append("\n\n" + _module.indentation + "static func " + factory.name + "(", factory.root.span)
127
+ var multiline := factory.arguments.size() > 3
128
+ for index in range(factory.arguments.size()):
129
+ var argument := factory.arguments[index]
130
+ if index > 0: _writer.append("," if multiline else ", ", argument.expression.span)
131
+ _writer.append(("\n" + _module.indentation.repeat(2) if multiline else "") + argument.name + ": " + argument.type_name, argument.expression.span)
132
+ _writer.append(("\n" + _module.indentation if multiline else "") + ") -> " + _element_class + ":\n", factory.root.span)
133
+ _variable = 0
134
+ var variable := _description(factory.root,_module.indentation.repeat(2))
135
+ _writer.append(_module.indentation.repeat(2) + "return " + variable + "\n", factory.root.span)
136
+
137
+ func _line(text: String, span: Model.Span, indentation: String) -> void:
138
+ _writer.append(indentation + text + "\n", span)
139
+
140
+ func _description(node: Model.Component, indentation: String) -> String:
141
+ var variable := "_gogo_element_%d" % _variable
142
+ while _module.identifiers.has(variable): variable += "_"
143
+ _variable += 1
144
+ var props := PackedStringArray()
145
+ var events := PackedStringArray()
146
+ var bindings := PackedStringArray()
147
+ var key := "null"
148
+ var keyed := "false"
149
+ for attribute in node.attributes:
150
+ 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
+ if attribute.kind == "key":
155
+ key = value
156
+ keyed = "true"
157
+ continue
158
+ var target := events if attribute.kind == "signal" else props
159
+ target.append(_string(attribute.name)+": "+value)
160
+ var children := PackedStringArray()
161
+ for child in node.children:
162
+ children.append(_arguments[child].name if child is Model.GdExpression else _description(child,indentation))
163
+ var native_type := _string(node.runtime_class) if ClassDB.class_exists(node.runtime_class) else node.runtime_class
164
+ _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)
166
+ return variable
167
+
168
+ func _bindable(property: Model.Bindable) -> void:
169
+ var incoming := "_gogo_incoming_"+property.name
170
+ while _module.identifiers.has(incoming): incoming += "_"
171
+ var previous := "_gogo_previous_"+property.name
172
+ while _module.identifiers.has(previous): previous += "_"
173
+ var indent := _module.indentation
174
+ _writer.append("signal "+property.signal_name+"(previous: ",property.name_span)
175
+ _writer.append(_file.slice(property.type_span),property.type_span,true)
176
+ _writer.append(", value: ",property.name_span)
177
+ _writer.append(_file.slice(property.type_span),property.type_span,true)
178
+ _writer.append(")\n",property.name_span)
179
+ if property.annotations_span != null:
180
+ _writer.append(_file.slice(property.annotations_span),property.annotations_span,true)
181
+ _writer.append(_file.slice(property.declaration_span),property.declaration_span,true)
182
+ _writer.append(":",property.name_span)
183
+ if property.comment_span != null:
184
+ _writer.append(" ")
185
+ _writer.append(_file.slice(property.comment_span),property.comment_span,true)
186
+ _writer.append("\n"+indent+"set("+incoming+"):\n",property.name_span)
187
+ # Use the native property backing slot: accesses inside its own setter are
188
+ # direct, and declaration initialization does not call the setter.
189
+ _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)
191
+ _writer.append(indent.repeat(2)+property.name+" = "+incoming+"\n",property.name_span)
192
+ _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)
194
+
195
+ func _binding_argument(argument: Argument) -> void:
196
+ var path := argument.binding_path.duplicate()
197
+ var field: String = path.pop_back()
198
+ var owner := "_gogo_root"
199
+ var source := "_gogo_source"
200
+ var edit := "_gogo_edit"
201
+ while _module.identifiers.has(owner): owner += "_"
202
+ while _module.identifiers.has(source): source += "_"
203
+ while _module.identifiers.has(edit): edit += "_"
204
+ var endpoint := owner
205
+ var checks: Array[String] = [owner+" != null"]
206
+ for name in path:
207
+ endpoint += "."+str(name)
208
+ 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)
@@ -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("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")
10
+
11
+ static func analyze(text: String, source_name: String = "<source>") -> Model.Result:
12
+ var file := Source.new(text, source_name)
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
@@ -0,0 +1 @@
1
+ uid://bko8jhx3i0jkj