@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.
- package/CHANGELOG.md +11 -0
- package/LICENSE +20 -0
- package/README.md +28 -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 +51 -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 +209 -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 +87 -0
- package/addons/estragon/compiler/model.gd.uid +1 -0
- package/addons/estragon/compiler/native/resolver.gd +200 -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/script_validation.gd +80 -0
- package/addons/estragon/compiler/script_validation.gd.uid +1 -0
- package/addons/estragon/compiler/source.gd +65 -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 +277 -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 +252 -0
- package/addons/estragon/editor/build_service.gd.uid +1 -0
- package/addons/estragon/editor/highlighter.gd +116 -0
- package/addons/estragon/editor/highlighter.gd.uid +1 -0
- package/addons/estragon/editor/highlighter_association.gd +80 -0
- package/addons/estragon/editor/highlighter_association.gd.uid +1 -0
- package/addons/estragon/editor/plugin.cfg +7 -0
- package/addons/estragon/editor/plugin.gd +225 -0
- package/addons/estragon/editor/plugin.gd.uid +1 -0
- package/addons/estragon/editor/script_dependencies.gd +45 -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
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Explicit Godot semantic validation, separate from deterministic source emission.
|
|
4
|
+
## Uses native Logger only for the synchronous reload window; never spawns tools.
|
|
5
|
+
const Model = preload("res://addons/estragon/compiler/model.gd")
|
|
6
|
+
const Compiler = preload("res://addons/estragon/compiler/compiler.gd")
|
|
7
|
+
|
|
8
|
+
class Validation extends RefCounted:
|
|
9
|
+
var generated_script: GDScript
|
|
10
|
+
var diagnostics: Array[Model.Diagnostic] = []
|
|
11
|
+
var ok: bool:
|
|
12
|
+
get: return generated_script != null and diagnostics.is_empty()
|
|
13
|
+
|
|
14
|
+
# This source is text so old editors never parse unsupported native base/types.
|
|
15
|
+
# It contains only the bundled logger adapter, never authored application code.
|
|
16
|
+
static func _capture(path: String) -> Object:
|
|
17
|
+
if not ClassDB.class_exists("Logger") or not ClassDB.class_exists("ScriptBacktrace"):
|
|
18
|
+
return null
|
|
19
|
+
if not OS.has_method("add_logger") or not OS.has_method("remove_logger"):
|
|
20
|
+
return null
|
|
21
|
+
var factory := GDScript.new()
|
|
22
|
+
factory.source_code = FileAccess.get_file_as_string("res://addons/estragon/compiler/diagnostic_capture.gd.txt")
|
|
23
|
+
if factory.reload() != OK: return null # Native errors remain visible.
|
|
24
|
+
var logger = factory.new()
|
|
25
|
+
logger.path = path
|
|
26
|
+
return logger
|
|
27
|
+
|
|
28
|
+
static func supports_isolated_path() -> bool:
|
|
29
|
+
return GDScript.new().has_method("set_path_cache")
|
|
30
|
+
|
|
31
|
+
static func validate(compilation: Compiler.Compilation, generated_path: String = "res://Generated.gd") -> Validation:
|
|
32
|
+
var result := Validation.new()
|
|
33
|
+
if not compilation.ok:
|
|
34
|
+
result.diagnostics.assign(compilation.diagnostics)
|
|
35
|
+
return result
|
|
36
|
+
var script := GDScript.new()
|
|
37
|
+
if not supports_isolated_path():
|
|
38
|
+
var diagnostic := Model.Diagnostic.new()
|
|
39
|
+
diagnostic.source_name = compilation.source_map.source.name
|
|
40
|
+
diagnostic.span = compilation.source_map.source.span(0)
|
|
41
|
+
diagnostic.message = "Isolated script-path preflight is unavailable on this Godot; no executable was returned or cached script modified. Builds require transactional native publication validation."
|
|
42
|
+
result.diagnostics.append(diagnostic)
|
|
43
|
+
return result
|
|
44
|
+
# Resource's cache-only setter avoids ownership transfer. On 4.4/4.5 the
|
|
45
|
+
# same-path ordinary setter also establishes GDScript's internal parser path.
|
|
46
|
+
# Resource returns before touching cache ownership because paths already match.
|
|
47
|
+
script.call("set_path_cache", generated_path)
|
|
48
|
+
script.resource_path = generated_path
|
|
49
|
+
return reload_script(compilation, script)
|
|
50
|
+
|
|
51
|
+
## Explicit editor publication step; callers retain Resource identity and state.
|
|
52
|
+
## validate() above remains isolated from the application's resource cache.
|
|
53
|
+
static func reload_script(compilation: Compiler.Compilation, script: GDScript, keep_state: bool = false) -> Validation:
|
|
54
|
+
var result := Validation.new()
|
|
55
|
+
if not compilation.ok:
|
|
56
|
+
result.diagnostics.assign(compilation.diagnostics)
|
|
57
|
+
return result
|
|
58
|
+
script.source_code = compilation.code
|
|
59
|
+
var logger = _capture(script.resource_path)
|
|
60
|
+
if logger != null: OS.call("add_logger", logger)
|
|
61
|
+
var error := script.reload(keep_state)
|
|
62
|
+
var messages: Array = []
|
|
63
|
+
if logger != null:
|
|
64
|
+
OS.call("remove_logger", logger)
|
|
65
|
+
messages = logger.snapshot()
|
|
66
|
+
for message in messages:
|
|
67
|
+
var diagnostic := Model.Diagnostic.new()
|
|
68
|
+
diagnostic.source_name = compilation.source_map.source.name
|
|
69
|
+
var position := compilation.source_map.original_position(message.line)
|
|
70
|
+
diagnostic.span = compilation.source_map.source.span(position.index if position != null else 0)
|
|
71
|
+
diagnostic.message = message.message
|
|
72
|
+
result.diagnostics.append(diagnostic)
|
|
73
|
+
if error != OK and result.diagnostics.is_empty():
|
|
74
|
+
var diagnostic := Model.Diagnostic.new()
|
|
75
|
+
diagnostic.source_name = compilation.source_map.source.name
|
|
76
|
+
diagnostic.span = compilation.source_map.source.span(0)
|
|
77
|
+
diagnostic.message = "Godot rejected generated GDScript (%s); exact authored location unavailable here, inspect native engine diagnostics" % error_string(error)
|
|
78
|
+
result.diagnostics.append(diagnostic)
|
|
79
|
+
if error == OK and result.diagnostics.is_empty(): result.generated_script = script
|
|
80
|
+
return result
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://ddbgqg8oqhtue
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Source ranges use code-point indexes internally and compatible UTF-16 externally.
|
|
4
|
+
const Model = preload("res://addons/estragon/compiler/model.gd")
|
|
5
|
+
var text: String
|
|
6
|
+
var name: String
|
|
7
|
+
var diagnostics: Array[Model.Diagnostic] = []
|
|
8
|
+
var _lines: PackedInt32Array = [0]
|
|
9
|
+
var _utf16: PackedInt32Array = [0]
|
|
10
|
+
|
|
11
|
+
func _init(value: String, source_name: String = "<source>") -> void:
|
|
12
|
+
text = value
|
|
13
|
+
name = source_name
|
|
14
|
+
for index in range(text.length()):
|
|
15
|
+
_utf16.append(_utf16[-1] + (2 if text.unicode_at(index) > 0xffff else 1))
|
|
16
|
+
if text[index] == "\n" or text[index] == "\r" and (index + 1 == text.length() or text[index + 1] != "\n"):
|
|
17
|
+
_lines.append(index + 1)
|
|
18
|
+
|
|
19
|
+
func position(index: int) -> Model.Position:
|
|
20
|
+
index = clampi(index, 0, text.length())
|
|
21
|
+
var low: int = 0
|
|
22
|
+
var high := _lines.size()
|
|
23
|
+
while low + 1 < high:
|
|
24
|
+
var middle := (low + high) >> 1
|
|
25
|
+
if _lines[middle] <= index: low = middle
|
|
26
|
+
else: high = middle
|
|
27
|
+
var point := Model.Position.new()
|
|
28
|
+
point.index = index
|
|
29
|
+
point.offset = _utf16[index]
|
|
30
|
+
point.line = low + 1
|
|
31
|
+
point.column = _utf16[index] - _utf16[_lines[low]] + 1
|
|
32
|
+
return point
|
|
33
|
+
|
|
34
|
+
func line_start(line: int) -> int:
|
|
35
|
+
return _lines[line - 1] if line > 0 and line <= _lines.size() else text.length()
|
|
36
|
+
|
|
37
|
+
func span(start: int, end: int = -1) -> Model.Span:
|
|
38
|
+
var result := Model.Span.new()
|
|
39
|
+
result.start = position(start)
|
|
40
|
+
result.end = position(start if end < 0 else end)
|
|
41
|
+
return result
|
|
42
|
+
|
|
43
|
+
func fail(message: String, start: int, end: int = -1) -> void:
|
|
44
|
+
if not diagnostics.is_empty(): return
|
|
45
|
+
var diagnostic := Model.Diagnostic.new()
|
|
46
|
+
diagnostic.source_name = name
|
|
47
|
+
diagnostic.span = span(start, end)
|
|
48
|
+
diagnostic.message = message
|
|
49
|
+
diagnostics.append(diagnostic)
|
|
50
|
+
|
|
51
|
+
func slice(bounds: Model.Span) -> String:
|
|
52
|
+
return text.substr(bounds.start.index, bounds.end.index - bounds.start.index)
|
|
53
|
+
|
|
54
|
+
## Convert compatible UTF-16 offsets/coordinates to Godot slicing indexes.
|
|
55
|
+
func index_at_offset(offset_value: int) -> int:
|
|
56
|
+
var low: int = 0
|
|
57
|
+
var high := _utf16.size()
|
|
58
|
+
while low + 1 < high:
|
|
59
|
+
var middle := (low + high) >> 1
|
|
60
|
+
if _utf16[middle] <= offset_value: low = middle
|
|
61
|
+
else: high = middle
|
|
62
|
+
return low
|
|
63
|
+
|
|
64
|
+
func offset(line: int, column: int = 1) -> int:
|
|
65
|
+
return mini(_utf16[-1], _utf16[line_start(line)] + maxi(0, column - 1))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://cqwbos0a0k37o
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Version-1 range maps, shared by native generation and diagnostic consumers.
|
|
4
|
+
const Model = preload("res://addons/estragon/compiler/model.gd")
|
|
5
|
+
const Source = preload("res://addons/estragon/compiler/source.gd")
|
|
6
|
+
var source: Source
|
|
7
|
+
var code: String
|
|
8
|
+
var segments: Array[Dictionary] = []
|
|
9
|
+
var _pieces: PackedStringArray = []
|
|
10
|
+
var _length: int = 0
|
|
11
|
+
|
|
12
|
+
func _init(file: Source) -> void:
|
|
13
|
+
source = file
|
|
14
|
+
|
|
15
|
+
func append(text: String, original: Model.Span = null, copied: bool = false) -> void:
|
|
16
|
+
if original != null and not text.is_empty():
|
|
17
|
+
segments.append({"from": _length, "to": _length + text.length(), "original": original, "kind": "copied" if copied else "generated"})
|
|
18
|
+
_pieces.append(text)
|
|
19
|
+
_length += text.length()
|
|
20
|
+
|
|
21
|
+
func finish() -> void:
|
|
22
|
+
code = "".join(_pieces)
|
|
23
|
+
var generated := Source.new(code)
|
|
24
|
+
for segment in segments:
|
|
25
|
+
segment.generated = generated.span(segment.from, segment.to)
|
|
26
|
+
_pieces.clear()
|
|
27
|
+
|
|
28
|
+
func original_position(line: int, column: int = 1) -> Model.Position:
|
|
29
|
+
var generated := Source.new(code)
|
|
30
|
+
var offset := generated.offset(line, column)
|
|
31
|
+
var selected: Dictionary = {}
|
|
32
|
+
for segment in segments:
|
|
33
|
+
if segment.generated.start.offset <= offset and offset < segment.generated.end.offset:
|
|
34
|
+
selected = segment
|
|
35
|
+
break
|
|
36
|
+
if selected.is_empty():
|
|
37
|
+
for segment in segments:
|
|
38
|
+
if segment.generated.start.line <= line and line <= segment.generated.end.line:
|
|
39
|
+
selected = segment
|
|
40
|
+
break
|
|
41
|
+
if selected.is_empty(): return null
|
|
42
|
+
if selected.kind == "generated": return selected.original.start
|
|
43
|
+
var delta: int = clampi(offset - selected.generated.start.offset, 0, selected.original.end.offset - selected.original.start.offset)
|
|
44
|
+
return source.position(source.index_at_offset(selected.original.start.offset + delta))
|
|
45
|
+
|
|
46
|
+
static func _point(point: Model.Position) -> Dictionary:
|
|
47
|
+
return {"offset": point.offset, "line": point.line, "column": point.column}
|
|
48
|
+
|
|
49
|
+
static func _span(span: Model.Span) -> Dictionary:
|
|
50
|
+
return {"start": _point(span.start), "end": _point(span.end)}
|
|
51
|
+
|
|
52
|
+
func to_dictionary() -> Dictionary:
|
|
53
|
+
var ranges: Array[Dictionary] = []
|
|
54
|
+
for segment in segments:
|
|
55
|
+
ranges.append({"generated": _span(segment.generated), "original": _span(segment.original), "kind": segment.kind})
|
|
56
|
+
return {"format": "estragon.gogo.source-map", "version": 1, "sourceName": source.name, "sourceContent": source.text, "segments": ranges}
|
|
57
|
+
|
|
58
|
+
func serialize() -> String:
|
|
59
|
+
return JSON.stringify(to_dictionary()) + "\n"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://cdqldld5vxhju
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Static native Node property/signal contracts; no SceneTree or editor dependency.
|
|
4
|
+
const Model = preload("res://addons/estragon/compiler/model.gd")
|
|
5
|
+
const Source = preload("res://addons/estragon/compiler/source.gd")
|
|
6
|
+
const Resolver = preload("res://addons/estragon/compiler/native/resolver.gd")
|
|
7
|
+
const Lexer = preload("res://addons/estragon/compiler/lexer.gd")
|
|
8
|
+
var file: Source
|
|
9
|
+
var resolver
|
|
10
|
+
var current_module
|
|
11
|
+
func _init(source: Source) -> void:
|
|
12
|
+
file = source
|
|
13
|
+
resolver = Resolver.new(source)
|
|
14
|
+
func validate(module: Model.Module) -> void:
|
|
15
|
+
current_module = module
|
|
16
|
+
resolver.scan(module)
|
|
17
|
+
for part in module.parts: _node(part)
|
|
18
|
+
func _node(node: Model.SyntaxNode) -> void:
|
|
19
|
+
if not file.diagnostics.is_empty(): return
|
|
20
|
+
if node is Model.GdExpression:
|
|
21
|
+
for part in node.parts: _node(part)
|
|
22
|
+
elif node is Model.Component: _component(node)
|
|
23
|
+
func _error(message: String, span: Model.Span) -> void:
|
|
24
|
+
file.fail(message,span.start.index,span.end.index)
|
|
25
|
+
|
|
26
|
+
func _component(node: Model.Component) -> void:
|
|
27
|
+
var resolved: Dictionary = resolver.resolve(node.name, node.name_span)
|
|
28
|
+
if resolved.is_empty(): return
|
|
29
|
+
node.runtime_class = node.name
|
|
30
|
+
var properties: Dictionary = {}
|
|
31
|
+
var signals: Dictionary = {}
|
|
32
|
+
for property in ClassDB.class_get_property_list(resolved.native): properties[property.name] = property
|
|
33
|
+
for event in ClassDB.class_get_signal_list(resolved.native): signals[event.name] = event
|
|
34
|
+
var script: Script = resolved.script
|
|
35
|
+
while script != null:
|
|
36
|
+
for property in script.get_script_property_list():
|
|
37
|
+
if not properties.has(property.name): properties[property.name] = property
|
|
38
|
+
for event in script.get_script_signal_list():
|
|
39
|
+
if not signals.has(event.name): signals[event.name] = resolver.signal_contract(script,event)
|
|
40
|
+
script = script.get_base_script()
|
|
41
|
+
properties.merge(resolved.get("properties",{}),true)
|
|
42
|
+
signals.merge(resolved.get("signals",{}),true)
|
|
43
|
+
var seen: Dictionary = {}
|
|
44
|
+
for attribute in node.attributes:
|
|
45
|
+
var name := attribute.name
|
|
46
|
+
if seen.has(name):
|
|
47
|
+
_error("Duplicate Node property or signal " + name, attribute.name_span)
|
|
48
|
+
return
|
|
49
|
+
seen[name] = true
|
|
50
|
+
if name.begins_with("bind:"):
|
|
51
|
+
_binding(attribute,node,properties,signals)
|
|
52
|
+
if not file.diagnostics.is_empty(): return
|
|
53
|
+
continue
|
|
54
|
+
if name=="key":
|
|
55
|
+
attribute.kind = "key"
|
|
56
|
+
attribute.type_name = "Variant"
|
|
57
|
+
if attribute.value is Model.Literal:
|
|
58
|
+
if str(attribute.value.value).is_empty(): _error("GGX key must be an integer or nonempty String",attribute.value.span)
|
|
59
|
+
else: _key_expression(attribute.value)
|
|
60
|
+
continue
|
|
61
|
+
if signals.has(name):
|
|
62
|
+
attribute.kind = "signal"
|
|
63
|
+
attribute.type_name = "Callable"
|
|
64
|
+
if not attribute.value is Model.GdExpression:
|
|
65
|
+
_error("Node signals require a named handler/Callable expression", attribute.value.span)
|
|
66
|
+
return
|
|
67
|
+
var lexer := Lexer.new(file)
|
|
68
|
+
var index: int = attribute.value.span.start.index + 1
|
|
69
|
+
while index < attribute.value.span.end.index - 1:
|
|
70
|
+
var token := lexer.next_token(index)
|
|
71
|
+
if token == null: return
|
|
72
|
+
if token.kind == "identifier" and token.text == "func":
|
|
73
|
+
_error("Inline anonymous GGX handlers are not supported; use a named handler/Callable", token.span)
|
|
74
|
+
return
|
|
75
|
+
index = token.span.end.index
|
|
76
|
+
elif properties.has(name) and name not in ["owner", "script"] and not name.contains("/") and not (int(properties[name].usage) & PROPERTY_USAGE_READ_ONLY):
|
|
77
|
+
attribute.type_name = _native_type(properties[name])
|
|
78
|
+
if attribute.type_name.is_empty():
|
|
79
|
+
_error("Unsupported Node property metadata: " + name, attribute.name_span)
|
|
80
|
+
return
|
|
81
|
+
else:
|
|
82
|
+
_error("Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
|
|
83
|
+
return
|
|
84
|
+
if attribute.value is Model.Literal:
|
|
85
|
+
if attribute.type_name not in ["String", "StringName"]:
|
|
86
|
+
_error("Typed Node values require {GDScript expressions}; only strings may be quoted", attribute.value.span)
|
|
87
|
+
return
|
|
88
|
+
attribute.value.kind = "string-literal"
|
|
89
|
+
attribute.value.type_name = attribute.type_name
|
|
90
|
+
else:
|
|
91
|
+
_node(attribute.value)
|
|
92
|
+
var sibling_names := {}
|
|
93
|
+
for child in node.children:
|
|
94
|
+
if child is Model.GdExpression:
|
|
95
|
+
_node(child)
|
|
96
|
+
_child_expression(child)
|
|
97
|
+
continue
|
|
98
|
+
if not child is Model.Component:
|
|
99
|
+
_error("Node GGX children must be newly declared Node elements; expression adoption is unsupported", child.span)
|
|
100
|
+
return
|
|
101
|
+
_node(child)
|
|
102
|
+
if child is Model.Component:
|
|
103
|
+
for attribute in child.attributes:
|
|
104
|
+
if attribute.name=="name" and attribute.value is Model.Literal:
|
|
105
|
+
var name: String = str(attribute.value.value)
|
|
106
|
+
if sibling_names.has(name):
|
|
107
|
+
_error("Duplicate declared sibling name "+name,attribute.value.span)
|
|
108
|
+
return
|
|
109
|
+
sibling_names[name] = true
|
|
110
|
+
_static_keys(node.children,{})
|
|
111
|
+
|
|
112
|
+
# Inspect only statically simultaneous children. A conditional expression's
|
|
113
|
+
# alternatives are validated at runtime; it must not create false duplicates.
|
|
114
|
+
func _static_keys(children: Array, keys: Dictionary) -> void:
|
|
115
|
+
for child in children:
|
|
116
|
+
if child is Model.Component:
|
|
117
|
+
for attribute in child.attributes:
|
|
118
|
+
if attribute.kind!="key": continue
|
|
119
|
+
var literal = null
|
|
120
|
+
if attribute.value is Model.Literal: literal = "s:"+str(attribute.value.value)
|
|
121
|
+
else:
|
|
122
|
+
var text: String = file.slice(attribute.value.span).substr(1).trim_suffix("}").strip_edges()
|
|
123
|
+
if text.is_valid_int(): literal = "i:"+str(int(text))
|
|
124
|
+
else:
|
|
125
|
+
var tokens := _expression_tokens(attribute.value)
|
|
126
|
+
if tokens.size()==1 and tokens[0].kind=="string" and not tokens[0].text.contains("\\"):
|
|
127
|
+
var value: String = tokens[0].text
|
|
128
|
+
var delimiter := 3 if value.begins_with(value[0].repeat(3)) else 1
|
|
129
|
+
literal = "s:"+value.substr(delimiter,value.length()-delimiter*2)
|
|
130
|
+
if literal==null: continue
|
|
131
|
+
if keys.has(literal):
|
|
132
|
+
_error("Duplicate declared sibling key "+str(literal),attribute.value.span)
|
|
133
|
+
return
|
|
134
|
+
keys[literal] = true
|
|
135
|
+
elif child is Model.GdExpression:
|
|
136
|
+
var conditional := false
|
|
137
|
+
var lexer := Lexer.new(file)
|
|
138
|
+
for part in child.parts:
|
|
139
|
+
if not part is Model.Code: continue
|
|
140
|
+
var cursor: int = part.span.start.index
|
|
141
|
+
while cursor<part.span.end.index:
|
|
142
|
+
var token = lexer.next_token(cursor)
|
|
143
|
+
if token==null: return
|
|
144
|
+
cursor = token.span.end.index
|
|
145
|
+
if token.kind=="identifier" and token.text=="if": conditional = true
|
|
146
|
+
if not conditional: _static_keys(child.parts,keys)
|
|
147
|
+
|
|
148
|
+
func _key_expression(expression) -> void:
|
|
149
|
+
var tokens := _expression_tokens(expression)
|
|
150
|
+
if tokens.is_empty(): return
|
|
151
|
+
# Token kinds keep strings/comments containing constructor-looking text
|
|
152
|
+
# ordinary values; never classify source by substring replacement.
|
|
153
|
+
var first: String = tokens[0].text
|
|
154
|
+
var invalid := false
|
|
155
|
+
if tokens.size()==1:
|
|
156
|
+
invalid = first in ["<element>","null","true","false",'""',"''",'""""""',"''''''"] or tokens[0].kind=="number" and first.is_valid_float() and not first.is_valid_int()
|
|
157
|
+
elif tokens.size()==2 and first in ["+","-"] and tokens[1].kind=="number":
|
|
158
|
+
invalid = tokens[1].text.is_valid_float() and not tokens[1].text.is_valid_int()
|
|
159
|
+
elif first in ["[","{","&","<element>"]: invalid = true
|
|
160
|
+
elif tokens.size()>1 and tokens[1].text=="(" and _direct_call(tokens,1):
|
|
161
|
+
invalid = first in ["bool","float","StringName","Vector2","Vector3","Color","Dictionary","NodePath"]
|
|
162
|
+
elif tokens.size()>3 and tokens[1].text=="." and tokens[2].text=="new" and tokens[3].text=="(" and _direct_call(tokens,3): invalid = true
|
|
163
|
+
if invalid: _error("GGX key must be an integer or nonempty String",expression.span)
|
|
164
|
+
func _direct_call(tokens: Array, start: int) -> bool:
|
|
165
|
+
var depth := 0
|
|
166
|
+
for index in range(start,tokens.size()):
|
|
167
|
+
if tokens[index].text=="(": depth += 1
|
|
168
|
+
elif tokens[index].text==")":
|
|
169
|
+
depth -= 1
|
|
170
|
+
if depth==0: return index==tokens.size()-1
|
|
171
|
+
return false
|
|
172
|
+
func _expression_tokens(expression) -> Array:
|
|
173
|
+
var tokens: Array = []
|
|
174
|
+
var lexer := Lexer.new(file)
|
|
175
|
+
for part in expression.parts:
|
|
176
|
+
if part is Model.Component:
|
|
177
|
+
tokens.append({"text":"<element>","kind":"element","span":part.span})
|
|
178
|
+
continue
|
|
179
|
+
var cursor: int = part.span.start.index
|
|
180
|
+
while cursor < part.span.end.index:
|
|
181
|
+
var token = lexer.next_token(cursor)
|
|
182
|
+
if token==null: return []
|
|
183
|
+
cursor = token.span.end.index
|
|
184
|
+
if token.kind not in ["whitespace","comment","newline","continuation"]: tokens.append({"text":token.text,"kind":token.kind,"span":token.span})
|
|
185
|
+
return tokens
|
|
186
|
+
func _child_expression(expression) -> void:
|
|
187
|
+
_child_result(_expression_tokens(expression),expression.span)
|
|
188
|
+
func _child_result(tokens: Array, span) -> void:
|
|
189
|
+
# Result alternatives are descriptions/null/sequences; the condition remains
|
|
190
|
+
# normal native GDScript. This closes the Variant ternary loophole where
|
|
191
|
+
# Godot defers an int/Object conversion until gameplay.
|
|
192
|
+
if tokens.size()==1 and tokens[0].text in ["<element>","null"]: return
|
|
193
|
+
var depth := 0
|
|
194
|
+
var conditional := -1
|
|
195
|
+
var alternative := -1
|
|
196
|
+
var outer_close := -1
|
|
197
|
+
for index in range(tokens.size()):
|
|
198
|
+
var value: String = tokens[index].text
|
|
199
|
+
if value in ["(","[","{"]: depth += 1
|
|
200
|
+
elif value in [")","]","}"]:
|
|
201
|
+
depth -= 1
|
|
202
|
+
if depth==0 and outer_close<0: outer_close = index
|
|
203
|
+
elif depth==0:
|
|
204
|
+
if value=="if" and conditional<0: conditional = index
|
|
205
|
+
elif value=="else" and conditional>=0:
|
|
206
|
+
alternative = index
|
|
207
|
+
break
|
|
208
|
+
if not tokens.is_empty() and tokens[0].text=="(" and outer_close==tokens.size()-1:
|
|
209
|
+
_child_result(tokens.slice(1,tokens.size()-1),span)
|
|
210
|
+
return
|
|
211
|
+
if conditional>0 and alternative>conditional+1 and alternative<tokens.size()-1:
|
|
212
|
+
_child_result(tokens.slice(0,conditional),span)
|
|
213
|
+
_child_result(tokens.slice(alternative+1),span)
|
|
214
|
+
return
|
|
215
|
+
if tokens.size()>=2 and tokens[0].text=="[" and outer_close==tokens.size()-1:
|
|
216
|
+
var begin := 1
|
|
217
|
+
depth = 0
|
|
218
|
+
for index in range(1,tokens.size()-1):
|
|
219
|
+
var value: String = tokens[index].text
|
|
220
|
+
if value in ["(","[","{"]: depth += 1
|
|
221
|
+
elif value in [")","]","}"]: depth -= 1
|
|
222
|
+
elif value=="," and depth==0:
|
|
223
|
+
_child_result(tokens.slice(begin,index),span)
|
|
224
|
+
begin = index+1
|
|
225
|
+
if begin<tokens.size()-1: _child_result(tokens.slice(begin,tokens.size()-1),span)
|
|
226
|
+
return
|
|
227
|
+
# Unknown native expressions (locals, typed helper returns, Array.map) are
|
|
228
|
+
# runtime-validated as a complete desired tree. Obvious scalar/live Node
|
|
229
|
+
# leaves fail at their authored span, including conditional alternatives.
|
|
230
|
+
if not tokens.is_empty():
|
|
231
|
+
var first: String = tokens[0].text
|
|
232
|
+
var constructor: bool = tokens.size()>3 and tokens[1].text=="." and tokens[2].text=="new" and tokens[3].text=="(" and _direct_call(tokens,3)
|
|
233
|
+
var scalar_call: bool = tokens.size()>1 and tokens[1].text=="(" and _direct_call(tokens,1) and first in ["int","float","bool","String","StringName","Vector2","Vector3","Color","Dictionary","NodePath"]
|
|
234
|
+
if tokens[0].kind=="identifier" and first not in ["true","false"] and not scalar_call and (not constructor or resolver.aliases.get(first,"")=="res://addons/estragon/runtime/composition/element.gd"):
|
|
235
|
+
return
|
|
236
|
+
_error("GGX children require Element, null or nested Arrays of descriptions; scalars/live Nodes reject",tokens[0].span if not tokens.is_empty() else span)
|
|
237
|
+
|
|
238
|
+
func _native_type(property: Dictionary) -> String:
|
|
239
|
+
if property.type == TYPE_OBJECT:
|
|
240
|
+
var native: String = str(property.get("class_name", ""))
|
|
241
|
+
return native if not native.is_empty() else "Object"
|
|
242
|
+
if property.type == TYPE_NIL: return "Variant"
|
|
243
|
+
# Names are stable Variant types, not an engine-version-specific type_string API.
|
|
244
|
+
return {TYPE_BOOL:"bool", TYPE_INT:"int", TYPE_FLOAT:"float", TYPE_STRING:"String", TYPE_STRING_NAME:"StringName", TYPE_VECTOR2:"Vector2", TYPE_VECTOR2I:"Vector2i", TYPE_RECT2:"Rect2", TYPE_RECT2I:"Rect2i", TYPE_VECTOR3:"Vector3", TYPE_VECTOR3I:"Vector3i", TYPE_TRANSFORM2D:"Transform2D", TYPE_VECTOR4:"Vector4", TYPE_VECTOR4I:"Vector4i", TYPE_PLANE:"Plane", TYPE_QUATERNION:"Quaternion", TYPE_AABB:"AABB", TYPE_BASIS:"Basis", TYPE_TRANSFORM3D:"Transform3D", TYPE_PROJECTION:"Projection", TYPE_COLOR:"Color", TYPE_NODE_PATH:"NodePath", TYPE_RID:"RID", TYPE_CALLABLE:"Callable", TYPE_SIGNAL:"Signal", TYPE_DICTIONARY:"Dictionary", TYPE_ARRAY:"Array", TYPE_PACKED_BYTE_ARRAY:"PackedByteArray", TYPE_PACKED_INT32_ARRAY:"PackedInt32Array", TYPE_PACKED_INT64_ARRAY:"PackedInt64Array", TYPE_PACKED_FLOAT32_ARRAY:"PackedFloat32Array", TYPE_PACKED_FLOAT64_ARRAY:"PackedFloat64Array", TYPE_PACKED_STRING_ARRAY:"PackedStringArray", TYPE_PACKED_VECTOR2_ARRAY:"PackedVector2Array", TYPE_PACKED_VECTOR3_ARRAY:"PackedVector3Array", TYPE_PACKED_COLOR_ARRAY:"PackedColorArray"}.get(property.type, "")
|
|
245
|
+
|
|
246
|
+
func _binding(attribute, node, properties: Dictionary, signals: Dictionary) -> void:
|
|
247
|
+
if attribute.name!="bind:value":
|
|
248
|
+
_error("Only bind:value is supported",attribute.name_span)
|
|
249
|
+
return
|
|
250
|
+
for peer in node.attributes:
|
|
251
|
+
if peer.name in ["value","value_changed"]:
|
|
252
|
+
_error("bind:value conflicts with value/value_changed",peer.name_span)
|
|
253
|
+
return
|
|
254
|
+
var event: Dictionary = signals.get("value_changed",{})
|
|
255
|
+
var args: Array = event.get("args",[])
|
|
256
|
+
if not properties.has("value") or properties.value.type!=TYPE_BOOL or int(properties.value.usage)&PROPERTY_USAGE_READ_ONLY or args.size()!=1 or args[0].type!=TYPE_BOOL:
|
|
257
|
+
_error("bind:value requires writable bool value and value_changed(value: bool)",attribute.name_span)
|
|
258
|
+
return
|
|
259
|
+
if not attribute.value is Model.GdExpression:
|
|
260
|
+
_error("bind:value requires an explicit self bindable lvalue path",attribute.value.span)
|
|
261
|
+
return
|
|
262
|
+
var tokens := _expression_tokens(attribute.value)
|
|
263
|
+
if tokens.size()<3 or tokens.size()%2!=1 or tokens[0].text!="self":
|
|
264
|
+
_error("bind:value requires self.field or self.model.field",attribute.value.span)
|
|
265
|
+
return
|
|
266
|
+
var names: Array = []
|
|
267
|
+
for index in range(1,tokens.size()):
|
|
268
|
+
if index%2==1 and tokens[index].text!="." or index%2==0 and tokens[index].kind!="identifier":
|
|
269
|
+
_error("bind:value accepts only assignable identifier paths",tokens[index].span)
|
|
270
|
+
return
|
|
271
|
+
if index%2==0: names.append(tokens[index].text)
|
|
272
|
+
if not resolver.bindable_path(current_module,names):
|
|
273
|
+
_error("bind:value path requires typed Gogo bindable fields ending in bool",attribute.value.span)
|
|
274
|
+
return
|
|
275
|
+
attribute.kind = "binding"
|
|
276
|
+
attribute.type_name = "Variant"
|
|
277
|
+
attribute.binding_path = names
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://18ek0ph56dq4
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Synchronous pre-Play boundary. No compiler, subprocess or widget hierarchy.
|
|
4
|
+
|
|
5
|
+
static func _failure(path: String, message: String) -> Dictionary:
|
|
6
|
+
return {"ok": false, "diagnostics": [path + ":1:1: " + message], "buffers": []}
|
|
7
|
+
|
|
8
|
+
static func _snapshot(scripts: ScriptEditor, resolve_path: Callable) -> Dictionary:
|
|
9
|
+
var buffers: Array[Dictionary] = []
|
|
10
|
+
for editor in scripts.get_open_script_editors():
|
|
11
|
+
var code = editor.get_base_editor()
|
|
12
|
+
if not code is TextEdit:
|
|
13
|
+
return _failure("<editor buffer>", "Cannot verify this editor buffer before Play; save or close it first.")
|
|
14
|
+
var path := ""
|
|
15
|
+
var resource: Resource
|
|
16
|
+
# The existing, engine-tested E01 adapter supplies exact identity, never
|
|
17
|
+
# a filename/content guess. Prefer its native resource capability.
|
|
18
|
+
if code.syntax_highlighter is EditorSyntaxHighlighter and code.syntax_highlighter.has_method("_get_edited_resource"):
|
|
19
|
+
resource = code.syntax_highlighter.call("_get_edited_resource") as Resource
|
|
20
|
+
if resource != null:
|
|
21
|
+
path = resource.resource_path
|
|
22
|
+
if path.is_empty():
|
|
23
|
+
return _failure("<unsaved editor buffer>", "Save this new/pathless buffer to a project file before Play.")
|
|
24
|
+
else:
|
|
25
|
+
path = resolve_path.call(editor, code)
|
|
26
|
+
if path.is_empty():
|
|
27
|
+
return _failure("<unidentified editor buffer>", "Cannot identify this buffer safely; save or close it before Play.")
|
|
28
|
+
if path.get_extension() != "gogo": continue
|
|
29
|
+
if resource == null:
|
|
30
|
+
# Baseline ResourceLoader returns the already-cached native TextFile;
|
|
31
|
+
# no text loader is required or invoked. Missing identity is a failure,
|
|
32
|
+
# not permission to trust a possibly stale tab tooltip/meta path.
|
|
33
|
+
if not ResourceLoader.has_cached(path):
|
|
34
|
+
return _failure(path, "Cannot verify this Gogo buffer identity; save or close it before Play.")
|
|
35
|
+
resource = ResourceLoader.load(path)
|
|
36
|
+
if resource == null or resource.resource_path != path or resource.get_class() != "TextFile":
|
|
37
|
+
return _failure(path, "Cannot verify this Gogo buffer identity; save or close it before Play.")
|
|
38
|
+
if not path.begins_with("res://") or path.contains("::"):
|
|
39
|
+
return _failure(path, "Gogo buffers must have a project file path before Play.")
|
|
40
|
+
buffers.append({"path": path, "code": code, "text": code.text,
|
|
41
|
+
"dirty": code.get_version() != code.get_saved_version()})
|
|
42
|
+
return {"ok": true, "diagnostics": [], "buffers": buffers}
|
|
43
|
+
|
|
44
|
+
static func save_and_verify(scripts: ScriptEditor, resolve_path: Callable) -> Dictionary:
|
|
45
|
+
var snapshot := _snapshot(scripts, resolve_path)
|
|
46
|
+
if not snapshot.ok: return snapshot
|
|
47
|
+
if scripts.has_method("save_all_scripts"):
|
|
48
|
+
# Preserve the newer editor's ordinary save/normalization behavior.
|
|
49
|
+
scripts.call("save_all_scripts")
|
|
50
|
+
snapshot = _snapshot(scripts, resolve_path)
|
|
51
|
+
if not snapshot.ok: return snapshot
|
|
52
|
+
else:
|
|
53
|
+
for buffer in snapshot.buffers:
|
|
54
|
+
if not buffer.dirty: continue
|
|
55
|
+
var file := FileAccess.open(buffer.path, FileAccess.WRITE)
|
|
56
|
+
if file == null:
|
|
57
|
+
return _failure(buffer.path, "Cannot save latest Gogo buffer (" + error_string(FileAccess.get_open_error()) + "); Play blocked.")
|
|
58
|
+
file.store_string(buffer.text)
|
|
59
|
+
file.flush()
|
|
60
|
+
var error := file.get_error()
|
|
61
|
+
file.close()
|
|
62
|
+
if error != OK:
|
|
63
|
+
return _failure(buffer.path, "Cannot persist latest Gogo buffer (" + error_string(error) + "); Play blocked.")
|
|
64
|
+
for buffer in snapshot.buffers:
|
|
65
|
+
var file := FileAccess.open(buffer.path, FileAccess.READ)
|
|
66
|
+
if file == null:
|
|
67
|
+
return _failure(buffer.path, "Cannot read saved Gogo source; Play blocked.")
|
|
68
|
+
var bytes := file.get_buffer(file.get_length())
|
|
69
|
+
var error := file.get_error()
|
|
70
|
+
file.close()
|
|
71
|
+
# Native TextEdit canonicalizes CRLF to LF even in a clean buffer.
|
|
72
|
+
# Preserve clean on-disk line endings when that is the only difference.
|
|
73
|
+
var matches := bytes == str(buffer.text).to_utf8_buffer()
|
|
74
|
+
if not buffer.dirty and not matches:
|
|
75
|
+
matches = bytes.get_string_from_utf8().replace("\r\n", "\n") == buffer.text
|
|
76
|
+
if error != OK or not matches or buffer.code.text != buffer.text:
|
|
77
|
+
return _failure(buffer.path, "Saved source does not match the latest Gogo buffer; save/reload it before Play.")
|
|
78
|
+
# Mark only after every persisted snapshot has been independently verified.
|
|
79
|
+
for buffer in snapshot.buffers: buffer.code.tag_saved_version()
|
|
80
|
+
if scripts.has_method("get_unsaved_files"):
|
|
81
|
+
for path in scripts.call("get_unsaved_files"):
|
|
82
|
+
if str(path).get_extension() == "gogo":
|
|
83
|
+
return _failure(str(path), "Cannot save latest Gogo buffer; resolve the Save error before Play.")
|
|
84
|
+
return snapshot
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://bajbhxcbtjgnu
|