Skip to content

Commit

Permalink
Add OpenSCAD syntax highlighting support. (#413)
Browse files Browse the repository at this point in the history
* WIP: added early/partial OpenSCAD syntax highlighing.

* Added manifest entry and some keywords.

* WIP: added new patterns and tidied up keywords.

* Updated last patterns.

* Added entry to meta-languages package.

* Bumped meta_languages version.

* Update plugins/language_openscad.lua

Co-authored-by: Guldoman <[email protected]>

* Update plugins/language_openscad.lua

Co-authored-by: Guldoman <[email protected]>

* Update manifest.json

---------

Co-authored-by: Guldoman <[email protected]>
  • Loading branch information
PerilousBooklet and Guldoman authored Apr 20, 2024
1 parent 6899123 commit 01d460b
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 1 deletion.
11 changes: 10 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"language_nix": {},
"language_objc": {},
"language_odin": {},
"language_openscad": {},
"language_perl": {},
"language_php": {},
"language_pico8": {},
Expand Down Expand Up @@ -162,7 +163,7 @@
"id": "meta_languages",
"mod_version": "3",
"type": "meta",
"version": "0.1.13"
"version": "0.1.14"
},
{
"description": "Align multiple carets and selections *([clip](https://user-images.githubusercontent.com/2798487/165631951-532f8d24-d596-4dd0-9d21-ff53c71ed32f.mp4))*",
Expand Down Expand Up @@ -1309,6 +1310,14 @@
],
"version": "0.1"
},
{
"description": "Syntax for the [OpenSCAD](https://openscad.org/) programming language",
"version": "0.1",
"path": "plugins/language_openscad.lua",
"id": "language_openscad",
"mod_version": "3",
"tags": ["language"]
},
{
"description": "Syntax for the [Perl](https://perl.org) programming language",
"id": "language_perl",
Expand Down
116 changes: 116 additions & 0 deletions plugins/language_openscad.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
-- mod-version:3
local syntax = require "core.syntax"

syntax.add {
name = "OpenSCAD",
files = {"%.scad$"},
comment = "//",
block_comment = { "/*", "*/" },
patterns = {
{ pattern = "//.*", type = "comment" }, -- Single-line comment
{ pattern = { "/%*", "%*/" }, type = "comment" }, -- Multi-line comment
{ pattern = { '"', '"', '\\' }, type = "string" }, -- String, double quotes
{ pattern = { "'", "'", '\\' }, type = "string" }, -- String, apices
{ pattern = "-?0x%x+", type = "number" }, -- ?
{ pattern = "-?%d+[%d%.eE]*[a-zA-Z]?", type = "number" }, -- ?
{ pattern = "-?%.?%d+", type = "number" }, -- ?
{ pattern = "[%+%-=/%*%^%%<>!~|&%?%:]", type = "operator" }, -- Operators
{ pattern = "[%a_][%w_]*%f[(]", type = "function" }, -- Functions
{ regex = "\\$[a-zA-Z]+", type = "keyword" }, -- Special variables
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
-- ?
["var"] = "keyword",
["module"] = "keyword",
["function"] = "keyword",
["include"] = "keyword",
["use"] = "keyword",
-- Constants
["undef"] = "keyword2",
["PI"] = "keyword2",
-- 2D
["circle"] = "keyword",
["square"] = "keyword",
["polygon"] = "keyword",
["text"] = "keyword",
["import"] = "keyword",
["projection"] = "keyword",
-- 3D
["sphere"] = "keyword",
["cube"] = "keyword",
["cylinder"] = "keyword",
["polyhedron"] = "keyword",
["surface"] = "keyword",
-- Transformations
["linear_extrude"] = "keyword",
["rotate_extrude"] = "keyword",
["translate"] = "keyword",
["rotate"] = "keyword",
["scale"] = "keyword",
["resize"] = "keyword",
["mirror"] = "keyword",
["multmatrix"] = "keyword",
["color"] = "keyword",
["offset"] = "keyword",
["hull"] = "keyword",
["minkowski"] = "keyword",
-- Boolean Operations
["union"] = "keyword",
["difference"] = "keyword",
["intersection"] = "keyword",
-- Flow Control
["for"] = "keyword",
["each"] = "keyword",
-- Type Test Functions
["is_undef"] = "function",
["is_bool"] = "function",
["is_num"] = "function",
["is_string"] = "function",
["is_list"] = "function",
["is_function"] = "function",
-- Other
["echo"] = "keyword",
["render"] = "keyword",
["children"] = "keyword",
["assert"] = "keyword",
-- Functions
["concat"] = "function",
["lookup"] = "function",
["str"] = "function",
["chr"] = "function",
["ord"] = "function",
["search"] = "function",
["version"] = "function",
["version_num"] = "function",
["parent_module"] = "function",
-- Math Functions
["abs"] = "keyword",
["sign"] = "keyword",
["sin"] = "keyword",
["cos"] = "keyword",
["tan"] = "keyword",
["acos"] = "keyword",
["asin"] = "keyword",
["atan"] = "keyword",
["atan2"] = "keyword",
["floor"] = "keyword",
["round"] = "keyword",
["ceil"] = "keyword",
["ln"] = "keyword",
["len"] = "keyword",
["let"] = "keyword",
["log"] = "keyword",
["pow"] = "keyword",
["sqrt"] = "keyword",
["exp"] = "keyword",
["rands"] = "keyword",
["min"] = "keyword",
["max"] = "keyword",
["norm"] = "keyword",
["cross"] = "keyword",
-- Literals
["true"] = "literal",
["false"] = "literal",
}
}

0 comments on commit 01d460b

Please sign in to comment.