class CharmciLexer(CppLexer): """ For `Charm++ <https://charm.cs.illinois.edu>`_ interface files (.ci). .. versionadded:: 2.4 """ name = 'Charmci' aliases = ['charmci'] filenames = ['*.ci'] mimetypes = [] tokens = { 'statements': [ (r'(module)(\s+)', bygroups(Keyword, Text), 'classname'), (words(('mainmodule', 'mainchare', 'chare', 'array', 'group', 'nodegroup', 'message', 'conditional')), Keyword), (words(('entry', 'aggregate', 'threaded', 'sync', 'exclusive', 'nokeep', 'notrace', 'immediate', 'expedited', 'inline', 'local', 'python', 'accel', 'readwrite', 'writeonly', 'accelblock', 'memcritical', 'packed', 'varsize', 'initproc', 'initnode', 'initcall', 'stacksize', 'createhere', 'createhome', 'reductiontarget', 'iget', 'nocopy', 'mutable', 'migratable', 'readonly')), Keyword), inherit, ], }
class RoboconfInstancesLexer(RegexLexer): """ Lexer for `Roboconf <http://roboconf.net/en/roboconf.html>`_ instances files. .. versionadded:: 2.1 """ name = 'Roboconf Instances' aliases = ['roboconf-instances'] filenames = ['*.instances'] flags = re.IGNORECASE | re.MULTILINE tokens = { 'root': [ # Skip white spaces (r'\s+', Text), # Keywords (words(('instance of', 'import'), suffix=r'\s*\b', prefix=r'\b'), Keyword), (words(('name', 'count'), suffix=r's*:?', prefix=r'\b'), Name), (r'\s*[\w.-]+\s*:', Name), # Comments (r'#.*\n', Comment), # Default (r'[^#]', Text), (r'.*\n', Text) ] }
class NesCLexer(CLexer): """ For `nesC <https://github.com/tinyos/nesc>`_ source code with preprocessor directives. .. versionadded:: 2.0 """ name = 'nesC' aliases = ['nesc'] filenames = ['*.nc'] mimetypes = ['text/x-nescsrc'] tokens = { 'statements': [ (words(('abstract', 'as', 'async', 'atomic', 'call', 'command', 'component', 'components', 'configuration', 'event', 'extends', 'generic', 'implementation', 'includes', 'interface', 'module', 'new', 'norace', 'post', 'provides', 'signal', 'task', 'uses'), suffix=r'\b'), Keyword), (words(('nx_struct', 'nx_union', 'nx_int8_t', 'nx_int16_t', 'nx_int32_t', 'nx_int64_t', 'nx_uint8_t', 'nx_uint16_t', 'nx_uint32_t', 'nx_uint64_t'), suffix=r'\b'), Keyword.Type), inherit, ], }
class CAmkESLexer(RegexLexer): """ Basic lexer for the input language for the `CAmkES <https://sel4.systems/CAmkES/>`_ component platform. .. versionadded:: 2.1 """ name = 'CAmkES' aliases = ['camkes', 'idl4'] filenames = ['*.camkes', '*.idl4'] tokens = { 'root': [ # C pre-processor directive (r'^\s*#.*\n', Comment.Preproc), # Whitespace, comments (r'\s+', Text), (r'/\*(.|\n)*?\*/', Comment), (r'//.*\n', Comment), (r'[\[(){},.;\]]', Punctuation), (r'[~!%^&*+=|?:<>/-]', Operator), (words(('assembly', 'attribute', 'component', 'composition', 'configuration', 'connection', 'connector', 'consumes', 'control', 'dataport', 'Dataport', 'Dataports', 'emits', 'event', 'Event', 'Events', 'export', 'from', 'group', 'hardware', 'has', 'interface', 'Interface', 'maybe', 'procedure', 'Procedure', 'Procedures', 'provides', 'template', 'thread', 'threads', 'to', 'uses', 'with'), suffix=r'\b'), Keyword), (words(('bool', 'boolean', 'Buf', 'char', 'character', 'double', 'float', 'in', 'inout', 'int', 'int16_6', 'int32_t', 'int64_t', 'int8_t', 'integer', 'mutex', 'out', 'real', 'refin', 'semaphore', 'signed', 'string', 'struct', 'uint16_t', 'uint32_t', 'uint64_t', 'uint8_t', 'uintptr_t', 'unsigned', 'void'), suffix=r'\b'), Keyword.Type), # Recognised attributes (r'[a-zA-Z_]\w*_(priority|domain|buffer)', Keyword.Reserved), (words(('dma_pool', 'from_access', 'to_access'), suffix=r'\b'), Keyword.Reserved), # CAmkES-level include (r'import\s+(<[^>]*>|"[^"]*");', Comment.Preproc), # C-level include (r'include\s+(<[^>]*>|"[^"]*");', Comment.Preproc), # Literals (r'0[xX][\da-fA-F]+', Number.Hex), (r'-?[\d]+', Number), (r'-?[\d]+\.[\d]+', Number.Float), (r'"[^"]*"', String), (r'[Tt]rue|[Ff]alse', Name.Builtin), # Identifiers (r'[a-zA-Z_]\w*', Name), ], }
class RoboconfGraphLexer(RegexLexer): """ Lexer for `Roboconf <http://roboconf.net/en/roboconf.html>`_ graph files. .. versionadded:: 2.1 """ name = 'Roboconf Graph' aliases = ['roboconf-graph'] filenames = ['*.graph'] flags = re.IGNORECASE | re.MULTILINE tokens = { 'root': [ # Skip white spaces (r'\s+', Text), # There is one operator (r'=', Operator), # Keywords (words(('facet', 'import'), suffix=r'\s*\b', prefix=r'\b'), Keyword), (words(( 'installer', 'extends', 'exports', 'imports', 'facets', 'children'), suffix=r'\s*:?', prefix=r'\b'), Name), # Comments (r'#.*\n', Comment), # Default (r'[^#]', Text), (r'.*\n', Text) ] }
class ProtoBufLexer(RegexLexer): """ Lexer for `Protocol Buffer <http://code.google.com/p/protobuf/>`_ definition files. .. versionadded:: 1.4 """ name = 'Protocol Buffer' aliases = ['protobuf', 'proto'] filenames = ['*.proto'] tokens = { 'root': [ (r'[ \t]+', Text), (r'[,;{}\[\]()<>]', Punctuation), (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single), (r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment.Multiline), (words(('import', 'option', 'optional', 'required', 'repeated', 'reserved', 'default', 'packed', 'ctype', 'extensions', 'to', 'max', 'rpc', 'returns', 'oneof'), prefix=r'\b', suffix=r'\b'), Keyword), (words(('int32', 'int64', 'uint32', 'uint64', 'sint32', 'sint64', 'fixed32', 'fixed64', 'sfixed32', 'sfixed64', 'float', 'double', 'bool', 'string', 'bytes'), suffix=r'\b'), Keyword.Type), (r'(true|false)\b', Keyword.Constant), (r'(package)(\s+)', bygroups(Keyword.Namespace, Text), 'package'), (r'(message|extend)(\s+)', bygroups(Keyword.Declaration, Text), 'message'), (r'(enum|group|service)(\s+)', bygroups(Keyword.Declaration, Text), 'type'), (r'\".*?\"', String), (r'\'.*?\'', String), (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float), (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), (r'(\-?(inf|nan))\b', Number.Float), (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex), (r'0[0-7]+[LlUu]*', Number.Oct), (r'\d+[LlUu]*', Number.Integer), (r'[+-=]', Operator), (r'([a-zA-Z_][\w.]*)([ \t]*)(=)', bygroups(Name.Attribute, Text, Operator)), (r'[a-zA-Z_][\w.]*', Name), ], 'package': [ (r'[a-zA-Z_]\w*', Name.Namespace, '#pop'), default('#pop'), ], 'message': [ (r'[a-zA-Z_]\w*', Name.Class, '#pop'), default('#pop'), ], 'type': [ (r'[a-zA-Z_]\w*', Name, '#pop'), default('#pop'), ], }
class CppLexer(CFamilyLexer): """ For C++ source code with preprocessor directives. """ name = 'C++' aliases = ['cpp', 'c++'] filenames = [ '*.cpp', '*.hpp', '*.c++', '*.h++', '*.cc', '*.hh', '*.cxx', '*.hxx', '*.C', '*.H', '*.cp', '*.CPP' ] mimetypes = ['text/x-c++hdr', 'text/x-c++src'] priority = 0.1 tokens = { 'statements': [ (words( ('catch', 'const_cast', 'delete', 'dynamic_cast', 'explicit', 'export', 'friend', 'mutable', 'namespace', 'new', 'operator', 'private', 'protected', 'public', 'reinterpret_cast', 'restrict', 'static_cast', 'template', 'this', 'throw', 'throws', 'try', 'typeid', 'typename', 'using', 'virtual', 'constexpr', 'nullptr', 'decltype', 'thread_local', 'alignas', 'alignof', 'static_assert', 'noexcept', 'override', 'final'), suffix=r'\b'), Keyword), (r'char(16_t|32_t)\b', Keyword.Type), (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), # C++11 raw strings (r'(R)(")([^\\()\s]{,16})(\()((?:.|\n)*?)(\)\3)(")', bygroups(String.Affix, String, String.Delimiter, String.Delimiter, String, String.Delimiter, String)), # C++11 UTF-8/16/32 strings (r'(u8|u|U)(")', bygroups(String.Affix, String), 'string'), inherit, ], 'root': [ inherit, # C++ Microsoft-isms (words(('virtual_inheritance', 'uuidof', 'super', 'single_inheritance', 'multiple_inheritance', 'interface', 'event'), prefix=r'__', suffix=r'\b'), Keyword.Reserved), # Offload C++ extensions, http://offload.codeplay.com/ (r'__(offload|blockingoffload|outer)\b', Keyword.Pseudo), ], 'classname': [ (r'[a-zA-Z_]\w*', Name.Class, '#pop'), # template specification (r'\s*(?=>)', Text, '#pop'), ], } def analyse_text(text): if re.search('#include <[a-z_]+>', text): return 0.2 if re.search('using namespace ', text): return 0.4
class CapDLLexer(RegexLexer): """ Basic lexer for `CapDL <https://ssrg.nicta.com.au/publications/nictaabstracts/Kuz_KLW_10.abstract.pml>`_. The source of the primary tool that reads such specifications is available at https://github.com/seL4/capdl/tree/master/capDL-tool. Note that this lexer only supports a subset of the grammar. For example, identifiers can shadow type names, but these instances are currently incorrectly highlighted as types. Supporting this would need a stateful lexer that is considered unnecessarily complex for now. .. versionadded:: 2.2 """ name = 'CapDL' aliases = ['capdl'] filenames = ['*.cdl'] tokens = { 'root': [ # C pre-processor directive (r'^\s*#.*\n', Comment.Preproc), # Whitespace, comments (r'\s+', Text), (r'/\*(.|\n)*?\*/', Comment), (r'(//|--).*\n', Comment), (r'[<>\[(){},:;=\]]', Punctuation), (r'\.\.', Punctuation), (words(('arch', 'arm11', 'caps', 'child_of', 'ia32', 'irq', 'maps', 'objects'), suffix=r'\b'), Keyword), (words(('aep', 'asid_pool', 'cnode', 'ep', 'frame', 'io_device', 'io_ports', 'io_pt', 'notification', 'pd', 'pt', 'tcb', 'ut', 'vcpu'), suffix=r'\b'), Keyword.Type), # Properties (words(('asid', 'addr', 'badge', 'cached', 'dom', 'domainID', 'elf', 'fault_ep', 'G', 'guard', 'guard_size', 'init', 'ip', 'prio', 'sp', 'R', 'RG', 'RX', 'RW', 'RWG', 'RWX', 'W', 'WG', 'WX', 'level', 'masked', 'master_reply', 'paddr', 'ports', 'reply', 'uncached'), suffix=r'\b'), Keyword.Reserved), # Literals (r'0[xX][\da-fA-F]+', Number.Hex), (r'\d+(\.\d+)?(k|M)?', Number), (words(('bits', ), suffix=r'\b'), Number), (words(('cspace', 'vspace', 'reply_slot', 'caller_slot', 'ipc_buffer_slot'), suffix=r'\b'), Number), # Identifiers (r'[a-zA-Z_][-@\.\w]*', Name), ], }
class PlPgsqlLexer(PostgresBase, RegexLexer): """ Handle the extra syntax in Pl/pgSQL language. .. versionadded:: 1.5 """ name = 'PL/pgSQL' aliases = ['plpgsql'] mimetypes = ['text/x-plpgsql'] flags = re.IGNORECASE tokens = {k: l[:] for (k, l) in iteritems(PostgresLexer.tokens)} # extend the keywords list for i, pattern in enumerate(tokens['root']): if pattern[1] == Keyword: tokens['root'][i] = (words(KEYWORDS + PLPGSQL_KEYWORDS, suffix=r'\b'), Keyword) del i break else: assert 0, "SQL keywords not found" # Add specific PL/pgSQL rules (before the SQL ones) tokens['root'][:0] = [ (r'\%[a-z]\w*\b', Name.Builtin), # actually, a datatype (r':=', Operator), (r'\<\<[a-z]\w*\>\>', Name.Label), (r'\#[a-z]\w*\b', Keyword.Pseudo), # #variable_conflict ]
class BCLexer(RegexLexer): """ A `BC <https://www.gnu.org/software/bc/>`_ lexer. .. versionadded:: 2.1 """ name = 'BC' aliases = ['bc'] filenames = ['*.bc'] tokens = { 'root': [ (r'/\*', Comment.Multiline, 'comment'), (r'"(?:[^"\\]|\\.)*"', String), (r'[{}();,]', Punctuation), (words(('if', 'else', 'while', 'for', 'break', 'continue', 'halt', 'return', 'define', 'auto', 'print', 'read', 'length', 'scale', 'sqrt', 'limits', 'quit', 'warranty'), suffix=r'\b'), Keyword), (r'\+\+|--|\|\||&&|' r'([-<>+*%\^/!=])=?', Operator), # bc doesn't support exponential (r'[0-9]+(\.[0-9]*)?', Number), (r'\.[0-9]+', Number), (r'.', Text) ], 'comment': [ (r'[^*/]+', Comment.Multiline), (r'\*/', Comment.Multiline, '#pop'), (r'[*/]', Comment.Multiline) ], }
class SilverLexer(RegexLexer): """ For `Silver <https://bitbucket.org/viperproject/silver>`_ source code. .. versionadded:: 2.2 """ name = 'Silver' aliases = ['silver'] filenames = ['*.sil', '*.vpr'] tokens = { 'root': [ # Whitespace and Comments (r'\n', Whitespace), (r'\s+', Whitespace), (r'//[/!](.*?)\n', Comment.Doc), (r'//(.*?)\n', Comment.Single), (r'/\*', Comment.Multiline, 'comment'), (words(('result', 'true', 'false', 'null', 'method', 'function', 'predicate', 'program', 'domain', 'axiom', 'var', 'returns', 'field', 'define', 'requires', 'ensures', 'invariant', 'fold', 'unfold', 'inhale', 'exhale', 'new', 'assert', 'assume', 'goto', 'while', 'if', 'elseif', 'else', 'fresh', 'constraining', 'Seq', 'Set', 'Multiset', 'union', 'intersection', 'setminus', 'subset', 'unfolding', 'in', 'old', 'forall', 'exists', 'acc', 'wildcard', 'write', 'none', 'epsilon', 'perm', 'unique', 'apply', 'package', 'folding', 'label', 'forperm'), suffix=r'\b'), Keyword), (words(('Int', 'Perm', 'Bool', 'Ref'), suffix=r'\b'), Keyword.Type), include('numbers'), (r'[!%&*+=|?:<>/\-\[\]]', Operator), (r'([{}():;,.])', Punctuation), # Identifier (r'[\w$]\w*', Name), ], 'comment': [ (r'[^*/]+', Comment.Multiline), (r'/\*', Comment.Multiline, '#push'), (r'\*/', Comment.Multiline, '#pop'), (r'[*/]', Comment.Multiline), ], 'numbers': [ (r'[0-9]+', Number.Integer), ], }
class RslLexer(RegexLexer): """ `RSL <http://en.wikipedia.org/wiki/RAISE>`_ is the formal specification language used in RAISE (Rigorous Approach to Industrial Software Engineering) method. .. versionadded:: 2.0 """ name = 'RSL' aliases = ['rsl'] filenames = ['*.rsl'] mimetypes = ['text/rsl'] flags = re.MULTILINE | re.DOTALL tokens = { 'root': [ (words( ('Bool', 'Char', 'Int', 'Nat', 'Real', 'Text', 'Unit', 'abs', 'all', 'always', 'any', 'as', 'axiom', 'card', 'case', 'channel', 'chaos', 'class', 'devt_relation', 'dom', 'elems', 'else', 'elif', 'end', 'exists', 'extend', 'false', 'for', 'hd', 'hide', 'if', 'in', 'is', 'inds', 'initialise', 'int', 'inter', 'isin', 'len', 'let', 'local', 'ltl_assertion', 'object', 'of', 'out', 'post', 'pre', 'read', 'real', 'rng', 'scheme', 'skip', 'stop', 'swap', 'then', 'theory', 'test_case', 'tl', 'transition_system', 'true', 'type', 'union', 'until', 'use', 'value', 'variable', 'while', 'with', 'write', '~isin', '-inflist', '-infset', '-list', '-set'), prefix=r'\b', suffix=r'\b'), Keyword), (r'(variable|value)\b', Keyword.Declaration), (r'--.*?\n', Comment), (r'<:.*?:>', Comment), (r'\{!.*?!\}', Comment), (r'/\*.*?\*/', Comment), (r'^[ \t]*([\w]+)[ \t]*:[^:]', Name.Function), (r'(^[ \t]*)([\w]+)([ \t]*\([\w\s,]*\)[ \t]*)(is|as)', bygroups(Text, Name.Function, Text, Keyword)), (r'\b[A-Z]\w*\b', Keyword.Type), (r'(true|false)\b', Keyword.Constant), (r'".*"', String), (r'\'.\'', String.Char), (r'(><|->|-m->|/\\|<=|<<=|<\.|\|\||\|\^\||-~->|-~m->|\\/|>=|>>|' r'\.>|\+\+|-\\|<->|=>|:-|~=|\*\*|<<|>>=|\+>|!!|\|=\||#)', Operator), (r'[0-9]+\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), (r'0x[0-9a-f]+', Number.Hex), (r'[0-9]+', Number.Integer), (r'.', Text), ], } def analyse_text(text): """ Check for the most common text in the beginning of a RSL file. """ if re.search(r'scheme\s*.*?=\s*class\s*type', text, re.I) is not None: return 1.0
class MaqlLexer(RegexLexer): """ Lexer for `GoodData MAQL <https://secure.gooddata.com/docs/html/advanced.metric.tutorial.html>`_ scripts. .. versionadded:: 1.4 """ name = 'MAQL' aliases = ['maql'] filenames = ['*.maql'] mimetypes = ['text/x-gooddata-maql', 'application/x-gooddata-maql'] flags = re.IGNORECASE tokens = { 'root': [ # IDENTITY (r'IDENTIFIER\b', Name.Builtin), # IDENTIFIER (r'\{[^}]+\}', Name.Variable), # NUMBER (r'[0-9]+(?:\.[0-9]+)?(?:e[+-]?[0-9]{1,3})?', Number), # STRING (r'"', String, 'string-literal'), # RELATION (r'\<\>|\!\=', Operator), (r'\=|\>\=|\>|\<\=|\<', Operator), # := (r'\:\=', Operator), # OBJECT (r'\[[^]]+\]', Name.Variable.Class), # keywords (words( ('DIMENSION', 'DIMENSIONS', 'BOTTOM', 'METRIC', 'COUNT', 'OTHER', 'FACT', 'WITH', 'TOP', 'OR', 'ATTRIBUTE', 'CREATE', 'PARENT', 'FALSE', 'ROW', 'ROWS', 'FROM', 'ALL', 'AS', 'PF', 'COLUMN', 'COLUMNS', 'DEFINE', 'REPORT', 'LIMIT', 'TABLE', 'LIKE', 'AND', 'BY', 'BETWEEN', 'EXCEPT', 'SELECT', 'MATCH', 'WHERE', 'TRUE', 'FOR', 'IN', 'WITHOUT', 'FILTER', 'ALIAS', 'WHEN', 'NOT', 'ON', 'KEYS', 'KEY', 'FULLSET', 'PRIMARY', 'LABELS', 'LABEL', 'VISUAL', 'TITLE', 'DESCRIPTION', 'FOLDER', 'ALTER', 'DROP', 'ADD', 'DATASET', 'DATATYPE', 'INT', 'BIGINT', 'DOUBLE', 'DATE', 'VARCHAR', 'DECIMAL', 'SYNCHRONIZE', 'TYPE', 'DEFAULT', 'ORDER', 'ASC', 'DESC', 'HYPERLINK', 'INCLUDE', 'TEMPLATE', 'MODIFY'), suffix=r'\b'), Keyword), # FUNCNAME (r'[a-z]\w*\b', Name.Function), # Comments (r'#.*', Comment.Single), # Punctuation (r'[,;()]', Punctuation), # Space is not significant (r'\s+', Text) ], 'string-literal': [(r'\\[tnrfbae"\\]', String.Escape), (r'"', String, '#pop'), (r'[^\\"]+', String)], }
class MathematicaLexer(RegexLexer): """ Lexer for `Mathematica <http://www.wolfram.com/mathematica/>`_ source code. .. versionadded:: 2.0 """ name = 'Mathematica' aliases = ['mathematica', 'mma', 'nb'] filenames = ['*.nb', '*.cdf', '*.nbp', '*.ma'] mimetypes = ['application/mathematica', 'application/vnd.wolfram.mathematica', 'application/vnd.wolfram.mathematica.package', 'application/vnd.wolfram.cdf'] # http://reference.wolfram.com/mathematica/guide/Syntax.html operators = ( ";;", "=", "=.", "!=" "==", ":=", "->", ":>", "/.", "+", "-", "*", "/", "^", "&&", "||", "!", "<>", "|", "/;", "?", "@", "//", "/@", "@@", "@@@", "~~", "===", "&", "<", ">", "<=", ">=", ) punctuation = (",", ";", "(", ")", "[", "]", "{", "}") def _multi_escape(entries): return '(%s)' % ('|'.join(re.escape(entry) for entry in entries)) tokens = { 'root': [ (r'(?s)\(\*.*?\*\)', Comment), (r'([a-zA-Z]+[A-Za-z0-9]*`)', Name.Namespace), (r'([A-Za-z0-9]*_+[A-Za-z0-9]*)', Name.Variable), (r'#\d*', Name.Variable), (r'([a-zA-Z]+[a-zA-Z0-9]*)', Name), (r'-?\d+\.\d*', Number.Float), (r'-?\d*\.\d+', Number.Float), (r'-?\d+', Number.Integer), (words(operators), Operator), (words(punctuation), Punctuation), (r'".*?"', String), (r'\s+', Text.Whitespace), ], }
class ResourceLexer(RegexLexer): """Lexer for `ICU Resource bundles <http://userguide.icu-project.org/locale/resources>`_. .. versionadded:: 2.0 """ name = 'ResourceBundle' aliases = ['resource', 'resourcebundle'] filenames = [] _types = (':table', ':array', ':string', ':bin', ':import', ':intvector', ':int', ':alias') flags = re.MULTILINE | re.IGNORECASE tokens = { 'root': [ (r'//.*?$', Comment), (r'"', String, 'string'), (r'-?\d+', Number.Integer), (r'[,{}]', Operator), (r'([^\s{:]+)(\s*)(%s?)' % '|'.join(_types), bygroups(Name, Text, Keyword)), (r'\s+', Text), (words(_types), Keyword), ], 'string': [(r'(\\x[0-9a-f]{2}|\\u[0-9a-f]{4}|\\U00[0-9a-f]{6}|' r'\\[0-7]{1,3}|\\c.|\\[abtnvfre\'"?\\]|\\\{|[^"{\\])+', String), (r'\{', String.Escape, 'msgname'), (r'"', String, '#pop')], 'msgname': [(r'([^{},]+)(\s*)', bygroups(Name, String.Escape), ('#pop', 'message'))], 'message': [(r'\{', String.Escape, 'msgname'), (r'\}', String.Escape, '#pop'), (r'(,)(\s*)([a-z]+)(\s*\})', bygroups(Operator, String.Escape, Keyword, String.Escape), '#pop'), (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)(offset)(\s*)(:)(\s*)(-?\d+)(\s*)', bygroups(Operator, String.Escape, Keyword, String.Escape, Operator, String.Escape, Operator.Word, String.Escape, Operator, String.Escape, Number.Integer, String.Escape), 'choice'), (r'(,)(\s*)([a-z]+)(\s*)(,)(\s*)', bygroups(Operator, String.Escape, Keyword, String.Escape, Operator, String.Escape), 'choice'), (r'\s+', String.Escape)], 'choice': [(r'(=|<|>|<=|>=|!=)(-?\d+)(\s*\{)', bygroups(Operator, Number.Integer, String.Escape), 'message'), (r'([a-z]+)(\s*\{)', bygroups(Keyword.Type, String.Escape), 'str'), (r'\}', String.Escape, ('#pop', '#pop')), (r'\s+', String.Escape)], 'str': [(r'\}', String.Escape, '#pop'), (r'\{', String.Escape, 'msgname'), (r'[^{}]+', String)] } def analyse_text(text): if text.startswith('root:table'): return 1.0
class BSTLexer(RegexLexer): """ A lexer for BibTeX bibliography styles. .. versionadded:: 2.2 """ name = 'BST' aliases = ['bst', 'bst-pybtex'] filenames = ['*.bst'] flags = re.IGNORECASE | re.MULTILINE tokens = { 'root': [ include('whitespace'), (words(['read', 'sort']), Keyword), (words(['execute', 'integers', 'iterate', 'reverse', 'strings']), Keyword, ('group')), (words(['function', 'macro']), Keyword, ('group', 'group')), (words(['entry']), Keyword, ('group', 'group', 'group')), ], 'group': [ include('whitespace'), (r'\{', Punctuation, ('#pop', 'group-end', 'body')), ], 'group-end': [ include('whitespace'), (r'\}', Punctuation, '#pop'), ], 'body': [ include('whitespace'), (r"\'[^#\"\{\}\s]+", Name.Function), (r'[^#\"\{\}\s]+\$', Name.Builtin), (r'[^#\"\{\}\s]+', Name.Variable), (r'"[^\"]*"', String), (r'#-?\d+', Number), (r'\{', Punctuation, ('group-end', 'body')), default('#pop'), ], 'whitespace': [ (r'\s+', Text), ('%.*?$', Comment.SingleLine), ], }
class PostgresLexer(PostgresBase, RegexLexer): """ Lexer for the PostgreSQL dialect of SQL. .. versionadded:: 1.5 """ name = 'PostgreSQL SQL dialect' aliases = ['postgresql', 'postgres'] mimetypes = ['text/x-postgresql'] flags = re.IGNORECASE tokens = { 'root': [ (r'\s+', Text), (r'--.*\n?', Comment.Single), (r'/\*', Comment.Multiline, 'multiline-comments'), (r'(' + '|'.join( s.replace(" ", r"\s+") for s in DATATYPES + PSEUDO_TYPES) + r')\b', Name.Builtin), (words(KEYWORDS, suffix=r'\b'), Keyword), (r'[+*/<>=~!@#%^&|`?-]+', Operator), (r'::', Operator), # cast (r'\$\d+', Name.Variable), (r'([0-9]*\.[0-9]*|[0-9]+)(e[+-]?[0-9]+)?', Number.Float), (r'[0-9]+', Number.Integer), (r"((?:E|U&)?)(')", bygroups(String.Affix, String.Single), 'string'), # quoted identifier (r'((?:U&)?)(")', bygroups(String.Affix, String.Name), 'quoted-ident'), (r'(?s)(\$)([^$]*)(\$)(.*?)(\$)(\2)(\$)', language_callback), (r'[a-z_]\w*', Name), # psql variable in SQL (r""":(['"]?)[a-z]\w*\b\1""", Name.Variable), (r'[;:()\[\]{},.]', Punctuation), ], 'multiline-comments': [(r'/\*', Comment.Multiline, 'multiline-comments'), (r'\*/', Comment.Multiline, '#pop'), (r'[^/*]+', Comment.Multiline), (r'[/*]', Comment.Multiline)], 'string': [ (r"[^']+", String.Single), (r"''", String.Single), (r"'", String.Single, '#pop'), ], 'quoted-ident': [ (r'[^"]+', String.Name), (r'""', String.Name), (r'"', String.Name, '#pop'), ], }
class BoogieLexer(RegexLexer): """ For `Boogie <https://boogie.codeplex.com/>`_ source code. .. versionadded:: 2.1 """ name = 'Boogie' aliases = ['boogie'] filenames = ['*.bpl'] tokens = { 'root': [ # Whitespace and Comments (r'\n', Whitespace), (r'\s+', Whitespace), (r'//[/!](.*?)\n', Comment.Doc), (r'//(.*?)\n', Comment.Single), (r'/\*', Comment.Multiline, 'comment'), (words(('axiom', 'break', 'call', 'ensures', 'else', 'exists', 'function', 'forall', 'if', 'invariant', 'modifies', 'procedure', 'requires', 'then', 'var', 'while'), suffix=r'\b'), Keyword), (words(('const', ), suffix=r'\b'), Keyword.Reserved), (words(('bool', 'int', 'ref'), suffix=r'\b'), Keyword.Type), include('numbers'), (r"(>=|<=|:=|!=|==>|&&|\|\||[+/\-=>*<\[\]])", Operator), (r"([{}():;,.])", Punctuation), # Identifier (r'[a-zA-Z_]\w*', Name), ], 'comment': [ (r'[^*/]+', Comment.Multiline), (r'/\*', Comment.Multiline, '#push'), (r'\*/', Comment.Multiline, '#pop'), (r'[*/]', Comment.Multiline), ], 'numbers': [ (r'[0-9]+', Number.Integer), ], }
class EiffelLexer(RegexLexer): """ For `Eiffel <http://www.eiffel.com>`_ source code. .. versionadded:: 2.0 """ name = 'Eiffel' aliases = ['eiffel'] filenames = ['*.e'] mimetypes = ['text/x-eiffel'] tokens = { 'root': [ (r'[^\S\n]+', Text), (r'--.*?\n', Comment.Single), (r'[^\S\n]+', Text), # Please note that keyword and operator are case insensitive. (r'(?i)(true|false|void|current|result|precursor)\b', Keyword.Constant), (r'(?i)(and(\s+then)?|not|xor|implies|or(\s+else)?)\b', Operator.Word), (words( ('across', 'agent', 'alias', 'all', 'as', 'assign', 'attached', 'attribute', 'check', 'class', 'convert', 'create', 'debug', 'deferred', 'detachable', 'do', 'else', 'elseif', 'end', 'ensure', 'expanded', 'export', 'external', 'feature', 'from', 'frozen', 'if', 'inherit', 'inspect', 'invariant', 'like', 'local', 'loop', 'none', 'note', 'obsolete', 'old', 'once', 'only', 'redefine', 'rename', 'require', 'rescue', 'retry', 'select', 'separate', 'then', 'undefine', 'until', 'variant', 'when'), prefix=r'(?i)\b', suffix=r'\b'), Keyword.Reserved), (r'"\[(([^\]%]|\n)|%(.|\n)|\][^"])*?\]"', String), (r'"([^"%\n]|%.)*?"', String), include('numbers'), (r"'([^'%]|%'|%%)'", String.Char), (r"(//|\\\\|>=|<=|:=|/=|~|/~|[\\?!#%&@|+/\-=>*$<^\[\]])", Operator), (r"([{}():;,.])", Punctuation), (r'([a-z]\w*)|([A-Z][A-Z0-9_]*[a-z]\w*)', Name), (r'([A-Z][A-Z0-9_]*)', Name.Class), (r'\n+', Text), ], 'numbers': [ (r'0[xX][a-fA-F0-9]+', Number.Hex), (r'0[bB][01]+', Number.Bin), (r'0[cC][0-7]+', Number.Oct), (r'([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+)', Number.Float), (r'[0-9]+', Number.Integer), ], }
class NitLexer(RegexLexer): """ For `nit <http://nitlanguage.org>`_ source. .. versionadded:: 2.0 """ name = 'Nit' aliases = ['nit'] filenames = ['*.nit'] tokens = { 'root': [ (r'#.*?$', Comment.Single), (words(('package', 'module', 'import', 'class', 'abstract', 'interface', 'universal', 'enum', 'end', 'fun', 'type', 'init', 'redef', 'isa', 'do', 'readable', 'writable', 'var', 'intern', 'extern', 'public', 'protected', 'private', 'intrude', 'if', 'then', 'else', 'while', 'loop', 'for', 'in', 'and', 'or', 'not', 'implies', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'is', 'once', 'super', 'self', 'true', 'false', 'nullable', 'null', 'as', 'isset', 'label', '__debug__'), suffix=r'(?=[\r\n\t( ])'), Keyword), (r'[A-Z]\w*', Name.Class), (r'"""(([^\'\\]|\\.)|\\r|\\n)*((\{\{?)?(""?\{\{?)*""""*)', String), # Simple long string (r'\'\'\'(((\\.|[^\'\\])|\\r|\\n)|\'((\\.|[^\'\\])|\\r|\\n)|' r'\'\'((\\.|[^\'\\])|\\r|\\n))*\'\'\'', String), # Simple long string alt (r'"""(([^\'\\]|\\.)|\\r|\\n)*((""?)?(\{\{?""?)*\{\{\{\{*)', String), # Start long string (r'\}\}\}(((\\.|[^\'\\])|\\r|\\n))*(""?)?(\{\{?""?)*\{\{\{\{*', String), # Mid long string (r'\}\}\}(((\\.|[^\'\\])|\\r|\\n))*(\{\{?)?(""?\{\{?)*""""*', String), # End long string (r'"(\\.|([^"}{\\]))*"', String), # Simple String (r'"(\\.|([^"}{\\]))*\{', String), # Start string (r'\}(\\.|([^"}{\\]))*\{', String), # Mid String (r'\}(\\.|([^"}{\\]))*"', String), # End String (r'(\'[^\'\\]\')|(\'\\.\')', String.Char), (r'[0-9]+', Number.Integer), (r'[0-9]*.[0-9]+', Number.Float), (r'0(x|X)[0-9A-Fa-f]+', Number.Hex), (r'[a-z]\w*', Name), (r'_\w+', Name.Variable.Instance), (r'==|!=|<==>|>=|>>|>|<=|<<|<|\+|-|=|/|\*|%|\+=|-=|!|@', Operator), (r'\(|\)|\[|\]|,|\.\.\.|\.\.|\.|::|:', Punctuation), (r'`\{[^`]*`\}', Text), # Extern blocks won't be Lexed by Nit (r'[\r\n\t ]+', Text), ], }
class OpenEdgeLexer(RegexLexer): """ Lexer for `OpenEdge ABL (formerly Progress) <http://web.progress.com/en/openedge/abl.html>`_ source code. .. versionadded:: 1.5 """ name = 'OpenEdge ABL' aliases = ['openedge', 'abl', 'progress'] filenames = ['*.p', '*.cls'] mimetypes = ['text/x-openedge', 'application/x-openedge'] types = ( r'(?i)(^|(?<=[^\w\-]))(CHARACTER|CHAR|CHARA|CHARAC|CHARACT|CHARACTE|' r'COM-HANDLE|DATE|DATETIME|DATETIME-TZ|' r'DECIMAL|DEC|DECI|DECIM|DECIMA|HANDLE|' r'INT64|INTEGER|INT|INTE|INTEG|INTEGE|' r'LOGICAL|LONGCHAR|MEMPTR|RAW|RECID|ROWID)\s*($|(?=[^\w\-]))') keywords = words(OPENEDGEKEYWORDS, prefix=r'(?i)(^|(?<=[^\w\-]))', suffix=r'\s*($|(?=[^\w\-]))') tokens = { 'root': [ (r'/\*', Comment.Multiline, 'comment'), (r'\{', Comment.Preproc, 'preprocessor'), (r'\s*&.*', Comment.Preproc), (r'0[xX][0-9a-fA-F]+[LlUu]*', Number.Hex), (r'(?i)(DEFINE|DEF|DEFI|DEFIN)\b', Keyword.Declaration), (types, Keyword.Type), (keywords, Name.Builtin), (r'"(\\\\|\\"|[^"])*"', String.Double), (r"'(\\\\|\\'|[^'])*'", String.Single), (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), (r'[0-9]+', Number.Integer), (r'\s+', Text), (r'[+*/=-]', Operator), (r'[.:()]', Punctuation), (r'.', Name.Variable), # Lazy catch-all ], 'comment': [(r'[^*/]', Comment.Multiline), (r'/\*', Comment.Multiline, '#push'), (r'\*/', Comment.Multiline, '#pop'), (r'[*/]', Comment.Multiline)], 'preprocessor': [ (r'[^{}]', Comment.Preproc), (r'\{', Comment.Preproc, '#push'), (r'\}', Comment.Preproc, '#pop'), ], }
class MozPreprocHashLexer(RegexLexer): """ Lexer for Mozilla Preprocessor files (with '#' as the marker). Other data is left untouched. .. versionadded:: 2.0 """ name = 'mozhashpreproc' aliases = [name] filenames = [] mimetypes = [] tokens = { 'root': [ (r'^#', Comment.Preproc, ('expr', 'exprstart')), (r'.+', Other), ], 'exprstart': [ (r'(literal)(.*)', bygroups(Comment.Preproc, Text), '#pop:2'), (words(('define', 'undef', 'if', 'ifdef', 'ifndef', 'else', 'elif', 'elifdef', 'elifndef', 'endif', 'expand', 'filter', 'unfilter', 'include', 'includesubst', 'error')), Comment.Preproc, '#pop'), ], 'expr': [ (words(('!', '!=', '==', '&&', '||')), Operator), (r'(defined)(\()', bygroups(Keyword, Punctuation)), (r'\)', Punctuation), (r'[0-9]+', Number.Decimal), (r'__\w+?__', Name.Variable), (r'@\w+?@', Name.Class), (r'\w+', Name), (r'\n', Text, '#pop'), (r'\s+', Text), (r'\S', Punctuation), ], }
class ECLexer(CLexer): """ For eC source code with preprocessor directives. .. versionadded:: 1.5 """ name = 'eC' aliases = ['ec'] filenames = ['*.ec', '*.eh'] mimetypes = ['text/x-echdr', 'text/x-ecsrc'] tokens = { 'statements': [ (words( ('virtual', 'class', 'private', 'public', 'property', 'import', 'delete', 'new', 'new0', 'renew', 'renew0', 'define', 'get', 'set', 'remote', 'dllexport', 'dllimport', 'stdcall', 'subclass', '__on_register_module', 'namespace', 'using', 'typed_object', 'any_object', 'incref', 'register', 'watch', 'stopwatching', 'firewatchers', 'watchable', 'class_designer', 'class_fixed', 'class_no_expansion', 'isset', 'class_default_property', 'property_category', 'class_data', 'class_property', 'thisclass', 'dbtable', 'dbindex', 'database_open', 'dbfield'), suffix=r'\b'), Keyword), (words(('uint', 'uint16', 'uint32', 'uint64', 'bool', 'byte', 'unichar', 'int64'), suffix=r'\b'), Keyword.Type), (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), (r'(null|value|this)\b', Name.Builtin), inherit, ], 'classname': [ (r'[a-zA-Z_]\w*', Name.Class, '#pop'), # template specification (r'\s*(?=>)', Text, '#pop'), ], }
class MqlLexer(CppLexer): """ For `MQL4 <http://docs.mql4.com/>`_ and `MQL5 <http://www.mql5.com/en/docs>`_ source code. .. versionadded:: 2.0 """ name = 'MQL' aliases = ['mql', 'mq4', 'mq5', 'mql4', 'mql5'] filenames = ['*.mq4', '*.mq5', '*.mqh'] mimetypes = ['text/x-mql'] tokens = { 'statements': [ (words(_mql_builtins.keywords, suffix=r'\b'), Keyword), (words(_mql_builtins.c_types, suffix=r'\b'), Keyword.Type), (words(_mql_builtins.types, suffix=r'\b'), Name.Function), (words(_mql_builtins.constants, suffix=r'\b'), Name.Constant), (words(_mql_builtins.colors, prefix='(clr)?', suffix=r'\b'), Name.Constant), inherit, ], }
class AmbientTalkLexer(RegexLexer): """ Lexer for `AmbientTalk <https://code.google.com/p/ambienttalk>`_ source code. .. versionadded:: 2.0 """ name = 'AmbientTalk' filenames = ['*.at'] aliases = ['at', 'ambienttalk', 'ambienttalk/2'] mimetypes = ['text/x-ambienttalk'] flags = re.MULTILINE | re.DOTALL builtin = words(('if:', 'then:', 'else:', 'when:', 'whenever:', 'discovered:', 'disconnected:', 'reconnected:', 'takenOffline:', 'becomes:', 'export:', 'as:', 'object:', 'actor:', 'mirror:', 'taggedAs:', 'mirroredBy:', 'is:')) tokens = { 'root': [ (r'\s+', Text), (r'//.*?\n', Comment.Single), (r'/\*.*?\*/', Comment.Multiline), (r'(def|deftype|import|alias|exclude)\b', Keyword), (builtin, Name.Builtin), (r'(true|false|nil)\b', Keyword.Constant), (r'(~|lobby|jlobby|/)\.', Keyword.Constant, 'namespace'), (r'"(\\\\|\\"|[^"])*"', String), (r'\|', Punctuation, 'arglist'), (r'<:|[*^!%&<>+=,./?-]|:=', Operator), (r"`[a-zA-Z_]\w*", String.Symbol), (r"[a-zA-Z_]\w*:", Name.Function), (r"[{}()\[\];`]", Punctuation), (r'(self|super)\b', Name.Variable.Instance), (r"[a-zA-Z_]\w*", Name.Variable), (r"@[a-zA-Z_]\w*", Name.Class), (r"@\[", Name.Class, 'annotations'), include('numbers'), ], 'numbers': [(r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), (r'\d+', Number.Integer)], 'namespace': [(r'[a-zA-Z_]\w*\.', Name.Namespace), (r'[a-zA-Z_]\w*:', Name.Function, '#pop'), (r'[a-zA-Z_]\w*(?!\.)', Name.Function, '#pop')], 'annotations': [(r"(.*?)\]", Name.Class, '#pop')], 'arglist': [ (r'\|', Punctuation, '#pop'), (r'\s*(,)\s*', Punctuation), (r'[a-zA-Z_]\w*', Name.Variable), ], }
class PikeLexer(CppLexer): """ For `Pike <http://pike.lysator.liu.se/>`_ source code. .. versionadded:: 2.0 """ name = 'Pike' aliases = ['pike'] filenames = ['*.pike', '*.pmod'] mimetypes = ['text/x-pike'] tokens = { 'statements': [ (words(('catch', 'new', 'private', 'protected', 'public', 'gauge', 'throw', 'throws', 'class', 'interface', 'implement', 'abstract', 'extends', 'from', 'this', 'super', 'constant', 'final', 'static', 'import', 'use', 'extern', 'inline', 'proto', 'break', 'continue', 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'as', 'in', 'version', 'return', 'true', 'false', 'null', '__VERSION__', '__MAJOR__', '__MINOR__', '__BUILD__', '__REAL_VERSION__', '__REAL_MAJOR__', '__REAL_MINOR__', '__REAL_BUILD__', '__DATE__', '__TIME__', '__FILE__', '__DIR__', '__LINE__', '__AUTO_BIGNUM__', '__NT__', '__PIKE__', '__amigaos__', '_Pragma', 'static_assert', 'defined', 'sscanf'), suffix=r'\b'), Keyword), (r'(bool|int|long|float|short|double|char|string|object|void|mapping|' r'array|multiset|program|function|lambda|mixed|' r'[a-z_][a-z0-9_]*_t)\b', Keyword.Type), (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), (r'[~!%^&*+=|?:<>/@-]', Operator), inherit, ], 'classname': [ (r'[a-zA-Z_]\w*', Name.Class, '#pop'), # template specification (r'\s*(?=>)', Text, '#pop'), ], }
class NuSMVLexer(RegexLexer): """ Lexer for the NuSMV language. .. versionadded:: 2.2 """ name = 'NuSMV' aliases = ['nusmv'] filenames = ['*.smv'] mimetypes = [] tokens = { 'root': [ # Comments (r'(?s)\/\-\-.*?\-\-/', Comment), (r'--.*\n', Comment), # Reserved (words(('MODULE', 'DEFINE', 'MDEFINE', 'CONSTANTS', 'VAR', 'IVAR', 'FROZENVAR', 'INIT', 'TRANS', 'INVAR', 'SPEC', 'CTLSPEC', 'LTLSPEC', 'PSLSPEC', 'COMPUTE', 'NAME', 'INVARSPEC', 'FAIRNESS', 'JUSTICE', 'COMPASSION', 'ISA', 'ASSIGN', 'CONSTRAINT', 'SIMPWFF', 'CTLWFF', 'LTLWFF', 'PSLWFF', 'COMPWFF', 'IN', 'MIN', 'MAX', 'MIRROR', 'PRED', 'PREDICATES'), suffix=r'(?![\w$#-])'), Keyword.Declaration), (r'process(?![\w$#-])', Keyword), (words(('array', 'of', 'boolean', 'integer', 'real', 'word'), suffix=r'(?![\w$#-])'), Keyword.Type), (words(('case', 'esac'), suffix=r'(?![\w$#-])'), Keyword), (words(('word1', 'bool', 'signed', 'unsigned', 'extend', 'resize', 'sizeof', 'uwconst', 'swconst', 'init', 'self', 'count', 'abs', 'max', 'min'), suffix=r'(?![\w$#-])'), Name.Builtin), (words(('EX', 'AX', 'EF', 'AF', 'EG', 'AG', 'E', 'F', 'O', 'G', 'H', 'X', 'Y', 'Z', 'A', 'U', 'S', 'V', 'T', 'BU', 'EBF', 'ABF', 'EBG', 'ABG', 'next', 'mod', 'union', 'in', 'xor', 'xnor'), suffix=r'(?![\w$#-])'), Operator.Word), (words(('TRUE', 'FALSE'), suffix=r'(?![\w$#-])'), Keyword.Constant), # Names (r'[a-zA-Z_][\w$#-]*', Name.Variable), # Operators (r':=', Operator), (r'[-&|+*/<>!=]', Operator), # Literals (r'\-?\d+\b', Number.Integer), (r'0[su][bB]\d*_[01_]+', Number.Bin), (r'0[su][oO]\d*_[0-7_]+', Number.Oct), (r'0[su][dD]\d*_[\d_]+', Number.Dec), (r'0[su][hH]\d*_[\da-fA-F_]+', Number.Hex), # Whitespace, punctuation and the rest (r'\s+', Text.Whitespace), (r'[()\[\]{};?:.,]', Punctuation), ], }
class AmplLexer(RegexLexer): """ For `AMPL <http://ampl.com/>`_ source code. .. versionadded:: 2.2 """ name = 'Ampl' aliases = ['ampl'] filenames = ['*.run'] tokens = { 'root': [ (r'\n', Text), (r'\s+', Text.Whitespace), (r'#.*?\n', Comment.Single), (r'/[*](.|\n)*?[*]/', Comment.Multiline), (words( ('call', 'cd', 'close', 'commands', 'data', 'delete', 'display', 'drop', 'end', 'environ', 'exit', 'expand', 'include', 'load', 'model', 'objective', 'option', 'problem', 'purge', 'quit', 'redeclare', 'reload', 'remove', 'reset', 'restore', 'shell', 'show', 'solexpand', 'solution', 'solve', 'update', 'unload', 'xref', 'coeff', 'coef', 'cover', 'obj', 'interval', 'default', 'from', 'to', 'to_come', 'net_in', 'net_out', 'dimen', 'dimension', 'check', 'complements', 'write', 'function', 'pipe', 'format', 'if', 'then', 'else', 'in', 'while', 'repeat', 'for'), suffix=r'\b'), Keyword.Reserved), (r'(integer|binary|symbolic|ordered|circular|reversed|INOUT|IN|OUT|LOCAL)', Keyword.Type), (r'\".*?\"', String.Double), (r'\'.*?\'', String.Single), (r'[()\[\]{},;:]+', Punctuation), (r'\b(\w+)(\.)(astatus|init0|init|lb0|lb1|lb2|lb|lrc|' r'lslack|rc|relax|slack|sstatus|status|ub0|ub1|ub2|' r'ub|urc|uslack|val)', bygroups(Name.Variable, Punctuation, Keyword.Reserved)), (r'(set|param|var|arc|minimize|maximize|subject to|s\.t\.|subj to|' r'node|table|suffix|read table|write table)(\s+)(\w+)', bygroups(Keyword.Declaration, Text, Name.Variable)), (r'(param)(\s*)(:)(\s*)(\w+)(\s*)(:)(\s*)((\w|\s)+)', bygroups(Keyword.Declaration, Text, Punctuation, Text, Name.Variable, Text, Punctuation, Text, Name.Variable)), (r'(let|fix|unfix)(\s*)((?:\{.*\})?)(\s*)(\w+)', bygroups(Keyword.Declaration, Text, using(this), Text, Name.Variable)), (words(('abs', 'acos', 'acosh', 'alias', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'ctime', 'cos', 'exp', 'floor', 'log', 'log10', 'max', 'min', 'precision', 'round', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'time', 'trunc', 'Beta', 'Cauchy', 'Exponential', 'Gamma', 'Irand224', 'Normal', 'Normal01', 'Poisson', 'Uniform', 'Uniform01', 'num', 'num0', 'ichar', 'char', 'length', 'substr', 'sprintf', 'match', 'sub', 'gsub', 'print', 'printf', 'next', 'nextw', 'prev', 'prevw', 'first', 'last', 'ord', 'ord0', 'card', 'arity', 'indexarity'), prefix=r'\b', suffix=r'\b'), Name.Builtin), (r'(\+|\-|\*|/|\*\*|=|<=|>=|==|\||\^|<|>|\!|\.\.|:=|\&|\!=|<<|>>)', Operator), (words(('or', 'exists', 'forall', 'and', 'in', 'not', 'within', 'union', 'diff', 'difference', 'symdiff', 'inter', 'intersect', 'intersection', 'cross', 'setof', 'by', 'less', 'sum', 'prod', 'product', 'div', 'mod'), suffix=r'\b'), Keyword.Reserved ), # Operator.Name but not enough emphasized with that (r'(\d+\.(?!\.)\d*|\.(?!.)\d+)([eE][+-]?\d+)?', Number.Float), (r'\d+([eE][+-]?\d+)?', Number.Integer), (r'[+-]?Infinity', Number.Integer), (r'(\w+|(\.(?!\.)))', Text) ] }
class PerlLexer(RegexLexer): """ For `Perl <http://www.perl.org>`_ source code. """ name = 'Perl' aliases = ['perl', 'pl'] filenames = ['*.pl', '*.pm', '*.t'] mimetypes = ['text/x-perl', 'application/x-perl'] flags = re.DOTALL | re.MULTILINE # TODO: give this to a perl guy who knows how to parse perl... tokens = { 'balanced-regex': [ (r'/(\\\\|\\[^\\]|[^\\/])*/[egimosx]*', String.Regex, '#pop'), (r'!(\\\\|\\[^\\]|[^\\!])*![egimosx]*', String.Regex, '#pop'), (r'\\(\\\\|[^\\])*\\[egimosx]*', String.Regex, '#pop'), (r'\{(\\\\|\\[^\\]|[^\\}])*\}[egimosx]*', String.Regex, '#pop'), (r'<(\\\\|\\[^\\]|[^\\>])*>[egimosx]*', String.Regex, '#pop'), (r'\[(\\\\|\\[^\\]|[^\\\]])*\][egimosx]*', String.Regex, '#pop'), (r'\((\\\\|\\[^\\]|[^\\)])*\)[egimosx]*', String.Regex, '#pop'), (r'@(\\\\|\\[^\\]|[^\\@])*@[egimosx]*', String.Regex, '#pop'), (r'%(\\\\|\\[^\\]|[^\\%])*%[egimosx]*', String.Regex, '#pop'), (r'\$(\\\\|\\[^\\]|[^\\$])*\$[egimosx]*', String.Regex, '#pop'), ], 'root': [ (r'\A\#!.+?$', Comment.Hashbang), (r'\#.*?$', Comment.Single), (r'^=[a-zA-Z0-9]+\s+.*?\n=cut', Comment.Multiline), (words(('case', 'continue', 'do', 'else', 'elsif', 'for', 'foreach', 'if', 'last', 'my', 'next', 'our', 'redo', 'reset', 'then', 'unless', 'until', 'while', 'print', 'new', 'BEGIN', 'CHECK', 'INIT', 'END', 'return'), suffix=r'\b'), Keyword), (r'(format)(\s+)(\w+)(\s*)(=)(\s*\n)', bygroups(Keyword, Text, Name, Text, Punctuation, Text), 'format'), (r'(eq|lt|gt|le|ge|ne|not|and|or|cmp)\b', Operator.Word), # common delimiters (r's/(\\\\|\\[^\\]|[^\\/])*/(\\\\|\\[^\\]|[^\\/])*/[egimosx]*', String.Regex), (r's!(\\\\|\\!|[^!])*!(\\\\|\\!|[^!])*![egimosx]*', String.Regex), (r's\\(\\\\|[^\\])*\\(\\\\|[^\\])*\\[egimosx]*', String.Regex), (r's@(\\\\|\\[^\\]|[^\\@])*@(\\\\|\\[^\\]|[^\\@])*@[egimosx]*', String.Regex), (r's%(\\\\|\\[^\\]|[^\\%])*%(\\\\|\\[^\\]|[^\\%])*%[egimosx]*', String.Regex), # balanced delimiters (r's\{(\\\\|\\[^\\]|[^\\}])*\}\s*', String.Regex, 'balanced-regex' ), (r's<(\\\\|\\[^\\]|[^\\>])*>\s*', String.Regex, 'balanced-regex'), (r's\[(\\\\|\\[^\\]|[^\\\]])*\]\s*', String.Regex, 'balanced-regex'), (r's\((\\\\|\\[^\\]|[^\\)])*\)\s*', String.Regex, 'balanced-regex'), (r'm?/(\\\\|\\[^\\]|[^\\/\n])*/[gcimosx]*', String.Regex), (r'm(?=[/!\\{<\[(@%$])', String.Regex, 'balanced-regex'), (r'((?<==~)|(?<=\())\s*/(\\\\|\\[^\\]|[^\\/])*/[gcimosx]*', String.Regex), (r'\s+', Text), (words( ('abs', 'accept', 'alarm', 'atan2', 'bind', 'binmode', 'bless', 'caller', 'chdir', 'chmod', 'chomp', 'chop', 'chown', 'chr', 'chroot', 'close', 'closedir', 'connect', 'continue', 'cos', 'crypt', 'dbmclose', 'dbmopen', 'defined', 'delete', 'die', 'dump', 'each', 'endgrent', 'endhostent', 'endnetent', 'endprotoent', 'endpwent', 'endservent', 'eof', 'eval', 'exec', 'exists', 'exit', 'exp', 'fcntl', 'fileno', 'flock', 'fork', 'format', 'formline', 'getc', 'getgrent', 'getgrgid', 'getgrnam', 'gethostbyaddr', 'gethostbyname', 'gethostent', 'getlogin', 'getnetbyaddr', 'getnetbyname', 'getnetent', 'getpeername', 'getpgrp', 'getppid', 'getpriority', 'getprotobyname', 'getprotobynumber', 'getprotoent', 'getpwent', 'getpwnam', 'getpwuid', 'getservbyname', 'getservbyport', 'getservent', 'getsockname', 'getsockopt', 'glob', 'gmtime', 'goto', 'grep', 'hex', 'import', 'index', 'int', 'ioctl', 'join', 'keys', 'kill', 'last', 'lc', 'lcfirst', 'length', 'link', 'listen', 'local', 'localtime', 'log', 'lstat', 'map', 'mkdir', 'msgctl', 'msgget', 'msgrcv', 'msgsnd', 'my', 'next', 'oct', 'open', 'opendir', 'ord', 'our', 'pack', 'pipe', 'pop', 'pos', 'printf', 'prototype', 'push', 'quotemeta', 'rand', 'read', 'readdir', 'readline', 'readlink', 'readpipe', 'recv', 'redo', 'ref', 'rename', 'reverse', 'rewinddir', 'rindex', 'rmdir', 'scalar', 'seek', 'seekdir', 'select', 'semctl', 'semget', 'semop', 'send', 'setgrent', 'sethostent', 'setnetent', 'setpgrp', 'setpriority', 'setprotoent', 'setpwent', 'setservent', 'setsockopt', 'shift', 'shmctl', 'shmget', 'shmread', 'shmwrite', 'shutdown', 'sin', 'sleep', 'socket', 'socketpair', 'sort', 'splice', 'split', 'sprintf', 'sqrt', 'srand', 'stat', 'study', 'substr', 'symlink', 'syscall', 'sysopen', 'sysread', 'sysseek', 'system', 'syswrite', 'tell', 'telldir', 'tie', 'tied', 'time', 'times', 'tr', 'truncate', 'uc', 'ucfirst', 'umask', 'undef', 'unlink', 'unpack', 'unshift', 'untie', 'utime', 'values', 'vec', 'wait', 'waitpid', 'wantarray', 'warn', 'write'), suffix=r'\b'), Name.Builtin), (r'((__(DATA|DIE|WARN)__)|(STD(IN|OUT|ERR)))\b', Name.Builtin.Pseudo), (r'(<<)([\'"]?)([a-zA-Z_]\w*)(\2;?\n.*?\n)(\3)(\n)', bygroups(String, String, String.Delimiter, String, String.Delimiter, Text)), (r'__END__', Comment.Preproc, 'end-part'), (r'\$\^[ADEFHILMOPSTWX]', Name.Variable.Global), (r"\$[\\\"\[\]'&`+*.,;=%~?@$!<>(^|/-](?!\w)", Name.Variable.Global), (r'[$@%#]+', Name.Variable, 'varname'), (r'0_?[0-7]+(_[0-7]+)*', Number.Oct), (r'0x[0-9A-Fa-f]+(_[0-9A-Fa-f]+)*', Number.Hex), (r'0b[01]+(_[01]+)*', Number.Bin), (r'(?i)(\d*(_\d*)*\.\d+(_\d*)*|\d+(_\d*)*\.\d+(_\d*)*)(e[+-]?\d+)?', Number.Float), (r'(?i)\d+(_\d*)*e[+-]?\d+(_\d*)*', Number.Float), (r'\d+(_\d+)*', Number.Integer), (r"'(\\\\|\\[^\\]|[^'\\])*'", String), (r'"(\\\\|\\[^\\]|[^"\\])*"', String), (r'`(\\\\|\\[^\\]|[^`\\])*`', String.Backtick), (r'<([^\s>]+)>', String.Regex), (r'(q|qq|qw|qr|qx)\{', String.Other, 'cb-string'), (r'(q|qq|qw|qr|qx)\(', String.Other, 'rb-string'), (r'(q|qq|qw|qr|qx)\[', String.Other, 'sb-string'), (r'(q|qq|qw|qr|qx)\<', String.Other, 'lt-string'), (r'(q|qq|qw|qr|qx)([\W_])(.|\n)*?\2', String.Other), (r'(package)(\s+)([a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*)', bygroups(Keyword, Text, Name.Namespace)), (r'(use|require|no)(\s+)([a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*)', bygroups(Keyword, Text, Name.Namespace)), (r'(sub)(\s+)', bygroups(Keyword, Text), 'funcname'), (words(('no', 'package', 'require', 'use'), suffix=r'\b'), Keyword), (r'(\[\]|\*\*|::|<<|>>|>=|<=>|<=|={3}|!=|=~|' r'!~|&&?|\|\||\.{1,3})', Operator), (r'[-+/*%=<>&^|!\\~]=?', Operator), (r'[()\[\]:;,<>/?{}]', Punctuation), # yes, there's no shortage # of punctuation in Perl! (r'(?=\w)', Name, 'name'), ], 'format': [ (r'\.\n', String.Interpol, '#pop'), (r'[^\n]*\n', String.Interpol), ], 'varname': [ (r'\s+', Text), (r'\{', Punctuation, '#pop'), # hash syntax? (r'\)|,', Punctuation, '#pop'), # argument specifier (r'\w+::', Name.Namespace), (r'[\w:]+', Name.Variable, '#pop'), ], 'name': [ (r'[a-zA-Z_]\w*(::[a-zA-Z_]\w*)*(::)?(?=\s*->)', Name.Namespace, '#pop'), (r'[a-zA-Z_]\w*(::[a-zA-Z_]\w*)*::', Name.Namespace, '#pop'), (r'[\w:]+', Name, '#pop'), (r'[A-Z_]+(?=\W)', Name.Constant, '#pop'), (r'(?=\W)', Text, '#pop'), ], 'funcname': [ (r'[a-zA-Z_]\w*[!?]?', Name.Function), (r'\s+', Text), # argument declaration (r'(\([$@%]*\))(\s*)', bygroups(Punctuation, Text)), (r';', Punctuation, '#pop'), (r'.*?\{', Punctuation, '#pop'), ], 'cb-string': [(r'\\[{}\\]', String.Other), (r'\\', String.Other), (r'\{', String.Other, 'cb-string'), (r'\}', String.Other, '#pop'), (r'[^{}\\]+', String.Other)], 'rb-string': [(r'\\[()\\]', String.Other), (r'\\', String.Other), (r'\(', String.Other, 'rb-string'), (r'\)', String.Other, '#pop'), (r'[^()]+', String.Other)], 'sb-string': [(r'\\[\[\]\\]', String.Other), (r'\\', String.Other), (r'\[', String.Other, 'sb-string'), (r'\]', String.Other, '#pop'), (r'[^\[\]]+', String.Other)], 'lt-string': [(r'\\[<>\\]', String.Other), (r'\\', String.Other), (r'\<', String.Other, 'lt-string'), (r'\>', String.Other, '#pop'), (r'[^<>]+', String.Other)], 'end-part': [(r'.+', Comment.Preproc, '#pop')] } def analyse_text(text): if shebang_matches(text, r'perl'): return True if re.search(r'(?:my|our)\s+[$@%(]', text): return 0.9
class GoLexer(RegexLexer): """ For `Go <http://golang.org>`_ source. .. versionadded:: 1.2 """ name = 'Go' filenames = ['*.go'] aliases = ['go'] mimetypes = ['text/x-gosrc'] flags = re.MULTILINE | re.UNICODE tokens = { 'root': [ (r'\n', Text), (r'\s+', Text), (r'\\\n', Text), # line continuations (r'//(.*?)\n', Comment.Single), (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), (r'(import|package)\b', Keyword.Namespace), (r'(var|func|struct|map|chan|type|interface|const)\b', Keyword.Declaration), (words(('break', 'default', 'select', 'case', 'defer', 'go', 'else', 'goto', 'switch', 'fallthrough', 'if', 'range', 'continue', 'for', 'return'), suffix=r'\b'), Keyword), (r'(true|false|iota|nil)\b', Keyword.Constant), # It seems the builtin types aren't actually keywords, but # can be used as functions. So we need two declarations. (words(('uint', 'uint8', 'uint16', 'uint32', 'uint64', 'int', 'int8', 'int16', 'int32', 'int64', 'float', 'float32', 'float64', 'complex64', 'complex128', 'byte', 'rune', 'string', 'bool', 'error', 'uintptr', 'print', 'println', 'panic', 'recover', 'close', 'complex', 'real', 'imag', 'len', 'cap', 'append', 'copy', 'delete', 'new', 'make'), suffix=r'\b(\()'), bygroups(Name.Builtin, Punctuation)), (words(('uint', 'uint8', 'uint16', 'uint32', 'uint64', 'int', 'int8', 'int16', 'int32', 'int64', 'float', 'float32', 'float64', 'complex64', 'complex128', 'byte', 'rune', 'string', 'bool', 'error', 'uintptr'), suffix=r'\b'), Keyword.Type), # imaginary_lit (r'\d+i', Number), (r'\d+\.\d*([Ee][-+]\d+)?i', Number), (r'\.\d+([Ee][-+]\d+)?i', Number), (r'\d+[Ee][-+]\d+i', Number), # float_lit (r'\d+(\.\d+[eE][+\-]?\d+|' r'\.\d*|[eE][+\-]?\d+)', Number.Float), (r'\.\d+([eE][+\-]?\d+)?', Number.Float), # int_lit # -- octal_lit (r'0[0-7]+', Number.Oct), # -- hex_lit (r'0[xX][0-9a-fA-F]+', Number.Hex), # -- decimal_lit (r'(0|[1-9][0-9]*)', Number.Integer), # char_lit (r"""'(\\['"\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|[^\\])'""", String.Char), # StringLiteral # -- raw_string_lit (r'`[^`]*`', String), # -- interpreted_string_lit (r'"(\\\\|\\"|[^"])*"', String), # Tokens (r'(<<=|>>=|<<|>>|<=|>=|&\^=|&\^|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\|' r'|<-|\+\+|--|==|!=|:=|\.\.\.|[+\-*/%&])', Operator), (r'[|^<>=!()\[\]{}.,;:]', Punctuation), # identifier (r'[^\W\d]\w*', Name.Other), ] }