@papercraftgames/estragon 0.1.0-beta.26 → 0.1.0-beta.28
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/addons/estragon/compiler/emitter.gd +78 -6
- package/addons/estragon/compiler/frontend.gd +4 -0
- package/addons/estragon/compiler/import_aliases.gd +64 -0
- package/addons/estragon/compiler/import_aliases.gd.uid +1 -0
- package/addons/estragon/compiler/layouts.gd +412 -0
- package/addons/estragon/compiler/layouts.gd.uid +1 -0
- package/addons/estragon/compiler/lexer.gd +1 -0
- package/addons/estragon/compiler/model.gd +25 -0
- package/addons/estragon/compiler/native/resolver.gd +15 -4
- package/addons/estragon/compiler/parser.gd +46 -0
- package/addons/estragon/compiler/validator.gd +22 -8
- package/addons/estragon/editor/completion.gd +47 -3
- package/addons/estragon/editor/components.gd +1 -1
- package/addons/estragon/editor/highlighter.gd +1 -1
- package/addons/estragon/editor/imports.gd +5 -1
- package/addons/estragon/editor/lexical_context.gd +2 -2
- package/addons/estragon/editor/plugin.cfg +1 -1
- package/addons/estragon/runtime/composition/computation.gd +13 -6
- package/addons/estragon/runtime/composition/preset.gd +101 -0
- package/addons/estragon/runtime/composition/preset.gd.uid +1 -0
- package/addons/estragon/runtime/node/box.gd +12 -5
- package/addons/estragon/runtime/node/button.gd +4 -4
- package/addons/estragon/runtime/node/component_2d.gd +83 -2
- package/addons/estragon/runtime/node/grid.gd +21 -17
- package/addons/estragon/runtime/node/internal/coordinator.gd +1 -1
- package/addons/estragon/runtime/node/internal/layout_core.gd +2 -1
- package/addons/estragon/runtime/node/internal/length.gd +2 -0
- package/addons/estragon/runtime/node/internal/scroll_2d.gd +6 -4
- package/addons/estragon/runtime/node/internal/stack_contract.gd +10 -2
- package/addons/estragon/runtime/node/internal/visual_style_2d.gd +192 -2
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ extends RefCounted
|
|
|
4
4
|
## Regexes classify Unicode characters only; no source rewriting/evaluation.
|
|
5
5
|
const Model = preload("model.gd")
|
|
6
6
|
const Source = preload("source.gd")
|
|
7
|
+
const KEYWORDS := ["layout","export","extends","class_name","class","func","static","var","const","return","if","elif","else","for","in","while","await","signal","true","false","null","pass","and","or","not","as","is","self","match","break","continue","assert","enum","preload","load","super","get","set","when","void","breakpoint"]
|
|
7
8
|
const OPERATORS := ["**=", "<<=", ">>=", ":=", "==", "!=", "<=", ">=", "<<", ">>", "**", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "&&", "||", "->"]
|
|
8
9
|
var file: Source
|
|
9
10
|
var tokens: Array[Model.Token] = []
|
|
@@ -69,13 +69,38 @@ class Component extends SyntaxNode:
|
|
|
69
69
|
var name: String
|
|
70
70
|
var name_span: Span
|
|
71
71
|
var runtime_class: String
|
|
72
|
+
var preset: Preset
|
|
73
|
+
var preset_expression: GdExpression
|
|
72
74
|
var attributes: Array[Attribute] = []
|
|
73
75
|
var children: Array[SyntaxNode] = []
|
|
74
76
|
var text_body: Array[SyntaxNode] = []
|
|
75
77
|
func _init() -> void:
|
|
76
78
|
kind = "component-expression"
|
|
77
79
|
|
|
80
|
+
class Layout extends SyntaxNode:
|
|
81
|
+
var root: Component
|
|
82
|
+
var mutable := false
|
|
83
|
+
var exported := false
|
|
84
|
+
var bindings: Array = []
|
|
85
|
+
func _init() -> void: kind = "layout-declaration"
|
|
86
|
+
|
|
87
|
+
class Preset extends RefCounted:
|
|
88
|
+
var name: String
|
|
89
|
+
var symbol: String
|
|
90
|
+
var base: String
|
|
91
|
+
var resolved: Dictionary = {}
|
|
92
|
+
var groups: Array = []
|
|
93
|
+
var generated: Dictionary = {}
|
|
94
|
+
var span: Span
|
|
95
|
+
var visible: int
|
|
96
|
+
var scope: int
|
|
97
|
+
var mutable := false
|
|
98
|
+
var exported := false
|
|
99
|
+
|
|
78
100
|
class Module extends RefCounted:
|
|
101
|
+
var presets: Array = []
|
|
102
|
+
var import_aliases: Dictionary = {}
|
|
103
|
+
var identifier_imports: Array = []
|
|
79
104
|
var project_imports: Dictionary = {}
|
|
80
105
|
var resource_imports: Array = []
|
|
81
106
|
var composition: bool = false
|
|
@@ -76,11 +76,19 @@ func scan(module: Model.Module) -> void:
|
|
|
76
76
|
path = output.get_base_dir().path_join(path).simplify_path()
|
|
77
77
|
if not path.is_absolute_path(): path = "res://" + path
|
|
78
78
|
aliases[name] = path.simplify_path()
|
|
79
|
+
if ClassDB.class_exists(name) and not module.import_aliases.has(name):
|
|
80
|
+
var private_name := "_GogoImport_"+str(module.import_aliases.size())
|
|
81
|
+
while module.identifiers.has(private_name): private_name += "_"
|
|
82
|
+
module.identifiers.append(private_name)
|
|
83
|
+
module.import_aliases[name] = private_name
|
|
79
84
|
for index in range(tokens.size()-3):
|
|
80
85
|
if tokens[index].text!="const" or tokens[index].span.start.column!=1 or tokens[index+2].text!="=": continue
|
|
81
86
|
var target: String = tokens[index+3].text
|
|
82
87
|
if index+4<tokens.size() and tokens[index+4].span.start.line==tokens[index+3].span.start.line: continue
|
|
83
|
-
|
|
88
|
+
# Script aliases retain lexical meaning even when their name shadows a
|
|
89
|
+
# native class. Never classify Other=Button as native behind an import.
|
|
90
|
+
if aliases.has(target): aliases[tokens[index+1].text] = aliases[target]
|
|
91
|
+
elif ClassDB.class_exists(target): native_aliases[tokens[index+1].text] = target
|
|
84
92
|
|
|
85
93
|
func scope():
|
|
86
94
|
if project == null: project = ProjectSources.new()
|
|
@@ -92,9 +100,9 @@ func resolve(name: String, span: Model.Span, project_tags: bool = true) -> Dicti
|
|
|
92
100
|
if not ClassDB.is_parent_class(native,"Node") or not ClassDB.can_instantiate(native): return _fail("Non-constructible native alias "+name,span)
|
|
93
101
|
return {"native":native,"script":null,"native_alias":native}
|
|
94
102
|
if aliases.has(name):
|
|
95
|
-
if ClassDB.class_exists(name):
|
|
96
|
-
return _fail("Ambiguous GGX preload alias " + name, span)
|
|
97
103
|
var explicit := _script(name,aliases[name],span,project_tags)
|
|
104
|
+
if explicit.is_empty(): return explicit
|
|
105
|
+
if _module.import_aliases.has(name): explicit.runtime_alias = _module.import_aliases[name]
|
|
98
106
|
return _import(name,explicit,explicit.get("gogo_path",""),span) if project_tags else explicit
|
|
99
107
|
if project_tags:
|
|
100
108
|
var candidates: Array = scope().named(name)
|
|
@@ -139,7 +147,7 @@ func _script(name: String, path: String, span: Model.Span, check_constructor: bo
|
|
|
139
147
|
# it must not load authored scripts (including their static initializers).
|
|
140
148
|
if source_only and FileAccess.file_exists(path): return _gogo(name,path,path,span,check_constructor)
|
|
141
149
|
if not ResourceLoader.exists(path, "GDScript"): return _fail("GGX script import not found: " + path, span)
|
|
142
|
-
var script
|
|
150
|
+
var script = load(path)
|
|
143
151
|
# CACHE_MODE_IGNORE still changes GDScript's internal cache on tested Godot.
|
|
144
152
|
# Never mutate an application's live Script during metadata analysis.
|
|
145
153
|
if script is GDScript and script.source_code.replace("\r\n","\n") != FileAccess.get_file_as_string(path).replace("\r\n","\n"):
|
|
@@ -243,6 +251,9 @@ func _gogo(name: String, path: String, authored: String, span: Model.Span, check
|
|
|
243
251
|
var qualified := ""
|
|
244
252
|
if kind==TYPE_OBJECT:
|
|
245
253
|
if type==declared_name: qualified = name
|
|
254
|
+
elif imported.aliases.has(type.get_slice(".",0)):
|
|
255
|
+
var root_name := type.get_slice(".",0)
|
|
256
|
+
qualified = name+"."+module.import_aliases.get(root_name,root_name)+type.trim_prefix(root_name)
|
|
246
257
|
elif ClassDB.class_exists(type.get_slice(".",0)) or imported.globals.has(type.get_slice(".",0)): qualified = type
|
|
247
258
|
else: qualified = name+"."+type
|
|
248
259
|
properties[part.name] = {"name":part.name,"type":kind,"class_name":qualified,"usage":PROPERTY_USAGE_DEFAULT,"source_writable":true}
|
|
@@ -249,6 +249,20 @@ func _scan(start: int, braced: bool) -> Dictionary:
|
|
|
249
249
|
operand = false
|
|
250
250
|
has_token = true
|
|
251
251
|
continue
|
|
252
|
+
# Layout declarations are statements, never expression islands.
|
|
253
|
+
if not braced and stack.is_empty() and character in "le" and _context(offset,false,true).first:
|
|
254
|
+
var probe := Lexer.new(file)
|
|
255
|
+
var first_token := probe.next_token(offset)
|
|
256
|
+
if first_token!=null and first_token.text in ["layout","export"]:
|
|
257
|
+
_copy(parts,copied,offset)
|
|
258
|
+
_cursor = offset
|
|
259
|
+
var declaration := _layout()
|
|
260
|
+
if declaration==null: break
|
|
261
|
+
parts.append(declaration)
|
|
262
|
+
offset = _cursor
|
|
263
|
+
copied = offset
|
|
264
|
+
operand = true
|
|
265
|
+
continue
|
|
252
266
|
var token := lexer.next_token(offset)
|
|
253
267
|
if token == null: break
|
|
254
268
|
var from := offset
|
|
@@ -293,3 +307,35 @@ func _context(offset: int, braced: bool, top: bool) -> Dictionary:
|
|
|
293
307
|
module.indentation = prefix
|
|
294
308
|
_indentation_seen = true
|
|
295
309
|
return {"line": line, "prefix": prefix, "first": first}
|
|
310
|
+
|
|
311
|
+
func _layout() -> Model.Layout:
|
|
312
|
+
var start := _cursor
|
|
313
|
+
if not _classes.is_empty():
|
|
314
|
+
file.fail("layout declarations inside named inner classes are unsupported; use an outer lexical scope",start)
|
|
315
|
+
return null
|
|
316
|
+
var result := Model.Layout.new()
|
|
317
|
+
var token := lexer.next_token(_cursor)
|
|
318
|
+
if token.text=="export":
|
|
319
|
+
result.exported = true
|
|
320
|
+
_cursor = token.span.end.index
|
|
321
|
+
_whitespace()
|
|
322
|
+
token = lexer.next_token(_cursor)
|
|
323
|
+
if token==null or token.text!="layout":
|
|
324
|
+
file.fail("export requires a layout const/var declaration",start,_cursor)
|
|
325
|
+
return null
|
|
326
|
+
_cursor = token.span.end.index
|
|
327
|
+
_whitespace()
|
|
328
|
+
token = lexer.next_token(_cursor)
|
|
329
|
+
if token==null or token.text not in ["const","var"]:
|
|
330
|
+
file.fail("layout requires const or var (not let)",_cursor)
|
|
331
|
+
return null
|
|
332
|
+
result.mutable = token.text=="var"
|
|
333
|
+
_cursor = token.span.end.index
|
|
334
|
+
_whitespace()
|
|
335
|
+
if not _at("<"):
|
|
336
|
+
file.fail("Expected layout root tag",_cursor)
|
|
337
|
+
return null
|
|
338
|
+
result.root = _component(0)
|
|
339
|
+
if result.root==null: return null
|
|
340
|
+
result.span = file.span(start,_cursor)
|
|
341
|
+
return result
|
|
@@ -26,13 +26,23 @@ func _node(node: Model.SyntaxNode) -> void:
|
|
|
26
26
|
if node is Model.GdExpression:
|
|
27
27
|
for part in node.parts: _node(part)
|
|
28
28
|
elif node is Model.Component: _component(node)
|
|
29
|
+
elif node is Model.Layout:
|
|
30
|
+
for binding in node.bindings:
|
|
31
|
+
for group in binding.groups:
|
|
32
|
+
var component := Model.Component.new()
|
|
33
|
+
component.name = group.name
|
|
34
|
+
component.name_span = group.name_span
|
|
35
|
+
component.span = group.span
|
|
36
|
+
component.preset = binding
|
|
37
|
+
component.attributes = group.attributes
|
|
38
|
+
_component(component)
|
|
29
39
|
func _error(message: String, span: Model.Span) -> void:
|
|
30
40
|
file.fail(message,span.start.index,span.end.index)
|
|
31
41
|
|
|
32
42
|
func _component(node: Model.Component) -> void:
|
|
33
|
-
var resolved: Dictionary = resolver.resolve(node.name, node.name_span)
|
|
43
|
+
var resolved: Dictionary = node.preset.resolved if node.preset!=null else resolver.resolve(node.name, node.name_span)
|
|
34
44
|
if resolved.is_empty(): return
|
|
35
|
-
node.runtime_class = resolved.get("project_alias",resolved.get("native_alias",node.name))
|
|
45
|
+
node.runtime_class = resolved.get("project_alias",resolved.get("runtime_alias",resolved.get("native_alias",node.name)))
|
|
36
46
|
var properties: Dictionary = {}
|
|
37
47
|
var signals: Dictionary = {}
|
|
38
48
|
for property in ClassDB.class_get_property_list(resolved.native): properties[property.name] = property
|
|
@@ -46,8 +56,7 @@ func _component(node: Model.Component) -> void:
|
|
|
46
56
|
script = script.get_base_script()
|
|
47
57
|
properties.merge(resolved.get("properties",{}),true)
|
|
48
58
|
signals.merge(resolved.get("signals",{}),true)
|
|
49
|
-
var stack_direction := StackContract.
|
|
50
|
-
if stack_direction.is_empty(): stack_direction = "row"
|
|
59
|
+
var stack_direction := StackContract.initial(resolved.script)
|
|
51
60
|
for attribute in node.attributes:
|
|
52
61
|
if attribute.name=="direction": stack_direction = str(attribute.value.value) if attribute.value is Model.Literal else StackContract.preset(resolved.script)
|
|
53
62
|
if VisualStyle.rect_conflict(resolved.script,node.attributes.map(func(item): return item.name)):
|
|
@@ -115,12 +124,12 @@ func _component(node: Model.Component) -> void:
|
|
|
115
124
|
_error("Removed layout API "+name+": use unit dimensions, grow and stretch" if name in ["flex","fill_width","fill_height","viewport_width_scale","viewport_height_scale"] else "Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
|
|
116
125
|
return
|
|
117
126
|
if not expanded and StackContract.registered(resolved.script) and attribute.value is Model.Literal:
|
|
118
|
-
var message := StackContract.error(name,attribute.value.value,stack_direction,StackContract.preset(resolved.script))
|
|
127
|
+
var message := StackContract.error(name,attribute.value.value,stack_direction,StackContract.preset(resolved.script),StackContract.grid_capable(resolved.script))
|
|
119
128
|
if not message.is_empty():
|
|
120
129
|
_error(message,attribute.value.span)
|
|
121
130
|
return
|
|
122
131
|
if not expanded and GridDefinition.marked(resolved.script) and attribute.value is Model.Literal:
|
|
123
|
-
if name in ["horizontal_align","vertical_align"] and attribute.value.value not in ["start","center","end","stretch"]:
|
|
132
|
+
if stack_direction=="grid" and name in ["horizontal_align","vertical_align"] and attribute.value.value not in ["start","center","end","stretch"]:
|
|
124
133
|
_error("Grid per-cell "+name+" requires start/center/end/stretch",attribute.value.span)
|
|
125
134
|
return
|
|
126
135
|
if name=="template":
|
|
@@ -133,10 +142,15 @@ func _component(node: Model.Component) -> void:
|
|
|
133
142
|
if not message.is_empty():
|
|
134
143
|
_error(message,attribute.value.span)
|
|
135
144
|
return
|
|
136
|
-
if GridDefinition.marked(resolved.script) and name in ["horizontal_align","vertical_align"] and attribute.value is Model.Literal and attribute.value.value not in ["start","center","end","stretch"]:
|
|
145
|
+
if stack_direction=="grid" and GridDefinition.marked(resolved.script) and name in ["horizontal_align","vertical_align"] and attribute.value is Model.Literal and attribute.value.value not in ["start","center","end","stretch"]:
|
|
137
146
|
_error("Grid "+name+" requires start, center, end or stretch",attribute.value.span)
|
|
138
147
|
return
|
|
139
148
|
var is_color := VisualStyle.registered(resolved.script,name)
|
|
149
|
+
if VisualStyle.supported(resolved.script) and name=="background_texture_mode" and attribute.value is Model.Literal:
|
|
150
|
+
var message := VisualStyle.surface_error(name,attribute.value.value)
|
|
151
|
+
if not message.is_empty():
|
|
152
|
+
_error(message,attribute.value.span)
|
|
153
|
+
return
|
|
140
154
|
if is_color:
|
|
141
155
|
_color(attribute)
|
|
142
156
|
if not file.diagnostics.is_empty(): return
|
|
@@ -202,7 +216,7 @@ func _component(node: Model.Component) -> void:
|
|
|
202
216
|
_error("Node GGX children must be newly declared Node elements; expression adoption is unsupported", child.span)
|
|
203
217
|
return
|
|
204
218
|
_node(child)
|
|
205
|
-
if not GridDefinition.marked(resolved.script):
|
|
219
|
+
if child.preset==null and not GridDefinition.marked(resolved.script):
|
|
206
220
|
for attribute in child.attributes:
|
|
207
221
|
if attribute.kind=="placement":
|
|
208
222
|
_error("GGX placement "+attribute.name+" requires a Grid parent",attribute.name_span)
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
@tool
|
|
2
2
|
extends RefCounted
|
|
3
3
|
## Lexical declarations + public ClassDB metadata. No authored Script loads/new().
|
|
4
|
+
const Parser = preload("../compiler/parser.gd")
|
|
5
|
+
const Model = preload("../compiler/model.gd")
|
|
6
|
+
const Layouts = preload("../compiler/layouts.gd")
|
|
4
7
|
const Validator = preload("../compiler/validator.gd")
|
|
5
8
|
const Source = preload("../compiler/source.gd")
|
|
6
9
|
const Context = preload("lexical_context.gd")
|
|
@@ -21,6 +24,8 @@ var _text := ""
|
|
|
21
24
|
var _path := ""
|
|
22
25
|
var _symbols: Dictionary = {}
|
|
23
26
|
var _aliases: Dictionary = {}
|
|
27
|
+
var _plain_aliases: Dictionary = {}
|
|
28
|
+
var _layout_names: Dictionary = {}
|
|
24
29
|
var _owners: Dictionary = {}
|
|
25
30
|
var _scoped: Dictionary = {}
|
|
26
31
|
var _blocks: Dictionary = {}
|
|
@@ -151,6 +156,7 @@ func _index(text: String, source: String) -> void:
|
|
|
151
156
|
_scoped = declarations.scoped
|
|
152
157
|
_blocks = declarations.blocks
|
|
153
158
|
_aliases = declarations.aliases
|
|
159
|
+
_plain_aliases = _aliases.duplicate()
|
|
154
160
|
_base = declarations.base
|
|
155
161
|
func _script(path: String) -> Dictionary:
|
|
156
162
|
var text: String = sources[path] if sources.has(path) else FileAccess.get_file_as_string(path)
|
|
@@ -441,7 +447,9 @@ func import_plan(text: String, source: String, requests: Array = []) -> Dictiona
|
|
|
441
447
|
for token in lexical.line(row).tokens:
|
|
442
448
|
if token.kind != "tag" or not token.text.is_valid_identifier(): continue
|
|
443
449
|
var item := Catalog.named(token.text)
|
|
444
|
-
|
|
450
|
+
# A bare native spelling already has meaning. Only explicit popup
|
|
451
|
+
# selection requests its colliding Estragon import.
|
|
452
|
+
if not item.is_empty() and item.dimension != 0 and not _symbols.has(token.text) and not ClassDB.class_exists(token.text): requests.append({"alias":token.text,"path":Catalog.path(item)})
|
|
445
453
|
if item.is_empty() and not _project_path(token.text).is_empty(): requests.append({"alias":token.text,"path":_project_path(token.text)})
|
|
446
454
|
return Imports.plan(text,source,requests,_symbols,_aliases,_tokens(text))
|
|
447
455
|
func definition(text: String, source: String, symbol: String) -> String:
|
|
@@ -461,6 +469,7 @@ func _grid_type(type: String, aliases: Dictionary, visited: Array = []) -> bool:
|
|
|
461
469
|
|
|
462
470
|
func candidates(text: String, source: String, lexical: RefCounted, row: int, column: int) -> Array:
|
|
463
471
|
_index(text,source)
|
|
472
|
+
_aliases = _layout_aliases(text,source,row,_plain_aliases)
|
|
464
473
|
lexical.update(text)
|
|
465
474
|
var context: Dictionary = lexical.context(row,column)
|
|
466
475
|
if context.suppressed: return _path_options(lexical.lines[row].left(column),context,source,row,column)
|
|
@@ -481,14 +490,14 @@ func candidates(text: String, source: String, lexical: RefCounted, row: int, col
|
|
|
481
490
|
for name in _classes:
|
|
482
491
|
if ClassDB.is_parent_class(name,"Node") and ClassDB.can_instantiate(name): offered[name] = {"kind":CodeEdit.KIND_CLASS}
|
|
483
492
|
for name in _aliases:
|
|
484
|
-
if _node_type(name,_aliases): offered[name] = {"kind":CodeEdit.KIND_CLASS,"origin":"explicit Node preload"}
|
|
493
|
+
if _node_type(name,_aliases): offered[name] = {"kind":CodeEdit.KIND_CLASS,"origin":"layout preset" if _layout_names.has(name) else "explicit Node preload"}
|
|
485
494
|
for entry in ProjectSettings.get_global_class_list():
|
|
486
495
|
var known := Catalog.named(str(entry["class"]))
|
|
487
496
|
if not known.is_empty() and Catalog.path(known) == str(entry.path): continue
|
|
488
497
|
if str(entry["class"]).begins_with(prefix) and _node_type(str(entry["class"]),{}): offered[entry["class"]] = {"kind":CodeEdit.KIND_CLASS,"origin":"project Node"}
|
|
489
498
|
for item in Catalog.ITEMS:
|
|
490
499
|
for alias in _aliases:
|
|
491
|
-
if _aliases[alias] == Catalog.path(item): offered.erase(alias)
|
|
500
|
+
if not _layout_names.has(alias) and _aliases[alias] == Catalog.path(item): offered.erase(alias)
|
|
492
501
|
offered.merge(_catalog_options(prefix,true))
|
|
493
502
|
# A bare native/global spelling with a project collision would fail
|
|
494
503
|
# compilation. Offer a source-qualified explicit choice instead.
|
|
@@ -540,3 +549,38 @@ func candidates(text: String, source: String, lexical: RefCounted, row: int, col
|
|
|
540
549
|
result.append({"text":display,"insert":insert,"kind":item.kind,"row":row,"start":cursor if context.mode == "tag" and context.closing else cursor+1,"column":column,"hint":item.get("hint",""),"imports":[item["import"]] if item.has("import") else []})
|
|
541
550
|
result.sort_custom(func(a,b): return a.text < b.text)
|
|
542
551
|
return result
|
|
552
|
+
|
|
553
|
+
func _layout_aliases(text: String, source: String, row: int, existing: Dictionary) -> Dictionary:
|
|
554
|
+
# Completion is tolerant and source-only. Use completed declarations before
|
|
555
|
+
# the edited line; incomplete markup must never execute/load authored code.
|
|
556
|
+
var file := Source.new(text,source)
|
|
557
|
+
var parser := Parser.new(file)
|
|
558
|
+
parser.parse()
|
|
559
|
+
var module = parser.module
|
|
560
|
+
var index := Layouts.new(file)
|
|
561
|
+
index.module = module
|
|
562
|
+
index._index()
|
|
563
|
+
var target := file.line_start(row+1)
|
|
564
|
+
var result := existing.duplicate()
|
|
565
|
+
_layout_names.clear()
|
|
566
|
+
var paths := {}
|
|
567
|
+
for part in module.parts:
|
|
568
|
+
if not part is Model.Layout or part.span.end.index>target: continue
|
|
569
|
+
var names: Array = [part.root]
|
|
570
|
+
for child in part.root.children:
|
|
571
|
+
if child is Model.Component: names.append(child)
|
|
572
|
+
for node in names:
|
|
573
|
+
if not node.name.is_valid_identifier(): continue
|
|
574
|
+
var binding := Model.Preset.new()
|
|
575
|
+
binding.name = node.name
|
|
576
|
+
binding.visible = part.span.end.index
|
|
577
|
+
binding.scope = index._scope(part.span.start.index)
|
|
578
|
+
binding.symbol = paths.get(node.name,result.get(node.name,(preload("../runtime/node/grid.gd") as Script).resource_path if node==part.root else (preload("../runtime/node/box.gd") as Script).resource_path))
|
|
579
|
+
paths[node.name] = binding.symbol
|
|
580
|
+
module.presets.append(binding)
|
|
581
|
+
for name in paths:
|
|
582
|
+
var binding = index._visible(name,target)
|
|
583
|
+
if binding!=null:
|
|
584
|
+
result[name] = binding.symbol
|
|
585
|
+
_layout_names[name] = true
|
|
586
|
+
return result
|
|
@@ -7,7 +7,7 @@ const ITEMS := [
|
|
|
7
7
|
{"alias":"Box","canonical":"EstragonBox","script":preload("../runtime/node/box.gd"),"dimension":2,"origin":"native layout"},
|
|
8
8
|
{"alias":"Text","canonical":"EstragonText","script":preload("../runtime/node/text.gd"),"dimension":2,"origin":"native widget"},
|
|
9
9
|
{"alias":"Rect","canonical":"EstragonRect","script":preload("../runtime/node/rect.gd"),"dimension":2,"origin":"native widget"},
|
|
10
|
-
{"alias":"
|
|
10
|
+
{"alias":"Button","canonical":"EstragonButton","script":preload("../runtime/node/button.gd"),"dimension":2,"origin":"Estragon native; explicit import"},
|
|
11
11
|
{"alias":"VBox","canonical":"EstragonVBox","script":preload("../runtime/node/vbox.gd"),"dimension":2,"origin":"native layout"},
|
|
12
12
|
{"alias":"HBox","canonical":"EstragonHBox","script":preload("../runtime/node/hbox.gd"),"dimension":2,"origin":"native layout"},
|
|
13
13
|
{"alias":"Entry2D","canonical":"Estragon2D","script":preload("../runtime/node/estragon_2d.gd"),"dimension":2,"origin":"layout entry"},
|
|
@@ -69,7 +69,7 @@ func _get_line_syntax_highlighting(index: int) -> Dictionary:
|
|
|
69
69
|
var native_colors: Dictionary = _native.get_line_syntax_highlighting(index) if _native != null else {}
|
|
70
70
|
var result: Dictionary = native_colors.duplicate(true) if _native != null else {0:{"color":color("code")}}
|
|
71
71
|
for token in lexical.line(index).tokens:
|
|
72
|
-
if _native != null and token.native and not (token.kind == "annotation" and token.text == "bindable"): continue
|
|
72
|
+
if _native != null and token.native and not (token.kind == "annotation" and token.text == "bindable" or token.kind == "keyword" and token.text in ["layout","export"]): continue
|
|
73
73
|
result[token.start] = {"color":color(token.kind)}
|
|
74
74
|
result[token.end] = {"color":_native_color(native_colors,token.end) if _native != null else color("code")}
|
|
75
75
|
return result
|
|
@@ -5,7 +5,11 @@ const Build = preload("build_service.gd")
|
|
|
5
5
|
const Source = preload("../compiler/source.gd")
|
|
6
6
|
const Catalog = preload("components.gd")
|
|
7
7
|
static func occupied(name: String, resource: String, symbols: Dictionary) -> bool:
|
|
8
|
-
if symbols.has(name)
|
|
8
|
+
if symbols.has(name): return true
|
|
9
|
+
var known := Catalog.named(name)
|
|
10
|
+
# Deliberate catalog selection may shadow a native class in Gogo. The
|
|
11
|
+
# compiler lowers that lexical import to a legal private GDScript symbol.
|
|
12
|
+
if ClassDB.class_exists(name) and (known.is_empty() or known.alias!=name or Catalog.path(known)!=resource): return true
|
|
9
13
|
for entry in ProjectSettings.get_global_class_list():
|
|
10
14
|
if str(entry["class"]) == name and str(entry.path) != resource and FileAccess.file_exists(str(entry.path)): return true
|
|
11
15
|
return false
|
|
@@ -5,7 +5,7 @@ extends RefCounted
|
|
|
5
5
|
const Lexer = preload("../compiler/lexer.gd")
|
|
6
6
|
const Source = preload("../compiler/source.gd")
|
|
7
7
|
const Parser = preload("../compiler/parser.gd")
|
|
8
|
-
const KEYWORDS := ["extends", "class_name", "class", "func", "static", "var", "const", "return", "if", "elif", "else", "for", "in", "while", "await", "signal", "true", "false", "null", "pass", "and", "or", "not", "as", "is", "self", "match", "break", "continue", "assert", "enum", "preload", "load", "super", "get", "set", "when", "void"]
|
|
8
|
+
const KEYWORDS := ["layout", "export", "extends", "class_name", "class", "func", "static", "var", "const", "return", "if", "elif", "else", "for", "in", "while", "await", "signal", "true", "false", "null", "pass", "and", "or", "not", "as", "is", "self", "match", "break", "continue", "assert", "enum", "preload", "load", "super", "get", "set", "when", "void"]
|
|
9
9
|
var lines: PackedStringArray = []
|
|
10
10
|
var records: Array = []
|
|
11
11
|
var scanned_lines := 0
|
|
@@ -149,7 +149,7 @@ func scan(text: String, state: Dictionary, newline: bool = true) -> Dictionary:
|
|
|
149
149
|
elif kind == "code" and (ClassDB.class_exists(word) or word in state.declared or word in ["int","float","bool","String","Array","Dictionary","Vector2","Vector3","Color","Callable","StringName","NodePath"] or previous in [":","->","extends","class_name","class"]): kind = "type"
|
|
150
150
|
if previous in ["class_name","class"] or previous == "const" and text.substr(i).strip_edges().begins_with("= preload("):
|
|
151
151
|
if word not in state.declared: state.declared.append(word)
|
|
152
|
-
state.operand = word in Parser.OPERANDS
|
|
152
|
+
state.operand = word in Parser.OPERANDS or word in ["layout","const","var","export"]
|
|
153
153
|
elif token.kind == "number": kind = "number"; state.operand = false
|
|
154
154
|
else:
|
|
155
155
|
if word in ["(","[","{"]: state.depth += 1
|
|
@@ -365,7 +365,7 @@ func _apply(desired: Element, record: Mounted) -> void:
|
|
|
365
365
|
# do not turn omission into permanent native state or change other props.
|
|
366
366
|
if VisualStyle.supported(desired.type):
|
|
367
367
|
for key in record.properties:
|
|
368
|
-
if key in Length.BORDER_EDGES and not desired.properties.has(key):
|
|
368
|
+
if (key in Length.BORDER_EDGES or key in VisualStyle.RADII.slice(1)) and not desired.properties.has(key):
|
|
369
369
|
node.set(key,"auto")
|
|
370
370
|
writes += 1
|
|
371
371
|
if Profile.is_enabled(): Profile.add("property_writes")
|
|
@@ -587,10 +587,10 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
587
587
|
policy.merge(_spread_resets(desired,previous),true)
|
|
588
588
|
policy.merge(desired.properties,true)
|
|
589
589
|
var fixed := StackContract.preset(desired.type)
|
|
590
|
-
var direction = policy.get("direction",
|
|
590
|
+
var direction = policy.get("direction",StackContract.initial(desired.type))
|
|
591
591
|
for key in ["direction","horizontal_align","vertical_align","align_content"]:
|
|
592
|
-
var value = policy.get(key,direction if key=="direction" else "start")
|
|
593
|
-
var message := StackContract.error(key,value,str(direction),fixed)
|
|
592
|
+
var value = policy.get(key,direction if key=="direction" else ("stretch" if direction=="grid" and key in ["horizontal_align","vertical_align"] else "start"))
|
|
593
|
+
var message := StackContract.error(key,value,str(direction),fixed,StackContract.grid_capable(desired.type))
|
|
594
594
|
if not message.is_empty():
|
|
595
595
|
validation_error = desired.location(key)+": "+message+"; previous tree retained"
|
|
596
596
|
return false
|
|
@@ -600,6 +600,10 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
600
600
|
if desired.properties.has(key): return _invalid_attribute(desired,key,"read-only scrolling measurement")
|
|
601
601
|
if GridDefinition.marked(desired.type):
|
|
602
602
|
var config := _grid_config(desired)
|
|
603
|
+
var grid_active: bool = desired.properties.get("direction","grid")=="grid"
|
|
604
|
+
if not grid_active:
|
|
605
|
+
config.horizontal_align = "stretch"
|
|
606
|
+
config.vertical_align = "stretch"
|
|
603
607
|
var grid_matches := _matches(desired.children,previous.children if previous!=null and _compatible(desired,previous) else [])
|
|
604
608
|
var placements: Array = []
|
|
605
609
|
var grid_children: Array = []
|
|
@@ -618,7 +622,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
618
622
|
var borrowed: Node = child.borrowed.get_ref()
|
|
619
623
|
if not borrowed is Control and not (borrowed is Node2D and (Length.registered(borrowed.get_script(),"width") or GridDefinition.component(borrowed.get_script()))): return _invalid_attribute(child,"area","Grid borrowed child has no bounded 2D layout participant")
|
|
620
624
|
var native: String = child.type if child.type is String else (child.borrowed.get_ref().get_class() if child.borrowed!=null else child.type.get_instance_base_type())
|
|
621
|
-
if ClassDB.is_parent_class(native,"Control"):
|
|
625
|
+
if grid_active and ClassDB.is_parent_class(native,"Control"):
|
|
622
626
|
var values := {}
|
|
623
627
|
var old = grid_matches[desired.children.find(child)]
|
|
624
628
|
var existing = child.borrowed.get_ref() if child.borrowed!=null else (old.node.get_ref() if old!=null else null)
|
|
@@ -633,7 +637,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
633
637
|
return _invalid_attribute(child,field,message)
|
|
634
638
|
placements.append(child.placement)
|
|
635
639
|
grid_children.append(child)
|
|
636
|
-
var parsed := GridDefinition.configuration(config,placements)
|
|
640
|
+
var parsed := GridDefinition.configuration(config,placements if grid_active else [])
|
|
637
641
|
if parsed.has("error"):
|
|
638
642
|
var origin = grid_children[parsed.item] if parsed.has("item") else desired
|
|
639
643
|
var key: String = str(origin.placement.keys()[0]) if parsed.has("item") and not origin.placement.is_empty() else parsed.get("field","columns")
|
|
@@ -645,6 +649,9 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
|
|
|
645
649
|
var native: String = desired.type if desired.type is String else desired.type.get_instance_base_type()
|
|
646
650
|
if not properties.has(key) or not NativeAttributes.writable(native,desired.type,str(key),properties[key]): return _invalid_attribute(desired,str(key),"unknown, read-only or reserved native property")
|
|
647
651
|
var value = desired.properties[key]
|
|
652
|
+
if VisualStyle.supported(desired.type) and key in VisualStyle.SURFACE:
|
|
653
|
+
var message := VisualStyle.surface_error(key,value)
|
|
654
|
+
if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
|
|
648
655
|
if key=="align_self" and StackContract.self_registered(desired.type):
|
|
649
656
|
var message := StackContract.error(key,value,"")
|
|
650
657
|
if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
@tool
|
|
2
|
+
extends RefCounted
|
|
3
|
+
## Reusable description defaults, not Nodes. Evaluation occurs inside the caller's
|
|
4
|
+
## existing composition read scope. Native types/identity/commit remain authoritative.
|
|
5
|
+
const ESTRAGON_PRESET := true
|
|
6
|
+
const Definition = preload("../node/internal/grid_definition.gd")
|
|
7
|
+
const Element = preload("element.gd")
|
|
8
|
+
var base: Variant
|
|
9
|
+
var defaults: Callable
|
|
10
|
+
var generated: Dictionary
|
|
11
|
+
var source: String
|
|
12
|
+
func _init(component, values: Callable, supplied: Dictionary, location: String) -> void:
|
|
13
|
+
base = component
|
|
14
|
+
defaults = values
|
|
15
|
+
generated = supplied.duplicate(true)
|
|
16
|
+
source = location
|
|
17
|
+
static func _native(value) -> bool:
|
|
18
|
+
if not value is Script and not value is String: return false
|
|
19
|
+
var name: String = value if value is String else value.get_instance_base_type()
|
|
20
|
+
return ClassDB.class_exists(name) and ClassDB.is_parent_class(name,"Node") and ClassDB.can_instantiate(name)
|
|
21
|
+
static func type_of(value):
|
|
22
|
+
if _native(value): return value
|
|
23
|
+
if value is RefCounted and value.get_script()!=null and value.get_script().get_script_constant_map().get("ESTRAGON_PRESET",false): return type_of(value.base)
|
|
24
|
+
return "Node2D"
|
|
25
|
+
static func apply(value, element: Element) -> Element:
|
|
26
|
+
if _native(value):
|
|
27
|
+
element.type = value
|
|
28
|
+
return element
|
|
29
|
+
if not value is RefCounted or value.get_script()==null or not value.get_script().get_script_constant_map().get("ESTRAGON_PRESET",false):
|
|
30
|
+
element.attribute_error = element.source+": component preset requires a preset or native Script/class; previous tree retained"
|
|
31
|
+
return element
|
|
32
|
+
return value.describe(element)
|
|
33
|
+
func describe(instance: Element) -> Element:
|
|
34
|
+
var desired := Element.new()
|
|
35
|
+
desired.source = source
|
|
36
|
+
apply(base,desired)
|
|
37
|
+
if not desired.attribute_error.is_empty():
|
|
38
|
+
instance.attribute_error = desired.attribute_error
|
|
39
|
+
return instance
|
|
40
|
+
if not defaults.is_valid():
|
|
41
|
+
instance.attribute_error = source+": layout default scope is no longer valid; previous tree retained"
|
|
42
|
+
return instance
|
|
43
|
+
var merged := {}
|
|
44
|
+
var locations := {}
|
|
45
|
+
for group in defaults.call():
|
|
46
|
+
var expanded := Element.new(desired.type)
|
|
47
|
+
expanded.expand(group)
|
|
48
|
+
if not expanded.attribute_error.is_empty():
|
|
49
|
+
instance.attribute_error = expanded.attribute_error
|
|
50
|
+
return instance
|
|
51
|
+
var values: Dictionary = expanded.properties.duplicate()
|
|
52
|
+
values.merge(expanded.handlers)
|
|
53
|
+
for name in values:
|
|
54
|
+
if merged.has(name) and (typeof(merged[name])!=typeof(values[name]) or merged[name]!=values[name]):
|
|
55
|
+
instance.attribute_error = expanded.location(name)+": conflicting repeated layout default "+name+"; previous tree retained"
|
|
56
|
+
return instance
|
|
57
|
+
merged[name] = values[name]
|
|
58
|
+
locations[name] = expanded.location(name)
|
|
59
|
+
# Generated matrix/placement is a fallback. Explicit defaults and use-site
|
|
60
|
+
# properties override it; named areas are logical metadata, never Node fields.
|
|
61
|
+
var values := generated.duplicate(true)
|
|
62
|
+
values.merge(merged,true)
|
|
63
|
+
if generated.has("areas") and merged.has("template") and merged.template is String and not merged.template.is_empty():
|
|
64
|
+
var parsed := Definition.template(merged.template)
|
|
65
|
+
if parsed.has("error") or parsed.areas!=generated.areas:
|
|
66
|
+
instance.attribute_error = locations.get("template",source)+": layout template must retain the declared area matrix; previous tree retained"
|
|
67
|
+
return instance
|
|
68
|
+
for name in ["columns","rows","areas"]:
|
|
69
|
+
if not merged.has(name): values[name] = null if name!="areas" else []
|
|
70
|
+
var ordered: Array = []
|
|
71
|
+
for name in values:
|
|
72
|
+
if name=="area":
|
|
73
|
+
desired.placement.area = values[name]
|
|
74
|
+
continue
|
|
75
|
+
ordered.append([name,values[name],locations.get(name,source)])
|
|
76
|
+
desired.expand(ordered)
|
|
77
|
+
desired.properties.merge(instance.properties,true)
|
|
78
|
+
# A caller template replaces the preset structured defaults as one native
|
|
79
|
+
# config. Explicit conflicting call-site tracks still fail normal preflight.
|
|
80
|
+
if Definition.marked(desired.type) and instance.properties.get("template",null) is String and not instance.properties.template.is_empty():
|
|
81
|
+
for name in ["columns","rows","areas"]:
|
|
82
|
+
if not instance.properties.has(name): desired.properties[name] = null if name!="areas" else []
|
|
83
|
+
if Definition.marked(desired.type):
|
|
84
|
+
var mode = desired.properties.get("direction","grid")
|
|
85
|
+
if mode in ["row","column"]:
|
|
86
|
+
var main := "horizontal_align" if mode=="row" else "vertical_align"
|
|
87
|
+
if not desired.properties.has(main): desired.properties[main] = "start"
|
|
88
|
+
desired.handlers.merge(instance.handlers,true)
|
|
89
|
+
desired.origins.merge(instance.origins,true)
|
|
90
|
+
desired.spread_properties.merge(instance.spread_properties,true)
|
|
91
|
+
# Defaults from spreads must reset through the existing retained removal path.
|
|
92
|
+
for name in values:
|
|
93
|
+
if name!="area" and not instance.properties.has(name): desired.spread_properties[name] = true
|
|
94
|
+
instance.type = desired.type
|
|
95
|
+
instance.properties = desired.properties
|
|
96
|
+
instance.handlers = desired.handlers
|
|
97
|
+
instance.origins = desired.origins
|
|
98
|
+
instance.spread_properties = desired.spread_properties
|
|
99
|
+
desired.placement.merge(instance.placement,true)
|
|
100
|
+
instance.placement = desired.placement
|
|
101
|
+
return instance
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://cnb0ee1nikf73
|
|
@@ -19,16 +19,23 @@ const ESTRAGON_STACK_POLICY := true
|
|
|
19
19
|
_changed()
|
|
20
20
|
var _policy_commit := false
|
|
21
21
|
const StackContract = preload("internal/stack_contract.gd")
|
|
22
|
-
@export_enum("row", "column") var direction: String = "row":
|
|
22
|
+
@export_enum("row", "column", "grid") var direction: String = "row":
|
|
23
23
|
set(value):
|
|
24
24
|
if value==direction: return
|
|
25
25
|
if _policy_commit:
|
|
26
26
|
direction = value
|
|
27
27
|
return
|
|
28
|
-
|
|
28
|
+
# Grid's default stretch becomes a legal main-axis start on mode change.
|
|
29
|
+
# Track/area/template values remain untouched and can be restored.
|
|
30
|
+
if direction=="grid" and value in ["row","column"] and StackContract.grid_capable(get_script()):
|
|
31
|
+
_policy_commit = true
|
|
32
|
+
if value=="row" and horizontal_align=="stretch": horizontal_align = "start"
|
|
33
|
+
if value=="column" and vertical_align=="stretch": vertical_align = "start"
|
|
34
|
+
_policy_commit = false
|
|
35
|
+
var message := StackContract.error("direction",value,value,StackContract.preset(get_script()),StackContract.grid_capable(get_script()))
|
|
29
36
|
if message.is_empty():
|
|
30
|
-
message = StackContract.error("horizontal_align",horizontal_align,value)
|
|
31
|
-
if message.is_empty(): message = StackContract.error("vertical_align",vertical_align,value)
|
|
37
|
+
message = StackContract.error("horizontal_align",horizontal_align,value,"",StackContract.grid_capable(get_script()))
|
|
38
|
+
if message.is_empty(): message = StackContract.error("vertical_align",vertical_align,value,"",StackContract.grid_capable(get_script()))
|
|
32
39
|
if not message.is_empty():
|
|
33
40
|
push_error("Estragon Box: "+message)
|
|
34
41
|
return
|
|
@@ -60,7 +67,7 @@ func _apply_stack_policy(values: Dictionary) -> void:
|
|
|
60
67
|
_policy_commit = false
|
|
61
68
|
if before!=[direction,horizontal_align,vertical_align]: _changed()
|
|
62
69
|
func _valid_alignment(property: String, value) -> bool:
|
|
63
|
-
var message := StackContract.error(property,value,"
|
|
70
|
+
var message := StackContract.error(property,value,direction,"",StackContract.grid_capable(get_script()))
|
|
64
71
|
if not message.is_empty(): push_error("Estragon Box: "+message)
|
|
65
72
|
return message.is_empty()
|
|
66
73
|
func _layout_axis() -> int:
|
|
@@ -4,23 +4,23 @@ extends "text.gd"
|
|
|
4
4
|
## Native primary-pointer button. No Control widget or polling wrapper.
|
|
5
5
|
signal pressed
|
|
6
6
|
const ESTRAGON_BUTTON_STYLE := true
|
|
7
|
-
var hover_background_color: Variant = Color("#
|
|
7
|
+
var hover_background_color: Variant = Color("#505050"):
|
|
8
8
|
set(value):
|
|
9
9
|
if is_same(hover_background_color,value) or not _visual_style.assign("hover_background_color",value): return
|
|
10
10
|
hover_background_color = value
|
|
11
11
|
_queue_style_redraw()
|
|
12
|
-
var pressed_background_color: Variant = Color("#
|
|
12
|
+
var pressed_background_color: Variant = Color("#252525"):
|
|
13
13
|
set(value):
|
|
14
14
|
if is_same(pressed_background_color,value) or not _visual_style.assign("pressed_background_color",value): return
|
|
15
15
|
pressed_background_color = value
|
|
16
16
|
_queue_style_redraw()
|
|
17
|
-
var disabled_background_color: Variant = Color("#
|
|
17
|
+
var disabled_background_color: Variant = Color("#303030"):
|
|
18
18
|
set(value):
|
|
19
19
|
if is_same(disabled_background_color,value) or not _visual_style.assign("disabled_background_color",value): return
|
|
20
20
|
disabled_background_color = value
|
|
21
21
|
_queue_style_redraw()
|
|
22
22
|
func _init() -> void:
|
|
23
|
-
background_color = Color("#
|
|
23
|
+
background_color = Color("#383838")
|
|
24
24
|
padding = "auto"
|
|
25
25
|
func _default_padding() -> Vector4:
|
|
26
26
|
return Vector4(14,8,14,8)
|