Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for the OpenSCAD language #3532

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions runtime/plugins/comment/comment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
80 changes: 80 additions & 0 deletions runtime/syntax/openscad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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"

# Symbols (operators, punctuation, and brackets)
- symbol: "(\\*|//|/|%|\\+|-|\\^|>|>=|<|<=|!=|==|=|[\\.]{2}|!|&&|\\|\\|)"
- symbol.brackets: "[(){}\\[\\]]"

# 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: "'"
skip: "\\\\."
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: "\\*\\/"
rules:
- todo: "(TODO|NOTE|FIXME):?"

- comment:
start: "\\/\\/|\\#"
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]+)?))"
52 changes: 0 additions & 52 deletions runtime/syntax/scad.yaml

This file was deleted.