|
| 1 | +""" |
| 2 | + pygments.lexers.openscad |
| 3 | + ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 4 | +
|
| 5 | + Lexers for the OpenSCAD languages. |
| 6 | +
|
| 7 | + :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. |
| 8 | + :license: BSD, see LICENSE for details. |
| 9 | +""" |
| 10 | + |
| 11 | +from pygments.lexer import RegexLexer, bygroups |
| 12 | +from pygments.token import Text, Comment, Punctuation, Operator, Keyword, Name, Literal |
| 13 | + |
| 14 | +__all__ = ['OpenScadLexer'] |
| 15 | + |
| 16 | + |
| 17 | +class OpenScadLexer(RegexLexer): |
| 18 | + name = "OpenSCAD" |
| 19 | + aliases = ["openscad"] |
| 20 | + filenames = ["*.scad"] |
| 21 | + |
| 22 | + tokens = { |
| 23 | + "root": [ |
| 24 | + (r"[^\S\n]+", Text), |
| 25 | + (r"\n", Text), |
| 26 | + (r"//(\n|[\w\W]*?[^\\]\n)", Comment.Singleline), |
| 27 | + (r"/(\\\n)?[*][\w\W]*?[*](\\\n)?/", Comment.Mutliline), |
| 28 | + (r"/(\\\n)?[*][\w\W]*", Comment.Mutliline), |
| 29 | + (r"[{}\[\]\(\),;:]", Punctuation), |
| 30 | + (r"[*!#%\-+=?/]", Operator), |
| 31 | + (r"<=|<|==|!=|>=|>|&&|\|\|", Operator), |
| 32 | + (r"\$(f[asn]|t|vp[rtd]|children)", Operator), |
| 33 | + (r"(undef|PI)\b", Keyword.Constant), |
| 34 | + ( |
| 35 | + r"(use|include)((?:\s|\\\\s)+)", |
| 36 | + bygroups(Keyword.Namespace, Text), |
| 37 | + "includes", |
| 38 | + ), |
| 39 | + ( |
| 40 | + r"(module)(\s*)([^\s\(]+)", |
| 41 | + bygroups(Keyword.Namespace, Text, Name.Namespace), |
| 42 | + ), |
| 43 | + ( |
| 44 | + r"(function)(\s*)([^\s\(]+)", |
| 45 | + bygroups(Keyword.Declaration, Text, Name.Function), |
| 46 | + ), |
| 47 | + (r"\b(true|false)\b", Literal), |
| 48 | + ( |
| 49 | + r"\b(function|module|include|use|for|intersection_for|if|else|return)\b", |
| 50 | + Keyword, |
| 51 | + ), |
| 52 | + ( |
| 53 | + r"\b(circle|square|polygon|text|sphere|cube|cylinder|polyhedron|translate|rotate|scale|resize|mirror|multmatrix|color|offset|hull|minkowski|union|difference|intersection|abs|sign|sin|cos|tan|acos|asin|atan|atan2|floor|round|ceil|ln|log|pow|sqrt|exp|rands|min|max|concat|lookup|str|chr|search|version|version_num|norm|cross|parent_module|echo|import|import_dxf|dxf_linear_extrude|linear_extrude|rotate_extrude|surface|projection|render|dxf_cross|dxf_dim|let|assign|len)\b", |
| 54 | + Name.Builtin, |
| 55 | + ), |
| 56 | + (r"\bchildren\b", Name.Builtin.Pseudo), |
| 57 | + (r""(\\\\|\\"|[^"])*"", Literal.StringDouble), |
| 58 | + (r"-?\d+(\.\d+)?(e[+-]?\d+)?", Literal.Number), |
| 59 | + (r"[a-zA-Z_]\w*", Name), |
| 60 | + ], |
| 61 | + "includes": [ |
| 62 | + ( |
| 63 | + r"(<)([^>]*)(>)", |
| 64 | + bygroups(Punctuation, Comment.PreprocFile, Punctuation), |
| 65 | + ), |
| 66 | + ], |
| 67 | + } |
0 commit comments