From 22c707a2847e09e51cbaa71beb5399b4bfaf66cf Mon Sep 17 00:00:00 2001 From: BenSiv Date: Mon, 4 Nov 2024 21:44:09 +0200 Subject: [PATCH 1/4] adding support for the openscad language --- runtime/plugins/comment/comment.lua | 1 + runtime/syntax/openscad.yaml | 48 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 runtime/syntax/openscad.yaml diff --git a/runtime/plugins/comment/comment.lua b/runtime/plugins/comment/comment.lua index ebb59626e..68f08d297 100644 --- a/runtime/plugins/comment/comment.lua +++ b/runtime/plugins/comment/comment.lua @@ -60,6 +60,7 @@ ft["yaml"] = "# %s" ft["zig"] = "// %s" ft["zscript"] = "// %s" ft["zsh"] = "# %s" +ft["openscad"] = "// %s" local last_ft diff --git a/runtime/syntax/openscad.yaml b/runtime/syntax/openscad.yaml new file mode 100644 index 000000000..8d1e4d695 --- /dev/null +++ b/runtime/syntax/openscad.yaml @@ -0,0 +1,48 @@ +filetype: openscad + +detect: + filename: "\\.scad$" + +rules: + - statement: "\\b(module|function|include|use|let|for|if|else|true|false)\\b" + - statement: "\\b(child|each|assign)\\b" + - statement: "\\b(intersection_for|import|export)\\b" + + - function: "\\b(circle|square|polygon|cube|sphere|cylinder|polyhedron|translate|rotate|scale|resize|mirror|multmatrix|color|offset|minkowski|hull|projection|surface|render|linear_extrude|rotate_extrude|dxf_linear_extrude|dxf_rotate_extrude)\\b" + + - constant: "\\b(pi|undef)\\b" + + - identifier: "\\b($fn|$fa|$fs|$t|$children)\\b" + - identifier: "\\b(x|y|z)\\b" + - identifier: "\\b(dx|dy|dz|angle|center|height|radius|diameter|r1|r2|h1|h2|points|paths|convexity|size|thickness|anchor)\\b" + + - symbol.brackets: "[(){}\\[\\]]" + - symbol: "(\\*|//|/|%|\\+|-|\\^|>|>=|<|<=|!=|==|=|[\\.]{2}|!|&&|\\|\\|)" + + - constant.number: "\\b((0[xX](([0-9A-Fa-f]+\\.[0-9A-Fa-f]*)|(\\.?[0-9A-Fa-f]+))([pP][-+]?[0-9]+)?)|((([0-9]+\\.[0-9]*)|(\\.?[0-9]+))([eE][-+]?[0-9]+)?))" + + - constant.string: + start: "\"" + end: "\"" + skip: "\\\\." + rules: + - constant.specialChar: "\\\\([abfnrtvz\\'\"]|[0-9]{1,3}|x[0-9a-fA-F][0-9a-fA-F]|u\\{[0-9a-fA-F]+\\})" + + - constant.string: + start: "'" + end: "'" + skip: "\\\\." + rules: + - constant.specialChar: "\\\\([abfnrtvz\\'\"]|[0-9]{1,3}|x[0-9a-fA-F][0-9a-fA-F]|u\\{[0-9a-fA-F]+\\})" + + - comment.block: + start: "\\/\\*" + end: "\\*\\/" + rules: + - todo: "(TODO|NOTE|FIXME):?" + + - comment: + start: "\\/\\/|\\#" + end: "$" + rules: + - todo: "(TODO|NOTE|FIXME):?" From dbf73d492680528a9548aa4551c111c78a03761a Mon Sep 17 00:00:00 2001 From: bensiv Date: Tue, 5 Nov 2024 08:25:20 +0200 Subject: [PATCH 2/4] placing the openscad comment sign in the alphabetic order --- runtime/plugins/comment/comment.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/plugins/comment/comment.lua b/runtime/plugins/comment/comment.lua index 68f08d297..09ba3b869 100644 --- a/runtime/plugins/comment/comment.lua +++ b/runtime/plugins/comment/comment.lua @@ -37,6 +37,7 @@ ft["nginx"] = "# %s" ft["nim"] = "# %s" ft["objc"] = "// %s" ft["ocaml"] = "(* %s *)" +ft["openscad"] = "// %s" ft["pascal"] = "{ %s }" ft["perl"] = "# %s" ft["php"] = "// %s" @@ -60,7 +61,6 @@ ft["yaml"] = "# %s" ft["zig"] = "// %s" ft["zscript"] = "// %s" ft["zsh"] = "# %s" -ft["openscad"] = "// %s" local last_ft From 077a494714b5fd0c1349f770ad619a1a5c0b69d2 Mon Sep 17 00:00:00 2001 From: bensiv Date: Tue, 5 Nov 2024 08:35:10 +0200 Subject: [PATCH 3/4] adding escape charachter to $ sign for spacial variables and also moving booleans to constants --- runtime/syntax/openscad.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/syntax/openscad.yaml b/runtime/syntax/openscad.yaml index 8d1e4d695..5fa80d04d 100644 --- a/runtime/syntax/openscad.yaml +++ b/runtime/syntax/openscad.yaml @@ -4,21 +4,21 @@ detect: filename: "\\.scad$" rules: - - statement: "\\b(module|function|include|use|let|for|if|else|true|false)\\b" + - statement: "\\b(module|function|include|use|let|for|if|else)\\b" - statement: "\\b(child|each|assign)\\b" - statement: "\\b(intersection_for|import|export)\\b" - function: "\\b(circle|square|polygon|cube|sphere|cylinder|polyhedron|translate|rotate|scale|resize|mirror|multmatrix|color|offset|minkowski|hull|projection|surface|render|linear_extrude|rotate_extrude|dxf_linear_extrude|dxf_rotate_extrude)\\b" - - constant: "\\b(pi|undef)\\b" + - constant: "\\b(pi|undef|true|false)\\b" - - identifier: "\\b($fn|$fa|$fs|$t|$children)\\b" + - identifier: "\\b(\\$fn|\\$fa|\\$fs|\\$t|\\$children)\\b" - identifier: "\\b(x|y|z)\\b" - identifier: "\\b(dx|dy|dz|angle|center|height|radius|diameter|r1|r2|h1|h2|points|paths|convexity|size|thickness|anchor)\\b" - symbol.brackets: "[(){}\\[\\]]" - symbol: "(\\*|//|/|%|\\+|-|\\^|>|>=|<|<=|!=|==|=|[\\.]{2}|!|&&|\\|\\|)" - + - constant.number: "\\b((0[xX](([0-9A-Fa-f]+\\.[0-9A-Fa-f]*)|(\\.?[0-9A-Fa-f]+))([pP][-+]?[0-9]+)?)|((([0-9]+\\.[0-9]*)|(\\.?[0-9]+))([eE][-+]?[0-9]+)?))" - constant.string: From 7ee7128e3b39ba9473e3428c61e278279dc24135 Mon Sep 17 00:00:00 2001 From: bensiv Date: Thu, 7 Nov 2024 16:04:38 +0200 Subject: [PATCH 4/4] merging openscad and scad files --- runtime/syntax/openscad.yaml | 38 +++++++++++++++++++++++--- runtime/syntax/scad.yaml | 52 ------------------------------------ 2 files changed, 35 insertions(+), 55 deletions(-) delete mode 100644 runtime/syntax/scad.yaml diff --git a/runtime/syntax/openscad.yaml b/runtime/syntax/openscad.yaml index 5fa80d04d..bff7b05c3 100644 --- a/runtime/syntax/openscad.yaml +++ b/runtime/syntax/openscad.yaml @@ -1,33 +1,58 @@ filetype: openscad +# OpenSCAD is a functional programming language used for representing +# 2D/3D models for use in the program of the same name. +# +# The following documents were used as reference material: +# https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language +# https://openscad.org/cheatsheet/index.html + detect: filename: "\\.scad$" rules: + # Keywords (statements, functions, and special OpenSCAD terms) + - statement: "\\b(abs|acos|asin|assert|atan|atan2|ceil|child|children|chr|color|concat|cos|cross|cube|cylinder|difference|dxf_cross|dxf_dim|each|echo|else|exp|floor|for|function|hull|if|import|import_dxf|intersection|intersection_for|is_bool|is_function|is_list|is_num|is_string|is_undef|len|let|linear_extrude|ln|log|lookup|max|min|minkowski|mirror|module|multmatrix|norm|offset|ord|parent_module|polygon|polyhedron|pow|projection|rands|render|resize|rotate|rotate_extrude|round|scale|search|sign|sin|sphere|sqrt|square|str|surface|tan|text|translate|union|version|version_num)\\b" + - statement: "\\b(module|function|include|use|let|for|if|else)\\b" - statement: "\\b(child|each|assign)\\b" - statement: "\\b(intersection_for|import|export)\\b" + # Functions (OpenSCAD built-in functions) - function: "\\b(circle|square|polygon|cube|sphere|cylinder|polyhedron|translate|rotate|scale|resize|mirror|multmatrix|color|offset|minkowski|hull|projection|surface|render|linear_extrude|rotate_extrude|dxf_linear_extrude|dxf_rotate_extrude)\\b" + # Constants (numbers, booleans, and other predefined constants) - constant: "\\b(pi|undef|true|false)\\b" + - constant.number: "\\b[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?|PI|inf|nan\\b" + - constant.bool: "\\b(true|false)\\b" + # Identifiers (specific variable names, special variables, and built-in OpenSCAD variables) - identifier: "\\b(\\$fn|\\$fa|\\$fs|\\$t|\\$children)\\b" - identifier: "\\b(x|y|z)\\b" - identifier: "\\b(dx|dy|dz|angle|center|height|radius|diameter|r1|r2|h1|h2|points|paths|convexity|size|thickness|anchor)\\b" - - symbol.brackets: "[(){}\\[\\]]" + # Symbols (operators, punctuation, and brackets) - symbol: "(\\*|//|/|%|\\+|-|\\^|>|>=|<|<=|!=|==|=|[\\.]{2}|!|&&|\\|\\|)" + - symbol.brackets: "[(){}\\[\\]]" - - constant.number: "\\b((0[xX](([0-9A-Fa-f]+\\.[0-9A-Fa-f]*)|(\\.?[0-9A-Fa-f]+))([pP][-+]?[0-9]+)?)|((([0-9]+\\.[0-9]*)|(\\.?[0-9]+))([eE][-+]?[0-9]+)?))" + # Special symbols that alter subtree interpretation (modifiers) + - special: "[#%!*]" + + # Special variables (beginning with a dollar sign) + - special: "\\B\\$[a-z]+\\b" + # Preprocessor directives (include and use) + - preproc: + start: "^ *(use|include) <" + end: ">;?" + + # Constants for strings and special characters - constant.string: start: "\"" end: "\"" skip: "\\\\." rules: - constant.specialChar: "\\\\([abfnrtvz\\'\"]|[0-9]{1,3}|x[0-9a-fA-F][0-9a-fA-F]|u\\{[0-9a-fA-F]+\\})" - - constant.string: start: "'" end: "'" @@ -35,6 +60,7 @@ rules: rules: - constant.specialChar: "\\\\([abfnrtvz\\'\"]|[0-9]{1,3}|x[0-9a-fA-F][0-9a-fA-F]|u\\{[0-9a-fA-F]+\\})" + # Comments (single-line and block comments) - comment.block: start: "\\/\\*" end: "\\*\\/" @@ -46,3 +72,9 @@ rules: end: "$" rules: - todo: "(TODO|NOTE|FIXME):?" + + # Handle undefined variables and constants + - constant: "\\b(undef)\\b" + + # Special handling of numbers (hexadecimal, floating point, etc.) + - constant.number: "\\b((0[xX](([0-9A-Fa-f]+\\.[0-9A-Fa-f]*)|(\\.?[0-9A-Fa-f]+))([pP][-+]?[0-9]+)?)|((([0-9]+\\.[0-9]*)|(\\.?[0-9]+))([eE][-+]?[0-9]+)?))" diff --git a/runtime/syntax/scad.yaml b/runtime/syntax/scad.yaml deleted file mode 100644 index 95094af1b..000000000 --- a/runtime/syntax/scad.yaml +++ /dev/null @@ -1,52 +0,0 @@ -filetype: OpenSCAD - -# OpenSCAD is a functional programming language used for representing -# 2D/3D models for use in the program of the same name. -# -# The following documents were used as reference material: -# https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language -# https://openscad.org/cheatsheet/index.html - -detect: - filename: "\\.scad$" - -rules: - - identifier: "\\b(function|module) +[a-z0-9_]+" - - - statement: "\\b(abs|acos|asin|assert|atan|atan2|ceil|child|children|chr|circle|color|concat|cos|cross|cube|cylinder|difference|dxf_cross|dxf_dim|each|echo|else|exp|floor|for|function|hull|if|import|import_dxf|intersection|intersection_for|is_bool|is_function|is_list|is_num|is_string|is_undef|len|let|linear_extrude|ln|log|lookup|max|min|minkowski|mirror|module|multmatrix|norm|offset|ord|parent_module|polygon|polyhedron|pow|projection|rands|render|resize|rotate|rotate_extrude|round|scale|search|sign|sin|sphere|sqrt|square|str|surface|tan|text|translate|union|version|version_num)\\b" - - - symbol: "[,\\.;:?]" - - symbol.operator: "[-+*/%^<>!=]|[<=>!]=|&&|\\|\\|" - - symbol.brackets: "[{(<>)}]|\\[|\\]" - - # modifiers that change interpretation of the subtree after it - - special: "[#%!*]" - - # special variables start with a dollar sign - - special: "\\B\\$[a-z]+\\b" - - - preproc: - start: "^ *(use|include) <" - end: ">;?" - - - constant.number: "\\b[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?|PI|inf|nan\\b" - - constant.bool: "\\b(true|false)\\b" - - constant: "\\b(undef)\\b" - - constant.string: - start: "\"" - end: "\"" - skip: "\\\\." - rules: - - constant.specialChar: "\\\\." - - - comment: - start: "//" - end: "$" - rules: - - todo: "(TODO|XXX|FIXME):?" - - - comment: - start: "/\\*" - end: "\\*/" - rules: - - todo: "(TODO|XXX|FIXME):?"