From 2b1947dc2fb7b8a8d7f60a85458147e790e9b74f Mon Sep 17 00:00:00 2001 From: Nimaoth Date: Tue, 19 Dec 2023 18:03:26 +0100 Subject: [PATCH] more work on new cell builder language --- model/cell-builder.ast-model | 1 + model/playground.ast-project | 3 +- model/test-language.ast-model | 2 +- scripting/absytree_internal.nim | 2 +- scripting/absytree_internal_wasm.nim | 2 +- scripting/editor_model_api.nim | 4 +- scripting/editor_model_api_wasm.nim | 8 +- src/ast/base_language.nim | 419 ++++++++------------------- src/ast/cells.nim | 4 +- src/ast/editor_language.nim | 2 +- src/ast/lang/cell_language.nim | 81 ++++++ src/ast/lang/lang_language.nim | 60 ++-- src/ast/model.nim | 60 +++- src/ast_ids.nim | 26 +- src/model_document.nim | 100 ++++--- 15 files changed, 383 insertions(+), 391 deletions(-) create mode 100644 model/cell-builder.ast-model create mode 100644 src/ast/lang/cell_language.nim diff --git a/model/cell-builder.ast-model b/model/cell-builder.ast-model new file mode 100644 index 00000000..89e0aec0 --- /dev/null +++ b/model/cell-builder.ast-model @@ -0,0 +1 @@ +{"id":"82ffffff9afd1f08150838c9","languages":["654fbb281446e19b3822523f"],"models":[],"rootNodes":[{"id":"82ffffff9afd1f08150838f2","class":"654fbb281446e19b3822524f","children":[["654fbb281446e19b38225250",[{"id":"82ffffff9afd1f08150838f7","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","CellBuilderDefinition"],["654fbb281446e19b38225238",""],["654fbb281446e19b38225236",false],["654fbb281446e19b38225239",false],["654fbb281446e19b38225248",false],["654fbb281446e19b3822524b",true],["654fbb281446e19b3822524a",0]],"children":[["654fbb281446e19b38225237",[{"id":"82ffffff0cfb77255e939d0f","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","654fbb281446e19b38225251"]]}]],["654fbb281446e19b3822523a",[]],["654fbb281446e19b3822522b",[]],["654fbb281446e19b3822522c",[{"id":"82ffffff0cfb77255e939d35","class":"654fbb281446e19b38225230","properties":[["62e5339c564d29f772934529","class"]],"children":[["654fbb281446e19b38225231",[{"id":"82ffffff0cfb77255e939d70","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","654fbb281446e19b3822522a"]]}]]]}]],["654fbb281446e19b3822522d",[{"id":"82ffffffb1fee44425c76425","class":"654fbb281446e19b38225233","properties":[["62e5339c564d29f772934529","cell definitions"]],"children":[["654fbb281446e19b38225234",[{"id":"82ffffffb1fee44425c76426","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","82ffffffeb36250369ecc38d"]]}]],["654fbb281446e19b38225235",[{"id":"82ffffffb1fee44425c76656","class":"654fbb281446e19b38225245"}]]]}]],["654fbb281446e19b38225249",[]]]},{"id":"82ffffffeb36250369ecc38d","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","CellDefinition"],["654fbb281446e19b38225238",""],["654fbb281446e19b38225236",true],["654fbb281446e19b38225239",false],["654fbb281446e19b38225248",false],["654fbb281446e19b3822524b",false],["654fbb281446e19b3822524a",0]],"children":[["654fbb281446e19b38225237",[]],["654fbb281446e19b3822523a",[]],["654fbb281446e19b3822522b",[]],["654fbb281446e19b3822522c",[]],["654fbb281446e19b3822522d",[]],["654fbb281446e19b38225249",[]]]},{"id":"82ffffffeb36250369ecc453","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","CollectionCellDefinition"],["654fbb281446e19b38225238",""],["654fbb281446e19b38225236",true],["654fbb281446e19b38225239",false],["654fbb281446e19b38225248",false],["654fbb281446e19b3822524b",false],["654fbb281446e19b3822524a",0]],"children":[["654fbb281446e19b38225237",[{"id":"82ffffffeb36250369ecc514","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","82ffffffeb36250369ecc38d"]]}]],["654fbb281446e19b3822523a",[]],["654fbb281446e19b3822522b",[]],["654fbb281446e19b3822522c",[]],["654fbb281446e19b3822522d",[{"id":"82ffffffb1fee44425c74de5","class":"654fbb281446e19b38225233","properties":[["62e5339c564d29f772934529","children"]],"children":[["654fbb281446e19b38225234",[{"id":"82ffffffb1fee44425c74de6","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","82ffffffeb36250369ecc38d"]]}]],["654fbb281446e19b38225235",[{"id":"82ffffffb1fee44425c7506b","class":"654fbb281446e19b38225246"}]]]}]],["654fbb281446e19b38225249",[]]]},{"id":"82ffffffeb36250369ecc6f4","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","HorizontalCellDefinition"],["654fbb281446e19b38225238","horizontal"],["654fbb281446e19b38225236",false],["654fbb281446e19b38225239",false],["654fbb281446e19b38225248",false],["654fbb281446e19b3822524b",false],["654fbb281446e19b3822524a",0]],"children":[["654fbb281446e19b38225237",[{"id":"82ffffffeb36250369ecc7e4","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","82ffffffeb36250369ecc453"]]}]],["654fbb281446e19b3822523a",[]],["654fbb281446e19b3822522b",[]],["654fbb281446e19b3822522c",[]],["654fbb281446e19b3822522d",[]],["654fbb281446e19b38225249",[]]]},{"id":"82ffffff65d17c4d369b48fc","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","VerticalCellDefinition"],["654fbb281446e19b38225238","vertical"],["654fbb281446e19b38225236",false],["654fbb281446e19b38225239",false],["654fbb281446e19b38225248",false],["654fbb281446e19b3822524b",false],["654fbb281446e19b3822524a",0]],"children":[["654fbb281446e19b38225237",[{"id":"82ffffff65d17c4d369b48fd","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","82ffffffeb36250369ecc453"]]}]],["654fbb281446e19b3822523a",[]],["654fbb281446e19b3822522b",[]],["654fbb281446e19b3822522c",[]],["654fbb281446e19b3822522d",[]],["654fbb281446e19b38225249",[]]]},{"id":"82ffffffb1fee44425c73d48","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","ConstantCellDefinition"],["654fbb281446e19b38225238",""],["654fbb281446e19b38225236",false],["654fbb281446e19b38225239",false],["654fbb281446e19b38225248",false],["654fbb281446e19b3822524b",false],["654fbb281446e19b3822524a",0]],"children":[["654fbb281446e19b38225237",[{"id":"82ffffffb1fee44425c73e75","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","82ffffffeb36250369ecc38d"]]}]],["654fbb281446e19b3822523a",[]],["654fbb281446e19b3822522b",[{"id":"82ffffffb1fee44425c74b10","class":"654fbb281446e19b3822522e","properties":[["62e5339c564d29f772934529","text"]],"children":[["654fbb281446e19b3822522f",[{"id":"82ffffffb1fee44425c74c96","class":"654fbb281446e19b3822523d"}]]]}]],["654fbb281446e19b3822522c",[]],["654fbb281446e19b3822522d",[]],["654fbb281446e19b38225249",[]]]},{"id":"82ffffffb1fee44425c74037","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","PropertyCellDefinition"],["654fbb281446e19b38225238",""],["654fbb281446e19b38225236",false],["654fbb281446e19b38225239",false],["654fbb281446e19b38225248",false],["654fbb281446e19b3822524b",false],["654fbb281446e19b3822524a",0]],"children":[["654fbb281446e19b38225237",[{"id":"82ffffffb1fee44425c74192","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","82ffffffeb36250369ecc38d"]]}]],["654fbb281446e19b3822523a",[]],["654fbb281446e19b3822522b",[]],["654fbb281446e19b3822522c",[]],["654fbb281446e19b3822522d",[]],["654fbb281446e19b38225249",[]]]},{"id":"82ffffffb1fee44425c74370","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","ReferenceCellDefinition"],["654fbb281446e19b38225238",""],["654fbb281446e19b38225236",false],["654fbb281446e19b38225239",false],["654fbb281446e19b38225248",false],["654fbb281446e19b3822524b",false],["654fbb281446e19b3822524a",0]],"children":[["654fbb281446e19b38225237",[{"id":"82ffffffb1fee44425c744e6","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","82ffffffeb36250369ecc38d"]]}]],["654fbb281446e19b3822523a",[]],["654fbb281446e19b3822522b",[]],["654fbb281446e19b3822522c",[]],["654fbb281446e19b3822522d",[]],["654fbb281446e19b38225249",[]]]},{"id":"82ffffffb1fee44425c7489e","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","ChildrenCellDefinition"],["654fbb281446e19b38225238",""],["654fbb281446e19b38225236",false],["654fbb281446e19b38225239",false],["654fbb281446e19b38225248",false],["654fbb281446e19b3822524b",false],["654fbb281446e19b3822524a",0]],"children":[["654fbb281446e19b38225237",[{"id":"82ffffffb1fee44425c749cc","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","82ffffffeb36250369ecc38d"]]}]],["654fbb281446e19b3822523a",[]],["654fbb281446e19b3822522b",[]],["654fbb281446e19b3822522c",[]],["654fbb281446e19b3822522d",[]],["654fbb281446e19b38225249",[]]]}]]]}]} \ No newline at end of file diff --git a/model/playground.ast-project b/model/playground.ast-project index ca8fe516..cd840fae 100644 --- a/model/playground.ast-project +++ b/model/playground.ast-project @@ -1,7 +1,8 @@ { "models": { "model/array.ast-model": "654fbb281446e19b38225265", - "test-language.ast-model": "654fbb281446e19b38225240", + "model/test-language.ast-model": "654fbb281446e19b38225240", + "model/cell-builder.ast-model": "82ffffff9afd1f08150838c9", "model/a.ast-model": "083671ebb3cd003f6c8faaf3", "model/aoc_day1.ast-model": "656f7f67d077504f640d8727", "model/aoc_day2.ast-model": "656f7f67d077504f640d8728", diff --git a/model/test-language.ast-model b/model/test-language.ast-model index 022fe2d1..63fd4ca1 100644 --- a/model/test-language.ast-model +++ b/model/test-language.ast-model @@ -1 +1 @@ -{"id":"654fbb281446e19b38225240","languages":["654fbb281446e19b3822523f"],"models":[],"rootNodes":[{"id":"654fbb281446e19b38225264","class":"654fbb281446e19b3822524f","children":[["654fbb281446e19b38225250",[{"id":"21b0810be06ab5607dd26759","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","CellBuilder"],["654fbb281446e19b38225238",""],["654fbb281446e19b38225236",false],["654fbb281446e19b38225239",false],["654fbb281446e19b38225248",false],["654fbb281446e19b3822524b",false],["654fbb281446e19b3822524a",0]],"children":[["654fbb281446e19b38225237",[]],["654fbb281446e19b3822523a",[]],["654fbb281446e19b3822522b",[]],["654fbb281446e19b3822522c",[]],["654fbb281446e19b3822522d",[{"id":"21b1b4d2382ec64408d523eb","class":"654fbb281446e19b38225233","properties":[["62e5339c564d29f772934529","targetClass"]],"children":[["654fbb281446e19b38225234",[{"id":"21b1b4d2382ec64408d523ec","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]}]],["654fbb281446e19b38225235",[{"id":"21b3fe38dade85465522ed18","class":"654fbb281446e19b38225245"}]]]}]],["654fbb281446e19b38225249",[]]]},{"id":"1c3ba37d1073b1226b9ee06b","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","Expression"],["654fbb281446e19b38225238","hello"],["654fbb281446e19b38225236",true],["654fbb281446e19b38225239",true],["654fbb281446e19b38225248",true],["654fbb281446e19b3822524b",true],["654fbb281446e19b3822524a",10]],"children":[["654fbb281446e19b38225237",[{"id":"1c73943084dd113e5b791530","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]}]],["654fbb281446e19b3822523a",[{"id":"1c7380ef84dd113e5b791405","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]},{"id":"1c73833184dd113e5b791440","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]}]],["654fbb281446e19b3822522b",[{"id":"1c3c25ef1073b1226b9ee0a6","class":"654fbb281446e19b3822522e","properties":[["62e5339c564d29f772934529","left"]],"children":[["654fbb281446e19b3822522f",[{"id":"1c744ac74dff7403658c5044","class":"654fbb281446e19b3822523c"}]]]},{"id":"1c3c47f11073b1226b9ee115","class":"654fbb281446e19b3822522e","properties":[["62e5339c564d29f772934529","right"]],"children":[["654fbb281446e19b3822522f",[{"id":"1c74514f4dff7403658c5081","class":"654fbb281446e19b3822523d"}]]]},{"id":"1c401636e2172031051e796a","class":"654fbb281446e19b3822522e","properties":[["62e5339c564d29f772934529","top"]],"children":[["654fbb281446e19b3822522f",[{"id":"1c7458c74dff7403658c50be","class":"654fbb281446e19b3822523e"}]]]}]],["654fbb281446e19b3822522c",[{"id":"1c45bbd9e60b0d1352276921","class":"654fbb281446e19b38225230","properties":[["62e5339c564d29f772934529","xvlc"]],"children":[["654fbb281446e19b38225231",[{"id":"1c45bbd9e60b0d1352276922","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]}]]]}]],["654fbb281446e19b3822522d",[{"id":"1c457f81e60b0d13522767f5","class":"654fbb281446e19b38225233","properties":[["62e5339c564d29f772934529","uiae"]],"children":[["654fbb281446e19b38225234",[{"id":"1c457f81e60b0d13522767f6","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]}]],["654fbb281446e19b38225235",[{"id":"1c7375e884dd113e5b7913ca","class":"654fbb281446e19b38225247"}]]]}]],["654fbb281446e19b38225249",[{"id":"2175d5b6f19f3b424661c6a8","class":"654fbb281446e19b3822524d","references":[["654fbb281446e19b3822524e","1c3c25ef1073b1226b9ee0a6"]]}]]]}]]]}]} \ No newline at end of file +{"id":"654fbb281446e19b38225240","languages":["654fbb281446e19b3822523f","82ffffff9afd1f08150838c9"],"models":["82ffffff9afd1f08150838c9"],"rootNodes":[{"id":"654fbb281446e19b38225264","class":"654fbb281446e19b3822524f","children":[["654fbb281446e19b38225250",[{"id":"21b0810be06ab5607dd26759","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","CellBuilder"],["654fbb281446e19b38225238",""],["654fbb281446e19b38225236",false],["654fbb281446e19b38225239",false],["654fbb281446e19b38225248",false],["654fbb281446e19b3822524b",false],["654fbb281446e19b3822524a",0]],"children":[["654fbb281446e19b38225237",[]],["654fbb281446e19b3822523a",[]],["654fbb281446e19b3822522b",[]],["654fbb281446e19b3822522c",[]],["654fbb281446e19b3822522d",[{"id":"21b1b4d2382ec64408d523eb","class":"654fbb281446e19b38225233","properties":[["62e5339c564d29f772934529","targetClass"]],"children":[["654fbb281446e19b38225234",[{"id":"21b1b4d2382ec64408d523ec","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]}]],["654fbb281446e19b38225235",[{"id":"21b3fe38dade85465522ed18","class":"654fbb281446e19b38225245"}]]]}]],["654fbb281446e19b38225249",[]]]},{"id":"1c3ba37d1073b1226b9ee06b","class":"654fbb281446e19b3822522a","properties":[["62e5339c564d29f772934529","Expression"],["654fbb281446e19b38225238","hello"],["654fbb281446e19b38225236",true],["654fbb281446e19b38225239",true],["654fbb281446e19b38225248",true],["654fbb281446e19b3822524b",true],["654fbb281446e19b3822524a",10]],"children":[["654fbb281446e19b38225237",[{"id":"1c73943084dd113e5b791530","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]}]],["654fbb281446e19b3822523a",[{"id":"1c7380ef84dd113e5b791405","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]},{"id":"1c73833184dd113e5b791440","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]}]],["654fbb281446e19b3822522b",[{"id":"1c3c25ef1073b1226b9ee0a6","class":"654fbb281446e19b3822522e","properties":[["62e5339c564d29f772934529","left"]],"children":[["654fbb281446e19b3822522f",[{"id":"1c744ac74dff7403658c5044","class":"654fbb281446e19b3822523c"}]]]},{"id":"1c3c47f11073b1226b9ee115","class":"654fbb281446e19b3822522e","properties":[["62e5339c564d29f772934529","right"]],"children":[["654fbb281446e19b3822522f",[{"id":"1c74514f4dff7403658c5081","class":"654fbb281446e19b3822523d"}]]]},{"id":"1c401636e2172031051e796a","class":"654fbb281446e19b3822522e","properties":[["62e5339c564d29f772934529","top"]],"children":[["654fbb281446e19b3822522f",[{"id":"1c7458c74dff7403658c50be","class":"654fbb281446e19b3822523e"}]]]}]],["654fbb281446e19b3822522c",[{"id":"1c45bbd9e60b0d1352276921","class":"654fbb281446e19b38225230","properties":[["62e5339c564d29f772934529","xvlc"]],"children":[["654fbb281446e19b38225231",[{"id":"1c45bbd9e60b0d1352276922","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]}]]]}]],["654fbb281446e19b3822522d",[{"id":"1c457f81e60b0d13522767f5","class":"654fbb281446e19b38225233","properties":[["62e5339c564d29f772934529","uiae"]],"children":[["654fbb281446e19b38225234",[{"id":"1c457f81e60b0d13522767f6","class":"654fbb281446e19b38225241","references":[["654fbb281446e19b38225242","1c3ba37d1073b1226b9ee06b"]]}]],["654fbb281446e19b38225235",[{"id":"1c7375e884dd113e5b7913ca","class":"654fbb281446e19b38225247"}]]]}]],["654fbb281446e19b38225249",[{"id":"2175d5b6f19f3b424661c6a8","class":"654fbb281446e19b3822524d","references":[["654fbb281446e19b3822524e","1c3c25ef1073b1226b9ee0a6"]]}]]]},{"id":"82ffffffdcf66d5b1112ec2b","class":"82ffffff9afd1f08150838f7","references":[["82ffffff0cfb77255e939d35","82ffffffeb36250369ecc6f4"]],"children":[["82ffffffb1fee44425c76425",[{"id":"82ffffffdcf66d5b1112ed6d","class":"82ffffffeb36250369ecc6f4","children":[["82ffffffb1fee44425c74de5",[]]]}]]]},{"id":"82ffffff204e313a6e5a9a44","class":"82ffffff9afd1f08150838f7","references":[["82ffffff0cfb77255e939d35","1c3ba37d1073b1226b9ee06b"]],"children":[["82ffffffb1fee44425c76425",[{"id":"82ffffff114a9324634116d4","class":"82ffffffeb36250369ecc6f4","children":[["82ffffffb1fee44425c74de5",[]]]}]]]},{"id":"82ffffff0aa7220c52c3c3e1","class":"82ffffff9afd1f08150838f7","references":[["82ffffff0cfb77255e939d35","21b0810be06ab5607dd26759"]],"children":[["82ffffffb1fee44425c76425",[{"id":"82ffffff0aa7220c52c3c467","class":"82ffffff65d17c4d369b48fc","children":[["82ffffffb1fee44425c74de5",[]]]}]]]}]]]}]} \ No newline at end of file diff --git a/scripting/absytree_internal.nim b/scripting/absytree_internal.nim index c95c966e..a9e49ea8 100644 --- a/scripting/absytree_internal.nim +++ b/scripting/absytree_internal.nim @@ -444,7 +444,7 @@ proc editor_model_addRootNode_void_ModelDocumentEditor_impl*( proc editor_model_saveProject_void_ModelDocumentEditor_impl*( self: ModelDocumentEditor) = discard -proc editor_model_loadBaseLanguageModel_void_ModelDocumentEditor_impl*( +proc editor_model_loadLanguageModel_void_ModelDocumentEditor_impl*( self: ModelDocumentEditor) = discard proc editor_model_findDeclaration_void_ModelDocumentEditor_bool_impl*( diff --git a/scripting/absytree_internal_wasm.nim b/scripting/absytree_internal_wasm.nim index 81f5bd11..63fa8867 100644 --- a/scripting/absytree_internal_wasm.nim +++ b/scripting/absytree_internal_wasm.nim @@ -297,7 +297,7 @@ proc editor_model_addRootNode_void_ModelDocumentEditor_impl( self: ModelDocumentEditor) {.importc.} proc editor_model_saveProject_void_ModelDocumentEditor_impl( self: ModelDocumentEditor) {.importc.} -proc editor_model_loadBaseLanguageModel_void_ModelDocumentEditor_impl( +proc editor_model_loadLanguageModel_void_ModelDocumentEditor_impl( self: ModelDocumentEditor) {.importc.} proc editor_model_findDeclaration_void_ModelDocumentEditor_bool_impl( self: ModelDocumentEditor; global: bool) {.importc.} diff --git a/scripting/editor_model_api.nim b/scripting/editor_model_api.nim index 3a6caed9..b324ed4b 100644 --- a/scripting/editor_model_api.nim +++ b/scripting/editor_model_api.nim @@ -149,7 +149,7 @@ proc addRootNode*(self: ModelDocumentEditor) = editor_model_addRootNode_void_ModelDocumentEditor_impl(self) proc saveProject*(self: ModelDocumentEditor) = editor_model_saveProject_void_ModelDocumentEditor_impl(self) -proc loadBaseLanguageModel*(self: ModelDocumentEditor) = - editor_model_loadBaseLanguageModel_void_ModelDocumentEditor_impl(self) +proc loadLanguageModel*(self: ModelDocumentEditor) = + editor_model_loadLanguageModel_void_ModelDocumentEditor_impl(self) proc findDeclaration*(self: ModelDocumentEditor; global: bool) = editor_model_findDeclaration_void_ModelDocumentEditor_bool_impl(self, global) diff --git a/scripting/editor_model_api_wasm.nim b/scripting/editor_model_api_wasm.nim index a71ce981..7055813b 100644 --- a/scripting/editor_model_api_wasm.nim +++ b/scripting/editor_model_api_wasm.nim @@ -1009,9 +1009,9 @@ proc saveProject*(self: ModelDocumentEditor) = argsJsonString.cstring) -proc editor_model_loadBaseLanguageModel_void_ModelDocumentEditor_wasm( - arg: cstring): cstring {.importc.} -proc loadBaseLanguageModel*(self: ModelDocumentEditor) = +proc editor_model_loadLanguageModel_void_ModelDocumentEditor_wasm(arg: cstring): cstring {. + importc.} +proc loadLanguageModel*(self: ModelDocumentEditor) = var argsJson = newJArray() argsJson.add block: when ModelDocumentEditor is JsonNode: @@ -1019,7 +1019,7 @@ proc loadBaseLanguageModel*(self: ModelDocumentEditor) = else: self.toJson() let argsJsonString = $argsJson - let res {.used.} = editor_model_loadBaseLanguageModel_void_ModelDocumentEditor_wasm( + let res {.used.} = editor_model_loadLanguageModel_void_ModelDocumentEditor_wasm( argsJsonString.cstring) diff --git a/src/ast/base_language.nim b/src/ast/base_language.nim index 329b9764..34d60e00 100644 --- a/src/ast/base_language.nim +++ b/src/ast/base_language.nim @@ -437,165 +437,119 @@ builder.addBuilderFor functionDefinitionClass.id, idNone(), proc(builder: CellBu return cell -builder.addBuilderFor structMemberDefinitionClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - proc isVisible(node: AstNode): bool = node.hasChild(IdStructMemberDefinitionValue) - - cell.add PropertyCell(node: owner ?? node, referenceNode: node, property: IdINamedName) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ":", style: CellStyle(noSpaceLeft: true), themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdStructMemberDefinitionType, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "=", themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - cell.add block: - buildChildrenT(builder, map, node, owner, IdStructMemberDefinitionValue, &{LayoutHorizontal}, 0.CellFlags): - placeholder: PlaceholderCell(id: newId().CellId, node: owner ?? node, referenceNode: node, role: role, shadowText: "...") - return cell - -builder.addBuilderFor structParameterClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add PropertyCell(node: owner ?? node, referenceNode: node, property: IdINamedName) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ":", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - cell.add block: - buildChildrenT(builder, map, node, owner, IdStructParameterType, &{LayoutHorizontal}, 0.CellFlags): - placeholder: PlaceholderCell(id: newId().CellId, node: owner ?? node, referenceNode: node, role: role, shadowText: "") - - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "=", themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - cell.add block: - buildChildrenT(builder, map, node, owner, IdStructParameterValue, &{LayoutHorizontal}, 0.CellFlags): - placeholder: PlaceholderCell(id: newId().CellId, node: owner ?? node, referenceNode: node, role: role, shadowText: "") - return cell - -builder.addBuilderFor structDefinitionClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "struct", themeForegroundColors: @["keyword"], disableEditing: true) - - cell.add block: - buildChildrenT(builder, map, node, owner, IdStructDefinitionParameter, &{LayoutHorizontal}, 0.CellFlags): - separator: ConstantCell(node: owner ?? node, referenceNode: node, text: ",", style: CellStyle(noSpaceLeft: true), themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true, disableSelection: true, deleteNeighbor: true) - placeholder: "" - - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "{", themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - - cell.add block: - buildChildrenT(builder, map, node, owner, IdStructDefinitionMembers, &{LayoutVertical}, &{OnNewLine, IndentChildren}): - placeholder: "..." - - let hasChildren = node.childCount(IdStructDefinitionMembers) > 0 - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "}", themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true, flags: hasChildren ?? OnNewLine) - - return cell - -builder.addBuilderFor structMemberAccessClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add block: - buildChildrenT(builder, map, node, owner, IdStructMemberAccessValue, &{LayoutHorizontal}, 0.CellFlags): - placeholder: "..." - - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ".", themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true, flags: &{NoSpaceLeft, NoSpaceRight}) - - cell.add block: - if node.resolveReference(IdStructMemberAccessMember).getSome(targetNode): - # var refCell = NodeReferenceCell(id: newId().CellId, node: owner ?? node, referenceNode: node, reference: IdStructMemberAccessMember, property: IdINamedName, disableEditing: true) - PropertyCell(id: newId().CellId, node: owner ?? node, referenceNode: targetNode, property: IdINamedName, themeForegroundColors: @["variable", "&editor.foreground"], disableEditing: true) - else: - PlaceholderCell(id: newId().CellId, node: owner ?? node, referenceNode: node, role: IdStructMemberAccessMember, shadowText: "_") - - return cell +builder.addBuilderFor IdStructMemberDefinition, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: PropertyCell, propertyRole: IdINamedName), + CellBuilderCommand(kind: ConstantCell, text: ":", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdStructMemberDefinitionType, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "=", themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdStructMemberDefinitionValue, uiFlags: &{LayoutHorizontal}), +] -builder.addBuilderFor pointerTypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "ptr", themeForegroundColors: @["keyword"], disableEditing: true) - # todo: build target cell - # cell.add builder.buildChildren(map, node, owner, IdPointerTypeTarget, &{LayoutHorizontal}) - return cell +builder.addBuilderFor IdStructParameter, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: PropertyCell, propertyRole: IdINamedName), + CellBuilderCommand(kind: ConstantCell, text: ":", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdStructParameterType, placeholder: "".some, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "=", themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdStructParameterValue, uiFlags: &{LayoutHorizontal}), +] -builder.addBuilderFor pointerTypeDeclClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "ptr", themeForegroundColors: @["keyword"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdPointerTypeDeclTarget, &{LayoutHorizontal}) - return cell +builder.addBuilderFor IdStructDefinition, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "struct", themeForegroundColors: @["keyword"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdStructDefinitionParameter, separator: ",".some, placeholder: "".some, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "{", themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdStructDefinitionMembers, uiFlags: &{LayoutVertical}, flags: &{OnNewLine, IndentChildren}), + CellBuilderCommand(kind: ConstantCell, text: "}", themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true, flags: &{OnNewLine}), +] -builder.addBuilderFor addressOfClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add builder.buildChildren(map, node, owner, IdAddressOfValue, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ".addr", flags: &{NoSpaceLeft}, themeForegroundColors: @["keyword"], disableEditing: true) - return cell +builder.addBuilderFor IdStructMemberAccess, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: Children, childrenRole: IdStructMemberAccessValue, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: ".", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: ReferenceCell, referenceRole: IdStructMemberAccessMember, targetProperty: IdINamedName.some, themeForegroundColors: @["variable", "&editor.foreground"], disableEditing: true), +] -builder.addBuilderFor derefClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add builder.buildChildren(map, node, owner, IdDerefValue, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ".deref", flags: &{NoSpaceLeft}, themeForegroundColors: @["keyword"], disableEditing: true) - return cell +# builder.addBuilderFor pointerTypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = +# var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) +# cell.fillChildren = proc(map: NodeCellMap) = +# cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "ptr", themeForegroundColors: @["keyword"], disableEditing: true) +# # todo: build target cell +# # cell.add builder.buildChildren(map, node, owner, IdPointerTypeTarget, &{LayoutHorizontal}) +# return cell -builder.addBuilderFor castClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add builder.buildChildren(map, node, owner, IdCastValue, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ".", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation"], disableEditing: true) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "as", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["keyword"], disableEditing: true) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "(", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdCastType, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ")", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation"], disableEditing: true) - return cell +builder.addBuilderFor IdPointerType, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "ptr", themeForegroundColors: @["keyword"], disableEditing: true), + # CellBuilderCommand(kind: ReferenceCell, referenceRole: IdPointerTypeTarget, themeForegroundColors: @["variable", "&editor.foreground"], disableEditing: true), +] -builder.addBuilderFor stringGetPointerClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add builder.buildChildren(map, node, owner, IdStringGetPointerValue, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ".", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation"], disableEditing: true) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "ptr", themeForegroundColors: @["keyword"], disableEditing: true) - return cell +builder.addBuilderFor IdPointerTypeDecl, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "ptr", themeForegroundColors: @["keyword"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdPointerTypeDeclTarget, uiFlags: &{LayoutHorizontal}), +] -builder.addBuilderFor stringGetLengthClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add builder.buildChildren(map, node, owner, IdStringGetLengthValue, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ".", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation"], disableEditing: true) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "len", themeForegroundColors: @["keyword"], disableEditing: true) - return cell +builder.addBuilderFor IdAddressOf, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: Children, childrenRole: IdAddressOfValue, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: ".addr", flags: &{NoSpaceLeft}, themeForegroundColors: @["keyword"], disableEditing: true), +] -builder.addBuilderFor IdArrayAccess, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add builder.buildChildren(map, node, owner, IdArrayAccessValue, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "[", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdArrayAccessIndex, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "]", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - return cell +builder.addBuilderFor IdDeref, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: Children, childrenRole: IdDerefValue, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: ".deref", flags: &{NoSpaceLeft}, themeForegroundColors: @["keyword"], disableEditing: true), +] -builder.addBuilderFor IdAllocate, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "alloc", themeForegroundColors: @["keyword"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdAllocateType, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ",", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - cell.add block: - buildChildrenT(builder, map, node, owner, IdAllocateCount, &{LayoutHorizontal}, 0.CellFlags): - placeholder: PlaceholderCell(id: newId().CellId, node: owner ?? node, referenceNode: node, role: role, shadowText: "1") - return cell +builder.addBuilderFor IdCast, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: Children, childrenRole: IdCastValue, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: ".", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation"], disableEditing: true), + CellBuilderCommand(kind: ConstantCell, text: "as", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["keyword"], disableEditing: true), + CellBuilderCommand(kind: ConstantCell, text: "(", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdCastType, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: ")", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation"], disableEditing: true), +] -builder.addBuilderFor callClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = +builder.addBuilderFor IdStringGetPointer, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: Children, childrenRole: IdStringGetPointerValue, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: ".", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation"], disableEditing: true), + CellBuilderCommand(kind: ConstantCell, text: "ptr", themeForegroundColors: @["keyword"], disableEditing: true), +] - cell.add builder.buildChildren(map, node, owner, IdCallFunction, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "(", style: CellStyle(noSpaceLeft: true, noSpaceRight: true), themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) +builder.addBuilderFor IdStringGetLength, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: Children, childrenRole: IdStringGetLengthValue, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: ".", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation"], disableEditing: true), + CellBuilderCommand(kind: ConstantCell, text: "len", themeForegroundColors: @["keyword"], disableEditing: true), +] - cell.add block: - buildChildrenT(builder, map, node, owner, IdCallArguments, &{LayoutHorizontal}, 0.CellFlags): - separator: ConstantCell(node: owner ?? node, referenceNode: node, text: ",", style: CellStyle(noSpaceLeft: true), themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true, disableSelection: true, deleteNeighbor: true) - placeholder: PlaceholderCell(id: newId().CellId, node: owner ?? node, referenceNode: node, role: role, shadowText: "") +builder.addBuilderFor IdArrayAccess, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: Children, childrenRole: IdArrayAccessValue, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "[", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdArrayAccessIndex, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "]", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), +] - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ")", style: CellStyle(noSpaceLeft: true), themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) +builder.addBuilderFor IdAllocate, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "alloc", themeForegroundColors: @["keyword"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdAllocateType, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: ",", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdAllocateCount, placeholder: "1".some, uiFlags: &{LayoutHorizontal}), +] - return cell +builder.addBuilderFor IdCall, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: Children, childrenRole: IdCallFunction, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "(", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdCallArguments, separator: ",".some, placeholder: "".some , uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: ")", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), +] builder.addBuilderFor thenCaseClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) @@ -632,90 +586,46 @@ builder.addBuilderFor ifClass.id, idNone(), proc(builder: CellBuilder, node: Ast return cell -builder.addBuilderFor whileClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "while", themeForegroundColors: @["keyword"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdWhileExpressionCondition, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ":", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdWhileExpressionBody, &{LayoutHorizontal}) - - return cell - -builder.addBuilderFor forLoopClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - proc varDeclNameOnlyBuilder(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = PropertyCell(node: owner ?? node, referenceNode: node, property: IdINamedName) - - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "for", themeForegroundColors: @["keyword"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdForLoopVariable, &{LayoutHorizontal}, builderFunc=varDeclNameOnlyBuilder) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "in", themeForegroundColors: @["keyword"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdForLoopStart, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "..<", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdForLoopEnd, &{LayoutHorizontal}, - placeholderFunc = proc(builder: CellBuilder, node: AstNode, owner: AstNode, role: RoleId, flags: CellFlags = 0.CellFlags): Cell = - return PlaceholderCell(id: newId().CellId, node: owner ?? node, referenceNode: node, role: role, flags: flags, shadowText: "∞")) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ":", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdForLoopBody, &{LayoutHorizontal}) - - return cell +builder.addBuilderFor IdWhileExpression, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "while", themeForegroundColors: @["keyword"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdWhileExpressionCondition, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: ":", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdWhileExpressionBody, uiFlags: &{LayoutHorizontal}), +] -# builder.addBuilderFor IdForLoop, idNone(), [ -# CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayourHorizontal}), -# CellBuilderCommand(kind: ConstantCell, text: "for", themeForegroundColors: @["keyword"], disableEditing: true), -# CellBuilderCommand(kind: Children, childrenRole: IdForLoopVariable, uiFlags: &{LayoutHorizontal}), -# ] +proc varDeclNameOnlyBuilder(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = PropertyCell(node: owner ?? node, referenceNode: node, property: IdINamedName) -builder.addBuilderFor breakClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["keyword"], disableEditing: true) - return cell +builder.addBuilderFor IdForLoop, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "for", themeForegroundColors: @["keyword"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdForLoopVariable, builderFunc: varDeclNameOnlyBuilder, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "in", themeForegroundColors: @["keyword"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdForLoopStart, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "..<", flags: &{NoSpaceLeft, NoSpaceRight}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdForLoopEnd, placeholder: "inf".some, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: ":", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + CellBuilderCommand(kind: Children, childrenRole: IdForLoopBody, uiFlags: &{LayoutHorizontal}), +] builder.addBuilderFor IdBreakExpression, idNone(), [ CellBuilderCommand(kind: AliasCell, themeForegroundColors: @["keyword"], disableEditing: true), ] -builder.addBuilderFor continueClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["keyword"], disableEditing: true) - return cell - builder.addBuilderFor IdContinueExpression, idNone(), [ CellBuilderCommand(kind: AliasCell, themeForegroundColors: @["keyword"], disableEditing: true), ] -builder.addBuilderFor returnClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["keyword"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdReturnExpressionValue, &{LayoutHorizontal}) - return cell - -builder.addBuilderFor IdContinueExpression, idNone(), [ +builder.addBuilderFor IdReturnExpression, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), CellBuilderCommand(kind: AliasCell, themeForegroundColors: @["keyword"], disableEditing: true), CellBuilderCommand(kind: Children, childrenRole: IdReturnExpressionValue, uiFlags: &{LayoutHorizontal}), ] -builder.addBuilderFor nodeReferenceClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - if node.resolveReference(IdNodeReferenceTarget).getSome(targetNode): - if targetNode.nodeClass.isSubclassOf(IdINamed): - return PropertyCell(id: newId().CellId, node: owner ?? node, referenceNode: targetNode, property: IdINamedName, themeForegroundColors: @["variable", "&editor.foreground"], disableEditing: true) - - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add ConstantCell(id: newId().CellId, node: owner ?? node, referenceNode: node, text: "<", flags: &{NoSpaceRight}, themeForegroundColors: @["keyword"]) - cell.add map.buildReference(node, owner, IdNodeReferenceTarget) - cell.add ConstantCell(id: newId().CellId, node: owner ?? node, referenceNode: node, text: ">", flags: &{NoSpaceLeft}, themeForegroundColors: @["keyword"]) - return cell - else: - return PlaceholderCell(id: newId().CellId, node: owner ?? node, referenceNode: node, role: IdNodeReferenceTarget, shadowText: fmt"") - builder.addBuilderFor IdNodeReference, idNone(), [ CellBuilderCommand(kind: ReferenceCell, referenceRole: IdNodeReferenceTarget, targetProperty: IdINamedName.some, themeForegroundColors: @["variable", "&editor.foreground"], disableEditing: true), ] -builder.addBuilderFor expressionClass.id, idNone(), &{OnlyExactMatch}, proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = ConstantCell(id: newId().CellId, node: owner ?? node, referenceNode: node, shadowText: "", themeBackgroundColors: @["&inputValidation.errorBackground", "&debugConsole.errorForeground"]) - return cell - builder.addBuilderFor IdExpression, idNone(), &{OnlyExactMatch}, [ CellBuilderCommand(kind: ConstantCell, shadowText: "", themeBackgroundColors: @["&inputValidation.errorBackground", "&debugConsole.errorForeground"]), ] @@ -737,14 +647,6 @@ builder.addBuilderFor binaryExpressionClass.id, idNone(), proc(builder: CellBuil return cell -builder.addBuilderFor divExpressionClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutVertical}, inline: true) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add builder.buildChildren(map, node, owner, IdBinaryExpressionLeft, &{LayoutHorizontal}) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "------", themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdBinaryExpressionRight, &{LayoutHorizontal}) - return cell - builder.addBuilderFor IdDiv, idNone(), [ CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutVertical}, inline: true), CellBuilderCommand(kind: Children, childrenRole: IdBinaryExpressionLeft, uiFlags: &{LayoutHorizontal}), @@ -752,59 +654,12 @@ builder.addBuilderFor IdDiv, idNone(), [ CellBuilderCommand(kind: Children, childrenRole: IdBinaryExpressionRight, uiFlags: &{LayoutHorizontal}), ] -builder.addBuilderFor unaryExpressionClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - cell.add AliasCell(node: owner ?? node, referenceNode: node, style: CellStyle(noSpaceRight: true), disableEditing: true) - cell.add builder.buildChildren(map, node, owner, IdUnaryExpressionChild, &{LayoutHorizontal}) - return cell - builder.addBuilderFor IdUnaryExpression, idNone(), [ CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), CellBuilderCommand(kind: AliasCell, flags: &{NoSpaceRight}, disableEditing: true), CellBuilderCommand(kind: Children, childrenRole: IdUnaryExpressionChild, uiFlags: &{LayoutHorizontal}), ] -builder.addBuilderFor metaTypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true) - return cell - -builder.addBuilderFor stringTypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true) - return cell - -builder.addBuilderFor voidTypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true) - return cell - -builder.addBuilderFor int32TypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true) - return cell - -builder.addBuilderFor uint32TypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true) - return cell - -builder.addBuilderFor int64TypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true) - return cell - -builder.addBuilderFor uint64TypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true) - return cell - -builder.addBuilderFor float32TypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true) - return cell - -builder.addBuilderFor float64TypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true) - return cell - -builder.addBuilderFor charTypeClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = AliasCell(id: newId().CellId, node: owner ?? node, referenceNode: node, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true) - return cell - builder.addBuilderFor IdType, idNone(), [CellBuilderCommand(kind: AliasCell, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true)] builder.addBuilderFor IdString, idNone(), [CellBuilderCommand(kind: AliasCell, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true)] builder.addBuilderFor IdVoid, idNone(), [CellBuilderCommand(kind: AliasCell, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true)] @@ -816,22 +671,6 @@ builder.addBuilderFor IdFloat32, idNone(), [CellBuilderCommand(kind: AliasCell, builder.addBuilderFor IdFloat64, idNone(), [CellBuilderCommand(kind: AliasCell, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true)] builder.addBuilderFor IdChar, idNone(), [CellBuilderCommand(kind: AliasCell, themeForegroundColors: @["storage.type", "&editor.foreground"], disableEditing: true)] -builder.addBuilderFor printExpressionClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - - cell.add AliasCell(node: owner ?? node, referenceNode: node, disableEditing: true) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "(", style: CellStyle(noSpaceLeft: true, noSpaceRight: true), themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - - cell.add block: - buildChildrenT(builder, map, node, owner, IdPrintArguments, &{LayoutHorizontal}, 0.CellFlags): - separator: ConstantCell(node: owner ?? node, referenceNode: node, text: ",", style: CellStyle(noSpaceLeft: true), themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true, disableSelection: true, deleteNeighbor: true) - placeholder: PlaceholderCell(id: newId().CellId, node: owner ?? node, referenceNode: node, role: role, shadowText: "") - - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ")", style: CellStyle(noSpaceLeft: true), themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - - return cell - builder.addBuilderFor IdPrint, idNone(), [ CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), CellBuilderCommand(kind: AliasCell, disableEditing: true), @@ -840,22 +679,6 @@ builder.addBuilderFor IdPrint, idNone(), [ CellBuilderCommand(kind: ConstantCell, text: ")", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), ] -builder.addBuilderFor buildExpressionClass.id, idNone(), proc(builder: CellBuilder, node: AstNode, owner: AstNode): Cell = - var cell = CollectionCell(id: newId().CellId, node: owner ?? node, referenceNode: node, uiFlags: &{LayoutHorizontal}) - cell.fillChildren = proc(map: NodeCellMap) = - - cell.add AliasCell(node: owner ?? node, referenceNode: node, disableEditing: true) - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: "(", style: CellStyle(noSpaceLeft: true, noSpaceRight: true), themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - - cell.add block: - buildChildrenT(builder, map, node, owner, IdBuildArguments, &{LayoutHorizontal}, 0.CellFlags): - separator: ConstantCell(node: owner ?? node, referenceNode: node, text: ",", style: CellStyle(noSpaceLeft: true), themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true, disableSelection: true, deleteNeighbor: true) - placeholder: PlaceholderCell(id: newId().CellId, node: owner ?? node, referenceNode: node, role: role, shadowText: "") - - cell.add ConstantCell(node: owner ?? node, referenceNode: node, text: ")", style: CellStyle(noSpaceLeft: true), themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true) - - return cell - builder.addBuilderFor IdBuildString, idNone(), [ CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), CellBuilderCommand(kind: AliasCell, disableEditing: true), @@ -2174,7 +1997,7 @@ scopeComputers[IdThenCase] = proc(ctx: ModelComputationContextBase, node: AstNod # debugf"compute scope for then case {node}" return ctx.computeDefaultScope(node) -let baseLanguage* = newLanguage(IdBaseLanguage, +let baseLanguage* = newLanguage(IdBaseLanguage, "Base", @[ namedInterface, declarationInterface, diff --git a/src/ast/cells.nim b/src/ast/cells.nim index 79bf4ea2..1dcc3227 100644 --- a/src/ast/cells.nim +++ b/src/ast/cells.nim @@ -99,6 +99,7 @@ type shadowText*: string themeForegroundColors*: seq[string] themeBackgroundColors*: seq[string] + builderFunc*: CellBuilderFunction case kind*: CellBuilderCommandKind of CollectionCell: @@ -112,7 +113,6 @@ type of ReferenceCell: referenceRole*: RoleId - builderFunc*: CellBuilderFunction targetProperty*: Option[RoleId] of AliasCell: @@ -772,7 +772,7 @@ proc buildCellWithCommands(map: NodeCellMap, node: AstNode, owner: AstNode, comm else: placeholder = buildDefaultPlaceholder - var cell = builder.buildChildren(map, node, owner, command.childrenRole, command.uiFlags, command.flags, customIsVisible=nil, separator, placeholder, builderFunc=nil) + var cell = builder.buildChildren(map, node, owner, command.childrenRole, command.uiFlags, command.flags, customIsVisible=nil, separator, placeholder, builderFunc=command.builderFunc) if currentCollectionCell.isNotNil: currentCollectionCell.add cell else: diff --git a/src/ast/editor_language.nim b/src/ast/editor_language.nim index 5e36375c..5692b70c 100644 --- a/src/ast/editor_language.nim +++ b/src/ast/editor_language.nim @@ -46,7 +46,7 @@ typeComputers[loadAppFileClass.id] = proc(ctx: ModelComputationContextBase, node # scope -let editorLanguage* = newLanguage(IdEditorLanguage, @[ +let editorLanguage* = newLanguage(IdEditorLanguage, "Editor", @[ loadAppFileClass, ], typeComputers, valueComputers, scopeComputers, validationComputers, [base_language.baseLanguage]) registerBuilder(IdEditorLanguage, builder) diff --git a/src/ast/lang/cell_language.nim b/src/ast/lang/cell_language.nim new file mode 100644 index 00000000..5fdb4405 --- /dev/null +++ b/src/ast/lang/cell_language.nim @@ -0,0 +1,81 @@ +import std/[tables, strformat, options, json] +import id, ast_ids, util, custom_logger +import ../model, ../cells, ../model_state, query_system, ../cell_builder_database +import ../base_language +import lang_language +import ui/node +import print +export id, ast_ids + +logCategory "cell-language" + +var builder = newCellBuilder() +var typeComputers = initTable[ClassId, proc(ctx: ModelComputationContextBase, node: AstNode): AstNode]() +var valueComputers = initTable[ClassId, proc(ctx: ModelComputationContextBase, node: AstNode): AstNode]() +var scopeComputers = initTable[ClassId, proc(ctx: ModelComputationContextBase, node: AstNode): seq[AstNode]]() +var validationComputers = initTable[ClassId, proc(ctx: ModelComputationContextBase, node: AstNode): bool]() + +builder.addBuilderFor IdCellBuilderDefinition, idNone(), [ + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutHorizontal}), + CellBuilderCommand(kind: ConstantCell, text: "cell layout for", themeForegroundColors: @["keyword"], disableEditing: true), + CellBuilderCommand(kind: ReferenceCell, referenceRole: IdCellBuilderDefinitionClass, targetProperty: IdINamedName.some, themeForegroundColors: @["variable"], disableEditing: true), + CellBuilderCommand(kind: ConstantCell, text: ":", flags: &{NoSpaceLeft}, themeForegroundColors: @["punctuation", "&editor.foreground"], disableEditing: true), + + CellBuilderCommand(kind: CollectionCell, uiFlags: &{LayoutVertical}, flags: &{OnNewLine, IndentChildren}), + CellBuilderCommand(kind: Children, childrenRole: IdCellBuilderDefinitionCellDefinitions, uiFlags: &{LayoutVertical}, flags: &{OnNewLine, IndentChildren}), + CellBuilderCommand(kind: EndCollectionCell), +] + +scopeComputers[IdCellBuilderDefinition] = proc(ctx: ModelComputationContextBase, node: AstNode): seq[AstNode] = + debugf"compute scope for cell builder definition {node}" + var nodes: seq[AstNode] = @[] + + # todo: improve this + for model in node.model.models: + for root in model.rootNodes: + for _, aspect in root.children(IdLangRootChildren): + if aspect.class == IdClassDefinition: + nodes.add aspect + + for root in node.model.rootNodes: + for _, aspect in root.children(IdLangRootChildren): + if aspect.class == IdClassDefinition: + nodes.add aspect + + return nodes + +var cellLanguage*: Language = block createCellLanguage: + proc resolveLanguage(id: LanguageId): Option[Language] = + if id == IdLangLanguage: + return lang_language.langLanguage.some + else: + echo "Unknown language id: ", id + + proc resolveModel(project: Project, id: ModelId): Option[Model] = discard + + let model = newModel(IdCellLanguage.ModelId) + model.addLanguage(lang_language.langLanguage) + + const jsonText = staticRead "../model/cell-builder.ast-model" + if not model.loadFromJson("model/cell-builder.ast-model", jsonText.parseJson, resolveLanguage, resolveModel): + echo "Failed to load cell builder model" + break createCellLanguage + + var language = createLanguageFromModel(model) + language.name = "Cells" + language.scopeComputers = scopeComputers + language + +registerBuilder(IdCellLanguage, builder) + +# let langLanguageModel = block: +# let model = newModel(IdLangLanguageModel) +# model.addLanguage(langLanguage) +# model.addRootNode createNodesForLanguage(langLanguage) +# model +# langLanguage.model = langLanguageModel +# langLanguage.model.addRootNode createNodesForLanguage(langLanguage) + +proc updateCellLanguage*(model: Model) = + cellLanguage = createLanguageFromModel(model) + cellLanguage.name = "Cells" \ No newline at end of file diff --git a/src/ast/lang/lang_language.nim b/src/ast/lang/lang_language.nim index f1d80cc4..09cca380 100644 --- a/src/ast/lang/lang_language.nim +++ b/src/ast/lang/lang_language.nim @@ -291,19 +291,21 @@ proc computeDefaultScope(ctx: ModelComputationContextBase, node: AstNode): seq[A scopeComputers[IdClassReference] = proc(ctx: ModelComputationContextBase, node: AstNode): seq[AstNode] = debugf"compute scope for class reference {node}" - log lvlWarn, "uaie" var nodes: seq[AstNode] = @[] for model in node.model.models: - echo "model ", model.id for root in model.rootNodes: - echo "import root ", root + for _, aspect in root.children(IdLangRootChildren): + if aspect.class == IdClassDefinition: + nodes.add aspect + + for language in node.model.languages: + for root in language.model.rootNodes: for _, aspect in root.children(IdLangRootChildren): if aspect.class == IdClassDefinition: nodes.add aspect for root in node.model.rootNodes: - echo "root ", root for _, aspect in root.children(IdLangRootChildren): if aspect.class == IdClassDefinition: nodes.add aspect @@ -321,6 +323,12 @@ scopeComputers[IdClassDefinition] = proc(ctx: ModelComputationContextBase, node: if aspect.class == IdClassDefinition: nodes.add aspect + for language in node.model.languages: + for root in language.model.rootNodes: + for _, aspect in root.children(IdLangRootChildren): + if aspect.class == IdClassDefinition: + nodes.add aspect + for root in node.model.rootNodes: for _, aspect in root.children(IdLangRootChildren): if aspect.class == IdClassDefinition: @@ -360,15 +368,6 @@ scopeComputers[IdRoleReference] = proc(ctx: ModelComputationContextBase, node: A return nodes -let langLanguage* = newLanguage(IdLangLanguage, @[ - langRootClass, langAspectClass, - roleDescriptorInterface, - propertyTypeClass, propertyTypeBoolClass, propertyTypeStringClass, propertyTypeNumberClass, propertyDefinitionClass, classDefinitionClass, - classReferenceClass, roleReferenceClass, referenceDefinitionClass, childrenDefinitionClass, - countClass, countZeroOrOneClass, countOneClass, countZeroOrMoreClass, countOneOrMoreClass, -], typeComputers, valueComputers, scopeComputers, validationComputers) -registerBuilder(IdLangLanguage, builder) - proc createNodeClassFromLangDefinition*(classMap: var Table[ClassId, NodeClass], def: AstNode): Option[NodeClass] = if classMap.contains(def.id.ClassId): return classMap[def.id.ClassId].some @@ -486,14 +485,16 @@ proc createNodeClassFromLangDefinition*(classMap: var Table[ClassId, NodeClass], return class.some -proc createLanguageFromNodes*(def: AstNode): Language = - log lvlInfo, fmt"createLanguageFromNodes" +proc createLanguageFromModel*(model: Model): Language = + log lvlInfo, fmt"createLanguageFromModel {model.path} ({model.id})" var classMap = initTable[ClassId, NodeClass]() var classes: seq[NodeClass] = @[] - for _, c in def.children(IdLangRootChildren): - if c.class == IdClassDefinition: - if createNodeClassFromLangDefinition(classMap, c).getSome(class): - classes.add class + + for def in model.rootNodes: + for _, c in def.children(IdLangRootChildren): + if c.class == IdClassDefinition: + if createNodeClassFromLangDefinition(classMap, c).getSome(class): + classes.add class var builder = newCellBuilder() var typeComputers = initTable[ClassId, proc(ctx: ModelComputationContextBase, node: AstNode): AstNode]() @@ -501,7 +502,7 @@ proc createLanguageFromNodes*(def: AstNode): Language = var scopeComputers = initTable[ClassId, proc(ctx: ModelComputationContextBase, node: AstNode): seq[AstNode]]() var validationComputers = initTable[ClassId, proc(ctx: ModelComputationContextBase, node: AstNode): bool]() - result = newLanguage(def.id.LanguageId, classes, typeComputers, valueComputers, scopeComputers, validationComputers) + result = newLanguage(model.id.LanguageId, "", classes, typeComputers, valueComputers, scopeComputers, validationComputers) proc createNodeFromNodeClass(classes: var Table[ClassId, AstNode], class: NodeClass): AstNode = # log lvlInfo, fmt"createNodeFromNodeClass {class.name}" @@ -591,4 +592,21 @@ proc createNodesForLanguage*(language: Language): AstNode = var classes = initTable[ClassId, AstNode]() for class in language.classes.values: - result.add IdLangRootChildren, createNodeFromNodeClass(classes, class) \ No newline at end of file + result.add IdLangRootChildren, createNodeFromNodeClass(classes, class) + +let langLanguage* = newLanguage(IdLangLanguage, "Language Creation", @[ + langRootClass, langAspectClass, + roleDescriptorInterface, + propertyTypeClass, propertyTypeBoolClass, propertyTypeStringClass, propertyTypeNumberClass, propertyDefinitionClass, classDefinitionClass, + classReferenceClass, roleReferenceClass, referenceDefinitionClass, childrenDefinitionClass, + countClass, countZeroOrOneClass, countOneClass, countZeroOrMoreClass, countOneOrMoreClass, +], typeComputers, valueComputers, scopeComputers, validationComputers) +registerBuilder(IdLangLanguage, builder) + +# let langLanguageModel = block: +# let model = newModel(IdLangLanguageModel) +# model.addLanguage(langLanguage) +# model.addRootNode createNodesForLanguage(langLanguage) +# model +# langLanguage.model = langLanguageModel +langLanguage.model.addRootNode createNodesForLanguage(langLanguage) \ No newline at end of file diff --git a/src/ast/model.nim b/src/ast/model.nim index 1c139bf7..15321945 100644 --- a/src/ast/model.nim +++ b/src/ast/model.nim @@ -98,6 +98,7 @@ type ModelComputationContextBase* = ref object of RootObj Language* = ref object + name* : string id {.getter.}: LanguageId version {.getter.}: int classes {.getter.}: Table[ClassId, NodeClass] @@ -255,7 +256,7 @@ proc verify*(self: Language): bool = result = true for c in self.classes.values: if c.base.isNotNil: - let baseClass = self.resolveClass(c.base.id) + let baseClass = c.base if baseClass.isNil: log(lvlError, fmt"Class {c.name} has unknown base class {c.base.name}") result = false @@ -268,7 +269,7 @@ proc verify*(self: Language): bool = log(lvlError, fmt"Class {c.name} is both final and abstract") result = false -proc newLanguage*(id: LanguageId, classes: seq[NodeClass], +proc newLanguage*(id: LanguageId, name: string, classes: seq[NodeClass], typeComputers: Table[ClassId, proc(ctx: ModelComputationContextBase, node: AstNode): AstNode], valueComputers: Table[ClassId, proc(ctx: ModelComputationContextBase, node: AstNode): AstNode], scopeComputers: Table[ClassId, proc(ctx: ModelComputationContextBase, node: AstNode): seq[AstNode]], @@ -278,6 +279,7 @@ proc newLanguage*(id: LanguageId, classes: seq[NodeClass], ): Language = new result result.id = id + result.name = name result.typeComputers = typeComputers result.valueComputers = valueComputers result.scopeComputers = scopeComputers @@ -1219,7 +1221,7 @@ proc loadFromJson*(project: Project, json: JsonNode, opt = Joptions()): bool = return true -proc loadFromJson*(project: Project, model: Model, workspace: WorkspaceFolder, path: string, json: JsonNode, +proc loadFromJsonAsync*(model: Model, project: Project, workspace: WorkspaceFolder, path: string, json: JsonNode, resolveLanguage: proc(id: LanguageId): Option[Language], resolveModel: proc(project: Project, workspace: WorkspaceFolder, id: ModelId): Future[Option[Model]], opt = Joptions()): Future[void] {.async.} = @@ -1247,10 +1249,55 @@ proc loadFromJson*(project: Project, model: Model, workspace: WorkspaceFolder, p for modelIdJson in json["models"]: let id = modelIdJson.jsonTo ModelId model.importedModels.incl id - if project.resolveModel(workspace, id).await.getSome(m): + if resolveModel(project, workspace, id).await.getSome(m): + model.addImport(m) + else: + log(lvlError, fmt"Unknown model {id}") + + if json.hasKey("rootNodes"): + for node in json["rootNodes"]: + if node.jsonToAstNode(model, opt).getSome(node): + model.addRootNode(node) + else: + log(lvlError, fmt"Failed to parse root node from json") + else: + log(lvlWarn, fmt"Missing root nodes") + +proc loadFromJson*(model: Model, path: string, json: JsonNode, + resolveLanguage: proc(id: LanguageId): Option[Language], + resolveModel: proc(project: Project, id: ModelId): Option[Model], + opt = Joptions()): bool = + model.path = path + if json.kind != JObject: + log(lvlError, fmt"Expected JObject") + return false + + if json.hasKey("id"): + model.id = json["id"].jsonTo ModelId + else: + log(lvlError, fmt"Missing id") + return false + + if json.hasKey("languages"): + for languageIdJson in json["languages"]: + let id = languageIdJson.jsonTo LanguageId + if resolveLanguage(id).getSome(language): + model.addLanguage(language) + else: + log(lvlError, fmt"Unknown language {id}") + return false + else: + log(lvlWarn, fmt"Missing languages") + + if json.hasKey("models"): + for modelIdJson in json["models"]: + let id = modelIdJson.jsonTo ModelId + model.importedModels.incl id + if resolveModel(model.project, id).getSome(m): model.addImport(m) else: log(lvlError, fmt"Unknown model {id}") + return false if json.hasKey("rootNodes"): for node in json["rootNodes"]: @@ -1258,5 +1305,8 @@ proc loadFromJson*(project: Project, model: Model, workspace: WorkspaceFolder, p model.addRootNode(node) else: log(lvlError, fmt"Failed to parse root node from json") + return false else: - log(lvlWarn, fmt"Missing root nodes") \ No newline at end of file + log(lvlWarn, fmt"Missing root nodes") + + return true \ No newline at end of file diff --git a/src/ast_ids.nim b/src/ast_ids.nim index 701db087..3e82b032 100644 --- a/src/ast_ids.nim +++ b/src/ast_ids.nim @@ -187,6 +187,7 @@ let IdStringGetLengthValue* = "654fbb281446e19b38225255".parseId.RoleId # lang language let IdLangLanguage* = "654fbb281446e19b3822523f".parseId.LanguageId +let IdLangLanguageModel* = "656f7f67d077504f640d8718".parseId.ModelId let IdLangRoot* = "654fbb281446e19b3822524f".parseId.ClassId let IdLangRootChildren* = "654fbb281446e19b38225250".parseId.RoleId @@ -238,11 +239,21 @@ let IdRoleReferenceTarget* = "654fbb281446e19b3822524e".parseId.RoleId let IdIRoleDescriptor* = "654fbb281446e19b3822524c".parseId.ClassId +let IdCellLanguage* = "82ffffff9afd1f08150838c9".parseId.LanguageId +let IdCellBuilderDefinition* = "82ffffff9afd1f08150838f7".parseId.ClassId +let IdCellBuilderDefinitionClass* = "82ffffff0cfb77255e939d35".parseId.RoleId +let IdCellBuilderDefinitionCellDefinitions* = "82ffffffb1fee44425c76425".parseId.RoleId +let IdCellDefinition* = "82ffffffeb36250369ecc38d".parseId.ClassId +let IdCollectionCellDefinition* = "82ffffffeb36250369ecc453".parseId.ClassId +let IdHorizontalCellDefinition* = "82ffffffeb36250369ecc6f4".parseId.ClassId +let IdVerticalCellDefinition* = "82ffffff65d17c4d369b48fc".parseId.ClassId +let IdConstantCellDefinition* = "82ffffffb1fee44425c73d48".parseId.ClassId +let IdPropertyCellDefinition* = "82ffffffb1fee44425c74037".parseId.ClassId +let IdReferenceCellDefinition* = "82ffffffb1fee44425c74370".parseId.ClassId +let IdChildrenCellDefinition* = "82ffffffb1fee44425c7489e".parseId.ClassId + # new ids -let Id656f7f67d077504f640d86ca* = "656f7f67d077504f640d86ca".parseId -let Id656f7f67d077504f640d86cb* = "656f7f67d077504f640d86cb".parseId -let Id656f7f67d077504f640d86cc* = "656f7f67d077504f640d86cc".parseId let Id656f7f67d077504f640d86cd* = "656f7f67d077504f640d86cd".parseId let Id656f7f67d077504f640d86ce* = "656f7f67d077504f640d86ce".parseId let Id656f7f67d077504f640d86cf* = "656f7f67d077504f640d86cf".parseId @@ -318,9 +329,8 @@ let Id656f7f67d077504f640d8714* = "656f7f67d077504f640d8714".parseId let Id656f7f67d077504f640d8715* = "656f7f67d077504f640d8715".parseId let Id656f7f67d077504f640d8716* = "656f7f67d077504f640d8716".parseId let Id656f7f67d077504f640d8717* = "656f7f67d077504f640d8717".parseId -let Id656f7f67d077504f640d8718* = "656f7f67d077504f640d8718".parseId -import strformat -for i in 0..100: - let id = newId() - echo &"let Id{id}* = \"{id}\".parseId" \ No newline at end of file +# import strformat +# for i in 0..100: +# let id = newId() +# echo &"let Id{id}* = \"{id}\".parseId" \ No newline at end of file diff --git a/src/model_document.nim b/src/model_document.nim index b27cf950..50f3c601 100644 --- a/src/model_document.nim +++ b/src/model_document.nim @@ -1,4 +1,4 @@ -import std/[strformat, strutils, sugar, tables, options, json, streams, algorithm, sets] +import std/[strformat, strutils, sugar, tables, options, json, streams, algorithm, sets, sequtils] import fusion/matching, bumpy, rect_utils, vmath, fuzzy import util, document, document_editor, text/text_document, events, id, ast_ids, scripting/expose, event, input, custom_async, myjsonutils, custom_unicode, delayed_task from scripting_api as api import nil @@ -6,7 +6,7 @@ import custom_logger, timer, array_buffer, config_provider, app_interface, dispa import platform/[filesystem, platform] import workspaces/[workspace] import ast/[model, base_language, editor_language, cells] -import ast/lang/lang_language +import ast/lang/[lang_language, cell_language] import ui/node import ast/[generator_wasm, base_language_wasm, editor_language_wasm, model_state, cell_builder_database] @@ -531,6 +531,8 @@ proc resolveLanguage(id: LanguageId): Option[Language] = return editor_language.editorLanguage.some elif id == IdLangLanguage: return lang_language.langLanguage.some + elif id == IdCellLanguage: + return cell_language.cellLanguage.some else: return Language.none @@ -542,7 +544,7 @@ proc loadModelAsync(project: Project, ws: WorkspaceFolder, path: string): Future let json = jsonText.parseJson var model = newModel() - await project.loadFromJson(model, ws, path, json, resolveLanguage, resolveModel) + await model.loadFromJsonAsync(project, ws, path, json, resolveLanguage, resolveModel) if model.id.isNone: log lvlError, fmt"Failed to load model: no id" return Model.none @@ -650,8 +652,8 @@ proc getSubstitutionsForClass(self: ModelDocumentEditor, targetCell: Cell, class let (parent, role, index) = targetCell.getSubstitutionTarget() - let scope = self.document.ctx.getScope(targetCell.node) # debugf"getScope {parent}, {targetCell.node}" + let scope = self.document.ctx.getScope(targetCell.node) for decl in scope: # debugf"scope: {decl}, {decl.nodeClass.isSubclassOf(refClass.id)}" if decl.nodeClass.isSubclassOf(refClass.id): @@ -3305,30 +3307,33 @@ method changed*(self: ModelLanguageSelectorItem, other: SelectorItem): bool = let other = other.ModelLanguageSelectorItem return self.language.id != other.language.id -proc addLanguage*(self: ModelDocumentEditor) {.expose("editor.model").} = +proc chooseLanguageFromUser*(self: ModelDocumentEditor, languages: openArray[LanguageId], handleConfirmed: proc(language: Language)) = + let languages = @languages var popup = self.app.createSelectorPopup().SelectorPopup popup.getCompletions = proc(popup: SelectorPopup, text: string): seq[SelectorItem] = - # Find everything matching text - - let languages = {IdBaseLanguage: "Base Language", IdEditorLanguage: "Editor Language", IdLangLanguage: "Lang Language"} - for (id, name) in languages: - if self.document.model.hasLanguage(id): - continue - let score = fuzzyMatchSmart(text, name) - result.add ModelLanguageSelectorItem(language: resolveLanguage(id).get, name: name, score: score) + for id in languages: + if resolveLanguage(id).getSome(language): + let score = fuzzyMatchSmart(text, language.name) + result.add ModelLanguageSelectorItem(language: language, name: language.name, score: score) result.sort((a, b) => cmp(a.score, b.score), Descending) popup.handleItemConfirmed = proc(item: SelectorItem) = - log lvlInfo, fmt"Add language {item.ModelLanguageSelectorItem.name} ({item.ModelLanguageSelectorItem.language.id}) to model {self.document.model.id}" let language = item.ModelLanguageSelectorItem.language - self.document.model.addLanguage(language) - self.document.builder.addBuilder(getBuilder(language.id)) + handleConfirmed(language) popup.updateCompletions() self.app.pushPopup popup +proc addLanguage*(self: ModelDocumentEditor) {.expose("editor.model").} = + let languages = [IdBaseLanguage, IdEditorLanguage, IdLangLanguage, IdCellLanguage].filterIt(not self.document.model.hasLanguage(it)) + self.chooseLanguageFromUser(languages, proc(language: Language) = + log lvlInfo, fmt"Add language {language.name} ({language.id}) to model {self.document.model.id}" + self.document.model.addLanguage(language) + self.document.builder.addBuilder(getBuilder(language.id)) + ) + type ModelImportSelectorItem* = ref object of SelectorItem model*: ModelId name*: string @@ -3439,9 +3444,7 @@ proc compileLanguage*(self: ModelDocumentEditor) {.expose("editor.model").} = if not self.document.model.hasLanguage(IdLangLanguage): return - for root in self.document.model.rootNodes: - let language = createLanguageFromNodes(root) - # todo + let language = createLanguageFromModel(self.document.model) proc addRootNode*(self: ModelDocumentEditor) {.expose("editor.model").} = var popup = self.app.createSelectorPopup().SelectorPopup @@ -3480,41 +3483,46 @@ proc saveProject*(self: ModelDocumentEditor) {.expose("editor.model").} = else: log lvlError, fmt"Failed to save project: no workspace" -proc loadBaseLanguageModel*(self: ModelDocumentEditor) {.expose("editor.model").} = - log lvlInfo, fmt"Loading base language model" - try: - var model = newModel() - var root = createNodesForLanguage(base_language.baseLanguage) - model.addLanguage(lang_language.langLanguage) - model.addRootNode(root) +proc loadLanguageModel*(self: ModelDocumentEditor) {.expose("editor.model").} = + let languages = [IdBaseLanguage, IdEditorLanguage, IdLangLanguage, IdCellLanguage] + self.chooseLanguageFromUser(languages, proc(language: Language) = + log lvlInfo, fmt"Loading language model of {language.name} ({language.id})" - let oldModel = self.document.model - self.document.model = model + try: + var model = newModel() + var root = createNodesForLanguage(language) + model.addLanguage(lang_language.langLanguage) + model.addRootNode(root) - discard self.document.model.onNodeDeleted.subscribe proc(d: auto) = self.document.handleNodeDeleted(d[0], d[1], d[2], d[3], d[4]) - discard self.document.model.onNodeInserted.subscribe proc(d: auto) = self.document.handleNodeInserted(d[0], d[1], d[2], d[3], d[4]) - discard self.document.model.onNodePropertyChanged.subscribe proc(d: auto) = self.document.handleNodePropertyChanged(d[0], d[1], d[2], d[3], d[4], d[5]) - discard self.document.model.onNodeReferenceChanged.subscribe proc(d: auto) = self.document.handleNodeReferenceChanged(d[0], d[1], d[2], d[3], d[4]) + let oldModel = self.document.model + self.document.model = model - self.document.builder.clear() - for language in self.document.model.languages: - self.document.builder.addBuilder(getBuilder(language.id)) + discard self.document.model.onNodeDeleted.subscribe proc(d: auto) = self.document.handleNodeDeleted(d[0], d[1], d[2], d[3], d[4]) + discard self.document.model.onNodeInserted.subscribe proc(d: auto) = self.document.handleNodeInserted(d[0], d[1], d[2], d[3], d[4]) + discard self.document.model.onNodePropertyChanged.subscribe proc(d: auto) = self.document.handleNodePropertyChanged(d[0], d[1], d[2], d[3], d[4], d[5]) + discard self.document.model.onNodeReferenceChanged.subscribe proc(d: auto) = self.document.handleNodeReferenceChanged(d[0], d[1], d[2], d[3], d[4]) + + self.document.builder.clear() + for language in self.document.model.languages: + self.document.builder.addBuilder(getBuilder(language.id)) - self.document.undoList.setLen 0 - self.document.redoList.setLen 0 + self.document.undoList.setLen 0 + self.document.redoList.setLen 0 - functionInstances.clear() - structInstances.clear() - self.document.ctx.state.clearCache() + functionInstances.clear() + structInstances.clear() + self.document.ctx.state.clearCache() - self.document.ctx.state.removeModel(oldModel) - self.document.ctx.state.addModel(model) + self.document.ctx.state.removeModel(oldModel) + self.document.ctx.state.addModel(model) - except CatchableError: - log lvlError, fmt"Failed to load model source file '{self.document.filename}': {getCurrentExceptionMsg()}" - log lvlError, getCurrentException().getStackTrace() + except CatchableError: + log lvlError, fmt"Failed to load model source file '{self.document.filename}': {getCurrentExceptionMsg()}" + log lvlError, getCurrentException().getStackTrace() + + self.document.onModelChanged.invoke (self.document) - self.document.onModelChanged.invoke (self.document) + ) proc findDeclaration*(self: ModelDocumentEditor, global: bool) {.expose("editor.model").} = var popup = self.app.createSelectorPopup().SelectorPopup