# -*- coding: utf-8 -*- """ pygments.lexers.haskell ~~~~~~~~~~~~~~~~~~~~~~~ Lexers for Haskell and related languages. :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ import re from pygments.lexer import Lexer, RegexLexer, bygroups, do_insertions, \ default, include from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Generic from pygments import unistring as uni __all__ = ['HaskellLexer', 'IdrisLexer', 'AgdaLexer', 'CryptolLexer', 'LiterateHaskellLexer', 'LiterateIdrisLexer', 'LiterateAgdaLexer', 'LiterateCryptolLexer', 'KokaLexer'] line_re = re.compile('.*?\n') class HaskellLexer(RegexLexer): """ A Haskell lexer based on the lexemes defined in the Haskell 98 Report. .. versionadded:: 0.8 """ name = 'Haskell' aliases = ['haskell', 'hs'] filenames = ['*.hs'] mimetypes = ['text/x-haskell'] flags = re.MULTILINE | re.UNICODE reserved = ('case', 'class', 'data', 'default', 'deriving', 'do', 'else', 'family', 'if', 'in', 'infix[lr]?', 'instance', 'let', 'newtype', 'of', 'then', 'type', 'where', '_') ascii = ('NUL', 'SOH', '[SE]TX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'HT', 'LF', 'VT', 'FF', 'CR', 'S[OI]', 'DLE', 'DC[1-4]', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', '[FGRU]S', 'SP', 'DEL') tokens = { 'root': [ # Whitespace: (r'\s+', Text), # (r'--\s*|.*$', Comment.Doc), (r'--(?![!#$%&*+./<=>?@^|_~:\\]).*?$', Comment.Single), (r'\{-', Comment.Multiline, 'comment'), # Lexemes: # Identifiers (r'\bimport\b', Keyword.Reserved, 'import'), (r'\bmodule\b', Keyword.Reserved, 'module'), (r'\berror\b', Name.Exception), (r'\b(%s)(?!\')\b' % '|'.join(reserved), Keyword.Reserved), (r"'[^\\]'", String.Char), # this has to come before the TH quote (r'^[_' + uni.Ll + r'][\w\']*', Name.Function), (r"'?[_" + uni.Ll + r"][\w']*", Name), (r"('')?[" + uni.Lu + r"][\w\']*", Keyword.Type), (r"(')[" + uni.Lu + r"][\w\']*", Keyword.Type), (r"(')\[[^\]]*\]", Keyword.Type), # tuples and lists get special treatment in GHC (r"(')\([^)]*\)", Keyword.Type), # .. # Operators (r'\\(?![:!#$%&*+.\\/<=>?@^|~-]+)', Name.Function), # lambda operator (r'(<-|::|->|=>|=)(?![:!#$%&*+.\\/<=>?@^|~-]+)', Operator.Word), # specials (r':[:!#$%&*+.\\/<=>?@^|~-]*', Keyword.Type), # Constructor operators (r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator), # Other operators # Numbers (r'\d+[eE][+-]?\d+', Number.Float), (r'\d+\.\d+([eE][+-]?\d+)?', Number.Float), (r'0[oO][0-7]+', Number.Oct), (r'0[xX][\da-fA-F]+', Number.Hex), (r'\d+', Number.Integer), # Character/String Literals (r"'", String.Char, 'character'), (r'"', String, 'string'), # Special (r'\[\]', Keyword.Type), (r'\(\)', Name.Builtin), (r'[][(),;`{}]', Punctuation), ], 'import': [ # Import statements (r'\s+', Text), (r'"', String, 'string'), # after "funclist" state (r'\)', Punctuation, '#pop'), (r'qualified\b', Keyword), # import X as Y (r'([' + uni.Lu + r'][\w.]*)(\s+)(as)(\s+)([' + uni.Lu + r'][\w.]*)', bygroups(Name.Namespace, Text, Keyword, Text, Name), '#pop'), # import X hiding (functions) (r'([' + uni.Lu + r'][\w.]*)(\s+)(hiding)(\s+)(\()', bygroups(Name.Namespace, Text, Keyword, Text, Punctuation), 'funclist'), # import X (functions) (r'([' + uni.Lu + r'][\w.]*)(\s+)(\()', bygroups(Name.Namespace, Text, Punctuation), 'funclist'), # import X (r'[\w.]+', Name.Namespace, '#pop'), ], 'module': [ (r'\s+', Text), (r'([' + uni.Lu + r'][\w.]*)(\s+)(\()', bygroups(Name.Namespace, Text, Punctuation), 'funclist'), (r'[' + uni.Lu + r'][\w.]*', Name.Namespace, '#pop'), ], 'funclist': [ (r'\s+', Text), (r'[' + uni.Lu + r']\w*', Keyword.Type), (r'(_[\w\']+|[' + uni.Ll + r'][\w\']*)', Name.Function), (r'--(?![!#$%&*+./<=>?@^|_~:\\]).*?$', Comment.Single), (r'\{-', Comment.Multiline, 'comment'), (r',', Punctuation), (r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator), # (HACK, but it makes sense to push two instances, believe me) (r'\(', Punctuation, ('funclist', 'funclist')), (r'\)', Punctuation, '#pop:2'), ], # NOTE: the next four states are shared in the AgdaLexer; make sure # any change is compatible with Agda as well or copy over and change 'comment': [ # Multiline Comments (r'[^-{}]+', Comment.Multiline), (r'\{-', Comment.Multiline, '#push'), (r'-\}', Comment.Multiline, '#pop'), (r'[-{}]', Comment.Multiline), ], 'character': [ # Allows multi-chars, incorrectly. (r"[^\\']'", String.Char, '#pop'), (r"\\", String.Escape, 'escape'), ("'", String.Char, '#pop'), ], 'string': [ (r'[^\\"]+', String), (r"\\", String.Escape, 'escape'), ('"', String, '#pop'), ], 'escape': [ (r'[abfnrtv"\'&\\]', String.Escape, '#pop'), (r'\^[][' + uni.Lu + r'@^_]', String.Escape, '#pop'), ('|'.join(ascii), String.Escape, '#pop'), (r'o[0-7]+', String.Escape, '#pop'), (r'x[\da-fA-F]+', String.Escape, '#pop'), (r'\d+', String.Escape, '#pop'), (r'\s+\\', String.Escape, '#pop'), ], } class IdrisLexer(RegexLexer): """ A lexer for the dependently typed programming language Idris. Based on the Haskell and Agda Lexer. .. versionadded:: 2.0 """ name = 'Idris' aliases = ['idris', 'idr'] filenames = ['*.idr'] mimetypes = ['text/x-idris'] reserved = ('case', 'class', 'data', 'default', 'using', 'do', 'else', 'if', 'in', 'infix[lr]?', 'instance', 'rewrite', 'auto', 'namespace', 'codata', 'mutual', 'private', 'public', 'abstract', 'total', 'partial', 'let', 'proof', 'of', 'then', 'static', 'where', '_', 'with', 'pattern', 'term', 'syntax', 'prefix', 'postulate', 'parameters', 'record', 'dsl', 'impossible', 'implicit', 'tactics', 'intros', 'intro', 'compute', 'refine', 'exact', 'trivial') ascii = ('NUL', 'SOH', '[SE]TX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'HT', 'LF', 'VT', 'FF', 'CR', 'S[OI]', 'DLE', 'DC[1-4]', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', '[FGRU]S', 'SP', 'DEL') directives = ('lib', 'link', 'flag', 'include', 'hide', 'freeze', 'access', 'default', 'logging', 'dynamic', 'name', 'error_handlers', 'language') tokens = { 'root': [ # Comments (r'^(\s*)(%%%s)' % '|'.join(directives), bygroups(Text, Keyword.Reserved)), (r'(\s*)(--(?![!#$%&*+./<=>?@^|_~:\\]).*?)$', bygroups(Text, Comment.Single)), (r'(\s*)(\|{3}.*?)$', bygroups(Text, Comment.Single)), (r'(\s*)(\{-)', bygroups(Text, Comment.Multiline), 'comment'), # Declaration (r'^(\s*)([^\s(){}]+)(\s*)(:)(\s*)', bygroups(Text, Name.Function, Text, Operator.Word, Text)), # Identifiers (r'\b(%s)(?!\')\b' % '|'.join(reserved), Keyword.Reserved), (r'(import|module)(\s+)', bygroups(Keyword.Reserved, Text), 'module'), (r"('')?[A-Z][\w\']*", Keyword.Type), (r'[a-z][\w\']*', Text), # Special Symbols (r'(<-|::|->|=>|=)', Operator.Word), # specials (r'([(){}\[\]:!#$%&*+.\\/<=>?@^|~-]+)', Operator.Word), # specials # Numbers (r'\d+[eE][+-]?\d+', Number.Float), (r'\d+\.\d+([eE][+-]?\d+)?', Number.Float), (r'0[xX][\da-fA-F]+', Number.Hex), (r'\d+', Number.Integer), # Strings (r"'", String.Char, 'character'), (r'"', String, 'string'), (r'[^\s(){}]+', Text), (r'\s+?', Text), # Whitespace ], 'module': [ (r'\s+', Text), (r'([A-Z][\w.]*)(\s+)(\()', bygroups(Name.Namespace, Text, Punctuation), 'funclist'), (r'[A-Z][\w.]*', Name.Namespace, '#pop'), ], 'funclist': [ (r'\s+', Text), (r'[A-Z]\w*', Keyword.Type), (r'(_[\w\']+|[a-z][\w\']*)', Name.Function), (r'--.*$', Comment.Single), (r'\{-', Comment.Multiline, 'comment'), (r',', Punctuation), (r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator), # (HACK, but it makes sense to push two instances, believe me) (r'\(', Punctuation, ('funclist', 'funclist')), (r'\)', Punctuation, '#pop:2'), ], # NOTE: the next four states are shared in the AgdaLexer; make sure # any change is compatible with Agda as well or copy over and change 'comment': [ # Multiline Comments (r'[^-{}]+', Comment.Multiline), (r'\{-', Comment.Multiline, '#push'), (r'-\}', Comment.Multiline, '#pop'), (r'[-{}]', Comment.Multiline), ], 'character': [ # Allows multi-chars, incorrectly. (r"[^\\']", String.Char), (r"\\", String.Escape, 'escape'), ("'", String.Char, '#pop'), ], 'string': [ (r'[^\\"]+', String), (r"\\", String.Escape, 'escape'), ('"', String, '#pop'), ], 'escape': [ (r'[abfnrtv"\'&\\]', String.Escape, '#pop'), (r'\^[][A-Z@^_]', String.Escape, '#pop'), ('|'.join(ascii), String.Escape, '#pop'), (r'o[0-7]+', String.Escape, '#pop'), (r'x[\da-fA-F]+', String.Escape, '#pop'), (r'\d+', String.Escape, '#pop'), (r'\s+\\', String.Escape, '#pop') ], } class AgdaLexer(RegexLexer): """ For the `Agda <http://wiki.portal.chalmers.se/agda/pmwiki.php>`_ dependently typed functional programming language and proof assistant. .. versionadded:: 2.0 """ name = 'Agda' aliases = ['agda'] filenames = ['*.agda'] mimetypes = ['text/x-agda'] reserved = ['abstract', 'codata', 'coinductive', 'constructor', 'data', 'field', 'forall', 'hiding', 'in', 'inductive', 'infix', 'infixl', 'infixr', 'instance', 'let', 'mutual', 'open', 'pattern', 'postulate', 'primitive', 'private', 'quote', 'quoteGoal', 'quoteTerm', 'record', 'renaming', 'rewrite', 'syntax', 'tactic', 'unquote', 'unquoteDecl', 'using', 'where', 'with'] tokens = { 'root': [ # Declaration (r'^(\s*)([^\s(){}]+)(\s*)(:)(\s*)', bygroups(Text, Name.Function, Text, Operator.Word, Text)), # Comments (r'--(?![!#$%&*+./<=>?@^|_~:\\]).*?$', Comment.Single), (r'\{-', Comment.Multiline, 'comment'), # Holes (r'\{!', Comment.Directive, 'hole'), # Lexemes: # Identifiers (r'\b(%s)(?!\')\b' % '|'.join(reserved), Keyword.Reserved), (r'(import|module)(\s+)', bygroups(Keyword.Reserved, Text), 'module'), (r'\b(Set|Prop)\b', Keyword.Type), # Special Symbols (r'(\(|\)|\{|\})', Operator), (u'(\\.{1,3}|\\||\u039B|\u2200|\u2192|:|=|->)', Operator.Word), # Numbers (r'\d+[eE][+-]?\d+', Number.Float), (r'\d+\.\d+([eE][+-]?\d+)?', Number.Float), (r'0[xX][\da-fA-F]+', Number.Hex), (r'\d+', Number.Integer), # Strings (r"'", String.Char, 'character'), (r'"', String, 'string'), (r'[^\s(){}]+', Text), (r'\s+?', Text), # Whitespace ], 'hole': [ # Holes (r'[^!{}]+', Comment.Directive), (r'\{!', Comment.Directive, '#push'), (r'!\}', Comment.Directive, '#pop'), (r'[!{}]', Comment.Directive), ], 'module': [ (r'\{-', Comment.Multiline, 'comment'), (r'[a-zA-Z][\w.]*', Name, '#pop'), (r'[\W0-9_]+', Text) ], 'comment': HaskellLexer.tokens['comment'], 'character': HaskellLexer.tokens['character'], 'string': HaskellLexer.tokens['string'], 'escape': HaskellLexer.tokens['escape'] } class CryptolLexer(RegexLexer): """ FIXME: A Cryptol2 lexer based on the lexemes defined in the Haskell 98 Report. .. versionadded:: 2.0 """ name = 'Cryptol' aliases = ['cryptol', 'cry'] filenames = ['*.cry'] mimetypes = ['text/x-cryptol'] reserved = ('Arith', 'Bit', 'Cmp', 'False', 'Inf', 'True', 'else', 'export', 'extern', 'fin', 'if', 'import', 'inf', 'lg2', 'max', 'min', 'module', 'newtype', 'pragma', 'property', 'then', 'type', 'where', 'width') ascii = ('NUL', 'SOH', '[SE]TX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'HT', 'LF', 'VT', 'FF', 'CR', 'S[OI]', 'DLE', 'DC[1-4]', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', '[FGRU]S', 'SP', 'DEL') tokens = { 'root': [ # Whitespace: (r'\s+', Text), # (r'--\s*|.*$', Comment.Doc), (r'//.*$', Comment.Single), (r'/\*', Comment.Multiline, 'comment'), # Lexemes: # Identifiers (r'\bimport\b', Keyword.Reserved, 'import'), (r'\bmodule\b', Keyword.Reserved, 'module'), (r'\berror\b', Name.Exception), (r'\b(%s)(?!\')\b' % '|'.join(reserved), Keyword.Reserved), (r'^[_a-z][\w\']*', Name.Function), (r"'?[_a-z][\w']*", Name), (r"('')?[A-Z][\w\']*", Keyword.Type), # Operators (r'\\(?![:!#$%&*+.\\/<=>?@^|~-]+)', Name.Function), # lambda operator (r'(<-|::|->|=>|=)(?![:!#$%&*+.\\/<=>?@^|~-]+)', Operator.Word), # specials (r':[:!#$%&*+.\\/<=>?@^|~-]*', Keyword.Type), # Constructor operators (r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator), # Other operators # Numbers (r'\d+[eE][+-]?\d+', Number.Float), (r'\d+\.\d+([eE][+-]?\d+)?', Number.Float), (r'0[oO][0-7]+', Number.Oct), (r'0[xX][\da-fA-F]+', Number.Hex), (r'\d+', Number.Integer), # Character/String Literals (r"'", String.Char, 'character'), (r'"', String, 'string'), # Special (r'\[\]', Keyword.Type), (r'\(\)', Name.Builtin), (r'[][(),;`{}]', Punctuation), ], 'import': [ # Import statements (r'\s+', Text), (r'"', String, 'string'), # after "funclist" state (r'\)', Punctuation, '#pop'), (r'qualified\b', Keyword), # import X as Y (r'([A-Z][\w.]*)(\s+)(as)(\s+)([A-Z][\w.]*)', bygroups(Name.Namespace, Text, Keyword, Text, Name), '#pop'), # import X hiding (functions) (r'([A-Z][\w.]*)(\s+)(hiding)(\s+)(\()', bygroups(Name.Namespace, Text, Keyword, Text, Punctuation), 'funclist'), # import X (functions) (r'([A-Z][\w.]*)(\s+)(\()', bygroups(Name.Namespace, Text, Punctuation), 'funclist'), # import X (r'[\w.]+', Name.Namespace, '#pop'), ], 'module': [ (r'\s+', Text), (r'([A-Z][\w.]*)(\s+)(\()', bygroups(Name.Namespace, Text, Punctuation), 'funclist'), (r'[A-Z][\w.]*', Name.Namespace, '#pop'), ], 'funclist': [ (r'\s+', Text), (r'[A-Z]\w*', Keyword.Type), (r'(_[\w\']+|[a-z][\w\']*)', Name.Function), # TODO: these don't match the comments in docs, remove. #(r'--(?![!#$%&*+./<=>?@^|_~:\\]).*?$', Comment.Single), #(r'{-', Comment.Multiline, 'comment'), (r',', Punctuation), (r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator), # (HACK, but it makes sense to push two instances, believe me) (r'\(', Punctuation, ('funclist', 'funclist')), (r'\)', Punctuation, '#pop:2'), ], 'comment': [ # Multiline Comments (r'[^/*]+', Comment.Multiline), (r'/\*', Comment.Multiline, '#push'), (r'\*/', Comment.Multiline, '#pop'), (r'[*/]', Comment.Multiline), ], 'character': [ # Allows multi-chars, incorrectly. (r"[^\\']'", String.Char, '#pop'), (r"\\", String.Escape, 'escape'), ("'", String.Char, '#pop'), ], 'string': [ (r'[^\\"]+', String), (r"\\", String.Escape, 'escape'), ('"', String, '#pop'), ], 'escape': [ (r'[abfnrtv"\'&\\]', String.Escape, '#pop'), (r'\^[][A-Z@^_]', String.Escape, '#pop'), ('|'.join(ascii), String.Escape, '#pop'), (r'o[0-7]+', String.Escape, '#pop'), (r'x[\da-fA-F]+', String.Escape, '#pop'), (r'\d+', String.Escape, '#pop'), (r'\s+\\', String.Escape, '#pop'), ], } EXTRA_KEYWORDS = set(('join', 'split', 'reverse', 'transpose', 'width', 'length', 'tail', '<<', '>>', '<<<', '>>>', 'const', 'reg', 'par', 'seq', 'ASSERT', 'undefined', 'error', 'trace')) def get_tokens_unprocessed(self, text): stack = ['root'] for index, token, value in \ RegexLexer.get_tokens_unprocessed(self, text, stack): if token is Name and value in self.EXTRA_KEYWORDS: yield index, Name.Builtin, value else: yield index, token, value class LiterateLexer(Lexer): """ Base class for lexers of literate file formats based on LaTeX or Bird-style (prefixing each code line with ">"). Additional options accepted: `litstyle` If given, must be ``"bird"`` or ``"latex"``. If not given, the style is autodetected: if the first non-whitespace character in the source is a backslash or percent character, LaTeX is assumed, else Bird. """ bird_re = re.compile(r'(>[ \t]*)(.*\n)') def __init__(self, baselexer, **options): self.baselexer = baselexer Lexer.__init__(self, **options) def get_tokens_unprocessed(self, text): style = self.options.get('litstyle') if style is None: style = (text.lstrip()[0:1] in '%\\') and 'latex' or 'bird' code = '' insertions = [] if style == 'bird': # bird-style for match in line_re.finditer(text): line = match.group() m = self.bird_re.match(line) if m: insertions.append((len(code), [(0, Comment.Special, m.group(1))])) code += m.group(2) else: insertions.append((len(code), [(0, Text, line)])) else: # latex-style from pygments.lexers.markup import TexLexer lxlexer = TexLexer(**self.options) codelines = 0 latex = '' for match in line_re.finditer(text): line = match.group() if codelines: if line.lstrip().startswith('\\end{code}'): codelines = 0 latex += line else: code += line elif line.lstrip().startswith('\\begin{code}'): codelines = 1 latex += line insertions.append((len(code), list(lxlexer.get_tokens_unprocessed(latex)))) latex = '' else: latex += line insertions.append((len(code), list(lxlexer.get_tokens_unprocessed(latex)))) for item in do_insertions(insertions, self.baselexer.get_tokens_unprocessed(code)): yield item class LiterateHaskellLexer(LiterateLexer): """ For Literate Haskell (Bird-style or LaTeX) source. Additional options accepted: `litstyle` If given, must be ``"bird"`` or ``"latex"``. If not given, the style is autodetected: if the first non-whitespace character in the source is a backslash or percent character, LaTeX is assumed, else Bird. .. versionadded:: 0.9 """ name = 'Literate Haskell' aliases = ['lhs', 'literate-haskell', 'lhaskell'] filenames = ['*.lhs'] mimetypes = ['text/x-literate-haskell'] def __init__(self, **options): hslexer = HaskellLexer(**options) LiterateLexer.__init__(self, hslexer, **options) class LiterateIdrisLexer(LiterateLexer): """ For Literate Idris (Bird-style or LaTeX) source. Additional options accepted: `litstyle` If given, must be ``"bird"`` or ``"latex"``. If not given, the style is autodetected: if the first non-whitespace character in the source is a backslash or percent character, LaTeX is assumed, else Bird. .. versionadded:: 2.0 """ name = 'Literate Idris' aliases = ['lidr', 'literate-idris', 'lidris'] filenames = ['*.lidr'] mimetypes = ['text/x-literate-idris'] def __init__(self, **options): hslexer = IdrisLexer(**options) LiterateLexer.__init__(self, hslexer, **options) class LiterateAgdaLexer(LiterateLexer): """ For Literate Agda source. Additional options accepted: `litstyle` If given, must be ``"bird"`` or ``"latex"``. If not given, the style is autodetected: if the first non-whitespace character in the source is a backslash or percent character, LaTeX is assumed, else Bird. .. versionadded:: 2.0 """ name = 'Literate Agda' aliases = ['lagda', 'literate-agda'] filenames = ['*.lagda'] mimetypes = ['text/x-literate-agda'] def __init__(self, **options): agdalexer = AgdaLexer(**options) LiterateLexer.__init__(self, agdalexer, litstyle='latex', **options) class LiterateCryptolLexer(LiterateLexer): """ For Literate Cryptol (Bird-style or LaTeX) source. Additional options accepted: `litstyle` If given, must be ``"bird"`` or ``"latex"``. If not given, the style is autodetected: if the first non-whitespace character in the source is a backslash or percent character, LaTeX is assumed, else Bird. .. versionadded:: 2.0 """ name = 'Literate Cryptol' aliases = ['lcry', 'literate-cryptol', 'lcryptol'] filenames = ['*.lcry'] mimetypes = ['text/x-literate-cryptol'] def __init__(self, **options): crylexer = CryptolLexer(**options) LiterateLexer.__init__(self, crylexer, **options) class KokaLexer(RegexLexer): """ Lexer for the `Koka <http://koka.codeplex.com>`_ language. .. versionadded:: 1.6 """ name = 'Koka' aliases = ['koka'] filenames = ['*.kk', '*.kki'] mimetypes = ['text/x-koka'] keywords = [ 'infix', 'infixr', 'infixl', 'type', 'cotype', 'rectype', 'alias', 'struct', 'con', 'fun', 'function', 'val', 'var', 'external', 'if', 'then', 'else', 'elif', 'return', 'match', 'private', 'public', 'private', 'module', 'import', 'as', 'include', 'inline', 'rec', 'try', 'yield', 'enum', 'interface', 'instance', ] # keywords that are followed by a type typeStartKeywords = [ 'type', 'cotype', 'rectype', 'alias', 'struct', 'enum', ] # keywords valid in a type typekeywords = [ 'forall', 'exists', 'some', 'with', ] # builtin names and special names builtin = [ 'for', 'while', 'repeat', 'foreach', 'foreach-indexed', 'error', 'catch', 'finally', 'cs', 'js', 'file', 'ref', 'assigned', ] # symbols that can be in an operator symbols = r'[$%&*+@!/\\^~=.:\-?|<>]+' # symbol boundary: an operator keyword should not be followed by any of these sboundary = '(?!'+symbols+')' # name boundary: a keyword should not be followed by any of these boundary = '(?![\w/])' # koka token abstractions tokenType = Name.Attribute tokenTypeDef = Name.Class tokenConstructor = Generic.Emph # main lexer tokens = { 'root': [ include('whitespace'), # go into type mode (r'::?' + sboundary, tokenType, 'type'), (r'(alias)(\s+)([a-z]\w*)?', bygroups(Keyword, Text, tokenTypeDef), 'alias-type'), (r'(struct)(\s+)([a-z]\w*)?', bygroups(Keyword, Text, tokenTypeDef), 'struct-type'), ((r'(%s)' % '|'.join(typeStartKeywords)) + r'(\s+)([a-z]\w*)?', bygroups(Keyword, Text, tokenTypeDef), 'type'), # special sequences of tokens (we use ?: for non-capturing group as # required by 'bygroups') (r'(module)(\s+)(interface\s+)?((?:[a-z]\w*/)*[a-z]\w*)', bygroups(Keyword, Text, Keyword, Name.Namespace)), (r'(import)(\s+)((?:[a-z]\w*/)*[a-z]\w*)' r'(?:(\s*)(=)(\s*)((?:qualified\s*)?)' r'((?:[a-z]\w*/)*[a-z]\w*))?', bygroups(Keyword, Text, Name.Namespace, Text, Keyword, Text, Keyword, Name.Namespace)), (r'(^(?:(?:public|private)\s*)?(?:function|fun|val))' r'(\s+)([a-z]\w*|\((?:' + symbols + r'|/)\))', bygroups(Keyword, Text, Name.Function)), (r'(^(?:(?:public|private)\s*)?external)(\s+)(inline\s+)?' r'([a-z]\w*|\((?:' + symbols + r'|/)\))', bygroups(Keyword, Text, Keyword, Name.Function)), # keywords (r'(%s)' % '|'.join(typekeywords) + boundary, Keyword.Type), (r'(%s)' % '|'.join(keywords) + boundary, Keyword), (r'(%s)' % '|'.join(builtin) + boundary, Keyword.Pseudo), (r'::?|:=|\->|[=.]' + sboundary, Keyword), # names (r'((?:[a-z]\w*/)*)([A-Z]\w*)', bygroups(Name.Namespace, tokenConstructor)), (r'((?:[a-z]\w*/)*)([a-z]\w*)', bygroups(Name.Namespace, Name)), (r'((?:[a-z]\w*/)*)(\((?:' + symbols + r'|/)\))', bygroups(Name.Namespace, Name)), (r'_\w*', Name.Variable), # literal string (r'@"', String.Double, 'litstring'), # operators (symbols + "|/(?![*/])", Operator), (r'`', Operator), (r'[{}()\[\];,]', Punctuation), # literals. No check for literal characters with len > 1 (r'[0-9]+\.[0-9]+([eE][\-+]?[0-9]+)?', Number.Float), (r'0[xX][0-9a-fA-F]+', Number.Hex), (r'[0-9]+', Number.Integer), (r"'", String.Char, 'char'), (r'"', String.Double, 'string'), ], # type started by alias 'alias-type': [ (r'=', Keyword), include('type') ], # type started by struct 'struct-type': [ (r'(?=\((?!,*\)))', Punctuation, '#pop'), include('type') ], # type started by colon 'type': [ (r'[(\[<]', tokenType, 'type-nested'), include('type-content') ], # type nested in brackets: can contain parameters, comma etc. 'type-nested': [ (r'[)\]>]', tokenType, '#pop'), (r'[(\[<]', tokenType, 'type-nested'), (r',', tokenType), (r'([a-z]\w*)(\s*)(:)(?!:)', bygroups(Name, Text, tokenType)), # parameter name include('type-content') ], # shared contents of a type 'type-content': [ include('whitespace'), # keywords (r'(%s)' % '|'.join(typekeywords) + boundary, Keyword), (r'(?=((%s)' % '|'.join(keywords) + boundary + '))', Keyword, '#pop'), # need to match because names overlap... # kinds (r'[EPHVX]' + boundary, tokenType), # type names (r'[a-z][0-9]*(?![\w/])', tokenType), (r'_\w*', tokenType.Variable), # Generic.Emph (r'((?:[a-z]\w*/)*)([A-Z]\w*)', bygroups(Name.Namespace, tokenType)), (r'((?:[a-z]\w*/)*)([a-z]\w+)', bygroups(Name.Namespace, tokenType)), # type keyword operators (r'::|->|[.:|]', tokenType), # catchall default('#pop') ], # comments and literals 'whitespace': [ (r'\n\s*#.*$', Comment.Preproc), (r'\s+', Text), (r'/\*', Comment.Multiline, 'comment'), (r'//.*$', Comment.Single) ], 'comment': [ (r'[^/*]+', Comment.Multiline), (r'/\*', Comment.Multiline, '#push'), (r'\*/', Comment.Multiline, '#pop'), (r'[*/]', Comment.Multiline), ], 'litstring': [ (r'[^"]+', String.Double), (r'""', String.Escape), (r'"', String.Double, '#pop'), ], 'string': [ (r'[^\\"\n]+', String.Double), include('escape-sequence'), (r'["\n]', String.Double, '#pop'), ], 'char': [ (r'[^\\\'\n]+', String.Char), include('escape-sequence'), (r'[\'\n]', String.Char, '#pop'), ], 'escape-sequence': [ (r'\\[nrt\\"\']', String.Escape), (r'\\x[0-9a-fA-F]{2}', String.Escape), (r'\\u[0-9a-fA-F]{4}', String.Escape), # Yes, \U literals are 6 hex digits. (r'\\U[0-9a-fA-F]{6}', String.Escape) ] }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__init__.py | File | 10.65 KB | 0644 |
|
__init__.pyc | File | 10.55 KB | 0644 |
|
_asy_builtins.py | File | 26.68 KB | 0644 |
|
_asy_builtins.pyc | File | 32.76 KB | 0644 |
|
_cl_builtins.py | File | 13.72 KB | 0644 |
|
_cl_builtins.pyc | File | 25.25 KB | 0644 |
|
_cocoa_builtins.py | File | 39.04 KB | 0644 |
|
_cocoa_builtins.pyc | File | 45.61 KB | 0644 |
|
_csound_builtins.py | File | 21.14 KB | 0644 |
|
_csound_builtins.pyc | File | 24.04 KB | 0644 |
|
_lasso_builtins.py | File | 131.38 KB | 0644 |
|
_lasso_builtins.pyc | File | 121.02 KB | 0644 |
|
_lua_builtins.py | File | 8.14 KB | 0644 |
|
_lua_builtins.pyc | File | 10.73 KB | 0644 |
|
_mapping.py | File | 53.43 KB | 0644 |
|
_mapping.pyc | File | 77.25 KB | 0644 |
|
_mql_builtins.py | File | 24.16 KB | 0644 |
|
_mql_builtins.pyc | File | 28.95 KB | 0644 |
|
_openedge_builtins.py | File | 47.23 KB | 0644 |
|
_openedge_builtins.pyc | File | 80.1 KB | 0644 |
|
_php_builtins.py | File | 150.75 KB | 0644 |
|
_php_builtins.pyc | File | 134.8 KB | 0644 |
|
_postgres_builtins.py | File | 10.95 KB | 0644 |
|
_postgres_builtins.pyc | File | 13.06 KB | 0644 |
|
_scilab_builtins.py | File | 51.18 KB | 0644 |
|
_scilab_builtins.pyc | File | 71.95 KB | 0644 |
|
_sourcemod_builtins.py | File | 26.48 KB | 0644 |
|
_sourcemod_builtins.pyc | File | 31.43 KB | 0644 |
|
_stan_builtins.py | File | 9.88 KB | 0644 |
|
_stan_builtins.pyc | File | 11.97 KB | 0644 |
|
_stata_builtins.py | File | 24.55 KB | 0644 |
|
_stata_builtins.pyc | File | 36.1 KB | 0644 |
|
_tsql_builtins.py | File | 15.12 KB | 0644 |
|
_tsql_builtins.pyc | File | 15.99 KB | 0644 |
|
_vim_builtins.py | File | 55.75 KB | 0644 |
|
_vim_builtins.pyc | File | 62.26 KB | 0644 |
|
actionscript.py | File | 10.92 KB | 0644 |
|
actionscript.pyc | File | 11.36 KB | 0644 |
|
agile.py | File | 900 B | 0644 |
|
agile.pyc | File | 1.4 KB | 0644 |
|
algebra.py | File | 7.03 KB | 0644 |
|
algebra.pyc | File | 7.76 KB | 0644 |
|
ambient.py | File | 2.5 KB | 0644 |
|
ambient.pyc | File | 2.87 KB | 0644 |
|
ampl.py | File | 4.02 KB | 0644 |
|
ampl.pyc | File | 4.61 KB | 0644 |
|
apl.py | File | 3.09 KB | 0644 |
|
apl.pyc | File | 1.99 KB | 0644 |
|
archetype.py | File | 10.87 KB | 0644 |
|
archetype.pyc | File | 7.44 KB | 0644 |
|
asm.py | File | 24.67 KB | 0644 |
|
asm.pyc | File | 23.89 KB | 0644 |
|
automation.py | File | 19.19 KB | 0644 |
|
automation.pyc | File | 16.59 KB | 0644 |
|
basic.py | File | 19.83 KB | 0644 |
|
basic.pyc | File | 17.63 KB | 0644 |
|
bibtex.py | File | 4.61 KB | 0644 |
|
bibtex.pyc | File | 4.43 KB | 0644 |
|
business.py | File | 27.02 KB | 0644 |
|
business.pyc | File | 25.07 KB | 0644 |
|
c_cpp.py | File | 10.28 KB | 0644 |
|
c_cpp.pyc | File | 9.72 KB | 0644 |
|
c_like.py | File | 23.56 KB | 0644 |
|
c_like.pyc | File | 26.43 KB | 0644 |
|
capnproto.py | File | 2.14 KB | 0644 |
|
capnproto.pyc | File | 2.02 KB | 0644 |
|
chapel.py | File | 3.43 KB | 0644 |
|
chapel.pyc | File | 3.36 KB | 0644 |
|
clean.py | File | 10.16 KB | 0644 |
|
clean.pyc | File | 8.27 KB | 0644 |
|
compiled.py | File | 1.35 KB | 0644 |
|
compiled.pyc | File | 2.14 KB | 0644 |
|
configs.py | File | 27.6 KB | 0644 |
|
configs.pyc | File | 25.05 KB | 0644 |
|
console.py | File | 4.02 KB | 0644 |
|
console.pyc | File | 3.85 KB | 0644 |
|
crystal.py | File | 16.45 KB | 0644 |
|
crystal.pyc | File | 11.39 KB | 0644 |
|
csound.py | File | 12.25 KB | 0644 |
|
csound.pyc | File | 9.39 KB | 0644 |
|
css.py | File | 30.77 KB | 0644 |
|
css.pyc | File | 37.17 KB | 0644 |
|
d.py | File | 9.31 KB | 0644 |
|
d.pyc | File | 7.69 KB | 0644 |
|
dalvik.py | File | 4.32 KB | 0644 |
|
dalvik.pyc | File | 3.71 KB | 0644 |
|
data.py | File | 18.33 KB | 0644 |
|
data.pyc | File | 12.44 KB | 0644 |
|
diff.py | File | 4.76 KB | 0644 |
|
diff.pyc | File | 4.4 KB | 0644 |
|
dotnet.py | File | 27.02 KB | 0644 |
|
dotnet.pyc | File | 23.13 KB | 0644 |
|
dsls.py | File | 32.55 KB | 0644 |
|
dsls.pyc | File | 31.3 KB | 0644 |
|
dylan.py | File | 10.18 KB | 0644 |
|
dylan.pyc | File | 11.14 KB | 0644 |
|
ecl.py | File | 5.74 KB | 0644 |
|
ecl.pyc | File | 6.7 KB | 0644 |
|
eiffel.py | File | 2.42 KB | 0644 |
|
eiffel.pyc | File | 2.91 KB | 0644 |
|
elm.py | File | 2.93 KB | 0644 |
|
elm.pyc | File | 2.91 KB | 0644 |
|
erlang.py | File | 18.49 KB | 0644 |
|
erlang.pyc | File | 17.2 KB | 0644 |
|
esoteric.py | File | 9.27 KB | 0644 |
|
esoteric.pyc | File | 9.15 KB | 0644 |
|
ezhil.py | File | 2.95 KB | 0644 |
|
ezhil.pyc | File | 3.71 KB | 0644 |
|
factor.py | File | 17.44 KB | 0644 |
|
factor.pyc | File | 23.61 KB | 0644 |
|
fantom.py | File | 9.75 KB | 0644 |
|
fantom.pyc | File | 5.88 KB | 0644 |
|
felix.py | File | 9.19 KB | 0644 |
|
felix.pyc | File | 7.73 KB | 0644 |
|
forth.py | File | 6.98 KB | 0644 |
|
forth.pyc | File | 4.84 KB | 0644 |
|
fortran.py | File | 9.54 KB | 0644 |
|
fortran.pyc | File | 11.16 KB | 0644 |
|
foxpro.py | File | 25.62 KB | 0644 |
|
foxpro.pyc | File | 19.9 KB | 0644 |
|
functional.py | File | 698 B | 0644 |
|
functional.pyc | File | 1.08 KB | 0644 |
|
go.py | File | 3.61 KB | 0644 |
|
go.pyc | File | 3.37 KB | 0644 |
|
grammar_notation.py | File | 6.18 KB | 0644 |
|
grammar_notation.pyc | File | 5.56 KB | 0644 |
|
graph.py | File | 2.31 KB | 0644 |
|
graph.pyc | File | 2.34 KB | 0644 |
|
graphics.py | File | 25.23 KB | 0644 |
|
graphics.pyc | File | 23.52 KB | 0644 |
|
haskell.py | File | 30.49 KB | 0644 |
|
haskell.pyc | File | 23.51 KB | 0644 |
|
haxe.py | File | 30.23 KB | 0644 |
|
haxe.pyc | File | 18.35 KB | 0644 |
|
hdl.py | File | 18.26 KB | 0644 |
|
hdl.pyc | File | 18.96 KB | 0644 |
|
hexdump.py | File | 3.42 KB | 0644 |
|
hexdump.pyc | File | 2.95 KB | 0644 |
|
html.py | File | 18.82 KB | 0644 |
|
html.pyc | File | 15.04 KB | 0644 |
|
idl.py | File | 14.63 KB | 0644 |
|
idl.pyc | File | 18.94 KB | 0644 |
|
igor.py | File | 19.53 KB | 0644 |
|
igor.pyc | File | 24.74 KB | 0644 |
|
inferno.py | File | 3.04 KB | 0644 |
|
inferno.pyc | File | 2.92 KB | 0644 |
|
installers.py | File | 12.56 KB | 0644 |
|
installers.pyc | File | 10.6 KB | 0644 |
|
int_fiction.py | File | 54.47 KB | 0644 |
|
int_fiction.pyc | File | 34.88 KB | 0644 |
|
iolang.py | File | 1.86 KB | 0644 |
|
iolang.pyc | File | 1.94 KB | 0644 |
|
j.py | File | 4.42 KB | 0644 |
|
j.pyc | File | 4.2 KB | 0644 |
|
javascript.py | File | 58.72 KB | 0644 |
|
javascript.pyc | File | 41.33 KB | 0644 |
|
julia.py | File | 13.76 KB | 0644 |
|
julia.pyc | File | 11.5 KB | 0644 |
|
jvm.py | File | 65.18 KB | 0644 |
|
jvm.pyc | File | 50.73 KB | 0644 |
|
lisp.py | File | 137.38 KB | 0644 |
|
lisp.pyc | File | 205.18 KB | 0644 |
|
make.py | File | 7.16 KB | 0644 |
|
make.pyc | File | 5.37 KB | 0644 |
|
markup.py | File | 19.97 KB | 0644 |
|
markup.pyc | File | 17.25 KB | 0644 |
|
math.py | File | 700 B | 0644 |
|
math.pyc | File | 1.09 KB | 0644 |
|
matlab.py | File | 28.47 KB | 0644 |
|
matlab.pyc | File | 30.52 KB | 0644 |
|
ml.py | File | 27.23 KB | 0644 |
|
ml.pyc | File | 14.98 KB | 0644 |
|
modeling.py | File | 12.53 KB | 0644 |
|
modeling.pyc | File | 10.87 KB | 0644 |
|
modula2.py | File | 51.33 KB | 0644 |
|
modula2.pyc | File | 25.89 KB | 0644 |
|
monte.py | File | 6.16 KB | 0644 |
|
monte.pyc | File | 4.94 KB | 0644 |
|
ncl.py | File | 62.49 KB | 0644 |
|
ncl.pyc | File | 67.46 KB | 0644 |
|
nimrod.py | File | 5.05 KB | 0644 |
|
nimrod.pyc | File | 4.74 KB | 0644 |
|
nit.py | File | 2.68 KB | 0644 |
|
nit.pyc | File | 2.99 KB | 0644 |
|
nix.py | File | 3.94 KB | 0644 |
|
nix.pyc | File | 4.28 KB | 0644 |
|
oberon.py | File | 3.65 KB | 0644 |
|
oberon.pyc | File | 3.41 KB | 0644 |
|
objective.py | File | 22.22 KB | 0644 |
|
objective.pyc | File | 19.74 KB | 0644 |
|
ooc.py | File | 2.93 KB | 0644 |
|
ooc.pyc | File | 3 KB | 0644 |
|
other.py | File | 1.73 KB | 0644 |
|
other.pyc | File | 2.71 KB | 0644 |
|
parasail.py | File | 2.67 KB | 0644 |
|
parasail.pyc | File | 2.58 KB | 0644 |
|
parsers.py | File | 26.94 KB | 0644 |
|
parsers.pyc | File | 23.14 KB | 0644 |
|
pascal.py | File | 31.88 KB | 0644 |
|
pascal.pyc | File | 29.58 KB | 0644 |
|
pawn.py | File | 7.9 KB | 0644 |
|
pawn.pyc | File | 7.16 KB | 0644 |
|
perl.py | File | 31.26 KB | 0644 |
|
perl.pyc | File | 29.81 KB | 0644 |
|
php.py | File | 10.48 KB | 0644 |
|
php.pyc | File | 9.26 KB | 0644 |
|
praat.py | File | 12.26 KB | 0644 |
|
praat.pyc | File | 11.46 KB | 0644 |
|
prolog.py | File | 11.78 KB | 0644 |
|
prolog.pyc | File | 8.05 KB | 0644 |
|
python.py | File | 41.39 KB | 0644 |
|
python.pyc | File | 36.48 KB | 0644 |
|
qvt.py | File | 5.97 KB | 0644 |
|
qvt.pyc | File | 5.27 KB | 0644 |
|
r.py | File | 23.2 KB | 0644 |
|
r.pyc | File | 32.97 KB | 0644 |
|
rdf.py | File | 9.18 KB | 0644 |
|
rdf.pyc | File | 6.45 KB | 0644 |
|
rebol.py | File | 18.18 KB | 0644 |
|
rebol.pyc | File | 13.49 KB | 0644 |
|
resource.py | File | 2.86 KB | 0644 |
|
resource.pyc | File | 2.86 KB | 0644 |
|
rnc.py | File | 1.94 KB | 0644 |
|
rnc.pyc | File | 1.78 KB | 0644 |
|
roboconf.py | File | 2.02 KB | 0644 |
|
roboconf.pyc | File | 2.34 KB | 0644 |
|
robotframework.py | File | 18.3 KB | 0644 |
|
robotframework.pyc | File | 25.03 KB | 0644 |
|
ruby.py | File | 21.62 KB | 0644 |
|
ruby.pyc | File | 16.91 KB | 0644 |
|
rust.py | File | 7.51 KB | 0644 |
|
rust.pyc | File | 5.67 KB | 0644 |
|
sas.py | File | 9.23 KB | 0644 |
|
sas.pyc | File | 9.63 KB | 0644 |
|
scripting.py | File | 66.17 KB | 0644 |
|
scripting.pyc | File | 67.97 KB | 0644 |
|
shell.py | File | 30.69 KB | 0644 |
|
shell.pyc | File | 24.13 KB | 0644 |
|
smalltalk.py | File | 7.05 KB | 0644 |
|
smalltalk.pyc | File | 5.24 KB | 0644 |
|
smv.py | File | 2.74 KB | 0644 |
|
smv.pyc | File | 3.16 KB | 0644 |
|
snobol.py | File | 2.69 KB | 0644 |
|
snobol.pyc | File | 2.27 KB | 0644 |
|
special.py | File | 3.08 KB | 0644 |
|
special.pyc | File | 3.86 KB | 0644 |
|
sql.py | File | 28.75 KB | 0644 |
|
sql.pyc | File | 28.6 KB | 0644 |
|
stata.py | File | 3.54 KB | 0644 |
|
stata.pyc | File | 2.7 KB | 0644 |
|
supercollider.py | File | 3.43 KB | 0644 |
|
supercollider.pyc | File | 3.83 KB | 0644 |
|
tcl.py | File | 5.27 KB | 0644 |
|
tcl.pyc | File | 5.1 KB | 0644 |
|
templates.py | File | 71.73 KB | 0644 |
|
templates.pyc | File | 74.43 KB | 0644 |
|
testing.py | File | 10.5 KB | 0644 |
|
testing.pyc | File | 8.42 KB | 0644 |
|
text.py | File | 977 B | 0644 |
|
text.pyc | File | 1.54 KB | 0644 |
|
textedit.py | File | 5.92 KB | 0644 |
|
textedit.pyc | File | 5.79 KB | 0644 |
|
textfmts.py | File | 10.6 KB | 0644 |
|
textfmts.pyc | File | 8.41 KB | 0644 |
|
theorem.py | File | 18.59 KB | 0644 |
|
theorem.pyc | File | 20.07 KB | 0644 |
|
trafficscript.py | File | 1.51 KB | 0644 |
|
trafficscript.pyc | File | 1.8 KB | 0644 |
|
typoscript.py | File | 8.2 KB | 0644 |
|
typoscript.pyc | File | 6.41 KB | 0644 |
|
urbi.py | File | 5.62 KB | 0644 |
|
urbi.pyc | File | 5.48 KB | 0644 |
|
varnish.py | File | 7.1 KB | 0644 |
|
varnish.pyc | File | 7.15 KB | 0644 |
|
verification.py | File | 3.62 KB | 0644 |
|
verification.pyc | File | 3.9 KB | 0644 |
|
web.py | File | 918 B | 0644 |
|
web.pyc | File | 1.4 KB | 0644 |
|
webmisc.py | File | 38.96 KB | 0644 |
|
webmisc.pyc | File | 28.98 KB | 0644 |
|
whiley.py | File | 3.92 KB | 0644 |
|
whiley.pyc | File | 3.23 KB | 0644 |
|
x10.py | File | 1.92 KB | 0644 |
|
x10.pyc | File | 2.6 KB | 0644 |
|