|
""" |
|
pygments.lexers.savi |
|
~~~~~~~~~~~~~~~~~~~~ |
|
|
|
Lexer for Savi. |
|
|
|
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS. |
|
:license: BSD, see LICENSE for details. |
|
""" |
|
|
|
from pygments.lexer import RegexLexer, bygroups, include |
|
from pygments.token import Whitespace, Keyword, Name, String, Number, \ |
|
Operator, Punctuation, Comment, Generic, Error |
|
|
|
__all__ = ['SaviLexer'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SaviLexer(RegexLexer): |
|
""" |
|
For Savi source code. |
|
|
|
.. versionadded: 2.10 |
|
""" |
|
|
|
name = 'Savi' |
|
url = 'https://github.com/savi-lang/savi' |
|
aliases = ['savi'] |
|
filenames = ['*.savi'] |
|
version_added = '' |
|
|
|
tokens = { |
|
"root": [ |
|
|
|
(r'//.*?$', Comment.Single), |
|
|
|
|
|
(r'::.*?$', Comment.Single), |
|
|
|
|
|
(r'(\')(\w+)(?=[^\'])', bygroups(Operator, Name)), |
|
|
|
|
|
(r'\w?"', String.Double, "string.double"), |
|
|
|
|
|
(r"'", String.Char, "string.char"), |
|
|
|
|
|
(r'(_?[A-Z]\w*)', Name.Class), |
|
|
|
|
|
(r'(\.)(\s*)(_?[A-Z]\w*)', bygroups(Punctuation, Whitespace, Name.Class)), |
|
|
|
|
|
(r'^([ \t]*)(:\w+)', |
|
bygroups(Whitespace, Name.Tag), |
|
"decl"), |
|
|
|
|
|
(r'((\w+|\+|\-|\*)\!)', Generic.Deleted), |
|
|
|
|
|
(r'\b\d([\d_]*(\.[\d_]+)?)\b', Number), |
|
|
|
|
|
(r'\b0x([0-9a-fA-F_]+)\b', Number.Hex), |
|
|
|
|
|
(r'\b0b([01_]+)\b', Number.Bin), |
|
|
|
|
|
(r'\w+(?=\()', Name.Function), |
|
|
|
|
|
(r'(\.)(\s*)(\w+)', bygroups(Punctuation, Whitespace, Name.Function)), |
|
|
|
|
|
(r'(@)(\w+)', bygroups(Punctuation, Name.Function)), |
|
|
|
|
|
(r'\(', Punctuation, "root"), |
|
(r'\)', Punctuation, "#pop"), |
|
|
|
|
|
(r'\{', Punctuation, "root"), |
|
(r'\}', Punctuation, "#pop"), |
|
|
|
|
|
(r'\[', Punctuation, "root"), |
|
(r'(\])(\!)', bygroups(Punctuation, Generic.Deleted), "#pop"), |
|
(r'\]', Punctuation, "#pop"), |
|
|
|
|
|
(r'[,;:\.@]', Punctuation), |
|
|
|
|
|
(r'(\|\>)', Operator), |
|
|
|
|
|
(r'(\&\&|\|\||\?\?|\&\?|\|\?|\.\?)', Operator), |
|
|
|
|
|
(r'(\<\=\>|\=\~|\=\=|\<\=|\>\=|\<|\>)', Operator), |
|
|
|
|
|
(r'(\+|\-|\/|\*|\%)', Operator), |
|
|
|
|
|
(r'(\=)', Operator), |
|
|
|
|
|
(r'(\!|\<\<|\<|\&|\|)', Operator), |
|
|
|
|
|
(r'\b\w+\b', Name), |
|
|
|
|
|
(r'[ \t\r]+\n*|\n+', Whitespace), |
|
], |
|
|
|
|
|
"decl": [ |
|
(r'\b[a-z_]\w*\b(?!\!)', Keyword.Declaration), |
|
(r':', Punctuation, "#pop"), |
|
(r'\n', Whitespace, "#pop"), |
|
include("root"), |
|
], |
|
|
|
|
|
"string.double": [ |
|
(r'\\\(', String.Interpol, "string.interpolation"), |
|
(r'\\u[0-9a-fA-F]{4}', String.Escape), |
|
(r'\\x[0-9a-fA-F]{2}', String.Escape), |
|
(r'\\[bfnrt\\\']', String.Escape), |
|
(r'\\"', String.Escape), |
|
(r'"', String.Double, "#pop"), |
|
(r'[^\\"]+', String.Double), |
|
(r'.', Error), |
|
], |
|
|
|
|
|
"string.char": [ |
|
(r'\\u[0-9a-fA-F]{4}', String.Escape), |
|
(r'\\x[0-9a-fA-F]{2}', String.Escape), |
|
(r'\\[bfnrt\\\']', String.Escape), |
|
(r"\\'", String.Escape), |
|
(r"'", String.Char, "#pop"), |
|
(r"[^\\']+", String.Char), |
|
(r'.', Error), |
|
], |
|
|
|
|
|
"string.interpolation": [ |
|
(r"\)", String.Interpol, "#pop"), |
|
include("root"), |
|
] |
|
} |
|
|