diff options
author | orivej <[email protected]> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/python/Pygments/py3/pygments/lexers/lisp.py | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/Pygments/py3/pygments/lexers/lisp.py')
-rw-r--r-- | contrib/python/Pygments/py3/pygments/lexers/lisp.py | 626 |
1 files changed, 313 insertions, 313 deletions
diff --git a/contrib/python/Pygments/py3/pygments/lexers/lisp.py b/contrib/python/Pygments/py3/pygments/lexers/lisp.py index 802bf94a86d..5628e336ca4 100644 --- a/contrib/python/Pygments/py3/pygments/lexers/lisp.py +++ b/contrib/python/Pygments/py3/pygments/lexers/lisp.py @@ -17,8 +17,8 @@ from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ from pygments.lexers.python import PythonLexer __all__ = ['SchemeLexer', 'CommonLispLexer', 'HyLexer', 'RacketLexer', - 'NewLispLexer', 'EmacsLispLexer', 'ShenLexer', 'CPSALexer', - 'XtlangLexer', 'FennelLexer'] + 'NewLispLexer', 'EmacsLispLexer', 'ShenLexer', 'CPSALexer', + 'XtlangLexer', 'FennelLexer'] class SchemeLexer(RegexLexer): @@ -157,7 +157,7 @@ class SchemeLexer(RegexLexer): (r"(?<=#\()" + valid_name, Name.Variable, '#pop'), # highlight the builtins - (r"(?<=\()(%s)" % '|'.join(re.escape(entry) + ' ' for entry in builtins), + (r"(?<=\()(%s)" % '|'.join(re.escape(entry) + ' ' for entry in builtins), Name.Builtin, '#pop'), @@ -346,7 +346,7 @@ class CommonLispLexer(RegexLexer): (r'#\d+#', Operator), # read-time comment - (r'#+nil' + terminated + r'\s*\(', Comment.Preproc, 'commented-form'), + (r'#+nil' + terminated + r'\s*\(', Comment.Preproc, 'commented-form'), # read-time conditional (r'#[+-]', Operator), @@ -358,7 +358,7 @@ class CommonLispLexer(RegexLexer): (r'(t|nil)' + terminated, Name.Constant), # functions and variables - (r'\*' + symbol + r'\*', Name.Variable.Global), + (r'\*' + symbol + r'\*', Name.Variable.Global), (symbol, Name.Variable), # parentheses @@ -1274,7 +1274,7 @@ class RacketLexer(RegexLexer): _opening_parenthesis = r'[([{]' _closing_parenthesis = r'[)\]}]' _delimiters = r'()[\]{}",\'`;\s' - _symbol = r'(?:\|[^|]*\||\\[\w\W]|[^|\\%s]+)+' % _delimiters + _symbol = r'(?:\|[^|]*\||\\[\w\W]|[^|\\%s]+)+' % _delimiters _exact_decimal_prefix = r'(?:#e)?(?:#d)?(?:#e)?' _exponent = r'(?:[defls][-+]?\d+)' _inexact_simple_no_hashes = r'(?:\d+(?:/\d+|\.\d*)?|\.\d+)' @@ -1326,16 +1326,16 @@ class RacketLexer(RegexLexer): (_inexact_simple, _delimiters), Number.Float, '#pop'), # #b - (r'(?iu)(#[ei])?#b%s' % _symbol, Number.Bin, '#pop'), + (r'(?iu)(#[ei])?#b%s' % _symbol, Number.Bin, '#pop'), # #o - (r'(?iu)(#[ei])?#o%s' % _symbol, Number.Oct, '#pop'), + (r'(?iu)(#[ei])?#o%s' % _symbol, Number.Oct, '#pop'), # #x - (r'(?iu)(#[ei])?#x%s' % _symbol, Number.Hex, '#pop'), + (r'(?iu)(#[ei])?#x%s' % _symbol, Number.Hex, '#pop'), # #i is always inexact, i.e. float - (r'(?iu)(#d)?#i%s' % _symbol, Number.Float, '#pop'), + (r'(?iu)(#d)?#i%s' % _symbol, Number.Float, '#pop'), # Strings and characters (r'#?"', String.Double, ('#pop', 'string')), @@ -1348,7 +1348,7 @@ class RacketLexer(RegexLexer): (r'#(true|false|[tTfF])', Name.Constant, '#pop'), # Keyword argument names (e.g. #:keyword) - (r'(?u)#:%s' % _symbol, Keyword.Declaration, '#pop'), + (r'(?u)#:%s' % _symbol, Keyword.Declaration, '#pop'), # Reader extensions (r'(#lang |#!)(\S+)', @@ -1425,14 +1425,14 @@ class RacketLexer(RegexLexer): class NewLispLexer(RegexLexer): """ - For `newLISP. <http://www.newlisp.org/>`_ source code (version 10.3.0). + For `newLISP. <http://www.newlisp.org/>`_ source code (version 10.3.0). .. versionadded:: 1.5 """ name = 'NewLisp' aliases = ['newlisp'] - filenames = ['*.lsp', '*.nl', '*.kif'] + filenames = ['*.lsp', '*.nl', '*.kif'] mimetypes = ['text/x-newlisp', 'application/x-newlisp'] flags = re.IGNORECASE | re.MULTILINE | re.UNICODE @@ -2180,7 +2180,7 @@ class EmacsLispLexer(RegexLexer): (r'(t|nil)' + terminated, Name.Constant), # functions and variables - (r'\*' + symbol + r'\*', Name.Variable.Global), + (r'\*' + symbol + r'\*', Name.Variable.Global), (symbol, Name.Variable), # parentheses @@ -2210,52 +2210,52 @@ class ShenLexer(RegexLexer): filenames = ['*.shen'] mimetypes = ['text/x-shen', 'application/x-shen'] - DECLARATIONS = ( - 'datatype', 'define', 'defmacro', 'defprolog', 'defcc', - 'synonyms', 'declare', 'package', 'type', 'function', - ) - - SPECIAL_FORMS = ( - 'lambda', 'get', 'let', 'if', 'cases', 'cond', 'put', 'time', 'freeze', - 'value', 'load', '$', 'protect', 'or', 'and', 'not', 'do', 'output', - 'prolog?', 'trap-error', 'error', 'make-string', '/.', 'set', '@p', - '@s', '@v', - ) - - BUILTINS = ( - '==', '=', '*', '+', '-', '/', '<', '>', '>=', '<=', '<-address', - '<-vector', 'abort', 'absvector', 'absvector?', 'address->', 'adjoin', - 'append', 'arity', 'assoc', 'bind', 'boolean?', 'bound?', 'call', 'cd', - 'close', 'cn', 'compile', 'concat', 'cons', 'cons?', 'cut', 'destroy', - 'difference', 'element?', 'empty?', 'enable-type-theory', - 'error-to-string', 'eval', 'eval-kl', 'exception', 'explode', 'external', - 'fail', 'fail-if', 'file', 'findall', 'fix', 'fst', 'fwhen', 'gensym', - 'get-time', 'hash', 'hd', 'hdstr', 'hdv', 'head', 'identical', - 'implementation', 'in', 'include', 'include-all-but', 'inferences', - 'input', 'input+', 'integer?', 'intern', 'intersection', 'is', 'kill', - 'language', 'length', 'limit', 'lineread', 'loaded', 'macro', 'macroexpand', - 'map', 'mapcan', 'maxinferences', 'mode', 'n->string', 'nl', 'nth', 'null', - 'number?', 'occurrences', 'occurs-check', 'open', 'os', 'out', 'port', - 'porters', 'pos', 'pr', 'preclude', 'preclude-all-but', 'print', 'profile', - 'profile-results', 'ps', 'quit', 'read', 'read+', 'read-byte', 'read-file', - 'read-file-as-bytelist', 'read-file-as-string', 'read-from-string', - 'release', 'remove', 'return', 'reverse', 'run', 'save', 'set', - 'simple-error', 'snd', 'specialise', 'spy', 'step', 'stinput', 'stoutput', - 'str', 'string->n', 'string->symbol', 'string?', 'subst', 'symbol?', - 'systemf', 'tail', 'tc', 'tc?', 'thaw', 'tl', 'tlstr', 'tlv', 'track', - 'tuple?', 'undefmacro', 'unify', 'unify!', 'union', 'unprofile', - 'unspecialise', 'untrack', 'variable?', 'vector', 'vector->', 'vector?', - 'verified', 'version', 'warn', 'when', 'write-byte', 'write-to-file', - 'y-or-n?', - ) - - BUILTINS_ANYWHERE = ('where', 'skip', '>>', '_', '!', '<e>', '<!>') + DECLARATIONS = ( + 'datatype', 'define', 'defmacro', 'defprolog', 'defcc', + 'synonyms', 'declare', 'package', 'type', 'function', + ) + + SPECIAL_FORMS = ( + 'lambda', 'get', 'let', 'if', 'cases', 'cond', 'put', 'time', 'freeze', + 'value', 'load', '$', 'protect', 'or', 'and', 'not', 'do', 'output', + 'prolog?', 'trap-error', 'error', 'make-string', '/.', 'set', '@p', + '@s', '@v', + ) + + BUILTINS = ( + '==', '=', '*', '+', '-', '/', '<', '>', '>=', '<=', '<-address', + '<-vector', 'abort', 'absvector', 'absvector?', 'address->', 'adjoin', + 'append', 'arity', 'assoc', 'bind', 'boolean?', 'bound?', 'call', 'cd', + 'close', 'cn', 'compile', 'concat', 'cons', 'cons?', 'cut', 'destroy', + 'difference', 'element?', 'empty?', 'enable-type-theory', + 'error-to-string', 'eval', 'eval-kl', 'exception', 'explode', 'external', + 'fail', 'fail-if', 'file', 'findall', 'fix', 'fst', 'fwhen', 'gensym', + 'get-time', 'hash', 'hd', 'hdstr', 'hdv', 'head', 'identical', + 'implementation', 'in', 'include', 'include-all-but', 'inferences', + 'input', 'input+', 'integer?', 'intern', 'intersection', 'is', 'kill', + 'language', 'length', 'limit', 'lineread', 'loaded', 'macro', 'macroexpand', + 'map', 'mapcan', 'maxinferences', 'mode', 'n->string', 'nl', 'nth', 'null', + 'number?', 'occurrences', 'occurs-check', 'open', 'os', 'out', 'port', + 'porters', 'pos', 'pr', 'preclude', 'preclude-all-but', 'print', 'profile', + 'profile-results', 'ps', 'quit', 'read', 'read+', 'read-byte', 'read-file', + 'read-file-as-bytelist', 'read-file-as-string', 'read-from-string', + 'release', 'remove', 'return', 'reverse', 'run', 'save', 'set', + 'simple-error', 'snd', 'specialise', 'spy', 'step', 'stinput', 'stoutput', + 'str', 'string->n', 'string->symbol', 'string?', 'subst', 'symbol?', + 'systemf', 'tail', 'tc', 'tc?', 'thaw', 'tl', 'tlstr', 'tlv', 'track', + 'tuple?', 'undefmacro', 'unify', 'unify!', 'union', 'unprofile', + 'unspecialise', 'untrack', 'variable?', 'vector', 'vector->', 'vector?', + 'verified', 'version', 'warn', 'when', 'write-byte', 'write-to-file', + 'y-or-n?', + ) + + BUILTINS_ANYWHERE = ('where', 'skip', '>>', '_', '!', '<e>', '<!>') MAPPINGS = {s: Keyword for s in DECLARATIONS} MAPPINGS.update((s, Name.Builtin) for s in BUILTINS) MAPPINGS.update((s, Keyword) for s in SPECIAL_FORMS) - valid_symbol_chars = r'[\w!$%*+,<=>?/.\'@&#:-]' + valid_symbol_chars = r'[\w!$%*+,<=>?/.\'@&#:-]' valid_name = '%s+' % valid_symbol_chars symbol_name = r'[a-z!$%%*+,<=>?/.\'@&#_-]%s*' % valid_symbol_chars variable = r'[A-Z]%s*' % valid_symbol_chars @@ -2351,13 +2351,13 @@ class ShenLexer(RegexLexer): token = Name.Function if token == Literal else token yield index, token, value - return + return def _process_signature(self, tokens): for index, token, value in tokens: if token == Literal and value == '}': yield index, Punctuation, value - return + return elif token in (Literal, Name.Function): token = Name.Variable if value.istitle() else Keyword.Type yield index, token, value @@ -2389,7 +2389,7 @@ class CPSALexer(RegexLexer): # valid names for identifiers # well, names can only not consist fully of numbers # but this should be good enough for now - valid_name = r'[\w!$%&*+,/:<=>?@^~|-]+' + valid_name = r'[\w!$%&*+,/:<=>?@^~|-]+' tokens = { 'root': [ @@ -2410,7 +2410,7 @@ class CPSALexer(RegexLexer): # strings, symbols and characters (r'"(\\\\|\\[^\\]|[^"\\])*"', String), (r"'" + valid_name, String.Symbol), - (r"#\\([()/'\"._!§$%& ?=+-]|[a-zA-Z0-9]+)", String.Char), + (r"#\\([()/'\"._!§$%& ?=+-]|[a-zA-Z0-9]+)", String.Char), # constants (r'(#t|#f)', Name.Constant), @@ -2439,226 +2439,226 @@ class CPSALexer(RegexLexer): (r'(\[|\])', Punctuation), ], } - - -class XtlangLexer(RegexLexer): - """An xtlang lexer for the `Extempore programming environment - <http://extempore.moso.com.au>`_. - - This is a mixture of Scheme and xtlang, really. Keyword lists are - taken from the Extempore Emacs mode - (https://github.com/extemporelang/extempore-emacs-mode) - - .. versionadded:: 2.2 - """ - name = 'xtlang' - aliases = ['extempore'] - filenames = ['*.xtm'] - mimetypes = [] - - common_keywords = ( - 'lambda', 'define', 'if', 'else', 'cond', 'and', - 'or', 'let', 'begin', 'set!', 'map', 'for-each', - ) - scheme_keywords = ( - 'do', 'delay', 'quasiquote', 'unquote', 'unquote-splicing', 'eval', - 'case', 'let*', 'letrec', 'quote', - ) - xtlang_bind_keywords = ( - 'bind-func', 'bind-val', 'bind-lib', 'bind-type', 'bind-alias', - 'bind-poly', 'bind-dylib', 'bind-lib-func', 'bind-lib-val', - ) - xtlang_keywords = ( - 'letz', 'memzone', 'cast', 'convert', 'dotimes', 'doloop', - ) - common_functions = ( - '*', '+', '-', '/', '<', '<=', '=', '>', '>=', '%', 'abs', 'acos', - 'angle', 'append', 'apply', 'asin', 'assoc', 'assq', 'assv', - 'atan', 'boolean?', 'caaaar', 'caaadr', 'caaar', 'caadar', - 'caaddr', 'caadr', 'caar', 'cadaar', 'cadadr', 'cadar', - 'caddar', 'cadddr', 'caddr', 'cadr', 'car', 'cdaaar', - 'cdaadr', 'cdaar', 'cdadar', 'cdaddr', 'cdadr', 'cdar', - 'cddaar', 'cddadr', 'cddar', 'cdddar', 'cddddr', 'cdddr', - 'cddr', 'cdr', 'ceiling', 'cons', 'cos', 'floor', 'length', - 'list', 'log', 'max', 'member', 'min', 'modulo', 'not', - 'reverse', 'round', 'sin', 'sqrt', 'substring', 'tan', - 'println', 'random', 'null?', 'callback', 'now', - ) - scheme_functions = ( - 'call-with-current-continuation', 'call-with-input-file', - 'call-with-output-file', 'call-with-values', 'call/cc', - 'char->integer', 'char-alphabetic?', 'char-ci<=?', 'char-ci<?', - 'char-ci=?', 'char-ci>=?', 'char-ci>?', 'char-downcase', - 'char-lower-case?', 'char-numeric?', 'char-ready?', - 'char-upcase', 'char-upper-case?', 'char-whitespace?', - 'char<=?', 'char<?', 'char=?', 'char>=?', 'char>?', 'char?', - 'close-input-port', 'close-output-port', 'complex?', - 'current-input-port', 'current-output-port', 'denominator', - 'display', 'dynamic-wind', 'eof-object?', 'eq?', 'equal?', - 'eqv?', 'even?', 'exact->inexact', 'exact?', 'exp', 'expt', - 'force', 'gcd', 'imag-part', 'inexact->exact', 'inexact?', - 'input-port?', 'integer->char', 'integer?', - 'interaction-environment', 'lcm', 'list->string', - 'list->vector', 'list-ref', 'list-tail', 'list?', 'load', - 'magnitude', 'make-polar', 'make-rectangular', 'make-string', - 'make-vector', 'memq', 'memv', 'negative?', 'newline', - 'null-environment', 'number->string', 'number?', - 'numerator', 'odd?', 'open-input-file', 'open-output-file', - 'output-port?', 'pair?', 'peek-char', 'port?', 'positive?', - 'procedure?', 'quotient', 'rational?', 'rationalize', 'read', - 'read-char', 'real-part', 'real?', - 'remainder', 'scheme-report-environment', 'set-car!', 'set-cdr!', - 'string', 'string->list', 'string->number', 'string->symbol', - 'string-append', 'string-ci<=?', 'string-ci<?', 'string-ci=?', - 'string-ci>=?', 'string-ci>?', 'string-copy', 'string-fill!', - 'string-length', 'string-ref', 'string-set!', 'string<=?', - 'string<?', 'string=?', 'string>=?', 'string>?', 'string?', - 'symbol->string', 'symbol?', 'transcript-off', 'transcript-on', - 'truncate', 'values', 'vector', 'vector->list', 'vector-fill!', - 'vector-length', 'vector?', - 'with-input-from-file', 'with-output-to-file', 'write', - 'write-char', 'zero?', - ) - xtlang_functions = ( - 'toString', 'afill!', 'pfill!', 'tfill!', 'tbind', 'vfill!', - 'array-fill!', 'pointer-fill!', 'tuple-fill!', 'vector-fill!', 'free', - 'array', 'tuple', 'list', '~', 'cset!', 'cref', '&', 'bor', - 'ang-names', '<<', '>>', 'nil', 'printf', 'sprintf', 'null', 'now', - 'pset!', 'pref-ptr', 'vset!', 'vref', 'aset!', 'aref', 'aref-ptr', - 'tset!', 'tref', 'tref-ptr', 'salloc', 'halloc', 'zalloc', 'alloc', - 'schedule', 'exp', 'log', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', - 'sqrt', 'expt', 'floor', 'ceiling', 'truncate', 'round', - 'llvm_printf', 'push_zone', 'pop_zone', 'memzone', 'callback', - 'llvm_sprintf', 'make-array', 'array-set!', 'array-ref', - 'array-ref-ptr', 'pointer-set!', 'pointer-ref', 'pointer-ref-ptr', - 'stack-alloc', 'heap-alloc', 'zone-alloc', 'make-tuple', 'tuple-set!', - 'tuple-ref', 'tuple-ref-ptr', 'closure-set!', 'closure-ref', 'pref', - 'pdref', 'impc_null', 'bitcast', 'void', 'ifret', 'ret->', 'clrun->', - 'make-env-zone', 'make-env', '<>', 'dtof', 'ftod', 'i1tof', - 'i1tod', 'i1toi8', 'i1toi32', 'i1toi64', 'i8tof', 'i8tod', - 'i8toi1', 'i8toi32', 'i8toi64', 'i32tof', 'i32tod', 'i32toi1', - 'i32toi8', 'i32toi64', 'i64tof', 'i64tod', 'i64toi1', - 'i64toi8', 'i64toi32', - ) - - # valid names for Scheme identifiers (names cannot consist fully - # of numbers, but this should be good enough for now) - valid_scheme_name = r'[\w!$%&*+,/:<=>?@^~|-]+' - - # valid characters in xtlang names & types - valid_xtlang_name = r'[\w.!-]+' - valid_xtlang_type = r'[]{}[\w<>,*/|!-]+' - - tokens = { - # keep track of when we're exiting the xtlang form - 'xtlang': [ - (r'\(', Punctuation, '#push'), - (r'\)', Punctuation, '#pop'), - - (r'(?<=bind-func\s)' + valid_xtlang_name, Name.Function), - (r'(?<=bind-val\s)' + valid_xtlang_name, Name.Function), - (r'(?<=bind-type\s)' + valid_xtlang_name, Name.Function), - (r'(?<=bind-alias\s)' + valid_xtlang_name, Name.Function), - (r'(?<=bind-poly\s)' + valid_xtlang_name, Name.Function), - (r'(?<=bind-lib\s)' + valid_xtlang_name, Name.Function), - (r'(?<=bind-dylib\s)' + valid_xtlang_name, Name.Function), - (r'(?<=bind-lib-func\s)' + valid_xtlang_name, Name.Function), - (r'(?<=bind-lib-val\s)' + valid_xtlang_name, Name.Function), - - # type annotations - (r':' + valid_xtlang_type, Keyword.Type), - - # types - (r'(<' + valid_xtlang_type + r'>|\|' + valid_xtlang_type + r'\||/' + - valid_xtlang_type + r'/|' + valid_xtlang_type + r'\*)\**', - Keyword.Type), - - # keywords - (words(xtlang_keywords, prefix=r'(?<=\()'), Keyword), - - # builtins - (words(xtlang_functions, prefix=r'(?<=\()'), Name.Function), - - include('common'), - - # variables - (valid_xtlang_name, Name.Variable), - ], - 'scheme': [ - # quoted symbols - (r"'" + valid_scheme_name, String.Symbol), - - # char literals - (r"#\\([()/'\"._!§$%& ?=+-]|[a-zA-Z0-9]+)", String.Char), - - # special operators - (r"('|#|`|,@|,|\.)", Operator), - - # keywords - (words(scheme_keywords, prefix=r'(?<=\()'), Keyword), - - # builtins - (words(scheme_functions, prefix=r'(?<=\()'), Name.Function), - - include('common'), - - # variables - (valid_scheme_name, Name.Variable), - ], - # common to both xtlang and Scheme - 'common': [ - # comments - (r';.*$', Comment.Single), - - # whitespaces - usually not relevant - (r'\s+', Text), - - # numbers - (r'-?\d+\.\d+', Number.Float), - (r'-?\d+', Number.Integer), - - # binary/oct/hex literals - (r'(#b|#o|#x)[\d.]+', Number), - - # strings + + +class XtlangLexer(RegexLexer): + """An xtlang lexer for the `Extempore programming environment + <http://extempore.moso.com.au>`_. + + This is a mixture of Scheme and xtlang, really. Keyword lists are + taken from the Extempore Emacs mode + (https://github.com/extemporelang/extempore-emacs-mode) + + .. versionadded:: 2.2 + """ + name = 'xtlang' + aliases = ['extempore'] + filenames = ['*.xtm'] + mimetypes = [] + + common_keywords = ( + 'lambda', 'define', 'if', 'else', 'cond', 'and', + 'or', 'let', 'begin', 'set!', 'map', 'for-each', + ) + scheme_keywords = ( + 'do', 'delay', 'quasiquote', 'unquote', 'unquote-splicing', 'eval', + 'case', 'let*', 'letrec', 'quote', + ) + xtlang_bind_keywords = ( + 'bind-func', 'bind-val', 'bind-lib', 'bind-type', 'bind-alias', + 'bind-poly', 'bind-dylib', 'bind-lib-func', 'bind-lib-val', + ) + xtlang_keywords = ( + 'letz', 'memzone', 'cast', 'convert', 'dotimes', 'doloop', + ) + common_functions = ( + '*', '+', '-', '/', '<', '<=', '=', '>', '>=', '%', 'abs', 'acos', + 'angle', 'append', 'apply', 'asin', 'assoc', 'assq', 'assv', + 'atan', 'boolean?', 'caaaar', 'caaadr', 'caaar', 'caadar', + 'caaddr', 'caadr', 'caar', 'cadaar', 'cadadr', 'cadar', + 'caddar', 'cadddr', 'caddr', 'cadr', 'car', 'cdaaar', + 'cdaadr', 'cdaar', 'cdadar', 'cdaddr', 'cdadr', 'cdar', + 'cddaar', 'cddadr', 'cddar', 'cdddar', 'cddddr', 'cdddr', + 'cddr', 'cdr', 'ceiling', 'cons', 'cos', 'floor', 'length', + 'list', 'log', 'max', 'member', 'min', 'modulo', 'not', + 'reverse', 'round', 'sin', 'sqrt', 'substring', 'tan', + 'println', 'random', 'null?', 'callback', 'now', + ) + scheme_functions = ( + 'call-with-current-continuation', 'call-with-input-file', + 'call-with-output-file', 'call-with-values', 'call/cc', + 'char->integer', 'char-alphabetic?', 'char-ci<=?', 'char-ci<?', + 'char-ci=?', 'char-ci>=?', 'char-ci>?', 'char-downcase', + 'char-lower-case?', 'char-numeric?', 'char-ready?', + 'char-upcase', 'char-upper-case?', 'char-whitespace?', + 'char<=?', 'char<?', 'char=?', 'char>=?', 'char>?', 'char?', + 'close-input-port', 'close-output-port', 'complex?', + 'current-input-port', 'current-output-port', 'denominator', + 'display', 'dynamic-wind', 'eof-object?', 'eq?', 'equal?', + 'eqv?', 'even?', 'exact->inexact', 'exact?', 'exp', 'expt', + 'force', 'gcd', 'imag-part', 'inexact->exact', 'inexact?', + 'input-port?', 'integer->char', 'integer?', + 'interaction-environment', 'lcm', 'list->string', + 'list->vector', 'list-ref', 'list-tail', 'list?', 'load', + 'magnitude', 'make-polar', 'make-rectangular', 'make-string', + 'make-vector', 'memq', 'memv', 'negative?', 'newline', + 'null-environment', 'number->string', 'number?', + 'numerator', 'odd?', 'open-input-file', 'open-output-file', + 'output-port?', 'pair?', 'peek-char', 'port?', 'positive?', + 'procedure?', 'quotient', 'rational?', 'rationalize', 'read', + 'read-char', 'real-part', 'real?', + 'remainder', 'scheme-report-environment', 'set-car!', 'set-cdr!', + 'string', 'string->list', 'string->number', 'string->symbol', + 'string-append', 'string-ci<=?', 'string-ci<?', 'string-ci=?', + 'string-ci>=?', 'string-ci>?', 'string-copy', 'string-fill!', + 'string-length', 'string-ref', 'string-set!', 'string<=?', + 'string<?', 'string=?', 'string>=?', 'string>?', 'string?', + 'symbol->string', 'symbol?', 'transcript-off', 'transcript-on', + 'truncate', 'values', 'vector', 'vector->list', 'vector-fill!', + 'vector-length', 'vector?', + 'with-input-from-file', 'with-output-to-file', 'write', + 'write-char', 'zero?', + ) + xtlang_functions = ( + 'toString', 'afill!', 'pfill!', 'tfill!', 'tbind', 'vfill!', + 'array-fill!', 'pointer-fill!', 'tuple-fill!', 'vector-fill!', 'free', + 'array', 'tuple', 'list', '~', 'cset!', 'cref', '&', 'bor', + 'ang-names', '<<', '>>', 'nil', 'printf', 'sprintf', 'null', 'now', + 'pset!', 'pref-ptr', 'vset!', 'vref', 'aset!', 'aref', 'aref-ptr', + 'tset!', 'tref', 'tref-ptr', 'salloc', 'halloc', 'zalloc', 'alloc', + 'schedule', 'exp', 'log', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', + 'sqrt', 'expt', 'floor', 'ceiling', 'truncate', 'round', + 'llvm_printf', 'push_zone', 'pop_zone', 'memzone', 'callback', + 'llvm_sprintf', 'make-array', 'array-set!', 'array-ref', + 'array-ref-ptr', 'pointer-set!', 'pointer-ref', 'pointer-ref-ptr', + 'stack-alloc', 'heap-alloc', 'zone-alloc', 'make-tuple', 'tuple-set!', + 'tuple-ref', 'tuple-ref-ptr', 'closure-set!', 'closure-ref', 'pref', + 'pdref', 'impc_null', 'bitcast', 'void', 'ifret', 'ret->', 'clrun->', + 'make-env-zone', 'make-env', '<>', 'dtof', 'ftod', 'i1tof', + 'i1tod', 'i1toi8', 'i1toi32', 'i1toi64', 'i8tof', 'i8tod', + 'i8toi1', 'i8toi32', 'i8toi64', 'i32tof', 'i32tod', 'i32toi1', + 'i32toi8', 'i32toi64', 'i64tof', 'i64tod', 'i64toi1', + 'i64toi8', 'i64toi32', + ) + + # valid names for Scheme identifiers (names cannot consist fully + # of numbers, but this should be good enough for now) + valid_scheme_name = r'[\w!$%&*+,/:<=>?@^~|-]+' + + # valid characters in xtlang names & types + valid_xtlang_name = r'[\w.!-]+' + valid_xtlang_type = r'[]{}[\w<>,*/|!-]+' + + tokens = { + # keep track of when we're exiting the xtlang form + 'xtlang': [ + (r'\(', Punctuation, '#push'), + (r'\)', Punctuation, '#pop'), + + (r'(?<=bind-func\s)' + valid_xtlang_name, Name.Function), + (r'(?<=bind-val\s)' + valid_xtlang_name, Name.Function), + (r'(?<=bind-type\s)' + valid_xtlang_name, Name.Function), + (r'(?<=bind-alias\s)' + valid_xtlang_name, Name.Function), + (r'(?<=bind-poly\s)' + valid_xtlang_name, Name.Function), + (r'(?<=bind-lib\s)' + valid_xtlang_name, Name.Function), + (r'(?<=bind-dylib\s)' + valid_xtlang_name, Name.Function), + (r'(?<=bind-lib-func\s)' + valid_xtlang_name, Name.Function), + (r'(?<=bind-lib-val\s)' + valid_xtlang_name, Name.Function), + + # type annotations + (r':' + valid_xtlang_type, Keyword.Type), + + # types + (r'(<' + valid_xtlang_type + r'>|\|' + valid_xtlang_type + r'\||/' + + valid_xtlang_type + r'/|' + valid_xtlang_type + r'\*)\**', + Keyword.Type), + + # keywords + (words(xtlang_keywords, prefix=r'(?<=\()'), Keyword), + + # builtins + (words(xtlang_functions, prefix=r'(?<=\()'), Name.Function), + + include('common'), + + # variables + (valid_xtlang_name, Name.Variable), + ], + 'scheme': [ + # quoted symbols + (r"'" + valid_scheme_name, String.Symbol), + + # char literals + (r"#\\([()/'\"._!§$%& ?=+-]|[a-zA-Z0-9]+)", String.Char), + + # special operators + (r"('|#|`|,@|,|\.)", Operator), + + # keywords + (words(scheme_keywords, prefix=r'(?<=\()'), Keyword), + + # builtins + (words(scheme_functions, prefix=r'(?<=\()'), Name.Function), + + include('common'), + + # variables + (valid_scheme_name, Name.Variable), + ], + # common to both xtlang and Scheme + 'common': [ + # comments + (r';.*$', Comment.Single), + + # whitespaces - usually not relevant + (r'\s+', Text), + + # numbers + (r'-?\d+\.\d+', Number.Float), + (r'-?\d+', Number.Integer), + + # binary/oct/hex literals + (r'(#b|#o|#x)[\d.]+', Number), + + # strings (r'"(\\\\|\\[^\\]|[^"\\])*"', String), - - # true/false constants - (r'(#t|#f)', Name.Constant), - - # keywords - (words(common_keywords, prefix=r'(?<=\()'), Keyword), - - # builtins - (words(common_functions, prefix=r'(?<=\()'), Name.Function), - - # the famous parentheses! - (r'(\(|\))', Punctuation), - ], - 'root': [ - # go into xtlang mode - (words(xtlang_bind_keywords, prefix=r'(?<=\()', suffix=r'\b'), - Keyword, 'xtlang'), - - include('scheme') - ], - } - - -class FennelLexer(RegexLexer): - """A lexer for the `Fennel programming language <https://fennel-lang.org>`_. - - Fennel compiles to Lua, so all the Lua builtins are recognized as well - as the special forms that are particular to the Fennel compiler. - - .. versionadded:: 2.3 - """ - name = 'Fennel' - aliases = ['fennel', 'fnl'] - filenames = ['*.fnl'] - + + # true/false constants + (r'(#t|#f)', Name.Constant), + + # keywords + (words(common_keywords, prefix=r'(?<=\()'), Keyword), + + # builtins + (words(common_functions, prefix=r'(?<=\()'), Name.Function), + + # the famous parentheses! + (r'(\(|\))', Punctuation), + ], + 'root': [ + # go into xtlang mode + (words(xtlang_bind_keywords, prefix=r'(?<=\()', suffix=r'\b'), + Keyword, 'xtlang'), + + include('scheme') + ], + } + + +class FennelLexer(RegexLexer): + """A lexer for the `Fennel programming language <https://fennel-lang.org>`_. + + Fennel compiles to Lua, so all the Lua builtins are recognized as well + as the special forms that are particular to the Fennel compiler. + + .. versionadded:: 2.3 + """ + name = 'Fennel' + aliases = ['fennel', 'fnl'] + filenames = ['*.fnl'] + # this list is current as of Fennel version 0.10.0. - special_forms = ( + special_forms = ( '#', '%', '*', '+', '-', '->', '->>', '-?>', '-?>>', '.', '..', '/', '//', ':', '<', '<=', '=', '>', '>=', '?.', '^', 'accumulate', 'and', 'band', 'bnot', 'bor', 'bxor', 'collect', 'comment', 'do', 'doc', @@ -2667,13 +2667,13 @@ class FennelLexer(RegexLexer): 'macrodebug', 'match', 'not', 'not=', 'or', 'partial', 'pick-args', 'pick-values', 'quote', 'require-macros', 'rshift', 'set', 'set-forcibly!', 'tset', 'values', 'when', 'while', 'with-open', '~=' - ) - + ) + declarations = ( 'fn', 'global', 'lambda', 'local', 'macro', 'macros', 'var', 'λ' ) - builtins = ( + builtins = ( '_G', '_VERSION', 'arg', 'assert', 'bit32', 'collectgarbage', 'coroutine', 'debug', 'dofile', 'error', 'getfenv', 'getmetatable', 'io', 'ipairs', 'load', 'loadfile', 'loadstring', @@ -2681,47 +2681,47 @@ class FennelLexer(RegexLexer): 'rawequal', 'rawget', 'rawlen', 'rawset', 'require', 'select', 'setfenv', 'setmetatable', 'string', 'table', 'tonumber', 'tostring', 'type', 'unpack', 'xpcall' - ) - + ) + # based on the scheme definition, but disallowing leading digits and # commas, and @ is not allowed. valid_name = r'[a-zA-Z_!$%&*+/:<=>?^~|-][\w!$%&*+/:<=>?^~|\.-]*' - - tokens = { - 'root': [ - # the only comment form is a semicolon; goes to the end of the line - (r';.*$', Comment.Single), - - (r'[,\s]+', Text), - (r'-?\d+\.\d+', Number.Float), - (r'-?\d+', Number.Integer), - + + tokens = { + 'root': [ + # the only comment form is a semicolon; goes to the end of the line + (r';.*$', Comment.Single), + + (r'[,\s]+', Text), + (r'-?\d+\.\d+', Number.Float), + (r'-?\d+', Number.Integer), + (r'"(\\\\|\\[^\\]|[^"\\])*"', String), - + (r'(true|false|nil)', Name.Constant), - # these are technically strings, but it's worth visually - # distinguishing them because their intent is different - # from regular strings. - (r':' + valid_name, String.Symbol), - - # special forms are keywords - (words(special_forms, suffix=' '), Keyword), + # these are technically strings, but it's worth visually + # distinguishing them because their intent is different + # from regular strings. + (r':' + valid_name, String.Symbol), + + # special forms are keywords + (words(special_forms, suffix=' '), Keyword), # these are ... even more special! (words(declarations, suffix=' '), Keyword.Declaration), - # lua standard library are builtins - (words(builtins, suffix=' '), Name.Builtin), - # special-case the vararg symbol - (r'\.\.\.', Name.Variable), - # regular identifiers - (valid_name, Name.Variable), - - # all your normal paired delimiters for your programming enjoyment - (r'(\(|\))', Punctuation), - (r'(\[|\])', Punctuation), - (r'(\{|\})', Punctuation), + # lua standard library are builtins + (words(builtins, suffix=' '), Name.Builtin), + # special-case the vararg symbol + (r'\.\.\.', Name.Variable), + # regular identifiers + (valid_name, Name.Variable), + + # all your normal paired delimiters for your programming enjoyment + (r'(\(|\))', Punctuation), + (r'(\[|\])', Punctuation), + (r'(\{|\})', Punctuation), # the # symbol is shorthand for a lambda function (r'#', Punctuation), - ] - } + ] + } |