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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add OpenSCAD lexer (#886)
  • Loading branch information
nantipov committed Jun 4, 2023
commit fc5c0cceea8682be51cf27a75dee9d662af75d4f
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,6 @@ Other contributors, listed alphabetically, are:
* Marc Auberer -- Spice lexer
* Amr Hesham -- Carbon lexer
* diskdance -- Wikitext lexer
* Nikolay Antipov -- OpenSCAD lexer

Many thanks for all contributions!
1 change: 1 addition & 0 deletions pygments/lexers/_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@
'OocLexer': ('pygments.lexers.ooc', 'Ooc', ('ooc',), ('*.ooc',), ('text/x-ooc',)),
'OpaLexer': ('pygments.lexers.ml', 'Opa', ('opa',), ('*.opa',), ('text/x-opa',)),
'OpenEdgeLexer': ('pygments.lexers.business', 'OpenEdge ABL', ('openedge', 'abl', 'progress'), ('*.p', '*.cls'), ('text/x-openedge', 'application/x-openedge')),
'OpenScadLexer': ('pygments.lexers.openscad', 'OpenSCAD', ('openscad',), ('*.scad',), ()),
'OutputLexer': ('pygments.lexers.special', 'Text output', ('output',), (), ()),
'PacmanConfLexer': ('pygments.lexers.configs', 'PacmanConf', ('pacmanconf',), ('pacman.conf',), ()),
'PanLexer': ('pygments.lexers.dsls', 'Pan', ('pan',), ('*.pan',), ()),
Expand Down
67 changes: 67 additions & 0 deletions pygments/lexers/openscad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
pygments.lexers.openscad
~~~~~~~~~~~~~~~~~~~~~~~~

Lexers for the OpenSCAD languages.

:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""

from pygments.lexer import RegexLexer, bygroups
from pygments.token import Text, Comment, Punctuation, Operator, Keyword, Name, Literal

__all__ = ['OpenScadLexer']


class OpenScadLexer(RegexLexer):
name = "OpenSCAD"
aliases = ["openscad"]
filenames = ["*.scad"]

tokens = {
"root": [
(r"[^\S\n]+", Text),
(r"\n", Text),
(r"//(\n|[\w\W]*?[^\\]\n)", Comment.Singleline),
(r"/(\\\n)?[*][\w\W]*?[*](\\\n)?/", Comment.Mutliline),
(r"/(\\\n)?[*][\w\W]*", Comment.Mutliline),
(r"[{}\[\]\(\),;:]", Punctuation),
(r"[*!#%\-+=?/]", Operator),
(r"<=|<|==|!=|>=|>|&&|\|\|", Operator),
(r"\$(f[asn]|t|vp[rtd]|children)", Operator),
(r"(undef|PI)\b", Keyword.Constant),
(
r"(use|include)((?:\s|\\\\s)+)",
bygroups(Keyword.Namespace, Text),
"includes",
),
(
r"(module)(\s*)([^\s\(]+)",
bygroups(Keyword.Namespace, Text, Name.Namespace),
),
(
r"(function)(\s*)([^\s\(]+)",
bygroups(Keyword.Declaration, Text, Name.Function),
),
(r"\b(true|false)\b", Literal),
(
r"\b(function|module|include|use|for|intersection_for|if|else|return)\b",
Keyword,
),
(
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",
Name.Builtin,
),
(r"\bchildren\b", Name.Builtin.Pseudo),
(r""(\\\\|\\"|[^"])*"", Literal.StringDouble),
(r"-?\d+(\.\d+)?(e[+-]?\d+)?", Literal.Number),
(r"[a-zA-Z_]\w*", Name),
],
"includes": [
(
r"(<)([^>]*)(>)",
bygroups(Punctuation, Comment.PreprocFile, Punctuation),
),
],
}
Loading