Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/openscad.py: 100%
10 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-26 07:02 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-26 07:02 +0000
1"""
2 pygments.lexers.openscad
3 ~~~~~~~~~~~~~~~~~~~~~~~~
5 Lexers for the OpenSCAD languages.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11from pygments.lexer import RegexLexer, bygroups, words, include
12from pygments.token import Text, Comment, Punctuation, Operator, Keyword, Name, Number, Whitespace, Literal, String
14__all__ = ['OpenScadLexer']
17class OpenScadLexer(RegexLexer):
18 """For openSCAD code.
20 .. versionadded:: 2.16.0
21 """
22 name = "OpenSCAD"
23 url = "https://openscad.org/"
24 aliases = ["openscad"]
25 filenames = ["*.scad"]
26 mimetypes = ["application/x-openscad"]
28 tokens = {
29 "root": [
30 (r"[^\S\n]+", Whitespace),
31 (r'//', Comment.Single, 'comment-single'),
32 (r'/\*', Comment.Multiline, 'comment-multi'),
33 (r"[{}\[\]\(\),;:]", Punctuation),
34 (r"[*!#%\-+=?/]", Operator),
35 (r"<=|<|==|!=|>=|>|&&|\|\|", Operator),
36 (r"\$(f[asn]|t|vp[rtd]|children)", Operator),
37 (r"(undef|PI)\b", Keyword.Constant),
38 (
39 r"(use|include)((?:\s|\\\\s)+)",
40 bygroups(Keyword.Namespace, Text),
41 "includes",
42 ),
43 (r"(module)(\s*)([^\s\(]+)",
44 bygroups(Keyword.Namespace, Whitespace, Name.Namespace)),
45 (r"(function)(\s*)([^\s\(]+)",
46 bygroups(Keyword.Declaration, Whitespace, Name.Function)),
47 (words(("true", "false"), prefix=r"\b", suffix=r"\b"), Literal),
48 (words((
49 "function", "module", "include", "use", "for",
50 "intersection_for", "if", "else", "return"
51 ), prefix=r"\b", suffix=r"\b"), Keyword
52 ),
53 (words((
54 "circle", "square", "polygon", "text", "sphere", "cube",
55 "cylinder", "polyhedron", "translate", "rotate", "scale",
56 "resize", "mirror", "multmatrix", "color", "offset", "hull",
57 "minkowski", "union", "difference", "intersection", "abs",
58 "sign", "sin", "cos", "tan", "acos", "asin", "atan", "atan2",
59 "floor", "round", "ceil", "ln", "log", "pow", "sqrt", "exp",
60 "rands", "min", "max", "concat", "lookup", "str", "chr",
61 "search", "version", "version_num", "norm", "cross",
62 "parent_module", "echo", "import", "import_dxf",
63 "dxf_linear_extrude", "linear_extrude", "rotate_extrude",
64 "surface", "projection", "render", "dxf_cross",
65 "dxf_dim", "let", "assign", "len"
66 ), prefix=r"\b", suffix=r"\b"),
67 Name.Builtin
68 ),
69 (r"\bchildren\b", Name.Builtin.Pseudo),
70 (r'""".*?"""', String.Double),
71 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
72 (r"-?\d+(\.\d+)?(e[+-]?\d+)?", Number),
73 (r"\w+", Name),
74 ],
75 "includes": [
76 (
77 r"(<)([^>]*)(>)",
78 bygroups(Punctuation, Comment.PreprocFile, Punctuation),
79 ),
80 ],
81 'comment': [
82 (r':param: [a-zA-Z_]\w*|:returns?:|(FIXME|MARK|TODO):',
83 Comment.Special)
84 ],
85 'comment-single': [
86 (r'\n', Text, '#pop'),
87 include('comment'),
88 (r'[^\n]+', Comment.Single)
89 ],
90 'comment-multi': [
91 include('comment'),
92 (r'[^*/]+', Comment.Multiline),
93 (r'/\*', Comment.Multiline, '#push'),
94 (r'\*/', Comment.Multiline, '#pop'),
95 (r'[*/]', Comment.Multiline)
96 ],
97 }