Add files using upload-large-folder tool
Browse files- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/agile.py +25 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/arturo.py +249 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/bqn.py +112 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/configs.py +1433 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/factor.py +363 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/fantom.py +251 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/functional.py +21 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/futhark.py +105 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/gdscript.py +189 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/graphics.py +794 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/nit.py +63 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/procfile.py +41 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/rell.py +68 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/rust.py +222 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/shell.py +902 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/smalltalk.py +194 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/sql.py +1111 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/typoscript.py +216 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/vyper.py +140 -0
- LTA_openwebtext_dualt/runs_transfer/lta_owt_distilbert_len1024_init_lm1b1m_posemb_repeat_fully_c1024_adamw_gbs512_4gpu_20k_20260514_120045/args.json +158 -0
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/agile.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.agile
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Just export lexer classes previously contained in this module.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
# ruff: noqa: F401
|
| 12 |
+
|
| 13 |
+
from pygments.lexers.lisp import SchemeLexer
|
| 14 |
+
from pygments.lexers.jvm import IokeLexer, ClojureLexer
|
| 15 |
+
from pygments.lexers.python import PythonLexer, PythonConsoleLexer, \
|
| 16 |
+
PythonTracebackLexer, Python3Lexer, Python3TracebackLexer, DgLexer
|
| 17 |
+
from pygments.lexers.ruby import RubyLexer, RubyConsoleLexer, FancyLexer
|
| 18 |
+
from pygments.lexers.perl import PerlLexer, Perl6Lexer
|
| 19 |
+
from pygments.lexers.d import CrocLexer, MiniDLexer
|
| 20 |
+
from pygments.lexers.iolang import IoLexer
|
| 21 |
+
from pygments.lexers.tcl import TclLexer
|
| 22 |
+
from pygments.lexers.factor import FactorLexer
|
| 23 |
+
from pygments.lexers.scripting import LuaLexer, MoonScriptLexer
|
| 24 |
+
|
| 25 |
+
__all__ = []
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/arturo.py
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from pygments.lexer import RegexLexer, bygroups, do_insertions, include, \
|
| 12 |
+
this, using, words
|
| 13 |
+
from pygments.token import Comment, Error, Keyword, Name, Number, Operator, \
|
| 14 |
+
Punctuation, String, Text
|
| 15 |
+
|
| 16 |
+
from pygments.util import ClassNotFound, get_bool_opt
|
| 17 |
+
|
| 18 |
+
__all__ = ['ArturoLexer']
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class ArturoLexer(RegexLexer):
|
| 22 |
+
"""
|
| 23 |
+
For Arturo source code.
|
| 24 |
+
|
| 25 |
+
See `Arturo's Github <https://github.com/arturo-lang/arturo>`_
|
| 26 |
+
and `Arturo's Website <https://arturo-lang.io/>`_.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
name = 'Arturo'
|
| 30 |
+
aliases = ['arturo', 'art']
|
| 31 |
+
filenames = ['*.art']
|
| 32 |
+
url = 'https://arturo-lang.io/'
|
| 33 |
+
version_added = '2.14'
|
| 34 |
+
|
| 35 |
+
def __init__(self, **options):
|
| 36 |
+
self.handle_annotateds = get_bool_opt(options, 'handle_annotateds',
|
| 37 |
+
True)
|
| 38 |
+
RegexLexer.__init__(self, **options)
|
| 39 |
+
|
| 40 |
+
def handle_annotated_strings(self, match):
|
| 41 |
+
"""Adds syntax from another languages inside annotated strings
|
| 42 |
+
|
| 43 |
+
match args:
|
| 44 |
+
1:open_string,
|
| 45 |
+
2:exclamation_mark,
|
| 46 |
+
3:lang_name,
|
| 47 |
+
4:space_or_newline,
|
| 48 |
+
5:code,
|
| 49 |
+
6:close_string
|
| 50 |
+
"""
|
| 51 |
+
from pygments.lexers import get_lexer_by_name
|
| 52 |
+
|
| 53 |
+
# Header's section
|
| 54 |
+
yield match.start(1), String.Double, match.group(1)
|
| 55 |
+
yield match.start(2), String.Interpol, match.group(2)
|
| 56 |
+
yield match.start(3), String.Interpol, match.group(3)
|
| 57 |
+
yield match.start(4), Text.Whitespace, match.group(4)
|
| 58 |
+
|
| 59 |
+
lexer = None
|
| 60 |
+
if self.handle_annotateds:
|
| 61 |
+
try:
|
| 62 |
+
lexer = get_lexer_by_name(match.group(3).strip())
|
| 63 |
+
except ClassNotFound:
|
| 64 |
+
pass
|
| 65 |
+
code = match.group(5)
|
| 66 |
+
|
| 67 |
+
if lexer is None:
|
| 68 |
+
yield match.group(5), String, code
|
| 69 |
+
else:
|
| 70 |
+
yield from do_insertions([], lexer.get_tokens_unprocessed(code))
|
| 71 |
+
|
| 72 |
+
yield match.start(6), String.Double, match.group(6)
|
| 73 |
+
|
| 74 |
+
tokens = {
|
| 75 |
+
'root': [
|
| 76 |
+
(r';.*?$', Comment.Single),
|
| 77 |
+
(r'^((\s#!)|(#!)).*?$', Comment.Hashbang),
|
| 78 |
+
|
| 79 |
+
# Constants
|
| 80 |
+
(words(('false', 'true', 'maybe'), # boolean
|
| 81 |
+
suffix=r'\b'), Name.Constant),
|
| 82 |
+
(words(('this', 'init'), # class related keywords
|
| 83 |
+
prefix=r'\b', suffix=r'\b\??:?'), Name.Builtin.Pseudo),
|
| 84 |
+
(r'`.`', String.Char), # character
|
| 85 |
+
(r'\\\w+\b\??:?', Name.Property), # array index
|
| 86 |
+
(r'#\w+', Name.Constant), # color
|
| 87 |
+
(r'\b[0-9]+\.[0-9]+', Number.Float), # float
|
| 88 |
+
(r'\b[0-9]+', Number.Integer), # integer
|
| 89 |
+
(r'\w+\b\??:', Name.Label), # label
|
| 90 |
+
# Note: Literals can be labeled too
|
| 91 |
+
(r'\'(?:\w+\b\??:?)', Keyword.Declaration), # literal
|
| 92 |
+
(r'\:\w+', Keyword.Type), # type
|
| 93 |
+
# Note: Attributes can be labeled too
|
| 94 |
+
(r'\.\w+\??:?', Name.Attribute), # attributes
|
| 95 |
+
|
| 96 |
+
# Switch structure
|
| 97 |
+
(r'(\()(.*?)(\)\?)',
|
| 98 |
+
bygroups(Punctuation, using(this), Punctuation)),
|
| 99 |
+
|
| 100 |
+
# Single Line Strings
|
| 101 |
+
(r'"', String.Double, 'inside-simple-string'),
|
| 102 |
+
(r'»', String.Single, 'inside-smart-string'),
|
| 103 |
+
(r'«««', String.Double, 'inside-safe-string'),
|
| 104 |
+
(r'\{\/', String.Single, 'inside-regex-string'),
|
| 105 |
+
|
| 106 |
+
# Multi Line Strings
|
| 107 |
+
(r'\{\:', String.Double, 'inside-curly-verb-string'),
|
| 108 |
+
(r'(\{)(\!)(\w+)(\s|\n)([\w\W]*?)(^\})', handle_annotated_strings),
|
| 109 |
+
(r'\{', String.Single, 'inside-curly-string'),
|
| 110 |
+
(r'\-{3,}', String.Single, 'inside-eof-string'),
|
| 111 |
+
|
| 112 |
+
include('builtin-functions'),
|
| 113 |
+
|
| 114 |
+
# Operators
|
| 115 |
+
(r'[()[\],]', Punctuation),
|
| 116 |
+
(words(('->', '==>', '|', '::', '@', '#', # sugar syntax
|
| 117 |
+
'$', '&', '!', '!!', './')), Name.Decorator),
|
| 118 |
+
(words(('<:', ':>', ':<', '>:', '<\\', '<>', '<', '>',
|
| 119 |
+
'ø', '∞',
|
| 120 |
+
'+', '-', '*', '~', '=', '^', '%', '/', '//',
|
| 121 |
+
'==>', '<=>', '<==>',
|
| 122 |
+
'=>>', '<<=>>', '<<==>>',
|
| 123 |
+
'-->', '<->', '<-->',
|
| 124 |
+
'=|', '|=', '-:', ':-',
|
| 125 |
+
'_', '.', '..', '\\')), Operator),
|
| 126 |
+
|
| 127 |
+
(r'\b\w+', Name),
|
| 128 |
+
(r'\s+', Text.Whitespace),
|
| 129 |
+
(r'.+$', Error),
|
| 130 |
+
],
|
| 131 |
+
|
| 132 |
+
'inside-interpol': [
|
| 133 |
+
(r'\|', String.Interpol, '#pop'),
|
| 134 |
+
(r'[^|]+', using(this)),
|
| 135 |
+
],
|
| 136 |
+
'inside-template': [
|
| 137 |
+
(r'\|\|\>', String.Interpol, '#pop'),
|
| 138 |
+
(r'[^|]+', using(this)),
|
| 139 |
+
],
|
| 140 |
+
'string-escape': [
|
| 141 |
+
(words(('\\\\', '\\n', '\\t', '\\"')), String.Escape),
|
| 142 |
+
],
|
| 143 |
+
|
| 144 |
+
'inside-simple-string': [
|
| 145 |
+
include('string-escape'),
|
| 146 |
+
(r'\|', String.Interpol, 'inside-interpol'), # Interpolation
|
| 147 |
+
(r'\<\|\|', String.Interpol, 'inside-template'), # Templates
|
| 148 |
+
(r'"', String.Double, '#pop'), # Closing Quote
|
| 149 |
+
(r'[^|"]+', String) # String Content
|
| 150 |
+
],
|
| 151 |
+
'inside-smart-string': [
|
| 152 |
+
include('string-escape'),
|
| 153 |
+
(r'\|', String.Interpol, 'inside-interpol'), # Interpolation
|
| 154 |
+
(r'\<\|\|', String.Interpol, 'inside-template'), # Templates
|
| 155 |
+
(r'\n', String.Single, '#pop'), # Closing Quote
|
| 156 |
+
(r'[^|\n]+', String) # String Content
|
| 157 |
+
],
|
| 158 |
+
'inside-safe-string': [
|
| 159 |
+
include('string-escape'),
|
| 160 |
+
(r'\|', String.Interpol, 'inside-interpol'), # Interpolation
|
| 161 |
+
(r'\<\|\|', String.Interpol, 'inside-template'), # Templates
|
| 162 |
+
(r'»»»', String.Double, '#pop'), # Closing Quote
|
| 163 |
+
(r'[^|»]+', String) # String Content
|
| 164 |
+
],
|
| 165 |
+
'inside-regex-string': [
|
| 166 |
+
(r'\\[sSwWdDbBZApPxucItnvfr0]+', String.Escape),
|
| 167 |
+
(r'\|', String.Interpol, 'inside-interpol'), # Interpolation
|
| 168 |
+
(r'\<\|\|', String.Interpol, 'inside-template'), # Templates
|
| 169 |
+
(r'\/\}', String.Single, '#pop'), # Closing Quote
|
| 170 |
+
(r'[^|\/]+', String.Regex), # String Content
|
| 171 |
+
],
|
| 172 |
+
'inside-curly-verb-string': [
|
| 173 |
+
include('string-escape'),
|
| 174 |
+
(r'\|', String.Interpol, 'inside-interpol'), # Interpolation
|
| 175 |
+
(r'\<\|\|', String.Interpol, 'inside-template'), # Templates
|
| 176 |
+
(r'\:\}', String.Double, '#pop'), # Closing Quote
|
| 177 |
+
(r'[^|<:]+', String), # String Content
|
| 178 |
+
],
|
| 179 |
+
'inside-curly-string': [
|
| 180 |
+
include('string-escape'),
|
| 181 |
+
(r'\|', String.Interpol, 'inside-interpol'), # Interpolation
|
| 182 |
+
(r'\<\|\|', String.Interpol, 'inside-template'), # Templates
|
| 183 |
+
(r'\}', String.Single, '#pop'), # Closing Quote
|
| 184 |
+
(r'[^|<}]+', String), # String Content
|
| 185 |
+
],
|
| 186 |
+
'inside-eof-string': [
|
| 187 |
+
include('string-escape'),
|
| 188 |
+
(r'\|', String.Interpol, 'inside-interpol'), # Interpolation
|
| 189 |
+
(r'\<\|\|', String.Interpol, 'inside-template'), # Templates
|
| 190 |
+
(r'\Z', String.Single, '#pop'), # Closing Quote
|
| 191 |
+
(r'[^|<]+', String), # String Content
|
| 192 |
+
],
|
| 193 |
+
|
| 194 |
+
'builtin-functions': [
|
| 195 |
+
(words((
|
| 196 |
+
'all', 'and', 'any', 'ascii', 'attr', 'attribute',
|
| 197 |
+
'attributeLabel', 'binary', 'block' 'char', 'contains',
|
| 198 |
+
'database', 'date', 'dictionary', 'empty', 'equal', 'even',
|
| 199 |
+
'every', 'exists', 'false', 'floatin', 'function', 'greater',
|
| 200 |
+
'greaterOrEqual', 'if', 'in', 'inline', 'integer', 'is',
|
| 201 |
+
'key', 'label', 'leap', 'less', 'lessOrEqual', 'literal',
|
| 202 |
+
'logical', 'lower', 'nand', 'negative', 'nor', 'not',
|
| 203 |
+
'notEqual', 'null', 'numeric', 'odd', 'or', 'path',
|
| 204 |
+
'pathLabel', 'positive', 'prefix', 'prime', 'set', 'some',
|
| 205 |
+
'sorted', 'standalone', 'string', 'subset', 'suffix',
|
| 206 |
+
'superset', 'ymbol', 'true', 'try', 'type', 'unless', 'upper',
|
| 207 |
+
'when', 'whitespace', 'word', 'xnor', 'xor', 'zero',
|
| 208 |
+
), prefix=r'\b', suffix=r'\b\?'), Name.Builtin),
|
| 209 |
+
(words((
|
| 210 |
+
'abs', 'acos', 'acosh', 'acsec', 'acsech', 'actan', 'actanh',
|
| 211 |
+
'add', 'after', 'alphabet', 'and', 'angle', 'append', 'arg',
|
| 212 |
+
'args', 'arity', 'array', 'as', 'asec', 'asech', 'asin',
|
| 213 |
+
'asinh', 'atan', 'atan2', 'atanh', 'attr', 'attrs', 'average',
|
| 214 |
+
'before', 'benchmark', 'blend', 'break', 'builtins1',
|
| 215 |
+
'builtins2', 'call', 'capitalize', 'case', 'ceil', 'chop',
|
| 216 |
+
'chunk', 'clear', 'close', 'cluster', 'color', 'combine',
|
| 217 |
+
'conj', 'continue', 'copy', 'cos', 'cosh', 'couple', 'csec',
|
| 218 |
+
'csech', 'ctan', 'ctanh', 'cursor', 'darken', 'dec', 'decode',
|
| 219 |
+
'decouple', 'define', 'delete', 'desaturate', 'deviation',
|
| 220 |
+
'dictionary', 'difference', 'digest', 'digits', 'div', 'do',
|
| 221 |
+
'download', 'drop', 'dup', 'e', 'else', 'empty', 'encode',
|
| 222 |
+
'ensure', 'env', 'epsilon', 'escape', 'execute', 'exit', 'exp',
|
| 223 |
+
'extend', 'extract', 'factors', 'false', 'fdiv', 'filter',
|
| 224 |
+
'first', 'flatten', 'floor', 'fold', 'from', 'function',
|
| 225 |
+
'gamma', 'gcd', 'get', 'goto', 'hash', 'help', 'hypot', 'if',
|
| 226 |
+
'in', 'inc', 'indent', 'index', 'infinity', 'info', 'input',
|
| 227 |
+
'insert', 'inspect', 'intersection', 'invert', 'join', 'keys',
|
| 228 |
+
'kurtosis', 'last', 'let', 'levenshtein', 'lighten', 'list',
|
| 229 |
+
'ln', 'log', 'loop', 'lower', 'mail', 'map', 'match', 'max',
|
| 230 |
+
'maybe', 'median', 'min', 'mod', 'module', 'mul', 'nand',
|
| 231 |
+
'neg', 'new', 'nor', 'normalize', 'not', 'now', 'null', 'open',
|
| 232 |
+
'or', 'outdent', 'pad', 'panic', 'path', 'pause',
|
| 233 |
+
'permissions', 'permutate', 'pi', 'pop', 'pow', 'powerset',
|
| 234 |
+
'powmod', 'prefix', 'print', 'prints', 'process', 'product',
|
| 235 |
+
'query', 'random', 'range', 'read', 'relative', 'remove',
|
| 236 |
+
'rename', 'render', 'repeat', 'replace', 'request', 'return',
|
| 237 |
+
'reverse', 'round', 'sample', 'saturate', 'script', 'sec',
|
| 238 |
+
'sech', 'select', 'serve', 'set', 'shl', 'shr', 'shuffle',
|
| 239 |
+
'sin', 'sinh', 'size', 'skewness', 'slice', 'sort', 'split',
|
| 240 |
+
'sqrt', 'squeeze', 'stack', 'strip', 'sub', 'suffix', 'sum',
|
| 241 |
+
'switch', 'symbols', 'symlink', 'sys', 'take', 'tan', 'tanh',
|
| 242 |
+
'terminal', 'to', 'true', 'truncate', 'try', 'type', 'union',
|
| 243 |
+
'unique', 'unless', 'until', 'unzip', 'upper', 'values', 'var',
|
| 244 |
+
'variance', 'volume', 'webview', 'while', 'with', 'wordwrap',
|
| 245 |
+
'write', 'xnor', 'xor', 'zip'
|
| 246 |
+
), prefix=r'\b', suffix=r'\b'), Name.Builtin)
|
| 247 |
+
],
|
| 248 |
+
|
| 249 |
+
}
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/bqn.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.bqn
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexer for BQN.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from pygments.lexer import RegexLexer
|
| 12 |
+
from pygments.token import Comment, Operator, Keyword, Name, String, \
|
| 13 |
+
Number, Punctuation, Whitespace
|
| 14 |
+
|
| 15 |
+
__all__ = ['BQNLexer']
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class BQNLexer(RegexLexer):
|
| 19 |
+
"""
|
| 20 |
+
A simple BQN lexer.
|
| 21 |
+
"""
|
| 22 |
+
name = 'BQN'
|
| 23 |
+
url = 'https://mlochbaum.github.io/BQN/index.html'
|
| 24 |
+
aliases = ['bqn']
|
| 25 |
+
filenames = ['*.bqn']
|
| 26 |
+
mimetypes = []
|
| 27 |
+
version_added = '2.16'
|
| 28 |
+
|
| 29 |
+
# An inter_word_char. Necessary because \w matches all alphanumeric
|
| 30 |
+
# Unicode characters, including ones (e.g., 𝕊) that BQN treats special.
|
| 31 |
+
_iwc = r'((?=[^𝕎𝕏𝔽𝔾𝕊𝕨𝕩𝕗𝕘𝕤𝕣])\w)'
|
| 32 |
+
|
| 33 |
+
tokens = {
|
| 34 |
+
'root': [
|
| 35 |
+
# Whitespace
|
| 36 |
+
# ==========
|
| 37 |
+
(r'\s+', Whitespace),
|
| 38 |
+
#
|
| 39 |
+
# Comment
|
| 40 |
+
# =======
|
| 41 |
+
# '#' is a comment that continues to the end of the line
|
| 42 |
+
(r'#.*$', Comment.Single),
|
| 43 |
+
#
|
| 44 |
+
# Strings
|
| 45 |
+
# =======
|
| 46 |
+
(r'\'((\'\')|[^\'])*\'', String.Single),
|
| 47 |
+
(r'"(("")|[^"])*"', String.Double),
|
| 48 |
+
#
|
| 49 |
+
# Null Character
|
| 50 |
+
# ==============
|
| 51 |
+
# Literal representation of the null character
|
| 52 |
+
(r'@', String.Symbol),
|
| 53 |
+
#
|
| 54 |
+
# Punctuation
|
| 55 |
+
# ===========
|
| 56 |
+
# This token type is used for diamond, commas
|
| 57 |
+
# and array and list brackets and strand syntax
|
| 58 |
+
(r'[\.⋄,\[\]⟨⟩‿]', Punctuation),
|
| 59 |
+
#
|
| 60 |
+
# Expression Grouping
|
| 61 |
+
# ===================
|
| 62 |
+
# Since this token type is important in BQN, it is not included in
|
| 63 |
+
# the punctuation token type but rather in the following one
|
| 64 |
+
(r'[\(\)]', String.Regex),
|
| 65 |
+
#
|
| 66 |
+
# Numbers
|
| 67 |
+
# =======
|
| 68 |
+
# Includes the numeric literals and the Nothing character
|
| 69 |
+
(r'¯?[0-9](([0-9]|_)*\.?([0-9]|_)+|([0-9]|_)*)([Ee][¯]?([0-9]|_)+)?|¯|∞|π|·', Number),
|
| 70 |
+
#
|
| 71 |
+
# Variables
|
| 72 |
+
# =========
|
| 73 |
+
(r'[a-z]' + _iwc + r'*', Name.Variable),
|
| 74 |
+
#
|
| 75 |
+
# 2-Modifiers
|
| 76 |
+
# ===========
|
| 77 |
+
# Needs to come before the 1-modifiers due to _𝕣 and _𝕣_
|
| 78 |
+
(r'[∘○⊸⟜⌾⊘◶⎉⚇⍟⎊]', Name.Property),
|
| 79 |
+
(r'_(𝕣|[a-zA-Z0-9]+)_', Name.Property),
|
| 80 |
+
#
|
| 81 |
+
# 1-Modifiers
|
| 82 |
+
# ===========
|
| 83 |
+
(r'[˙˜˘¨⌜⁼´˝`𝕣]', Name.Attribute),
|
| 84 |
+
(r'_(𝕣|[a-zA-Z0-9]+)', Name.Attribute),
|
| 85 |
+
#
|
| 86 |
+
# Functions
|
| 87 |
+
# =========
|
| 88 |
+
# The monadic or dyadic function primitives and function
|
| 89 |
+
# operands and arguments, along with function self-reference
|
| 90 |
+
(r'[+\-×÷\⋆√⌊⌈∧∨¬|≤<>≥=≠≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!𝕎𝕏𝔽𝔾𝕊]',
|
| 91 |
+
Operator),
|
| 92 |
+
(r'[A-Z]' + _iwc + r'*|•' + _iwc + r'+', Operator),
|
| 93 |
+
#
|
| 94 |
+
# Constant
|
| 95 |
+
# ========
|
| 96 |
+
(r'˙', Name.Constant),
|
| 97 |
+
#
|
| 98 |
+
# Define/Export/Change
|
| 99 |
+
# ====================
|
| 100 |
+
(r'[←↩⇐]', Keyword.Declaration),
|
| 101 |
+
#
|
| 102 |
+
# Blocks
|
| 103 |
+
# ======
|
| 104 |
+
(r'[{}]', Keyword.Type),
|
| 105 |
+
#
|
| 106 |
+
# Extra characters
|
| 107 |
+
# ================
|
| 108 |
+
(r'[;:?𝕨𝕩𝕗𝕘𝕤]', Name.Entity),
|
| 109 |
+
#
|
| 110 |
+
|
| 111 |
+
],
|
| 112 |
+
}
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/configs.py
ADDED
|
@@ -0,0 +1,1433 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.configs
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexers for configuration file formats.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import re
|
| 12 |
+
|
| 13 |
+
from pygments.lexer import ExtendedRegexLexer, RegexLexer, default, words, \
|
| 14 |
+
bygroups, include, using, line_re
|
| 15 |
+
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
|
| 16 |
+
Number, Punctuation, Whitespace, Literal, Error, Generic
|
| 17 |
+
from pygments.lexers.shell import BashLexer
|
| 18 |
+
from pygments.lexers.data import JsonLexer
|
| 19 |
+
|
| 20 |
+
__all__ = ['IniLexer', 'SystemdLexer', 'DesktopLexer', 'RegeditLexer', 'PropertiesLexer',
|
| 21 |
+
'KconfigLexer', 'Cfengine3Lexer', 'ApacheConfLexer', 'SquidConfLexer',
|
| 22 |
+
'NginxConfLexer', 'LighttpdConfLexer', 'DockerLexer',
|
| 23 |
+
'TerraformLexer', 'TermcapLexer', 'TerminfoLexer',
|
| 24 |
+
'PkgConfigLexer', 'PacmanConfLexer', 'AugeasLexer', 'TOMLLexer',
|
| 25 |
+
'NestedTextLexer', 'SingularityLexer', 'UnixConfigLexer']
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class IniLexer(RegexLexer):
|
| 29 |
+
"""
|
| 30 |
+
Lexer for configuration files in INI style.
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
name = 'INI'
|
| 34 |
+
aliases = ['ini', 'cfg', 'dosini']
|
| 35 |
+
filenames = [
|
| 36 |
+
'*.ini', '*.cfg', '*.inf', '.editorconfig',
|
| 37 |
+
]
|
| 38 |
+
mimetypes = ['text/x-ini', 'text/inf']
|
| 39 |
+
url = 'https://en.wikipedia.org/wiki/INI_file'
|
| 40 |
+
version_added = ''
|
| 41 |
+
|
| 42 |
+
tokens = {
|
| 43 |
+
'root': [
|
| 44 |
+
(r'\s+', Whitespace),
|
| 45 |
+
(r'[;#].*', Comment.Single),
|
| 46 |
+
(r'(\[.*?\])([ \t]*)$', bygroups(Keyword, Whitespace)),
|
| 47 |
+
(r'''(.*?)([ \t]*)([=:])([ \t]*)(["'])''',
|
| 48 |
+
bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String),
|
| 49 |
+
"quoted_value"),
|
| 50 |
+
(r'(.*?)([ \t]*)([=:])([ \t]*)([^;#\n]*)(\\)(\s+)',
|
| 51 |
+
bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String,
|
| 52 |
+
Text, Whitespace),
|
| 53 |
+
"value"),
|
| 54 |
+
(r'(.*?)([ \t]*)([=:])([ \t]*)([^ ;#\n]*(?: +[^ ;#\n]+)*)',
|
| 55 |
+
bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)),
|
| 56 |
+
# standalone option, supported by some INI parsers
|
| 57 |
+
(r'(.+?)$', Name.Attribute),
|
| 58 |
+
],
|
| 59 |
+
'quoted_value': [
|
| 60 |
+
(r'''([^"'\n]*)(["'])(\s*)''',
|
| 61 |
+
bygroups(String, String, Whitespace), "#pop"),
|
| 62 |
+
(r'[;#].*', Comment.Single),
|
| 63 |
+
(r'$', String, "#pop"),
|
| 64 |
+
],
|
| 65 |
+
'value': [ # line continuation
|
| 66 |
+
(r'\s+', Whitespace),
|
| 67 |
+
(r'(\s*)(.*)(\\)([ \t]*)',
|
| 68 |
+
bygroups(Whitespace, String, Text, Whitespace)),
|
| 69 |
+
(r'.*$', String, "#pop"),
|
| 70 |
+
],
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
def analyse_text(text):
|
| 74 |
+
npos = text.find('\n')
|
| 75 |
+
if npos < 3:
|
| 76 |
+
return False
|
| 77 |
+
if text[0] == '[' and text[npos-1] == ']':
|
| 78 |
+
return 0.8
|
| 79 |
+
return False
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class DesktopLexer(RegexLexer):
|
| 83 |
+
"""
|
| 84 |
+
Lexer for .desktop files.
|
| 85 |
+
"""
|
| 86 |
+
|
| 87 |
+
name = 'Desktop file'
|
| 88 |
+
url = "https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html"
|
| 89 |
+
aliases = ['desktop']
|
| 90 |
+
filenames = ['*.desktop']
|
| 91 |
+
mimetypes = ['application/x-desktop']
|
| 92 |
+
version_added = '2.16'
|
| 93 |
+
|
| 94 |
+
tokens = {
|
| 95 |
+
'root': [
|
| 96 |
+
(r'^[ \t]*\n', Whitespace),
|
| 97 |
+
(r'^(#.*)(\n)', bygroups(Comment.Single, Whitespace)),
|
| 98 |
+
(r'(\[[^\]\n]+\])(\n)', bygroups(Keyword, Whitespace)),
|
| 99 |
+
(r'([-A-Za-z0-9]+)(\[[^\] \t=]+\])?([ \t]*)(=)([ \t]*)([^\n]*)([ \t\n]*\n)',
|
| 100 |
+
bygroups(Name.Attribute, Name.Namespace, Whitespace, Operator, Whitespace, String, Whitespace)),
|
| 101 |
+
],
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
def analyse_text(text):
|
| 105 |
+
if text.startswith("[Desktop Entry]"):
|
| 106 |
+
return 1.0
|
| 107 |
+
if re.search(r"^\[Desktop Entry\][ \t]*$", text[:500], re.MULTILINE) is not None:
|
| 108 |
+
return 0.9
|
| 109 |
+
return 0.0
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class SystemdLexer(RegexLexer):
|
| 113 |
+
"""
|
| 114 |
+
Lexer for systemd unit files.
|
| 115 |
+
"""
|
| 116 |
+
|
| 117 |
+
name = 'Systemd'
|
| 118 |
+
url = "https://www.freedesktop.org/software/systemd/man/systemd.syntax.html"
|
| 119 |
+
aliases = ['systemd']
|
| 120 |
+
filenames = [
|
| 121 |
+
'*.service', '*.socket', '*.device', '*.mount', '*.automount',
|
| 122 |
+
'*.swap', '*.target', '*.path', '*.timer', '*.slice', '*.scope',
|
| 123 |
+
]
|
| 124 |
+
version_added = '2.16'
|
| 125 |
+
|
| 126 |
+
tokens = {
|
| 127 |
+
'root': [
|
| 128 |
+
(r'^[ \t]*\n', Whitespace),
|
| 129 |
+
(r'^([;#].*)(\n)', bygroups(Comment.Single, Whitespace)),
|
| 130 |
+
(r'(\[[^\]\n]+\])(\n)', bygroups(Keyword, Whitespace)),
|
| 131 |
+
(r'([^=]+)([ \t]*)(=)([ \t]*)([^\n]*)(\\)(\n)',
|
| 132 |
+
bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String,
|
| 133 |
+
Text, Whitespace),
|
| 134 |
+
"value"),
|
| 135 |
+
(r'([^=]+)([ \t]*)(=)([ \t]*)([^\n]*)(\n)',
|
| 136 |
+
bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String, Whitespace)),
|
| 137 |
+
],
|
| 138 |
+
'value': [
|
| 139 |
+
# line continuation
|
| 140 |
+
(r'^([;#].*)(\n)', bygroups(Comment.Single, Whitespace)),
|
| 141 |
+
(r'([ \t]*)([^\n]*)(\\)(\n)',
|
| 142 |
+
bygroups(Whitespace, String, Text, Whitespace)),
|
| 143 |
+
(r'([ \t]*)([^\n]*)(\n)',
|
| 144 |
+
bygroups(Whitespace, String, Whitespace), "#pop"),
|
| 145 |
+
],
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
def analyse_text(text):
|
| 149 |
+
if text.startswith("[Unit]"):
|
| 150 |
+
return 1.0
|
| 151 |
+
if re.search(r"^\[Unit\][ \t]*$", text[:500], re.MULTILINE) is not None:
|
| 152 |
+
return 0.9
|
| 153 |
+
return 0.0
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
class RegeditLexer(RegexLexer):
|
| 157 |
+
"""
|
| 158 |
+
Lexer for Windows Registry files produced by regedit.
|
| 159 |
+
"""
|
| 160 |
+
|
| 161 |
+
name = 'reg'
|
| 162 |
+
url = 'http://en.wikipedia.org/wiki/Windows_Registry#.REG_files'
|
| 163 |
+
aliases = ['registry']
|
| 164 |
+
filenames = ['*.reg']
|
| 165 |
+
mimetypes = ['text/x-windows-registry']
|
| 166 |
+
version_added = '1.6'
|
| 167 |
+
|
| 168 |
+
tokens = {
|
| 169 |
+
'root': [
|
| 170 |
+
(r'Windows Registry Editor.*', Text),
|
| 171 |
+
(r'\s+', Whitespace),
|
| 172 |
+
(r'[;#].*', Comment.Single),
|
| 173 |
+
(r'(\[)(-?)(HKEY_[A-Z_]+)(.*?\])$',
|
| 174 |
+
bygroups(Keyword, Operator, Name.Builtin, Keyword)),
|
| 175 |
+
# String keys, which obey somewhat normal escaping
|
| 176 |
+
(r'("(?:\\"|\\\\|[^"])+")([ \t]*)(=)([ \t]*)',
|
| 177 |
+
bygroups(Name.Attribute, Whitespace, Operator, Whitespace),
|
| 178 |
+
'value'),
|
| 179 |
+
# Bare keys (includes @)
|
| 180 |
+
(r'(.*?)([ \t]*)(=)([ \t]*)',
|
| 181 |
+
bygroups(Name.Attribute, Whitespace, Operator, Whitespace),
|
| 182 |
+
'value'),
|
| 183 |
+
],
|
| 184 |
+
'value': [
|
| 185 |
+
(r'-', Operator, '#pop'), # delete value
|
| 186 |
+
(r'(dword|hex(?:\([0-9a-fA-F]\))?)(:)([0-9a-fA-F,]+)',
|
| 187 |
+
bygroups(Name.Variable, Punctuation, Number), '#pop'),
|
| 188 |
+
# As far as I know, .reg files do not support line continuation.
|
| 189 |
+
(r'.+', String, '#pop'),
|
| 190 |
+
default('#pop'),
|
| 191 |
+
]
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
def analyse_text(text):
|
| 195 |
+
return text.startswith('Windows Registry Editor')
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
class PropertiesLexer(RegexLexer):
|
| 199 |
+
"""
|
| 200 |
+
Lexer for configuration files in Java's properties format.
|
| 201 |
+
|
| 202 |
+
Note: trailing whitespace counts as part of the value as per spec
|
| 203 |
+
"""
|
| 204 |
+
|
| 205 |
+
name = 'Properties'
|
| 206 |
+
aliases = ['properties', 'jproperties']
|
| 207 |
+
filenames = ['*.properties']
|
| 208 |
+
mimetypes = ['text/x-java-properties']
|
| 209 |
+
url = 'https://en.wikipedia.org/wiki/.properties'
|
| 210 |
+
version_added = '1.4'
|
| 211 |
+
|
| 212 |
+
tokens = {
|
| 213 |
+
'root': [
|
| 214 |
+
# comments
|
| 215 |
+
(r'[!#].*|/{2}.*', Comment.Single),
|
| 216 |
+
# ending a comment or whitespace-only line
|
| 217 |
+
(r'\n', Whitespace),
|
| 218 |
+
# eat whitespace at the beginning of a line
|
| 219 |
+
(r'^[^\S\n]+', Whitespace),
|
| 220 |
+
# start lexing a key
|
| 221 |
+
default('key'),
|
| 222 |
+
],
|
| 223 |
+
'key': [
|
| 224 |
+
# non-escaped key characters
|
| 225 |
+
(r'[^\\:=\s]+', Name.Attribute),
|
| 226 |
+
# escapes
|
| 227 |
+
include('escapes'),
|
| 228 |
+
# separator is the first non-escaped whitespace or colon or '=' on the line;
|
| 229 |
+
# if it's whitespace, = and : are gobbled after it
|
| 230 |
+
(r'([^\S\n]*)([:=])([^\S\n]*)',
|
| 231 |
+
bygroups(Whitespace, Operator, Whitespace),
|
| 232 |
+
('#pop', 'value')),
|
| 233 |
+
(r'[^\S\n]+', Whitespace, ('#pop', 'value')),
|
| 234 |
+
# maybe we got no value after all
|
| 235 |
+
(r'\n', Whitespace, '#pop'),
|
| 236 |
+
],
|
| 237 |
+
'value': [
|
| 238 |
+
# non-escaped value characters
|
| 239 |
+
(r'[^\\\n]+', String),
|
| 240 |
+
# escapes
|
| 241 |
+
include('escapes'),
|
| 242 |
+
# end the value on an unescaped newline
|
| 243 |
+
(r'\n', Whitespace, '#pop'),
|
| 244 |
+
],
|
| 245 |
+
'escapes': [
|
| 246 |
+
# line continuations; these gobble whitespace at the beginning of the next line
|
| 247 |
+
(r'(\\\n)([^\S\n]*)', bygroups(String.Escape, Whitespace)),
|
| 248 |
+
# other escapes
|
| 249 |
+
(r'\\(.|\n)', String.Escape),
|
| 250 |
+
],
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def _rx_indent(level):
|
| 255 |
+
# Kconfig *always* interprets a tab as 8 spaces, so this is the default.
|
| 256 |
+
# Edit this if you are in an environment where KconfigLexer gets expanded
|
| 257 |
+
# input (tabs expanded to spaces) and the expansion tab width is != 8,
|
| 258 |
+
# e.g. in connection with Trac (trac.ini, [mimeviewer], tab_width).
|
| 259 |
+
# Value range here is 2 <= {tab_width} <= 8.
|
| 260 |
+
tab_width = 8
|
| 261 |
+
# Regex matching a given indentation {level}, assuming that indentation is
|
| 262 |
+
# a multiple of {tab_width}. In other cases there might be problems.
|
| 263 |
+
if tab_width == 2:
|
| 264 |
+
space_repeat = '+'
|
| 265 |
+
else:
|
| 266 |
+
space_repeat = '{1,%d}' % (tab_width - 1)
|
| 267 |
+
if level == 1:
|
| 268 |
+
level_repeat = ''
|
| 269 |
+
else:
|
| 270 |
+
level_repeat = f'{{{level}}}'
|
| 271 |
+
return rf'(?:\t| {space_repeat}\t| {{{tab_width}}}){level_repeat}.*\n'
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
class KconfigLexer(RegexLexer):
|
| 275 |
+
"""
|
| 276 |
+
For Linux-style Kconfig files.
|
| 277 |
+
"""
|
| 278 |
+
|
| 279 |
+
name = 'Kconfig'
|
| 280 |
+
aliases = ['kconfig', 'menuconfig', 'linux-config', 'kernel-config']
|
| 281 |
+
version_added = '1.6'
|
| 282 |
+
# Adjust this if new kconfig file names appear in your environment
|
| 283 |
+
filenames = ['Kconfig*', '*Config.in*', 'external.in*',
|
| 284 |
+
'standard-modules.in']
|
| 285 |
+
mimetypes = ['text/x-kconfig']
|
| 286 |
+
url = 'https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html'
|
| 287 |
+
|
| 288 |
+
# No re.MULTILINE, indentation-aware help text needs line-by-line handling
|
| 289 |
+
flags = 0
|
| 290 |
+
|
| 291 |
+
def call_indent(level):
|
| 292 |
+
# If indentation >= {level} is detected, enter state 'indent{level}'
|
| 293 |
+
return (_rx_indent(level), String.Doc, f'indent{level}')
|
| 294 |
+
|
| 295 |
+
def do_indent(level):
|
| 296 |
+
# Print paragraphs of indentation level >= {level} as String.Doc,
|
| 297 |
+
# ignoring blank lines. Then return to 'root' state.
|
| 298 |
+
return [
|
| 299 |
+
(_rx_indent(level), String.Doc),
|
| 300 |
+
(r'\s*\n', Text),
|
| 301 |
+
default('#pop:2')
|
| 302 |
+
]
|
| 303 |
+
|
| 304 |
+
tokens = {
|
| 305 |
+
'root': [
|
| 306 |
+
(r'\s+', Whitespace),
|
| 307 |
+
(r'#.*?\n', Comment.Single),
|
| 308 |
+
(words((
|
| 309 |
+
'mainmenu', 'config', 'menuconfig', 'choice', 'endchoice',
|
| 310 |
+
'comment', 'menu', 'endmenu', 'visible if', 'if', 'endif',
|
| 311 |
+
'source', 'prompt', 'select', 'depends on', 'default',
|
| 312 |
+
'range', 'option'), suffix=r'\b'),
|
| 313 |
+
Keyword),
|
| 314 |
+
(r'(---help---|help)[\t ]*\n', Keyword, 'help'),
|
| 315 |
+
(r'(bool|tristate|string|hex|int|defconfig_list|modules|env)\b',
|
| 316 |
+
Name.Builtin),
|
| 317 |
+
(r'[!=&|]', Operator),
|
| 318 |
+
(r'[()]', Punctuation),
|
| 319 |
+
(r'[0-9]+', Number.Integer),
|
| 320 |
+
(r"'(''|[^'])*'", String.Single),
|
| 321 |
+
(r'"(""|[^"])*"', String.Double),
|
| 322 |
+
(r'\S+', Text),
|
| 323 |
+
],
|
| 324 |
+
# Help text is indented, multi-line and ends when a lower indentation
|
| 325 |
+
# level is detected.
|
| 326 |
+
'help': [
|
| 327 |
+
# Skip blank lines after help token, if any
|
| 328 |
+
(r'\s*\n', Text),
|
| 329 |
+
# Determine the first help line's indentation level heuristically(!).
|
| 330 |
+
# Attention: this is not perfect, but works for 99% of "normal"
|
| 331 |
+
# indentation schemes up to a max. indentation level of 7.
|
| 332 |
+
call_indent(7),
|
| 333 |
+
call_indent(6),
|
| 334 |
+
call_indent(5),
|
| 335 |
+
call_indent(4),
|
| 336 |
+
call_indent(3),
|
| 337 |
+
call_indent(2),
|
| 338 |
+
call_indent(1),
|
| 339 |
+
default('#pop'), # for incomplete help sections without text
|
| 340 |
+
],
|
| 341 |
+
# Handle text for indentation levels 7 to 1
|
| 342 |
+
'indent7': do_indent(7),
|
| 343 |
+
'indent6': do_indent(6),
|
| 344 |
+
'indent5': do_indent(5),
|
| 345 |
+
'indent4': do_indent(4),
|
| 346 |
+
'indent3': do_indent(3),
|
| 347 |
+
'indent2': do_indent(2),
|
| 348 |
+
'indent1': do_indent(1),
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
class Cfengine3Lexer(RegexLexer):
|
| 353 |
+
"""
|
| 354 |
+
Lexer for CFEngine3 policy files.
|
| 355 |
+
"""
|
| 356 |
+
|
| 357 |
+
name = 'CFEngine3'
|
| 358 |
+
url = 'http://cfengine.org'
|
| 359 |
+
aliases = ['cfengine3', 'cf3']
|
| 360 |
+
filenames = ['*.cf']
|
| 361 |
+
mimetypes = []
|
| 362 |
+
version_added = '1.5'
|
| 363 |
+
|
| 364 |
+
tokens = {
|
| 365 |
+
'root': [
|
| 366 |
+
(r'#.*?\n', Comment),
|
| 367 |
+
(r'(body)(\s+)(\S+)(\s+)(control)',
|
| 368 |
+
bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword)),
|
| 369 |
+
(r'(body|bundle)(\s+)(\S+)(\s+)(\w+)(\()',
|
| 370 |
+
bygroups(Keyword, Whitespace, Keyword, Whitespace, Name.Function, Punctuation),
|
| 371 |
+
'arglist'),
|
| 372 |
+
(r'(body|bundle)(\s+)(\S+)(\s+)(\w+)',
|
| 373 |
+
bygroups(Keyword, Whitespace, Keyword, Whitespace, Name.Function)),
|
| 374 |
+
(r'(")([^"]+)(")(\s+)(string|slist|int|real)(\s*)(=>)(\s*)',
|
| 375 |
+
bygroups(Punctuation, Name.Variable, Punctuation,
|
| 376 |
+
Whitespace, Keyword.Type, Whitespace, Operator, Whitespace)),
|
| 377 |
+
(r'(\S+)(\s*)(=>)(\s*)',
|
| 378 |
+
bygroups(Keyword.Reserved, Whitespace, Operator, Text)),
|
| 379 |
+
(r'"', String, 'string'),
|
| 380 |
+
(r'(\w+)(\()', bygroups(Name.Function, Punctuation)),
|
| 381 |
+
(r'([\w.!&|()]+)(::)', bygroups(Name.Class, Punctuation)),
|
| 382 |
+
(r'(\w+)(:)', bygroups(Keyword.Declaration, Punctuation)),
|
| 383 |
+
(r'@[{(][^)}]+[})]', Name.Variable),
|
| 384 |
+
(r'[(){},;]', Punctuation),
|
| 385 |
+
(r'=>', Operator),
|
| 386 |
+
(r'->', Operator),
|
| 387 |
+
(r'\d+\.\d+', Number.Float),
|
| 388 |
+
(r'\d+', Number.Integer),
|
| 389 |
+
(r'\w+', Name.Function),
|
| 390 |
+
(r'\s+', Whitespace),
|
| 391 |
+
],
|
| 392 |
+
'string': [
|
| 393 |
+
(r'\$[{(]', String.Interpol, 'interpol'),
|
| 394 |
+
(r'\\.', String.Escape),
|
| 395 |
+
(r'"', String, '#pop'),
|
| 396 |
+
(r'\n', String),
|
| 397 |
+
(r'.', String),
|
| 398 |
+
],
|
| 399 |
+
'interpol': [
|
| 400 |
+
(r'\$[{(]', String.Interpol, '#push'),
|
| 401 |
+
(r'[})]', String.Interpol, '#pop'),
|
| 402 |
+
(r'[^${()}]+', String.Interpol),
|
| 403 |
+
],
|
| 404 |
+
'arglist': [
|
| 405 |
+
(r'\)', Punctuation, '#pop'),
|
| 406 |
+
(r',', Punctuation),
|
| 407 |
+
(r'\w+', Name.Variable),
|
| 408 |
+
(r'\s+', Whitespace),
|
| 409 |
+
],
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
class ApacheConfLexer(RegexLexer):
|
| 414 |
+
"""
|
| 415 |
+
Lexer for configuration files following the Apache config file
|
| 416 |
+
format.
|
| 417 |
+
"""
|
| 418 |
+
|
| 419 |
+
name = 'ApacheConf'
|
| 420 |
+
aliases = ['apacheconf', 'aconf', 'apache']
|
| 421 |
+
filenames = ['.htaccess', 'apache.conf', 'apache2.conf']
|
| 422 |
+
mimetypes = ['text/x-apacheconf']
|
| 423 |
+
url = 'https://httpd.apache.org/docs/current/configuring.html'
|
| 424 |
+
version_added = '0.6'
|
| 425 |
+
flags = re.MULTILINE | re.IGNORECASE
|
| 426 |
+
|
| 427 |
+
tokens = {
|
| 428 |
+
'root': [
|
| 429 |
+
(r'\s+', Whitespace),
|
| 430 |
+
(r'#(.*\\\n)+.*$|(#.*?)$', Comment),
|
| 431 |
+
(r'(<[^\s>/][^\s>]*)(?:(\s+)(.*))?(>)',
|
| 432 |
+
bygroups(Name.Tag, Whitespace, String, Name.Tag)),
|
| 433 |
+
(r'(</[^\s>]+)(>)',
|
| 434 |
+
bygroups(Name.Tag, Name.Tag)),
|
| 435 |
+
(r'[a-z]\w*', Name.Builtin, 'value'),
|
| 436 |
+
(r'\.+', Text),
|
| 437 |
+
],
|
| 438 |
+
'value': [
|
| 439 |
+
(r'\\\n', Text),
|
| 440 |
+
(r'\n+', Whitespace, '#pop'),
|
| 441 |
+
(r'\\', Text),
|
| 442 |
+
(r'[^\S\n]+', Whitespace),
|
| 443 |
+
(r'\d+\.\d+\.\d+\.\d+(?:/\d+)?', Number),
|
| 444 |
+
(r'\d+', Number),
|
| 445 |
+
(r'/([*a-z0-9][*\w./-]+)', String.Other),
|
| 446 |
+
(r'(on|off|none|any|all|double|email|dns|min|minimal|'
|
| 447 |
+
r'os|productonly|full|emerg|alert|crit|error|warn|'
|
| 448 |
+
r'notice|info|debug|registry|script|inetd|standalone|'
|
| 449 |
+
r'user|group)\b', Keyword),
|
| 450 |
+
(r'"([^"\\]*(?:\\(.|\n)[^"\\]*)*)"', String.Double),
|
| 451 |
+
(r'[^\s"\\]+', Text)
|
| 452 |
+
],
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
class SquidConfLexer(RegexLexer):
|
| 457 |
+
"""
|
| 458 |
+
Lexer for squid configuration files.
|
| 459 |
+
"""
|
| 460 |
+
|
| 461 |
+
name = 'SquidConf'
|
| 462 |
+
url = 'http://www.squid-cache.org/'
|
| 463 |
+
aliases = ['squidconf', 'squid.conf', 'squid']
|
| 464 |
+
filenames = ['squid.conf']
|
| 465 |
+
mimetypes = ['text/x-squidconf']
|
| 466 |
+
version_added = '0.9'
|
| 467 |
+
flags = re.IGNORECASE
|
| 468 |
+
|
| 469 |
+
keywords = (
|
| 470 |
+
"access_log", "acl", "always_direct", "announce_host",
|
| 471 |
+
"announce_period", "announce_port", "announce_to", "anonymize_headers",
|
| 472 |
+
"append_domain", "as_whois_server", "auth_param_basic",
|
| 473 |
+
"authenticate_children", "authenticate_program", "authenticate_ttl",
|
| 474 |
+
"broken_posts", "buffered_logs", "cache_access_log", "cache_announce",
|
| 475 |
+
"cache_dir", "cache_dns_program", "cache_effective_group",
|
| 476 |
+
"cache_effective_user", "cache_host", "cache_host_acl",
|
| 477 |
+
"cache_host_domain", "cache_log", "cache_mem", "cache_mem_high",
|
| 478 |
+
"cache_mem_low", "cache_mgr", "cachemgr_passwd", "cache_peer",
|
| 479 |
+
"cache_peer_access", "cache_replacement_policy", "cache_stoplist",
|
| 480 |
+
"cache_stoplist_pattern", "cache_store_log", "cache_swap",
|
| 481 |
+
"cache_swap_high", "cache_swap_log", "cache_swap_low", "client_db",
|
| 482 |
+
"client_lifetime", "client_netmask", "connect_timeout", "coredump_dir",
|
| 483 |
+
"dead_peer_timeout", "debug_options", "delay_access", "delay_class",
|
| 484 |
+
"delay_initial_bucket_level", "delay_parameters", "delay_pools",
|
| 485 |
+
"deny_info", "dns_children", "dns_defnames", "dns_nameservers",
|
| 486 |
+
"dns_testnames", "emulate_httpd_log", "err_html_text",
|
| 487 |
+
"fake_user_agent", "firewall_ip", "forwarded_for", "forward_snmpd_port",
|
| 488 |
+
"fqdncache_size", "ftpget_options", "ftpget_program", "ftp_list_width",
|
| 489 |
+
"ftp_passive", "ftp_user", "half_closed_clients", "header_access",
|
| 490 |
+
"header_replace", "hierarchy_stoplist", "high_response_time_warning",
|
| 491 |
+
"high_page_fault_warning", "hosts_file", "htcp_port", "http_access",
|
| 492 |
+
"http_anonymizer", "httpd_accel", "httpd_accel_host",
|
| 493 |
+
"httpd_accel_port", "httpd_accel_uses_host_header",
|
| 494 |
+
"httpd_accel_with_proxy", "http_port", "http_reply_access",
|
| 495 |
+
"icp_access", "icp_hit_stale", "icp_port", "icp_query_timeout",
|
| 496 |
+
"ident_lookup", "ident_lookup_access", "ident_timeout",
|
| 497 |
+
"incoming_http_average", "incoming_icp_average", "inside_firewall",
|
| 498 |
+
"ipcache_high", "ipcache_low", "ipcache_size", "local_domain",
|
| 499 |
+
"local_ip", "logfile_rotate", "log_fqdn", "log_icp_queries",
|
| 500 |
+
"log_mime_hdrs", "maximum_object_size", "maximum_single_addr_tries",
|
| 501 |
+
"mcast_groups", "mcast_icp_query_timeout", "mcast_miss_addr",
|
| 502 |
+
"mcast_miss_encode_key", "mcast_miss_port", "memory_pools",
|
| 503 |
+
"memory_pools_limit", "memory_replacement_policy", "mime_table",
|
| 504 |
+
"min_http_poll_cnt", "min_icp_poll_cnt", "minimum_direct_hops",
|
| 505 |
+
"minimum_object_size", "minimum_retry_timeout", "miss_access",
|
| 506 |
+
"negative_dns_ttl", "negative_ttl", "neighbor_timeout",
|
| 507 |
+
"neighbor_type_domain", "netdb_high", "netdb_low", "netdb_ping_period",
|
| 508 |
+
"netdb_ping_rate", "never_direct", "no_cache", "passthrough_proxy",
|
| 509 |
+
"pconn_timeout", "pid_filename", "pinger_program", "positive_dns_ttl",
|
| 510 |
+
"prefer_direct", "proxy_auth", "proxy_auth_realm", "query_icmp",
|
| 511 |
+
"quick_abort", "quick_abort_max", "quick_abort_min",
|
| 512 |
+
"quick_abort_pct", "range_offset_limit", "read_timeout",
|
| 513 |
+
"redirect_children", "redirect_program",
|
| 514 |
+
"redirect_rewrites_host_header", "reference_age",
|
| 515 |
+
"refresh_pattern", "reload_into_ims", "request_body_max_size",
|
| 516 |
+
"request_size", "request_timeout", "shutdown_lifetime",
|
| 517 |
+
"single_parent_bypass", "siteselect_timeout", "snmp_access",
|
| 518 |
+
"snmp_incoming_address", "snmp_port", "source_ping", "ssl_proxy",
|
| 519 |
+
"store_avg_object_size", "store_objects_per_bucket",
|
| 520 |
+
"strip_query_terms", "swap_level1_dirs", "swap_level2_dirs",
|
| 521 |
+
"tcp_incoming_address", "tcp_outgoing_address", "tcp_recv_bufsize",
|
| 522 |
+
"test_reachability", "udp_hit_obj", "udp_hit_obj_size",
|
| 523 |
+
"udp_incoming_address", "udp_outgoing_address", "unique_hostname",
|
| 524 |
+
"unlinkd_program", "uri_whitespace", "useragent_log",
|
| 525 |
+
"visible_hostname", "wais_relay", "wais_relay_host", "wais_relay_port",
|
| 526 |
+
)
|
| 527 |
+
|
| 528 |
+
opts = (
|
| 529 |
+
"proxy-only", "weight", "ttl", "no-query", "default", "round-robin",
|
| 530 |
+
"multicast-responder", "on", "off", "all", "deny", "allow", "via",
|
| 531 |
+
"parent", "no-digest", "heap", "lru", "realm", "children", "q1", "q2",
|
| 532 |
+
"credentialsttl", "none", "disable", "offline_toggle", "diskd",
|
| 533 |
+
)
|
| 534 |
+
|
| 535 |
+
actions = (
|
| 536 |
+
"shutdown", "info", "parameter", "server_list", "client_list",
|
| 537 |
+
r'squid.conf',
|
| 538 |
+
)
|
| 539 |
+
|
| 540 |
+
actions_stats = (
|
| 541 |
+
"objects", "vm_objects", "utilization", "ipcache", "fqdncache", "dns",
|
| 542 |
+
"redirector", "io", "reply_headers", "filedescriptors", "netdb",
|
| 543 |
+
)
|
| 544 |
+
|
| 545 |
+
actions_log = ("status", "enable", "disable", "clear")
|
| 546 |
+
|
| 547 |
+
acls = (
|
| 548 |
+
"url_regex", "urlpath_regex", "referer_regex", "port", "proto",
|
| 549 |
+
"req_mime_type", "rep_mime_type", "method", "browser", "user", "src",
|
| 550 |
+
"dst", "time", "dstdomain", "ident", "snmp_community",
|
| 551 |
+
)
|
| 552 |
+
|
| 553 |
+
ipv4_group = r'(\d+|0x[0-9a-f]+)'
|
| 554 |
+
ipv4 = rf'({ipv4_group}(\.{ipv4_group}){{3}})'
|
| 555 |
+
ipv6_group = r'([0-9a-f]{0,4})'
|
| 556 |
+
ipv6 = rf'({ipv6_group}(:{ipv6_group}){{1,7}})'
|
| 557 |
+
bare_ip = rf'({ipv4}|{ipv6})'
|
| 558 |
+
# XXX: /integer is a subnet mark, but what is /IP ?
|
| 559 |
+
# There is no test where it is used.
|
| 560 |
+
ip = rf'{bare_ip}(/({bare_ip}|\d+))?'
|
| 561 |
+
|
| 562 |
+
tokens = {
|
| 563 |
+
'root': [
|
| 564 |
+
(r'\s+', Whitespace),
|
| 565 |
+
(r'#', Comment, 'comment'),
|
| 566 |
+
(words(keywords, prefix=r'\b', suffix=r'\b'), Keyword),
|
| 567 |
+
(words(opts, prefix=r'\b', suffix=r'\b'), Name.Constant),
|
| 568 |
+
# Actions
|
| 569 |
+
(words(actions, prefix=r'\b', suffix=r'\b'), String),
|
| 570 |
+
(words(actions_stats, prefix=r'stats/', suffix=r'\b'), String),
|
| 571 |
+
(words(actions_log, prefix=r'log/', suffix=r'='), String),
|
| 572 |
+
(words(acls, prefix=r'\b', suffix=r'\b'), Keyword),
|
| 573 |
+
(ip, Number.Float),
|
| 574 |
+
(r'(?:\b\d+\b(?:-\b\d+|%)?)', Number),
|
| 575 |
+
(r'\S+', Text),
|
| 576 |
+
],
|
| 577 |
+
'comment': [
|
| 578 |
+
(r'\s*TAG:.*', String.Escape, '#pop'),
|
| 579 |
+
(r'.+', Comment, '#pop'),
|
| 580 |
+
default('#pop'),
|
| 581 |
+
],
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
class NginxConfLexer(RegexLexer):
|
| 586 |
+
"""
|
| 587 |
+
Lexer for Nginx configuration files.
|
| 588 |
+
"""
|
| 589 |
+
name = 'Nginx configuration file'
|
| 590 |
+
url = 'http://nginx.net/'
|
| 591 |
+
aliases = ['nginx']
|
| 592 |
+
filenames = ['nginx.conf']
|
| 593 |
+
mimetypes = ['text/x-nginx-conf']
|
| 594 |
+
version_added = '0.11'
|
| 595 |
+
|
| 596 |
+
tokens = {
|
| 597 |
+
'root': [
|
| 598 |
+
(r'(include)(\s+)([^\s;]+)', bygroups(Keyword, Whitespace, Name)),
|
| 599 |
+
(r'[^\s;#]+', Keyword, 'stmt'),
|
| 600 |
+
include('base'),
|
| 601 |
+
],
|
| 602 |
+
'block': [
|
| 603 |
+
(r'\}', Punctuation, '#pop:2'),
|
| 604 |
+
(r'[^\s;#]+', Keyword.Namespace, 'stmt'),
|
| 605 |
+
include('base'),
|
| 606 |
+
],
|
| 607 |
+
'stmt': [
|
| 608 |
+
(r'\{', Punctuation, 'block'),
|
| 609 |
+
(r';', Punctuation, '#pop'),
|
| 610 |
+
include('base'),
|
| 611 |
+
],
|
| 612 |
+
'base': [
|
| 613 |
+
(r'#.*\n', Comment.Single),
|
| 614 |
+
(r'on|off', Name.Constant),
|
| 615 |
+
(r'\$[^\s;#()]+', Name.Variable),
|
| 616 |
+
(r'([a-z0-9.-]+)(:)([0-9]+)',
|
| 617 |
+
bygroups(Name, Punctuation, Number.Integer)),
|
| 618 |
+
(r'[a-z-]+/[a-z-+]+', String), # mimetype
|
| 619 |
+
# (r'[a-zA-Z._-]+', Keyword),
|
| 620 |
+
(r'[0-9]+[km]?\b', Number.Integer),
|
| 621 |
+
(r'(~)(\s*)([^\s{]+)', bygroups(Punctuation, Whitespace, String.Regex)),
|
| 622 |
+
(r'[:=~]', Punctuation),
|
| 623 |
+
(r'[^\s;#{}$]+', String), # catch all
|
| 624 |
+
(r'/[^\s;#]*', Name), # pathname
|
| 625 |
+
(r'\s+', Whitespace),
|
| 626 |
+
(r'[$;]', Text), # leftover characters
|
| 627 |
+
],
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
|
| 631 |
+
class LighttpdConfLexer(RegexLexer):
|
| 632 |
+
"""
|
| 633 |
+
Lexer for Lighttpd configuration files.
|
| 634 |
+
"""
|
| 635 |
+
name = 'Lighttpd configuration file'
|
| 636 |
+
url = 'http://lighttpd.net/'
|
| 637 |
+
aliases = ['lighttpd', 'lighty']
|
| 638 |
+
filenames = ['lighttpd.conf']
|
| 639 |
+
mimetypes = ['text/x-lighttpd-conf']
|
| 640 |
+
version_added = '0.11'
|
| 641 |
+
|
| 642 |
+
tokens = {
|
| 643 |
+
'root': [
|
| 644 |
+
(r'#.*\n', Comment.Single),
|
| 645 |
+
(r'/\S*', Name), # pathname
|
| 646 |
+
(r'[a-zA-Z._-]+', Keyword),
|
| 647 |
+
(r'\d+\.\d+\.\d+\.\d+(?:/\d+)?', Number),
|
| 648 |
+
(r'[0-9]+', Number),
|
| 649 |
+
(r'=>|=~|\+=|==|=|\+', Operator),
|
| 650 |
+
(r'\$[A-Z]+', Name.Builtin),
|
| 651 |
+
(r'[(){}\[\],]', Punctuation),
|
| 652 |
+
(r'"([^"\\]*(?:\\.[^"\\]*)*)"', String.Double),
|
| 653 |
+
(r'\s+', Whitespace),
|
| 654 |
+
],
|
| 655 |
+
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
|
| 659 |
+
class DockerLexer(RegexLexer):
|
| 660 |
+
"""
|
| 661 |
+
Lexer for Docker configuration files.
|
| 662 |
+
"""
|
| 663 |
+
name = 'Docker'
|
| 664 |
+
url = 'http://docker.io'
|
| 665 |
+
aliases = ['docker', 'dockerfile']
|
| 666 |
+
filenames = ['Dockerfile', '*.docker']
|
| 667 |
+
mimetypes = ['text/x-dockerfile-config']
|
| 668 |
+
version_added = '2.0'
|
| 669 |
+
|
| 670 |
+
_keywords = (r'(?:MAINTAINER|EXPOSE|WORKDIR|USER|STOPSIGNAL)')
|
| 671 |
+
_bash_keywords = (r'(?:RUN|CMD|ENTRYPOINT|ENV|ARG|LABEL|ADD|COPY)')
|
| 672 |
+
_lb = r'(?:\s*\\?\s*)' # dockerfile line break regex
|
| 673 |
+
flags = re.IGNORECASE | re.MULTILINE
|
| 674 |
+
|
| 675 |
+
tokens = {
|
| 676 |
+
'root': [
|
| 677 |
+
(r'#.*', Comment),
|
| 678 |
+
(r'(FROM)([ \t]*)(\S*)([ \t]*)(?:(AS)([ \t]*)(\S*))?',
|
| 679 |
+
bygroups(Keyword, Whitespace, String, Whitespace, Keyword, Whitespace, String)),
|
| 680 |
+
(rf'(ONBUILD)(\s+)({_lb})', bygroups(Keyword, Whitespace, using(BashLexer))),
|
| 681 |
+
(rf'(HEALTHCHECK)(\s+)(({_lb}--\w+=\w+{_lb})*)',
|
| 682 |
+
bygroups(Keyword, Whitespace, using(BashLexer))),
|
| 683 |
+
(rf'(VOLUME|ENTRYPOINT|CMD|SHELL)(\s+)({_lb})(\[.*?\])',
|
| 684 |
+
bygroups(Keyword, Whitespace, using(BashLexer), using(JsonLexer))),
|
| 685 |
+
(rf'(LABEL|ENV|ARG)(\s+)(({_lb}\w+=\w+{_lb})*)',
|
| 686 |
+
bygroups(Keyword, Whitespace, using(BashLexer))),
|
| 687 |
+
(rf'({_keywords}|VOLUME)\b(\s+)(.*)', bygroups(Keyword, Whitespace, String)),
|
| 688 |
+
(rf'({_bash_keywords})(\s+)', bygroups(Keyword, Whitespace)),
|
| 689 |
+
(r'(.*\\\n)*.+', using(BashLexer)),
|
| 690 |
+
]
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
|
| 694 |
+
class TerraformLexer(ExtendedRegexLexer):
|
| 695 |
+
"""
|
| 696 |
+
Lexer for terraformi ``.tf`` files.
|
| 697 |
+
"""
|
| 698 |
+
|
| 699 |
+
name = 'Terraform'
|
| 700 |
+
url = 'https://www.terraform.io/'
|
| 701 |
+
aliases = ['terraform', 'tf', 'hcl']
|
| 702 |
+
filenames = ['*.tf', '*.hcl']
|
| 703 |
+
mimetypes = ['application/x-tf', 'application/x-terraform']
|
| 704 |
+
version_added = '2.1'
|
| 705 |
+
|
| 706 |
+
classes = ('backend', 'data', 'module', 'output', 'provider',
|
| 707 |
+
'provisioner', 'resource', 'variable')
|
| 708 |
+
classes_re = "({})".format(('|').join(classes))
|
| 709 |
+
|
| 710 |
+
types = ('string', 'number', 'bool', 'list', 'tuple', 'map', 'set', 'object', 'null')
|
| 711 |
+
|
| 712 |
+
numeric_functions = ('abs', 'ceil', 'floor', 'log', 'max',
|
| 713 |
+
'mix', 'parseint', 'pow', 'signum')
|
| 714 |
+
|
| 715 |
+
string_functions = ('chomp', 'format', 'formatlist', 'indent',
|
| 716 |
+
'join', 'lower', 'regex', 'regexall', 'replace',
|
| 717 |
+
'split', 'strrev', 'substr', 'title', 'trim',
|
| 718 |
+
'trimprefix', 'trimsuffix', 'trimspace', 'upper'
|
| 719 |
+
)
|
| 720 |
+
|
| 721 |
+
collection_functions = ('alltrue', 'anytrue', 'chunklist', 'coalesce',
|
| 722 |
+
'coalescelist', 'compact', 'concat', 'contains',
|
| 723 |
+
'distinct', 'element', 'flatten', 'index', 'keys',
|
| 724 |
+
'length', 'list', 'lookup', 'map', 'matchkeys',
|
| 725 |
+
'merge', 'range', 'reverse', 'setintersection',
|
| 726 |
+
'setproduct', 'setsubtract', 'setunion', 'slice',
|
| 727 |
+
'sort', 'sum', 'transpose', 'values', 'zipmap'
|
| 728 |
+
)
|
| 729 |
+
|
| 730 |
+
encoding_functions = ('base64decode', 'base64encode', 'base64gzip',
|
| 731 |
+
'csvdecode', 'jsondecode', 'jsonencode', 'textdecodebase64',
|
| 732 |
+
'textencodebase64', 'urlencode', 'yamldecode', 'yamlencode')
|
| 733 |
+
|
| 734 |
+
filesystem_functions = ('abspath', 'dirname', 'pathexpand', 'basename',
|
| 735 |
+
'file', 'fileexists', 'fileset', 'filebase64', 'templatefile')
|
| 736 |
+
|
| 737 |
+
date_time_functions = ('formatdate', 'timeadd', 'timestamp')
|
| 738 |
+
|
| 739 |
+
hash_crypto_functions = ('base64sha256', 'base64sha512', 'bcrypt', 'filebase64sha256',
|
| 740 |
+
'filebase64sha512', 'filemd5', 'filesha1', 'filesha256', 'filesha512',
|
| 741 |
+
'md5', 'rsadecrypt', 'sha1', 'sha256', 'sha512', 'uuid', 'uuidv5')
|
| 742 |
+
|
| 743 |
+
ip_network_functions = ('cidrhost', 'cidrnetmask', 'cidrsubnet', 'cidrsubnets')
|
| 744 |
+
|
| 745 |
+
type_conversion_functions = ('can', 'defaults', 'tobool', 'tolist', 'tomap',
|
| 746 |
+
'tonumber', 'toset', 'tostring', 'try')
|
| 747 |
+
|
| 748 |
+
builtins = numeric_functions + string_functions + collection_functions + encoding_functions +\
|
| 749 |
+
filesystem_functions + date_time_functions + hash_crypto_functions + ip_network_functions +\
|
| 750 |
+
type_conversion_functions
|
| 751 |
+
builtins_re = "({})".format(('|').join(builtins))
|
| 752 |
+
|
| 753 |
+
def heredoc_callback(self, match, ctx):
|
| 754 |
+
# Parse a terraform heredoc
|
| 755 |
+
# match: 1 = <<[-]?, 2 = name 3 = rest of line
|
| 756 |
+
|
| 757 |
+
start = match.start(1)
|
| 758 |
+
yield start, Operator, match.group(1) # <<[-]?
|
| 759 |
+
yield match.start(2), String.Delimiter, match.group(2) # heredoc name
|
| 760 |
+
|
| 761 |
+
ctx.pos = match.start(3)
|
| 762 |
+
ctx.end = match.end(3)
|
| 763 |
+
yield ctx.pos, String.Heredoc, match.group(3)
|
| 764 |
+
ctx.pos = match.end()
|
| 765 |
+
|
| 766 |
+
hdname = match.group(2)
|
| 767 |
+
tolerant = True # leading whitespace is always accepted
|
| 768 |
+
|
| 769 |
+
lines = []
|
| 770 |
+
|
| 771 |
+
for match in line_re.finditer(ctx.text, ctx.pos):
|
| 772 |
+
if tolerant:
|
| 773 |
+
check = match.group().strip()
|
| 774 |
+
else:
|
| 775 |
+
check = match.group().rstrip()
|
| 776 |
+
if check == hdname:
|
| 777 |
+
for amatch in lines:
|
| 778 |
+
yield amatch.start(), String.Heredoc, amatch.group()
|
| 779 |
+
yield match.start(), String.Delimiter, match.group()
|
| 780 |
+
ctx.pos = match.end()
|
| 781 |
+
break
|
| 782 |
+
else:
|
| 783 |
+
lines.append(match)
|
| 784 |
+
else:
|
| 785 |
+
# end of heredoc not found -- error!
|
| 786 |
+
for amatch in lines:
|
| 787 |
+
yield amatch.start(), Error, amatch.group()
|
| 788 |
+
ctx.end = len(ctx.text)
|
| 789 |
+
|
| 790 |
+
tokens = {
|
| 791 |
+
'root': [
|
| 792 |
+
include('basic'),
|
| 793 |
+
include('whitespace'),
|
| 794 |
+
|
| 795 |
+
# Strings
|
| 796 |
+
(r'(".*")', bygroups(String.Double)),
|
| 797 |
+
|
| 798 |
+
# Constants
|
| 799 |
+
(words(('true', 'false'), prefix=r'\b', suffix=r'\b'), Name.Constant),
|
| 800 |
+
|
| 801 |
+
# Types
|
| 802 |
+
(words(types, prefix=r'\b', suffix=r'\b'), Keyword.Type),
|
| 803 |
+
|
| 804 |
+
include('identifier'),
|
| 805 |
+
include('punctuation'),
|
| 806 |
+
(r'[0-9]+', Number),
|
| 807 |
+
],
|
| 808 |
+
'basic': [
|
| 809 |
+
(r'\s*/\*', Comment.Multiline, 'comment'),
|
| 810 |
+
(r'\s*(#|//).*\n', Comment.Single),
|
| 811 |
+
include('whitespace'),
|
| 812 |
+
|
| 813 |
+
# e.g. terraform {
|
| 814 |
+
# e.g. egress {
|
| 815 |
+
(r'(\s*)([0-9a-zA-Z-_]+)(\s*)(=?)(\s*)(\{)',
|
| 816 |
+
bygroups(Whitespace, Name.Builtin, Whitespace, Operator, Whitespace, Punctuation)),
|
| 817 |
+
|
| 818 |
+
# Assignment with attributes, e.g. something = ...
|
| 819 |
+
(r'(\s*)([0-9a-zA-Z-_]+)(\s*)(=)(\s*)',
|
| 820 |
+
bygroups(Whitespace, Name.Attribute, Whitespace, Operator, Whitespace)),
|
| 821 |
+
|
| 822 |
+
# Assignment with environment variables and similar, e.g. "something" = ...
|
| 823 |
+
# or key value assignment, e.g. "SlotName" : ...
|
| 824 |
+
(r'(\s*)("\S+")(\s*)([=:])(\s*)',
|
| 825 |
+
bygroups(Whitespace, Literal.String.Double, Whitespace, Operator, Whitespace)),
|
| 826 |
+
|
| 827 |
+
# Functions, e.g. jsonencode(element("value"))
|
| 828 |
+
(builtins_re + r'(\()', bygroups(Name.Function, Punctuation)),
|
| 829 |
+
|
| 830 |
+
# List of attributes, e.g. ignore_changes = [last_modified, filename]
|
| 831 |
+
(r'(\[)([a-z_,\s]+)(\])', bygroups(Punctuation, Name.Builtin, Punctuation)),
|
| 832 |
+
|
| 833 |
+
# e.g. resource "aws_security_group" "allow_tls" {
|
| 834 |
+
# e.g. backend "consul" {
|
| 835 |
+
(classes_re + r'(\s+)("[0-9a-zA-Z-_]+")?(\s*)("[0-9a-zA-Z-_]+")(\s+)(\{)',
|
| 836 |
+
bygroups(Keyword.Reserved, Whitespace, Name.Class, Whitespace, Name.Variable, Whitespace, Punctuation)),
|
| 837 |
+
|
| 838 |
+
# here-doc style delimited strings
|
| 839 |
+
(r'(<<-?)\s*([a-zA-Z_]\w*)(.*?\n)', heredoc_callback),
|
| 840 |
+
],
|
| 841 |
+
'identifier': [
|
| 842 |
+
(r'\b(var\.[0-9a-zA-Z-_\.\[\]]+)\b', bygroups(Name.Variable)),
|
| 843 |
+
(r'\b([0-9a-zA-Z-_\[\]]+\.[0-9a-zA-Z-_\.\[\]]+)\b',
|
| 844 |
+
bygroups(Name.Variable)),
|
| 845 |
+
],
|
| 846 |
+
'punctuation': [
|
| 847 |
+
(r'[\[\]()\{\},.?:!=]', Punctuation),
|
| 848 |
+
],
|
| 849 |
+
'comment': [
|
| 850 |
+
(r'[^*/]', Comment.Multiline),
|
| 851 |
+
(r'/\*', Comment.Multiline, '#push'),
|
| 852 |
+
(r'\*/', Comment.Multiline, '#pop'),
|
| 853 |
+
(r'[*/]', Comment.Multiline)
|
| 854 |
+
],
|
| 855 |
+
'whitespace': [
|
| 856 |
+
(r'\n', Whitespace),
|
| 857 |
+
(r'\s+', Whitespace),
|
| 858 |
+
(r'(\\)(\n)', bygroups(Text, Whitespace)),
|
| 859 |
+
],
|
| 860 |
+
}
|
| 861 |
+
|
| 862 |
+
|
| 863 |
+
class TermcapLexer(RegexLexer):
|
| 864 |
+
"""
|
| 865 |
+
Lexer for termcap database source.
|
| 866 |
+
|
| 867 |
+
This is very simple and minimal.
|
| 868 |
+
"""
|
| 869 |
+
name = 'Termcap'
|
| 870 |
+
aliases = ['termcap']
|
| 871 |
+
filenames = ['termcap', 'termcap.src']
|
| 872 |
+
mimetypes = []
|
| 873 |
+
url = 'https://en.wikipedia.org/wiki/Termcap'
|
| 874 |
+
version_added = '2.1'
|
| 875 |
+
|
| 876 |
+
# NOTE:
|
| 877 |
+
# * multiline with trailing backslash
|
| 878 |
+
# * separator is ':'
|
| 879 |
+
# * to embed colon as data, we must use \072
|
| 880 |
+
# * space after separator is not allowed (mayve)
|
| 881 |
+
tokens = {
|
| 882 |
+
'root': [
|
| 883 |
+
(r'^#.*', Comment),
|
| 884 |
+
(r'^[^\s#:|]+', Name.Tag, 'names'),
|
| 885 |
+
(r'\s+', Whitespace),
|
| 886 |
+
],
|
| 887 |
+
'names': [
|
| 888 |
+
(r'\n', Whitespace, '#pop'),
|
| 889 |
+
(r':', Punctuation, 'defs'),
|
| 890 |
+
(r'\|', Punctuation),
|
| 891 |
+
(r'[^:|]+', Name.Attribute),
|
| 892 |
+
],
|
| 893 |
+
'defs': [
|
| 894 |
+
(r'(\\)(\n[ \t]*)', bygroups(Text, Whitespace)),
|
| 895 |
+
(r'\n[ \t]*', Whitespace, '#pop:2'),
|
| 896 |
+
(r'(#)([0-9]+)', bygroups(Operator, Number)),
|
| 897 |
+
(r'=', Operator, 'data'),
|
| 898 |
+
(r':', Punctuation),
|
| 899 |
+
(r'[^\s:=#]+', Name.Class),
|
| 900 |
+
],
|
| 901 |
+
'data': [
|
| 902 |
+
(r'\\072', Literal),
|
| 903 |
+
(r':', Punctuation, '#pop'),
|
| 904 |
+
(r'[^:\\]+', Literal), # for performance
|
| 905 |
+
(r'.', Literal),
|
| 906 |
+
],
|
| 907 |
+
}
|
| 908 |
+
|
| 909 |
+
|
| 910 |
+
class TerminfoLexer(RegexLexer):
|
| 911 |
+
"""
|
| 912 |
+
Lexer for terminfo database source.
|
| 913 |
+
|
| 914 |
+
This is very simple and minimal.
|
| 915 |
+
"""
|
| 916 |
+
name = 'Terminfo'
|
| 917 |
+
aliases = ['terminfo']
|
| 918 |
+
filenames = ['terminfo', 'terminfo.src']
|
| 919 |
+
mimetypes = []
|
| 920 |
+
url = 'https://en.wikipedia.org/wiki/Terminfo'
|
| 921 |
+
version_added = '2.1'
|
| 922 |
+
|
| 923 |
+
# NOTE:
|
| 924 |
+
# * multiline with leading whitespace
|
| 925 |
+
# * separator is ','
|
| 926 |
+
# * to embed comma as data, we can use \,
|
| 927 |
+
# * space after separator is allowed
|
| 928 |
+
tokens = {
|
| 929 |
+
'root': [
|
| 930 |
+
(r'^#.*$', Comment),
|
| 931 |
+
(r'^[^\s#,|]+', Name.Tag, 'names'),
|
| 932 |
+
(r'\s+', Whitespace),
|
| 933 |
+
],
|
| 934 |
+
'names': [
|
| 935 |
+
(r'\n', Whitespace, '#pop'),
|
| 936 |
+
(r'(,)([ \t]*)', bygroups(Punctuation, Whitespace), 'defs'),
|
| 937 |
+
(r'\|', Punctuation),
|
| 938 |
+
(r'[^,|]+', Name.Attribute),
|
| 939 |
+
],
|
| 940 |
+
'defs': [
|
| 941 |
+
(r'\n[ \t]+', Whitespace),
|
| 942 |
+
(r'\n', Whitespace, '#pop:2'),
|
| 943 |
+
(r'(#)([0-9]+)', bygroups(Operator, Number)),
|
| 944 |
+
(r'=', Operator, 'data'),
|
| 945 |
+
(r'(,)([ \t]*)', bygroups(Punctuation, Whitespace)),
|
| 946 |
+
(r'[^\s,=#]+', Name.Class),
|
| 947 |
+
],
|
| 948 |
+
'data': [
|
| 949 |
+
(r'\\[,\\]', Literal),
|
| 950 |
+
(r'(,)([ \t]*)', bygroups(Punctuation, Whitespace), '#pop'),
|
| 951 |
+
(r'[^\\,]+', Literal), # for performance
|
| 952 |
+
(r'.', Literal),
|
| 953 |
+
],
|
| 954 |
+
}
|
| 955 |
+
|
| 956 |
+
|
| 957 |
+
class PkgConfigLexer(RegexLexer):
|
| 958 |
+
"""
|
| 959 |
+
Lexer for pkg-config
|
| 960 |
+
(see also `manual page <http://linux.die.net/man/1/pkg-config>`_).
|
| 961 |
+
"""
|
| 962 |
+
|
| 963 |
+
name = 'PkgConfig'
|
| 964 |
+
url = 'http://www.freedesktop.org/wiki/Software/pkg-config/'
|
| 965 |
+
aliases = ['pkgconfig']
|
| 966 |
+
filenames = ['*.pc']
|
| 967 |
+
mimetypes = []
|
| 968 |
+
version_added = '2.1'
|
| 969 |
+
|
| 970 |
+
tokens = {
|
| 971 |
+
'root': [
|
| 972 |
+
(r'#.*$', Comment.Single),
|
| 973 |
+
|
| 974 |
+
# variable definitions
|
| 975 |
+
(r'^(\w+)(=)', bygroups(Name.Attribute, Operator)),
|
| 976 |
+
|
| 977 |
+
# keyword lines
|
| 978 |
+
(r'^([\w.]+)(:)',
|
| 979 |
+
bygroups(Name.Tag, Punctuation), 'spvalue'),
|
| 980 |
+
|
| 981 |
+
# variable references
|
| 982 |
+
include('interp'),
|
| 983 |
+
|
| 984 |
+
# fallback
|
| 985 |
+
(r'\s+', Whitespace),
|
| 986 |
+
(r'[^${}#=:\n.]+', Text),
|
| 987 |
+
(r'.', Text),
|
| 988 |
+
],
|
| 989 |
+
'interp': [
|
| 990 |
+
# you can escape literal "$" as "$$"
|
| 991 |
+
(r'\$\$', Text),
|
| 992 |
+
|
| 993 |
+
# variable references
|
| 994 |
+
(r'\$\{', String.Interpol, 'curly'),
|
| 995 |
+
],
|
| 996 |
+
'curly': [
|
| 997 |
+
(r'\}', String.Interpol, '#pop'),
|
| 998 |
+
(r'\w+', Name.Attribute),
|
| 999 |
+
],
|
| 1000 |
+
'spvalue': [
|
| 1001 |
+
include('interp'),
|
| 1002 |
+
|
| 1003 |
+
(r'#.*$', Comment.Single, '#pop'),
|
| 1004 |
+
(r'\n', Whitespace, '#pop'),
|
| 1005 |
+
|
| 1006 |
+
# fallback
|
| 1007 |
+
(r'\s+', Whitespace),
|
| 1008 |
+
(r'[^${}#\n\s]+', Text),
|
| 1009 |
+
(r'.', Text),
|
| 1010 |
+
],
|
| 1011 |
+
}
|
| 1012 |
+
|
| 1013 |
+
|
| 1014 |
+
class PacmanConfLexer(RegexLexer):
|
| 1015 |
+
"""
|
| 1016 |
+
Lexer for pacman.conf.
|
| 1017 |
+
|
| 1018 |
+
Actually, IniLexer works almost fine for this format,
|
| 1019 |
+
but it yield error token. It is because pacman.conf has
|
| 1020 |
+
a form without assignment like:
|
| 1021 |
+
|
| 1022 |
+
UseSyslog
|
| 1023 |
+
Color
|
| 1024 |
+
TotalDownload
|
| 1025 |
+
CheckSpace
|
| 1026 |
+
VerbosePkgLists
|
| 1027 |
+
|
| 1028 |
+
These are flags to switch on.
|
| 1029 |
+
"""
|
| 1030 |
+
|
| 1031 |
+
name = 'PacmanConf'
|
| 1032 |
+
url = 'https://www.archlinux.org/pacman/pacman.conf.5.html'
|
| 1033 |
+
aliases = ['pacmanconf']
|
| 1034 |
+
filenames = ['pacman.conf']
|
| 1035 |
+
mimetypes = []
|
| 1036 |
+
version_added = '2.1'
|
| 1037 |
+
|
| 1038 |
+
tokens = {
|
| 1039 |
+
'root': [
|
| 1040 |
+
# comment
|
| 1041 |
+
(r'#.*$', Comment.Single),
|
| 1042 |
+
|
| 1043 |
+
# section header
|
| 1044 |
+
(r'^(\s*)(\[.*?\])(\s*)$', bygroups(Whitespace, Keyword, Whitespace)),
|
| 1045 |
+
|
| 1046 |
+
# variable definitions
|
| 1047 |
+
# (Leading space is allowed...)
|
| 1048 |
+
(r'(\w+)(\s*)(=)',
|
| 1049 |
+
bygroups(Name.Attribute, Whitespace, Operator)),
|
| 1050 |
+
|
| 1051 |
+
# flags to on
|
| 1052 |
+
(r'^(\s*)(\w+)(\s*)$',
|
| 1053 |
+
bygroups(Whitespace, Name.Attribute, Whitespace)),
|
| 1054 |
+
|
| 1055 |
+
# built-in special values
|
| 1056 |
+
(words((
|
| 1057 |
+
'$repo', # repository
|
| 1058 |
+
'$arch', # architecture
|
| 1059 |
+
'%o', # outfile
|
| 1060 |
+
'%u', # url
|
| 1061 |
+
), suffix=r'\b'),
|
| 1062 |
+
Name.Variable),
|
| 1063 |
+
|
| 1064 |
+
# fallback
|
| 1065 |
+
(r'\s+', Whitespace),
|
| 1066 |
+
(r'.', Text),
|
| 1067 |
+
],
|
| 1068 |
+
}
|
| 1069 |
+
|
| 1070 |
+
|
| 1071 |
+
class AugeasLexer(RegexLexer):
|
| 1072 |
+
"""
|
| 1073 |
+
Lexer for Augeas.
|
| 1074 |
+
"""
|
| 1075 |
+
name = 'Augeas'
|
| 1076 |
+
url = 'http://augeas.net'
|
| 1077 |
+
aliases = ['augeas']
|
| 1078 |
+
filenames = ['*.aug']
|
| 1079 |
+
version_added = '2.4'
|
| 1080 |
+
|
| 1081 |
+
tokens = {
|
| 1082 |
+
'root': [
|
| 1083 |
+
(r'(module)(\s*)([^\s=]+)', bygroups(Keyword.Namespace, Whitespace, Name.Namespace)),
|
| 1084 |
+
(r'(let)(\s*)([^\s=]+)', bygroups(Keyword.Declaration, Whitespace, Name.Variable)),
|
| 1085 |
+
(r'(del|store|value|counter|seq|key|label|autoload|incl|excl|transform|test|get|put)(\s+)', bygroups(Name.Builtin, Whitespace)),
|
| 1086 |
+
(r'(\()([^:]+)(\:)(unit|string|regexp|lens|tree|filter)(\))', bygroups(Punctuation, Name.Variable, Punctuation, Keyword.Type, Punctuation)),
|
| 1087 |
+
(r'\(\*', Comment.Multiline, 'comment'),
|
| 1088 |
+
(r'[*+\-.;=?|]', Operator),
|
| 1089 |
+
(r'[()\[\]{}]', Operator),
|
| 1090 |
+
(r'"', String.Double, 'string'),
|
| 1091 |
+
(r'\/', String.Regex, 'regex'),
|
| 1092 |
+
(r'([A-Z]\w*)(\.)(\w+)', bygroups(Name.Namespace, Punctuation, Name.Variable)),
|
| 1093 |
+
(r'.', Name.Variable),
|
| 1094 |
+
(r'\s+', Whitespace),
|
| 1095 |
+
],
|
| 1096 |
+
'string': [
|
| 1097 |
+
(r'\\.', String.Escape),
|
| 1098 |
+
(r'[^"]', String.Double),
|
| 1099 |
+
(r'"', String.Double, '#pop'),
|
| 1100 |
+
],
|
| 1101 |
+
'regex': [
|
| 1102 |
+
(r'\\.', String.Escape),
|
| 1103 |
+
(r'[^/]', String.Regex),
|
| 1104 |
+
(r'\/', String.Regex, '#pop'),
|
| 1105 |
+
],
|
| 1106 |
+
'comment': [
|
| 1107 |
+
(r'[^*)]', Comment.Multiline),
|
| 1108 |
+
(r'\(\*', Comment.Multiline, '#push'),
|
| 1109 |
+
(r'\*\)', Comment.Multiline, '#pop'),
|
| 1110 |
+
(r'[)*]', Comment.Multiline)
|
| 1111 |
+
],
|
| 1112 |
+
}
|
| 1113 |
+
|
| 1114 |
+
|
| 1115 |
+
class TOMLLexer(RegexLexer):
|
| 1116 |
+
"""
|
| 1117 |
+
Lexer for TOML, a simple language for config files.
|
| 1118 |
+
"""
|
| 1119 |
+
|
| 1120 |
+
name = 'TOML'
|
| 1121 |
+
aliases = ['toml']
|
| 1122 |
+
filenames = ['*.toml', 'Pipfile', 'poetry.lock']
|
| 1123 |
+
mimetypes = ['application/toml']
|
| 1124 |
+
url = 'https://toml.io'
|
| 1125 |
+
version_added = '2.4'
|
| 1126 |
+
|
| 1127 |
+
# Based on the TOML spec: https://toml.io/en/v1.0.0
|
| 1128 |
+
|
| 1129 |
+
# The following is adapted from CPython's tomllib:
|
| 1130 |
+
_time = r"\d\d:\d\d(:\d\d(\.\d+)?)?"
|
| 1131 |
+
_datetime = rf"""(?x)
|
| 1132 |
+
\d\d\d\d-\d\d-\d\d # date, e.g., 1988-10-27
|
| 1133 |
+
(
|
| 1134 |
+
[Tt ] {_time} # optional time
|
| 1135 |
+
(
|
| 1136 |
+
[Zz]|[+-]\d\d:\d\d # optional time offset
|
| 1137 |
+
)?
|
| 1138 |
+
)?
|
| 1139 |
+
"""
|
| 1140 |
+
|
| 1141 |
+
tokens = {
|
| 1142 |
+
'root': [
|
| 1143 |
+
# Note that we make an effort in order to distinguish
|
| 1144 |
+
# moments at which we're parsing a key and moments at
|
| 1145 |
+
# which we're parsing a value. In the TOML code
|
| 1146 |
+
#
|
| 1147 |
+
# 1234 = 1234
|
| 1148 |
+
#
|
| 1149 |
+
# the first "1234" should be Name, the second Integer.
|
| 1150 |
+
|
| 1151 |
+
# Whitespace
|
| 1152 |
+
(r'\s+', Whitespace),
|
| 1153 |
+
|
| 1154 |
+
# Comment
|
| 1155 |
+
(r'#.*', Comment.Single),
|
| 1156 |
+
|
| 1157 |
+
# Assignment keys
|
| 1158 |
+
include('key'),
|
| 1159 |
+
|
| 1160 |
+
# After "=", find a value
|
| 1161 |
+
(r'(=)(\s*)', bygroups(Operator, Whitespace), 'value'),
|
| 1162 |
+
|
| 1163 |
+
# Table header
|
| 1164 |
+
(r'\[\[?', Keyword, 'table-key'),
|
| 1165 |
+
],
|
| 1166 |
+
'key': [
|
| 1167 |
+
# Start of bare key (only ASCII is allowed here).
|
| 1168 |
+
(r'[A-Za-z0-9_-]+', Name),
|
| 1169 |
+
# Quoted key
|
| 1170 |
+
(r'"', String.Double, 'basic-string'),
|
| 1171 |
+
(r"'", String.Single, 'literal-string'),
|
| 1172 |
+
# Dots act as separators in keys
|
| 1173 |
+
(r'\.', Punctuation),
|
| 1174 |
+
],
|
| 1175 |
+
'table-key': [
|
| 1176 |
+
# This is like 'key', but highlights the name components
|
| 1177 |
+
# and separating dots as Keyword because it looks better
|
| 1178 |
+
# when the whole table header is Keyword. We do highlight
|
| 1179 |
+
# strings as strings though.
|
| 1180 |
+
# Start of bare key (only ASCII is allowed here).
|
| 1181 |
+
(r'[A-Za-z0-9_-]+', Keyword),
|
| 1182 |
+
(r'"', String.Double, 'basic-string'),
|
| 1183 |
+
(r"'", String.Single, 'literal-string'),
|
| 1184 |
+
(r'\.', Keyword),
|
| 1185 |
+
(r'\]\]?', Keyword, '#pop'),
|
| 1186 |
+
|
| 1187 |
+
# Inline whitespace allowed
|
| 1188 |
+
(r'[ \t]+', Whitespace),
|
| 1189 |
+
],
|
| 1190 |
+
'value': [
|
| 1191 |
+
# Datetime, baretime
|
| 1192 |
+
(_datetime, Literal.Date, '#pop'),
|
| 1193 |
+
(_time, Literal.Date, '#pop'),
|
| 1194 |
+
|
| 1195 |
+
# Recognize as float if there is a fractional part
|
| 1196 |
+
# and/or an exponent.
|
| 1197 |
+
(r'[+-]?\d[0-9_]*[eE][+-]?\d[0-9_]*', Number.Float, '#pop'),
|
| 1198 |
+
(r'[+-]?\d[0-9_]*\.\d[0-9_]*([eE][+-]?\d[0-9_]*)?',
|
| 1199 |
+
Number.Float, '#pop'),
|
| 1200 |
+
|
| 1201 |
+
# Infinities and NaN
|
| 1202 |
+
(r'[+-]?(inf|nan)', Number.Float, '#pop'),
|
| 1203 |
+
|
| 1204 |
+
# Integers
|
| 1205 |
+
(r'-?0b[01_]+', Number.Bin, '#pop'),
|
| 1206 |
+
(r'-?0o[0-7_]+', Number.Oct, '#pop'),
|
| 1207 |
+
(r'-?0x[0-9a-fA-F_]+', Number.Hex, '#pop'),
|
| 1208 |
+
(r'[+-]?[0-9_]+', Number.Integer, '#pop'),
|
| 1209 |
+
|
| 1210 |
+
# Strings
|
| 1211 |
+
(r'"""', String.Double, ('#pop', 'multiline-basic-string')),
|
| 1212 |
+
(r'"', String.Double, ('#pop', 'basic-string')),
|
| 1213 |
+
(r"'''", String.Single, ('#pop', 'multiline-literal-string')),
|
| 1214 |
+
(r"'", String.Single, ('#pop', 'literal-string')),
|
| 1215 |
+
|
| 1216 |
+
# Booleans
|
| 1217 |
+
(r'true|false', Keyword.Constant, '#pop'),
|
| 1218 |
+
|
| 1219 |
+
# Start of array
|
| 1220 |
+
(r'\[', Punctuation, ('#pop', 'array')),
|
| 1221 |
+
|
| 1222 |
+
# Start of inline table
|
| 1223 |
+
(r'\{', Punctuation, ('#pop', 'inline-table')),
|
| 1224 |
+
],
|
| 1225 |
+
'array': [
|
| 1226 |
+
# Whitespace, including newlines, is ignored inside arrays,
|
| 1227 |
+
# and comments are allowed.
|
| 1228 |
+
(r'\s+', Whitespace),
|
| 1229 |
+
(r'#.*', Comment.Single),
|
| 1230 |
+
|
| 1231 |
+
# Delimiters
|
| 1232 |
+
(r',', Punctuation),
|
| 1233 |
+
|
| 1234 |
+
# End of array
|
| 1235 |
+
(r'\]', Punctuation, '#pop'),
|
| 1236 |
+
|
| 1237 |
+
# Parse a value and come back
|
| 1238 |
+
default('value'),
|
| 1239 |
+
],
|
| 1240 |
+
'inline-table': [
|
| 1241 |
+
# Whitespace (since TOML 1.1.0, same as in array)
|
| 1242 |
+
(r'\s+', Whitespace),
|
| 1243 |
+
(r'#.*', Comment.Single),
|
| 1244 |
+
|
| 1245 |
+
# Keys
|
| 1246 |
+
include('key'),
|
| 1247 |
+
|
| 1248 |
+
# Values
|
| 1249 |
+
(r'(=)(\s*)', bygroups(Punctuation, Whitespace), 'value'),
|
| 1250 |
+
|
| 1251 |
+
# Delimiters
|
| 1252 |
+
(r',', Punctuation),
|
| 1253 |
+
|
| 1254 |
+
# End of inline table
|
| 1255 |
+
(r'\}', Punctuation, '#pop'),
|
| 1256 |
+
],
|
| 1257 |
+
'basic-string': [
|
| 1258 |
+
(r'"', String.Double, '#pop'),
|
| 1259 |
+
include('escapes'),
|
| 1260 |
+
(r'[^"\\]+', String.Double),
|
| 1261 |
+
],
|
| 1262 |
+
'literal-string': [
|
| 1263 |
+
(r".*?'", String.Single, '#pop'),
|
| 1264 |
+
],
|
| 1265 |
+
'multiline-basic-string': [
|
| 1266 |
+
(r'"""', String.Double, '#pop'),
|
| 1267 |
+
(r'(\\)(\n)', bygroups(String.Escape, Whitespace)),
|
| 1268 |
+
include('escapes'),
|
| 1269 |
+
(r'[^"\\]+', String.Double),
|
| 1270 |
+
(r'"', String.Double),
|
| 1271 |
+
],
|
| 1272 |
+
'multiline-literal-string': [
|
| 1273 |
+
(r"'''", String.Single, '#pop'),
|
| 1274 |
+
(r"[^']+", String.Single),
|
| 1275 |
+
(r"'", String.Single),
|
| 1276 |
+
],
|
| 1277 |
+
'escapes': [
|
| 1278 |
+
(r'\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}', String.Escape),
|
| 1279 |
+
(r'\\.', String.Escape),
|
| 1280 |
+
],
|
| 1281 |
+
}
|
| 1282 |
+
|
| 1283 |
+
class NestedTextLexer(RegexLexer):
|
| 1284 |
+
"""
|
| 1285 |
+
Lexer for *NextedText*, a human-friendly data format.
|
| 1286 |
+
|
| 1287 |
+
.. versionchanged:: 2.16
|
| 1288 |
+
Added support for *NextedText* v3.0.
|
| 1289 |
+
"""
|
| 1290 |
+
|
| 1291 |
+
name = 'NestedText'
|
| 1292 |
+
url = 'https://nestedtext.org'
|
| 1293 |
+
aliases = ['nestedtext', 'nt']
|
| 1294 |
+
filenames = ['*.nt']
|
| 1295 |
+
version_added = '2.9'
|
| 1296 |
+
|
| 1297 |
+
tokens = {
|
| 1298 |
+
'root': [
|
| 1299 |
+
# Comment: # ...
|
| 1300 |
+
(r'^([ ]*)(#.*)$', bygroups(Whitespace, Comment)),
|
| 1301 |
+
|
| 1302 |
+
# Inline dictionary: {...}
|
| 1303 |
+
(r'^([ ]*)(\{)', bygroups(Whitespace, Punctuation), 'inline_dict'),
|
| 1304 |
+
|
| 1305 |
+
# Inline list: [...]
|
| 1306 |
+
(r'^([ ]*)(\[)', bygroups(Whitespace, Punctuation), 'inline_list'),
|
| 1307 |
+
|
| 1308 |
+
# empty multiline string item: >
|
| 1309 |
+
(r'^([ ]*)(>)$', bygroups(Whitespace, Punctuation)),
|
| 1310 |
+
|
| 1311 |
+
# multiline string item: > ...
|
| 1312 |
+
(r'^([ ]*)(>)( )(.*?)([ \t]*)$', bygroups(Whitespace, Punctuation, Whitespace, Text, Whitespace)),
|
| 1313 |
+
|
| 1314 |
+
# empty list item: -
|
| 1315 |
+
(r'^([ ]*)(-)$', bygroups(Whitespace, Punctuation)),
|
| 1316 |
+
|
| 1317 |
+
# list item: - ...
|
| 1318 |
+
(r'^([ ]*)(-)( )(.*?)([ \t]*)$', bygroups(Whitespace, Punctuation, Whitespace, Text, Whitespace)),
|
| 1319 |
+
|
| 1320 |
+
# empty multiline key item: :
|
| 1321 |
+
(r'^([ ]*)(:)$', bygroups(Whitespace, Punctuation)),
|
| 1322 |
+
|
| 1323 |
+
# multiline key item: : ...
|
| 1324 |
+
(r'^([ ]*)(:)( )([^\n]*?)([ \t]*)$', bygroups(Whitespace, Punctuation, Whitespace, Name.Tag, Whitespace)),
|
| 1325 |
+
|
| 1326 |
+
# empty dict key item: ...:
|
| 1327 |
+
(r'^([ ]*)([^\{\[\s].*?)(:)$', bygroups(Whitespace, Name.Tag, Punctuation)),
|
| 1328 |
+
|
| 1329 |
+
# dict key item: ...: ...
|
| 1330 |
+
(r'^([ ]*)([^\{\[\s].*?)(:)( )(.*?)([ \t]*)$', bygroups(Whitespace, Name.Tag, Punctuation, Whitespace, Text, Whitespace)),
|
| 1331 |
+
],
|
| 1332 |
+
'inline_list': [
|
| 1333 |
+
include('whitespace'),
|
| 1334 |
+
(r'[^\{\}\[\],\s]+', Text),
|
| 1335 |
+
include('inline_value'),
|
| 1336 |
+
(r',', Punctuation),
|
| 1337 |
+
(r'\]', Punctuation, '#pop'),
|
| 1338 |
+
(r'\n', Error, '#pop'),
|
| 1339 |
+
],
|
| 1340 |
+
'inline_dict': [
|
| 1341 |
+
include('whitespace'),
|
| 1342 |
+
(r'[^\{\}\[\],:\s]+', Name.Tag),
|
| 1343 |
+
(r':', Punctuation, 'inline_dict_value'),
|
| 1344 |
+
(r'\}', Punctuation, '#pop'),
|
| 1345 |
+
(r'\n', Error, '#pop'),
|
| 1346 |
+
],
|
| 1347 |
+
'inline_dict_value': [
|
| 1348 |
+
include('whitespace'),
|
| 1349 |
+
(r'[^\{\}\[\],:\s]+', Text),
|
| 1350 |
+
include('inline_value'),
|
| 1351 |
+
(r',', Punctuation, '#pop'),
|
| 1352 |
+
(r'\}', Punctuation, '#pop:2'),
|
| 1353 |
+
],
|
| 1354 |
+
'inline_value': [
|
| 1355 |
+
include('whitespace'),
|
| 1356 |
+
(r'\{', Punctuation, 'inline_dict'),
|
| 1357 |
+
(r'\[', Punctuation, 'inline_list'),
|
| 1358 |
+
],
|
| 1359 |
+
'whitespace': [
|
| 1360 |
+
(r'[ \t]+', Whitespace),
|
| 1361 |
+
],
|
| 1362 |
+
}
|
| 1363 |
+
|
| 1364 |
+
|
| 1365 |
+
class SingularityLexer(RegexLexer):
|
| 1366 |
+
"""
|
| 1367 |
+
Lexer for Singularity definition files.
|
| 1368 |
+
"""
|
| 1369 |
+
|
| 1370 |
+
name = 'Singularity'
|
| 1371 |
+
url = 'https://www.sylabs.io/guides/3.0/user-guide/definition_files.html'
|
| 1372 |
+
aliases = ['singularity']
|
| 1373 |
+
filenames = ['*.def', 'Singularity']
|
| 1374 |
+
version_added = '2.6'
|
| 1375 |
+
flags = re.IGNORECASE | re.MULTILINE | re.DOTALL
|
| 1376 |
+
|
| 1377 |
+
_headers = r'^(\s*)(bootstrap|from|osversion|mirrorurl|include|registry|namespace|includecmd)(:)'
|
| 1378 |
+
_section = r'^(%(?:pre|post|setup|environment|help|labels|test|runscript|files|startscript))(\s*)'
|
| 1379 |
+
_appsect = r'^(%app(?:install|help|run|labels|env|test|files))(\s*)'
|
| 1380 |
+
|
| 1381 |
+
tokens = {
|
| 1382 |
+
'root': [
|
| 1383 |
+
(_section, bygroups(Generic.Heading, Whitespace), 'script'),
|
| 1384 |
+
(_appsect, bygroups(Generic.Heading, Whitespace), 'script'),
|
| 1385 |
+
(_headers, bygroups(Whitespace, Keyword, Text)),
|
| 1386 |
+
(r'\s*#.*?\n', Comment),
|
| 1387 |
+
(r'\b(([0-9]+\.?[0-9]*)|(\.[0-9]+))\b', Number),
|
| 1388 |
+
(r'[ \t]+', Whitespace),
|
| 1389 |
+
(r'(?!^\s*%).', Text),
|
| 1390 |
+
],
|
| 1391 |
+
'script': [
|
| 1392 |
+
(r'(.+?(?=^\s*%))|(.*)', using(BashLexer), '#pop'),
|
| 1393 |
+
],
|
| 1394 |
+
}
|
| 1395 |
+
|
| 1396 |
+
def analyse_text(text):
|
| 1397 |
+
"""This is a quite simple script file, but there are a few keywords
|
| 1398 |
+
which seem unique to this language."""
|
| 1399 |
+
result = 0
|
| 1400 |
+
if re.search(r'\b(?:osversion|includecmd|mirrorurl)\b', text, re.IGNORECASE):
|
| 1401 |
+
result += 0.5
|
| 1402 |
+
|
| 1403 |
+
if re.search(SingularityLexer._section[1:], text):
|
| 1404 |
+
result += 0.49
|
| 1405 |
+
|
| 1406 |
+
return result
|
| 1407 |
+
|
| 1408 |
+
|
| 1409 |
+
class UnixConfigLexer(RegexLexer):
|
| 1410 |
+
"""
|
| 1411 |
+
Lexer for Unix/Linux config files using colon-separated values, e.g.
|
| 1412 |
+
|
| 1413 |
+
* ``/etc/group``
|
| 1414 |
+
* ``/etc/passwd``
|
| 1415 |
+
* ``/etc/shadow``
|
| 1416 |
+
"""
|
| 1417 |
+
|
| 1418 |
+
name = 'Unix/Linux config files'
|
| 1419 |
+
aliases = ['unixconfig', 'linuxconfig']
|
| 1420 |
+
filenames = []
|
| 1421 |
+
url = 'https://en.wikipedia.org/wiki/Configuration_file#Unix_and_Unix-like_operating_systems'
|
| 1422 |
+
version_added = '2.12'
|
| 1423 |
+
|
| 1424 |
+
tokens = {
|
| 1425 |
+
'root': [
|
| 1426 |
+
(r'^#.*', Comment),
|
| 1427 |
+
(r'\n', Whitespace),
|
| 1428 |
+
(r':', Punctuation),
|
| 1429 |
+
(r'[0-9]+', Number),
|
| 1430 |
+
(r'((?!\n)[a-zA-Z0-9\_\-\s\(\),]){2,}', Text),
|
| 1431 |
+
(r'[^:\n]+', String),
|
| 1432 |
+
],
|
| 1433 |
+
}
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/factor.py
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.factor
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexers for the Factor language.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from pygments.lexer import RegexLexer, bygroups, default, words
|
| 12 |
+
from pygments.token import Text, Comment, Keyword, Name, String, Number, \
|
| 13 |
+
Whitespace, Punctuation
|
| 14 |
+
|
| 15 |
+
__all__ = ['FactorLexer']
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class FactorLexer(RegexLexer):
|
| 19 |
+
"""
|
| 20 |
+
Lexer for the Factor language.
|
| 21 |
+
"""
|
| 22 |
+
name = 'Factor'
|
| 23 |
+
url = 'http://factorcode.org'
|
| 24 |
+
aliases = ['factor']
|
| 25 |
+
filenames = ['*.factor']
|
| 26 |
+
mimetypes = ['text/x-factor']
|
| 27 |
+
version_added = '1.4'
|
| 28 |
+
|
| 29 |
+
builtin_kernel = words((
|
| 30 |
+
'-rot', '2bi', '2bi@', '2bi*', '2curry', '2dip', '2drop', '2dup', '2keep', '2nip',
|
| 31 |
+
'2over', '2tri', '2tri@', '2tri*', '3bi', '3curry', '3dip', '3drop', '3dup', '3keep',
|
| 32 |
+
'3tri', '4dip', '4drop', '4dup', '4keep', '<wrapper>', '=', '>boolean', 'clone',
|
| 33 |
+
'?', '?execute', '?if', 'and', 'assert', 'assert=', 'assert?', 'bi', 'bi-curry',
|
| 34 |
+
'bi-curry@', 'bi-curry*', 'bi@', 'bi*', 'boa', 'boolean', 'boolean?', 'both?',
|
| 35 |
+
'build', 'call', 'callstack', 'callstack>array', 'callstack?', 'clear', '(clone)',
|
| 36 |
+
'compose', 'compose?', 'curry', 'curry?', 'datastack', 'die', 'dip', 'do', 'drop',
|
| 37 |
+
'dup', 'dupd', 'either?', 'eq?', 'equal?', 'execute', 'hashcode', 'hashcode*',
|
| 38 |
+
'identity-hashcode', 'identity-tuple', 'identity-tuple?', 'if', 'if*',
|
| 39 |
+
'keep', 'loop', 'most', 'new', 'nip', 'not', 'null', 'object', 'or', 'over',
|
| 40 |
+
'pick', 'prepose', 'retainstack', 'rot', 'same?', 'swap', 'swapd', 'throw',
|
| 41 |
+
'tri', 'tri-curry', 'tri-curry@', 'tri-curry*', 'tri@', 'tri*', 'tuple',
|
| 42 |
+
'tuple?', 'unless', 'unless*', 'until', 'when', 'when*', 'while', 'with',
|
| 43 |
+
'wrapper', 'wrapper?', 'xor'), suffix=r'(\s+)')
|
| 44 |
+
|
| 45 |
+
builtin_assocs = words((
|
| 46 |
+
'2cache', '<enum>', '>alist', '?at', '?of', 'assoc', 'assoc-all?',
|
| 47 |
+
'assoc-any?', 'assoc-clone-like', 'assoc-combine', 'assoc-diff',
|
| 48 |
+
'assoc-diff!', 'assoc-differ', 'assoc-each', 'assoc-empty?',
|
| 49 |
+
'assoc-filter', 'assoc-filter!', 'assoc-filter-as', 'assoc-find',
|
| 50 |
+
'assoc-hashcode', 'assoc-intersect', 'assoc-like', 'assoc-map',
|
| 51 |
+
'assoc-map-as', 'assoc-partition', 'assoc-refine', 'assoc-size',
|
| 52 |
+
'assoc-stack', 'assoc-subset?', 'assoc-union', 'assoc-union!',
|
| 53 |
+
'assoc=', 'assoc>map', 'assoc?', 'at', 'at+', 'at*', 'cache', 'change-at',
|
| 54 |
+
'clear-assoc', 'delete-at', 'delete-at*', 'enum', 'enum?', 'extract-keys',
|
| 55 |
+
'inc-at', 'key?', 'keys', 'map>assoc', 'maybe-set-at', 'new-assoc', 'of',
|
| 56 |
+
'push-at', 'rename-at', 'set-at', 'sift-keys', 'sift-values', 'substitute',
|
| 57 |
+
'unzip', 'value-at', 'value-at*', 'value?', 'values', 'zip'), suffix=r'(\s+)')
|
| 58 |
+
|
| 59 |
+
builtin_combinators = words((
|
| 60 |
+
'2cleave', '2cleave>quot', '3cleave', '3cleave>quot', '4cleave',
|
| 61 |
+
'4cleave>quot', 'alist>quot', 'call-effect', 'case', 'case-find',
|
| 62 |
+
'case>quot', 'cleave', 'cleave>quot', 'cond', 'cond>quot', 'deep-spread>quot',
|
| 63 |
+
'execute-effect', 'linear-case-quot', 'no-case', 'no-case?', 'no-cond',
|
| 64 |
+
'no-cond?', 'recursive-hashcode', 'shallow-spread>quot', 'spread',
|
| 65 |
+
'to-fixed-point', 'wrong-values', 'wrong-values?'), suffix=r'(\s+)')
|
| 66 |
+
|
| 67 |
+
builtin_math = words((
|
| 68 |
+
'-', '/', '/f', '/i', '/mod', '2/', '2^', '<', '<=', '<fp-nan>', '>',
|
| 69 |
+
'>=', '>bignum', '>fixnum', '>float', '>integer', '(all-integers?)',
|
| 70 |
+
'(each-integer)', '(find-integer)', '*', '+', '?1+',
|
| 71 |
+
'abs', 'align', 'all-integers?', 'bignum', 'bignum?', 'bit?', 'bitand',
|
| 72 |
+
'bitnot', 'bitor', 'bits>double', 'bits>float', 'bitxor', 'complex',
|
| 73 |
+
'complex?', 'denominator', 'double>bits', 'each-integer', 'even?',
|
| 74 |
+
'find-integer', 'find-last-integer', 'fixnum', 'fixnum?', 'float',
|
| 75 |
+
'float>bits', 'float?', 'fp-bitwise=', 'fp-infinity?', 'fp-nan-payload',
|
| 76 |
+
'fp-nan?', 'fp-qnan?', 'fp-sign', 'fp-snan?', 'fp-special?',
|
| 77 |
+
'if-zero', 'imaginary-part', 'integer', 'integer>fixnum',
|
| 78 |
+
'integer>fixnum-strict', 'integer?', 'log2', 'log2-expects-positive',
|
| 79 |
+
'log2-expects-positive?', 'mod', 'neg', 'neg?', 'next-float',
|
| 80 |
+
'next-power-of-2', 'number', 'number=', 'number?', 'numerator', 'odd?',
|
| 81 |
+
'out-of-fixnum-range', 'out-of-fixnum-range?', 'power-of-2?',
|
| 82 |
+
'prev-float', 'ratio', 'ratio?', 'rational', 'rational?', 'real',
|
| 83 |
+
'real-part', 'real?', 'recip', 'rem', 'sgn', 'shift', 'sq', 'times',
|
| 84 |
+
'u<', 'u<=', 'u>', 'u>=', 'unless-zero', 'unordered?', 'when-zero',
|
| 85 |
+
'zero?'), suffix=r'(\s+)')
|
| 86 |
+
|
| 87 |
+
builtin_sequences = words((
|
| 88 |
+
'1sequence', '2all?', '2each', '2map', '2map-as', '2map-reduce', '2reduce',
|
| 89 |
+
'2selector', '2sequence', '3append', '3append-as', '3each', '3map', '3map-as',
|
| 90 |
+
'3sequence', '4sequence', '<repetition>', '<reversed>', '<slice>', '?first',
|
| 91 |
+
'?last', '?nth', '?second', '?set-nth', 'accumulate', 'accumulate!',
|
| 92 |
+
'accumulate-as', 'all?', 'any?', 'append', 'append!', 'append-as',
|
| 93 |
+
'assert-sequence', 'assert-sequence=', 'assert-sequence?',
|
| 94 |
+
'binary-reduce', 'bounds-check', 'bounds-check?', 'bounds-error',
|
| 95 |
+
'bounds-error?', 'but-last', 'but-last-slice', 'cartesian-each',
|
| 96 |
+
'cartesian-map', 'cartesian-product', 'change-nth', 'check-slice',
|
| 97 |
+
'check-slice-error', 'clone-like', 'collapse-slice', 'collector',
|
| 98 |
+
'collector-for', 'concat', 'concat-as', 'copy', 'count', 'cut', 'cut-slice',
|
| 99 |
+
'cut*', 'delete-all', 'delete-slice', 'drop-prefix', 'each', 'each-from',
|
| 100 |
+
'each-index', 'empty?', 'exchange', 'filter', 'filter!', 'filter-as', 'find',
|
| 101 |
+
'find-from', 'find-index', 'find-index-from', 'find-last', 'find-last-from',
|
| 102 |
+
'first', 'first2', 'first3', 'first4', 'flip', 'follow', 'fourth', 'glue', 'halves',
|
| 103 |
+
'harvest', 'head', 'head-slice', 'head-slice*', 'head*', 'head?',
|
| 104 |
+
'if-empty', 'immutable', 'immutable-sequence', 'immutable-sequence?',
|
| 105 |
+
'immutable?', 'index', 'index-from', 'indices', 'infimum', 'infimum-by',
|
| 106 |
+
'insert-nth', 'interleave', 'iota', 'iota-tuple', 'iota-tuple?', 'join',
|
| 107 |
+
'join-as', 'last', 'last-index', 'last-index-from', 'length', 'lengthen',
|
| 108 |
+
'like', 'longer', 'longer?', 'longest', 'map', 'map!', 'map-as', 'map-find',
|
| 109 |
+
'map-find-last', 'map-index', 'map-integers', 'map-reduce', 'map-sum',
|
| 110 |
+
'max-length', 'member-eq?', 'member?', 'midpoint@', 'min-length',
|
| 111 |
+
'mismatch', 'move', 'new-like', 'new-resizable', 'new-sequence',
|
| 112 |
+
'non-negative-integer-expected', 'non-negative-integer-expected?',
|
| 113 |
+
'nth', 'nths', 'pad-head', 'pad-tail', 'padding', 'partition', 'pop', 'pop*',
|
| 114 |
+
'prefix', 'prepend', 'prepend-as', 'produce', 'produce-as', 'product', 'push',
|
| 115 |
+
'push-all', 'push-either', 'push-if', 'reduce', 'reduce-index', 'remove',
|
| 116 |
+
'remove!', 'remove-eq', 'remove-eq!', 'remove-nth', 'remove-nth!', 'repetition',
|
| 117 |
+
'repetition?', 'replace-slice', 'replicate', 'replicate-as', 'rest',
|
| 118 |
+
'rest-slice', 'reverse', 'reverse!', 'reversed', 'reversed?', 'second',
|
| 119 |
+
'selector', 'selector-for', 'sequence', 'sequence-hashcode', 'sequence=',
|
| 120 |
+
'sequence?', 'set-first', 'set-fourth', 'set-last', 'set-length', 'set-nth',
|
| 121 |
+
'set-second', 'set-third', 'short', 'shorten', 'shorter', 'shorter?',
|
| 122 |
+
'shortest', 'sift', 'slice', 'slice-error', 'slice-error?', 'slice?',
|
| 123 |
+
'snip', 'snip-slice', 'start', 'start*', 'subseq', 'subseq?', 'suffix',
|
| 124 |
+
'suffix!', 'sum', 'sum-lengths', 'supremum', 'supremum-by', 'surround', 'tail',
|
| 125 |
+
'tail-slice', 'tail-slice*', 'tail*', 'tail?', 'third', 'trim',
|
| 126 |
+
'trim-head', 'trim-head-slice', 'trim-slice', 'trim-tail', 'trim-tail-slice',
|
| 127 |
+
'unclip', 'unclip-last', 'unclip-last-slice', 'unclip-slice', 'unless-empty',
|
| 128 |
+
'virtual-exemplar', 'virtual-sequence', 'virtual-sequence?', 'virtual@',
|
| 129 |
+
'when-empty'), suffix=r'(\s+)')
|
| 130 |
+
|
| 131 |
+
builtin_namespaces = words((
|
| 132 |
+
'+@', 'change', 'change-global', 'counter', 'dec', 'get', 'get-global',
|
| 133 |
+
'global', 'inc', 'init-namespaces', 'initialize', 'is-global', 'make-assoc',
|
| 134 |
+
'namespace', 'namestack', 'off', 'on', 'set', 'set-global', 'set-namestack',
|
| 135 |
+
'toggle', 'with-global', 'with-scope', 'with-variable', 'with-variables'),
|
| 136 |
+
suffix=r'(\s+)')
|
| 137 |
+
|
| 138 |
+
builtin_arrays = words((
|
| 139 |
+
'1array', '2array', '3array', '4array', '<array>', '>array', 'array',
|
| 140 |
+
'array?', 'pair', 'pair?', 'resize-array'), suffix=r'(\s+)')
|
| 141 |
+
|
| 142 |
+
builtin_io = words((
|
| 143 |
+
'(each-stream-block-slice)', '(each-stream-block)',
|
| 144 |
+
'(stream-contents-by-block)', '(stream-contents-by-element)',
|
| 145 |
+
'(stream-contents-by-length-or-block)',
|
| 146 |
+
'(stream-contents-by-length)', '+byte+', '+character+',
|
| 147 |
+
'bad-seek-type', 'bad-seek-type?', 'bl', 'contents', 'each-block',
|
| 148 |
+
'each-block-size', 'each-block-slice', 'each-line', 'each-morsel',
|
| 149 |
+
'each-stream-block', 'each-stream-block-slice', 'each-stream-line',
|
| 150 |
+
'error-stream', 'flush', 'input-stream', 'input-stream?',
|
| 151 |
+
'invalid-read-buffer', 'invalid-read-buffer?', 'lines', 'nl',
|
| 152 |
+
'output-stream', 'output-stream?', 'print', 'read', 'read-into',
|
| 153 |
+
'read-partial', 'read-partial-into', 'read-until', 'read1', 'readln',
|
| 154 |
+
'seek-absolute', 'seek-absolute?', 'seek-end', 'seek-end?',
|
| 155 |
+
'seek-input', 'seek-output', 'seek-relative', 'seek-relative?',
|
| 156 |
+
'stream-bl', 'stream-contents', 'stream-contents*', 'stream-copy',
|
| 157 |
+
'stream-copy*', 'stream-element-type', 'stream-flush',
|
| 158 |
+
'stream-length', 'stream-lines', 'stream-nl', 'stream-print',
|
| 159 |
+
'stream-read', 'stream-read-into', 'stream-read-partial',
|
| 160 |
+
'stream-read-partial-into', 'stream-read-partial-unsafe',
|
| 161 |
+
'stream-read-unsafe', 'stream-read-until', 'stream-read1',
|
| 162 |
+
'stream-readln', 'stream-seek', 'stream-seekable?', 'stream-tell',
|
| 163 |
+
'stream-write', 'stream-write1', 'tell-input', 'tell-output',
|
| 164 |
+
'with-error-stream', 'with-error-stream*', 'with-error>output',
|
| 165 |
+
'with-input-output+error-streams',
|
| 166 |
+
'with-input-output+error-streams*', 'with-input-stream',
|
| 167 |
+
'with-input-stream*', 'with-output-stream', 'with-output-stream*',
|
| 168 |
+
'with-output>error', 'with-output+error-stream',
|
| 169 |
+
'with-output+error-stream*', 'with-streams', 'with-streams*',
|
| 170 |
+
'write', 'write1'), suffix=r'(\s+)')
|
| 171 |
+
|
| 172 |
+
builtin_strings = words((
|
| 173 |
+
'1string', '<string>', '>string', 'resize-string', 'string',
|
| 174 |
+
'string?'), suffix=r'(\s+)')
|
| 175 |
+
|
| 176 |
+
builtin_vectors = words((
|
| 177 |
+
'1vector', '<vector>', '>vector', '?push', 'vector', 'vector?'),
|
| 178 |
+
suffix=r'(\s+)')
|
| 179 |
+
|
| 180 |
+
builtin_continuations = words((
|
| 181 |
+
'<condition>', '<continuation>', '<restart>', 'attempt-all',
|
| 182 |
+
'attempt-all-error', 'attempt-all-error?', 'callback-error-hook',
|
| 183 |
+
'callcc0', 'callcc1', 'cleanup', 'compute-restarts', 'condition',
|
| 184 |
+
'condition?', 'continuation', 'continuation?', 'continue',
|
| 185 |
+
'continue-restart', 'continue-with', 'current-continuation',
|
| 186 |
+
'error', 'error-continuation', 'error-in-thread', 'error-thread',
|
| 187 |
+
'ifcc', 'ignore-errors', 'in-callback?', 'original-error', 'recover',
|
| 188 |
+
'restart', 'restart?', 'restarts', 'rethrow', 'rethrow-restarts',
|
| 189 |
+
'return', 'return-continuation', 'thread-error-hook', 'throw-continue',
|
| 190 |
+
'throw-restarts', 'with-datastack', 'with-return'), suffix=r'(\s+)')
|
| 191 |
+
|
| 192 |
+
tokens = {
|
| 193 |
+
'root': [
|
| 194 |
+
# factor allows a file to start with a shebang
|
| 195 |
+
(r'#!.*$', Comment.Preproc),
|
| 196 |
+
default('base'),
|
| 197 |
+
],
|
| 198 |
+
'base': [
|
| 199 |
+
(r'\s+', Whitespace),
|
| 200 |
+
|
| 201 |
+
# defining words
|
| 202 |
+
(r'((?:MACRO|MEMO|TYPED)?:[:]?)(\s+)(\S+)',
|
| 203 |
+
bygroups(Keyword, Whitespace, Name.Function)),
|
| 204 |
+
(r'(M:[:]?)(\s+)(\S+)(\s+)(\S+)',
|
| 205 |
+
bygroups(Keyword, Whitespace, Name.Class, Whitespace,
|
| 206 |
+
Name.Function)),
|
| 207 |
+
(r'(C:)(\s+)(\S+)(\s+)(\S+)',
|
| 208 |
+
bygroups(Keyword, Whitespace, Name.Function, Whitespace,
|
| 209 |
+
Name.Class)),
|
| 210 |
+
(r'(GENERIC:)(\s+)(\S+)',
|
| 211 |
+
bygroups(Keyword, Whitespace, Name.Function)),
|
| 212 |
+
(r'(HOOK:|GENERIC#)(\s+)(\S+)(\s+)(\S+)',
|
| 213 |
+
bygroups(Keyword, Whitespace, Name.Function, Whitespace,
|
| 214 |
+
Name.Function)),
|
| 215 |
+
(r'(\()(\s)', bygroups(Name.Function, Whitespace), 'stackeffect'),
|
| 216 |
+
(r'(;)(\s)', bygroups(Keyword, Whitespace)),
|
| 217 |
+
|
| 218 |
+
# imports and namespaces
|
| 219 |
+
(r'(USING:)(\s+)',
|
| 220 |
+
bygroups(Keyword.Namespace, Whitespace), 'vocabs'),
|
| 221 |
+
(r'(USE:|UNUSE:|IN:|QUALIFIED:)(\s+)(\S+)',
|
| 222 |
+
bygroups(Keyword.Namespace, Whitespace, Name.Namespace)),
|
| 223 |
+
(r'(QUALIFIED-WITH:)(\s+)(\S+)(\s+)(\S+)',
|
| 224 |
+
bygroups(Keyword.Namespace, Whitespace, Name.Namespace,
|
| 225 |
+
Whitespace, Name.Namespace)),
|
| 226 |
+
(r'(FROM:|EXCLUDE:)(\s+)(\S+)(\s+=>\s)',
|
| 227 |
+
bygroups(Keyword.Namespace, Whitespace, Name.Namespace,
|
| 228 |
+
Whitespace), 'words'),
|
| 229 |
+
(r'(RENAME:)(\s+)(\S+)(\s+)(\S+)(\s+)(=>)(\s+)(\S+)',
|
| 230 |
+
bygroups(Keyword.Namespace, Whitespace, Name.Function, Whitespace,
|
| 231 |
+
Name.Namespace, Whitespace, Punctuation, Whitespace,
|
| 232 |
+
Name.Function)),
|
| 233 |
+
(r'(ALIAS:|TYPEDEF:)(\s+)(\S+)(\s+)(\S+)',
|
| 234 |
+
bygroups(Keyword.Namespace, Whitespace, Name.Function, Whitespace,
|
| 235 |
+
Name.Function)),
|
| 236 |
+
(r'(DEFER:|FORGET:|POSTPONE:)(\s+)(\S+)',
|
| 237 |
+
bygroups(Keyword.Namespace, Whitespace, Name.Function)),
|
| 238 |
+
|
| 239 |
+
# tuples and classes
|
| 240 |
+
(r'(TUPLE:|ERROR:)(\s+)(\S+)(\s+)(<)(\s+)(\S+)',
|
| 241 |
+
bygroups(Keyword, Whitespace, Name.Class, Whitespace, Punctuation,
|
| 242 |
+
Whitespace, Name.Class), 'slots'),
|
| 243 |
+
(r'(TUPLE:|ERROR:|BUILTIN:)(\s+)(\S+)',
|
| 244 |
+
bygroups(Keyword, Whitespace, Name.Class), 'slots'),
|
| 245 |
+
(r'(MIXIN:|UNION:|INTERSECTION:)(\s+)(\S+)',
|
| 246 |
+
bygroups(Keyword, Whitespace, Name.Class)),
|
| 247 |
+
(r'(PREDICATE:)(\s+)(\S+)(\s+)(<)(\s+)(\S+)',
|
| 248 |
+
bygroups(Keyword, Whitespace, Name.Class, Whitespace,
|
| 249 |
+
Punctuation, Whitespace, Name.Class)),
|
| 250 |
+
(r'(C:)(\s+)(\S+)(\s+)(\S+)',
|
| 251 |
+
bygroups(Keyword, Whitespace, Name.Function, Whitespace, Name.Class)),
|
| 252 |
+
(r'(INSTANCE:)(\s+)(\S+)(\s+)(\S+)',
|
| 253 |
+
bygroups(Keyword, Whitespace, Name.Class, Whitespace, Name.Class)),
|
| 254 |
+
(r'(SLOT:)(\s+)(\S+)', bygroups(Keyword, Whitespace, Name.Function)),
|
| 255 |
+
(r'(SINGLETON:)(\s+)(\S+)', bygroups(Keyword, Whitespace, Name.Class)),
|
| 256 |
+
(r'SINGLETONS:', Keyword, 'classes'),
|
| 257 |
+
|
| 258 |
+
# other syntax
|
| 259 |
+
(r'(CONSTANT:|SYMBOL:|MAIN:|HELP:)(\s+)(\S+)',
|
| 260 |
+
bygroups(Keyword, Whitespace, Name.Function)),
|
| 261 |
+
(r'(SYMBOLS:)(\s+)', bygroups(Keyword, Whitespace), 'words'),
|
| 262 |
+
(r'(SYNTAX:)(\s+)', bygroups(Keyword, Whitespace)),
|
| 263 |
+
(r'(ALIEN:)(\s+)', bygroups(Keyword, Whitespace)),
|
| 264 |
+
(r'(STRUCT:)(\s+)(\S+)', bygroups(Keyword, Whitespace, Name.Class)),
|
| 265 |
+
(r'(FUNCTION:)(\s+)'
|
| 266 |
+
r'(\S+)(\s+)(\S+)(\s+)'
|
| 267 |
+
r'(\()(\s+)([^)]+)(\))(\s)',
|
| 268 |
+
bygroups(Keyword.Namespace, Whitespace,
|
| 269 |
+
Text, Whitespace, Name.Function, Whitespace,
|
| 270 |
+
Punctuation, Whitespace, Text, Punctuation, Whitespace)),
|
| 271 |
+
(r'(FUNCTION-ALIAS:)(\s+)'
|
| 272 |
+
r'(\S+)(\s+)(\S+)(\s+)'
|
| 273 |
+
r'(\S+)(\s+)'
|
| 274 |
+
r'(\()(\s+)([^)]+)(\))(\s)',
|
| 275 |
+
bygroups(Keyword.Namespace, Whitespace,
|
| 276 |
+
Text, Whitespace, Name.Function, Whitespace,
|
| 277 |
+
Name.Function, Whitespace,
|
| 278 |
+
Punctuation, Whitespace, Text, Punctuation, Whitespace)),
|
| 279 |
+
|
| 280 |
+
# vocab.private
|
| 281 |
+
(r'(<PRIVATE|PRIVATE>)(\s)', bygroups(Keyword.Namespace, Whitespace)),
|
| 282 |
+
|
| 283 |
+
# strings
|
| 284 |
+
(r'"""\s(?:.|\n)*?\s"""', String),
|
| 285 |
+
(r'"(?:\\\\|\\"|[^"])*"', String),
|
| 286 |
+
(r'(\S+")(\s+)((?:\\\\|\\"|[^"])*")',
|
| 287 |
+
bygroups(String, Whitespace, String)),
|
| 288 |
+
(r'(CHAR:)(\s+)(\\[\\abfnrstv]|[^\\]\S*)(\s)',
|
| 289 |
+
bygroups(String.Char, Whitespace, String.Char, Whitespace)),
|
| 290 |
+
|
| 291 |
+
# comments
|
| 292 |
+
(r'!\s+.*$', Comment),
|
| 293 |
+
(r'#!\s+.*$', Comment),
|
| 294 |
+
(r'/\*\s+(?:.|\n)*?\s\*/', Comment),
|
| 295 |
+
|
| 296 |
+
# boolean constants
|
| 297 |
+
(r'[tf]\b', Name.Constant),
|
| 298 |
+
|
| 299 |
+
# symbols and literals
|
| 300 |
+
(r'[\\$]\s+\S+', Name.Constant),
|
| 301 |
+
(r'M\\\s+\S+\s+\S+', Name.Constant),
|
| 302 |
+
|
| 303 |
+
# numbers
|
| 304 |
+
(r'[+-]?(?:[\d,]*\d)?\.(?:\d([\d,]*\d)?)?(?:[eE][+-]?\d+)?\s', Number),
|
| 305 |
+
(r'[+-]?\d(?:[\d,]*\d)?(?:[eE][+-]?\d+)?\s', Number),
|
| 306 |
+
(r'0x[a-fA-F\d](?:[a-fA-F\d,]*[a-fA-F\d])?(?:p\d([\d,]*\d)?)?\s', Number),
|
| 307 |
+
(r'NAN:\s+[a-fA-F\d](?:[a-fA-F\d,]*[a-fA-F\d])?(?:p\d([\d,]*\d)?)?\s', Number),
|
| 308 |
+
(r'0b[01]+\s', Number.Bin),
|
| 309 |
+
(r'0o[0-7]+\s', Number.Oct),
|
| 310 |
+
(r'(?:\d([\d,]*\d)?)?\+\d(?:[\d,]*\d)?/\d(?:[\d,]*\d)?\s', Number),
|
| 311 |
+
(r'(?:\-\d([\d,]*\d)?)?\-\d(?:[\d,]*\d)?/\d(?:[\d,]*\d)?\s', Number),
|
| 312 |
+
|
| 313 |
+
# keywords
|
| 314 |
+
(r'(?:deprecated|final|foldable|flushable|inline|recursive)\s',
|
| 315 |
+
Keyword),
|
| 316 |
+
|
| 317 |
+
# builtins
|
| 318 |
+
(builtin_kernel, bygroups(Name.Builtin, Whitespace)),
|
| 319 |
+
(builtin_assocs, bygroups(Name.Builtin, Whitespace)),
|
| 320 |
+
(builtin_combinators, bygroups(Name.Builtin, Whitespace)),
|
| 321 |
+
(builtin_math, bygroups(Name.Builtin, Whitespace)),
|
| 322 |
+
(builtin_sequences, bygroups(Name.Builtin, Whitespace)),
|
| 323 |
+
(builtin_namespaces, bygroups(Name.Builtin, Whitespace)),
|
| 324 |
+
(builtin_arrays, bygroups(Name.Builtin, Whitespace)),
|
| 325 |
+
(builtin_io, bygroups(Name.Builtin, Whitespace)),
|
| 326 |
+
(builtin_strings, bygroups(Name.Builtin, Whitespace)),
|
| 327 |
+
(builtin_vectors, bygroups(Name.Builtin, Whitespace)),
|
| 328 |
+
(builtin_continuations, bygroups(Name.Builtin, Whitespace)),
|
| 329 |
+
|
| 330 |
+
# everything else is text
|
| 331 |
+
(r'\S+', Text),
|
| 332 |
+
],
|
| 333 |
+
'stackeffect': [
|
| 334 |
+
(r'\s+', Whitespace),
|
| 335 |
+
(r'(\()(\s+)', bygroups(Name.Function, Whitespace), 'stackeffect'),
|
| 336 |
+
(r'(\))(\s+)', bygroups(Name.Function, Whitespace), '#pop'),
|
| 337 |
+
(r'(--)(\s+)', bygroups(Name.Function, Whitespace)),
|
| 338 |
+
(r'\S+', Name.Variable),
|
| 339 |
+
],
|
| 340 |
+
'slots': [
|
| 341 |
+
(r'\s+', Whitespace),
|
| 342 |
+
(r'(;)(\s+)', bygroups(Keyword, Whitespace), '#pop'),
|
| 343 |
+
(r'(\{)(\s+)(\S+)(\s+)([^}]+)(\s+)(\})(\s+)',
|
| 344 |
+
bygroups(Text, Whitespace, Name.Variable, Whitespace,
|
| 345 |
+
Text, Whitespace, Text, Whitespace)),
|
| 346 |
+
(r'\S+', Name.Variable),
|
| 347 |
+
],
|
| 348 |
+
'vocabs': [
|
| 349 |
+
(r'\s+', Whitespace),
|
| 350 |
+
(r'(;)(\s+)', bygroups(Keyword, Whitespace), '#pop'),
|
| 351 |
+
(r'\S+', Name.Namespace),
|
| 352 |
+
],
|
| 353 |
+
'classes': [
|
| 354 |
+
(r'\s+', Whitespace),
|
| 355 |
+
(r'(;)(\s+)', bygroups(Keyword, Whitespace), '#pop'),
|
| 356 |
+
(r'\S+', Name.Class),
|
| 357 |
+
],
|
| 358 |
+
'words': [
|
| 359 |
+
(r'\s+', Whitespace),
|
| 360 |
+
(r'(;)(\s+)', bygroups(Keyword, Whitespace), '#pop'),
|
| 361 |
+
(r'\S+', Name.Function),
|
| 362 |
+
],
|
| 363 |
+
}
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/fantom.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.fantom
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexer for the Fantom language.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from string import Template
|
| 12 |
+
|
| 13 |
+
from pygments.lexer import RegexLexer, include, bygroups, using, \
|
| 14 |
+
this, default, words
|
| 15 |
+
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
|
| 16 |
+
Number, Punctuation, Literal, Whitespace
|
| 17 |
+
|
| 18 |
+
__all__ = ['FantomLexer']
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class FantomLexer(RegexLexer):
|
| 22 |
+
"""
|
| 23 |
+
For Fantom source code.
|
| 24 |
+
"""
|
| 25 |
+
name = 'Fantom'
|
| 26 |
+
aliases = ['fan']
|
| 27 |
+
filenames = ['*.fan']
|
| 28 |
+
mimetypes = ['application/x-fantom']
|
| 29 |
+
url = 'https://www.fantom.org'
|
| 30 |
+
version_added = '1.5'
|
| 31 |
+
|
| 32 |
+
# often used regexes
|
| 33 |
+
def s(str):
|
| 34 |
+
return Template(str).substitute(
|
| 35 |
+
dict(
|
| 36 |
+
pod=r'[\"\w\.]+',
|
| 37 |
+
eos=r'\n|;',
|
| 38 |
+
id=r'[a-zA-Z_]\w*',
|
| 39 |
+
# all chars which can be part of type definition. Starts with
|
| 40 |
+
# either letter, or [ (maps), or | (funcs)
|
| 41 |
+
type=r'(?:\[|[a-zA-Z_]|\|)[:\w\[\]|\->?]*?',
|
| 42 |
+
)
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
tokens = {
|
| 46 |
+
'comments': [
|
| 47 |
+
(r'(?s)/\*.*?\*/', Comment.Multiline), # Multiline
|
| 48 |
+
(r'//.*?$', Comment.Single), # Single line
|
| 49 |
+
# TODO: highlight references in fandocs
|
| 50 |
+
(r'\*\*.*?$', Comment.Special), # Fandoc
|
| 51 |
+
(r'#.*$', Comment.Single) # Shell-style
|
| 52 |
+
],
|
| 53 |
+
'literals': [
|
| 54 |
+
(r'\b-?[\d_]+(ns|ms|sec|min|hr|day)', Number), # Duration
|
| 55 |
+
(r'\b-?[\d_]*\.[\d_]+(ns|ms|sec|min|hr|day)', Number), # Duration with dot
|
| 56 |
+
(r'\b-?(\d+)?\.\d+(f|F|d|D)?', Number.Float), # Float/Decimal
|
| 57 |
+
(r'\b-?0x[0-9a-fA-F_]+', Number.Hex), # Hex
|
| 58 |
+
(r'\b-?[\d_]+', Number.Integer), # Int
|
| 59 |
+
(r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char), # Char
|
| 60 |
+
(r'"', Punctuation, 'insideStr'), # Opening quote
|
| 61 |
+
(r'`', Punctuation, 'insideUri'), # Opening accent
|
| 62 |
+
(r'\b(true|false|null)\b', Keyword.Constant), # Bool & null
|
| 63 |
+
(r'(?:(\w+)(::))?(\w+)(<\|)(.*?)(\|>)', # DSL
|
| 64 |
+
bygroups(Name.Namespace, Punctuation, Name.Class,
|
| 65 |
+
Punctuation, String, Punctuation)),
|
| 66 |
+
(r'(?:(\w+)(::))?(\w+)?(#)(\w+)?', # Type/slot literal
|
| 67 |
+
bygroups(Name.Namespace, Punctuation, Name.Class,
|
| 68 |
+
Punctuation, Name.Function)),
|
| 69 |
+
(r'\[,\]', Literal), # Empty list
|
| 70 |
+
(s(r'($type)(\[,\])'), # Typed empty list
|
| 71 |
+
bygroups(using(this, state='inType'), Literal)),
|
| 72 |
+
(r'\[:\]', Literal), # Empty Map
|
| 73 |
+
(s(r'($type)(\[:\])'),
|
| 74 |
+
bygroups(using(this, state='inType'), Literal)),
|
| 75 |
+
],
|
| 76 |
+
'insideStr': [
|
| 77 |
+
(r'\\\\', String.Escape), # Escaped backslash
|
| 78 |
+
(r'\\"', String.Escape), # Escaped "
|
| 79 |
+
(r'\\`', String.Escape), # Escaped `
|
| 80 |
+
(r'\$\w+', String.Interpol), # Subst var
|
| 81 |
+
(r'\$\{.*?\}', String.Interpol), # Subst expr
|
| 82 |
+
(r'"', Punctuation, '#pop'), # Closing quot
|
| 83 |
+
(r'.', String) # String content
|
| 84 |
+
],
|
| 85 |
+
'insideUri': [ # TODO: remove copy/paste str/uri
|
| 86 |
+
(r'\\\\', String.Escape), # Escaped backslash
|
| 87 |
+
(r'\\"', String.Escape), # Escaped "
|
| 88 |
+
(r'\\`', String.Escape), # Escaped `
|
| 89 |
+
(r'\$\w+', String.Interpol), # Subst var
|
| 90 |
+
(r'\$\{.*?\}', String.Interpol), # Subst expr
|
| 91 |
+
(r'`', Punctuation, '#pop'), # Closing tick
|
| 92 |
+
(r'.', String.Backtick) # URI content
|
| 93 |
+
],
|
| 94 |
+
'protectionKeywords': [
|
| 95 |
+
(r'\b(public|protected|private|internal)\b', Keyword),
|
| 96 |
+
],
|
| 97 |
+
'typeKeywords': [
|
| 98 |
+
(r'\b(abstract|final|const|native|facet|enum)\b', Keyword),
|
| 99 |
+
],
|
| 100 |
+
'methodKeywords': [
|
| 101 |
+
(r'\b(abstract|native|once|override|static|virtual|final)\b',
|
| 102 |
+
Keyword),
|
| 103 |
+
],
|
| 104 |
+
'fieldKeywords': [
|
| 105 |
+
(r'\b(abstract|const|final|native|override|static|virtual|'
|
| 106 |
+
r'readonly)\b', Keyword)
|
| 107 |
+
],
|
| 108 |
+
'otherKeywords': [
|
| 109 |
+
(words((
|
| 110 |
+
'try', 'catch', 'throw', 'finally', 'for', 'if', 'else', 'while',
|
| 111 |
+
'as', 'is', 'isnot', 'switch', 'case', 'default', 'continue',
|
| 112 |
+
'break', 'do', 'return', 'get', 'set'), prefix=r'\b', suffix=r'\b'),
|
| 113 |
+
Keyword),
|
| 114 |
+
(r'\b(it|this|super)\b', Name.Builtin.Pseudo),
|
| 115 |
+
],
|
| 116 |
+
'operators': [
|
| 117 |
+
(r'\+\+|\-\-|\+|\-|\*|/|\|\||&&|<=>|<=|<|>=|>|=|!|\[|\]', Operator)
|
| 118 |
+
],
|
| 119 |
+
'inType': [
|
| 120 |
+
(r'[\[\]|\->:?]', Punctuation),
|
| 121 |
+
(s(r'$id'), Name.Class),
|
| 122 |
+
default('#pop'),
|
| 123 |
+
|
| 124 |
+
],
|
| 125 |
+
'root': [
|
| 126 |
+
include('comments'),
|
| 127 |
+
include('protectionKeywords'),
|
| 128 |
+
include('typeKeywords'),
|
| 129 |
+
include('methodKeywords'),
|
| 130 |
+
include('fieldKeywords'),
|
| 131 |
+
include('literals'),
|
| 132 |
+
include('otherKeywords'),
|
| 133 |
+
include('operators'),
|
| 134 |
+
(r'using\b', Keyword.Namespace, 'using'), # Using stmt
|
| 135 |
+
(r'@\w+', Name.Decorator, 'facet'), # Symbol
|
| 136 |
+
(r'(class|mixin)(\s+)(\w+)', bygroups(Keyword, Whitespace, Name.Class),
|
| 137 |
+
'inheritance'), # Inheritance list
|
| 138 |
+
|
| 139 |
+
# Type var := val
|
| 140 |
+
(s(r'($type)([ \t]+)($id)(\s*)(:=)'),
|
| 141 |
+
bygroups(using(this, state='inType'), Whitespace,
|
| 142 |
+
Name.Variable, Whitespace, Operator)),
|
| 143 |
+
|
| 144 |
+
# var := val
|
| 145 |
+
(s(r'($id)(\s*)(:=)'),
|
| 146 |
+
bygroups(Name.Variable, Whitespace, Operator)),
|
| 147 |
+
|
| 148 |
+
# .someId( or ->someId( ###
|
| 149 |
+
(s(r'(\.|(?:\->))($id)(\s*)(\()'),
|
| 150 |
+
bygroups(Operator, Name.Function, Whitespace, Punctuation),
|
| 151 |
+
'insideParen'),
|
| 152 |
+
|
| 153 |
+
# .someId or ->someId
|
| 154 |
+
(s(r'(\.|(?:\->))($id)'),
|
| 155 |
+
bygroups(Operator, Name.Function)),
|
| 156 |
+
|
| 157 |
+
# new makeXXX (
|
| 158 |
+
(r'(new)(\s+)(make\w*)(\s*)(\()',
|
| 159 |
+
bygroups(Keyword, Whitespace, Name.Function, Whitespace, Punctuation),
|
| 160 |
+
'insideMethodDeclArgs'),
|
| 161 |
+
|
| 162 |
+
# Type name (
|
| 163 |
+
(s(r'($type)([ \t]+)' # Return type and whitespace
|
| 164 |
+
r'($id)(\s*)(\()'), # method name + open brace
|
| 165 |
+
bygroups(using(this, state='inType'), Whitespace,
|
| 166 |
+
Name.Function, Whitespace, Punctuation),
|
| 167 |
+
'insideMethodDeclArgs'),
|
| 168 |
+
|
| 169 |
+
# ArgType argName,
|
| 170 |
+
(s(r'($type)(\s+)($id)(\s*)(,)'),
|
| 171 |
+
bygroups(using(this, state='inType'), Whitespace, Name.Variable,
|
| 172 |
+
Whitespace, Punctuation)),
|
| 173 |
+
|
| 174 |
+
# ArgType argName)
|
| 175 |
+
# Covered in 'insideParen' state
|
| 176 |
+
|
| 177 |
+
# ArgType argName -> ArgType|
|
| 178 |
+
(s(r'($type)(\s+)($id)(\s*)(\->)(\s*)($type)(\|)'),
|
| 179 |
+
bygroups(using(this, state='inType'), Whitespace, Name.Variable,
|
| 180 |
+
Whitespace, Punctuation, Whitespace, using(this, state='inType'),
|
| 181 |
+
Punctuation)),
|
| 182 |
+
|
| 183 |
+
# ArgType argName|
|
| 184 |
+
(s(r'($type)(\s+)($id)(\s*)(\|)'),
|
| 185 |
+
bygroups(using(this, state='inType'), Whitespace, Name.Variable,
|
| 186 |
+
Whitespace, Punctuation)),
|
| 187 |
+
|
| 188 |
+
# Type var
|
| 189 |
+
(s(r'($type)([ \t]+)($id)'),
|
| 190 |
+
bygroups(using(this, state='inType'), Whitespace,
|
| 191 |
+
Name.Variable)),
|
| 192 |
+
|
| 193 |
+
(r'\(', Punctuation, 'insideParen'),
|
| 194 |
+
(r'\{', Punctuation, 'insideBrace'),
|
| 195 |
+
(r'\s+', Whitespace),
|
| 196 |
+
(r'.', Text)
|
| 197 |
+
],
|
| 198 |
+
'insideParen': [
|
| 199 |
+
(r'\)', Punctuation, '#pop'),
|
| 200 |
+
include('root'),
|
| 201 |
+
],
|
| 202 |
+
'insideMethodDeclArgs': [
|
| 203 |
+
(r'\)', Punctuation, '#pop'),
|
| 204 |
+
(s(r'($type)(\s+)($id)(\s*)(\))'),
|
| 205 |
+
bygroups(using(this, state='inType'), Whitespace, Name.Variable,
|
| 206 |
+
Whitespace, Punctuation), '#pop'),
|
| 207 |
+
include('root'),
|
| 208 |
+
],
|
| 209 |
+
'insideBrace': [
|
| 210 |
+
(r'\}', Punctuation, '#pop'),
|
| 211 |
+
include('root'),
|
| 212 |
+
],
|
| 213 |
+
'inheritance': [
|
| 214 |
+
(r'\s+', Whitespace), # Whitespace
|
| 215 |
+
(r':|,', Punctuation),
|
| 216 |
+
(r'(?:(\w+)(::))?(\w+)',
|
| 217 |
+
bygroups(Name.Namespace, Punctuation, Name.Class)),
|
| 218 |
+
(r'\{', Punctuation, '#pop')
|
| 219 |
+
],
|
| 220 |
+
'using': [
|
| 221 |
+
(r'[ \t]+', Whitespace), # consume whitespaces
|
| 222 |
+
(r'(\[)(\w+)(\])',
|
| 223 |
+
bygroups(Punctuation, Comment.Special, Punctuation)), # ffi
|
| 224 |
+
(r'(\")?([\w.]+)(\")?',
|
| 225 |
+
bygroups(Punctuation, Name.Namespace, Punctuation)), # podname
|
| 226 |
+
(r'::', Punctuation, 'usingClass'),
|
| 227 |
+
default('#pop')
|
| 228 |
+
],
|
| 229 |
+
'usingClass': [
|
| 230 |
+
(r'[ \t]+', Whitespace), # consume whitespaces
|
| 231 |
+
(r'(as)(\s+)(\w+)',
|
| 232 |
+
bygroups(Keyword.Declaration, Whitespace, Name.Class), '#pop:2'),
|
| 233 |
+
(r'[\w$]+', Name.Class),
|
| 234 |
+
default('#pop:2') # jump out to root state
|
| 235 |
+
],
|
| 236 |
+
'facet': [
|
| 237 |
+
(r'\s+', Whitespace),
|
| 238 |
+
(r'\{', Punctuation, 'facetFields'),
|
| 239 |
+
default('#pop')
|
| 240 |
+
],
|
| 241 |
+
'facetFields': [
|
| 242 |
+
include('comments'),
|
| 243 |
+
include('literals'),
|
| 244 |
+
include('operators'),
|
| 245 |
+
(r'\s+', Whitespace),
|
| 246 |
+
(r'(\s*)(\w+)(\s*)(=)', bygroups(Whitespace, Name, Whitespace, Operator)),
|
| 247 |
+
(r'\}', Punctuation, '#pop'),
|
| 248 |
+
(r'\s+', Whitespace),
|
| 249 |
+
(r'.', Text)
|
| 250 |
+
],
|
| 251 |
+
}
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/functional.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.functional
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Just export lexer classes previously contained in this module.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
# ruff: noqa: F401
|
| 12 |
+
from pygments.lexers.lisp import SchemeLexer, CommonLispLexer, RacketLexer, \
|
| 13 |
+
NewLispLexer, ShenLexer
|
| 14 |
+
from pygments.lexers.haskell import HaskellLexer, LiterateHaskellLexer, \
|
| 15 |
+
KokaLexer
|
| 16 |
+
from pygments.lexers.theorem import RocqLexer
|
| 17 |
+
from pygments.lexers.erlang import ErlangLexer, ErlangShellLexer, \
|
| 18 |
+
ElixirConsoleLexer, ElixirLexer
|
| 19 |
+
from pygments.lexers.ml import SMLLexer, OcamlLexer, OpaLexer
|
| 20 |
+
|
| 21 |
+
__all__ = []
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/futhark.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.futhark
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexer for the Futhark language
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present 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 Comment, Operator, Keyword, Name, String, \
|
| 13 |
+
Number, Punctuation, Whitespace
|
| 14 |
+
from pygments import unistring as uni
|
| 15 |
+
|
| 16 |
+
__all__ = ['FutharkLexer']
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class FutharkLexer(RegexLexer):
|
| 20 |
+
"""
|
| 21 |
+
A Futhark lexer
|
| 22 |
+
"""
|
| 23 |
+
name = 'Futhark'
|
| 24 |
+
url = 'https://futhark-lang.org/'
|
| 25 |
+
aliases = ['futhark']
|
| 26 |
+
filenames = ['*.fut']
|
| 27 |
+
mimetypes = ['text/x-futhark']
|
| 28 |
+
version_added = '2.8'
|
| 29 |
+
|
| 30 |
+
num_types = ('i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'f32', 'f64')
|
| 31 |
+
|
| 32 |
+
other_types = ('bool', )
|
| 33 |
+
|
| 34 |
+
reserved = ('if', 'then', 'else', 'def', 'let', 'loop', 'in', 'with',
|
| 35 |
+
'type', 'type~', 'type^',
|
| 36 |
+
'val', 'entry', 'for', 'while', 'do', 'case', 'match',
|
| 37 |
+
'include', 'import', 'module', 'open', 'local', 'assert', '_')
|
| 38 |
+
|
| 39 |
+
ascii = ('NUL', 'SOH', '[SE]TX', 'EOT', 'ENQ', 'ACK',
|
| 40 |
+
'BEL', 'BS', 'HT', 'LF', 'VT', 'FF', 'CR', 'S[OI]', 'DLE',
|
| 41 |
+
'DC[1-4]', 'NAK', 'SYN', 'ETB', 'CAN',
|
| 42 |
+
'EM', 'SUB', 'ESC', '[FGRU]S', 'SP', 'DEL')
|
| 43 |
+
|
| 44 |
+
num_postfix = r'({})?'.format('|'.join(num_types))
|
| 45 |
+
|
| 46 |
+
identifier_re = '[a-zA-Z_][a-zA-Z_0-9\']*'
|
| 47 |
+
|
| 48 |
+
# opstart_re = '+\-\*/%=\!><\|&\^'
|
| 49 |
+
|
| 50 |
+
tokens = {
|
| 51 |
+
'root': [
|
| 52 |
+
(r'--(.*?)$', Comment.Single),
|
| 53 |
+
(r'\s+', Whitespace),
|
| 54 |
+
(r'\(\)', Punctuation),
|
| 55 |
+
(r'\b({})(?!\')\b'.format('|'.join(reserved)), Keyword.Reserved),
|
| 56 |
+
(r'\b({})(?!\')\b'.format('|'.join(num_types + other_types)), Keyword.Type),
|
| 57 |
+
|
| 58 |
+
# Identifiers
|
| 59 |
+
(r'#\[([a-zA-Z_\(\) ]*)\]', Comment.Preproc),
|
| 60 |
+
(rf'[#!]?({identifier_re}\.)*{identifier_re}', Name),
|
| 61 |
+
|
| 62 |
+
(r'\\', Operator),
|
| 63 |
+
(r'[-+/%=!><|&*^][-+/%=!><|&*^.]*', Operator),
|
| 64 |
+
(r'[][(),:;`{}?.\'~^]', Punctuation),
|
| 65 |
+
|
| 66 |
+
# Numbers
|
| 67 |
+
(r'0[xX]_*[\da-fA-F](_*[\da-fA-F])*_*[pP][+-]?\d(_*\d)*' + num_postfix,
|
| 68 |
+
Number.Float),
|
| 69 |
+
(r'0[xX]_*[\da-fA-F](_*[\da-fA-F])*\.[\da-fA-F](_*[\da-fA-F])*'
|
| 70 |
+
r'(_*[pP][+-]?\d(_*\d)*)?' + num_postfix, Number.Float),
|
| 71 |
+
(r'\d(_*\d)*_*[eE][+-]?\d(_*\d)*' + num_postfix, Number.Float),
|
| 72 |
+
(r'\d(_*\d)*\.\d(_*\d)*(_*[eE][+-]?\d(_*\d)*)?' + num_postfix, Number.Float),
|
| 73 |
+
(r'0[bB]_*[01](_*[01])*' + num_postfix, Number.Bin),
|
| 74 |
+
(r'0[xX]_*[\da-fA-F](_*[\da-fA-F])*' + num_postfix, Number.Hex),
|
| 75 |
+
(r'\d(_*\d)*' + num_postfix, Number.Integer),
|
| 76 |
+
|
| 77 |
+
# Character/String Literals
|
| 78 |
+
(r"'", String.Char, 'character'),
|
| 79 |
+
(r'"', String, 'string'),
|
| 80 |
+
# Special
|
| 81 |
+
(r'\[[a-zA-Z_\d]*\]', Keyword.Type),
|
| 82 |
+
(r'\(\)', Name.Builtin),
|
| 83 |
+
],
|
| 84 |
+
'character': [
|
| 85 |
+
# Allows multi-chars, incorrectly.
|
| 86 |
+
(r"[^\\']'", String.Char, '#pop'),
|
| 87 |
+
(r"\\", String.Escape, 'escape'),
|
| 88 |
+
("'", String.Char, '#pop'),
|
| 89 |
+
],
|
| 90 |
+
'string': [
|
| 91 |
+
(r'[^\\"]+', String),
|
| 92 |
+
(r"\\", String.Escape, 'escape'),
|
| 93 |
+
('"', String, '#pop'),
|
| 94 |
+
],
|
| 95 |
+
|
| 96 |
+
'escape': [
|
| 97 |
+
(r'[abfnrtv"\'&\\]', String.Escape, '#pop'),
|
| 98 |
+
(r'\^[][' + uni.Lu + r'@^_]', String.Escape, '#pop'),
|
| 99 |
+
('|'.join(ascii), String.Escape, '#pop'),
|
| 100 |
+
(r'o[0-7]+', String.Escape, '#pop'),
|
| 101 |
+
(r'x[\da-fA-F]+', String.Escape, '#pop'),
|
| 102 |
+
(r'\d+', String.Escape, '#pop'),
|
| 103 |
+
(r'(\s+)(\\)', bygroups(Whitespace, String.Escape), '#pop'),
|
| 104 |
+
],
|
| 105 |
+
}
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/gdscript.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.gdscript
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexer for GDScript.
|
| 6 |
+
|
| 7 |
+
Modified by Daniel J. Ramirez <djrmuv@gmail.com> based on the original
|
| 8 |
+
python.py.
|
| 9 |
+
|
| 10 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 11 |
+
:license: BSD, see LICENSE for details.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
import re
|
| 15 |
+
|
| 16 |
+
from pygments.lexer import RegexLexer, include, bygroups, default, words, \
|
| 17 |
+
combined
|
| 18 |
+
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
|
| 19 |
+
Number, Punctuation, Whitespace
|
| 20 |
+
|
| 21 |
+
__all__ = ["GDScriptLexer"]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class GDScriptLexer(RegexLexer):
|
| 25 |
+
"""
|
| 26 |
+
For GDScript source code.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
name = "GDScript"
|
| 30 |
+
url = 'https://www.godotengine.org'
|
| 31 |
+
aliases = ["gdscript", "gd"]
|
| 32 |
+
filenames = ["*.gd"]
|
| 33 |
+
mimetypes = ["text/x-gdscript", "application/x-gdscript"]
|
| 34 |
+
version_added = ''
|
| 35 |
+
|
| 36 |
+
def innerstring_rules(ttype):
|
| 37 |
+
return [
|
| 38 |
+
# the old style '%s' % (...) string formatting
|
| 39 |
+
(r"%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?"
|
| 40 |
+
"[hlL]?[E-GXc-giorsux%]",
|
| 41 |
+
String.Interpol),
|
| 42 |
+
# backslashes, quotes and formatting signs must be parsed one at a time
|
| 43 |
+
(r'[^\\\'"%\n]+', ttype),
|
| 44 |
+
(r'[\'"\\]', ttype),
|
| 45 |
+
# unhandled string formatting sign
|
| 46 |
+
(r"%", ttype),
|
| 47 |
+
# newlines are an error (use "nl" state)
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
tokens = {
|
| 51 |
+
"root": [
|
| 52 |
+
(r"\n", Whitespace),
|
| 53 |
+
(r'^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")',
|
| 54 |
+
bygroups(Whitespace, String.Affix, String.Doc)),
|
| 55 |
+
(r"^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')",
|
| 56 |
+
bygroups(Whitespace, String.Affix, String.Doc)),
|
| 57 |
+
(r"[^\S\n]+", Whitespace),
|
| 58 |
+
(r"#.*$", Comment.Single),
|
| 59 |
+
(r"[]{}:(),;[]", Punctuation),
|
| 60 |
+
(r"(\\)(\n)", bygroups(Text, Whitespace)),
|
| 61 |
+
(r"\\", Text),
|
| 62 |
+
(r"(in|and|or|not)\b", Operator.Word),
|
| 63 |
+
(r"!=|==|<<|>>|&&|\+=|-=|\*=|/=|%=|&=|\|=|\|\||[-~+/*%=<>&^.!|$]",
|
| 64 |
+
Operator),
|
| 65 |
+
include("keywords"),
|
| 66 |
+
(r"(func)(\s+)", bygroups(Keyword, Whitespace), "funcname"),
|
| 67 |
+
(r"(class)(\s+)", bygroups(Keyword, Whitespace), "classname"),
|
| 68 |
+
include("builtins"),
|
| 69 |
+
('([rR]|[uUbB][rR]|[rR][uUbB])(""")',
|
| 70 |
+
bygroups(String.Affix, String.Double),
|
| 71 |
+
"tdqs"),
|
| 72 |
+
("([rR]|[uUbB][rR]|[rR][uUbB])(''')",
|
| 73 |
+
bygroups(String.Affix, String.Single),
|
| 74 |
+
"tsqs"),
|
| 75 |
+
('([rR]|[uUbB][rR]|[rR][uUbB])(")',
|
| 76 |
+
bygroups(String.Affix, String.Double),
|
| 77 |
+
"dqs"),
|
| 78 |
+
("([rR]|[uUbB][rR]|[rR][uUbB])(')",
|
| 79 |
+
bygroups(String.Affix, String.Single),
|
| 80 |
+
"sqs"),
|
| 81 |
+
('([uUbB]?)(""")',
|
| 82 |
+
bygroups(String.Affix, String.Double),
|
| 83 |
+
combined("stringescape", "tdqs")),
|
| 84 |
+
("([uUbB]?)(''')",
|
| 85 |
+
bygroups(String.Affix, String.Single),
|
| 86 |
+
combined("stringescape", "tsqs")),
|
| 87 |
+
('([uUbB]?)(")',
|
| 88 |
+
bygroups(String.Affix, String.Double),
|
| 89 |
+
combined("stringescape", "dqs")),
|
| 90 |
+
("([uUbB]?)(')",
|
| 91 |
+
bygroups(String.Affix, String.Single),
|
| 92 |
+
combined("stringescape", "sqs")),
|
| 93 |
+
include("name"),
|
| 94 |
+
include("numbers"),
|
| 95 |
+
],
|
| 96 |
+
"keywords": [
|
| 97 |
+
(words(("and", "in", "not", "or", "as", "breakpoint", "class",
|
| 98 |
+
"class_name", "extends", "is", "func", "setget", "signal",
|
| 99 |
+
"tool", "const", "enum", "export", "onready", "static",
|
| 100 |
+
"var", "break", "continue", "if", "elif", "else", "for",
|
| 101 |
+
"pass", "return", "match", "while", "remote", "master",
|
| 102 |
+
"puppet", "remotesync", "mastersync", "puppetsync"),
|
| 103 |
+
suffix=r"\b"), Keyword),
|
| 104 |
+
],
|
| 105 |
+
"builtins": [
|
| 106 |
+
(words(("Color8", "ColorN", "abs", "acos", "asin", "assert", "atan",
|
| 107 |
+
"atan2", "bytes2var", "ceil", "char", "clamp", "convert",
|
| 108 |
+
"cos", "cosh", "db2linear", "decimals", "dectime", "deg2rad",
|
| 109 |
+
"dict2inst", "ease", "exp", "floor", "fmod", "fposmod",
|
| 110 |
+
"funcref", "hash", "inst2dict", "instance_from_id", "is_inf",
|
| 111 |
+
"is_nan", "lerp", "linear2db", "load", "log", "max", "min",
|
| 112 |
+
"nearest_po2", "pow", "preload", "print", "print_stack",
|
| 113 |
+
"printerr", "printraw", "prints", "printt", "rad2deg",
|
| 114 |
+
"rand_range", "rand_seed", "randf", "randi", "randomize",
|
| 115 |
+
"range", "round", "seed", "sign", "sin", "sinh", "sqrt",
|
| 116 |
+
"stepify", "str", "str2var", "tan", "tan", "tanh",
|
| 117 |
+
"type_exist", "typeof", "var2bytes", "var2str", "weakref",
|
| 118 |
+
"yield"), prefix=r"(?<!\.)", suffix=r"\b"),
|
| 119 |
+
Name.Builtin),
|
| 120 |
+
(r"((?<!\.)(self|false|true)|(PI|TAU|NAN|INF)" r")\b",
|
| 121 |
+
Name.Builtin.Pseudo),
|
| 122 |
+
(words(("bool", "int", "float", "String", "NodePath", "Vector2",
|
| 123 |
+
"Rect2", "Transform2D", "Vector3", "Rect3", "Plane", "Quat",
|
| 124 |
+
"Basis", "Transform", "Color", "RID", "Object", "NodePath",
|
| 125 |
+
"Dictionary", "Array", "PackedByteArray", "PackedInt32Array",
|
| 126 |
+
"PackedInt64Array", "PackedFloat32Array", "PackedFloat64Array",
|
| 127 |
+
"PackedStringArray", "PackedVector2Array", "PackedVector3Array",
|
| 128 |
+
"PackedColorArray", "null", "void"),
|
| 129 |
+
prefix=r"(?<!\.)", suffix=r"\b"),
|
| 130 |
+
Name.Builtin.Type),
|
| 131 |
+
],
|
| 132 |
+
"numbers": [
|
| 133 |
+
(r"(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?", Number.Float),
|
| 134 |
+
(r"\d+[eE][+-]?[0-9]+j?", Number.Float),
|
| 135 |
+
(r"0[xX][a-fA-F0-9]+", Number.Hex),
|
| 136 |
+
(r"\d+j?", Number.Integer),
|
| 137 |
+
],
|
| 138 |
+
"name": [(r"[a-zA-Z_]\w*", Name)],
|
| 139 |
+
"funcname": [(r"[a-zA-Z_]\w*", Name.Function, "#pop"), default("#pop")],
|
| 140 |
+
"classname": [(r"[a-zA-Z_]\w*", Name.Class, "#pop")],
|
| 141 |
+
"stringescape": [
|
| 142 |
+
(
|
| 143 |
+
r'\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|'
|
| 144 |
+
r"U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})",
|
| 145 |
+
String.Escape,
|
| 146 |
+
)
|
| 147 |
+
],
|
| 148 |
+
"strings-single": innerstring_rules(String.Single),
|
| 149 |
+
"strings-double": innerstring_rules(String.Double),
|
| 150 |
+
"dqs": [
|
| 151 |
+
(r'"', String.Double, "#pop"),
|
| 152 |
+
(r'\\\\|\\"|\\\n', String.Escape), # included here for raw strings
|
| 153 |
+
include("strings-double"),
|
| 154 |
+
],
|
| 155 |
+
"sqs": [
|
| 156 |
+
(r"'", String.Single, "#pop"),
|
| 157 |
+
(r"\\\\|\\'|\\\n", String.Escape), # included here for raw strings
|
| 158 |
+
include("strings-single"),
|
| 159 |
+
],
|
| 160 |
+
"tdqs": [
|
| 161 |
+
(r'"""', String.Double, "#pop"),
|
| 162 |
+
include("strings-double"),
|
| 163 |
+
(r"\n", Whitespace),
|
| 164 |
+
],
|
| 165 |
+
"tsqs": [
|
| 166 |
+
(r"'''", String.Single, "#pop"),
|
| 167 |
+
include("strings-single"),
|
| 168 |
+
(r"\n", Whitespace),
|
| 169 |
+
],
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
def analyse_text(text):
|
| 173 |
+
score = 0.0
|
| 174 |
+
|
| 175 |
+
if re.search(
|
| 176 |
+
r"func (_ready|_init|_input|_process|_unhandled_input)", text
|
| 177 |
+
):
|
| 178 |
+
score += 0.8
|
| 179 |
+
|
| 180 |
+
if re.search(
|
| 181 |
+
r"(extends |class_name |onready |preload|load|setget|func [^_])",
|
| 182 |
+
text
|
| 183 |
+
):
|
| 184 |
+
score += 0.4
|
| 185 |
+
|
| 186 |
+
if re.search(r"(var|const|enum|export|signal|tool)", text):
|
| 187 |
+
score += 0.2
|
| 188 |
+
|
| 189 |
+
return min(score, 1.0)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/graphics.py
ADDED
|
@@ -0,0 +1,794 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.graphics
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexers for computer graphics and plotting related languages.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from pygments.lexer import RegexLexer, words, include, bygroups, using, \
|
| 12 |
+
this, default
|
| 13 |
+
from pygments.token import Text, Comment, Operator, Keyword, Name, \
|
| 14 |
+
Number, Punctuation, String, Whitespace
|
| 15 |
+
|
| 16 |
+
__all__ = ['GLShaderLexer', 'PostScriptLexer', 'AsymptoteLexer', 'GnuplotLexer',
|
| 17 |
+
'PovrayLexer', 'HLSLShaderLexer']
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class GLShaderLexer(RegexLexer):
|
| 21 |
+
"""
|
| 22 |
+
GLSL (OpenGL Shader) lexer.
|
| 23 |
+
"""
|
| 24 |
+
name = 'GLSL'
|
| 25 |
+
aliases = ['glsl']
|
| 26 |
+
filenames = ['*.vert', '*.frag', '*.geo']
|
| 27 |
+
mimetypes = ['text/x-glslsrc']
|
| 28 |
+
url = 'https://www.khronos.org/api/opengl'
|
| 29 |
+
version_added = '1.1'
|
| 30 |
+
|
| 31 |
+
tokens = {
|
| 32 |
+
'root': [
|
| 33 |
+
(r'#(?:.*\\\n)*.*$', Comment.Preproc),
|
| 34 |
+
(r'//.*$', Comment.Single),
|
| 35 |
+
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
|
| 36 |
+
(r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?',
|
| 37 |
+
Operator),
|
| 38 |
+
(r'[?:]', Operator), # quick hack for ternary
|
| 39 |
+
(r'\bdefined\b', Operator),
|
| 40 |
+
(r'[;{}(),\[\]]', Punctuation),
|
| 41 |
+
# FIXME when e is present, no decimal point needed
|
| 42 |
+
(r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float),
|
| 43 |
+
(r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float),
|
| 44 |
+
(r'0[xX][0-9a-fA-F]*', Number.Hex),
|
| 45 |
+
(r'0[0-7]*', Number.Oct),
|
| 46 |
+
(r'[1-9][0-9]*', Number.Integer),
|
| 47 |
+
(words((
|
| 48 |
+
# Storage qualifiers
|
| 49 |
+
'attribute', 'const', 'uniform', 'varying',
|
| 50 |
+
'buffer', 'shared', 'in', 'out',
|
| 51 |
+
# Layout qualifiers
|
| 52 |
+
'layout',
|
| 53 |
+
# Interpolation qualifiers
|
| 54 |
+
'flat', 'smooth', 'noperspective',
|
| 55 |
+
# Auxiliary qualifiers
|
| 56 |
+
'centroid', 'sample', 'patch',
|
| 57 |
+
# Parameter qualifiers. Some double as Storage qualifiers
|
| 58 |
+
'inout',
|
| 59 |
+
# Precision qualifiers
|
| 60 |
+
'lowp', 'mediump', 'highp', 'precision',
|
| 61 |
+
# Invariance qualifiers
|
| 62 |
+
'invariant',
|
| 63 |
+
# Precise qualifiers
|
| 64 |
+
'precise',
|
| 65 |
+
# Memory qualifiers
|
| 66 |
+
'coherent', 'volatile', 'restrict', 'readonly', 'writeonly',
|
| 67 |
+
# Statements
|
| 68 |
+
'break', 'continue', 'do', 'for', 'while', 'switch',
|
| 69 |
+
'case', 'default', 'if', 'else', 'subroutine',
|
| 70 |
+
'discard', 'return', 'struct'),
|
| 71 |
+
prefix=r'\b', suffix=r'\b'),
|
| 72 |
+
Keyword),
|
| 73 |
+
(words((
|
| 74 |
+
# Boolean values
|
| 75 |
+
'true', 'false'),
|
| 76 |
+
prefix=r'\b', suffix=r'\b'),
|
| 77 |
+
Keyword.Constant),
|
| 78 |
+
(words((
|
| 79 |
+
# Miscellaneous types
|
| 80 |
+
'void', 'atomic_uint',
|
| 81 |
+
# Floating-point scalars and vectors
|
| 82 |
+
'float', 'vec2', 'vec3', 'vec4',
|
| 83 |
+
'double', 'dvec2', 'dvec3', 'dvec4',
|
| 84 |
+
# Integer scalars and vectors
|
| 85 |
+
'int', 'ivec2', 'ivec3', 'ivec4',
|
| 86 |
+
'uint', 'uvec2', 'uvec3', 'uvec4',
|
| 87 |
+
# Boolean scalars and vectors
|
| 88 |
+
'bool', 'bvec2', 'bvec3', 'bvec4',
|
| 89 |
+
# Matrices
|
| 90 |
+
'mat2', 'mat3', 'mat4', 'dmat2', 'dmat3', 'dmat4',
|
| 91 |
+
'mat2x2', 'mat2x3', 'mat2x4', 'dmat2x2', 'dmat2x3', 'dmat2x4',
|
| 92 |
+
'mat3x2', 'mat3x3', 'mat3x4', 'dmat3x2', 'dmat3x3',
|
| 93 |
+
'dmat3x4', 'mat4x2', 'mat4x3', 'mat4x4', 'dmat4x2', 'dmat4x3', 'dmat4x4',
|
| 94 |
+
# Floating-point samplers
|
| 95 |
+
'sampler1D', 'sampler2D', 'sampler3D', 'samplerCube',
|
| 96 |
+
'sampler1DArray', 'sampler2DArray', 'samplerCubeArray',
|
| 97 |
+
'sampler2DRect', 'samplerBuffer',
|
| 98 |
+
'sampler2DMS', 'sampler2DMSArray',
|
| 99 |
+
# Shadow samplers
|
| 100 |
+
'sampler1DShadow', 'sampler2DShadow', 'samplerCubeShadow',
|
| 101 |
+
'sampler1DArrayShadow', 'sampler2DArrayShadow',
|
| 102 |
+
'samplerCubeArrayShadow', 'sampler2DRectShadow',
|
| 103 |
+
# Signed integer samplers
|
| 104 |
+
'isampler1D', 'isampler2D', 'isampler3D', 'isamplerCube',
|
| 105 |
+
'isampler1DArray', 'isampler2DArray', 'isamplerCubeArray',
|
| 106 |
+
'isampler2DRect', 'isamplerBuffer',
|
| 107 |
+
'isampler2DMS', 'isampler2DMSArray',
|
| 108 |
+
# Unsigned integer samplers
|
| 109 |
+
'usampler1D', 'usampler2D', 'usampler3D', 'usamplerCube',
|
| 110 |
+
'usampler1DArray', 'usampler2DArray', 'usamplerCubeArray',
|
| 111 |
+
'usampler2DRect', 'usamplerBuffer',
|
| 112 |
+
'usampler2DMS', 'usampler2DMSArray',
|
| 113 |
+
# Floating-point image types
|
| 114 |
+
'image1D', 'image2D', 'image3D', 'imageCube',
|
| 115 |
+
'image1DArray', 'image2DArray', 'imageCubeArray',
|
| 116 |
+
'image2DRect', 'imageBuffer',
|
| 117 |
+
'image2DMS', 'image2DMSArray',
|
| 118 |
+
# Signed integer image types
|
| 119 |
+
'iimage1D', 'iimage2D', 'iimage3D', 'iimageCube',
|
| 120 |
+
'iimage1DArray', 'iimage2DArray', 'iimageCubeArray',
|
| 121 |
+
'iimage2DRect', 'iimageBuffer',
|
| 122 |
+
'iimage2DMS', 'iimage2DMSArray',
|
| 123 |
+
# Unsigned integer image types
|
| 124 |
+
'uimage1D', 'uimage2D', 'uimage3D', 'uimageCube',
|
| 125 |
+
'uimage1DArray', 'uimage2DArray', 'uimageCubeArray',
|
| 126 |
+
'uimage2DRect', 'uimageBuffer',
|
| 127 |
+
'uimage2DMS', 'uimage2DMSArray'),
|
| 128 |
+
prefix=r'\b', suffix=r'\b'),
|
| 129 |
+
Keyword.Type),
|
| 130 |
+
(words((
|
| 131 |
+
# Reserved for future use.
|
| 132 |
+
'common', 'partition', 'active', 'asm', 'class',
|
| 133 |
+
'union', 'enum', 'typedef', 'template', 'this',
|
| 134 |
+
'resource', 'goto', 'inline', 'noinline', 'public',
|
| 135 |
+
'static', 'extern', 'external', 'interface', 'long',
|
| 136 |
+
'short', 'half', 'fixed', 'unsigned', 'superp', 'input',
|
| 137 |
+
'output', 'hvec2', 'hvec3', 'hvec4', 'fvec2', 'fvec3',
|
| 138 |
+
'fvec4', 'sampler3DRect', 'filter', 'sizeof', 'cast',
|
| 139 |
+
'namespace', 'using'),
|
| 140 |
+
prefix=r'\b', suffix=r'\b'),
|
| 141 |
+
Keyword.Reserved),
|
| 142 |
+
# All names beginning with "gl_" are reserved.
|
| 143 |
+
(r'gl_\w*', Name.Builtin),
|
| 144 |
+
(r'[a-zA-Z_]\w*', Name),
|
| 145 |
+
(r'\.', Punctuation),
|
| 146 |
+
(r'\s+', Whitespace),
|
| 147 |
+
],
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
class HLSLShaderLexer(RegexLexer):
|
| 152 |
+
"""
|
| 153 |
+
HLSL (Microsoft Direct3D Shader) lexer.
|
| 154 |
+
"""
|
| 155 |
+
name = 'HLSL'
|
| 156 |
+
aliases = ['hlsl']
|
| 157 |
+
filenames = ['*.hlsl', '*.hlsli']
|
| 158 |
+
mimetypes = ['text/x-hlsl']
|
| 159 |
+
url = 'https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl'
|
| 160 |
+
version_added = '2.3'
|
| 161 |
+
|
| 162 |
+
tokens = {
|
| 163 |
+
'root': [
|
| 164 |
+
(r'#(?:.*\\\n)*.*$', Comment.Preproc),
|
| 165 |
+
(r'//.*$', Comment.Single),
|
| 166 |
+
(r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
|
| 167 |
+
(r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?',
|
| 168 |
+
Operator),
|
| 169 |
+
(r'[?:]', Operator), # quick hack for ternary
|
| 170 |
+
(r'\bdefined\b', Operator),
|
| 171 |
+
(r'[;{}(),.\[\]]', Punctuation),
|
| 172 |
+
# FIXME when e is present, no decimal point needed
|
| 173 |
+
(r'[+-]?\d*\.\d+([eE][-+]?\d+)?f?', Number.Float),
|
| 174 |
+
(r'[+-]?\d+\.\d*([eE][-+]?\d+)?f?', Number.Float),
|
| 175 |
+
(r'0[xX][0-9a-fA-F]*', Number.Hex),
|
| 176 |
+
(r'0[0-7]*', Number.Oct),
|
| 177 |
+
(r'[1-9][0-9]*', Number.Integer),
|
| 178 |
+
(r'"', String, 'string'),
|
| 179 |
+
(words((
|
| 180 |
+
'asm','asm_fragment','break','case','cbuffer','centroid','class',
|
| 181 |
+
'column_major','compile','compile_fragment','const','continue',
|
| 182 |
+
'default','discard','do','else','export','extern','for','fxgroup',
|
| 183 |
+
'globallycoherent','groupshared','if','in','inline','inout',
|
| 184 |
+
'interface','line','lineadj','linear','namespace','nointerpolation',
|
| 185 |
+
'noperspective','NULL','out','packoffset','pass','pixelfragment',
|
| 186 |
+
'point','precise','return','register','row_major','sample',
|
| 187 |
+
'sampler','shared','stateblock','stateblock_state','static',
|
| 188 |
+
'struct','switch','tbuffer','technique','technique10',
|
| 189 |
+
'technique11','texture','typedef','triangle','triangleadj',
|
| 190 |
+
'uniform','vertexfragment','volatile','while'),
|
| 191 |
+
prefix=r'\b', suffix=r'\b'),
|
| 192 |
+
Keyword),
|
| 193 |
+
(words(('true','false'), prefix=r'\b', suffix=r'\b'),
|
| 194 |
+
Keyword.Constant),
|
| 195 |
+
(words((
|
| 196 |
+
'auto','catch','char','const_cast','delete','dynamic_cast','enum',
|
| 197 |
+
'explicit','friend','goto','long','mutable','new','operator',
|
| 198 |
+
'private','protected','public','reinterpret_cast','short','signed',
|
| 199 |
+
'sizeof','static_cast','template','this','throw','try','typename',
|
| 200 |
+
'union','unsigned','using','virtual'),
|
| 201 |
+
prefix=r'\b', suffix=r'\b'),
|
| 202 |
+
Keyword.Reserved),
|
| 203 |
+
(words((
|
| 204 |
+
'dword','matrix','snorm','string','unorm','unsigned','void','vector',
|
| 205 |
+
'BlendState','Buffer','ByteAddressBuffer','ComputeShader',
|
| 206 |
+
'DepthStencilState','DepthStencilView','DomainShader',
|
| 207 |
+
'GeometryShader','HullShader','InputPatch','LineStream',
|
| 208 |
+
'OutputPatch','PixelShader','PointStream','RasterizerState',
|
| 209 |
+
'RenderTargetView','RasterizerOrderedBuffer',
|
| 210 |
+
'RasterizerOrderedByteAddressBuffer',
|
| 211 |
+
'RasterizerOrderedStructuredBuffer','RasterizerOrderedTexture1D',
|
| 212 |
+
'RasterizerOrderedTexture1DArray','RasterizerOrderedTexture2D',
|
| 213 |
+
'RasterizerOrderedTexture2DArray','RasterizerOrderedTexture3D',
|
| 214 |
+
'RWBuffer','RWByteAddressBuffer','RWStructuredBuffer',
|
| 215 |
+
'RWTexture1D','RWTexture1DArray','RWTexture2D','RWTexture2DArray',
|
| 216 |
+
'RWTexture3D','SamplerState','SamplerComparisonState',
|
| 217 |
+
'StructuredBuffer','Texture1D','Texture1DArray','Texture2D',
|
| 218 |
+
'Texture2DArray','Texture2DMS','Texture2DMSArray','Texture3D',
|
| 219 |
+
'TextureCube','TextureCubeArray','TriangleStream','VertexShader'),
|
| 220 |
+
prefix=r'\b', suffix=r'\b'),
|
| 221 |
+
Keyword.Type),
|
| 222 |
+
(words((
|
| 223 |
+
'bool','double','float','int','half','min16float','min10float',
|
| 224 |
+
'min16int','min12int','min16uint','uint'),
|
| 225 |
+
prefix=r'\b', suffix=r'([1-4](x[1-4])?)?\b'),
|
| 226 |
+
Keyword.Type), # vector and matrix types
|
| 227 |
+
(words((
|
| 228 |
+
'abort','abs','acos','all','AllMemoryBarrier',
|
| 229 |
+
'AllMemoryBarrierWithGroupSync','any','AppendStructuredBuffer',
|
| 230 |
+
'asdouble','asfloat','asin','asint','asuint','asuint','atan',
|
| 231 |
+
'atan2','ceil','CheckAccessFullyMapped','clamp','clip',
|
| 232 |
+
'CompileShader','ConsumeStructuredBuffer','cos','cosh','countbits',
|
| 233 |
+
'cross','D3DCOLORtoUBYTE4','ddx','ddx_coarse','ddx_fine','ddy',
|
| 234 |
+
'ddy_coarse','ddy_fine','degrees','determinant',
|
| 235 |
+
'DeviceMemoryBarrier','DeviceMemoryBarrierWithGroupSync','distance',
|
| 236 |
+
'dot','dst','errorf','EvaluateAttributeAtCentroid',
|
| 237 |
+
'EvaluateAttributeAtSample','EvaluateAttributeSnapped','exp',
|
| 238 |
+
'exp2','f16tof32','f32tof16','faceforward','firstbithigh',
|
| 239 |
+
'firstbitlow','floor','fma','fmod','frac','frexp','fwidth',
|
| 240 |
+
'GetRenderTargetSampleCount','GetRenderTargetSamplePosition',
|
| 241 |
+
'GlobalOrderedCountIncrement','GroupMemoryBarrier',
|
| 242 |
+
'GroupMemoryBarrierWithGroupSync','InterlockedAdd','InterlockedAnd',
|
| 243 |
+
'InterlockedCompareExchange','InterlockedCompareStore',
|
| 244 |
+
'InterlockedExchange','InterlockedMax','InterlockedMin',
|
| 245 |
+
'InterlockedOr','InterlockedXor','isfinite','isinf','isnan',
|
| 246 |
+
'ldexp','length','lerp','lit','log','log10','log2','mad','max',
|
| 247 |
+
'min','modf','msad4','mul','noise','normalize','pow','printf',
|
| 248 |
+
'Process2DQuadTessFactorsAvg','Process2DQuadTessFactorsMax',
|
| 249 |
+
'Process2DQuadTessFactorsMin','ProcessIsolineTessFactors',
|
| 250 |
+
'ProcessQuadTessFactorsAvg','ProcessQuadTessFactorsMax',
|
| 251 |
+
'ProcessQuadTessFactorsMin','ProcessTriTessFactorsAvg',
|
| 252 |
+
'ProcessTriTessFactorsMax','ProcessTriTessFactorsMin',
|
| 253 |
+
'QuadReadLaneAt','QuadSwapX','QuadSwapY','radians','rcp',
|
| 254 |
+
'reflect','refract','reversebits','round','rsqrt','saturate',
|
| 255 |
+
'sign','sin','sincos','sinh','smoothstep','sqrt','step','tan',
|
| 256 |
+
'tanh','tex1D','tex1D','tex1Dbias','tex1Dgrad','tex1Dlod',
|
| 257 |
+
'tex1Dproj','tex2D','tex2D','tex2Dbias','tex2Dgrad','tex2Dlod',
|
| 258 |
+
'tex2Dproj','tex3D','tex3D','tex3Dbias','tex3Dgrad','tex3Dlod',
|
| 259 |
+
'tex3Dproj','texCUBE','texCUBE','texCUBEbias','texCUBEgrad',
|
| 260 |
+
'texCUBElod','texCUBEproj','transpose','trunc','WaveAllBitAnd',
|
| 261 |
+
'WaveAllMax','WaveAllMin','WaveAllBitOr','WaveAllBitXor',
|
| 262 |
+
'WaveAllEqual','WaveAllProduct','WaveAllSum','WaveAllTrue',
|
| 263 |
+
'WaveAnyTrue','WaveBallot','WaveGetLaneCount','WaveGetLaneIndex',
|
| 264 |
+
'WaveGetOrderedIndex','WaveIsHelperLane','WaveOnce',
|
| 265 |
+
'WavePrefixProduct','WavePrefixSum','WaveReadFirstLane',
|
| 266 |
+
'WaveReadLaneAt'),
|
| 267 |
+
prefix=r'\b', suffix=r'\b'),
|
| 268 |
+
Name.Builtin), # built-in functions
|
| 269 |
+
(words((
|
| 270 |
+
'SV_ClipDistance','SV_ClipDistance0','SV_ClipDistance1',
|
| 271 |
+
'SV_Culldistance','SV_CullDistance0','SV_CullDistance1',
|
| 272 |
+
'SV_Coverage','SV_Depth','SV_DepthGreaterEqual',
|
| 273 |
+
'SV_DepthLessEqual','SV_DispatchThreadID','SV_DomainLocation',
|
| 274 |
+
'SV_GroupID','SV_GroupIndex','SV_GroupThreadID','SV_GSInstanceID',
|
| 275 |
+
'SV_InnerCoverage','SV_InsideTessFactor','SV_InstanceID',
|
| 276 |
+
'SV_IsFrontFace','SV_OutputControlPointID','SV_Position',
|
| 277 |
+
'SV_PrimitiveID','SV_RenderTargetArrayIndex','SV_SampleIndex',
|
| 278 |
+
'SV_StencilRef','SV_TessFactor','SV_VertexID',
|
| 279 |
+
'SV_ViewportArrayIndex'),
|
| 280 |
+
prefix=r'\b', suffix=r'\b'),
|
| 281 |
+
Name.Decorator), # system-value semantics
|
| 282 |
+
(r'\bSV_Target[0-7]?\b', Name.Decorator),
|
| 283 |
+
(words((
|
| 284 |
+
'allow_uav_condition','branch','call','domain','earlydepthstencil',
|
| 285 |
+
'fastopt','flatten','forcecase','instance','loop','maxtessfactor',
|
| 286 |
+
'numthreads','outputcontrolpoints','outputtopology','partitioning',
|
| 287 |
+
'patchconstantfunc','unroll'),
|
| 288 |
+
prefix=r'\b', suffix=r'\b'),
|
| 289 |
+
Name.Decorator), # attributes
|
| 290 |
+
(r'[a-zA-Z_]\w*', Name),
|
| 291 |
+
(r'\\$', Comment.Preproc), # backslash at end of line -- usually macro continuation
|
| 292 |
+
(r'\s+', Whitespace),
|
| 293 |
+
],
|
| 294 |
+
'string': [
|
| 295 |
+
(r'"', String, '#pop'),
|
| 296 |
+
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|'
|
| 297 |
+
r'u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})', String.Escape),
|
| 298 |
+
(r'[^\\"\n]+', String), # all other characters
|
| 299 |
+
(r'\\\n', String), # line continuation
|
| 300 |
+
(r'\\', String), # stray backslash
|
| 301 |
+
],
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
class PostScriptLexer(RegexLexer):
|
| 306 |
+
"""
|
| 307 |
+
Lexer for PostScript files.
|
| 308 |
+
"""
|
| 309 |
+
name = 'PostScript'
|
| 310 |
+
url = 'https://en.wikipedia.org/wiki/PostScript'
|
| 311 |
+
aliases = ['postscript', 'postscr']
|
| 312 |
+
filenames = ['*.ps', '*.eps']
|
| 313 |
+
mimetypes = ['application/postscript']
|
| 314 |
+
version_added = '1.4'
|
| 315 |
+
|
| 316 |
+
delimiter = r'()<>\[\]{}/%\s'
|
| 317 |
+
delimiter_end = rf'(?=[{delimiter}])'
|
| 318 |
+
|
| 319 |
+
valid_name_chars = rf'[^{delimiter}]'
|
| 320 |
+
valid_name = rf"{valid_name_chars}+{delimiter_end}"
|
| 321 |
+
|
| 322 |
+
tokens = {
|
| 323 |
+
'root': [
|
| 324 |
+
# All comment types
|
| 325 |
+
(r'^%!.+$', Comment.Preproc),
|
| 326 |
+
(r'%%.*$', Comment.Special),
|
| 327 |
+
(r'(^%.*\n){2,}', Comment.Multiline),
|
| 328 |
+
(r'%.*$', Comment.Single),
|
| 329 |
+
|
| 330 |
+
# String literals are awkward; enter separate state.
|
| 331 |
+
(r'\(', String, 'stringliteral'),
|
| 332 |
+
|
| 333 |
+
(r'[{}<>\[\]]', Punctuation),
|
| 334 |
+
|
| 335 |
+
# Numbers
|
| 336 |
+
(r'<[0-9A-Fa-f]+>' + delimiter_end, Number.Hex),
|
| 337 |
+
# Slight abuse: use Oct to signify any explicit base system
|
| 338 |
+
(r'[0-9]+\#(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)'
|
| 339 |
+
r'((e|E)[0-9]+)?' + delimiter_end, Number.Oct),
|
| 340 |
+
(r'(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)((e|E)[0-9]+)?'
|
| 341 |
+
+ delimiter_end, Number.Float),
|
| 342 |
+
(r'(\-|\+)?[0-9]+' + delimiter_end, Number.Integer),
|
| 343 |
+
|
| 344 |
+
# References
|
| 345 |
+
(rf'\/{valid_name}', Name.Variable),
|
| 346 |
+
|
| 347 |
+
# Names
|
| 348 |
+
(valid_name, Name.Function), # Anything else is executed
|
| 349 |
+
|
| 350 |
+
# These keywords taken from
|
| 351 |
+
# <http://www.math.ubc.ca/~cass/graphics/manual/pdf/a1.pdf>
|
| 352 |
+
# Is there an authoritative list anywhere that doesn't involve
|
| 353 |
+
# trawling documentation?
|
| 354 |
+
|
| 355 |
+
(r'(false|true)' + delimiter_end, Keyword.Constant),
|
| 356 |
+
|
| 357 |
+
# Conditionals / flow control
|
| 358 |
+
(r'(eq|ne|g[et]|l[et]|and|or|not|if(?:else)?|for(?:all)?)'
|
| 359 |
+
+ delimiter_end, Keyword.Reserved),
|
| 360 |
+
|
| 361 |
+
(words((
|
| 362 |
+
'abs', 'add', 'aload', 'arc', 'arcn', 'array', 'atan', 'begin',
|
| 363 |
+
'bind', 'ceiling', 'charpath', 'clip', 'closepath', 'concat',
|
| 364 |
+
'concatmatrix', 'copy', 'cos', 'currentlinewidth', 'currentmatrix',
|
| 365 |
+
'currentpoint', 'curveto', 'cvi', 'cvs', 'def', 'defaultmatrix',
|
| 366 |
+
'dict', 'dictstackoverflow', 'div', 'dtransform', 'dup', 'end',
|
| 367 |
+
'exch', 'exec', 'exit', 'exp', 'fill', 'findfont', 'floor', 'get',
|
| 368 |
+
'getinterval', 'grestore', 'gsave', 'gt', 'identmatrix', 'idiv',
|
| 369 |
+
'idtransform', 'index', 'invertmatrix', 'itransform', 'length',
|
| 370 |
+
'lineto', 'ln', 'load', 'log', 'loop', 'matrix', 'mod', 'moveto',
|
| 371 |
+
'mul', 'neg', 'newpath', 'pathforall', 'pathbbox', 'pop', 'print',
|
| 372 |
+
'pstack', 'put', 'quit', 'rand', 'rangecheck', 'rcurveto', 'repeat',
|
| 373 |
+
'restore', 'rlineto', 'rmoveto', 'roll', 'rotate', 'round', 'run',
|
| 374 |
+
'save', 'scale', 'scalefont', 'setdash', 'setfont', 'setgray',
|
| 375 |
+
'setlinecap', 'setlinejoin', 'setlinewidth', 'setmatrix',
|
| 376 |
+
'setrgbcolor', 'shfill', 'show', 'showpage', 'sin', 'sqrt',
|
| 377 |
+
'stack', 'stringwidth', 'stroke', 'strokepath', 'sub', 'syntaxerror',
|
| 378 |
+
'transform', 'translate', 'truncate', 'typecheck', 'undefined',
|
| 379 |
+
'undefinedfilename', 'undefinedresult'), suffix=delimiter_end),
|
| 380 |
+
Name.Builtin),
|
| 381 |
+
|
| 382 |
+
(r'\s+', Whitespace),
|
| 383 |
+
],
|
| 384 |
+
|
| 385 |
+
'stringliteral': [
|
| 386 |
+
(r'[^()\\]+', String),
|
| 387 |
+
(r'\\', String.Escape, 'escape'),
|
| 388 |
+
(r'\(', String, '#push'),
|
| 389 |
+
(r'\)', String, '#pop'),
|
| 390 |
+
],
|
| 391 |
+
|
| 392 |
+
'escape': [
|
| 393 |
+
(r'[0-8]{3}|n|r|t|b|f|\\|\(|\)', String.Escape, '#pop'),
|
| 394 |
+
default('#pop'),
|
| 395 |
+
],
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
class AsymptoteLexer(RegexLexer):
|
| 400 |
+
"""
|
| 401 |
+
For Asymptote source code.
|
| 402 |
+
"""
|
| 403 |
+
name = 'Asymptote'
|
| 404 |
+
url = 'http://asymptote.sf.net/'
|
| 405 |
+
aliases = ['asymptote', 'asy']
|
| 406 |
+
filenames = ['*.asy']
|
| 407 |
+
mimetypes = ['text/x-asymptote']
|
| 408 |
+
version_added = '1.2'
|
| 409 |
+
|
| 410 |
+
#: optional Comment or Whitespace
|
| 411 |
+
_ws = r'(?:\s|//.*?\n|/\*.*?\*/)+'
|
| 412 |
+
|
| 413 |
+
tokens = {
|
| 414 |
+
'whitespace': [
|
| 415 |
+
(r'\n', Whitespace),
|
| 416 |
+
(r'\s+', Whitespace),
|
| 417 |
+
(r'(\\)(\n)', bygroups(Text, Whitespace)), # line continuation
|
| 418 |
+
(r'//(\n|(.|\n)*?[^\\]\n)', Comment),
|
| 419 |
+
(r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment),
|
| 420 |
+
],
|
| 421 |
+
'statements': [
|
| 422 |
+
# simple string (TeX friendly)
|
| 423 |
+
(r'"(\\\\|\\[^\\]|[^"\\])*"', String),
|
| 424 |
+
# C style string (with character escapes)
|
| 425 |
+
(r"'", String, 'string'),
|
| 426 |
+
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
|
| 427 |
+
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
|
| 428 |
+
(r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
|
| 429 |
+
(r'0[0-7]+[Ll]?', Number.Oct),
|
| 430 |
+
(r'\d+[Ll]?', Number.Integer),
|
| 431 |
+
(r'[~!%^&*+=|?:<>/-]', Operator),
|
| 432 |
+
(r'[()\[\],.]', Punctuation),
|
| 433 |
+
(r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)),
|
| 434 |
+
(r'(and|controls|tension|atleast|curl|if|else|while|for|do|'
|
| 435 |
+
r'return|break|continue|struct|typedef|new|access|import|'
|
| 436 |
+
r'unravel|from|include|quote|static|public|private|restricted|'
|
| 437 |
+
r'this|explicit|true|false|null|cycle|newframe|operator)\b', Keyword),
|
| 438 |
+
# Since an asy-type-name can be also an asy-function-name,
|
| 439 |
+
# in the following we test if the string " [a-zA-Z]" follows
|
| 440 |
+
# the Keyword.Type.
|
| 441 |
+
# Of course it is not perfect !
|
| 442 |
+
(r'(Braid|FitResult|Label|Legend|TreeNode|abscissa|arc|arrowhead|'
|
| 443 |
+
r'binarytree|binarytreeNode|block|bool|bool3|bounds|bqe|circle|'
|
| 444 |
+
r'conic|coord|coordsys|cputime|ellipse|file|filltype|frame|grid3|'
|
| 445 |
+
r'guide|horner|hsv|hyperbola|indexedTransform|int|inversion|key|'
|
| 446 |
+
r'light|line|linefit|marginT|marker|mass|object|pair|parabola|path|'
|
| 447 |
+
r'path3|pen|picture|point|position|projection|real|revolution|'
|
| 448 |
+
r'scaleT|scientific|segment|side|slice|splitface|string|surface|'
|
| 449 |
+
r'tensionSpecifier|ticklocate|ticksgridT|tickvalues|transform|'
|
| 450 |
+
r'transformation|tree|triangle|trilinear|triple|vector|'
|
| 451 |
+
r'vertex|void)(?=\s+[a-zA-Z])', Keyword.Type),
|
| 452 |
+
# Now the asy-type-name which are not asy-function-name
|
| 453 |
+
# except yours !
|
| 454 |
+
# Perhaps useless
|
| 455 |
+
(r'(Braid|FitResult|TreeNode|abscissa|arrowhead|block|bool|bool3|'
|
| 456 |
+
r'bounds|coord|frame|guide|horner|int|linefit|marginT|pair|pen|'
|
| 457 |
+
r'picture|position|real|revolution|slice|splitface|ticksgridT|'
|
| 458 |
+
r'tickvalues|tree|triple|vertex|void)\b', Keyword.Type),
|
| 459 |
+
(r'[a-zA-Z_]\w*:(?!:)', Name.Label),
|
| 460 |
+
(r'[a-zA-Z_]\w*', Name),
|
| 461 |
+
],
|
| 462 |
+
'root': [
|
| 463 |
+
include('whitespace'),
|
| 464 |
+
# functions
|
| 465 |
+
(r'((?:[\w*\s])+?(?:\s|\*))' # return arguments
|
| 466 |
+
r'([a-zA-Z_]\w*)' # method name
|
| 467 |
+
r'(\s*\([^;]*?\))' # signature
|
| 468 |
+
r'(' + _ws + r')(\{)',
|
| 469 |
+
bygroups(using(this), Name.Function, using(this), using(this),
|
| 470 |
+
Punctuation),
|
| 471 |
+
'function'),
|
| 472 |
+
# function declarations
|
| 473 |
+
(r'((?:[\w*\s])+?(?:\s|\*))' # return arguments
|
| 474 |
+
r'([a-zA-Z_]\w*)' # method name
|
| 475 |
+
r'(\s*\([^;]*?\))' # signature
|
| 476 |
+
r'(' + _ws + r')(;)',
|
| 477 |
+
bygroups(using(this), Name.Function, using(this), using(this),
|
| 478 |
+
Punctuation)),
|
| 479 |
+
default('statement'),
|
| 480 |
+
],
|
| 481 |
+
'statement': [
|
| 482 |
+
include('whitespace'),
|
| 483 |
+
include('statements'),
|
| 484 |
+
('[{}]', Punctuation),
|
| 485 |
+
(';', Punctuation, '#pop'),
|
| 486 |
+
],
|
| 487 |
+
'function': [
|
| 488 |
+
include('whitespace'),
|
| 489 |
+
include('statements'),
|
| 490 |
+
(';', Punctuation),
|
| 491 |
+
(r'\{', Punctuation, '#push'),
|
| 492 |
+
(r'\}', Punctuation, '#pop'),
|
| 493 |
+
],
|
| 494 |
+
'string': [
|
| 495 |
+
(r"'", String, '#pop'),
|
| 496 |
+
(r'\\([\\abfnrtv"\'?]|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
|
| 497 |
+
(r'\n', String),
|
| 498 |
+
(r"[^\\'\n]+", String), # all other characters
|
| 499 |
+
(r'\\\n', String),
|
| 500 |
+
(r'\\n', String), # line continuation
|
| 501 |
+
(r'\\', String), # stray backslash
|
| 502 |
+
],
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
def get_tokens_unprocessed(self, text):
|
| 506 |
+
from pygments.lexers._asy_builtins import ASYFUNCNAME, ASYVARNAME
|
| 507 |
+
for index, token, value in \
|
| 508 |
+
RegexLexer.get_tokens_unprocessed(self, text):
|
| 509 |
+
if token is Name and value in ASYFUNCNAME:
|
| 510 |
+
token = Name.Function
|
| 511 |
+
elif token is Name and value in ASYVARNAME:
|
| 512 |
+
token = Name.Variable
|
| 513 |
+
yield index, token, value
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
def _shortened(word):
|
| 517 |
+
dpos = word.find('$')
|
| 518 |
+
return '|'.join(word[:dpos] + word[dpos+1:i] + r'\b'
|
| 519 |
+
for i in range(len(word), dpos, -1))
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
def _shortened_many(*words):
|
| 523 |
+
return '|'.join(map(_shortened, words))
|
| 524 |
+
|
| 525 |
+
|
| 526 |
+
class GnuplotLexer(RegexLexer):
|
| 527 |
+
"""
|
| 528 |
+
For Gnuplot plotting scripts.
|
| 529 |
+
"""
|
| 530 |
+
|
| 531 |
+
name = 'Gnuplot'
|
| 532 |
+
url = 'http://gnuplot.info/'
|
| 533 |
+
aliases = ['gnuplot']
|
| 534 |
+
filenames = ['*.plot', '*.plt']
|
| 535 |
+
mimetypes = ['text/x-gnuplot']
|
| 536 |
+
version_added = '0.11'
|
| 537 |
+
|
| 538 |
+
tokens = {
|
| 539 |
+
'root': [
|
| 540 |
+
include('whitespace'),
|
| 541 |
+
(_shortened('bi$nd'), Keyword, 'bind'),
|
| 542 |
+
(_shortened_many('ex$it', 'q$uit'), Keyword, 'quit'),
|
| 543 |
+
(_shortened('f$it'), Keyword, 'fit'),
|
| 544 |
+
(r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation), 'if'),
|
| 545 |
+
(r'else\b', Keyword),
|
| 546 |
+
(_shortened('pa$use'), Keyword, 'pause'),
|
| 547 |
+
(_shortened_many('p$lot', 'rep$lot', 'sp$lot'), Keyword, 'plot'),
|
| 548 |
+
(_shortened('sa$ve'), Keyword, 'save'),
|
| 549 |
+
(_shortened('se$t'), Keyword, ('genericargs', 'optionarg')),
|
| 550 |
+
(_shortened_many('sh$ow', 'uns$et'),
|
| 551 |
+
Keyword, ('noargs', 'optionarg')),
|
| 552 |
+
(_shortened_many('low$er', 'ra$ise', 'ca$ll', 'cd$', 'cl$ear',
|
| 553 |
+
'h$elp', '\\?$', 'hi$story', 'l$oad', 'pr$int',
|
| 554 |
+
'pwd$', 're$read', 'res$et', 'scr$eendump',
|
| 555 |
+
'she$ll', 'sy$stem', 'up$date'),
|
| 556 |
+
Keyword, 'genericargs'),
|
| 557 |
+
(_shortened_many('pwd$', 're$read', 'res$et', 'scr$eendump',
|
| 558 |
+
'she$ll', 'test$'),
|
| 559 |
+
Keyword, 'noargs'),
|
| 560 |
+
(r'([a-zA-Z_]\w*)(\s*)(=)',
|
| 561 |
+
bygroups(Name.Variable, Whitespace, Operator), 'genericargs'),
|
| 562 |
+
(r'([a-zA-Z_]\w*)(\s*)(\()(.*?)(\))(\s*)(=)',
|
| 563 |
+
bygroups(Name.Function, Whitespace, Punctuation,
|
| 564 |
+
Text, Punctuation, Whitespace, Operator), 'genericargs'),
|
| 565 |
+
(r'@[a-zA-Z_]\w*', Name.Constant), # macros
|
| 566 |
+
(r';', Keyword),
|
| 567 |
+
],
|
| 568 |
+
'comment': [
|
| 569 |
+
(r'[^\\\n]+', Comment),
|
| 570 |
+
(r'\\\n', Comment),
|
| 571 |
+
(r'\\', Comment),
|
| 572 |
+
# don't add the newline to the Comment token
|
| 573 |
+
default('#pop'),
|
| 574 |
+
],
|
| 575 |
+
'whitespace': [
|
| 576 |
+
('#', Comment, 'comment'),
|
| 577 |
+
(r'[ \t\v\f]+', Whitespace),
|
| 578 |
+
],
|
| 579 |
+
'noargs': [
|
| 580 |
+
include('whitespace'),
|
| 581 |
+
# semicolon and newline end the argument list
|
| 582 |
+
(r';', Punctuation, '#pop'),
|
| 583 |
+
(r'\n', Whitespace, '#pop'),
|
| 584 |
+
],
|
| 585 |
+
'dqstring': [
|
| 586 |
+
(r'"', String, '#pop'),
|
| 587 |
+
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
|
| 588 |
+
(r'[^\\"\n]+', String), # all other characters
|
| 589 |
+
(r'\\\n', String), # line continuation
|
| 590 |
+
(r'\\', String), # stray backslash
|
| 591 |
+
(r'\n', Whitespace, '#pop'), # newline ends the string too
|
| 592 |
+
],
|
| 593 |
+
'sqstring': [
|
| 594 |
+
(r"''", String), # escaped single quote
|
| 595 |
+
(r"'", String, '#pop'),
|
| 596 |
+
(r"[^\\'\n]+", String), # all other characters
|
| 597 |
+
(r'\\\n', String), # line continuation
|
| 598 |
+
(r'\\', String), # normal backslash
|
| 599 |
+
(r'\n', Whitespace, '#pop'), # newline ends the string too
|
| 600 |
+
],
|
| 601 |
+
'genericargs': [
|
| 602 |
+
include('noargs'),
|
| 603 |
+
(r'"', String, 'dqstring'),
|
| 604 |
+
(r"'", String, 'sqstring'),
|
| 605 |
+
(r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
|
| 606 |
+
(r'(\d+\.\d*|\.\d+)', Number.Float),
|
| 607 |
+
(r'-?\d+', Number.Integer),
|
| 608 |
+
('[,.~!%^&*+=|?:<>/-]', Operator),
|
| 609 |
+
(r'[{}()\[\]]', Punctuation),
|
| 610 |
+
(r'(eq|ne)\b', Operator.Word),
|
| 611 |
+
(r'([a-zA-Z_]\w*)(\s*)(\()',
|
| 612 |
+
bygroups(Name.Function, Text, Punctuation)),
|
| 613 |
+
(r'[a-zA-Z_]\w*', Name),
|
| 614 |
+
(r'@[a-zA-Z_]\w*', Name.Constant), # macros
|
| 615 |
+
(r'(\\)(\n)', bygroups(Text, Whitespace)),
|
| 616 |
+
],
|
| 617 |
+
'optionarg': [
|
| 618 |
+
include('whitespace'),
|
| 619 |
+
(_shortened_many(
|
| 620 |
+
"a$ll", "an$gles", "ar$row", "au$toscale", "b$ars", "bor$der",
|
| 621 |
+
"box$width", "cl$abel", "c$lip", "cn$trparam", "co$ntour", "da$ta",
|
| 622 |
+
"data$file", "dg$rid3d", "du$mmy", "enc$oding", "dec$imalsign",
|
| 623 |
+
"fit$", "font$path", "fo$rmat", "fu$nction", "fu$nctions", "g$rid",
|
| 624 |
+
"hid$den3d", "his$torysize", "is$osamples", "k$ey", "keyt$itle",
|
| 625 |
+
"la$bel", "li$nestyle", "ls$", "loa$dpath", "loc$ale", "log$scale",
|
| 626 |
+
"mac$ros", "map$ping", "map$ping3d", "mar$gin", "lmar$gin",
|
| 627 |
+
"rmar$gin", "tmar$gin", "bmar$gin", "mo$use", "multi$plot",
|
| 628 |
+
"mxt$ics", "nomxt$ics", "mx2t$ics", "nomx2t$ics", "myt$ics",
|
| 629 |
+
"nomyt$ics", "my2t$ics", "nomy2t$ics", "mzt$ics", "nomzt$ics",
|
| 630 |
+
"mcbt$ics", "nomcbt$ics", "of$fsets", "or$igin", "o$utput",
|
| 631 |
+
"pa$rametric", "pm$3d", "pal$ette", "colorb$ox", "p$lot",
|
| 632 |
+
"poi$ntsize", "pol$ar", "pr$int", "obj$ect", "sa$mples", "si$ze",
|
| 633 |
+
"st$yle", "su$rface", "table$", "t$erminal", "termo$ptions", "ti$cs",
|
| 634 |
+
"ticsc$ale", "ticsl$evel", "timef$mt", "tim$estamp", "tit$le",
|
| 635 |
+
"v$ariables", "ve$rsion", "vi$ew", "xyp$lane", "xda$ta", "x2da$ta",
|
| 636 |
+
"yda$ta", "y2da$ta", "zda$ta", "cbda$ta", "xl$abel", "x2l$abel",
|
| 637 |
+
"yl$abel", "y2l$abel", "zl$abel", "cbl$abel", "xti$cs", "noxti$cs",
|
| 638 |
+
"x2ti$cs", "nox2ti$cs", "yti$cs", "noyti$cs", "y2ti$cs", "noy2ti$cs",
|
| 639 |
+
"zti$cs", "nozti$cs", "cbti$cs", "nocbti$cs", "xdti$cs", "noxdti$cs",
|
| 640 |
+
"x2dti$cs", "nox2dti$cs", "ydti$cs", "noydti$cs", "y2dti$cs",
|
| 641 |
+
"noy2dti$cs", "zdti$cs", "nozdti$cs", "cbdti$cs", "nocbdti$cs",
|
| 642 |
+
"xmti$cs", "noxmti$cs", "x2mti$cs", "nox2mti$cs", "ymti$cs",
|
| 643 |
+
"noymti$cs", "y2mti$cs", "noy2mti$cs", "zmti$cs", "nozmti$cs",
|
| 644 |
+
"cbmti$cs", "nocbmti$cs", "xr$ange", "x2r$ange", "yr$ange",
|
| 645 |
+
"y2r$ange", "zr$ange", "cbr$ange", "rr$ange", "tr$ange", "ur$ange",
|
| 646 |
+
"vr$ange", "xzeroa$xis", "x2zeroa$xis", "yzeroa$xis", "y2zeroa$xis",
|
| 647 |
+
"zzeroa$xis", "zeroa$xis", "z$ero"), Name.Builtin, '#pop'),
|
| 648 |
+
],
|
| 649 |
+
'bind': [
|
| 650 |
+
('!', Keyword, '#pop'),
|
| 651 |
+
(_shortened('all$windows'), Name.Builtin),
|
| 652 |
+
include('genericargs'),
|
| 653 |
+
],
|
| 654 |
+
'quit': [
|
| 655 |
+
(r'gnuplot\b', Keyword),
|
| 656 |
+
include('noargs'),
|
| 657 |
+
],
|
| 658 |
+
'fit': [
|
| 659 |
+
(r'via\b', Name.Builtin),
|
| 660 |
+
include('plot'),
|
| 661 |
+
],
|
| 662 |
+
'if': [
|
| 663 |
+
(r'\)', Punctuation, '#pop'),
|
| 664 |
+
include('genericargs'),
|
| 665 |
+
],
|
| 666 |
+
'pause': [
|
| 667 |
+
(r'(mouse|any|button1|button2|button3)\b', Name.Builtin),
|
| 668 |
+
(_shortened('key$press'), Name.Builtin),
|
| 669 |
+
include('genericargs'),
|
| 670 |
+
],
|
| 671 |
+
'plot': [
|
| 672 |
+
(_shortened_many('ax$es', 'axi$s', 'bin$ary', 'ev$ery', 'i$ndex',
|
| 673 |
+
'mat$rix', 's$mooth', 'thru$', 't$itle',
|
| 674 |
+
'not$itle', 'u$sing', 'w$ith'),
|
| 675 |
+
Name.Builtin),
|
| 676 |
+
include('genericargs'),
|
| 677 |
+
],
|
| 678 |
+
'save': [
|
| 679 |
+
(_shortened_many('f$unctions', 's$et', 't$erminal', 'v$ariables'),
|
| 680 |
+
Name.Builtin),
|
| 681 |
+
include('genericargs'),
|
| 682 |
+
],
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
|
| 686 |
+
class PovrayLexer(RegexLexer):
|
| 687 |
+
"""
|
| 688 |
+
For Persistence of Vision Raytracer files.
|
| 689 |
+
"""
|
| 690 |
+
name = 'POVRay'
|
| 691 |
+
url = 'http://www.povray.org/'
|
| 692 |
+
aliases = ['pov']
|
| 693 |
+
filenames = ['*.pov', '*.inc']
|
| 694 |
+
mimetypes = ['text/x-povray']
|
| 695 |
+
version_added = '0.11'
|
| 696 |
+
|
| 697 |
+
tokens = {
|
| 698 |
+
'root': [
|
| 699 |
+
(r'/\*[\w\W]*?\*/', Comment.Multiline),
|
| 700 |
+
(r'//.*$', Comment.Single),
|
| 701 |
+
(r'(?s)"(?:\\.|[^"\\])+"', String.Double),
|
| 702 |
+
(words((
|
| 703 |
+
'break', 'case', 'debug', 'declare', 'default', 'define', 'else',
|
| 704 |
+
'elseif', 'end', 'error', 'fclose', 'fopen', 'for', 'if', 'ifdef',
|
| 705 |
+
'ifndef', 'include', 'local', 'macro', 'range', 'read', 'render',
|
| 706 |
+
'statistics', 'switch', 'undef', 'version', 'warning', 'while',
|
| 707 |
+
'write'), prefix=r'#', suffix=r'\b'),
|
| 708 |
+
Comment.Preproc),
|
| 709 |
+
(words((
|
| 710 |
+
'aa_level', 'aa_threshold', 'abs', 'acos', 'acosh', 'adaptive', 'adc_bailout',
|
| 711 |
+
'agate', 'agate_turb', 'all', 'alpha', 'ambient', 'ambient_light', 'angle',
|
| 712 |
+
'aperture', 'arc_angle', 'area_light', 'asc', 'asin', 'asinh', 'assumed_gamma',
|
| 713 |
+
'atan', 'atan2', 'atanh', 'atmosphere', 'atmospheric_attenuation',
|
| 714 |
+
'attenuating', 'average', 'background', 'black_hole', 'blue', 'blur_samples',
|
| 715 |
+
'bounded_by', 'box_mapping', 'bozo', 'break', 'brick', 'brick_size',
|
| 716 |
+
'brightness', 'brilliance', 'bumps', 'bumpy1', 'bumpy2', 'bumpy3', 'bump_map',
|
| 717 |
+
'bump_size', 'case', 'caustics', 'ceil', 'checker', 'chr', 'clipped_by', 'clock',
|
| 718 |
+
'color', 'color_map', 'colour', 'colour_map', 'component', 'composite', 'concat',
|
| 719 |
+
'confidence', 'conic_sweep', 'constant', 'control0', 'control1', 'cos', 'cosh',
|
| 720 |
+
'count', 'crackle', 'crand', 'cube', 'cubic_spline', 'cylindrical_mapping',
|
| 721 |
+
'debug', 'declare', 'default', 'degrees', 'dents', 'diffuse', 'direction',
|
| 722 |
+
'distance', 'distance_maximum', 'div', 'dust', 'dust_type', 'eccentricity',
|
| 723 |
+
'else', 'emitting', 'end', 'error', 'error_bound', 'exp', 'exponent',
|
| 724 |
+
'fade_distance', 'fade_power', 'falloff', 'falloff_angle', 'false',
|
| 725 |
+
'file_exists', 'filter', 'finish', 'fisheye', 'flatness', 'flip', 'floor',
|
| 726 |
+
'focal_point', 'fog', 'fog_alt', 'fog_offset', 'fog_type', 'frequency', 'gif',
|
| 727 |
+
'global_settings', 'glowing', 'gradient', 'granite', 'gray_threshold',
|
| 728 |
+
'green', 'halo', 'hexagon', 'hf_gray_16', 'hierarchy', 'hollow', 'hypercomplex',
|
| 729 |
+
'if', 'ifdef', 'iff', 'image_map', 'incidence', 'include', 'int', 'interpolate',
|
| 730 |
+
'inverse', 'ior', 'irid', 'irid_wavelength', 'jitter', 'lambda', 'leopard',
|
| 731 |
+
'linear', 'linear_spline', 'linear_sweep', 'location', 'log', 'looks_like',
|
| 732 |
+
'look_at', 'low_error_factor', 'mandel', 'map_type', 'marble', 'material_map',
|
| 733 |
+
'matrix', 'max', 'max_intersections', 'max_iteration', 'max_trace_level',
|
| 734 |
+
'max_value', 'metallic', 'min', 'minimum_reuse', 'mod', 'mortar',
|
| 735 |
+
'nearest_count', 'no', 'normal', 'normal_map', 'no_shadow', 'number_of_waves',
|
| 736 |
+
'octaves', 'off', 'offset', 'omega', 'omnimax', 'on', 'once', 'onion', 'open',
|
| 737 |
+
'orthographic', 'panoramic', 'pattern1', 'pattern2', 'pattern3',
|
| 738 |
+
'perspective', 'pgm', 'phase', 'phong', 'phong_size', 'pi', 'pigment',
|
| 739 |
+
'pigment_map', 'planar_mapping', 'png', 'point_at', 'pot', 'pow', 'ppm',
|
| 740 |
+
'precision', 'pwr', 'quadratic_spline', 'quaternion', 'quick_color',
|
| 741 |
+
'quick_colour', 'quilted', 'radial', 'radians', 'radiosity', 'radius', 'rainbow',
|
| 742 |
+
'ramp_wave', 'rand', 'range', 'reciprocal', 'recursion_limit', 'red',
|
| 743 |
+
'reflection', 'refraction', 'render', 'repeat', 'rgb', 'rgbf', 'rgbft', 'rgbt',
|
| 744 |
+
'right', 'ripples', 'rotate', 'roughness', 'samples', 'scale', 'scallop_wave',
|
| 745 |
+
'scattering', 'seed', 'shadowless', 'sin', 'sine_wave', 'sinh', 'sky', 'sky_sphere',
|
| 746 |
+
'slice', 'slope_map', 'smooth', 'specular', 'spherical_mapping', 'spiral',
|
| 747 |
+
'spiral1', 'spiral2', 'spotlight', 'spotted', 'sqr', 'sqrt', 'statistics', 'str',
|
| 748 |
+
'strcmp', 'strength', 'strlen', 'strlwr', 'strupr', 'sturm', 'substr', 'switch', 'sys',
|
| 749 |
+
't', 'tan', 'tanh', 'test_camera_1', 'test_camera_2', 'test_camera_3',
|
| 750 |
+
'test_camera_4', 'texture', 'texture_map', 'tga', 'thickness', 'threshold',
|
| 751 |
+
'tightness', 'tile2', 'tiles', 'track', 'transform', 'translate', 'transmit',
|
| 752 |
+
'triangle_wave', 'true', 'ttf', 'turbulence', 'turb_depth', 'type',
|
| 753 |
+
'ultra_wide_angle', 'up', 'use_color', 'use_colour', 'use_index', 'u_steps',
|
| 754 |
+
'val', 'variance', 'vaxis_rotate', 'vcross', 'vdot', 'version', 'vlength',
|
| 755 |
+
'vnormalize', 'volume_object', 'volume_rendered', 'vol_with_light',
|
| 756 |
+
'vrotate', 'v_steps', 'warning', 'warp', 'water_level', 'waves', 'while', 'width',
|
| 757 |
+
'wood', 'wrinkles', 'yes'), prefix=r'\b', suffix=r'\b'),
|
| 758 |
+
Keyword),
|
| 759 |
+
(words((
|
| 760 |
+
'bicubic_patch', 'blob', 'box', 'camera', 'cone', 'cubic', 'cylinder', 'difference',
|
| 761 |
+
'disc', 'height_field', 'intersection', 'julia_fractal', 'lathe',
|
| 762 |
+
'light_source', 'merge', 'mesh', 'object', 'plane', 'poly', 'polygon', 'prism',
|
| 763 |
+
'quadric', 'quartic', 'smooth_triangle', 'sor', 'sphere', 'superellipsoid',
|
| 764 |
+
'text', 'torus', 'triangle', 'union'), suffix=r'\b'),
|
| 765 |
+
Name.Builtin),
|
| 766 |
+
(r'\b(x|y|z|u|v)\b', Name.Builtin.Pseudo),
|
| 767 |
+
(r'[a-zA-Z_]\w*', Name),
|
| 768 |
+
(r'[0-9]*\.[0-9]+', Number.Float),
|
| 769 |
+
(r'[0-9]+', Number.Integer),
|
| 770 |
+
(r'[\[\](){}<>;,]', Punctuation),
|
| 771 |
+
(r'[-+*/=.|&]|<=|>=|!=', Operator),
|
| 772 |
+
(r'"(\\\\|\\[^\\]|[^"\\])*"', String),
|
| 773 |
+
(r'\s+', Whitespace),
|
| 774 |
+
]
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
def analyse_text(text):
|
| 778 |
+
"""POVRAY is similar to JSON/C, but the combination of camera and
|
| 779 |
+
light_source is probably not very likely elsewhere. HLSL or GLSL
|
| 780 |
+
are similar (GLSL even has #version), but they miss #declare, and
|
| 781 |
+
light_source/camera are not keywords anywhere else -- it's fair
|
| 782 |
+
to assume though that any POVRAY scene must have a camera and
|
| 783 |
+
lightsource."""
|
| 784 |
+
result = 0
|
| 785 |
+
if '#version' in text:
|
| 786 |
+
result += 0.05
|
| 787 |
+
if '#declare' in text:
|
| 788 |
+
result += 0.05
|
| 789 |
+
if 'camera' in text:
|
| 790 |
+
result += 0.05
|
| 791 |
+
if 'light_source' in text:
|
| 792 |
+
result += 0.1
|
| 793 |
+
|
| 794 |
+
return result
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/nit.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.nit
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexer for the Nit language.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from pygments.lexer import RegexLexer, words
|
| 12 |
+
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
|
| 13 |
+
Number, Punctuation
|
| 14 |
+
|
| 15 |
+
__all__ = ['NitLexer']
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class NitLexer(RegexLexer):
|
| 19 |
+
"""
|
| 20 |
+
For nit source.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
name = 'Nit'
|
| 24 |
+
url = 'http://nitlanguage.org'
|
| 25 |
+
aliases = ['nit']
|
| 26 |
+
filenames = ['*.nit']
|
| 27 |
+
version_added = '2.0'
|
| 28 |
+
tokens = {
|
| 29 |
+
'root': [
|
| 30 |
+
(r'#.*?$', Comment.Single),
|
| 31 |
+
(words((
|
| 32 |
+
'package', 'module', 'import', 'class', 'abstract', 'interface',
|
| 33 |
+
'universal', 'enum', 'end', 'fun', 'type', 'init', 'redef',
|
| 34 |
+
'isa', 'do', 'readable', 'writable', 'var', 'intern', 'extern',
|
| 35 |
+
'public', 'protected', 'private', 'intrude', 'if', 'then',
|
| 36 |
+
'else', 'while', 'loop', 'for', 'in', 'and', 'or', 'not',
|
| 37 |
+
'implies', 'return', 'continue', 'break', 'abort', 'assert',
|
| 38 |
+
'new', 'is', 'once', 'super', 'self', 'true', 'false', 'nullable',
|
| 39 |
+
'null', 'as', 'isset', 'label', '__debug__'), suffix=r'(?=[\r\n\t( ])'),
|
| 40 |
+
Keyword),
|
| 41 |
+
(r'[A-Z]\w*', Name.Class),
|
| 42 |
+
(r'"""(([^\'\\]|\\.)|\\r|\\n)*((\{\{?)?(""?\{\{?)*""""*)', String), # Simple long string
|
| 43 |
+
(r'\'\'\'(((\\.|[^\'\\])|\\r|\\n)|\'((\\.|[^\'\\])|\\r|\\n)|'
|
| 44 |
+
r'\'\'((\\.|[^\'\\])|\\r|\\n))*\'\'\'', String), # Simple long string alt
|
| 45 |
+
(r'"""(([^\'\\]|\\.)|\\r|\\n)*((""?)?(\{\{?""?)*\{\{\{\{*)', String), # Start long string
|
| 46 |
+
(r'\}\}\}(((\\.|[^\'\\])|\\r|\\n))*(""?)?(\{\{?""?)*\{\{\{\{*', String), # Mid long string
|
| 47 |
+
(r'\}\}\}(((\\.|[^\'\\])|\\r|\\n))*(\{\{?)?(""?\{\{?)*""""*', String), # End long string
|
| 48 |
+
(r'"(\\.|([^"}{\\]))*"', String), # Simple String
|
| 49 |
+
(r'"(\\.|([^"}{\\]))*\{', String), # Start string
|
| 50 |
+
(r'\}(\\.|([^"}{\\]))*\{', String), # Mid String
|
| 51 |
+
(r'\}(\\.|([^"}{\\]))*"', String), # End String
|
| 52 |
+
(r'(\'[^\'\\]\')|(\'\\.\')', String.Char),
|
| 53 |
+
(r'[0-9]+', Number.Integer),
|
| 54 |
+
(r'[0-9]*.[0-9]+', Number.Float),
|
| 55 |
+
(r'0(x|X)[0-9A-Fa-f]+', Number.Hex),
|
| 56 |
+
(r'[a-z]\w*', Name),
|
| 57 |
+
(r'_\w+', Name.Variable.Instance),
|
| 58 |
+
(r'==|!=|<==>|>=|>>|>|<=|<<|<|\+|-|=|/|\*|%|\+=|-=|!|@', Operator),
|
| 59 |
+
(r'\(|\)|\[|\]|,|\.\.\.|\.\.|\.|::|:', Punctuation),
|
| 60 |
+
(r'`\{[^`]*`\}', Text), # Extern blocks won't be Lexed by Nit
|
| 61 |
+
(r'[\r\n\t ]+', Text),
|
| 62 |
+
],
|
| 63 |
+
}
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/procfile.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.procfile
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexer for Procfile file format.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present 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 Name, Number, String, Text, Punctuation
|
| 13 |
+
|
| 14 |
+
__all__ = ["ProcfileLexer"]
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class ProcfileLexer(RegexLexer):
|
| 18 |
+
"""
|
| 19 |
+
Lexer for Procfile file format.
|
| 20 |
+
|
| 21 |
+
The format is used to run processes on Heroku or is used by Foreman or
|
| 22 |
+
Honcho tools.
|
| 23 |
+
"""
|
| 24 |
+
name = 'Procfile'
|
| 25 |
+
url = 'https://devcenter.heroku.com/articles/procfile#procfile-format'
|
| 26 |
+
aliases = ['procfile']
|
| 27 |
+
filenames = ['Procfile']
|
| 28 |
+
version_added = '2.10'
|
| 29 |
+
|
| 30 |
+
tokens = {
|
| 31 |
+
'root': [
|
| 32 |
+
(r'^([a-z]+)(:)', bygroups(Name.Label, Punctuation)),
|
| 33 |
+
(r'\s+', Text.Whitespace),
|
| 34 |
+
(r'"[^"]*"', String),
|
| 35 |
+
(r"'[^']*'", String),
|
| 36 |
+
(r'[0-9]+', Number.Integer),
|
| 37 |
+
(r'\$[a-zA-Z_][\w]*', Name.Variable),
|
| 38 |
+
(r'(\w+)(=)(\w+)', bygroups(Name.Variable, Punctuation, String)),
|
| 39 |
+
(r'([\w\-\./]+)', Text),
|
| 40 |
+
],
|
| 41 |
+
}
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/rell.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.rell
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexers for the Rell language.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from pygments.lexer import RegexLexer, bygroups, default, words
|
| 12 |
+
from pygments.token import Comment, Keyword, Name, String, Number, \
|
| 13 |
+
Punctuation, Whitespace
|
| 14 |
+
|
| 15 |
+
__all__ = ['RellLexer']
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class RellLexer(RegexLexer):
|
| 19 |
+
"""
|
| 20 |
+
A Lexer for Rell.
|
| 21 |
+
"""
|
| 22 |
+
name = 'Rell'
|
| 23 |
+
url = 'https://docs.chromia.com/rell/rell-intro'
|
| 24 |
+
aliases = ['rell']
|
| 25 |
+
filenames = ['*.rell']
|
| 26 |
+
mimetypes = ['text/x-rell']
|
| 27 |
+
version_added = '2.20'
|
| 28 |
+
|
| 29 |
+
ident = r'[a-zA-Z_][a-zA-Z0-9_]*'
|
| 30 |
+
|
| 31 |
+
tokens = {
|
| 32 |
+
'root': [
|
| 33 |
+
(words((
|
| 34 |
+
'big_integer', 'boolean', 'byte_array', 'decimal', 'gtv',
|
| 35 |
+
'integer', 'json', 'list', 'map', 'mutable', 'set', 'text',
|
| 36 |
+
'virtual'), suffix=r'\b'),
|
| 37 |
+
Keyword.Type),
|
| 38 |
+
(r'(false|true|null)\b', Keyword.Constant),
|
| 39 |
+
(r'(entity|enum|namespace|object|struct)\b', Keyword.Declaration),
|
| 40 |
+
(r'(function|operation|query)\b', Keyword.Declaration, 'function'),
|
| 41 |
+
(words((
|
| 42 |
+
'abstract', 'and', 'break', 'continue', 'create', 'delete',
|
| 43 |
+
'else', 'for', 'if', 'import', 'in', 'index', 'key', 'limit',
|
| 44 |
+
'module', 'not', 'offset', 'or', 'override', 'return', 'update',
|
| 45 |
+
'val', 'var', 'when', 'while'), suffix=r'\b'),
|
| 46 |
+
Keyword.Reserved),
|
| 47 |
+
(r'//.*?$', Comment.Single),
|
| 48 |
+
(r'/\*(.|\n|\r)*?\*/', Comment.Multiline),
|
| 49 |
+
(r'"(\\\\|\\"|[^"])*"', String.Double),
|
| 50 |
+
(r'\'(\\\\|\\\'|[^\\\'])*\'', String.Single),
|
| 51 |
+
(r'-?[0-9]*\.[0-9]+([eE][+-][0-9]+)?', Number.Float),
|
| 52 |
+
(r'-?[0-9]+([eE][+-][0-9]+|[lL])?', Number.Integer),
|
| 53 |
+
(r'x(\'[a-fA-F0-9]*\'|"[a-fA-F0-9]*")', String.Binary),
|
| 54 |
+
(r'(\.)([ \n\t\r]*)(' + ident + ')',
|
| 55 |
+
bygroups(Punctuation, Whitespace, Name.Attribute)),
|
| 56 |
+
(r'[{}():;,]+', Punctuation),
|
| 57 |
+
(r'[ \n\t\r]+', Whitespace),
|
| 58 |
+
(r'@[a-zA-Z_][a-zA-Z0-9_]*', Name.Decorator),
|
| 59 |
+
(r'[~^*!%&\[\]<>|+=/?\-@\$]', Punctuation.Marker),
|
| 60 |
+
(ident, Name),
|
| 61 |
+
(r'(\.)+', Punctuation),
|
| 62 |
+
],
|
| 63 |
+
'function': [
|
| 64 |
+
(r'[ \n\t\r]+', Whitespace),
|
| 65 |
+
(ident, Name.Function, '#pop'),
|
| 66 |
+
default('#pop'),
|
| 67 |
+
],
|
| 68 |
+
}
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/rust.py
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.rust
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexers for the Rust language.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from pygments.lexer import RegexLexer, include, bygroups, words, default
|
| 12 |
+
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
|
| 13 |
+
Number, Punctuation, Whitespace
|
| 14 |
+
|
| 15 |
+
__all__ = ['RustLexer']
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class RustLexer(RegexLexer):
|
| 19 |
+
"""
|
| 20 |
+
Lexer for the Rust programming language (version 1.47).
|
| 21 |
+
"""
|
| 22 |
+
name = 'Rust'
|
| 23 |
+
url = 'https://www.rust-lang.org/'
|
| 24 |
+
filenames = ['*.rs', '*.rs.in']
|
| 25 |
+
aliases = ['rust', 'rs']
|
| 26 |
+
mimetypes = ['text/rust', 'text/x-rust']
|
| 27 |
+
version_added = '1.6'
|
| 28 |
+
|
| 29 |
+
keyword_types = (words((
|
| 30 |
+
'u8', 'u16', 'u32', 'u64', 'u128', 'i8', 'i16', 'i32', 'i64', 'i128',
|
| 31 |
+
'usize', 'isize', 'f32', 'f64', 'char', 'str', 'bool',
|
| 32 |
+
), suffix=r'\b'), Keyword.Type)
|
| 33 |
+
|
| 34 |
+
builtin_funcs_types = (words((
|
| 35 |
+
'Copy', 'Send', 'Sized', 'Sync', 'Unpin',
|
| 36 |
+
'Drop', 'Fn', 'FnMut', 'FnOnce', 'drop',
|
| 37 |
+
'Box', 'ToOwned', 'Clone',
|
| 38 |
+
'PartialEq', 'PartialOrd', 'Eq', 'Ord',
|
| 39 |
+
'AsRef', 'AsMut', 'Into', 'From', 'Default',
|
| 40 |
+
'Iterator', 'Extend', 'IntoIterator', 'DoubleEndedIterator',
|
| 41 |
+
'ExactSizeIterator',
|
| 42 |
+
'Option', 'Some', 'None',
|
| 43 |
+
'Result', 'Ok', 'Err',
|
| 44 |
+
'String', 'ToString', 'Vec',
|
| 45 |
+
), suffix=r'\b'), Name.Builtin)
|
| 46 |
+
|
| 47 |
+
builtin_macros = (words((
|
| 48 |
+
'asm', 'assert', 'assert_eq', 'assert_ne', 'cfg', 'column',
|
| 49 |
+
'compile_error', 'concat', 'concat_idents', 'dbg', 'debug_assert',
|
| 50 |
+
'debug_assert_eq', 'debug_assert_ne', 'env', 'eprint', 'eprintln',
|
| 51 |
+
'file', 'format', 'format_args', 'format_args_nl', 'global_asm',
|
| 52 |
+
'include', 'include_bytes', 'include_str',
|
| 53 |
+
'is_aarch64_feature_detected',
|
| 54 |
+
'is_arm_feature_detected',
|
| 55 |
+
'is_mips64_feature_detected',
|
| 56 |
+
'is_mips_feature_detected',
|
| 57 |
+
'is_powerpc64_feature_detected',
|
| 58 |
+
'is_powerpc_feature_detected',
|
| 59 |
+
'is_x86_feature_detected',
|
| 60 |
+
'line', 'llvm_asm', 'log_syntax', 'macro_rules', 'matches',
|
| 61 |
+
'module_path', 'option_env', 'panic', 'print', 'println', 'stringify',
|
| 62 |
+
'thread_local', 'todo', 'trace_macros', 'unimplemented', 'unreachable',
|
| 63 |
+
'vec', 'write', 'writeln',
|
| 64 |
+
), suffix=r'!'), Name.Function.Magic)
|
| 65 |
+
|
| 66 |
+
tokens = {
|
| 67 |
+
'root': [
|
| 68 |
+
# rust allows a file to start with a shebang, but if the first line
|
| 69 |
+
# starts with #![ then it's not a shebang but a crate attribute.
|
| 70 |
+
(r'#![^[\r\n].*$', Comment.Preproc),
|
| 71 |
+
default('base'),
|
| 72 |
+
],
|
| 73 |
+
'base': [
|
| 74 |
+
# Whitespace and Comments
|
| 75 |
+
(r'\n', Whitespace),
|
| 76 |
+
(r'\s+', Whitespace),
|
| 77 |
+
(r'//!.*?\n', String.Doc),
|
| 78 |
+
(r'///(\n|[^/].*?\n)', String.Doc),
|
| 79 |
+
(r'//(.*?)\n', Comment.Single),
|
| 80 |
+
(r'/\*\*(\n|[^/*])', String.Doc, 'doccomment'),
|
| 81 |
+
(r'/\*!', String.Doc, 'doccomment'),
|
| 82 |
+
(r'/\*', Comment.Multiline, 'comment'),
|
| 83 |
+
|
| 84 |
+
# Macro parameters
|
| 85 |
+
(r"""\$([a-zA-Z_]\w*|\(,?|\),?|,?)""", Comment.Preproc),
|
| 86 |
+
# Keywords
|
| 87 |
+
(words(('as', 'async', 'await', 'box', 'const', 'crate', 'dyn',
|
| 88 |
+
'else', 'extern', 'for', 'if', 'impl', 'in', 'loop',
|
| 89 |
+
'match', 'move', 'mut', 'pub', 'ref', 'return', 'static',
|
| 90 |
+
'super', 'trait', 'unsafe', 'use', 'where', 'while'),
|
| 91 |
+
suffix=r'\b'), Keyword),
|
| 92 |
+
(words(('abstract', 'become', 'do', 'final', 'macro', 'override',
|
| 93 |
+
'priv', 'typeof', 'try', 'unsized', 'virtual', 'yield'),
|
| 94 |
+
suffix=r'\b'), Keyword.Reserved),
|
| 95 |
+
(r'(true|false)\b', Keyword.Constant),
|
| 96 |
+
(r'self\b', Name.Builtin.Pseudo),
|
| 97 |
+
(r'mod\b', Keyword, 'modname'),
|
| 98 |
+
(r'let\b', Keyword.Declaration),
|
| 99 |
+
(r'fn\b', Keyword, 'funcname'),
|
| 100 |
+
(r'(struct|enum|type|union)\b', Keyword, 'typename'),
|
| 101 |
+
(r'(default)(\s+)(type|fn)\b', bygroups(Keyword, Whitespace, Keyword)),
|
| 102 |
+
keyword_types,
|
| 103 |
+
(r'[sS]elf\b', Name.Builtin.Pseudo),
|
| 104 |
+
# Prelude (taken from Rust's src/libstd/prelude.rs)
|
| 105 |
+
builtin_funcs_types,
|
| 106 |
+
builtin_macros,
|
| 107 |
+
# Path separators, so types don't catch them.
|
| 108 |
+
(r'::\b', Punctuation),
|
| 109 |
+
# Types in positions.
|
| 110 |
+
(r'(?::|->)', Punctuation, 'typename'),
|
| 111 |
+
# Labels
|
| 112 |
+
(r'(break|continue)(\b\s*)(\'[A-Za-z_]\w*)?',
|
| 113 |
+
bygroups(Keyword, Text.Whitespace, Name.Label)),
|
| 114 |
+
|
| 115 |
+
# Character literals
|
| 116 |
+
(r"""'(\\['"\\nrt]|\\x[0-7][0-9a-fA-F]|\\0"""
|
| 117 |
+
r"""|\\u\{[0-9a-fA-F]{1,6}\}|.)'""",
|
| 118 |
+
String.Char),
|
| 119 |
+
(r"""b'(\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\0"""
|
| 120 |
+
r"""|\\u\{[0-9a-fA-F]{1,6}\}|.)'""",
|
| 121 |
+
String.Char),
|
| 122 |
+
|
| 123 |
+
# Binary literals
|
| 124 |
+
(r'0b[01_]+', Number.Bin, 'number_lit'),
|
| 125 |
+
# Octal literals
|
| 126 |
+
(r'0o[0-7_]+', Number.Oct, 'number_lit'),
|
| 127 |
+
# Hexadecimal literals
|
| 128 |
+
(r'0[xX][0-9a-fA-F_]+', Number.Hex, 'number_lit'),
|
| 129 |
+
# Decimal literals
|
| 130 |
+
(r'[0-9][0-9_]*(\.[0-9_]+[eE][+\-]?[0-9_]+|'
|
| 131 |
+
r'\.[0-9_]*(?!\.)|[eE][+\-]?[0-9_]+)', Number.Float,
|
| 132 |
+
'number_lit'),
|
| 133 |
+
(r'[0-9][0-9_]*', Number.Integer, 'number_lit'),
|
| 134 |
+
|
| 135 |
+
# String literals
|
| 136 |
+
(r'b"', String, 'bytestring'),
|
| 137 |
+
(r'"', String, 'string'),
|
| 138 |
+
(r'(?s)b?r(#*)".*?"\1', String),
|
| 139 |
+
|
| 140 |
+
# Lifetime names
|
| 141 |
+
(r"'", Operator, 'lifetime'),
|
| 142 |
+
|
| 143 |
+
# Operators and Punctuation
|
| 144 |
+
(r'\.\.=?', Operator),
|
| 145 |
+
(r'[{}()\[\],.;]', Punctuation),
|
| 146 |
+
(r'[+\-*/%&|<>^!~@=:?]', Operator),
|
| 147 |
+
|
| 148 |
+
# Identifiers
|
| 149 |
+
(r'[a-zA-Z_]\w*', Name),
|
| 150 |
+
# Raw identifiers
|
| 151 |
+
(r'r#[a-zA-Z_]\w*', Name),
|
| 152 |
+
|
| 153 |
+
# Attributes
|
| 154 |
+
(r'#!?\[', Comment.Preproc, 'attribute['),
|
| 155 |
+
|
| 156 |
+
# Misc
|
| 157 |
+
# Lone hashes: not used in Rust syntax, but allowed in macro
|
| 158 |
+
# arguments, most famously for quote::quote!()
|
| 159 |
+
(r'#', Punctuation),
|
| 160 |
+
],
|
| 161 |
+
'comment': [
|
| 162 |
+
(r'[^*/]+', Comment.Multiline),
|
| 163 |
+
(r'/\*', Comment.Multiline, '#push'),
|
| 164 |
+
(r'\*/', Comment.Multiline, '#pop'),
|
| 165 |
+
(r'[*/]', Comment.Multiline),
|
| 166 |
+
],
|
| 167 |
+
'doccomment': [
|
| 168 |
+
(r'[^*/]+', String.Doc),
|
| 169 |
+
(r'/\*', String.Doc, '#push'),
|
| 170 |
+
(r'\*/', String.Doc, '#pop'),
|
| 171 |
+
(r'[*/]', String.Doc),
|
| 172 |
+
],
|
| 173 |
+
'modname': [
|
| 174 |
+
(r'\s+', Whitespace),
|
| 175 |
+
(r'[a-zA-Z_]\w*', Name.Namespace, '#pop'),
|
| 176 |
+
default('#pop'),
|
| 177 |
+
],
|
| 178 |
+
'funcname': [
|
| 179 |
+
(r'\s+', Whitespace),
|
| 180 |
+
(r'[a-zA-Z_]\w*', Name.Function, '#pop'),
|
| 181 |
+
default('#pop'),
|
| 182 |
+
],
|
| 183 |
+
'typename': [
|
| 184 |
+
(r'\s+', Whitespace),
|
| 185 |
+
(r'&', Keyword.Pseudo),
|
| 186 |
+
(r"'", Operator, 'lifetime'),
|
| 187 |
+
builtin_funcs_types,
|
| 188 |
+
keyword_types,
|
| 189 |
+
(r'[a-zA-Z_]\w*', Name.Class, '#pop'),
|
| 190 |
+
default('#pop'),
|
| 191 |
+
],
|
| 192 |
+
'lifetime': [
|
| 193 |
+
(r"(static|_)", Name.Builtin),
|
| 194 |
+
(r"[a-zA-Z_]+\w*", Name.Attribute),
|
| 195 |
+
default('#pop'),
|
| 196 |
+
],
|
| 197 |
+
'number_lit': [
|
| 198 |
+
(r'[ui](8|16|32|64|size)', Keyword, '#pop'),
|
| 199 |
+
(r'f(32|64)', Keyword, '#pop'),
|
| 200 |
+
default('#pop'),
|
| 201 |
+
],
|
| 202 |
+
'string': [
|
| 203 |
+
(r'"', String, '#pop'),
|
| 204 |
+
(r"""\\['"\\nrt]|\\x[0-7][0-9a-fA-F]|\\0"""
|
| 205 |
+
r"""|\\u\{[0-9a-fA-F]{1,6}\}""", String.Escape),
|
| 206 |
+
(r'[^\\"]+', String),
|
| 207 |
+
(r'\\', String),
|
| 208 |
+
],
|
| 209 |
+
'bytestring': [
|
| 210 |
+
(r"""\\x[89a-fA-F][0-9a-fA-F]""", String.Escape),
|
| 211 |
+
include('string'),
|
| 212 |
+
],
|
| 213 |
+
'attribute_common': [
|
| 214 |
+
(r'"', String, 'string'),
|
| 215 |
+
(r'\[', Comment.Preproc, 'attribute['),
|
| 216 |
+
],
|
| 217 |
+
'attribute[': [
|
| 218 |
+
include('attribute_common'),
|
| 219 |
+
(r'\]', Comment.Preproc, '#pop'),
|
| 220 |
+
(r'[^"\]\[]+', Comment.Preproc),
|
| 221 |
+
],
|
| 222 |
+
}
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/shell.py
ADDED
|
@@ -0,0 +1,902 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.shell
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexers for various shells.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import re
|
| 12 |
+
|
| 13 |
+
from pygments.lexer import Lexer, RegexLexer, do_insertions, bygroups, \
|
| 14 |
+
include, default, this, using, words, line_re
|
| 15 |
+
from pygments.token import Punctuation, Whitespace, \
|
| 16 |
+
Text, Comment, Operator, Keyword, Name, String, Number, Generic
|
| 17 |
+
from pygments.util import shebang_matches
|
| 18 |
+
|
| 19 |
+
__all__ = ['BashLexer', 'BashSessionLexer', 'TcshLexer', 'BatchLexer',
|
| 20 |
+
'SlurmBashLexer', 'MSDOSSessionLexer', 'PowerShellLexer',
|
| 21 |
+
'PowerShellSessionLexer', 'TcshSessionLexer', 'FishShellLexer',
|
| 22 |
+
'ExeclineLexer']
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class BashLexer(RegexLexer):
|
| 26 |
+
"""
|
| 27 |
+
Lexer for (ba|k|z|)sh shell scripts.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
name = 'Bash'
|
| 31 |
+
aliases = ['bash', 'sh', 'ksh', 'zsh', 'shell', 'openrc']
|
| 32 |
+
filenames = ['*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass',
|
| 33 |
+
'*.exheres-0', '*.exlib', '*.zsh',
|
| 34 |
+
'.bashrc', 'bashrc', '.bash_*', 'bash_*', 'zshrc', '.zshrc',
|
| 35 |
+
'.kshrc', 'kshrc',
|
| 36 |
+
'PKGBUILD']
|
| 37 |
+
mimetypes = ['application/x-sh', 'application/x-shellscript', 'text/x-shellscript']
|
| 38 |
+
url = 'https://en.wikipedia.org/wiki/Unix_shell'
|
| 39 |
+
version_added = '0.6'
|
| 40 |
+
|
| 41 |
+
tokens = {
|
| 42 |
+
'root': [
|
| 43 |
+
include('basic'),
|
| 44 |
+
(r'`', String.Backtick, 'backticks'),
|
| 45 |
+
include('data'),
|
| 46 |
+
include('interp'),
|
| 47 |
+
],
|
| 48 |
+
'interp': [
|
| 49 |
+
(r'\$\(\(', Keyword, 'math'),
|
| 50 |
+
(r'\$\(', Keyword, 'paren'),
|
| 51 |
+
(r'\$\{#?', String.Interpol, 'curly'),
|
| 52 |
+
(r'\$[a-zA-Z_]\w*', Name.Variable), # user variable
|
| 53 |
+
(r'\$(?:\d+|[#$?!_*@-])', Name.Variable), # builtin
|
| 54 |
+
(r'\$', Text),
|
| 55 |
+
],
|
| 56 |
+
'basic': [
|
| 57 |
+
(r'\b(if|fi|else|while|in|do|done|for|then|return|function|case|'
|
| 58 |
+
r'select|break|continue|until|esac|elif)(\s*)\b',
|
| 59 |
+
bygroups(Keyword, Whitespace)),
|
| 60 |
+
(r'\b(alias|bg|bind|builtin|caller|cd|command|compgen|'
|
| 61 |
+
r'complete|declare|dirs|disown|echo|enable|eval|exec|exit|'
|
| 62 |
+
r'export|false|fc|fg|getopts|hash|help|history|jobs|kill|let|'
|
| 63 |
+
r'local|logout|popd|printf|pushd|pwd|read|readonly|set|shift|'
|
| 64 |
+
r'shopt|source|suspend|test|time|times|trap|true|type|typeset|'
|
| 65 |
+
r'ulimit|umask|unalias|unset|wait)(?=[\s)`])',
|
| 66 |
+
Name.Builtin),
|
| 67 |
+
(r'\A#!.+\n', Comment.Hashbang),
|
| 68 |
+
(r'#.*\n', Comment.Single),
|
| 69 |
+
(r'\\[\w\W]', String.Escape),
|
| 70 |
+
(r'(\b\w+)(\s*)(\+?=)', bygroups(Name.Variable, Whitespace, Operator)),
|
| 71 |
+
(r'[\[\]{}()=]', Operator),
|
| 72 |
+
(r'<<<', Operator), # here-string
|
| 73 |
+
(r'<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2', String),
|
| 74 |
+
(r'&&|\|\|', Operator),
|
| 75 |
+
],
|
| 76 |
+
'data': [
|
| 77 |
+
(r'(?s)\$?"(\\.|[^"\\$])*"', String.Double),
|
| 78 |
+
(r'"', String.Double, 'string'),
|
| 79 |
+
(r"(?s)\$'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
|
| 80 |
+
(r"(?s)'.*?'", String.Single),
|
| 81 |
+
(r';', Punctuation),
|
| 82 |
+
(r'&', Punctuation),
|
| 83 |
+
(r'\|', Punctuation),
|
| 84 |
+
(r'\s+', Whitespace),
|
| 85 |
+
(r'\d+\b', Number),
|
| 86 |
+
(r'[^=\s\[\]{}()$"\'`\\<&|;]+', Text),
|
| 87 |
+
(r'<', Text),
|
| 88 |
+
],
|
| 89 |
+
'string': [
|
| 90 |
+
(r'"', String.Double, '#pop'),
|
| 91 |
+
(r'(?s)(\\\\|\\[0-7]+|\\.|[^"\\$])+', String.Double),
|
| 92 |
+
include('interp'),
|
| 93 |
+
],
|
| 94 |
+
'curly': [
|
| 95 |
+
(r'\}', String.Interpol, '#pop'),
|
| 96 |
+
(r':-', Keyword),
|
| 97 |
+
(r'\w+', Name.Variable),
|
| 98 |
+
(r'[^}:"\'`$\\]+', Punctuation),
|
| 99 |
+
(r':', Punctuation),
|
| 100 |
+
include('root'),
|
| 101 |
+
],
|
| 102 |
+
'paren': [
|
| 103 |
+
(r'\)', Keyword, '#pop'),
|
| 104 |
+
include('root'),
|
| 105 |
+
],
|
| 106 |
+
'math': [
|
| 107 |
+
(r'\)\)', Keyword, '#pop'),
|
| 108 |
+
(r'\*\*|\|\||<<|>>|[-+*/%^|&<>]', Operator),
|
| 109 |
+
(r'\d+#[\da-zA-Z]+', Number),
|
| 110 |
+
(r'\d+#(?! )', Number),
|
| 111 |
+
(r'0[xX][\da-fA-F]+', Number),
|
| 112 |
+
(r'\d+', Number),
|
| 113 |
+
(r'[a-zA-Z_]\w*', Name.Variable), # user variable
|
| 114 |
+
include('root'),
|
| 115 |
+
],
|
| 116 |
+
'backticks': [
|
| 117 |
+
(r'`', String.Backtick, '#pop'),
|
| 118 |
+
include('root'),
|
| 119 |
+
],
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
def analyse_text(text):
|
| 123 |
+
if shebang_matches(text, r'(ba|z|)sh'):
|
| 124 |
+
return 1
|
| 125 |
+
if text.startswith('$ '):
|
| 126 |
+
return 0.2
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class SlurmBashLexer(BashLexer):
|
| 130 |
+
"""
|
| 131 |
+
Lexer for (ba|k|z|)sh Slurm scripts.
|
| 132 |
+
"""
|
| 133 |
+
|
| 134 |
+
name = 'Slurm'
|
| 135 |
+
aliases = ['slurm', 'sbatch']
|
| 136 |
+
filenames = ['*.sl']
|
| 137 |
+
mimetypes = []
|
| 138 |
+
version_added = '2.4'
|
| 139 |
+
EXTRA_KEYWORDS = {'srun'}
|
| 140 |
+
|
| 141 |
+
def get_tokens_unprocessed(self, text):
|
| 142 |
+
for index, token, value in BashLexer.get_tokens_unprocessed(self, text):
|
| 143 |
+
if token is Text and value in self.EXTRA_KEYWORDS:
|
| 144 |
+
yield index, Name.Builtin, value
|
| 145 |
+
elif token is Comment.Single and 'SBATCH' in value:
|
| 146 |
+
yield index, Keyword.Pseudo, value
|
| 147 |
+
else:
|
| 148 |
+
yield index, token, value
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
class ShellSessionBaseLexer(Lexer):
|
| 152 |
+
"""
|
| 153 |
+
Base lexer for shell sessions.
|
| 154 |
+
|
| 155 |
+
.. versionadded:: 2.1
|
| 156 |
+
"""
|
| 157 |
+
|
| 158 |
+
_bare_continuation = False
|
| 159 |
+
_venv = re.compile(r'^(\([^)]*\))(\s*)')
|
| 160 |
+
|
| 161 |
+
def get_tokens_unprocessed(self, text):
|
| 162 |
+
innerlexer = self._innerLexerCls(**self.options)
|
| 163 |
+
|
| 164 |
+
pos = 0
|
| 165 |
+
curcode = ''
|
| 166 |
+
insertions = []
|
| 167 |
+
backslash_continuation = False
|
| 168 |
+
|
| 169 |
+
for match in line_re.finditer(text):
|
| 170 |
+
line = match.group()
|
| 171 |
+
|
| 172 |
+
venv_match = self._venv.match(line)
|
| 173 |
+
if venv_match:
|
| 174 |
+
venv = venv_match.group(1)
|
| 175 |
+
venv_whitespace = venv_match.group(2)
|
| 176 |
+
insertions.append((len(curcode),
|
| 177 |
+
[(0, Generic.Prompt.VirtualEnv, venv)]))
|
| 178 |
+
if venv_whitespace:
|
| 179 |
+
insertions.append((len(curcode),
|
| 180 |
+
[(0, Text, venv_whitespace)]))
|
| 181 |
+
line = line[venv_match.end():]
|
| 182 |
+
|
| 183 |
+
m = self._ps1rgx.match(line)
|
| 184 |
+
if m:
|
| 185 |
+
# To support output lexers (say diff output), the output
|
| 186 |
+
# needs to be broken by prompts whenever the output lexer
|
| 187 |
+
# changes.
|
| 188 |
+
if not insertions:
|
| 189 |
+
pos = match.start()
|
| 190 |
+
|
| 191 |
+
insertions.append((len(curcode),
|
| 192 |
+
[(0, Generic.Prompt, m.group(1))]))
|
| 193 |
+
curcode += m.group(2)
|
| 194 |
+
backslash_continuation = curcode.endswith('\\\n')
|
| 195 |
+
elif backslash_continuation:
|
| 196 |
+
if line.startswith(self._ps2):
|
| 197 |
+
insertions.append((len(curcode),
|
| 198 |
+
[(0, Generic.Prompt,
|
| 199 |
+
line[:len(self._ps2)])]))
|
| 200 |
+
curcode += line[len(self._ps2):]
|
| 201 |
+
else:
|
| 202 |
+
curcode += line
|
| 203 |
+
backslash_continuation = curcode.endswith('\\\n')
|
| 204 |
+
elif self._bare_continuation and line.startswith(self._ps2):
|
| 205 |
+
insertions.append((len(curcode),
|
| 206 |
+
[(0, Generic.Prompt,
|
| 207 |
+
line[:len(self._ps2)])]))
|
| 208 |
+
curcode += line[len(self._ps2):]
|
| 209 |
+
else:
|
| 210 |
+
if insertions:
|
| 211 |
+
toks = innerlexer.get_tokens_unprocessed(curcode)
|
| 212 |
+
for i, t, v in do_insertions(insertions, toks):
|
| 213 |
+
yield pos+i, t, v
|
| 214 |
+
yield match.start(), Generic.Output, line
|
| 215 |
+
insertions = []
|
| 216 |
+
curcode = ''
|
| 217 |
+
if insertions:
|
| 218 |
+
for i, t, v in do_insertions(insertions,
|
| 219 |
+
innerlexer.get_tokens_unprocessed(curcode)):
|
| 220 |
+
yield pos+i, t, v
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
class BashSessionLexer(ShellSessionBaseLexer):
|
| 224 |
+
"""
|
| 225 |
+
Lexer for Bash shell sessions, i.e. command lines, including a
|
| 226 |
+
prompt, interspersed with output.
|
| 227 |
+
"""
|
| 228 |
+
|
| 229 |
+
name = 'Bash Session'
|
| 230 |
+
aliases = ['console', 'shell-session']
|
| 231 |
+
filenames = ['*.sh-session', '*.shell-session']
|
| 232 |
+
mimetypes = ['application/x-shell-session', 'application/x-sh-session']
|
| 233 |
+
url = 'https://en.wikipedia.org/wiki/Unix_shell'
|
| 234 |
+
version_added = '1.1'
|
| 235 |
+
_example = "console/example.sh-session"
|
| 236 |
+
|
| 237 |
+
_innerLexerCls = BashLexer
|
| 238 |
+
_ps1rgx = re.compile(
|
| 239 |
+
r'^((?:(?:\[.*?\])|(?:\(\S+\))?(?:| |sh\S*?|\w+\S+[@:]\S+(?:\s+\S+)' \
|
| 240 |
+
r'?|\[\S+[@:][^\n]+\].+))\s*[$#%]\s*)(.*\n?)')
|
| 241 |
+
_ps2 = '> '
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
class BatchLexer(RegexLexer):
|
| 245 |
+
"""
|
| 246 |
+
Lexer for the DOS/Windows Batch file format.
|
| 247 |
+
"""
|
| 248 |
+
name = 'Batchfile'
|
| 249 |
+
aliases = ['batch', 'bat', 'dosbatch', 'winbatch']
|
| 250 |
+
filenames = ['*.bat', '*.cmd']
|
| 251 |
+
mimetypes = ['application/x-dos-batch']
|
| 252 |
+
url = 'https://en.wikipedia.org/wiki/Batch_file'
|
| 253 |
+
version_added = '0.7'
|
| 254 |
+
|
| 255 |
+
flags = re.MULTILINE | re.IGNORECASE
|
| 256 |
+
|
| 257 |
+
_nl = r'\n\x1a'
|
| 258 |
+
_punct = r'&<>|'
|
| 259 |
+
_ws = r'\t\v\f\r ,;=\xa0'
|
| 260 |
+
_nlws = r'\s\x1a\xa0,;='
|
| 261 |
+
_space = rf'(?:(?:(?:\^[{_nl}])?[{_ws}])+)'
|
| 262 |
+
_keyword_terminator = (rf'(?=(?:\^[{_nl}]?)?[{_ws}+./:[\\\]]|[{_nl}{_punct}(])')
|
| 263 |
+
_token_terminator = rf'(?=\^?[{_ws}]|[{_punct}{_nl}])'
|
| 264 |
+
_start_label = rf'((?:(?<=^[^:])|^[^:]?)[{_ws}]*)(:)'
|
| 265 |
+
_label = rf'(?:(?:[^{_nlws}{_punct}+:^]|\^[{_nl}]?[\w\W])*)'
|
| 266 |
+
_label_compound = rf'(?:(?:[^{_nlws}{_punct}+:^)]|\^[{_nl}]?[^)])*)'
|
| 267 |
+
_number = rf'(?:-?(?:0[0-7]+|0x[\da-f]+|\d+){_token_terminator})'
|
| 268 |
+
_opword = r'(?:equ|geq|gtr|leq|lss|neq)'
|
| 269 |
+
_string = rf'(?:"[^{_nl}"]*(?:"|(?=[{_nl}])))'
|
| 270 |
+
_variable = (r'(?:(?:%(?:\*|(?:~[a-z]*(?:\$[^:]+:)?)?\d|'
|
| 271 |
+
rf'[^%:{_nl}]+(?::(?:~(?:-?\d+)?(?:,(?:-?\d+)?)?|(?:[^%{_nl}^]|'
|
| 272 |
+
rf'\^[^%{_nl}])[^={_nl}]*=(?:[^%{_nl}^]|\^[^%{_nl}])*)?)?%))|'
|
| 273 |
+
rf'(?:\^?![^!:{_nl}]+(?::(?:~(?:-?\d+)?(?:,(?:-?\d+)?)?|(?:'
|
| 274 |
+
rf'[^!{_nl}^]|\^[^!{_nl}])[^={_nl}]*=(?:[^!{_nl}^]|\^[^!{_nl}])*)?)?\^?!))')
|
| 275 |
+
_core_token = rf'(?:(?:(?:\^[{_nl}]?)?[^"{_nlws}{_punct}])+)'
|
| 276 |
+
_core_token_compound = rf'(?:(?:(?:\^[{_nl}]?)?[^"{_nlws}{_punct})])+)'
|
| 277 |
+
_token = rf'(?:[{_punct}]+|{_core_token})'
|
| 278 |
+
_token_compound = rf'(?:[{_punct}]+|{_core_token_compound})'
|
| 279 |
+
_stoken = (rf'(?:[{_punct}]+|(?:{_string}|{_variable}|{_core_token})+)')
|
| 280 |
+
|
| 281 |
+
def _make_begin_state(compound, _core_token=_core_token,
|
| 282 |
+
_core_token_compound=_core_token_compound,
|
| 283 |
+
_keyword_terminator=_keyword_terminator,
|
| 284 |
+
_nl=_nl, _punct=_punct, _string=_string,
|
| 285 |
+
_space=_space, _start_label=_start_label,
|
| 286 |
+
_stoken=_stoken, _token_terminator=_token_terminator,
|
| 287 |
+
_variable=_variable, _ws=_ws):
|
| 288 |
+
rest = '(?:{}|{}|[^"%{}{}{}])*'.format(_string, _variable, _nl, _punct,
|
| 289 |
+
')' if compound else '')
|
| 290 |
+
rest_of_line = rf'(?:(?:[^{_nl}^]|\^[{_nl}]?[\w\W])*)'
|
| 291 |
+
rest_of_line_compound = rf'(?:(?:[^{_nl}^)]|\^[{_nl}]?[^)])*)'
|
| 292 |
+
set_space = rf'((?:(?:\^[{_nl}]?)?[^\S\n])*)'
|
| 293 |
+
suffix = ''
|
| 294 |
+
if compound:
|
| 295 |
+
_keyword_terminator = rf'(?:(?=\))|{_keyword_terminator})'
|
| 296 |
+
_token_terminator = rf'(?:(?=\))|{_token_terminator})'
|
| 297 |
+
suffix = '/compound'
|
| 298 |
+
return [
|
| 299 |
+
((r'\)', Punctuation, '#pop') if compound else
|
| 300 |
+
(rf'\)((?=\()|{_token_terminator}){rest_of_line}',
|
| 301 |
+
Comment.Single)),
|
| 302 |
+
(rf'(?={_start_label})', Text, f'follow{suffix}'),
|
| 303 |
+
(_space, using(this, state='text')),
|
| 304 |
+
include(f'redirect{suffix}'),
|
| 305 |
+
(rf'[{_nl}]+', Text),
|
| 306 |
+
(r'\(', Punctuation, 'root/compound'),
|
| 307 |
+
(r'@+', Punctuation),
|
| 308 |
+
(rf'((?:for|if|rem)(?:(?=(?:\^[{_nl}]?)?/)|(?:(?!\^)|'
|
| 309 |
+
rf'(?<=m))(?:(?=\()|{_token_terminator})))({_space}?{_core_token_compound if compound else _core_token}?(?:\^[{_nl}]?)?/(?:\^[{_nl}]?)?\?)',
|
| 310 |
+
bygroups(Keyword, using(this, state='text')),
|
| 311 |
+
f'follow{suffix}'),
|
| 312 |
+
(rf'(goto{_keyword_terminator})({rest}(?:\^[{_nl}]?)?/(?:\^[{_nl}]?)?\?{rest})',
|
| 313 |
+
bygroups(Keyword, using(this, state='text')),
|
| 314 |
+
f'follow{suffix}'),
|
| 315 |
+
(words(('assoc', 'break', 'cd', 'chdir', 'cls', 'color', 'copy',
|
| 316 |
+
'date', 'del', 'dir', 'dpath', 'echo', 'endlocal', 'erase',
|
| 317 |
+
'exit', 'ftype', 'keys', 'md', 'mkdir', 'mklink', 'move',
|
| 318 |
+
'path', 'pause', 'popd', 'prompt', 'pushd', 'rd', 'ren',
|
| 319 |
+
'rename', 'rmdir', 'setlocal', 'shift', 'start', 'time',
|
| 320 |
+
'title', 'type', 'ver', 'verify', 'vol'),
|
| 321 |
+
suffix=_keyword_terminator), Keyword, f'follow{suffix}'),
|
| 322 |
+
(rf'(call)({_space}?)(:)',
|
| 323 |
+
bygroups(Keyword, using(this, state='text'), Punctuation),
|
| 324 |
+
f'call{suffix}'),
|
| 325 |
+
(rf'call{_keyword_terminator}', Keyword),
|
| 326 |
+
(rf'(for{_token_terminator}(?!\^))({_space})(/f{_token_terminator})',
|
| 327 |
+
bygroups(Keyword, using(this, state='text'), Keyword),
|
| 328 |
+
('for/f', 'for')),
|
| 329 |
+
(rf'(for{_token_terminator}(?!\^))({_space})(/l{_token_terminator})',
|
| 330 |
+
bygroups(Keyword, using(this, state='text'), Keyword),
|
| 331 |
+
('for/l', 'for')),
|
| 332 |
+
(rf'for{_token_terminator}(?!\^)', Keyword, ('for2', 'for')),
|
| 333 |
+
(rf'(goto{_keyword_terminator})({_space}?)(:?)',
|
| 334 |
+
bygroups(Keyword, using(this, state='text'), Punctuation),
|
| 335 |
+
f'label{suffix}'),
|
| 336 |
+
(rf'(if(?:(?=\()|{_token_terminator})(?!\^))({_space}?)((?:/i{_token_terminator})?)({_space}?)((?:not{_token_terminator})?)({_space}?)',
|
| 337 |
+
bygroups(Keyword, using(this, state='text'), Keyword,
|
| 338 |
+
using(this, state='text'), Keyword,
|
| 339 |
+
using(this, state='text')), ('(?', 'if')),
|
| 340 |
+
(rf'rem(((?=\()|{_token_terminator}){_space}?{_stoken}?.*|{_keyword_terminator}{rest_of_line_compound if compound else rest_of_line})',
|
| 341 |
+
Comment.Single, f'follow{suffix}'),
|
| 342 |
+
(rf'(set{_keyword_terminator}){set_space}(/a)',
|
| 343 |
+
bygroups(Keyword, using(this, state='text'), Keyword),
|
| 344 |
+
f'arithmetic{suffix}'),
|
| 345 |
+
(r'(set{}){}((?:/p)?){}((?:(?:(?:\^[{}]?)?[^"{}{}^={}]|'
|
| 346 |
+
r'\^[{}]?[^"=])+)?)((?:(?:\^[{}]?)?=)?)'.format(_keyword_terminator, set_space, set_space, _nl, _nl, _punct,
|
| 347 |
+
')' if compound else '', _nl, _nl),
|
| 348 |
+
bygroups(Keyword, using(this, state='text'), Keyword,
|
| 349 |
+
using(this, state='text'), using(this, state='variable'),
|
| 350 |
+
Punctuation),
|
| 351 |
+
f'follow{suffix}'),
|
| 352 |
+
default(f'follow{suffix}')
|
| 353 |
+
]
|
| 354 |
+
|
| 355 |
+
def _make_follow_state(compound, _label=_label,
|
| 356 |
+
_label_compound=_label_compound, _nl=_nl,
|
| 357 |
+
_space=_space, _start_label=_start_label,
|
| 358 |
+
_token=_token, _token_compound=_token_compound,
|
| 359 |
+
_ws=_ws):
|
| 360 |
+
suffix = '/compound' if compound else ''
|
| 361 |
+
state = []
|
| 362 |
+
if compound:
|
| 363 |
+
state.append((r'(?=\))', Text, '#pop'))
|
| 364 |
+
state += [
|
| 365 |
+
(rf'{_start_label}([{_ws}]*)({_label_compound if compound else _label})(.*)',
|
| 366 |
+
bygroups(Text, Punctuation, Text, Name.Label, Comment.Single)),
|
| 367 |
+
include(f'redirect{suffix}'),
|
| 368 |
+
(rf'(?=[{_nl}])', Text, '#pop'),
|
| 369 |
+
(r'\|\|?|&&?', Punctuation, '#pop'),
|
| 370 |
+
include('text')
|
| 371 |
+
]
|
| 372 |
+
return state
|
| 373 |
+
|
| 374 |
+
def _make_arithmetic_state(compound, _nl=_nl, _punct=_punct,
|
| 375 |
+
_string=_string, _variable=_variable,
|
| 376 |
+
_ws=_ws, _nlws=_nlws):
|
| 377 |
+
op = r'=+\-*/!~'
|
| 378 |
+
state = []
|
| 379 |
+
if compound:
|
| 380 |
+
state.append((r'(?=\))', Text, '#pop'))
|
| 381 |
+
state += [
|
| 382 |
+
(r'0[0-7]+', Number.Oct),
|
| 383 |
+
(r'0x[\da-f]+', Number.Hex),
|
| 384 |
+
(r'\d+', Number.Integer),
|
| 385 |
+
(r'[(),]+', Punctuation),
|
| 386 |
+
(rf'([{op}]|%|\^\^)+', Operator),
|
| 387 |
+
(r'({}|{}|(\^[{}]?)?[^(){}%\^"{}{}]|\^[{}]?{})+'.format(_string, _variable, _nl, op, _nlws, _punct, _nlws,
|
| 388 |
+
r'[^)]' if compound else r'[\w\W]'),
|
| 389 |
+
using(this, state='variable')),
|
| 390 |
+
(r'(?=[\x00|&])', Text, '#pop'),
|
| 391 |
+
include('follow')
|
| 392 |
+
]
|
| 393 |
+
return state
|
| 394 |
+
|
| 395 |
+
def _make_call_state(compound, _label=_label,
|
| 396 |
+
_label_compound=_label_compound):
|
| 397 |
+
state = []
|
| 398 |
+
if compound:
|
| 399 |
+
state.append((r'(?=\))', Text, '#pop'))
|
| 400 |
+
state.append((r'(:?)(%s)' % (_label_compound if compound else _label),
|
| 401 |
+
bygroups(Punctuation, Name.Label), '#pop'))
|
| 402 |
+
return state
|
| 403 |
+
|
| 404 |
+
def _make_label_state(compound, _label=_label,
|
| 405 |
+
_label_compound=_label_compound, _nl=_nl,
|
| 406 |
+
_punct=_punct, _string=_string, _variable=_variable):
|
| 407 |
+
state = []
|
| 408 |
+
if compound:
|
| 409 |
+
state.append((r'(?=\))', Text, '#pop'))
|
| 410 |
+
state.append((r'({}?)((?:{}|{}|\^[{}]?{}|[^"%^{}{}{}])*)'.format(_label_compound if compound else _label, _string,
|
| 411 |
+
_variable, _nl, r'[^)]' if compound else r'[\w\W]', _nl,
|
| 412 |
+
_punct, r')' if compound else ''),
|
| 413 |
+
bygroups(Name.Label, Comment.Single), '#pop'))
|
| 414 |
+
return state
|
| 415 |
+
|
| 416 |
+
def _make_redirect_state(compound,
|
| 417 |
+
_core_token_compound=_core_token_compound,
|
| 418 |
+
_nl=_nl, _punct=_punct, _stoken=_stoken,
|
| 419 |
+
_string=_string, _space=_space,
|
| 420 |
+
_variable=_variable, _nlws=_nlws):
|
| 421 |
+
stoken_compound = (rf'(?:[{_punct}]+|(?:{_string}|{_variable}|{_core_token_compound})+)')
|
| 422 |
+
return [
|
| 423 |
+
(rf'((?:(?<=[{_nlws}])\d)?)(>>?&|<&)([{_nlws}]*)(\d)',
|
| 424 |
+
bygroups(Number.Integer, Punctuation, Text, Number.Integer)),
|
| 425 |
+
(rf'((?:(?<=[{_nlws}])(?<!\^[{_nl}])\d)?)(>>?|<)({_space}?{stoken_compound if compound else _stoken})',
|
| 426 |
+
bygroups(Number.Integer, Punctuation, using(this, state='text')))
|
| 427 |
+
]
|
| 428 |
+
|
| 429 |
+
tokens = {
|
| 430 |
+
'root': _make_begin_state(False),
|
| 431 |
+
'follow': _make_follow_state(False),
|
| 432 |
+
'arithmetic': _make_arithmetic_state(False),
|
| 433 |
+
'call': _make_call_state(False),
|
| 434 |
+
'label': _make_label_state(False),
|
| 435 |
+
'redirect': _make_redirect_state(False),
|
| 436 |
+
'root/compound': _make_begin_state(True),
|
| 437 |
+
'follow/compound': _make_follow_state(True),
|
| 438 |
+
'arithmetic/compound': _make_arithmetic_state(True),
|
| 439 |
+
'call/compound': _make_call_state(True),
|
| 440 |
+
'label/compound': _make_label_state(True),
|
| 441 |
+
'redirect/compound': _make_redirect_state(True),
|
| 442 |
+
'variable-or-escape': [
|
| 443 |
+
(_variable, Name.Variable),
|
| 444 |
+
(rf'%%|\^[{_nl}]?(\^!|[\w\W])', String.Escape)
|
| 445 |
+
],
|
| 446 |
+
'string': [
|
| 447 |
+
(r'"', String.Double, '#pop'),
|
| 448 |
+
(_variable, Name.Variable),
|
| 449 |
+
(r'\^!|%%', String.Escape),
|
| 450 |
+
(rf'[^"%^{_nl}]+|[%^]', String.Double),
|
| 451 |
+
default('#pop')
|
| 452 |
+
],
|
| 453 |
+
'sqstring': [
|
| 454 |
+
include('variable-or-escape'),
|
| 455 |
+
(r'[^%]+|%', String.Single)
|
| 456 |
+
],
|
| 457 |
+
'bqstring': [
|
| 458 |
+
include('variable-or-escape'),
|
| 459 |
+
(r'[^%]+|%', String.Backtick)
|
| 460 |
+
],
|
| 461 |
+
'text': [
|
| 462 |
+
(r'"', String.Double, 'string'),
|
| 463 |
+
include('variable-or-escape'),
|
| 464 |
+
(rf'[^"%^{_nlws}{_punct}\d)]+|.', Text)
|
| 465 |
+
],
|
| 466 |
+
'variable': [
|
| 467 |
+
(r'"', String.Double, 'string'),
|
| 468 |
+
include('variable-or-escape'),
|
| 469 |
+
(rf'[^"%^{_nl}]+|.', Name.Variable)
|
| 470 |
+
],
|
| 471 |
+
'for': [
|
| 472 |
+
(rf'({_space})(in)({_space})(\()',
|
| 473 |
+
bygroups(using(this, state='text'), Keyword,
|
| 474 |
+
using(this, state='text'), Punctuation), '#pop'),
|
| 475 |
+
include('follow')
|
| 476 |
+
],
|
| 477 |
+
'for2': [
|
| 478 |
+
(r'\)', Punctuation),
|
| 479 |
+
(rf'({_space})(do{_token_terminator})',
|
| 480 |
+
bygroups(using(this, state='text'), Keyword), '#pop'),
|
| 481 |
+
(rf'[{_nl}]+', Text),
|
| 482 |
+
include('follow')
|
| 483 |
+
],
|
| 484 |
+
'for/f': [
|
| 485 |
+
(rf'(")((?:{_variable}|[^"])*?")([{_nlws}]*)(\))',
|
| 486 |
+
bygroups(String.Double, using(this, state='string'), Text,
|
| 487 |
+
Punctuation)),
|
| 488 |
+
(r'"', String.Double, ('#pop', 'for2', 'string')),
|
| 489 |
+
(rf"('(?:%%|{_variable}|[\w\W])*?')([{_nlws}]*)(\))",
|
| 490 |
+
bygroups(using(this, state='sqstring'), Text, Punctuation)),
|
| 491 |
+
(rf'(`(?:%%|{_variable}|[\w\W])*?`)([{_nlws}]*)(\))',
|
| 492 |
+
bygroups(using(this, state='bqstring'), Text, Punctuation)),
|
| 493 |
+
include('for2')
|
| 494 |
+
],
|
| 495 |
+
'for/l': [
|
| 496 |
+
(r'-?\d+', Number.Integer),
|
| 497 |
+
include('for2')
|
| 498 |
+
],
|
| 499 |
+
'if': [
|
| 500 |
+
(rf'((?:cmdextversion|errorlevel){_token_terminator})({_space})(\d+)',
|
| 501 |
+
bygroups(Keyword, using(this, state='text'),
|
| 502 |
+
Number.Integer), '#pop'),
|
| 503 |
+
(rf'(defined{_token_terminator})({_space})({_stoken})',
|
| 504 |
+
bygroups(Keyword, using(this, state='text'),
|
| 505 |
+
using(this, state='variable')), '#pop'),
|
| 506 |
+
(rf'(exist{_token_terminator})({_space}{_stoken})',
|
| 507 |
+
bygroups(Keyword, using(this, state='text')), '#pop'),
|
| 508 |
+
(rf'({_number}{_space})({_opword})({_space}{_number})',
|
| 509 |
+
bygroups(using(this, state='arithmetic'), Operator.Word,
|
| 510 |
+
using(this, state='arithmetic')), '#pop'),
|
| 511 |
+
(_stoken, using(this, state='text'), ('#pop', 'if2')),
|
| 512 |
+
],
|
| 513 |
+
'if2': [
|
| 514 |
+
(rf'({_space}?)(==)({_space}?{_stoken})',
|
| 515 |
+
bygroups(using(this, state='text'), Operator,
|
| 516 |
+
using(this, state='text')), '#pop'),
|
| 517 |
+
(rf'({_space})({_opword})({_space}{_stoken})',
|
| 518 |
+
bygroups(using(this, state='text'), Operator.Word,
|
| 519 |
+
using(this, state='text')), '#pop')
|
| 520 |
+
],
|
| 521 |
+
'(?': [
|
| 522 |
+
(_space, using(this, state='text')),
|
| 523 |
+
(r'\(', Punctuation, ('#pop', 'else?', 'root/compound')),
|
| 524 |
+
default('#pop')
|
| 525 |
+
],
|
| 526 |
+
'else?': [
|
| 527 |
+
(_space, using(this, state='text')),
|
| 528 |
+
(rf'else{_token_terminator}', Keyword, '#pop'),
|
| 529 |
+
default('#pop')
|
| 530 |
+
]
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
|
| 534 |
+
class MSDOSSessionLexer(ShellSessionBaseLexer):
|
| 535 |
+
"""
|
| 536 |
+
Lexer for MS DOS shell sessions, i.e. command lines, including a
|
| 537 |
+
prompt, interspersed with output.
|
| 538 |
+
"""
|
| 539 |
+
|
| 540 |
+
name = 'MSDOS Session'
|
| 541 |
+
aliases = ['doscon']
|
| 542 |
+
filenames = []
|
| 543 |
+
mimetypes = []
|
| 544 |
+
url = 'https://en.wikipedia.org/wiki/MS-DOS'
|
| 545 |
+
version_added = '2.1'
|
| 546 |
+
_example = "doscon/session"
|
| 547 |
+
|
| 548 |
+
_innerLexerCls = BatchLexer
|
| 549 |
+
_ps1rgx = re.compile(r'^([^>]*>)(.*\n?)')
|
| 550 |
+
_ps2 = 'More? '
|
| 551 |
+
|
| 552 |
+
|
| 553 |
+
class TcshLexer(RegexLexer):
|
| 554 |
+
"""
|
| 555 |
+
Lexer for tcsh scripts.
|
| 556 |
+
"""
|
| 557 |
+
|
| 558 |
+
name = 'Tcsh'
|
| 559 |
+
aliases = ['tcsh', 'csh']
|
| 560 |
+
filenames = ['*.tcsh', '*.csh']
|
| 561 |
+
mimetypes = ['application/x-csh']
|
| 562 |
+
url = 'https://www.tcsh.org'
|
| 563 |
+
version_added = '0.10'
|
| 564 |
+
|
| 565 |
+
tokens = {
|
| 566 |
+
'root': [
|
| 567 |
+
include('basic'),
|
| 568 |
+
(r'\$\(', Keyword, 'paren'),
|
| 569 |
+
(r'\$\{#?', Keyword, 'curly'),
|
| 570 |
+
(r'`', String.Backtick, 'backticks'),
|
| 571 |
+
include('data'),
|
| 572 |
+
],
|
| 573 |
+
'basic': [
|
| 574 |
+
(r'\b(if|endif|else|while|then|foreach|case|default|'
|
| 575 |
+
r'break|continue|goto|breaksw|end|switch|endsw)\s*\b',
|
| 576 |
+
Keyword),
|
| 577 |
+
(r'\b(alias|alloc|bg|bindkey|builtins|bye|caller|cd|chdir|'
|
| 578 |
+
r'complete|dirs|echo|echotc|eval|exec|exit|fg|filetest|getxvers|'
|
| 579 |
+
r'glob|getspath|hashstat|history|hup|inlib|jobs|kill|'
|
| 580 |
+
r'limit|log|login|logout|ls-F|migrate|newgrp|nice|nohup|notify|'
|
| 581 |
+
r'onintr|popd|printenv|pushd|rehash|repeat|rootnode|popd|pushd|'
|
| 582 |
+
r'set|shift|sched|setenv|setpath|settc|setty|setxvers|shift|'
|
| 583 |
+
r'source|stop|suspend|source|suspend|telltc|time|'
|
| 584 |
+
r'umask|unalias|uncomplete|unhash|universe|unlimit|unset|unsetenv|'
|
| 585 |
+
r'ver|wait|warp|watchlog|where|which)\s*\b',
|
| 586 |
+
Name.Builtin),
|
| 587 |
+
(r'#.*', Comment),
|
| 588 |
+
(r'\\[\w\W]', String.Escape),
|
| 589 |
+
(r'(\b\w+)(\s*)(=)', bygroups(Name.Variable, Text, Operator)),
|
| 590 |
+
(r'[\[\]{}()=]+', Operator),
|
| 591 |
+
(r'<<\s*(\'?)\\?(\w+)[\w\W]+?\2', String),
|
| 592 |
+
(r';', Punctuation),
|
| 593 |
+
],
|
| 594 |
+
'data': [
|
| 595 |
+
(r'(?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double),
|
| 596 |
+
(r"(?s)'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
|
| 597 |
+
(r'\s+', Text),
|
| 598 |
+
(r'[^=\s\[\]{}()$"\'`\\;#]+', Text),
|
| 599 |
+
(r'\d+(?= |\Z)', Number),
|
| 600 |
+
(r'\$#?(\w+|.)', Name.Variable),
|
| 601 |
+
],
|
| 602 |
+
'curly': [
|
| 603 |
+
(r'\}', Keyword, '#pop'),
|
| 604 |
+
(r':-', Keyword),
|
| 605 |
+
(r'\w+', Name.Variable),
|
| 606 |
+
(r'[^}:"\'`$]+', Punctuation),
|
| 607 |
+
(r':', Punctuation),
|
| 608 |
+
include('root'),
|
| 609 |
+
],
|
| 610 |
+
'paren': [
|
| 611 |
+
(r'\)', Keyword, '#pop'),
|
| 612 |
+
include('root'),
|
| 613 |
+
],
|
| 614 |
+
'backticks': [
|
| 615 |
+
(r'`', String.Backtick, '#pop'),
|
| 616 |
+
include('root'),
|
| 617 |
+
],
|
| 618 |
+
}
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
class TcshSessionLexer(ShellSessionBaseLexer):
|
| 622 |
+
"""
|
| 623 |
+
Lexer for Tcsh sessions, i.e. command lines, including a
|
| 624 |
+
prompt, interspersed with output.
|
| 625 |
+
"""
|
| 626 |
+
|
| 627 |
+
name = 'Tcsh Session'
|
| 628 |
+
aliases = ['tcshcon']
|
| 629 |
+
filenames = []
|
| 630 |
+
mimetypes = []
|
| 631 |
+
url = 'https://www.tcsh.org'
|
| 632 |
+
version_added = '2.1'
|
| 633 |
+
_example = "tcshcon/session"
|
| 634 |
+
|
| 635 |
+
_innerLexerCls = TcshLexer
|
| 636 |
+
_ps1rgx = re.compile(r'^([^>]+>)(.*\n?)')
|
| 637 |
+
_ps2 = '? '
|
| 638 |
+
|
| 639 |
+
|
| 640 |
+
class PowerShellLexer(RegexLexer):
|
| 641 |
+
"""
|
| 642 |
+
For Windows PowerShell code.
|
| 643 |
+
"""
|
| 644 |
+
name = 'PowerShell'
|
| 645 |
+
aliases = ['powershell', 'pwsh', 'posh', 'ps1', 'psm1']
|
| 646 |
+
filenames = ['*.ps1', '*.psm1']
|
| 647 |
+
mimetypes = ['text/x-powershell']
|
| 648 |
+
url = 'https://learn.microsoft.com/en-us/powershell'
|
| 649 |
+
version_added = '1.5'
|
| 650 |
+
|
| 651 |
+
flags = re.DOTALL | re.IGNORECASE | re.MULTILINE
|
| 652 |
+
|
| 653 |
+
keywords = (
|
| 654 |
+
'while validateset validaterange validatepattern validatelength '
|
| 655 |
+
'validatecount until trap switch return ref process param parameter in '
|
| 656 |
+
'if global: local: function foreach for finally filter end elseif else '
|
| 657 |
+
'dynamicparam do default continue cmdletbinding break begin alias \\? '
|
| 658 |
+
'% #script #private #local #global mandatory parametersetname position '
|
| 659 |
+
'valuefrompipeline valuefrompipelinebypropertyname '
|
| 660 |
+
'valuefromremainingarguments helpmessage try catch throw').split()
|
| 661 |
+
|
| 662 |
+
operators = (
|
| 663 |
+
'and as band bnot bor bxor casesensitive ccontains ceq cge cgt cle '
|
| 664 |
+
'clike clt cmatch cne cnotcontains cnotlike cnotmatch contains '
|
| 665 |
+
'creplace eq exact f file ge gt icontains ieq ige igt ile ilike ilt '
|
| 666 |
+
'imatch ine inotcontains inotlike inotmatch ireplace is isnot le like '
|
| 667 |
+
'lt match ne not notcontains notlike notmatch or regex replace '
|
| 668 |
+
'wildcard').split()
|
| 669 |
+
|
| 670 |
+
verbs = (
|
| 671 |
+
'write where watch wait use update unregister unpublish unprotect '
|
| 672 |
+
'unlock uninstall undo unblock trace test tee take sync switch '
|
| 673 |
+
'suspend submit stop step start split sort skip show set send select '
|
| 674 |
+
'search scroll save revoke resume restore restart resolve resize '
|
| 675 |
+
'reset request repair rename remove register redo receive read push '
|
| 676 |
+
'publish protect pop ping out optimize open new move mount merge '
|
| 677 |
+
'measure lock limit join invoke install initialize import hide group '
|
| 678 |
+
'grant get format foreach find export expand exit enter enable edit '
|
| 679 |
+
'dismount disconnect disable deny debug cxnew copy convertto '
|
| 680 |
+
'convertfrom convert connect confirm compress complete compare close '
|
| 681 |
+
'clear checkpoint block backup assert approve aggregate add').split()
|
| 682 |
+
|
| 683 |
+
aliases_ = (
|
| 684 |
+
'ac asnp cat cd cfs chdir clc clear clhy cli clp cls clv cnsn '
|
| 685 |
+
'compare copy cp cpi cpp curl cvpa dbp del diff dir dnsn ebp echo epal '
|
| 686 |
+
'epcsv epsn erase etsn exsn fc fhx fl foreach ft fw gal gbp gc gci gcm '
|
| 687 |
+
'gcs gdr ghy gi gjb gl gm gmo gp gps gpv group gsn gsnp gsv gu gv gwmi '
|
| 688 |
+
'h history icm iex ihy ii ipal ipcsv ipmo ipsn irm ise iwmi iwr kill lp '
|
| 689 |
+
'ls man md measure mi mount move mp mv nal ndr ni nmo npssc nsn nv ogv '
|
| 690 |
+
'oh popd ps pushd pwd r rbp rcjb rcsn rd rdr ren ri rjb rm rmdir rmo '
|
| 691 |
+
'rni rnp rp rsn rsnp rujb rv rvpa rwmi sajb sal saps sasv sbp sc select '
|
| 692 |
+
'set shcm si sl sleep sls sort sp spjb spps spsv start sujb sv swmi tee '
|
| 693 |
+
'trcm type wget where wjb write').split()
|
| 694 |
+
|
| 695 |
+
commenthelp = (
|
| 696 |
+
'component description example externalhelp forwardhelpcategory '
|
| 697 |
+
'forwardhelptargetname functionality inputs link '
|
| 698 |
+
'notes outputs parameter remotehelprunspace role synopsis').split()
|
| 699 |
+
|
| 700 |
+
tokens = {
|
| 701 |
+
'root': [
|
| 702 |
+
# we need to count pairs of parentheses for correct highlight
|
| 703 |
+
# of '$(...)' blocks in strings
|
| 704 |
+
(r'\(', Punctuation, 'child'),
|
| 705 |
+
(r'\s+', Text),
|
| 706 |
+
(r'^(\s*#[#\s]*)(\.(?:{}))([^\n]*$)'.format('|'.join(commenthelp)),
|
| 707 |
+
bygroups(Comment, String.Doc, Comment)),
|
| 708 |
+
(r'#[^\n]*?$', Comment),
|
| 709 |
+
(r'(<|<)#', Comment.Multiline, 'multline'),
|
| 710 |
+
(r'@"\n', String.Heredoc, 'heredoc-double'),
|
| 711 |
+
(r"@'\n.*?\n'@", String.Heredoc),
|
| 712 |
+
# escaped syntax
|
| 713 |
+
(r'`[\'"$@-]', Punctuation),
|
| 714 |
+
(r'"', String.Double, 'string'),
|
| 715 |
+
(r"'([^']|'')*'", String.Single),
|
| 716 |
+
(r'(\$|@@|@)((global|script|private|env):)?\w+',
|
| 717 |
+
Name.Variable),
|
| 718 |
+
(r'({})\b'.format('|'.join(keywords)), Keyword),
|
| 719 |
+
(r'-({})\b'.format('|'.join(operators)), Operator),
|
| 720 |
+
(r'({})-[a-z_]\w*\b'.format('|'.join(verbs)), Name.Builtin),
|
| 721 |
+
(r'({})\s'.format('|'.join(aliases_)), Name.Builtin),
|
| 722 |
+
(r'\[[a-z_\[][\w. `,\[\]]*\]', Name.Constant), # .net [type]s
|
| 723 |
+
(r'-[a-z_]\w*', Name),
|
| 724 |
+
(r'\w+', Name),
|
| 725 |
+
(r'[.,;:@{}\[\]$()=+*/\\&%!~?^`|<>-]', Punctuation),
|
| 726 |
+
],
|
| 727 |
+
'child': [
|
| 728 |
+
(r'\)', Punctuation, '#pop'),
|
| 729 |
+
include('root'),
|
| 730 |
+
],
|
| 731 |
+
'multline': [
|
| 732 |
+
(r'[^#&.]+', Comment.Multiline),
|
| 733 |
+
(r'#(>|>)', Comment.Multiline, '#pop'),
|
| 734 |
+
(r'\.({})'.format('|'.join(commenthelp)), String.Doc),
|
| 735 |
+
(r'[#&.]', Comment.Multiline),
|
| 736 |
+
],
|
| 737 |
+
'string': [
|
| 738 |
+
(r"`[0abfnrtv'\"$`]", String.Escape),
|
| 739 |
+
(r'[^$`"]+', String.Double),
|
| 740 |
+
(r'\$\(', Punctuation, 'child'),
|
| 741 |
+
(r'""', String.Double),
|
| 742 |
+
(r'[`$]', String.Double),
|
| 743 |
+
(r'"', String.Double, '#pop'),
|
| 744 |
+
],
|
| 745 |
+
'heredoc-double': [
|
| 746 |
+
(r'\n"@', String.Heredoc, '#pop'),
|
| 747 |
+
(r'\$\(', Punctuation, 'child'),
|
| 748 |
+
(r'[^@\n]+"]', String.Heredoc),
|
| 749 |
+
(r".", String.Heredoc),
|
| 750 |
+
]
|
| 751 |
+
}
|
| 752 |
+
|
| 753 |
+
|
| 754 |
+
class PowerShellSessionLexer(ShellSessionBaseLexer):
|
| 755 |
+
"""
|
| 756 |
+
Lexer for PowerShell sessions, i.e. command lines, including a
|
| 757 |
+
prompt, interspersed with output.
|
| 758 |
+
"""
|
| 759 |
+
|
| 760 |
+
name = 'PowerShell Session'
|
| 761 |
+
aliases = ['pwsh-session', 'ps1con']
|
| 762 |
+
filenames = []
|
| 763 |
+
mimetypes = []
|
| 764 |
+
url = 'https://learn.microsoft.com/en-us/powershell'
|
| 765 |
+
version_added = '2.1'
|
| 766 |
+
_example = "pwsh-session/session"
|
| 767 |
+
|
| 768 |
+
_innerLexerCls = PowerShellLexer
|
| 769 |
+
_bare_continuation = True
|
| 770 |
+
_ps1rgx = re.compile(r'^((?:\[[^]]+\]: )?PS[^>]*> ?)(.*\n?)')
|
| 771 |
+
_ps2 = '> '
|
| 772 |
+
|
| 773 |
+
|
| 774 |
+
class FishShellLexer(RegexLexer):
|
| 775 |
+
"""
|
| 776 |
+
Lexer for Fish shell scripts.
|
| 777 |
+
"""
|
| 778 |
+
|
| 779 |
+
name = 'Fish'
|
| 780 |
+
aliases = ['fish', 'fishshell']
|
| 781 |
+
filenames = ['*.fish', '*.load']
|
| 782 |
+
mimetypes = ['application/x-fish']
|
| 783 |
+
url = 'https://fishshell.com'
|
| 784 |
+
version_added = '2.1'
|
| 785 |
+
|
| 786 |
+
tokens = {
|
| 787 |
+
'root': [
|
| 788 |
+
include('basic'),
|
| 789 |
+
include('data'),
|
| 790 |
+
include('interp'),
|
| 791 |
+
],
|
| 792 |
+
'interp': [
|
| 793 |
+
(r'\$\(\(', Keyword, 'math'),
|
| 794 |
+
(r'\(', Keyword, 'paren'),
|
| 795 |
+
(r'\$#?(\w+|.)', Name.Variable),
|
| 796 |
+
],
|
| 797 |
+
'basic': [
|
| 798 |
+
(r'\b(begin|end|if|else|while|break|for|in|return|function|block|'
|
| 799 |
+
r'case|continue|switch|not|and|or|set|echo|exit|pwd|true|false|'
|
| 800 |
+
r'cd|count|test)(\s*)\b',
|
| 801 |
+
bygroups(Keyword, Text)),
|
| 802 |
+
(r'\b(alias|bg|bind|breakpoint|builtin|command|commandline|'
|
| 803 |
+
r'complete|contains|dirh|dirs|emit|eval|exec|fg|fish|fish_config|'
|
| 804 |
+
r'fish_indent|fish_pager|fish_prompt|fish_right_prompt|'
|
| 805 |
+
r'fish_update_completions|fishd|funced|funcsave|functions|help|'
|
| 806 |
+
r'history|isatty|jobs|math|mimedb|nextd|open|popd|prevd|psub|'
|
| 807 |
+
r'pushd|random|read|set_color|source|status|trap|type|ulimit|'
|
| 808 |
+
r'umask|vared|fc|getopts|hash|kill|printf|time|wait)\s*\b(?!\.)',
|
| 809 |
+
Name.Builtin),
|
| 810 |
+
(r'#.*\n', Comment),
|
| 811 |
+
(r'\\[\w\W]', String.Escape),
|
| 812 |
+
(r'(\b\w+)(\s*)(=)', bygroups(Name.Variable, Whitespace, Operator)),
|
| 813 |
+
(r'[\[\]()=]', Operator),
|
| 814 |
+
(r'<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2', String),
|
| 815 |
+
],
|
| 816 |
+
'data': [
|
| 817 |
+
(r'(?s)\$?"(\\\\|\\[0-7]+|\\.|[^"\\$])*"', String.Double),
|
| 818 |
+
(r'"', String.Double, 'string'),
|
| 819 |
+
(r"(?s)\$'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
|
| 820 |
+
(r"(?s)'.*?'", String.Single),
|
| 821 |
+
(r';', Punctuation),
|
| 822 |
+
(r'&|\||\^|<|>', Operator),
|
| 823 |
+
(r'\s+', Text),
|
| 824 |
+
(r'\d+(?= |\Z)', Number),
|
| 825 |
+
(r'[^=\s\[\]{}()$"\'`\\<&|;]+', Text),
|
| 826 |
+
],
|
| 827 |
+
'string': [
|
| 828 |
+
(r'"', String.Double, '#pop'),
|
| 829 |
+
(r'(?s)(\\\\|\\[0-7]+|\\.|[^"\\$])+', String.Double),
|
| 830 |
+
include('interp'),
|
| 831 |
+
],
|
| 832 |
+
'paren': [
|
| 833 |
+
(r'\)', Keyword, '#pop'),
|
| 834 |
+
include('root'),
|
| 835 |
+
],
|
| 836 |
+
'math': [
|
| 837 |
+
(r'\)\)', Keyword, '#pop'),
|
| 838 |
+
(r'[-+*/%^|&]|\*\*|\|\|', Operator),
|
| 839 |
+
(r'\d+#\d+', Number),
|
| 840 |
+
(r'\d+#(?! )', Number),
|
| 841 |
+
(r'\d+', Number),
|
| 842 |
+
include('root'),
|
| 843 |
+
],
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
class ExeclineLexer(RegexLexer):
|
| 847 |
+
"""
|
| 848 |
+
Lexer for Laurent Bercot's execline language.
|
| 849 |
+
"""
|
| 850 |
+
|
| 851 |
+
name = 'execline'
|
| 852 |
+
aliases = ['execline']
|
| 853 |
+
filenames = ['*.exec']
|
| 854 |
+
url = 'https://skarnet.org/software/execline'
|
| 855 |
+
version_added = '2.7'
|
| 856 |
+
|
| 857 |
+
tokens = {
|
| 858 |
+
'root': [
|
| 859 |
+
include('basic'),
|
| 860 |
+
include('data'),
|
| 861 |
+
include('interp')
|
| 862 |
+
],
|
| 863 |
+
'interp': [
|
| 864 |
+
(r'\$\{', String.Interpol, 'curly'),
|
| 865 |
+
(r'\$[\w@#]+', Name.Variable), # user variable
|
| 866 |
+
(r'\$', Text),
|
| 867 |
+
],
|
| 868 |
+
'basic': [
|
| 869 |
+
(r'\b(background|backtick|cd|define|dollarat|elgetopt|'
|
| 870 |
+
r'elgetpositionals|elglob|emptyenv|envfile|exec|execlineb|'
|
| 871 |
+
r'exit|export|fdblock|fdclose|fdmove|fdreserve|fdswap|'
|
| 872 |
+
r'forbacktickx|foreground|forstdin|forx|getcwd|getpid|heredoc|'
|
| 873 |
+
r'homeof|if|ifelse|ifte|ifthenelse|importas|loopwhilex|'
|
| 874 |
+
r'multidefine|multisubstitute|pipeline|piperw|posix-cd|'
|
| 875 |
+
r'redirfd|runblock|shift|trap|tryexec|umask|unexport|wait|'
|
| 876 |
+
r'withstdinas)\b', Name.Builtin),
|
| 877 |
+
(r'\A#!.+\n', Comment.Hashbang),
|
| 878 |
+
(r'#.*\n', Comment.Single),
|
| 879 |
+
(r'[{}]', Operator)
|
| 880 |
+
],
|
| 881 |
+
'data': [
|
| 882 |
+
(r'(?s)"(\\.|[^"\\$])*"', String.Double),
|
| 883 |
+
(r'"', String.Double, 'string'),
|
| 884 |
+
(r'\s+', Text),
|
| 885 |
+
(r'[^\s{}$"\\]+', Text)
|
| 886 |
+
],
|
| 887 |
+
'string': [
|
| 888 |
+
(r'"', String.Double, '#pop'),
|
| 889 |
+
(r'(?s)(\\\\|\\.|[^"\\$])+', String.Double),
|
| 890 |
+
include('interp'),
|
| 891 |
+
],
|
| 892 |
+
'curly': [
|
| 893 |
+
(r'\}', String.Interpol, '#pop'),
|
| 894 |
+
(r'[\w#@]+', Name.Variable),
|
| 895 |
+
include('root')
|
| 896 |
+
]
|
| 897 |
+
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
def analyse_text(text):
|
| 901 |
+
if shebang_matches(text, r'execlineb'):
|
| 902 |
+
return 1
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/smalltalk.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.smalltalk
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexers for Smalltalk and related languages.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from pygments.lexer import RegexLexer, include, bygroups, default
|
| 12 |
+
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
|
| 13 |
+
Number, Punctuation
|
| 14 |
+
|
| 15 |
+
__all__ = ['SmalltalkLexer', 'NewspeakLexer']
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class SmalltalkLexer(RegexLexer):
|
| 19 |
+
"""
|
| 20 |
+
For Smalltalk syntax.
|
| 21 |
+
Contributed by Stefan Matthias Aust.
|
| 22 |
+
Rewritten by Nils Winter.
|
| 23 |
+
"""
|
| 24 |
+
name = 'Smalltalk'
|
| 25 |
+
url = 'http://www.smalltalk.org/'
|
| 26 |
+
filenames = ['*.st']
|
| 27 |
+
aliases = ['smalltalk', 'squeak', 'st']
|
| 28 |
+
mimetypes = ['text/x-smalltalk']
|
| 29 |
+
version_added = '0.10'
|
| 30 |
+
|
| 31 |
+
tokens = {
|
| 32 |
+
'root': [
|
| 33 |
+
(r'(<)(\w+:)(.*?)(>)', bygroups(Text, Keyword, Text, Text)),
|
| 34 |
+
include('squeak fileout'),
|
| 35 |
+
include('whitespaces'),
|
| 36 |
+
include('method definition'),
|
| 37 |
+
(r'(\|)([\w\s]*)(\|)', bygroups(Operator, Name.Variable, Operator)),
|
| 38 |
+
include('objects'),
|
| 39 |
+
(r'\^|\:=|\_', Operator),
|
| 40 |
+
# temporaries
|
| 41 |
+
(r'[\]({}.;!]', Text),
|
| 42 |
+
],
|
| 43 |
+
'method definition': [
|
| 44 |
+
# Not perfect can't allow whitespaces at the beginning and the
|
| 45 |
+
# without breaking everything
|
| 46 |
+
(r'([a-zA-Z]+\w*:)(\s*)(\w+)',
|
| 47 |
+
bygroups(Name.Function, Text, Name.Variable)),
|
| 48 |
+
(r'^(\b[a-zA-Z]+\w*\b)(\s*)$', bygroups(Name.Function, Text)),
|
| 49 |
+
(r'^([-+*/\\~<>=|&!?,@%]+)(\s*)(\w+)(\s*)$',
|
| 50 |
+
bygroups(Name.Function, Text, Name.Variable, Text)),
|
| 51 |
+
],
|
| 52 |
+
'blockvariables': [
|
| 53 |
+
include('whitespaces'),
|
| 54 |
+
(r'(:)(\s*)(\w+)',
|
| 55 |
+
bygroups(Operator, Text, Name.Variable)),
|
| 56 |
+
(r'\|', Operator, '#pop'),
|
| 57 |
+
default('#pop'), # else pop
|
| 58 |
+
],
|
| 59 |
+
'literals': [
|
| 60 |
+
(r"'(''|[^'])*'", String, 'afterobject'),
|
| 61 |
+
(r'\$.', String.Char, 'afterobject'),
|
| 62 |
+
(r'#\(', String.Symbol, 'parenth'),
|
| 63 |
+
(r'\)', Text, 'afterobject'),
|
| 64 |
+
(r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number, 'afterobject'),
|
| 65 |
+
],
|
| 66 |
+
'_parenth_helper': [
|
| 67 |
+
include('whitespaces'),
|
| 68 |
+
(r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number),
|
| 69 |
+
(r'[-+*/\\~<>=|&#!?,@%\w:]+', String.Symbol),
|
| 70 |
+
# literals
|
| 71 |
+
(r"'(''|[^'])*'", String),
|
| 72 |
+
(r'\$.', String.Char),
|
| 73 |
+
(r'#*\(', String.Symbol, 'inner_parenth'),
|
| 74 |
+
],
|
| 75 |
+
'parenth': [
|
| 76 |
+
# This state is a bit tricky since
|
| 77 |
+
# we can't just pop this state
|
| 78 |
+
(r'\)', String.Symbol, ('root', 'afterobject')),
|
| 79 |
+
include('_parenth_helper'),
|
| 80 |
+
],
|
| 81 |
+
'inner_parenth': [
|
| 82 |
+
(r'\)', String.Symbol, '#pop'),
|
| 83 |
+
include('_parenth_helper'),
|
| 84 |
+
],
|
| 85 |
+
'whitespaces': [
|
| 86 |
+
# skip whitespace and comments
|
| 87 |
+
(r'\s+', Text),
|
| 88 |
+
(r'"(""|[^"])*"', Comment),
|
| 89 |
+
],
|
| 90 |
+
'objects': [
|
| 91 |
+
(r'\[', Text, 'blockvariables'),
|
| 92 |
+
(r'\]', Text, 'afterobject'),
|
| 93 |
+
(r'\b(self|super|true|false|nil|thisContext)\b',
|
| 94 |
+
Name.Builtin.Pseudo, 'afterobject'),
|
| 95 |
+
(r'\b[A-Z]\w*(?!:)\b', Name.Class, 'afterobject'),
|
| 96 |
+
(r'\b[a-z]\w*(?!:)\b', Name.Variable, 'afterobject'),
|
| 97 |
+
(r'#("(""|[^"])*"|[-+*/\\~<>=|&!?,@%]+|[\w:]+)',
|
| 98 |
+
String.Symbol, 'afterobject'),
|
| 99 |
+
include('literals'),
|
| 100 |
+
],
|
| 101 |
+
'afterobject': [
|
| 102 |
+
(r'! !$', Keyword, '#pop'), # squeak chunk delimiter
|
| 103 |
+
include('whitespaces'),
|
| 104 |
+
(r'\b(ifTrue:|ifFalse:|whileTrue:|whileFalse:|timesRepeat:)',
|
| 105 |
+
Name.Builtin, '#pop'),
|
| 106 |
+
(r'\b(new\b(?!:))', Name.Builtin),
|
| 107 |
+
(r'\:=|\_', Operator, '#pop'),
|
| 108 |
+
(r'\b[a-zA-Z]+\w*:', Name.Function, '#pop'),
|
| 109 |
+
(r'\b[a-zA-Z]+\w*', Name.Function),
|
| 110 |
+
(r'\w+:?|[-+*/\\~<>=|&!?,@%]+', Name.Function, '#pop'),
|
| 111 |
+
(r'\.', Punctuation, '#pop'),
|
| 112 |
+
(r';', Punctuation),
|
| 113 |
+
(r'[\])}]', Text),
|
| 114 |
+
(r'[\[({]', Text, '#pop'),
|
| 115 |
+
],
|
| 116 |
+
'squeak fileout': [
|
| 117 |
+
# Squeak fileout format (optional)
|
| 118 |
+
(r'^"(""|[^"])*"!', Keyword),
|
| 119 |
+
(r"^'(''|[^'])*'!", Keyword),
|
| 120 |
+
(r'^(!)(\w+)( commentStamp: )(.*?)( prior: .*?!\n)(.*?)(!)',
|
| 121 |
+
bygroups(Keyword, Name.Class, Keyword, String, Keyword, Text, Keyword)),
|
| 122 |
+
(r"^(!)(\w+(?: class)?)( methodsFor: )('(?:''|[^'])*')(.*?!)",
|
| 123 |
+
bygroups(Keyword, Name.Class, Keyword, String, Keyword)),
|
| 124 |
+
(r'^(\w+)( subclass: )(#\w+)'
|
| 125 |
+
r'(\s+instanceVariableNames: )(.*?)'
|
| 126 |
+
r'(\s+classVariableNames: )(.*?)'
|
| 127 |
+
r'(\s+poolDictionaries: )(.*?)'
|
| 128 |
+
r'(\s+category: )(.*?)(!)',
|
| 129 |
+
bygroups(Name.Class, Keyword, String.Symbol, Keyword, String, Keyword,
|
| 130 |
+
String, Keyword, String, Keyword, String, Keyword)),
|
| 131 |
+
(r'^(\w+(?: class)?)(\s+instanceVariableNames: )(.*?)(!)',
|
| 132 |
+
bygroups(Name.Class, Keyword, String, Keyword)),
|
| 133 |
+
(r'(!\n)(\].*)(! !)$', bygroups(Keyword, Text, Keyword)),
|
| 134 |
+
(r'! !$', Keyword),
|
| 135 |
+
],
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
class NewspeakLexer(RegexLexer):
|
| 140 |
+
"""
|
| 141 |
+
For Newspeak syntax.
|
| 142 |
+
"""
|
| 143 |
+
name = 'Newspeak'
|
| 144 |
+
url = 'http://newspeaklanguage.org/'
|
| 145 |
+
filenames = ['*.ns2']
|
| 146 |
+
aliases = ['newspeak', ]
|
| 147 |
+
mimetypes = ['text/x-newspeak']
|
| 148 |
+
version_added = '1.1'
|
| 149 |
+
|
| 150 |
+
tokens = {
|
| 151 |
+
'root': [
|
| 152 |
+
(r'\b(Newsqueak2)\b', Keyword.Declaration),
|
| 153 |
+
(r"'[^']*'", String),
|
| 154 |
+
(r'\b(class)(\s+)(\w+)(\s*)',
|
| 155 |
+
bygroups(Keyword.Declaration, Text, Name.Class, Text)),
|
| 156 |
+
(r'\b(mixin|self|super|private|public|protected|nil|true|false)\b',
|
| 157 |
+
Keyword),
|
| 158 |
+
(r'(\w+\:)(\s*)([a-zA-Z_]\w+)',
|
| 159 |
+
bygroups(Name.Function, Text, Name.Variable)),
|
| 160 |
+
(r'(\w+)(\s*)(=)',
|
| 161 |
+
bygroups(Name.Attribute, Text, Operator)),
|
| 162 |
+
(r'<\w+>', Comment.Special),
|
| 163 |
+
include('expressionstat'),
|
| 164 |
+
include('whitespace')
|
| 165 |
+
],
|
| 166 |
+
|
| 167 |
+
'expressionstat': [
|
| 168 |
+
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
|
| 169 |
+
(r'\d+', Number.Integer),
|
| 170 |
+
(r':\w+', Name.Variable),
|
| 171 |
+
(r'(\w+)(::)', bygroups(Name.Variable, Operator)),
|
| 172 |
+
(r'\w+:', Name.Function),
|
| 173 |
+
(r'\w+', Name.Variable),
|
| 174 |
+
(r'\(|\)', Punctuation),
|
| 175 |
+
(r'\[|\]', Punctuation),
|
| 176 |
+
(r'\{|\}', Punctuation),
|
| 177 |
+
|
| 178 |
+
(r'(\^|\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-|:)', Operator),
|
| 179 |
+
(r'\.|;', Punctuation),
|
| 180 |
+
include('whitespace'),
|
| 181 |
+
include('literals'),
|
| 182 |
+
],
|
| 183 |
+
'literals': [
|
| 184 |
+
(r'\$.', String),
|
| 185 |
+
(r"'[^']*'", String),
|
| 186 |
+
(r"#'[^']*'", String.Symbol),
|
| 187 |
+
(r"#\w+:?", String.Symbol),
|
| 188 |
+
(r"#(\+|\/|~|\*|<|>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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.sql
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexers for various SQL dialects and related interactive sessions.
|
| 6 |
+
|
| 7 |
+
Postgres specific lexers:
|
| 8 |
+
|
| 9 |
+
`PostgresLexer`
|
| 10 |
+
A SQL lexer for the PostgreSQL dialect. Differences w.r.t. the SQL
|
| 11 |
+
lexer are:
|
| 12 |
+
|
| 13 |
+
- keywords and data types list parsed from the PG docs (run the
|
| 14 |
+
`_postgres_builtins` module to update them);
|
| 15 |
+
- Content of $-strings parsed using a specific lexer, e.g. the content
|
| 16 |
+
of a PL/Python function is parsed using the Python lexer;
|
| 17 |
+
- parse PG specific constructs: E-strings, $-strings, U&-strings,
|
| 18 |
+
different operators and punctuation.
|
| 19 |
+
|
| 20 |
+
`PlPgsqlLexer`
|
| 21 |
+
A lexer for the PL/pgSQL language. Adds a few specific construct on
|
| 22 |
+
top of the PG SQL lexer (such as <<label>>).
|
| 23 |
+
|
| 24 |
+
`PostgresConsoleLexer`
|
| 25 |
+
A lexer to highlight an interactive psql session:
|
| 26 |
+
|
| 27 |
+
- identifies the prompt and does its best to detect the end of command
|
| 28 |
+
in multiline statement where not all the lines are prefixed by a
|
| 29 |
+
prompt, telling them apart from the output;
|
| 30 |
+
- highlights errors in the output and notification levels;
|
| 31 |
+
- handles psql backslash commands.
|
| 32 |
+
|
| 33 |
+
`PostgresExplainLexer`
|
| 34 |
+
A lexer to highlight Postgres execution plan.
|
| 35 |
+
|
| 36 |
+
The ``tests/examplefiles`` contains a few test files with data to be
|
| 37 |
+
parsed by these lexers.
|
| 38 |
+
|
| 39 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 40 |
+
:license: BSD, see LICENSE for details.
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
import collections
|
| 44 |
+
import re
|
| 45 |
+
|
| 46 |
+
from pygments.lexer import Lexer, RegexLexer, do_insertions, bygroups, words
|
| 47 |
+
from pygments.lexers import _googlesql_builtins
|
| 48 |
+
from pygments.lexers import _mysql_builtins
|
| 49 |
+
from pygments.lexers import _postgres_builtins
|
| 50 |
+
from pygments.lexers import _sql_builtins
|
| 51 |
+
from pygments.lexers import _tsql_builtins
|
| 52 |
+
from pygments.lexers import get_lexer_by_name, ClassNotFound
|
| 53 |
+
from pygments.token import Punctuation, Whitespace, Text, Comment, Operator, \
|
| 54 |
+
Keyword, Name, String, Number, Generic, Literal
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
__all__ = ['GoogleSqlLexer', 'PostgresLexer', 'PlPgsqlLexer',
|
| 58 |
+
'PostgresConsoleLexer', 'PostgresExplainLexer', 'SqlLexer',
|
| 59 |
+
'TransactSqlLexer', 'MySqlLexer', 'SqliteConsoleLexer', 'RqlLexer']
|
| 60 |
+
|
| 61 |
+
line_re = re.compile('.*?\n')
|
| 62 |
+
sqlite_prompt_re = re.compile(r'^(?:sqlite| ...)>(?= )')
|
| 63 |
+
|
| 64 |
+
language_re = re.compile(r"\s+LANGUAGE\s+'?(\w+)'?", re.IGNORECASE)
|
| 65 |
+
|
| 66 |
+
do_re = re.compile(r'\bDO\b', re.IGNORECASE)
|
| 67 |
+
|
| 68 |
+
# Regular expressions for analyse_text()
|
| 69 |
+
name_between_bracket_re = re.compile(r'\[[a-zA-Z_]\w*\]')
|
| 70 |
+
name_between_backtick_re = re.compile(r'`[a-zA-Z_]\w*`')
|
| 71 |
+
tsql_go_re = re.compile(r'\bgo\b', re.IGNORECASE)
|
| 72 |
+
tsql_declare_re = re.compile(r'\bdeclare\s+@', re.IGNORECASE)
|
| 73 |
+
tsql_variable_re = re.compile(r'@[a-zA-Z_]\w*\b')
|
| 74 |
+
|
| 75 |
+
# Identifiers for analyse_text()
|
| 76 |
+
googlesql_identifiers = (
|
| 77 |
+
_googlesql_builtins.functionnames
|
| 78 |
+
+ _googlesql_builtins.keywords
|
| 79 |
+
+ _googlesql_builtins.types)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def language_callback(lexer, match):
|
| 83 |
+
"""Parse the content of a $-string using a lexer
|
| 84 |
+
|
| 85 |
+
The lexer is chosen looking for a nearby LANGUAGE or assumed as
|
| 86 |
+
plpgsql if inside a DO statement and no LANGUAGE has been found.
|
| 87 |
+
"""
|
| 88 |
+
lx = None
|
| 89 |
+
m = language_re.match(lexer.text[match.end():match.end()+100])
|
| 90 |
+
if m is not None:
|
| 91 |
+
lx = lexer._get_lexer(m.group(1))
|
| 92 |
+
else:
|
| 93 |
+
m = list(language_re.finditer(
|
| 94 |
+
lexer.text[max(0, match.start()-100):match.start()]))
|
| 95 |
+
if m:
|
| 96 |
+
lx = lexer._get_lexer(m[-1].group(1))
|
| 97 |
+
else:
|
| 98 |
+
m = list(do_re.finditer(
|
| 99 |
+
lexer.text[max(0, match.start()-25):match.start()]))
|
| 100 |
+
if m:
|
| 101 |
+
lx = lexer._get_lexer('plpgsql')
|
| 102 |
+
|
| 103 |
+
# 1 = $, 2 = delimiter, 3 = $
|
| 104 |
+
yield (match.start(1), String, match.group(1))
|
| 105 |
+
yield (match.start(2), String.Delimiter, match.group(2))
|
| 106 |
+
yield (match.start(3), String, match.group(3))
|
| 107 |
+
# 4 = string contents
|
| 108 |
+
if lx:
|
| 109 |
+
yield from lx.get_tokens_unprocessed(match.group(4))
|
| 110 |
+
else:
|
| 111 |
+
yield (match.start(4), String, match.group(4))
|
| 112 |
+
# 5 = $, 6 = delimiter, 7 = $
|
| 113 |
+
yield (match.start(5), String, match.group(5))
|
| 114 |
+
yield (match.start(6), String.Delimiter, match.group(6))
|
| 115 |
+
yield (match.start(7), String, match.group(7))
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
class PostgresBase:
|
| 119 |
+
"""Base class for Postgres-related lexers.
|
| 120 |
+
|
| 121 |
+
This is implemented as a mixin to avoid the Lexer metaclass kicking in.
|
| 122 |
+
this way the different lexer don't have a common Lexer ancestor. If they
|
| 123 |
+
had, _tokens could be created on this ancestor and not updated for the
|
| 124 |
+
other classes, resulting e.g. in PL/pgSQL parsed as SQL. This shortcoming
|
| 125 |
+
seem to suggest that regexp lexers are not really subclassable.
|
| 126 |
+
"""
|
| 127 |
+
def get_tokens_unprocessed(self, text, *args):
|
| 128 |
+
# Have a copy of the entire text to be used by `language_callback`.
|
| 129 |
+
self.text = text
|
| 130 |
+
yield from super().get_tokens_unprocessed(text, *args)
|
| 131 |
+
|
| 132 |
+
def _get_lexer(self, lang):
|
| 133 |
+
if lang.lower() == 'sql':
|
| 134 |
+
return get_lexer_by_name('postgresql', **self.options)
|
| 135 |
+
|
| 136 |
+
tries = [lang]
|
| 137 |
+
if lang.startswith('pl'):
|
| 138 |
+
tries.append(lang[2:])
|
| 139 |
+
if lang.endswith('u'):
|
| 140 |
+
tries.append(lang[:-1])
|
| 141 |
+
if lang.startswith('pl') and lang.endswith('u'):
|
| 142 |
+
tries.append(lang[2:-1])
|
| 143 |
+
|
| 144 |
+
for lx in tries:
|
| 145 |
+
try:
|
| 146 |
+
return get_lexer_by_name(lx, **self.options)
|
| 147 |
+
except ClassNotFound:
|
| 148 |
+
pass
|
| 149 |
+
else:
|
| 150 |
+
# TODO: better logging
|
| 151 |
+
# print >>sys.stderr, "language not found:", lang
|
| 152 |
+
return None
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
class PostgresLexer(PostgresBase, RegexLexer):
|
| 156 |
+
"""
|
| 157 |
+
Lexer for the PostgreSQL dialect of SQL.
|
| 158 |
+
"""
|
| 159 |
+
|
| 160 |
+
name = 'PostgreSQL SQL dialect'
|
| 161 |
+
aliases = ['postgresql', 'postgres']
|
| 162 |
+
mimetypes = ['text/x-postgresql']
|
| 163 |
+
url = 'https://www.postgresql.org'
|
| 164 |
+
version_added = '1.5'
|
| 165 |
+
|
| 166 |
+
flags = re.IGNORECASE
|
| 167 |
+
tokens = {
|
| 168 |
+
'root': [
|
| 169 |
+
(r'\s+', Whitespace),
|
| 170 |
+
(r'--.*\n?', Comment.Single),
|
| 171 |
+
(r'/\*', Comment.Multiline, 'multiline-comments'),
|
| 172 |
+
(r'(' + '|'.join(s.replace(" ", r"\s+")
|
| 173 |
+
for s in _postgres_builtins.DATATYPES +
|
| 174 |
+
_postgres_builtins.PSEUDO_TYPES) + r')\b',
|
| 175 |
+
Name.Builtin),
|
| 176 |
+
(words(_postgres_builtins.KEYWORDS, suffix=r'\b'), Keyword),
|
| 177 |
+
(r'[+*/<>=~!@#%^&|`?-]+', Operator),
|
| 178 |
+
(r'::', Operator), # cast
|
| 179 |
+
(r'\$\d+', Name.Variable),
|
| 180 |
+
(r'([0-9]*\.[0-9]*|[0-9]+)(e[+-]?[0-9]+)?', Number.Float),
|
| 181 |
+
(r'[0-9]+', Number.Integer),
|
| 182 |
+
(r"((?:E|U&)?)(')", bygroups(String.Affix, String.Single), 'string'),
|
| 183 |
+
# quoted identifier
|
| 184 |
+
(r'((?:U&)?)(")', bygroups(String.Affix, String.Name), 'quoted-ident'),
|
| 185 |
+
(r'(?s)(\$)([^$]*)(\$)(.*?)(\$)(\2)(\$)', language_callback),
|
| 186 |
+
(r'[a-z_]\w*', Name),
|
| 187 |
+
|
| 188 |
+
# psql variable in SQL
|
| 189 |
+
(r""":(['"]?)[a-z]\w*\b\1""", Name.Variable),
|
| 190 |
+
|
| 191 |
+
(r'[;:()\[\]{},.]', Punctuation),
|
| 192 |
+
],
|
| 193 |
+
'multiline-comments': [
|
| 194 |
+
(r'/\*', Comment.Multiline, 'multiline-comments'),
|
| 195 |
+
(r'\*/', Comment.Multiline, '#pop'),
|
| 196 |
+
(r'[^/*]+', Comment.Multiline),
|
| 197 |
+
(r'[/*]', Comment.Multiline)
|
| 198 |
+
],
|
| 199 |
+
'string': [
|
| 200 |
+
(r"[^']+", String.Single),
|
| 201 |
+
(r"''", String.Single),
|
| 202 |
+
(r"'", String.Single, '#pop'),
|
| 203 |
+
],
|
| 204 |
+
'quoted-ident': [
|
| 205 |
+
(r'[^"]+', String.Name),
|
| 206 |
+
(r'""', String.Name),
|
| 207 |
+
(r'"', String.Name, '#pop'),
|
| 208 |
+
],
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class PlPgsqlLexer(PostgresBase, RegexLexer):
|
| 213 |
+
"""
|
| 214 |
+
Handle the extra syntax in Pl/pgSQL language.
|
| 215 |
+
"""
|
| 216 |
+
name = 'PL/pgSQL'
|
| 217 |
+
aliases = ['plpgsql']
|
| 218 |
+
mimetypes = ['text/x-plpgsql']
|
| 219 |
+
url = 'https://www.postgresql.org/docs/current/plpgsql.html'
|
| 220 |
+
version_added = '1.5'
|
| 221 |
+
|
| 222 |
+
flags = re.IGNORECASE
|
| 223 |
+
# FIXME: use inheritance
|
| 224 |
+
tokens = {name: state[:] for (name, state) in PostgresLexer.tokens.items()}
|
| 225 |
+
|
| 226 |
+
# extend the keywords list
|
| 227 |
+
for i, pattern in enumerate(tokens['root']):
|
| 228 |
+
if pattern[1] == Keyword:
|
| 229 |
+
tokens['root'][i] = (
|
| 230 |
+
words(_postgres_builtins.KEYWORDS +
|
| 231 |
+
_postgres_builtins.PLPGSQL_KEYWORDS, suffix=r'\b'),
|
| 232 |
+
Keyword)
|
| 233 |
+
del i
|
| 234 |
+
break
|
| 235 |
+
else:
|
| 236 |
+
assert 0, "SQL keywords not found"
|
| 237 |
+
|
| 238 |
+
# Add specific PL/pgSQL rules (before the SQL ones)
|
| 239 |
+
tokens['root'][:0] = [
|
| 240 |
+
(r'\%[a-z]\w*\b', Name.Builtin), # actually, a datatype
|
| 241 |
+
(r':=', Operator),
|
| 242 |
+
(r'\<\<[a-z]\w*\>\>', Name.Label),
|
| 243 |
+
(r'\#[a-z]\w*\b', Keyword.Pseudo), # #variable_conflict
|
| 244 |
+
]
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
class PsqlRegexLexer(PostgresBase, RegexLexer):
|
| 248 |
+
"""
|
| 249 |
+
Extend the PostgresLexer adding support specific for psql commands.
|
| 250 |
+
|
| 251 |
+
This is not a complete psql lexer yet as it lacks prompt support
|
| 252 |
+
and output rendering.
|
| 253 |
+
"""
|
| 254 |
+
|
| 255 |
+
name = 'PostgreSQL console - regexp based lexer'
|
| 256 |
+
aliases = [] # not public
|
| 257 |
+
|
| 258 |
+
flags = re.IGNORECASE
|
| 259 |
+
tokens = {name: state[:] for (name, state) in PostgresLexer.tokens.items()}
|
| 260 |
+
|
| 261 |
+
tokens['root'].append(
|
| 262 |
+
(r'\\[^\s]+', Keyword.Pseudo, 'psql-command'))
|
| 263 |
+
tokens['psql-command'] = [
|
| 264 |
+
(r'\n', Text, 'root'),
|
| 265 |
+
(r'\s+', Whitespace),
|
| 266 |
+
(r'\\[^\s]+', Keyword.Pseudo),
|
| 267 |
+
(r""":(['"]?)[a-z]\w*\b\1""", Name.Variable),
|
| 268 |
+
(r"'(''|[^'])*'", String.Single),
|
| 269 |
+
(r"`([^`])*`", String.Backtick),
|
| 270 |
+
(r"[^\s]+", String.Symbol),
|
| 271 |
+
]
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
re_prompt = re.compile(r'^(\S.*?)??[=\-\(\$\'\"][#>]')
|
| 275 |
+
re_psql_command = re.compile(r'\s*\\')
|
| 276 |
+
re_end_command = re.compile(r';\s*(--.*?)?$')
|
| 277 |
+
re_psql_command = re.compile(r'(\s*)(\\.+?)(\s+)$')
|
| 278 |
+
re_error = re.compile(r'(ERROR|FATAL):')
|
| 279 |
+
re_message = re.compile(
|
| 280 |
+
r'((?:DEBUG|INFO|NOTICE|WARNING|ERROR|'
|
| 281 |
+
r'FATAL|HINT|DETAIL|CONTEXT|LINE [0-9]+):)(.*?\n)')
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
class lookahead:
|
| 285 |
+
"""Wrap an iterator and allow pushing back an item."""
|
| 286 |
+
def __init__(self, x):
|
| 287 |
+
self.iter = iter(x)
|
| 288 |
+
self._nextitem = None
|
| 289 |
+
|
| 290 |
+
def __iter__(self):
|
| 291 |
+
return self
|
| 292 |
+
|
| 293 |
+
def send(self, i):
|
| 294 |
+
self._nextitem = i
|
| 295 |
+
return i
|
| 296 |
+
|
| 297 |
+
def __next__(self):
|
| 298 |
+
if self._nextitem is not None:
|
| 299 |
+
ni = self._nextitem
|
| 300 |
+
self._nextitem = None
|
| 301 |
+
return ni
|
| 302 |
+
return next(self.iter)
|
| 303 |
+
next = __next__
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
class PostgresConsoleLexer(Lexer):
|
| 307 |
+
"""
|
| 308 |
+
Lexer for psql sessions.
|
| 309 |
+
"""
|
| 310 |
+
|
| 311 |
+
name = 'PostgreSQL console (psql)'
|
| 312 |
+
aliases = ['psql', 'postgresql-console', 'postgres-console']
|
| 313 |
+
mimetypes = ['text/x-postgresql-psql']
|
| 314 |
+
url = 'https://www.postgresql.org'
|
| 315 |
+
version_added = '1.5'
|
| 316 |
+
_example = "psql/psql_session.txt"
|
| 317 |
+
|
| 318 |
+
def get_tokens_unprocessed(self, data):
|
| 319 |
+
sql = PsqlRegexLexer(**self.options)
|
| 320 |
+
|
| 321 |
+
lines = lookahead(line_re.findall(data))
|
| 322 |
+
|
| 323 |
+
# prompt-output cycle
|
| 324 |
+
while 1:
|
| 325 |
+
|
| 326 |
+
# consume the lines of the command: start with an optional prompt
|
| 327 |
+
# and continue until the end of command is detected
|
| 328 |
+
curcode = ''
|
| 329 |
+
insertions = []
|
| 330 |
+
for line in lines:
|
| 331 |
+
# Identify a shell prompt in case of psql commandline example
|
| 332 |
+
if line.startswith('$') and not curcode:
|
| 333 |
+
lexer = get_lexer_by_name('console', **self.options)
|
| 334 |
+
yield from lexer.get_tokens_unprocessed(line)
|
| 335 |
+
break
|
| 336 |
+
|
| 337 |
+
# Identify a psql prompt
|
| 338 |
+
mprompt = re_prompt.match(line)
|
| 339 |
+
if mprompt is not None:
|
| 340 |
+
insertions.append((len(curcode),
|
| 341 |
+
[(0, Generic.Prompt, mprompt.group())]))
|
| 342 |
+
curcode += line[len(mprompt.group()):]
|
| 343 |
+
else:
|
| 344 |
+
curcode += line
|
| 345 |
+
|
| 346 |
+
# Check if this is the end of the command
|
| 347 |
+
# TODO: better handle multiline comments at the end with
|
| 348 |
+
# a lexer with an external state?
|
| 349 |
+
if re_psql_command.match(curcode) \
|
| 350 |
+
or re_end_command.search(curcode):
|
| 351 |
+
break
|
| 352 |
+
|
| 353 |
+
# Emit the combined stream of command and prompt(s)
|
| 354 |
+
yield from do_insertions(insertions,
|
| 355 |
+
sql.get_tokens_unprocessed(curcode))
|
| 356 |
+
|
| 357 |
+
# Emit the output lines
|
| 358 |
+
out_token = Generic.Output
|
| 359 |
+
for line in lines:
|
| 360 |
+
mprompt = re_prompt.match(line)
|
| 361 |
+
if mprompt is not None:
|
| 362 |
+
# push the line back to have it processed by the prompt
|
| 363 |
+
lines.send(line)
|
| 364 |
+
break
|
| 365 |
+
|
| 366 |
+
mmsg = re_message.match(line)
|
| 367 |
+
if mmsg is not None:
|
| 368 |
+
if mmsg.group(1).startswith("ERROR") \
|
| 369 |
+
or mmsg.group(1).startswith("FATAL"):
|
| 370 |
+
out_token = Generic.Error
|
| 371 |
+
yield (mmsg.start(1), Generic.Strong, mmsg.group(1))
|
| 372 |
+
yield (mmsg.start(2), out_token, mmsg.group(2))
|
| 373 |
+
else:
|
| 374 |
+
yield (0, out_token, line)
|
| 375 |
+
else:
|
| 376 |
+
return
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
class PostgresExplainLexer(RegexLexer):
|
| 380 |
+
"""
|
| 381 |
+
Handle PostgreSQL EXPLAIN output
|
| 382 |
+
"""
|
| 383 |
+
|
| 384 |
+
name = 'PostgreSQL EXPLAIN dialect'
|
| 385 |
+
aliases = ['postgres-explain']
|
| 386 |
+
filenames = ['*.explain']
|
| 387 |
+
mimetypes = ['text/x-postgresql-explain']
|
| 388 |
+
url = 'https://www.postgresql.org/docs/current/using-explain.html'
|
| 389 |
+
version_added = '2.15'
|
| 390 |
+
|
| 391 |
+
tokens = {
|
| 392 |
+
'root': [
|
| 393 |
+
(r'(:|\(|\)|ms|kB|->|\.\.|\,|\/|=|%)', Punctuation),
|
| 394 |
+
(r'(\s+)', Whitespace),
|
| 395 |
+
|
| 396 |
+
# This match estimated cost and effectively measured counters with ANALYZE
|
| 397 |
+
# Then, we move to instrumentation state
|
| 398 |
+
(r'(cost)(=?)', bygroups(Name.Class, Punctuation), 'instrumentation'),
|
| 399 |
+
(r'(actual)( )(=?)', bygroups(Name.Class, Whitespace, Punctuation), 'instrumentation'),
|
| 400 |
+
|
| 401 |
+
# Misc keywords
|
| 402 |
+
(words(('actual', 'Memory Usage', 'Disk Usage', 'Memory', 'Buckets',
|
| 403 |
+
'Batches', 'originally', 'row', 'rows', 'Hits', 'Misses',
|
| 404 |
+
'Evictions', 'Overflows', 'Planned Partitions', 'Estimates',
|
| 405 |
+
'capacity', 'distinct keys', 'lookups', 'hit percent',
|
| 406 |
+
'Index Searches', 'Storage', 'Disk Maximum Storage'), suffix=r'\b'),
|
| 407 |
+
Comment.Single),
|
| 408 |
+
|
| 409 |
+
(r'(hit|read|dirtied|written|write|time|calls)(=)', bygroups(Comment.Single, Operator)),
|
| 410 |
+
(r'(shared|temp|local)', Keyword.Pseudo),
|
| 411 |
+
|
| 412 |
+
# We move to sort state in order to emphasize specific keywords (especially disk access)
|
| 413 |
+
(r'(Sort Method)(: )', bygroups(Comment.Preproc, Punctuation), 'sort'),
|
| 414 |
+
|
| 415 |
+
# These keywords can be followed by an object, like a table
|
| 416 |
+
(r'(Sort Key|Group Key|Presorted Key|Hash Key)(:)( )',
|
| 417 |
+
bygroups(Comment.Preproc, Punctuation, Whitespace), 'object_name'),
|
| 418 |
+
(r'(Cache Key|Cache Mode)(:)( )', bygroups(Comment, Punctuation, Whitespace), 'object_name'),
|
| 419 |
+
|
| 420 |
+
# These keywords can be followed by a predicate
|
| 421 |
+
(words(('Join Filter', 'Subplans Removed', 'Filter', 'Merge Cond',
|
| 422 |
+
'Hash Cond', 'Index Cond', 'Recheck Cond', 'Heap Blocks',
|
| 423 |
+
'TID Cond', 'Run Condition', 'Order By', 'Function Call',
|
| 424 |
+
'Table Function Call', 'Inner Unique', 'Params Evaluated',
|
| 425 |
+
'Single Copy', 'Sampling', 'One-Time Filter', 'Output',
|
| 426 |
+
'Relations', 'Remote SQL', 'Disabled'), suffix=r'\b'),
|
| 427 |
+
Comment.Preproc, 'predicate'),
|
| 428 |
+
|
| 429 |
+
# Special keyword to handle ON CONFLICT
|
| 430 |
+
(r'Conflict ', Comment.Preproc, 'conflict'),
|
| 431 |
+
|
| 432 |
+
# Special keyword for InitPlan or SubPlan
|
| 433 |
+
(r'(InitPlan|SubPlan)( )(\d+)( )',
|
| 434 |
+
bygroups(Keyword, Whitespace, Number.Integer, Whitespace),
|
| 435 |
+
'init_plan'),
|
| 436 |
+
|
| 437 |
+
(words(('Sort Method', 'Join Filter', 'Planning time',
|
| 438 |
+
'Planning Time', 'Execution time', 'Execution Time',
|
| 439 |
+
'Workers Planned', 'Workers Launched', 'Buffers',
|
| 440 |
+
'Planning', 'Worker', 'Query Identifier', 'Time',
|
| 441 |
+
'Full-sort Groups', 'Pre-sorted Groups'), suffix=r'\b'), Comment.Preproc),
|
| 442 |
+
|
| 443 |
+
# Emphasize these keywords
|
| 444 |
+
|
| 445 |
+
(words(('Rows Removed by Join Filter', 'Rows Removed by Filter',
|
| 446 |
+
'Rows Removed by Index Recheck',
|
| 447 |
+
'Heap Fetches', 'never executed'),
|
| 448 |
+
suffix=r'\b'), Name.Exception),
|
| 449 |
+
(r'(I/O Timings)(:)( )', bygroups(Name.Exception, Punctuation, Whitespace)),
|
| 450 |
+
|
| 451 |
+
(words(_postgres_builtins.EXPLAIN_KEYWORDS, suffix=r'\b'), Keyword),
|
| 452 |
+
|
| 453 |
+
# join keywords
|
| 454 |
+
(r'((Right|Left|Full|Semi|Anti) Join)', Keyword.Type),
|
| 455 |
+
(r'(Parallel |Async |Finalize |Partial )', Comment.Preproc),
|
| 456 |
+
(r'Backward', Comment.Preproc),
|
| 457 |
+
(r'(Intersect|Except|Hash)', Comment.Preproc),
|
| 458 |
+
|
| 459 |
+
(r'(CTE)( )(\w*)?', bygroups(Comment, Whitespace, Name.Variable)),
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
# Treat "on" and "using" as a punctuation
|
| 463 |
+
(r'(on|using)', Punctuation, 'object_name'),
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
# strings
|
| 467 |
+
(r"'(''|[^'])*'", String.Single),
|
| 468 |
+
# numbers
|
| 469 |
+
(r'-?\d+\.\d+', Number.Float),
|
| 470 |
+
(r'(-?\d+)', Number.Integer),
|
| 471 |
+
|
| 472 |
+
# boolean
|
| 473 |
+
(r'(true|false)', Name.Constant),
|
| 474 |
+
# explain header
|
| 475 |
+
(r'\s*QUERY PLAN\s*\n\s*-+', Comment.Single),
|
| 476 |
+
# Settings
|
| 477 |
+
(r'(Settings)(:)( )', bygroups(Comment.Preproc, Punctuation, Whitespace), 'setting'),
|
| 478 |
+
|
| 479 |
+
# Handle JIT counters
|
| 480 |
+
(r'(JIT|Functions|Options|Timing)(:)', bygroups(Comment.Preproc, Punctuation)),
|
| 481 |
+
(r'(Inlining|Optimization|Expressions|Deforming|Generation|Emission|Total)', Keyword.Pseudo),
|
| 482 |
+
|
| 483 |
+
# Handle Triggers counters
|
| 484 |
+
(r'(Trigger)( )(\S*)(:)( )',
|
| 485 |
+
bygroups(Comment.Preproc, Whitespace, Name.Variable, Punctuation, Whitespace)),
|
| 486 |
+
|
| 487 |
+
],
|
| 488 |
+
'expression': [
|
| 489 |
+
# matches any kind of parenthesized expression
|
| 490 |
+
# the first opening paren is matched by the 'caller'
|
| 491 |
+
(r'\(', Punctuation, '#push'),
|
| 492 |
+
(r'\)', Punctuation, '#pop'),
|
| 493 |
+
(r'(never executed)', Name.Exception),
|
| 494 |
+
(r'[^)(]+', Comment),
|
| 495 |
+
],
|
| 496 |
+
'object_name': [
|
| 497 |
+
|
| 498 |
+
# This is a cost or analyze measure
|
| 499 |
+
(r'(\(cost)(=?)', bygroups(Name.Class, Punctuation), 'instrumentation'),
|
| 500 |
+
(r'(\(actual)( )(=?)', bygroups(Name.Class, Whitespace, Punctuation), 'instrumentation'),
|
| 501 |
+
|
| 502 |
+
# if object_name is parenthesized, mark opening paren as
|
| 503 |
+
# punctuation, call 'expression', and exit state
|
| 504 |
+
(r'\(', Punctuation, 'expression'),
|
| 505 |
+
(r'(on)', Punctuation),
|
| 506 |
+
# matches possibly schema-qualified table and column names
|
| 507 |
+
(r'\w+(\.\w+)*( USING \S+| \w+ USING \S+)', Name.Variable),
|
| 508 |
+
(r'\"?\w+\"?(?:\.\"?\w+\"?)?', Name.Variable),
|
| 509 |
+
(r'\'\S*\'', Name.Variable),
|
| 510 |
+
|
| 511 |
+
# if we encounter a comma, another object is listed
|
| 512 |
+
(r',\n', Punctuation, 'object_name'),
|
| 513 |
+
(r',', Punctuation, 'object_name'),
|
| 514 |
+
|
| 515 |
+
# special case: "*SELECT*"
|
| 516 |
+
(r'"\*SELECT\*( \d+)?"(.\w+)?', Name.Variable),
|
| 517 |
+
(r'"\*VALUES\*(_\d+)?"(.\w+)?', Name.Variable),
|
| 518 |
+
(r'"ANY_subquery"', Name.Variable),
|
| 519 |
+
|
| 520 |
+
# Variable $1 ...
|
| 521 |
+
(r'\$\d+', Name.Variable),
|
| 522 |
+
# cast
|
| 523 |
+
(r'::\w+', Name.Variable),
|
| 524 |
+
(r' +', Whitespace),
|
| 525 |
+
(r'"', Punctuation),
|
| 526 |
+
(r'\[\.\.\.\]', Punctuation),
|
| 527 |
+
(r'\)', Punctuation, '#pop'),
|
| 528 |
+
],
|
| 529 |
+
'predicate': [
|
| 530 |
+
# if predicate is parenthesized, mark paren as punctuation
|
| 531 |
+
(r'(\()([^\n]*)(\))', bygroups(Punctuation, Name.Variable, Punctuation), '#pop'),
|
| 532 |
+
# otherwise color until newline
|
| 533 |
+
(r'[^\n]*', Name.Variable, '#pop'),
|
| 534 |
+
],
|
| 535 |
+
'instrumentation': [
|
| 536 |
+
(r'=|\.\.', Punctuation),
|
| 537 |
+
(r' +', Whitespace),
|
| 538 |
+
(r'(rows|width|time|loops)', Name.Class),
|
| 539 |
+
(r'\d+\.\d+', Number.Float),
|
| 540 |
+
(r'(\d+)', Number.Integer),
|
| 541 |
+
(r'\)', Punctuation, '#pop'),
|
| 542 |
+
],
|
| 543 |
+
'conflict': [
|
| 544 |
+
(r'(Resolution: )(\w+)', bygroups(Comment.Preproc, Name.Variable)),
|
| 545 |
+
(r'(Arbiter \w+:)', Comment.Preproc, 'object_name'),
|
| 546 |
+
(r'(Filter: )', Comment.Preproc, 'predicate'),
|
| 547 |
+
],
|
| 548 |
+
'setting': [
|
| 549 |
+
(r'([a-z_]*?)(\s*)(=)(\s*)(\'.*?\')', bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)),
|
| 550 |
+
(r'\, ', Punctuation),
|
| 551 |
+
],
|
| 552 |
+
'init_plan': [
|
| 553 |
+
(r'\(', Punctuation),
|
| 554 |
+
(r'returns \$\d+(,\$\d+)?', Name.Variable),
|
| 555 |
+
(r'\)', Punctuation, '#pop'),
|
| 556 |
+
],
|
| 557 |
+
'sort': [
|
| 558 |
+
(r':|kB', Punctuation),
|
| 559 |
+
(r'(quicksort|top-N|heapsort|Average|Memory|Peak)', Comment.Prepoc),
|
| 560 |
+
(r'(external|merge|Disk|sort)', Name.Exception),
|
| 561 |
+
(r'(\d+)', Number.Integer),
|
| 562 |
+
(r' +', Whitespace),
|
| 563 |
+
],
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
class SqlLexer(RegexLexer):
|
| 568 |
+
"""
|
| 569 |
+
Lexer for Structured Query Language. Currently, this lexer does
|
| 570 |
+
not recognize any special syntax except ANSI SQL.
|
| 571 |
+
"""
|
| 572 |
+
|
| 573 |
+
name = 'SQL'
|
| 574 |
+
aliases = ['sql']
|
| 575 |
+
filenames = ['*.sql']
|
| 576 |
+
mimetypes = ['text/x-sql']
|
| 577 |
+
url = 'https://en.wikipedia.org/wiki/SQL'
|
| 578 |
+
version_added = ''
|
| 579 |
+
|
| 580 |
+
flags = re.IGNORECASE
|
| 581 |
+
tokens = {
|
| 582 |
+
'root': [
|
| 583 |
+
(r'\s+', Whitespace),
|
| 584 |
+
(r'--.*\n?', Comment.Single),
|
| 585 |
+
(r'/\*', Comment.Multiline, 'multiline-comments'),
|
| 586 |
+
(words(_sql_builtins.KEYWORDS, suffix=r'\b'), Keyword),
|
| 587 |
+
(words(_sql_builtins.DATATYPES, suffix=r'\b'), Name.Builtin),
|
| 588 |
+
(r'[+*/<>=~!@#%^&|`?-]', Operator),
|
| 589 |
+
(r'[0-9]+', Number.Integer),
|
| 590 |
+
# TODO: Backslash escapes?
|
| 591 |
+
(r"'(''|[^'])*'", String.Single),
|
| 592 |
+
(r'"(""|[^"])*"', String.Symbol), # not a real string literal in ANSI SQL
|
| 593 |
+
(r'[a-z_][\w$]*', Name), # allow $s in strings for Oracle
|
| 594 |
+
(r'[;:()\[\],.]', Punctuation)
|
| 595 |
+
],
|
| 596 |
+
'multiline-comments': [
|
| 597 |
+
(r'/\*', Comment.Multiline, 'multiline-comments'),
|
| 598 |
+
(r'\*/', Comment.Multiline, '#pop'),
|
| 599 |
+
(r'[^/*]+', Comment.Multiline),
|
| 600 |
+
(r'[/*]', Comment.Multiline)
|
| 601 |
+
]
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
def analyse_text(self, text):
|
| 605 |
+
return
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
class TransactSqlLexer(RegexLexer):
|
| 609 |
+
"""
|
| 610 |
+
Transact-SQL (T-SQL) is Microsoft's and Sybase's proprietary extension to
|
| 611 |
+
SQL.
|
| 612 |
+
|
| 613 |
+
The list of keywords includes ODBC and keywords reserved for future use.
|
| 614 |
+
"""
|
| 615 |
+
|
| 616 |
+
name = 'Transact-SQL'
|
| 617 |
+
aliases = ['tsql', 't-sql']
|
| 618 |
+
filenames = ['*.sql']
|
| 619 |
+
mimetypes = ['text/x-tsql']
|
| 620 |
+
url = 'https://www.tsql.info'
|
| 621 |
+
version_added = ''
|
| 622 |
+
|
| 623 |
+
flags = re.IGNORECASE
|
| 624 |
+
|
| 625 |
+
tokens = {
|
| 626 |
+
'root': [
|
| 627 |
+
(r'\s+', Whitespace),
|
| 628 |
+
(r'--.*[$|\n]?', Comment.Single),
|
| 629 |
+
(r'/\*', Comment.Multiline, 'multiline-comments'),
|
| 630 |
+
(words(_tsql_builtins.OPERATORS), Operator),
|
| 631 |
+
(words(_tsql_builtins.OPERATOR_WORDS, suffix=r'\b'), Operator.Word),
|
| 632 |
+
(words(_tsql_builtins.TYPES, suffix=r'\b'), Name.Class),
|
| 633 |
+
(words(_tsql_builtins.FUNCTIONS, suffix=r'\b'), Name.Function),
|
| 634 |
+
(r'(goto)(\s+)(\w+\b)', bygroups(Keyword, Whitespace, Name.Label)),
|
| 635 |
+
(words(_tsql_builtins.KEYWORDS, suffix=r'\b'), Keyword),
|
| 636 |
+
(r'(\[)([^]]+)(\])', bygroups(Operator, Name, Operator)),
|
| 637 |
+
(r'0x[0-9a-f]+', Number.Hex),
|
| 638 |
+
# Float variant 1, for example: 1., 1.e2, 1.2e3
|
| 639 |
+
(r'[0-9]+\.[0-9]*(e[+-]?[0-9]+)?', Number.Float),
|
| 640 |
+
# Float variant 2, for example: .1, .1e2
|
| 641 |
+
(r'\.[0-9]+(e[+-]?[0-9]+)?', Number.Float),
|
| 642 |
+
# Float variant 3, for example: 123e45
|
| 643 |
+
(r'[0-9]+e[+-]?[0-9]+', Number.Float),
|
| 644 |
+
(r'[0-9]+', Number.Integer),
|
| 645 |
+
(r"'(''|[^'])*'", String.Single),
|
| 646 |
+
(r'"(""|[^"])*"', String.Symbol),
|
| 647 |
+
(r'[;(),.]', Punctuation),
|
| 648 |
+
# Below we use \w even for the first "real" character because
|
| 649 |
+
# tokens starting with a digit have already been recognized
|
| 650 |
+
# as Number above.
|
| 651 |
+
(r'@@\w+', Name.Builtin),
|
| 652 |
+
(r'@\w+', Name.Variable),
|
| 653 |
+
(r'(\w+)(:)', bygroups(Name.Label, Punctuation)),
|
| 654 |
+
(r'#?#?\w+', Name), # names for temp tables and anything else
|
| 655 |
+
(r'\?', Name.Variable.Magic), # parameter for prepared statements
|
| 656 |
+
],
|
| 657 |
+
'multiline-comments': [
|
| 658 |
+
(r'/\*', Comment.Multiline, 'multiline-comments'),
|
| 659 |
+
(r'\*/', Comment.Multiline, '#pop'),
|
| 660 |
+
(r'[^/*]+', Comment.Multiline),
|
| 661 |
+
(r'[/*]', Comment.Multiline)
|
| 662 |
+
]
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
def analyse_text(text):
|
| 666 |
+
rating = 0
|
| 667 |
+
if tsql_declare_re.search(text):
|
| 668 |
+
# Found T-SQL variable declaration.
|
| 669 |
+
rating = 1.0
|
| 670 |
+
else:
|
| 671 |
+
name_between_backtick_count = len(
|
| 672 |
+
name_between_backtick_re.findall(text))
|
| 673 |
+
name_between_bracket_count = len(
|
| 674 |
+
name_between_bracket_re.findall(text))
|
| 675 |
+
# We need to check if there are any names using
|
| 676 |
+
# backticks or brackets, as otherwise both are 0
|
| 677 |
+
# and 0 >= 2 * 0, so we would always assume it's true
|
| 678 |
+
dialect_name_count = name_between_backtick_count + name_between_bracket_count
|
| 679 |
+
if dialect_name_count >= 1 and \
|
| 680 |
+
name_between_bracket_count >= 2 * name_between_backtick_count:
|
| 681 |
+
# Found at least twice as many [name] as `name`.
|
| 682 |
+
rating += 0.5
|
| 683 |
+
elif name_between_bracket_count > name_between_backtick_count:
|
| 684 |
+
rating += 0.2
|
| 685 |
+
elif name_between_bracket_count > 0:
|
| 686 |
+
rating += 0.1
|
| 687 |
+
if tsql_variable_re.search(text) is not None:
|
| 688 |
+
rating += 0.1
|
| 689 |
+
if tsql_go_re.search(text) is not None:
|
| 690 |
+
rating += 0.1
|
| 691 |
+
return rating
|
| 692 |
+
|
| 693 |
+
|
| 694 |
+
class MySqlLexer(RegexLexer):
|
| 695 |
+
"""The Oracle MySQL lexer.
|
| 696 |
+
|
| 697 |
+
This lexer does not attempt to maintain strict compatibility with
|
| 698 |
+
MariaDB syntax or keywords. Although MySQL and MariaDB's common code
|
| 699 |
+
history suggests there may be significant overlap between the two,
|
| 700 |
+
compatibility between the two is not a target for this lexer.
|
| 701 |
+
"""
|
| 702 |
+
|
| 703 |
+
name = 'MySQL'
|
| 704 |
+
aliases = ['mysql']
|
| 705 |
+
mimetypes = ['text/x-mysql']
|
| 706 |
+
url = 'https://www.mysql.com'
|
| 707 |
+
version_added = ''
|
| 708 |
+
|
| 709 |
+
flags = re.IGNORECASE
|
| 710 |
+
tokens = {
|
| 711 |
+
'root': [
|
| 712 |
+
(r'\s+', Whitespace),
|
| 713 |
+
|
| 714 |
+
# Comments
|
| 715 |
+
(r'(?:#|--\s+).*', Comment.Single),
|
| 716 |
+
(r'/\*\+', Comment.Special, 'optimizer-hints'),
|
| 717 |
+
(r'/\*', Comment.Multiline, 'multiline-comment'),
|
| 718 |
+
|
| 719 |
+
# Hexadecimal literals
|
| 720 |
+
(r"x'([0-9a-f]{2})+'", Number.Hex), # MySQL requires paired hex characters in this form.
|
| 721 |
+
(r'0x[0-9a-f]+', Number.Hex),
|
| 722 |
+
|
| 723 |
+
# Binary literals
|
| 724 |
+
(r"b'[01]+'", Number.Bin),
|
| 725 |
+
(r'0b[01]+', Number.Bin),
|
| 726 |
+
|
| 727 |
+
# Numeric literals
|
| 728 |
+
(r'[0-9]+\.[0-9]*(e[+-]?[0-9]+)?', Number.Float), # Mandatory integer, optional fraction and exponent
|
| 729 |
+
(r'[0-9]*\.[0-9]+(e[+-]?[0-9]+)?', Number.Float), # Mandatory fraction, optional integer and exponent
|
| 730 |
+
(r'[0-9]+e[+-]?[0-9]+', Number.Float), # Exponents with integer significands are still floats
|
| 731 |
+
(r'[0-9]+(?=[^0-9a-z$_\u0080-\uffff])', Number.Integer), # Integers that are not in a schema object name
|
| 732 |
+
|
| 733 |
+
# Date literals
|
| 734 |
+
(r"\{\s*d\s*(?P<quote>['\"])\s*\d{2}(\d{2})?.?\d{2}.?\d{2}\s*(?P=quote)\s*\}",
|
| 735 |
+
Literal.Date),
|
| 736 |
+
|
| 737 |
+
# Time literals
|
| 738 |
+
(r"\{\s*t\s*(?P<quote>['\"])\s*(?:\d+\s+)?\d{1,2}.?\d{1,2}.?\d{1,2}(\.\d*)?\s*(?P=quote)\s*\}",
|
| 739 |
+
Literal.Date),
|
| 740 |
+
|
| 741 |
+
# Timestamp literals
|
| 742 |
+
(
|
| 743 |
+
r"\{\s*ts\s*(?P<quote>['\"])\s*"
|
| 744 |
+
r"\d{2}(?:\d{2})?.?\d{2}.?\d{2}" # Date part
|
| 745 |
+
r"\s+" # Whitespace between date and time
|
| 746 |
+
r"\d{1,2}.?\d{1,2}.?\d{1,2}(\.\d*)?" # Time part
|
| 747 |
+
r"\s*(?P=quote)\s*\}",
|
| 748 |
+
Literal.Date
|
| 749 |
+
),
|
| 750 |
+
|
| 751 |
+
# String literals
|
| 752 |
+
(r"'", String.Single, 'single-quoted-string'),
|
| 753 |
+
(r'"', String.Double, 'double-quoted-string'),
|
| 754 |
+
|
| 755 |
+
# Variables
|
| 756 |
+
(r'@@(?:global\.|persist\.|persist_only\.|session\.)?[a-z_]+', Name.Variable),
|
| 757 |
+
(r'@[a-z0-9_$.]+', Name.Variable),
|
| 758 |
+
(r"@'", Name.Variable, 'single-quoted-variable'),
|
| 759 |
+
(r'@"', Name.Variable, 'double-quoted-variable'),
|
| 760 |
+
(r"@`", Name.Variable, 'backtick-quoted-variable'),
|
| 761 |
+
(r'\?', Name.Variable), # For demonstrating prepared statements
|
| 762 |
+
|
| 763 |
+
# Operators
|
| 764 |
+
(r'[!%&*+/:<=>^|~-]+', Operator),
|
| 765 |
+
|
| 766 |
+
# Exceptions; these words tokenize differently in different contexts.
|
| 767 |
+
(r'\b(set)(?!\s*\()', Keyword),
|
| 768 |
+
(r'\b(character)(\s+)(set)\b', bygroups(Keyword, Whitespace, Keyword)),
|
| 769 |
+
# In all other known cases, "SET" is tokenized by MYSQL_DATATYPES.
|
| 770 |
+
|
| 771 |
+
(words(_mysql_builtins.MYSQL_CONSTANTS, prefix=r'\b', suffix=r'\b'),
|
| 772 |
+
Name.Constant),
|
| 773 |
+
(words(_mysql_builtins.MYSQL_DATATYPES, prefix=r'\b', suffix=r'\b'),
|
| 774 |
+
Keyword.Type),
|
| 775 |
+
(words(_mysql_builtins.MYSQL_KEYWORDS, prefix=r'\b', suffix=r'\b'),
|
| 776 |
+
Keyword),
|
| 777 |
+
(words(_mysql_builtins.MYSQL_FUNCTIONS, prefix=r'\b', suffix=r'\b(\s*)(\()'),
|
| 778 |
+
bygroups(Name.Function, Whitespace, Punctuation)),
|
| 779 |
+
|
| 780 |
+
# Schema object names
|
| 781 |
+
#
|
| 782 |
+
# Note: Although the first regex supports unquoted all-numeric
|
| 783 |
+
# identifiers, this will not be a problem in practice because
|
| 784 |
+
# numeric literals have already been handled above.
|
| 785 |
+
#
|
| 786 |
+
('[0-9a-z$_\u0080-\uffff]+', Name),
|
| 787 |
+
(r'`', Name.Quoted, 'schema-object-name'),
|
| 788 |
+
|
| 789 |
+
# Punctuation
|
| 790 |
+
(r'[(),.;]', Punctuation),
|
| 791 |
+
],
|
| 792 |
+
|
| 793 |
+
# Multiline comment substates
|
| 794 |
+
# ---------------------------
|
| 795 |
+
|
| 796 |
+
'optimizer-hints': [
|
| 797 |
+
(r'[^*a-z]+', Comment.Special),
|
| 798 |
+
(r'\*/', Comment.Special, '#pop'),
|
| 799 |
+
(words(_mysql_builtins.MYSQL_OPTIMIZER_HINTS, suffix=r'\b'),
|
| 800 |
+
Comment.Preproc),
|
| 801 |
+
('[a-z]+', Comment.Special),
|
| 802 |
+
(r'\*', Comment.Special),
|
| 803 |
+
],
|
| 804 |
+
|
| 805 |
+
'multiline-comment': [
|
| 806 |
+
(r'[^*]+', Comment.Multiline),
|
| 807 |
+
(r'\*/', Comment.Multiline, '#pop'),
|
| 808 |
+
(r'\*', Comment.Multiline),
|
| 809 |
+
],
|
| 810 |
+
|
| 811 |
+
# String substates
|
| 812 |
+
# ----------------
|
| 813 |
+
|
| 814 |
+
'single-quoted-string': [
|
| 815 |
+
(r"[^'\\]+", String.Single),
|
| 816 |
+
(r"''", String.Escape),
|
| 817 |
+
(r"""\\[0'"bnrtZ\\%_]""", String.Escape),
|
| 818 |
+
(r"'", String.Single, '#pop'),
|
| 819 |
+
],
|
| 820 |
+
|
| 821 |
+
'double-quoted-string': [
|
| 822 |
+
(r'[^"\\]+', String.Double),
|
| 823 |
+
(r'""', String.Escape),
|
| 824 |
+
(r"""\\[0'"bnrtZ\\%_]""", String.Escape),
|
| 825 |
+
(r'"', String.Double, '#pop'),
|
| 826 |
+
],
|
| 827 |
+
|
| 828 |
+
# Variable substates
|
| 829 |
+
# ------------------
|
| 830 |
+
|
| 831 |
+
'single-quoted-variable': [
|
| 832 |
+
(r"[^']+", Name.Variable),
|
| 833 |
+
(r"''", Name.Variable),
|
| 834 |
+
(r"'", Name.Variable, '#pop'),
|
| 835 |
+
],
|
| 836 |
+
|
| 837 |
+
'double-quoted-variable': [
|
| 838 |
+
(r'[^"]+', Name.Variable),
|
| 839 |
+
(r'""', Name.Variable),
|
| 840 |
+
(r'"', Name.Variable, '#pop'),
|
| 841 |
+
],
|
| 842 |
+
|
| 843 |
+
'backtick-quoted-variable': [
|
| 844 |
+
(r'[^`]+', Name.Variable),
|
| 845 |
+
(r'``', Name.Variable),
|
| 846 |
+
(r'`', Name.Variable, '#pop'),
|
| 847 |
+
],
|
| 848 |
+
|
| 849 |
+
# Schema object name substates
|
| 850 |
+
# ----------------------------
|
| 851 |
+
#
|
| 852 |
+
# "Name.Quoted" and "Name.Quoted.Escape" are non-standard but
|
| 853 |
+
# formatters will style them as "Name" by default but add
|
| 854 |
+
# additional styles based on the token name. This gives users
|
| 855 |
+
# flexibility to add custom styles as desired.
|
| 856 |
+
#
|
| 857 |
+
'schema-object-name': [
|
| 858 |
+
(r'[^`]+', Name.Quoted),
|
| 859 |
+
(r'``', Name.Quoted.Escape),
|
| 860 |
+
(r'`', Name.Quoted, '#pop'),
|
| 861 |
+
],
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
def analyse_text(text):
|
| 865 |
+
rating = 0
|
| 866 |
+
name_between_backtick_count = len(
|
| 867 |
+
name_between_backtick_re.findall(text))
|
| 868 |
+
name_between_bracket_count = len(
|
| 869 |
+
name_between_bracket_re.findall(text))
|
| 870 |
+
# Same logic as above in the TSQL analysis
|
| 871 |
+
dialect_name_count = name_between_backtick_count + name_between_bracket_count
|
| 872 |
+
if dialect_name_count >= 1 and \
|
| 873 |
+
name_between_backtick_count >= 2 * name_between_bracket_count:
|
| 874 |
+
# Found at least twice as many `name` as [name].
|
| 875 |
+
rating += 0.5
|
| 876 |
+
elif name_between_backtick_count > name_between_bracket_count:
|
| 877 |
+
rating += 0.2
|
| 878 |
+
elif name_between_backtick_count > 0:
|
| 879 |
+
rating += 0.1
|
| 880 |
+
return rating
|
| 881 |
+
|
| 882 |
+
|
| 883 |
+
class GoogleSqlLexer(RegexLexer):
|
| 884 |
+
"""
|
| 885 |
+
GoogleSQL is Google's standard SQL dialect, formerly known as ZetaSQL.
|
| 886 |
+
|
| 887 |
+
The list of keywords includes reserved words for future use.
|
| 888 |
+
"""
|
| 889 |
+
|
| 890 |
+
name = 'GoogleSQL'
|
| 891 |
+
aliases = ['googlesql', 'zetasql']
|
| 892 |
+
filenames = ['*.googlesql', '*.googlesql.sql']
|
| 893 |
+
mimetypes = ['text/x-google-sql', 'text/x-google-sql-aux']
|
| 894 |
+
url = 'https://cloud.google.com/bigquery/googlesql'
|
| 895 |
+
version_added = '2.19'
|
| 896 |
+
|
| 897 |
+
flags = re.IGNORECASE
|
| 898 |
+
tokens = {
|
| 899 |
+
'root': [
|
| 900 |
+
(r'\s+', Whitespace),
|
| 901 |
+
|
| 902 |
+
# Comments
|
| 903 |
+
(r'(?:#|--\s+).*', Comment.Single),
|
| 904 |
+
(r'/\*', Comment.Multiline, 'multiline-comment'),
|
| 905 |
+
|
| 906 |
+
# Hexadecimal literals
|
| 907 |
+
(r"x'([0-9a-f]{2})+'", Number.Hex),
|
| 908 |
+
(r'0x[0-9a-f]+', Number.Hex),
|
| 909 |
+
|
| 910 |
+
# Binary literals
|
| 911 |
+
(r"b'[01]+'", Number.Bin),
|
| 912 |
+
(r'0b[01]+', Number.Bin),
|
| 913 |
+
|
| 914 |
+
# Numeric literals
|
| 915 |
+
(r'[0-9]+\.[0-9]*(e[+-]?[0-9]+)?', Number.Float), # Mandatory integer, optional fraction and exponent
|
| 916 |
+
(r'[0-9]*\.[0-9]+(e[+-]?[0-9]+)?', Number.Float), # Mandatory fraction, optional integer and exponent
|
| 917 |
+
(r'[0-9]+e[+-]?[0-9]+', Number.Float), # Exponents with integer significands are still floats
|
| 918 |
+
(r'[0-9]+(?=[^0-9a-z$_\u0080-\uffff])', Number.Integer), # Integers that are not in a schema object name
|
| 919 |
+
|
| 920 |
+
# Date literals
|
| 921 |
+
(r"\{\s*d\s*(?P<quote>['\"])\s*\d{2}(\d{2})?.?\d{2}.?\d{2}\s*(?P=quote)\s*\}",
|
| 922 |
+
Literal.Date),
|
| 923 |
+
|
| 924 |
+
# Time literals
|
| 925 |
+
(r"\{\s*t\s*(?P<quote>['\"])\s*(?:\d+\s+)?\d{1,2}.?\d{1,2}.?\d{1,2}(\.\d*)?\s*(?P=quote)\s*\}",
|
| 926 |
+
Literal.Date),
|
| 927 |
+
|
| 928 |
+
# Timestamp literals
|
| 929 |
+
(
|
| 930 |
+
r"\{\s*ts\s*(?P<quote>['\"])\s*"
|
| 931 |
+
r"\d{2}(?:\d{2})?.?\d{2}.?\d{2}" # Date part
|
| 932 |
+
r"\s+" # Whitespace between date and time
|
| 933 |
+
r"\d{1,2}.?\d{1,2}.?\d{1,2}(\.\d*)?" # Time part
|
| 934 |
+
r"\s*(?P=quote)\s*\}",
|
| 935 |
+
Literal.Date
|
| 936 |
+
),
|
| 937 |
+
|
| 938 |
+
# String literals
|
| 939 |
+
(r"'", String.Single, 'single-quoted-string'),
|
| 940 |
+
(r'"', String.Double, 'double-quoted-string'),
|
| 941 |
+
|
| 942 |
+
# Variables
|
| 943 |
+
(r'@@(?:global\.|persist\.|persist_only\.|session\.)?[a-z_]+', Name.Variable),
|
| 944 |
+
(r'@[a-z0-9_$.]+', Name.Variable),
|
| 945 |
+
(r"@'", Name.Variable, 'single-quoted-variable'),
|
| 946 |
+
(r'@"', Name.Variable, 'double-quoted-variable'),
|
| 947 |
+
(r"@`", Name.Variable, 'backtick-quoted-variable'),
|
| 948 |
+
(r'\?', Name.Variable), # For demonstrating prepared statements
|
| 949 |
+
|
| 950 |
+
# Exceptions; these words tokenize differently in different contexts.
|
| 951 |
+
(r'\b(set)(?!\s*\()', Keyword),
|
| 952 |
+
(r'\b(character)(\s+)(set)\b', bygroups(Keyword, Whitespace, Keyword)),
|
| 953 |
+
|
| 954 |
+
# Constants, types, keywords, functions, operators
|
| 955 |
+
(words(_googlesql_builtins.constants, prefix=r'\b', suffix=r'\b'), Name.Constant),
|
| 956 |
+
(words(_googlesql_builtins.types, prefix=r'\b', suffix=r'\b'), Keyword.Type),
|
| 957 |
+
(words(_googlesql_builtins.keywords, prefix=r'\b', suffix=r'\b'), Keyword),
|
| 958 |
+
(words(_googlesql_builtins.functionnames, prefix=r'\b', suffix=r'\b(\s*)(\()'),
|
| 959 |
+
bygroups(Name.Function, Whitespace, Punctuation)),
|
| 960 |
+
(words(_googlesql_builtins.operators, prefix=r'\b', suffix=r'\b'), Operator),
|
| 961 |
+
|
| 962 |
+
# Schema object names
|
| 963 |
+
#
|
| 964 |
+
# Note: Although the first regex supports unquoted all-numeric
|
| 965 |
+
# identifiers, this will not be a problem in practice because
|
| 966 |
+
# numeric literals have already been handled above.
|
| 967 |
+
#
|
| 968 |
+
('[0-9a-z$_\u0080-\uffff]+', Name),
|
| 969 |
+
(r'`', Name.Quoted, 'schema-object-name'),
|
| 970 |
+
|
| 971 |
+
# Punctuation
|
| 972 |
+
(r'[(),.;]', Punctuation),
|
| 973 |
+
],
|
| 974 |
+
|
| 975 |
+
# Multiline comment substates
|
| 976 |
+
# ---------------------------
|
| 977 |
+
|
| 978 |
+
'multiline-comment': [
|
| 979 |
+
(r'[^*]+', Comment.Multiline),
|
| 980 |
+
(r'\*/', Comment.Multiline, '#pop'),
|
| 981 |
+
(r'\*', Comment.Multiline),
|
| 982 |
+
],
|
| 983 |
+
|
| 984 |
+
# String substates
|
| 985 |
+
# ----------------
|
| 986 |
+
|
| 987 |
+
'single-quoted-string': [
|
| 988 |
+
(r"[^'\\]+", String.Single),
|
| 989 |
+
(r"''", String.Escape),
|
| 990 |
+
(r"""\\[0'"bnrtZ\\%_]""", String.Escape),
|
| 991 |
+
(r"'", String.Single, '#pop'),
|
| 992 |
+
],
|
| 993 |
+
|
| 994 |
+
'double-quoted-string': [
|
| 995 |
+
(r'[^"\\]+', String.Double),
|
| 996 |
+
(r'""', String.Escape),
|
| 997 |
+
(r"""\\[0'"bnrtZ\\%_]""", String.Escape),
|
| 998 |
+
(r'"', String.Double, '#pop'),
|
| 999 |
+
],
|
| 1000 |
+
|
| 1001 |
+
# Variable substates
|
| 1002 |
+
# ------------------
|
| 1003 |
+
|
| 1004 |
+
'single-quoted-variable': [
|
| 1005 |
+
(r"[^']+", Name.Variable),
|
| 1006 |
+
(r"''", Name.Variable),
|
| 1007 |
+
(r"'", Name.Variable, '#pop'),
|
| 1008 |
+
],
|
| 1009 |
+
|
| 1010 |
+
'double-quoted-variable': [
|
| 1011 |
+
(r'[^"]+', Name.Variable),
|
| 1012 |
+
(r'""', Name.Variable),
|
| 1013 |
+
(r'"', Name.Variable, '#pop'),
|
| 1014 |
+
],
|
| 1015 |
+
|
| 1016 |
+
'backtick-quoted-variable': [
|
| 1017 |
+
(r'[^`]+', Name.Variable),
|
| 1018 |
+
(r'``', Name.Variable),
|
| 1019 |
+
(r'`', Name.Variable, '#pop'),
|
| 1020 |
+
],
|
| 1021 |
+
|
| 1022 |
+
# Schema object name substates
|
| 1023 |
+
# ----------------------------
|
| 1024 |
+
#
|
| 1025 |
+
# "Name.Quoted" and "Name.Quoted.Escape" are non-standard but
|
| 1026 |
+
# formatters will style them as "Name" by default but add
|
| 1027 |
+
# additional styles based on the token name. This gives users
|
| 1028 |
+
# flexibility to add custom styles as desired.
|
| 1029 |
+
#
|
| 1030 |
+
'schema-object-name': [
|
| 1031 |
+
(r'[^`]+', Name.Quoted),
|
| 1032 |
+
(r'``', Name.Quoted.Escape),
|
| 1033 |
+
(r'`', Name.Quoted, '#pop'),
|
| 1034 |
+
],
|
| 1035 |
+
}
|
| 1036 |
+
|
| 1037 |
+
def analyse_text(text):
|
| 1038 |
+
tokens = collections.Counter(text.split())
|
| 1039 |
+
return 0.001 * sum(count for t, count in tokens.items()
|
| 1040 |
+
if t in googlesql_identifiers)
|
| 1041 |
+
|
| 1042 |
+
|
| 1043 |
+
class SqliteConsoleLexer(Lexer):
|
| 1044 |
+
"""
|
| 1045 |
+
Lexer for example sessions using sqlite3.
|
| 1046 |
+
"""
|
| 1047 |
+
|
| 1048 |
+
name = 'sqlite3con'
|
| 1049 |
+
aliases = ['sqlite3']
|
| 1050 |
+
filenames = ['*.sqlite3-console']
|
| 1051 |
+
mimetypes = ['text/x-sqlite3-console']
|
| 1052 |
+
url = 'https://www.sqlite.org'
|
| 1053 |
+
version_added = '0.11'
|
| 1054 |
+
_example = "sqlite3/sqlite3.sqlite3-console"
|
| 1055 |
+
|
| 1056 |
+
def get_tokens_unprocessed(self, data):
|
| 1057 |
+
sql = SqlLexer(**self.options)
|
| 1058 |
+
|
| 1059 |
+
curcode = ''
|
| 1060 |
+
insertions = []
|
| 1061 |
+
for match in line_re.finditer(data):
|
| 1062 |
+
line = match.group()
|
| 1063 |
+
prompt_match = sqlite_prompt_re.match(line)
|
| 1064 |
+
if prompt_match is not None:
|
| 1065 |
+
insertions.append((len(curcode),
|
| 1066 |
+
[(0, Generic.Prompt, line[:7])]))
|
| 1067 |
+
insertions.append((len(curcode),
|
| 1068 |
+
[(7, Whitespace, ' ')]))
|
| 1069 |
+
curcode += line[8:]
|
| 1070 |
+
else:
|
| 1071 |
+
if curcode:
|
| 1072 |
+
yield from do_insertions(insertions,
|
| 1073 |
+
sql.get_tokens_unprocessed(curcode))
|
| 1074 |
+
curcode = ''
|
| 1075 |
+
insertions = []
|
| 1076 |
+
if line.startswith('SQL error: '):
|
| 1077 |
+
yield (match.start(), Generic.Traceback, line)
|
| 1078 |
+
else:
|
| 1079 |
+
yield (match.start(), Generic.Output, line)
|
| 1080 |
+
if curcode:
|
| 1081 |
+
yield from do_insertions(insertions,
|
| 1082 |
+
sql.get_tokens_unprocessed(curcode))
|
| 1083 |
+
|
| 1084 |
+
|
| 1085 |
+
class RqlLexer(RegexLexer):
|
| 1086 |
+
"""
|
| 1087 |
+
Lexer for Relation Query Language.
|
| 1088 |
+
"""
|
| 1089 |
+
name = 'RQL'
|
| 1090 |
+
url = 'http://www.logilab.org/project/rql'
|
| 1091 |
+
aliases = ['rql']
|
| 1092 |
+
filenames = ['*.rql']
|
| 1093 |
+
mimetypes = ['text/x-rql']
|
| 1094 |
+
version_added = '2.0'
|
| 1095 |
+
|
| 1096 |
+
flags = re.IGNORECASE
|
| 1097 |
+
tokens = {
|
| 1098 |
+
'root': [
|
| 1099 |
+
(r'\s+', Whitespace),
|
| 1100 |
+
(r'(DELETE|SET|INSERT|UNION|DISTINCT|WITH|WHERE|BEING|OR'
|
| 1101 |
+
r'|AND|NOT|GROUPBY|HAVING|ORDERBY|ASC|DESC|LIMIT|OFFSET'
|
| 1102 |
+
r'|TODAY|NOW|TRUE|FALSE|NULL|EXISTS)\b', Keyword),
|
| 1103 |
+
(r'[+*/<>=%-]', Operator),
|
| 1104 |
+
(r'(Any|is|instance_of|CWEType|CWRelation)\b', Name.Builtin),
|
| 1105 |
+
(r'[0-9]+', Number.Integer),
|
| 1106 |
+
(r'[A-Z_]\w*\??', Name),
|
| 1107 |
+
(r"'(''|[^'])*'", String.Single),
|
| 1108 |
+
(r'"(""|[^"])*"', String.Single),
|
| 1109 |
+
(r'[;:()\[\],.]', Punctuation)
|
| 1110 |
+
],
|
| 1111 |
+
}
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/pygments/lexers/typoscript.py
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.typoscript
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexers for TypoScript
|
| 6 |
+
|
| 7 |
+
`TypoScriptLexer`
|
| 8 |
+
A TypoScript lexer.
|
| 9 |
+
|
| 10 |
+
`TypoScriptCssDataLexer`
|
| 11 |
+
Lexer that highlights markers, constants and registers within css.
|
| 12 |
+
|
| 13 |
+
`TypoScriptHtmlDataLexer`
|
| 14 |
+
Lexer that highlights markers, constants and registers within html tags.
|
| 15 |
+
|
| 16 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 17 |
+
:license: BSD, see LICENSE for details.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
import re
|
| 21 |
+
|
| 22 |
+
from pygments.lexer import RegexLexer, include, bygroups, using
|
| 23 |
+
from pygments.token import Text, Comment, Name, String, Number, \
|
| 24 |
+
Operator, Punctuation
|
| 25 |
+
|
| 26 |
+
__all__ = ['TypoScriptLexer', 'TypoScriptCssDataLexer', 'TypoScriptHtmlDataLexer']
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class TypoScriptCssDataLexer(RegexLexer):
|
| 30 |
+
"""
|
| 31 |
+
Lexer that highlights markers, constants and registers within css blocks.
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
name = 'TypoScriptCssData'
|
| 35 |
+
aliases = ['typoscriptcssdata']
|
| 36 |
+
url = 'http://docs.typo3.org/typo3cms/TyposcriptReference/'
|
| 37 |
+
version_added = '2.2'
|
| 38 |
+
|
| 39 |
+
tokens = {
|
| 40 |
+
'root': [
|
| 41 |
+
# marker: ###MARK###
|
| 42 |
+
(r'(.*)(###\w+###)(.*)', bygroups(String, Name.Constant, String)),
|
| 43 |
+
# constant: {$some.constant}
|
| 44 |
+
(r'(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})',
|
| 45 |
+
bygroups(String.Symbol, Operator, Name.Constant,
|
| 46 |
+
Name.Constant, String.Symbol)), # constant
|
| 47 |
+
# constant: {register:somevalue}
|
| 48 |
+
(r'(.*)(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})(.*)',
|
| 49 |
+
bygroups(String, String.Symbol, Name.Constant, Operator,
|
| 50 |
+
Name.Constant, String.Symbol, String)), # constant
|
| 51 |
+
# whitespace
|
| 52 |
+
(r'\s+', Text),
|
| 53 |
+
# comments
|
| 54 |
+
(r'/\*(?:(?!\*/).)*\*/', Comment),
|
| 55 |
+
(r'(?<!(#|\'|"))(?:#(?!(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3}))[^\n#]+|//[^\n]*)',
|
| 56 |
+
Comment),
|
| 57 |
+
# other
|
| 58 |
+
(r'[<>,:=.*%+|]', String),
|
| 59 |
+
(r'[\w"\-!/&;(){}]+', String),
|
| 60 |
+
]
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class TypoScriptHtmlDataLexer(RegexLexer):
|
| 65 |
+
"""
|
| 66 |
+
Lexer that highlights markers, constants and registers within html tags.
|
| 67 |
+
"""
|
| 68 |
+
|
| 69 |
+
name = 'TypoScriptHtmlData'
|
| 70 |
+
aliases = ['typoscripthtmldata']
|
| 71 |
+
url = 'http://docs.typo3.org/typo3cms/TyposcriptReference/'
|
| 72 |
+
version_added = '2.2'
|
| 73 |
+
|
| 74 |
+
tokens = {
|
| 75 |
+
'root': [
|
| 76 |
+
# INCLUDE_TYPOSCRIPT
|
| 77 |
+
(r'(INCLUDE_TYPOSCRIPT)', Name.Class),
|
| 78 |
+
# Language label or extension resource FILE:... or LLL:... or EXT:...
|
| 79 |
+
(r'(EXT|FILE|LLL):[^}\n"]*', String),
|
| 80 |
+
# marker: ###MARK###
|
| 81 |
+
(r'(.*)(###\w+###)(.*)', bygroups(String, Name.Constant, String)),
|
| 82 |
+
# constant: {$some.constant}
|
| 83 |
+
(r'(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})',
|
| 84 |
+
bygroups(String.Symbol, Operator, Name.Constant,
|
| 85 |
+
Name.Constant, String.Symbol)), # constant
|
| 86 |
+
# constant: {register:somevalue}
|
| 87 |
+
(r'(.*)(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})(.*)',
|
| 88 |
+
bygroups(String, String.Symbol, Name.Constant, Operator,
|
| 89 |
+
Name.Constant, String.Symbol, String)), # constant
|
| 90 |
+
# whitespace
|
| 91 |
+
(r'\s+', Text),
|
| 92 |
+
# other
|
| 93 |
+
(r'[<>,:=.*%+|]', String),
|
| 94 |
+
(r'[\w"\-!/&;(){}#]+', String),
|
| 95 |
+
]
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
class TypoScriptLexer(RegexLexer):
|
| 100 |
+
"""
|
| 101 |
+
Lexer for TypoScript code.
|
| 102 |
+
"""
|
| 103 |
+
|
| 104 |
+
name = 'TypoScript'
|
| 105 |
+
url = 'http://docs.typo3.org/typo3cms/TyposcriptReference/'
|
| 106 |
+
aliases = ['typoscript']
|
| 107 |
+
filenames = ['*.typoscript']
|
| 108 |
+
mimetypes = ['text/x-typoscript']
|
| 109 |
+
version_added = '2.2'
|
| 110 |
+
|
| 111 |
+
flags = re.DOTALL | re.MULTILINE
|
| 112 |
+
|
| 113 |
+
tokens = {
|
| 114 |
+
'root': [
|
| 115 |
+
include('comment'),
|
| 116 |
+
include('constant'),
|
| 117 |
+
include('html'),
|
| 118 |
+
include('label'),
|
| 119 |
+
include('whitespace'),
|
| 120 |
+
include('keywords'),
|
| 121 |
+
include('punctuation'),
|
| 122 |
+
include('operator'),
|
| 123 |
+
include('structure'),
|
| 124 |
+
include('literal'),
|
| 125 |
+
include('other'),
|
| 126 |
+
],
|
| 127 |
+
'keywords': [
|
| 128 |
+
# Conditions
|
| 129 |
+
(r'(?i)(\[)(browser|compatVersion|dayofmonth|dayofweek|dayofyear|'
|
| 130 |
+
r'device|ELSE|END|GLOBAL|globalString|globalVar|hostname|hour|IP|'
|
| 131 |
+
r'language|loginUser|loginuser|minute|month|page|PIDinRootline|'
|
| 132 |
+
r'PIDupinRootline|system|treeLevel|useragent|userFunc|usergroup|'
|
| 133 |
+
r'version)([^\]]*)(\])',
|
| 134 |
+
bygroups(String.Symbol, Name.Constant, Text, String.Symbol)),
|
| 135 |
+
# Functions
|
| 136 |
+
(r'(?=[\w\-])(HTMLparser|HTMLparser_tags|addParams|cache|encapsLines|'
|
| 137 |
+
r'filelink|if|imageLinkWrap|imgResource|makelinks|numRows|numberFormat|'
|
| 138 |
+
r'parseFunc|replacement|round|select|split|stdWrap|strPad|tableStyle|'
|
| 139 |
+
r'tags|textStyle|typolink)(?![\w\-])', Name.Function),
|
| 140 |
+
# Toplevel objects and _*
|
| 141 |
+
(r'(?:(=?\s*<?\s+|^\s*))(cObj|field|config|content|constants|FEData|'
|
| 142 |
+
r'file|frameset|includeLibs|lib|page|plugin|register|resources|sitemap|'
|
| 143 |
+
r'sitetitle|styles|temp|tt_[^:.\s]*|types|xmlnews|INCLUDE_TYPOSCRIPT|'
|
| 144 |
+
r'_CSS_DEFAULT_STYLE|_DEFAULT_PI_VARS|_LOCAL_LANG)(?![\w\-])',
|
| 145 |
+
bygroups(Operator, Name.Builtin)),
|
| 146 |
+
# Content objects
|
| 147 |
+
(r'(?=[\w\-])(CASE|CLEARGIF|COA|COA_INT|COBJ_ARRAY|COLUMNS|CONTENT|'
|
| 148 |
+
r'CTABLE|EDITPANEL|FILE|FILES|FLUIDTEMPLATE|FORM|HMENU|HRULER|HTML|'
|
| 149 |
+
r'IMAGE|IMGTEXT|IMG_RESOURCE|LOAD_REGISTER|MEDIA|MULTIMEDIA|OTABLE|'
|
| 150 |
+
r'PAGE|QTOBJECT|RECORDS|RESTORE_REGISTER|SEARCHRESULT|SVG|SWFOBJECT|'
|
| 151 |
+
r'TEMPLATE|TEXT|USER|USER_INT)(?![\w\-])', Name.Class),
|
| 152 |
+
# Menu states
|
| 153 |
+
(r'(?=[\w\-])(ACTIFSUBRO|ACTIFSUB|ACTRO|ACT|CURIFSUBRO|CURIFSUB|CURRO|'
|
| 154 |
+
r'CUR|IFSUBRO|IFSUB|NO|SPC|USERDEF1RO|USERDEF1|USERDEF2RO|USERDEF2|'
|
| 155 |
+
r'USRRO|USR)', Name.Class),
|
| 156 |
+
# Menu objects
|
| 157 |
+
(r'(?=[\w\-])(GMENU_FOLDOUT|GMENU_LAYERS|GMENU|IMGMENUITEM|IMGMENU|'
|
| 158 |
+
r'JSMENUITEM|JSMENU|TMENUITEM|TMENU_LAYERS|TMENU)', Name.Class),
|
| 159 |
+
# PHP objects
|
| 160 |
+
(r'(?=[\w\-])(PHP_SCRIPT(_EXT|_INT)?)', Name.Class),
|
| 161 |
+
(r'(?=[\w\-])(userFunc)(?![\w\-])', Name.Function),
|
| 162 |
+
],
|
| 163 |
+
'whitespace': [
|
| 164 |
+
(r'\s+', Text),
|
| 165 |
+
],
|
| 166 |
+
'html': [
|
| 167 |
+
(r'<\S[^\n>]*>', using(TypoScriptHtmlDataLexer)),
|
| 168 |
+
(r'&[^;\n]*;', String),
|
| 169 |
+
(r'(?s)(_CSS_DEFAULT_STYLE)(\s*)(\()(.*(?=\n\)))',
|
| 170 |
+
bygroups(Name.Class, Text, String.Symbol, using(TypoScriptCssDataLexer))),
|
| 171 |
+
],
|
| 172 |
+
'literal': [
|
| 173 |
+
(r'0x[0-9A-Fa-f]+t?', Number.Hex),
|
| 174 |
+
# (r'[0-9]*\.[0-9]+([eE][0-9]+)?[fd]?\s*(?:[^=])', Number.Float),
|
| 175 |
+
(r'[0-9]+', Number.Integer),
|
| 176 |
+
(r'(###\w+###)', Name.Constant),
|
| 177 |
+
],
|
| 178 |
+
'label': [
|
| 179 |
+
# Language label or extension resource FILE:... or LLL:... or EXT:...
|
| 180 |
+
(r'(EXT|FILE|LLL):[^}\n"]*', String),
|
| 181 |
+
# Path to a resource
|
| 182 |
+
(r'(?![^\w\-])([\w\-]+(?:/[\w\-]+)+/?)(\S*\n)',
|
| 183 |
+
bygroups(String, String)),
|
| 184 |
+
],
|
| 185 |
+
'punctuation': [
|
| 186 |
+
(r'[,.]', Punctuation),
|
| 187 |
+
],
|
| 188 |
+
'operator': [
|
| 189 |
+
(r'[<>,:=.*%+|]', Operator),
|
| 190 |
+
],
|
| 191 |
+
'structure': [
|
| 192 |
+
# Brackets and braces
|
| 193 |
+
(r'[{}()\[\]\\]', String.Symbol),
|
| 194 |
+
],
|
| 195 |
+
'constant': [
|
| 196 |
+
# Constant: {$some.constant}
|
| 197 |
+
(r'(\{)(\$)((?:[\w\-]+\.)*)([\w\-]+)(\})',
|
| 198 |
+
bygroups(String.Symbol, Operator, Name.Constant,
|
| 199 |
+
Name.Constant, String.Symbol)), # constant
|
| 200 |
+
# Constant: {register:somevalue}
|
| 201 |
+
(r'(\{)([\w\-]+)(\s*:\s*)([\w\-]+)(\})',
|
| 202 |
+
bygroups(String.Symbol, Name.Constant, Operator,
|
| 203 |
+
Name.Constant, String.Symbol)), # constant
|
| 204 |
+
# Hex color: #ff0077
|
| 205 |
+
(r'(#[a-fA-F0-9]{6}\b|#[a-fA-F0-9]{3}\b)', String.Char)
|
| 206 |
+
],
|
| 207 |
+
'comment': [
|
| 208 |
+
(r'(?<!(#|\'|"))(?:#(?!(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3}))[^\n#]+|//[^\n]*)',
|
| 209 |
+
Comment),
|
| 210 |
+
(r'/\*(?:(?!\*/).)*\*/', Comment),
|
| 211 |
+
(r'(\s*#\s*\n)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|
| 1 |
+
"""
|
| 2 |
+
pygments.lexers.vyper
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
Lexer for the Vyper Smart Contract language.
|
| 6 |
+
|
| 7 |
+
:copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
|
| 8 |
+
:license: BSD, see LICENSE for details.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from pygments.lexer import RegexLexer, bygroups, words
|
| 12 |
+
from pygments.token import (Comment, String, Name, Keyword, Number,
|
| 13 |
+
Operator, Punctuation, Text, Whitespace)
|
| 14 |
+
|
| 15 |
+
__all__ = ['VyperLexer']
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class VyperLexer(RegexLexer):
|
| 19 |
+
"""For the Vyper smart contract language.
|
| 20 |
+
"""
|
| 21 |
+
name = 'Vyper'
|
| 22 |
+
aliases = ['vyper']
|
| 23 |
+
filenames = ['*.vy']
|
| 24 |
+
url = "https://vyper.readthedocs.io"
|
| 25 |
+
version_added = '2.17'
|
| 26 |
+
|
| 27 |
+
tokens = {
|
| 28 |
+
'root': [
|
| 29 |
+
# Whitespace
|
| 30 |
+
(r'\s+', Whitespace),
|
| 31 |
+
|
| 32 |
+
# Line continuations
|
| 33 |
+
(r'(\\)(\n|\r\n|\r)', bygroups(Text, Whitespace)),
|
| 34 |
+
|
| 35 |
+
# Comments - inline and multiline
|
| 36 |
+
(r'#.*$', Comment.Single),
|
| 37 |
+
(r'\"\"\"', Comment.Multiline, 'multiline-comment'),
|
| 38 |
+
|
| 39 |
+
# Strings - single and double
|
| 40 |
+
(r"'", String.Single, 'single-string'),
|
| 41 |
+
(r'"', String.Double, 'double-string'),
|
| 42 |
+
|
| 43 |
+
# Functions (working)
|
| 44 |
+
(r'(def)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)',
|
| 45 |
+
bygroups(Keyword, Whitespace, Name.Function)),
|
| 46 |
+
|
| 47 |
+
# Event and Struct
|
| 48 |
+
(r'(event|struct|interface|log)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)',
|
| 49 |
+
bygroups(Keyword, Whitespace, Name.Class)),
|
| 50 |
+
|
| 51 |
+
# Imports
|
| 52 |
+
(r'(from)(\s+)(vyper\.\w+)(\s+)(import)(\s+)(\w+)',
|
| 53 |
+
bygroups(Keyword, Whitespace, Name.Namespace, Whitespace,
|
| 54 |
+
Keyword, Whitespace, Name.Class)),
|
| 55 |
+
|
| 56 |
+
# Numeric Literals
|
| 57 |
+
(r'\b0x[0-9a-fA-F]+\b', Number.Hex),
|
| 58 |
+
(r'\b(\d{1,3}(?:_\d{3})*|\d+)\b', Number.Integer),
|
| 59 |
+
(r'\b\d+\.\d*\b', Number.Float),
|
| 60 |
+
|
| 61 |
+
# Keywords
|
| 62 |
+
(words(('def', 'event', 'pass', 'return', 'for', 'while', 'if', 'elif',
|
| 63 |
+
'else', 'assert', 'raise', 'import', 'in', 'struct', 'implements',
|
| 64 |
+
'interface', 'from', 'indexed', 'log', 'extcall', 'staticcall'),
|
| 65 |
+
prefix=r'\b', suffix=r'\b'), Keyword),
|
| 66 |
+
|
| 67 |
+
# Visibility and State Mutability
|
| 68 |
+
(words(('public', 'private', 'view', 'pure', 'constant',
|
| 69 |
+
'immutable', 'nonpayable'), prefix=r'\b', suffix=r'\b'),
|
| 70 |
+
Keyword.Declaration),
|
| 71 |
+
|
| 72 |
+
# Built-in Functions
|
| 73 |
+
(words(('bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'shift',
|
| 74 |
+
'create_minimal_proxy_to', 'create_copy_of', 'create_from_blueprint',
|
| 75 |
+
'ecadd', 'ecmul', 'ecrecover', 'keccak256', 'sha256', 'concat', 'convert',
|
| 76 |
+
'uint2str', 'extract32', 'slice', 'abs', 'ceil', 'floor', 'max', 'max_value',
|
| 77 |
+
'min', 'min_value', 'pow_mod256', 'sqrt', 'isqrt', 'uint256_addmod',
|
| 78 |
+
'uint256_mulmod', 'unsafe_add', 'unsafe_sub', 'unsafe_mul', 'unsafe_div',
|
| 79 |
+
'as_wei_value', 'blockhash', 'empty', 'len', 'method_id', '_abi_encode',
|
| 80 |
+
'_abi_decode', 'print', 'range'), prefix=r'\b', suffix=r'\b'),
|
| 81 |
+
Name.Builtin),
|
| 82 |
+
|
| 83 |
+
# Built-in Variables and Attributes
|
| 84 |
+
(words(('msg.sender', 'msg.value', 'block.timestamp', 'block.number', 'msg.gas'),
|
| 85 |
+
prefix=r'\b', suffix=r'\b'),
|
| 86 |
+
Name.Builtin.Pseudo),
|
| 87 |
+
|
| 88 |
+
(words(('uint', 'uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint256',
|
| 89 |
+
'int', 'int8', 'int16', 'int32', 'int64', 'int128', 'int256', 'bool',
|
| 90 |
+
'decimal', 'bytes', 'bytes1', 'bytes2', 'bytes3', 'bytes4', 'bytes5',
|
| 91 |
+
'bytes6', 'bytes7', 'bytes8', 'bytes9', 'bytes10', 'bytes11',
|
| 92 |
+
'bytes12', 'bytes13', 'bytes14', 'bytes15', 'bytes16', 'bytes17',
|
| 93 |
+
'bytes18', 'bytes19', 'bytes20', 'bytes21', 'bytes22', 'bytes23',
|
| 94 |
+
'bytes24', 'bytes25', 'bytes26', 'bytes27', 'bytes28', 'bytes29',
|
| 95 |
+
'bytes30', 'bytes31', 'bytes32', 'string', 'String', 'address',
|
| 96 |
+
'enum', 'struct'), prefix=r'\b', suffix=r'\b'),
|
| 97 |
+
Keyword.Type),
|
| 98 |
+
|
| 99 |
+
# indexed keywords
|
| 100 |
+
(r'\b(indexed)\b(\s*)(\()(\s*)(\w+)(\s*)(\))',
|
| 101 |
+
bygroups(Keyword, Whitespace, Punctuation, Whitespace,
|
| 102 |
+
Keyword.Type, Punctuation)),
|
| 103 |
+
|
| 104 |
+
# Operators and Punctuation
|
| 105 |
+
(r'(\+|\-|\*|\/|<=?|>=?|==|!=|=|\||&|%)', Operator),
|
| 106 |
+
(r'[.,:;()\[\]{}]', Punctuation),
|
| 107 |
+
|
| 108 |
+
# Other variable names and types
|
| 109 |
+
(r'@[\w.]+', Name.Decorator),
|
| 110 |
+
(r'__\w+__', Name.Magic), # Matches double underscores followed by word characters
|
| 111 |
+
(r'EMPTY_BYTES32', Name.Constant),
|
| 112 |
+
(r'\bERC20\b', Name.Class),
|
| 113 |
+
(r'\bself\b', Name.Attribute),
|
| 114 |
+
|
| 115 |
+
(r'Bytes\[\d+\]', Keyword.Type),
|
| 116 |
+
|
| 117 |
+
# Generic names and variables
|
| 118 |
+
(r'\b[a-zA-Z_]\w*\b:', Name.Variable),
|
| 119 |
+
(r'\b[a-zA-Z_]\w*\b', Name),
|
| 120 |
+
|
| 121 |
+
],
|
| 122 |
+
|
| 123 |
+
'multiline-comment': [
|
| 124 |
+
(r'\"\"\"', Comment.Multiline, '#pop'),
|
| 125 |
+
(r'[^"]+', Comment.Multiline),
|
| 126 |
+
(r'\"', Comment.Multiline)
|
| 127 |
+
],
|
| 128 |
+
|
| 129 |
+
'single-string': [
|
| 130 |
+
(r"[^\\']+", String.Single),
|
| 131 |
+
(r"'", String.Single, '#pop'),
|
| 132 |
+
(r'\\.', String.Escape),
|
| 133 |
+
],
|
| 134 |
+
|
| 135 |
+
'double-string': [
|
| 136 |
+
(r'[^\\"]+', String.Double),
|
| 137 |
+
(r'"', String.Double, '#pop'),
|
| 138 |
+
(r'\\.', String.Escape),
|
| 139 |
+
]
|
| 140 |
+
}
|
LTA_openwebtext_dualt/runs_transfer/lta_owt_distilbert_len1024_init_lm1b1m_posemb_repeat_fully_c1024_adamw_gbs512_4gpu_20k_20260514_120045/args.json
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"data_path": "/e2e-data/evad-tech-vla/wanghan58/data/small_benchmarks/langflow_2604_11748/openwebtext",
|
| 3 |
+
"text_column": "text",
|
| 4 |
+
"txt_record_mode": "auto",
|
| 5 |
+
"detokenizer": "auto",
|
| 6 |
+
"openwebtext_split": "train_minus_100k",
|
| 7 |
+
"tokenizer_path": "/e2e-data/evad-tech-vla/wanghan58/workspace/imagenet_handoff_20260327/nlp_dts_light/assets/distilbert-base-uncased/tokenizer.json",
|
| 8 |
+
"save_dir": "runs_transfer/lta_owt_distilbert_len1024_init_lm1b1m_posemb_repeat_fully_c1024_adamw_gbs512_4gpu_20k_20260514_120045",
|
| 9 |
+
"max_records": 0,
|
| 10 |
+
"elf_conditional_hf": false,
|
| 11 |
+
"eval_data_path": "",
|
| 12 |
+
"dataset_cache_dir": "",
|
| 13 |
+
"max_input_len": 64,
|
| 14 |
+
"conditional_pad_token": "eos",
|
| 15 |
+
"label_drop_prob": 0.0,
|
| 16 |
+
"streaming": false,
|
| 17 |
+
"record_pad_truncate": false,
|
| 18 |
+
"record_add_eos": false,
|
| 19 |
+
"record_add_special_tokens": false,
|
| 20 |
+
"record_pad_token": "pad",
|
| 21 |
+
"record_shuffle_buffer": 10000,
|
| 22 |
+
"wrap": true,
|
| 23 |
+
"wrap_mode": "stream",
|
| 24 |
+
"wrap_record_buffer_size": 200,
|
| 25 |
+
"owt_cached_chunks": false,
|
| 26 |
+
"owt_chunk_cache_dir": "",
|
| 27 |
+
"owt_chunk_cache_rebuild": false,
|
| 28 |
+
"owt_chunk_cache_write_batch": 4096,
|
| 29 |
+
"owt_exact_repeat_per_chunk": 0,
|
| 30 |
+
"online_chunk_shuffle": false,
|
| 31 |
+
"online_chunk_shuffle_buffer": 10000,
|
| 32 |
+
"max_len": 1024,
|
| 33 |
+
"stride": 0,
|
| 34 |
+
"batch_size": 16,
|
| 35 |
+
"num_workers": 4,
|
| 36 |
+
"dataloader_prefetch_factor": 4,
|
| 37 |
+
"blocking_data_transfer": false,
|
| 38 |
+
"global_batch_size": 512,
|
| 39 |
+
"grad_accum": 8,
|
| 40 |
+
"total_steps": 20000,
|
| 41 |
+
"lr": 0.0003,
|
| 42 |
+
"weight_decay": 0.0,
|
| 43 |
+
"adam_beta1": 0.9,
|
| 44 |
+
"adam_beta2": 0.999,
|
| 45 |
+
"adam_eps": 1e-08,
|
| 46 |
+
"optimizer": "adamw",
|
| 47 |
+
"muon_momentum": 0.95,
|
| 48 |
+
"muon_ns_steps": 5,
|
| 49 |
+
"muon_update_scale": 1.0,
|
| 50 |
+
"ema_decay": 0.0,
|
| 51 |
+
"ema_start_step": 0,
|
| 52 |
+
"warmup_steps": 2500,
|
| 53 |
+
"lr_schedule": "constant_warmup",
|
| 54 |
+
"min_lr": 6e-05,
|
| 55 |
+
"adamw_param_groups": "nanogpt",
|
| 56 |
+
"grad_clip": 1.0,
|
| 57 |
+
"seed": 42,
|
| 58 |
+
"d_model": 768,
|
| 59 |
+
"cond_dim": 128,
|
| 60 |
+
"n_layers": 12,
|
| 61 |
+
"n_heads": 12,
|
| 62 |
+
"dim_ff": 3072,
|
| 63 |
+
"dropout": 0.1,
|
| 64 |
+
"vocab_size_override": 0,
|
| 65 |
+
"model_type": "ddit",
|
| 66 |
+
"state_format": "prob",
|
| 67 |
+
"bridge": "dirichlet",
|
| 68 |
+
"target_loss": "hard_ce",
|
| 69 |
+
"meanflow_weight": 0.0,
|
| 70 |
+
"loss_t_weight_mode": "none",
|
| 71 |
+
"loss_t_min_weight": 0.0,
|
| 72 |
+
"loss_t_drop_below": 0.2,
|
| 73 |
+
"prior_center_loss_beta": 0.0,
|
| 74 |
+
"prior_center_state": "uniform",
|
| 75 |
+
"rollout_train_prob": 0.0,
|
| 76 |
+
"rollout_train_steps": 1,
|
| 77 |
+
"rollout_train_infer_steps": 64,
|
| 78 |
+
"rollout_train_temp": 1.45,
|
| 79 |
+
"rollout_train_max_gamma": 1.0,
|
| 80 |
+
"rollout_train_corrupt_only": true,
|
| 81 |
+
"rollout_train_samplewise": false,
|
| 82 |
+
"rollout_train_compute_always": false,
|
| 83 |
+
"rollout_train_debug_return_base": false,
|
| 84 |
+
"target_prob": 1.0,
|
| 85 |
+
"min_t": 0.0,
|
| 86 |
+
"max_t": 1.0,
|
| 87 |
+
"dual_t": true,
|
| 88 |
+
"corrupt_t_mode": "same",
|
| 89 |
+
"corrupt_t_value": 0.0,
|
| 90 |
+
"corrupt_min_t": null,
|
| 91 |
+
"corrupt_max_t": null,
|
| 92 |
+
"prefix_block_prob": 0.0,
|
| 93 |
+
"prefix_block_len": 128,
|
| 94 |
+
"min_mask_ratio": 0.1,
|
| 95 |
+
"max_mask_ratio": 1.0,
|
| 96 |
+
"mask_ratio_floor_schedule": "none",
|
| 97 |
+
"mask_mixture_original_prob": 0.0,
|
| 98 |
+
"mask_mixture_lowk_prob": 0.0,
|
| 99 |
+
"mask_mixture_lowcorrupt_prob": 0.0,
|
| 100 |
+
"mask_mixture_block_prob": 0.0,
|
| 101 |
+
"mask_mixture_all_prob": 0.0,
|
| 102 |
+
"mask_mixture_lowk_clean_tokens": "1,2,4,8,16,32,64",
|
| 103 |
+
"mask_mixture_lowcorrupt_tokens": "1,2,4,8,16,32,64",
|
| 104 |
+
"mask_mixture_block_tokens": "64,128",
|
| 105 |
+
"clean_state_mode": "onehot",
|
| 106 |
+
"wrong_token_replace_prob": "1.0",
|
| 107 |
+
"wrong_token_schedule": "linear_t",
|
| 108 |
+
"wrong_token_exp_k": 1.0,
|
| 109 |
+
"dirichlet_concentration_min": 1.0,
|
| 110 |
+
"dirichlet_concentration_max": 1024.0,
|
| 111 |
+
"dirichlet_endpoint_mode": "categorical_dual_t",
|
| 112 |
+
"dirichlet_semantic_t_mode": "same",
|
| 113 |
+
"dirichlet_semantic_t_value": 0.0,
|
| 114 |
+
"dirichlet_semantic_t_curve": "linear",
|
| 115 |
+
"dirichlet_semantic_t_power": 1.0,
|
| 116 |
+
"endpoint_sequence_random_prob_alpha": 0.0,
|
| 117 |
+
"categorical_wrong_from_full_vocab": true,
|
| 118 |
+
"categorical_wrong_from_batch_valid_tokens": false,
|
| 119 |
+
"simplex_bridge_sampler": "dirichlet",
|
| 120 |
+
"logistic_normal_sigma_min": 0.18,
|
| 121 |
+
"logistic_normal_sigma_max": 2.2,
|
| 122 |
+
"logistic_normal_tau_min": 0.65,
|
| 123 |
+
"logistic_normal_tau_max": 1.15,
|
| 124 |
+
"dirichlet_scale": 128.0,
|
| 125 |
+
"dirichlet_floor": 0.001,
|
| 126 |
+
"eps": 1e-08,
|
| 127 |
+
"log_every": 50,
|
| 128 |
+
"eval_every": 0,
|
| 129 |
+
"save_every": 1000,
|
| 130 |
+
"latest_every": 500,
|
| 131 |
+
"resume_path": "",
|
| 132 |
+
"init_model_path": "runs/lta_lm1b_dirichlet_categorical_fullvocab_c1024_fullycoupled_flmpack_onehot_hardce_ddit_small_len128_gbs512_8gpu_1m_nw0/step_1000000.pt",
|
| 133 |
+
"init_pos_embed_mode": "repeat",
|
| 134 |
+
"infer_steps": 128,
|
| 135 |
+
"decode_damping": 1.0,
|
| 136 |
+
"max_gamma": 1.0,
|
| 137 |
+
"decode_solver": "flowmap",
|
| 138 |
+
"noise_init": "logistic_normal",
|
| 139 |
+
"bridge_noise_init": "logistic_normal",
|
| 140 |
+
"noise_sigma": -1.0,
|
| 141 |
+
"demo_mask_ratios": "0.1,0.5,1.0",
|
| 142 |
+
"demo_fill_t": 0.0,
|
| 143 |
+
"bf16": true,
|
| 144 |
+
"allow_tf32": true,
|
| 145 |
+
"activation_checkpointing": false,
|
| 146 |
+
"activation_checkpoint_interval": 1,
|
| 147 |
+
"activation_checkpoint_scope": "block",
|
| 148 |
+
"ddp_static_graph": false,
|
| 149 |
+
"ddp_gradient_as_bucket_view": true,
|
| 150 |
+
"full_train_stats": false,
|
| 151 |
+
"log_train_stats_each_step": true,
|
| 152 |
+
"log_t_bin_stats": true,
|
| 153 |
+
"log_t_bin_edges": "0,0.2,0.4,0.6,0.8,1.0",
|
| 154 |
+
"torch_compile": false,
|
| 155 |
+
"compile_mode": "max-autotune",
|
| 156 |
+
"resolved_detokenizer": null,
|
| 157 |
+
"effective_vocab_size": 30522
|
| 158 |
+
}
|