-
Notifications
You must be signed in to change notification settings - Fork 743
Add OpenSCAD lexer #2449
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
Merged
Merged
Add OpenSCAD lexer #2449
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fc5c0cc
add OpenSCAD lexer (#886)
nantipov 61075c0
Format and doc adjustments (#886)
nantipov c226d2d
Documentation; imports optimization; regex adjustments (#886)
nantipov 93bd376
Adjust regex for comments; handle the children builtin (#886)
nantipov d2c84bf
Single whitespace expression (#886)
nantipov File filter
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
commit fc5c0cceea8682be51cf27a75dee9d662af75d4f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
jeanas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
tokens = { | ||
"root": [ | ||
(r"[^\S\n]+", Text), | ||
(r"\n", Text), | ||
jeanas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
(r"//(\n|[\w\W]*?[^\\]\n)", Comment.Singleline), | ||
nantipov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
(r"/(\\\n)?[*][\w\W]*?[*](\\\n)?/", Comment.Mutliline), | ||
nantipov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
(r"/(\\\n)?[*][\w\W]*", Comment.Mutliline), | ||
jeanas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
(r"[{}\[\]\(\),;:]", Punctuation), | ||
(r"[*!#%\-+=?/]", Operator), | ||
(r"<=|<|==|!=|>=|>|&&|\|\|", Operator), | ||
jeanas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
(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), | ||
), | ||
nantipov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
( | ||
r"(function)(\s*)([^\s\(]+)", | ||
bygroups(Keyword.Declaration, Text, Name.Function), | ||
), | ||
nantipov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
(r"\b(true|false)\b", Literal), | ||
( | ||
r"\b(function|module|include|use|for|intersection_for|if|else|return)\b", | ||
Keyword, | ||
), | ||
nantipov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
( | ||
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, | ||
jeanas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
), | ||
(r"\bchildren\b", Name.Builtin.Pseudo), | ||
(r""(\\\\|\\"|[^"])*"", Literal.StringDouble), | ||
nantipov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
(r"-?\d+(\.\d+)?(e[+-]?\d+)?", Literal.Number), | ||
jeanas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
(r"[a-zA-Z_]\w*", Name), | ||
jeanas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
], | ||
"includes": [ | ||
( | ||
r"(<)([^>]*)(>)", | ||
jeanas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
bygroups(Punctuation, Comment.PreprocFile, Punctuation), | ||
), | ||
], | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.