From afde2562fb33b3779afd276f9bed782f3f7e7f6a Mon Sep 17 00:00:00 2001 From: Rodz Labs Date: Tue, 5 Oct 2021 22:38:27 +0200 Subject: [PATCH] Added basic syntax error reporting in Globals tab of node editor --- addons/material_maker/parser/glsl_parser.gd | 2 +- addons/material_maker/parser/parser_base.gd | 2 +- .../nodes/material_export/material_export.gd | 2 +- .../windows/node_editor/node_editor.gd | 13 +++++++--- .../windows/node_editor/node_editor.tscn | 26 ++++++++++++------- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/addons/material_maker/parser/glsl_parser.gd b/addons/material_maker/parser/glsl_parser.gd index 0f67c9ca..7f2824b9 100644 --- a/addons/material_maker/parser/glsl_parser.gd +++ b/addons/material_maker/parser/glsl_parser.gd @@ -3,7 +3,7 @@ extends "res://addons/material_maker/parser/glsl_parser_base.gd" const REGEXS : Array = [ { type="ignore", regex="^[\\s\\r\\n]+" }, { type="ignore", regex="^//.*?[\\r\\n]" }, - { type="ignore", regex="^/\\*.*?\\*/" }, + { type="ignore", regex="^/\\*(?:.|[\\r\\n])*?\\*/" }, { type="FLOATCONSTANT", regex="^(\\d*[.])?\\d+([eE][-+]?\\d+)?" }, { type="IDENTIFIER", regex="^\\$?[\\w_]+" }, { type="SYMBOLS", regex="^(\\|\\||\\&\\&|\\^\\^|==)" }, diff --git a/addons/material_maker/parser/parser_base.gd b/addons/material_maker/parser/parser_base.gd index f85c1be5..c558cef8 100644 --- a/addons/material_maker/parser/parser_base.gd +++ b/addons/material_maker/parser/parser_base.gd @@ -74,7 +74,7 @@ func parse(s : String): var penultimate_nt : String while true: if ! actions[state].has(next_token.type): - return { status="ERROR", msg="Unexpected token %s (state %d)" % [ next_token.type, state ], pos=next_token.pos_begin } + return { status="ERROR", state=state, msg="near '%s' (expected '%s')" % [ next_token.value, PoolStringArray(actions[state].keys()).join("', '") ], pos=next_token.pos_begin } var action = actions[state][next_token.type] match action[0]: "s": diff --git a/material_maker/nodes/material_export/material_export.gd b/material_maker/nodes/material_export/material_export.gd index b3f64e4f..5df96805 100644 --- a/material_maker/nodes/material_export/material_export.gd +++ b/material_maker/nodes/material_export/material_export.gd @@ -16,7 +16,7 @@ func _on_MaterialExport_gui_input(event : InputEvent) -> void: var can_copy = ( generator.model == null ) var can_paste = false var graph = parse_json(OS.clipboard) - if graph != null and graph is Dictionary: + if graph != null and graph is Dictionary and graph.has("nodes"): if graph.nodes.size() == 1 and graph.nodes[0].type == "material_export" and graph.nodes[0].has("shader_model"): can_paste = true if can_copy: diff --git a/material_maker/windows/node_editor/node_editor.gd b/material_maker/windows/node_editor/node_editor.gd index ff8c404c..755fc652 100644 --- a/material_maker/windows/node_editor/node_editor.gd +++ b/material_maker/windows/node_editor/node_editor.gd @@ -18,9 +18,9 @@ const OutputEditor = preload("res://material_maker/windows/node_editor/output.ts signal node_changed func _ready() -> void: - main_code_editor.add_color_region("//", "", Color(0, 0.5, 0), true) - instance_functions_editor.add_color_region("//", "", Color(0, 0.5, 0), true) - global_functions_editor.add_color_region("//", "", Color(0, 0.5, 0), true) + for e in [ main_code_editor, instance_functions_editor, global_functions_editor ]: + e.add_color_region("//", "", Color(0, 0.5, 0), true) + e.add_color_region("/*", "*/", Color(0, 0.5, 0), false) func add_item(parent, scene) -> Node: var object = scene.instance() @@ -116,16 +116,23 @@ var globals_error_line = -1 func _on_Functions_text_changed(): var text : String = global_functions_editor.text + var error_label = $"Sizer/Tabs/Global Functions/ErrorLabel" if globals_error_line != -1: global_functions_editor.set_line_as_safe(globals_error_line, false) + error_label.visible = false var result = parser.parse(global_functions_editor.text) if result is Dictionary and result.has("status"): match result.status: "OK": globals_error_line = -1 + if result.non_terminal != "translation_unit": + error_label.visible = true + error_label.text = "GLSL translation unit expected (found %s)" % result.non_terminal _: globals_error_line = text.substr(0, result.pos).count("\n") global_functions_editor.set_line_as_safe(globals_error_line, true) + error_label.visible = true + error_label.text = "Syntax error line "+str(globals_error_line+1)+": "+result.msg # OK/Apply/Cancel buttons diff --git a/material_maker/windows/node_editor/node_editor.tscn b/material_maker/windows/node_editor/node_editor.tscn index efdc1bad..3c8c231a 100644 --- a/material_maker/windows/node_editor/node_editor.tscn +++ b/material_maker/windows/node_editor/node_editor.tscn @@ -195,27 +195,25 @@ margin_right = -4.0 margin_bottom = -4.0 [node name="Includes" type="HBoxContainer" parent="Sizer/Tabs/Global Functions"] -margin_right = 40.0 -margin_bottom = 40.0 +margin_right = 942.0 +margin_bottom = 24.0 [node name="LabelIncludes" type="Label" parent="Sizer/Tabs/Global Functions/Includes"] -margin_left = 46.0 margin_top = 5.0 -margin_right = 88.0 +margin_right = 59.0 margin_bottom = 19.0 text = "Includes:" [node name="Includes" type="LineEdit" parent="Sizer/Tabs/Global Functions/Includes"] -margin_left = 469.0 -margin_right = 888.0 +margin_left = 63.0 +margin_right = 942.0 margin_bottom = 24.0 size_flags_horizontal = 3 [node name="Functions" type="TextEdit" parent="Sizer/Tabs/Global Functions"] -anchor_right = 1.0 -anchor_bottom = 1.0 -margin_right = -8.0 -margin_bottom = -36.0 +margin_top = 28.0 +margin_right = 942.0 +margin_bottom = 390.0 mouse_default_cursor_shape = 0 size_flags_vertical = 3 custom_fonts/font = SubResource( 3 ) @@ -224,6 +222,14 @@ custom_colors/brace_mismatch_color = Color( 1, 0, 0, 1 ) custom_colors/executing_line_color = Color( 1, 0, 0, 1 ) syntax_highlighting = true show_line_numbers = true +minimap_draw = true + +[node name="ErrorLabel" type="Label" parent="Sizer/Tabs/Global Functions"] +visible = false +margin_right = 40.0 +margin_bottom = 14.0 +custom_colors/font_color = Color( 1, 0, 0, 1 ) +clip_text = true [node name="HBoxContainer" type="HBoxContainer" parent="Sizer"] margin_left = 366.0