Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc5c0cc

Browse files
committed
add OpenSCAD lexer (#886)
1 parent 94518b4 commit fc5c0cc

File tree

4 files changed

+439
-0
lines changed

4 files changed

+439
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,6 @@ Other contributors, listed alphabetically, are:
267267
* Marc Auberer -- Spice lexer
268268
* Amr Hesham -- Carbon lexer
269269
* diskdance -- Wikitext lexer
270+
* Nikolay Antipov -- OpenSCAD lexer
270271

271272
Many thanks for all contributions!

pygments/lexers/_mapping.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@
353353
'OocLexer': ('pygments.lexers.ooc', 'Ooc', ('ooc',), ('*.ooc',), ('text/x-ooc',)),
354354
'OpaLexer': ('pygments.lexers.ml', 'Opa', ('opa',), ('*.opa',), ('text/x-opa',)),
355355
'OpenEdgeLexer': ('pygments.lexers.business', 'OpenEdge ABL', ('openedge', 'abl', 'progress'), ('*.p', '*.cls'), ('text/x-openedge', 'application/x-openedge')),
356+
'OpenScadLexer': ('pygments.lexers.openscad', 'OpenSCAD', ('openscad',), ('*.scad',), ()),
356357
'OutputLexer': ('pygments.lexers.special', 'Text output', ('output',), (), ()),
357358
'PacmanConfLexer': ('pygments.lexers.configs', 'PacmanConf', ('pacmanconf',), ('pacman.conf',), ()),
358359
'PanLexer': ('pygments.lexers.dsls', 'Pan', ('pan',), ('*.pan',), ()),

pygments/lexers/openscad.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)