|
""" |
|
pygments.lexers.wren |
|
~~~~~~~~~~~~~~~~~~~~ |
|
|
|
Lexer for Wren. |
|
|
|
:copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS. |
|
:license: BSD, see LICENSE for details. |
|
""" |
|
|
|
import re |
|
|
|
from pygments.lexer import include, RegexLexer, words |
|
from pygments.token import Whitespace, Punctuation, Keyword, Name, Comment, \ |
|
Operator, Number, String |
|
|
|
__all__ = ['WrenLexer'] |
|
|
|
class WrenLexer(RegexLexer): |
|
""" |
|
For Wren source code, version 0.4.0. |
|
""" |
|
name = 'Wren' |
|
url = 'https://wren.io' |
|
aliases = ['wren'] |
|
filenames = ['*.wren'] |
|
version_added = '2.14' |
|
|
|
flags = re.MULTILINE | re.DOTALL |
|
|
|
tokens = { |
|
'root': [ |
|
|
|
(r'\s+', Whitespace), |
|
(r'[,\\\[\]{}]', Punctuation), |
|
|
|
|
|
|
|
|
|
(r'\(', Punctuation, 'root'), |
|
(r'\)', Punctuation, '#pop'), |
|
|
|
|
|
(words(( |
|
'as', 'break', 'class', 'construct', 'continue', 'else', |
|
'for', 'foreign', 'if', 'import', 'return', 'static', 'super', |
|
'this', 'var', 'while'), prefix = r'(?<!\.)', |
|
suffix = r'\b'), Keyword), |
|
|
|
(words(( |
|
'true', 'false', 'null'), prefix = r'(?<!\.)', |
|
suffix = r'\b'), Keyword.Constant), |
|
|
|
(words(( |
|
'in', 'is'), prefix = r'(?<!\.)', |
|
suffix = r'\b'), Operator.Word), |
|
|
|
|
|
(r'/\*', Comment.Multiline, 'comment'), |
|
(r'//.*?$', Comment.Single), |
|
(r'#.*?(\(.*?\))?$', Comment.Special), |
|
|
|
|
|
(r'[!%&*+\-./:<=>?\\^|~]+', Operator), |
|
(r'[a-z][a-zA-Z_0-9]*', Name), |
|
(r'[A-Z][a-zA-Z_0-9]*', Name.Class), |
|
(r'__[a-zA-Z_0-9]*', Name.Variable.Class), |
|
(r'_[a-zA-Z_0-9]*', Name.Variable.Instance), |
|
|
|
|
|
(r'0x[0-9a-fA-F]+', Number.Hex), |
|
(r'\d+(\.\d+)?([eE][-+]?\d+)?', Number.Float), |
|
|
|
|
|
(r'""".*?"""', String), |
|
(r'"', String, 'string'), |
|
], |
|
'comment': [ |
|
(r'/\*', Comment.Multiline, '#push'), |
|
(r'\*/', Comment.Multiline, '#pop'), |
|
(r'([^*/]|\*(?!/)|/(?!\*))+', Comment.Multiline), |
|
], |
|
'string': [ |
|
(r'"', String, '#pop'), |
|
(r'\\[\\%"0abefnrtv]', String.Escape), |
|
(r'\\x[a-fA-F0-9]{2}', String.Escape), |
|
(r'\\u[a-fA-F0-9]{4}', String.Escape), |
|
(r'\\U[a-fA-F0-9]{8}', String.Escape), |
|
|
|
(r'%\(', String.Interpol, 'interpolation'), |
|
(r'[^\\"%]+', String), |
|
], |
|
'interpolation': [ |
|
|
|
(r'\)', String.Interpol, '#pop'), |
|
include('root'), |
|
], |
|
} |
|
|