Added basic syntax error reporting in Globals tab of node editor

This commit is contained in:
Rodz Labs 2021-10-05 22:38:27 +02:00
parent 096d3c6268
commit afde2562fb
5 changed files with 29 additions and 16 deletions

View File

@ -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="^(\\|\\||\\&\\&|\\^\\^|==)" },

View File

@ -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":

View File

@ -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:

View File

@ -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

View File

@ -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