diff --git a/venv/Lib/site-packages/pygments/lexers/boa.py b/venv/Lib/site-packages/pygments/lexers/boa.py new file mode 100644 index 0000000000000000000000000000000000000000..06977dd198e573f17e5d3d9d37a74b4da2eeb929 --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/boa.py @@ -0,0 +1,97 @@ +""" + pygments.lexers.boa + ~~~~~~~~~~~~~~~~~~~ + + Lexers for the Boa language. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer, words +from pygments.token import String, Comment, Keyword, Name, Number, Operator, \ + Punctuation, Whitespace + +__all__ = ['BoaLexer'] + + +class BoaLexer(RegexLexer): + """ + Lexer for the Boa language. + """ + name = 'Boa' + aliases = ['boa'] + filenames = ['*.boa'] + url = 'https://boa.cs.iastate.edu/docs' + version_added = '2.4' + + reserved = words( + ('input', 'output', 'of', 'weight', 'before', 'after', 'stop', + 'ifall', 'foreach', 'exists', 'function', 'break', 'switch', 'case', + 'visitor', 'default', 'return', 'visit', 'while', 'if', 'else'), + suffix=r'\b', prefix=r'\b') + keywords = words( + ('bottom', 'collection', 'maximum', 'mean', 'minimum', 'set', 'sum', + 'top', 'string', 'int', 'bool', 'float', 'time', 'false', 'true', + 'array', 'map', 'stack', 'enum', 'type'), suffix=r'\b', prefix=r'\b') + classes = words( + ('Project', 'ForgeKind', 'CodeRepository', 'Revision', 'RepositoryKind', + 'ChangedFile', 'FileKind', 'ASTRoot', 'Namespace', 'Declaration', 'Type', + 'Method', 'Variable', 'Statement', 'Expression', 'Modifier', + 'StatementKind', 'ExpressionKind', 'ModifierKind', 'Visibility', + 'TypeKind', 'Person', 'ChangeKind'), + suffix=r'\b', prefix=r'\b') + operators = ('->', ':=', ':', '=', '<<', '!', '++', '||', + '&&', '+', '-', '*', ">", "<") + string_sep = ('`', '\"') + built_in_functions = words( + ( + # Array functions + 'new', 'sort', + # Date & Time functions + 'yearof', 'dayofyear', 'hourof', 'minuteof', 'secondof', 'now', + 'addday', 'addmonth', 'addweek', 'addyear', 'dayofmonth', 'dayofweek', + 'dayofyear', 'formattime', 'trunctoday', 'trunctohour', 'trunctominute', + 'trunctomonth', 'trunctosecond', 'trunctoyear', + # Map functions + 'clear', 'haskey', 'keys', 'lookup', 'remove', 'values', + # Math functions + 'abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', + 'ceil', 'cos', 'cosh', 'exp', 'floor', 'highbit', 'isfinite', 'isinf', + 'isnan', 'isnormal', 'log', 'log10', 'max', 'min', 'nrand', 'pow', + 'rand', 'round', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc', + # Other functions + 'def', 'hash', 'len', + # Set functions + 'add', 'contains', 'remove', + # String functions + 'format', 'lowercase', 'match', 'matchposns', 'matchstrs', 'regex', + 'split', 'splitall', 'splitn', 'strfind', 'strreplace', 'strrfind', + 'substring', 'trim', 'uppercase', + # Type Conversion functions + 'bool', 'float', 'int', 'string', 'time', + # Domain-Specific functions + 'getast', 'getsnapshot', 'hasfiletype', 'isfixingrevision', 'iskind', + 'isliteral', + ), + prefix=r'\b', + suffix=r'\(') + + tokens = { + 'root': [ + (r'#.*?$', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline), + (reserved, Keyword.Reserved), + (built_in_functions, Name.Function), + (keywords, Keyword.Type), + (classes, Name.Classes), + (words(operators), Operator), + (r'[][(),;{}\\.]', Punctuation), + (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double), + (r"`(\\\\|\\[^\\]|[^`\\])*`", String.Backtick), + (words(string_sep), String.Delimiter), + (r'[a-zA-Z_]+', Name.Variable), + (r'[0-9]+', Number.Integer), + (r'\s+', Whitespace), # Whitespace + ] + } diff --git a/venv/Lib/site-packages/pygments/lexers/bqn.py b/venv/Lib/site-packages/pygments/lexers/bqn.py new file mode 100644 index 0000000000000000000000000000000000000000..beb292fbf48d0fcccd07120cfad2c4dd18abc302 --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/bqn.py @@ -0,0 +1,112 @@ +""" + pygments.lexers.bqn + ~~~~~~~~~~~~~~~~~~~ + + Lexer for BQN. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer +from pygments.token import Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Whitespace + +__all__ = ['BQNLexer'] + + +class BQNLexer(RegexLexer): + """ + A simple BQN lexer. + """ + name = 'BQN' + url = 'https://mlochbaum.github.io/BQN/index.html' + aliases = ['bqn'] + filenames = ['*.bqn'] + mimetypes = [] + version_added = '2.16' + + # An inter_word_char. Necessary because \w matches all alphanumeric + # Unicode characters, including ones (e.g., 𝕊) that BQN treats special. + _iwc = r'((?=[^𝕎𝕏𝔽𝔾𝕊𝕨𝕩𝕗𝕘𝕤𝕣])\w)' + + tokens = { + 'root': [ + # Whitespace + # ========== + (r'\s+', Whitespace), + # + # Comment + # ======= + # '#' is a comment that continues to the end of the line + (r'#.*$', Comment.Single), + # + # Strings + # ======= + (r'\'((\'\')|[^\'])*\'', String.Single), + (r'"(("")|[^"])*"', String.Double), + # + # Null Character + # ============== + # Literal representation of the null character + (r'@', String.Symbol), + # + # Punctuation + # =========== + # This token type is used for diamond, commas + # and array and list brackets and strand syntax + (r'[\.⋄,\[\]⟨⟩‿]', Punctuation), + # + # Expression Grouping + # =================== + # Since this token type is important in BQN, it is not included in + # the punctuation token type but rather in the following one + (r'[\(\)]', String.Regex), + # + # Numbers + # ======= + # Includes the numeric literals and the Nothing character + (r'¯?[0-9](([0-9]|_)*\.?([0-9]|_)+|([0-9]|_)*)([Ee][¯]?([0-9]|_)+)?|¯|∞|π|·', Number), + # + # Variables + # ========= + (r'[a-z]' + _iwc + r'*', Name.Variable), + # + # 2-Modifiers + # =========== + # Needs to come before the 1-modifiers due to _𝕣 and _𝕣_ + (r'[∘○⊸⟜⌾⊘◶⎉⚇⍟⎊]', Name.Property), + (r'_(𝕣|[a-zA-Z0-9]+)_', Name.Property), + # + # 1-Modifiers + # =========== + (r'[˙˜˘¨⌜⁼´˝`𝕣]', Name.Attribute), + (r'_(𝕣|[a-zA-Z0-9]+)', Name.Attribute), + # + # Functions + # ========= + # The monadic or dyadic function primitives and function + # operands and arguments, along with function self-reference + (r'[+\-×÷\⋆√⌊⌈∧∨¬|≤<>≥=≠≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!𝕎𝕏𝔽𝔾𝕊]', + Operator), + (r'[A-Z]' + _iwc + r'*|•' + _iwc + r'+', Operator), + # + # Constant + # ======== + (r'˙', Name.Constant), + # + # Define/Export/Change + # ==================== + (r'[←↩⇐]', Keyword.Declaration), + # + # Blocks + # ====== + (r'[{}]', Keyword.Type), + # + # Extra characters + # ================ + (r'[;:?𝕨𝕩𝕗𝕘𝕤]', Name.Entity), + # + + ], + } diff --git a/venv/Lib/site-packages/pygments/lexers/business.py b/venv/Lib/site-packages/pygments/lexers/business.py new file mode 100644 index 0000000000000000000000000000000000000000..3f9a86829b46c4444f3e4aa4dbc7ba64f7fc7599 --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/business.py @@ -0,0 +1,625 @@ +""" + pygments.lexers.business + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for "business-oriented" languages. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, include, words, bygroups +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Error, Whitespace + +from pygments.lexers._openedge_builtins import OPENEDGEKEYWORDS + +__all__ = ['CobolLexer', 'CobolFreeformatLexer', 'ABAPLexer', 'OpenEdgeLexer', + 'GoodDataCLLexer', 'MaqlLexer'] + + +class CobolLexer(RegexLexer): + """ + Lexer for OpenCOBOL code. + """ + name = 'COBOL' + aliases = ['cobol'] + filenames = ['*.cob', '*.COB', '*.cpy', '*.CPY'] + mimetypes = ['text/x-cobol'] + url = 'https://en.wikipedia.org/wiki/COBOL' + version_added = '1.6' + + flags = re.IGNORECASE | re.MULTILINE + + # Data Types: by PICTURE and USAGE + # Operators: **, *, +, -, /, <, >, <=, >=, =, <> + # Logical (?): NOT, AND, OR + + # Reserved words: + # http://opencobol.add1tocobol.com/#reserved-words + # Intrinsics: + # http://opencobol.add1tocobol.com/#does-opencobol-implement-any-intrinsic-functions + + tokens = { + 'root': [ + include('comment'), + include('strings'), + include('core'), + include('nums'), + (r'[a-z0-9]([\w\-]*[a-z0-9]+)?', Name.Variable), + # (r'[\s]+', Text), + (r'[ \t]+', Whitespace), + ], + 'comment': [ + (r'(^.{6}[*/].*\n|^.{6}|\*>.*\n)', Comment), + ], + 'core': [ + # Figurative constants + (r'(^|(?<=[^\w\-]))(ALL\s+)?' + r'((ZEROES)|(HIGH-VALUE|LOW-VALUE|QUOTE|SPACE|ZERO)(S)?)' + r'\s*($|(?=[^\w\-]))', + Name.Constant), + + # Reserved words STATEMENTS and other bolds + (words(( + 'ACCEPT', 'ADD', 'ALLOCATE', 'CALL', 'CANCEL', 'CLOSE', 'COMPUTE', + 'CONFIGURATION', 'CONTINUE', 'DATA', 'DELETE', 'DISPLAY', 'DIVIDE', + 'DIVISION', 'ELSE', 'END', 'END-ACCEPT', + 'END-ADD', 'END-CALL', 'END-COMPUTE', 'END-DELETE', 'END-DISPLAY', + 'END-DIVIDE', 'END-EVALUATE', 'END-IF', 'END-MULTIPLY', 'END-OF-PAGE', + 'END-PERFORM', 'END-READ', 'END-RETURN', 'END-REWRITE', 'END-SEARCH', + 'END-START', 'END-STRING', 'END-SUBTRACT', 'END-UNSTRING', 'END-WRITE', + 'ENVIRONMENT', 'EVALUATE', 'EXIT', 'FD', 'FILE', 'FILE-CONTROL', 'FOREVER', + 'FREE', 'GENERATE', 'GO', 'GOBACK', 'IDENTIFICATION', 'IF', 'INITIALIZE', + 'INITIATE', 'INPUT-OUTPUT', 'INSPECT', 'INVOKE', 'I-O-CONTROL', 'LINKAGE', + 'LOCAL-STORAGE', 'MERGE', 'MOVE', 'MULTIPLY', 'OPEN', 'PERFORM', + 'PROCEDURE', 'PROGRAM-ID', 'RAISE', 'READ', 'RELEASE', 'RESUME', + 'RETURN', 'REWRITE', 'SCREEN', 'SD', 'SEARCH', 'SECTION', 'SET', + 'SORT', 'START', 'STOP', 'STRING', 'SUBTRACT', 'SUPPRESS', + 'TERMINATE', 'THEN', 'UNLOCK', 'UNSTRING', 'USE', 'VALIDATE', + 'WORKING-STORAGE', 'WRITE'), prefix=r'(^|(?<=[^\w\-]))', + suffix=r'\s*($|(?=[^\w\-]))'), + Keyword.Reserved), + + # Reserved words + (words(( + 'ACCESS', 'ADDRESS', 'ADVANCING', 'AFTER', 'ALL', + 'ALPHABET', 'ALPHABETIC', 'ALPHABETIC-LOWER', 'ALPHABETIC-UPPER', + 'ALPHANUMERIC', 'ALPHANUMERIC-EDITED', 'ALSO', 'ALTER', 'ALTERNATE', + 'ANY', 'ARE', 'AREA', 'AREAS', 'ARGUMENT-NUMBER', 'ARGUMENT-VALUE', 'AS', + 'ASCENDING', 'ASSIGN', 'AT', 'AUTO', 'AUTO-SKIP', 'AUTOMATIC', + 'AUTOTERMINATE', 'BACKGROUND-COLOR', 'BASED', 'BEEP', 'BEFORE', 'BELL', + 'BLANK', 'BLINK', 'BLOCK', 'BOTTOM', 'BY', 'BYTE-LENGTH', 'CHAINING', + 'CHARACTER', 'CHARACTERS', 'CLASS', 'CODE', 'CODE-SET', 'COL', + 'COLLATING', 'COLS', 'COLUMN', 'COLUMNS', 'COMMA', 'COMMAND-LINE', + 'COMMIT', 'COMMON', 'CONSTANT', 'CONTAINS', 'CONTENT', 'CONTROL', + 'CONTROLS', 'CONVERTING', 'COPY', 'CORR', 'CORRESPONDING', 'COUNT', 'CRT', + 'CURRENCY', 'CURSOR', 'CYCLE', 'DATE', 'DAY', 'DAY-OF-WEEK', 'DE', + 'DEBUGGING', 'DECIMAL-POINT', 'DECLARATIVES', 'DEFAULT', 'DELIMITED', + 'DELIMITER', 'DEPENDING', 'DESCENDING', 'DETAIL', 'DISK', + 'DOWN', 'DUPLICATES', 'DYNAMIC', 'EBCDIC', + 'ENTRY', 'ENVIRONMENT-NAME', 'ENVIRONMENT-VALUE', 'EOL', 'EOP', + 'EOS', 'ERASE', 'ERROR', 'ESCAPE', 'EXCEPTION', + 'EXCLUSIVE', 'EXTEND', 'EXTERNAL', 'FILE-ID', 'FILLER', 'FINAL', + 'FIRST', 'FIXED', 'FLOAT-LONG', 'FLOAT-SHORT', + 'FOOTING', 'FOR', 'FOREGROUND-COLOR', 'FORMAT', 'FROM', 'FULL', + 'FUNCTION', 'FUNCTION-ID', 'GIVING', 'GLOBAL', 'GROUP', + 'HEADING', 'HIGHLIGHT', 'I-O', 'ID', + 'IGNORE', 'IGNORING', 'IN', 'INDEX', 'INDEXED', 'INDICATE', + 'INITIAL', 'INITIALIZED', 'INPUT', 'INTO', 'INTRINSIC', 'INVALID', + 'IS', 'JUST', 'JUSTIFIED', 'KEY', 'LABEL', + 'LAST', 'LEADING', 'LEFT', 'LENGTH', 'LIMIT', 'LIMITS', 'LINAGE', + 'LINAGE-COUNTER', 'LINE', 'LINES', 'LOCALE', 'LOCK', + 'LOWLIGHT', 'MANUAL', 'MEMORY', 'MINUS', 'MODE', 'MULTIPLE', + 'NATIONAL', 'NATIONAL-EDITED', 'NATIVE', 'NEGATIVE', 'NEXT', 'NO', + 'NULL', 'NULLS', 'NUMBER', 'NUMBERS', 'NUMERIC', 'NUMERIC-EDITED', + 'OBJECT-COMPUTER', 'OCCURS', 'OF', 'OFF', 'OMITTED', 'ON', 'ONLY', + 'OPTIONAL', 'ORDER', 'ORGANIZATION', 'OTHER', 'OUTPUT', 'OVERFLOW', + 'OVERLINE', 'PACKED-DECIMAL', 'PADDING', 'PAGE', 'PARAGRAPH', + 'PLUS', 'POINTER', 'POSITION', 'POSITIVE', 'PRESENT', 'PREVIOUS', + 'PRINTER', 'PRINTING', 'PROCEDURE-POINTER', 'PROCEDURES', + 'PROCEED', 'PROGRAM', 'PROGRAM-POINTER', 'PROMPT', 'QUOTE', + 'QUOTES', 'RANDOM', 'RD', 'RECORD', 'RECORDING', 'RECORDS', 'RECURSIVE', + 'REDEFINES', 'REEL', 'REFERENCE', 'RELATIVE', 'REMAINDER', 'REMOVAL', + 'RENAMES', 'REPLACING', 'REPORT', 'REPORTING', 'REPORTS', 'REPOSITORY', + 'REQUIRED', 'RESERVE', 'RETURNING', 'REVERSE-VIDEO', 'REWIND', + 'RIGHT', 'ROLLBACK', 'ROUNDED', 'RUN', 'SAME', 'SCROLL', + 'SECURE', 'SEGMENT-LIMIT', 'SELECT', 'SENTENCE', 'SEPARATE', + 'SEQUENCE', 'SEQUENTIAL', 'SHARING', 'SIGN', 'SIGNED', 'SIGNED-INT', + 'SIGNED-LONG', 'SIGNED-SHORT', 'SIZE', 'SORT-MERGE', 'SOURCE', + 'SOURCE-COMPUTER', 'SPECIAL-NAMES', 'STANDARD', + 'STANDARD-1', 'STANDARD-2', 'STATUS', 'SUBKEY', 'SUM', + 'SYMBOLIC', 'SYNC', 'SYNCHRONIZED', 'TALLYING', 'TAPE', + 'TEST', 'THROUGH', 'THRU', 'TIME', 'TIMES', 'TO', 'TOP', 'TRAILING', + 'TRANSFORM', 'TYPE', 'UNDERLINE', 'UNIT', 'UNSIGNED', + 'UNSIGNED-INT', 'UNSIGNED-LONG', 'UNSIGNED-SHORT', 'UNTIL', 'UP', + 'UPDATE', 'UPON', 'USAGE', 'USING', 'VALUE', 'VALUES', 'VARYING', + 'WAIT', 'WHEN', 'WITH', 'WORDS', 'YYYYDDD', 'YYYYMMDD'), + prefix=r'(^|(?<=[^\w\-]))', suffix=r'\s*($|(?=[^\w\-]))'), + Keyword.Pseudo), + + # inactive reserved words + (words(( + 'ACTIVE-CLASS', 'ALIGNED', 'ANYCASE', 'ARITHMETIC', 'ATTRIBUTE', + 'B-AND', 'B-NOT', 'B-OR', 'B-XOR', 'BIT', 'BOOLEAN', 'CD', 'CENTER', + 'CF', 'CH', 'CHAIN', 'CLASS-ID', 'CLASSIFICATION', 'COMMUNICATION', + 'CONDITION', 'DATA-POINTER', 'DESTINATION', 'DISABLE', 'EC', 'EGI', + 'EMI', 'ENABLE', 'END-RECEIVE', 'ENTRY-CONVENTION', 'EO', 'ESI', + 'EXCEPTION-OBJECT', 'EXPANDS', 'FACTORY', 'FLOAT-BINARY-16', + 'FLOAT-BINARY-34', 'FLOAT-BINARY-7', 'FLOAT-DECIMAL-16', + 'FLOAT-DECIMAL-34', 'FLOAT-EXTENDED', 'FORMAT', 'FUNCTION-POINTER', + 'GET', 'GROUP-USAGE', 'IMPLEMENTS', 'INFINITY', 'INHERITS', + 'INTERFACE', 'INTERFACE-ID', 'INVOKE', 'LC_ALL', 'LC_COLLATE', + 'LC_CTYPE', 'LC_MESSAGES', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', + 'LINE-COUNTER', 'MESSAGE', 'METHOD', 'METHOD-ID', 'NESTED', 'NONE', + 'NORMAL', 'OBJECT', 'OBJECT-REFERENCE', 'OPTIONS', 'OVERRIDE', + 'PAGE-COUNTER', 'PF', 'PH', 'PROPERTY', 'PROTOTYPE', 'PURGE', + 'QUEUE', 'RAISE', 'RAISING', 'RECEIVE', 'RELATION', 'REPLACE', + 'REPRESENTS-NOT-A-NUMBER', 'RESET', 'RESUME', 'RETRY', 'RF', 'RH', + 'SECONDS', 'SEGMENT', 'SELF', 'SEND', 'SOURCES', 'STATEMENT', + 'STEP', 'STRONG', 'SUB-QUEUE-1', 'SUB-QUEUE-2', 'SUB-QUEUE-3', + 'SUPER', 'SYMBOL', 'SYSTEM-DEFAULT', 'TABLE', 'TERMINAL', 'TEXT', + 'TYPEDEF', 'UCS-4', 'UNIVERSAL', 'USER-DEFAULT', 'UTF-16', 'UTF-8', + 'VAL-STATUS', 'VALID', 'VALIDATE', 'VALIDATE-STATUS'), + prefix=r'(^|(?<=[^\w\-]))', suffix=r'\s*($|(?=[^\w\-]))'), + Error), + + # Data Types + (r'(^|(?<=[^\w\-]))' + r'(PIC\s+.+?(?=(\s|\.\s))|PICTURE\s+.+?(?=(\s|\.\s))|' + r'(COMPUTATIONAL)(-[1-5X])?|(COMP)(-[1-5X])?|' + r'BINARY-C-LONG|' + r'BINARY-CHAR|BINARY-DOUBLE|BINARY-LONG|BINARY-SHORT|' + r'BINARY)\s*($|(?=[^\w\-]))', Keyword.Type), + + # Operators + (r'(\*\*|\*|\+|-|/|<=|>=|<|>|==|/=|=)', Operator), + + # (r'(::)', Keyword.Declaration), + + (r'([(),;:&%.])', Punctuation), + + # Intrinsics + (r'(^|(?<=[^\w\-]))(ABS|ACOS|ANNUITY|ASIN|ATAN|BYTE-LENGTH|' + r'CHAR|COMBINED-DATETIME|CONCATENATE|COS|CURRENT-DATE|' + r'DATE-OF-INTEGER|DATE-TO-YYYYMMDD|DAY-OF-INTEGER|DAY-TO-YYYYDDD|' + r'EXCEPTION-(?:FILE|LOCATION|STATEMENT|STATUS)|EXP10|EXP|E|' + r'FACTORIAL|FRACTION-PART|INTEGER-OF-(?:DATE|DAY|PART)|INTEGER|' + r'LENGTH|LOCALE-(?:DATE|TIME(?:-FROM-SECONDS)?)|LOG(?:10)?|' + r'LOWER-CASE|MAX|MEAN|MEDIAN|MIDRANGE|MIN|MOD|NUMVAL(?:-C)?|' + r'ORD(?:-MAX|-MIN)?|PI|PRESENT-VALUE|RANDOM|RANGE|REM|REVERSE|' + r'SECONDS-FROM-FORMATTED-TIME|SECONDS-PAST-MIDNIGHT|SIGN|SIN|SQRT|' + r'STANDARD-DEVIATION|STORED-CHAR-LENGTH|SUBSTITUTE(?:-CASE)?|' + r'SUM|TAN|TEST-DATE-YYYYMMDD|TEST-DAY-YYYYDDD|TRIM|' + r'UPPER-CASE|VARIANCE|WHEN-COMPILED|YEAR-TO-YYYY)\s*' + r'($|(?=[^\w\-]))', Name.Function), + + # Booleans + (r'(^|(?<=[^\w\-]))(true|false)\s*($|(?=[^\w\-]))', Name.Builtin), + # Comparing Operators + (r'(^|(?<=[^\w\-]))(equal|equals|ne|lt|le|gt|ge|' + r'greater|less|than|not|and|or)\s*($|(?=[^\w\-]))', Operator.Word), + ], + + # \"[^\"\n]*\"|\'[^\'\n]*\' + 'strings': [ + # apparently strings can be delimited by EOL if they are continued + # in the next line + (r'"[^"\n]*("|\n)', String.Double), + (r"'[^'\n]*('|\n)", String.Single), + ], + + 'nums': [ + (r'\d+(\s*|\.$|$)', Number.Integer), + (r'[+-]?\d*\.\d+(E[-+]?\d+)?', Number.Float), + (r'[+-]?\d+\.\d*(E[-+]?\d+)?', Number.Float), + ], + } + + +class CobolFreeformatLexer(CobolLexer): + """ + Lexer for Free format OpenCOBOL code. + """ + name = 'COBOLFree' + aliases = ['cobolfree'] + filenames = ['*.cbl', '*.CBL'] + mimetypes = [] + url = 'https://opencobol.add1tocobol.com' + version_added = '1.6' + + flags = re.IGNORECASE | re.MULTILINE + + tokens = { + 'comment': [ + (r'(\*>.*\n|^\w*\*.*$)', Comment), + ], + } + + +class ABAPLexer(RegexLexer): + """ + Lexer for ABAP, SAP's integrated language. + """ + name = 'ABAP' + aliases = ['abap'] + filenames = ['*.abap', '*.ABAP'] + mimetypes = ['text/x-abap'] + url = 'https://community.sap.com/topics/abap' + version_added = '1.1' + + flags = re.IGNORECASE | re.MULTILINE + + tokens = { + 'common': [ + (r'\s+', Whitespace), + (r'^\*.*$', Comment.Single), + (r'\".*?\n', Comment.Single), + (r'##\w+', Comment.Special), + ], + 'variable-names': [ + (r'<\S+>', Name.Variable), + (r'\w[\w~]*(?:(\[\])|->\*)?', Name.Variable), + ], + 'root': [ + include('common'), + # function calls + (r'CALL\s+(?:BADI|CUSTOMER-FUNCTION|FUNCTION)', + Keyword), + (r'(CALL\s+(?:DIALOG|SCREEN|SUBSCREEN|SELECTION-SCREEN|' + r'TRANSACTION|TRANSFORMATION))\b', + Keyword), + (r'(FORM|PERFORM)(\s+)(\w+)', + bygroups(Keyword, Whitespace, Name.Function)), + (r'(PERFORM)(\s+)(\()(\w+)(\))', + bygroups(Keyword, Whitespace, Punctuation, Name.Variable, Punctuation)), + (r'(MODULE)(\s+)(\S+)(\s+)(INPUT|OUTPUT)', + bygroups(Keyword, Whitespace, Name.Function, Whitespace, Keyword)), + + # method implementation + (r'(METHOD)(\s+)([\w~]+)', + bygroups(Keyword, Whitespace, Name.Function)), + # method calls + (r'(\s+)([\w\-]+)([=\-]>)([\w\-~]+)', + bygroups(Whitespace, Name.Variable, Operator, Name.Function)), + # call methodnames returning style + (r'(?<=[=-]>)([\w\-~]+)(?=\()', Name.Function), + + # text elements + (r'(TEXT)(-)(\d{3})', + bygroups(Keyword, Punctuation, Number.Integer)), + (r'(TEXT)(-)(\w{3})', + bygroups(Keyword, Punctuation, Name.Variable)), + + # keywords with dashes in them. + # these need to be first, because for instance the -ID part + # of MESSAGE-ID wouldn't get highlighted if MESSAGE was + # first in the list of keywords. + (r'(ADD-CORRESPONDING|AUTHORITY-CHECK|' + r'CLASS-DATA|CLASS-EVENTS|CLASS-METHODS|CLASS-POOL|' + r'DELETE-ADJACENT|DIVIDE-CORRESPONDING|' + r'EDITOR-CALL|ENHANCEMENT-POINT|ENHANCEMENT-SECTION|EXIT-COMMAND|' + r'FIELD-GROUPS|FIELD-SYMBOLS|FIELD-SYMBOL|FUNCTION-POOL|' + r'INTERFACE-POOL|INVERTED-DATE|' + r'LOAD-OF-PROGRAM|LOG-POINT|' + r'MESSAGE-ID|MOVE-CORRESPONDING|MULTIPLY-CORRESPONDING|' + r'NEW-LINE|NEW-PAGE|NEW-SECTION|NO-EXTENSION|' + r'OUTPUT-LENGTH|PRINT-CONTROL|' + r'SELECT-OPTIONS|START-OF-SELECTION|SUBTRACT-CORRESPONDING|' + r'SYNTAX-CHECK|SYSTEM-EXCEPTIONS|' + r'TYPE-POOL|TYPE-POOLS|NO-DISPLAY' + r')\b', Keyword), + + # keyword kombinations + (r'(?])(CREATE\s+(PUBLIC|PRIVATE|DATA|OBJECT)|' + r'(PUBLIC|PRIVATE|PROTECTED)\s+SECTION|' + r'(TYPE|LIKE)\s+((LINE\s+OF|REF\s+TO|' + r'(SORTED|STANDARD|HASHED)\s+TABLE\s+OF))?|' + r'FROM\s+(DATABASE|MEMORY)|CALL\s+METHOD|' + r'(GROUP|ORDER) BY|HAVING|SEPARATED BY|' + r'GET\s+(BADI|BIT|CURSOR|DATASET|LOCALE|PARAMETER|' + r'PF-STATUS|(PROPERTY|REFERENCE)\s+OF|' + r'RUN\s+TIME|TIME\s+(STAMP)?)?|' + r'SET\s+(BIT|BLANK\s+LINES|COUNTRY|CURSOR|DATASET|EXTENDED\s+CHECK|' + r'HANDLER|HOLD\s+DATA|LANGUAGE|LEFT\s+SCROLL-BOUNDARY|' + r'LOCALE|MARGIN|PARAMETER|PF-STATUS|PROPERTY\s+OF|' + r'RUN\s+TIME\s+(ANALYZER|CLOCK\s+RESOLUTION)|SCREEN|' + r'TITLEBAR|UPADTE\s+TASK\s+LOCAL|USER-COMMAND)|' + r'CONVERT\s+((INVERTED-)?DATE|TIME|TIME\s+STAMP|TEXT)|' + r'(CLOSE|OPEN)\s+(DATASET|CURSOR)|' + r'(TO|FROM)\s+(DATA BUFFER|INTERNAL TABLE|MEMORY ID|' + r'DATABASE|SHARED\s+(MEMORY|BUFFER))|' + r'DESCRIBE\s+(DISTANCE\s+BETWEEN|FIELD|LIST|TABLE)|' + r'FREE\s(MEMORY|OBJECT)?|' + r'PROCESS\s+(BEFORE\s+OUTPUT|AFTER\s+INPUT|' + r'ON\s+(VALUE-REQUEST|HELP-REQUEST))|' + r'AT\s+(LINE-SELECTION|USER-COMMAND|END\s+OF|NEW)|' + r'AT\s+SELECTION-SCREEN(\s+(ON(\s+(BLOCK|(HELP|VALUE)-REQUEST\s+FOR|' + r'END\s+OF|RADIOBUTTON\s+GROUP))?|OUTPUT))?|' + r'SELECTION-SCREEN:?\s+((BEGIN|END)\s+OF\s+((TABBED\s+)?BLOCK|LINE|' + r'SCREEN)|COMMENT|FUNCTION\s+KEY|' + r'INCLUDE\s+BLOCKS|POSITION|PUSHBUTTON|' + r'SKIP|ULINE)|' + r'LEAVE\s+(LIST-PROCESSING|PROGRAM|SCREEN|' + r'TO LIST-PROCESSING|TO TRANSACTION)' + r'(ENDING|STARTING)\s+AT|' + r'FORMAT\s+(COLOR|INTENSIFIED|INVERSE|HOTSPOT|INPUT|FRAMES|RESET)|' + r'AS\s+(CHECKBOX|SUBSCREEN|WINDOW)|' + r'WITH\s+(((NON-)?UNIQUE)?\s+KEY|FRAME)|' + r'(BEGIN|END)\s+OF|' + r'DELETE(\s+ADJACENT\s+DUPLICATES\sFROM)?|' + r'COMPARING(\s+ALL\s+FIELDS)?|' + r'(INSERT|APPEND)(\s+INITIAL\s+LINE\s+(IN)?TO|\s+LINES\s+OF)?|' + r'IN\s+((BYTE|CHARACTER)\s+MODE|PROGRAM)|' + r'END-OF-(DEFINITION|PAGE|SELECTION)|' + r'WITH\s+FRAME(\s+TITLE)|' + r'(REPLACE|FIND)\s+((FIRST|ALL)\s+OCCURRENCES?\s+OF\s+)?(SUBSTRING|REGEX)?|' + r'MATCH\s+(LENGTH|COUNT|LINE|OFFSET)|' + r'(RESPECTING|IGNORING)\s+CASE|' + r'IN\s+UPDATE\s+TASK|' + r'(SOURCE|RESULT)\s+(XML)?|' + r'REFERENCE\s+INTO|' + + # simple kombinations + r'AND\s+(MARK|RETURN)|CLIENT\s+SPECIFIED|CORRESPONDING\s+FIELDS\s+OF|' + r'IF\s+FOUND|FOR\s+EVENT|INHERITING\s+FROM|LEAVE\s+TO\s+SCREEN|' + r'LOOP\s+AT\s+(SCREEN)?|LOWER\s+CASE|MATCHCODE\s+OBJECT|MODIF\s+ID|' + r'MODIFY\s+SCREEN|NESTING\s+LEVEL|NO\s+INTERVALS|OF\s+STRUCTURE|' + r'RADIOBUTTON\s+GROUP|RANGE\s+OF|REF\s+TO|SUPPRESS DIALOG|' + r'TABLE\s+OF|UPPER\s+CASE|TRANSPORTING\s+NO\s+FIELDS|' + r'VALUE\s+CHECK|VISIBLE\s+LENGTH|HEADER\s+LINE|COMMON\s+PART)\b', Keyword), + + # single word keywords. + (r'(^|(?<=(\s|\.)))(ABBREVIATED|ABSTRACT|ADD|ALIASES|ALIGN|ALPHA|' + r'ASSERT|AS|ASSIGN(ING)?|AT(\s+FIRST)?|' + r'BACK|BLOCK|BREAK-POINT|' + r'CASE|CAST|CATCH|CHANGING|CHECK|CLASS|CLEAR|COLLECT|COLOR|COMMIT|COND|CONV|' + r'CREATE|COMMUNICATION|COMPONENTS?|COMPUTE|CONCATENATE|CONDENSE|' + r'CONSTANTS|CONTEXTS|CONTINUE|CONTROLS|COUNTRY|CURRENCY|' + r'DATA|DATE|DECIMALS|DEFAULT|DEFINE|DEFINITION|DEFERRED|DEMAND|' + r'DETAIL|DIRECTORY|DIVIDE|DO|DUMMY|' + r'ELSE(IF)?|ENDAT|ENDCASE|ENDCATCH|ENDCLASS|ENDDO|ENDFORM|ENDFUNCTION|' + r'ENDIF|ENDINTERFACE|ENDLOOP|ENDMETHOD|ENDMODULE|ENDSELECT|ENDTRY|ENDWHILE|' + r'ENHANCEMENT|EVENTS|EXACT|EXCEPTIONS?|EXIT|EXPONENT|EXPORT|EXPORTING|EXTRACT|' + r'FETCH|FIELDS?|FOR|FORM|FORMAT|FREE|FROM|FUNCTION|' + r'HIDE|' + r'ID|IF|IMPORT|IMPLEMENTATION|IMPORTING|IN|INCLUDE|INCLUDING|' + r'INDEX|INFOTYPES|INITIALIZATION|INTERFACE|INTERFACES|INTO|' + r'LANGUAGE|LEAVE|LENGTH|LINES|LOAD|LOCAL|' + r'JOIN|' + r'KEY|' + r'NEW|NEXT|' + r'MAXIMUM|MESSAGE|METHOD[S]?|MINIMUM|MODULE|MODIFIER|MODIFY|MOVE|MULTIPLY|' + r'NODES|NUMBER|' + r'OBLIGATORY|OBJECT|OF|OFF|ON|OTHERS|OVERLAY|' + r'PACK|PAD|PARAMETERS|PERCENTAGE|POSITION|PROGRAM|PROVIDE|PUBLIC|PUT|PF\d\d|' + r'RAISE|RAISING|RANGES?|READ|RECEIVE|REDEFINITION|REFRESH|REJECT|REPORT|RESERVE|' + r'REF|RESUME|RETRY|RETURN|RETURNING|RIGHT|ROLLBACK|REPLACE|' + r'SCROLL|SEARCH|SELECT|SHIFT|SIGN|SINGLE|SIZE|SKIP|SORT|SPLIT|STATICS|STOP|' + r'STYLE|SUBMATCHES|SUBMIT|SUBTRACT|SUM(?!\()|SUMMARY|SUMMING|SUPPLY|SWITCH|' + r'TABLE|TABLES|TIMESTAMP|TIMES?|TIMEZONE|TITLE|\??TO|' + r'TOP-OF-PAGE|TRANSFER|TRANSLATE|TRY|TYPES|' + r'ULINE|UNDER|UNPACK|UPDATE|USING|' + r'VALUE|VALUES|VIA|VARYING|VARY|' + r'WAIT|WHEN|WHERE|WIDTH|WHILE|WITH|WINDOW|WRITE|XSD|ZERO)\b', Keyword), + + # builtins + (r'(abs|acos|asin|atan|' + r'boolc|boolx|bit_set|' + r'char_off|charlen|ceil|cmax|cmin|condense|contains|' + r'contains_any_of|contains_any_not_of|concat_lines_of|cos|cosh|' + r'count|count_any_of|count_any_not_of|' + r'dbmaxlen|distance|' + r'escape|exp|' + r'find|find_end|find_any_of|find_any_not_of|floor|frac|from_mixed|' + r'insert|' + r'lines|log|log10|' + r'match|matches|' + r'nmax|nmin|numofchar|' + r'repeat|replace|rescale|reverse|round|' + r'segment|shift_left|shift_right|sign|sin|sinh|sqrt|strlen|' + r'substring|substring_after|substring_from|substring_before|substring_to|' + r'tan|tanh|to_upper|to_lower|to_mixed|translate|trunc|' + r'xstrlen)(\()\b', bygroups(Name.Builtin, Punctuation)), + + (r'&[0-9]', Name), + (r'[0-9]+', Number.Integer), + + # operators which look like variable names before + # parsing variable names. + (r'(?<=(\s|.))(AND|OR|EQ|NE|GT|LT|GE|LE|CO|CN|CA|NA|CS|NOT|NS|CP|NP|' + r'BYTE-CO|BYTE-CN|BYTE-CA|BYTE-NA|BYTE-CS|BYTE-NS|' + r'IS\s+(NOT\s+)?(INITIAL|ASSIGNED|REQUESTED|BOUND))\b', Operator.Word), + + include('variable-names'), + + # standard operators after variable names, + # because < and > are part of field symbols. + (r'[?*<>=\-+&]', Operator), + (r"'(''|[^'])*'", String.Single), + (r"`([^`])*`", String.Single), + (r"([|}])([^{}|]*?)([|{])", + bygroups(Punctuation, String.Single, Punctuation)), + (r'[/;:()\[\],.]', Punctuation), + (r'(!)(\w+)', bygroups(Operator, Name)), + ], + } + + +class OpenEdgeLexer(RegexLexer): + """ + Lexer for OpenEdge ABL (formerly Progress) source code. + """ + name = 'OpenEdge ABL' + aliases = ['openedge', 'abl', 'progress'] + filenames = ['*.p', '*.cls'] + mimetypes = ['text/x-openedge', 'application/x-openedge'] + url = 'https://www.progress.com/openedge/features/abl' + version_added = '1.5' + + 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+', Whitespace), + (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'), + ], + } + + def analyse_text(text): + """Try to identify OpenEdge ABL based on a few common constructs.""" + result = 0 + + if 'END.' in text: + result += 0.05 + + if 'END PROCEDURE.' in text: + result += 0.05 + + if 'ELSE DO:' in text: + result += 0.05 + + return result + + +class GoodDataCLLexer(RegexLexer): + """ + Lexer for GoodData-CL script files. + """ + + name = 'GoodData-CL' + aliases = ['gooddata-cl'] + filenames = ['*.gdc'] + mimetypes = ['text/x-gooddata-cl'] + url = 'https://github.com/gooddata/GoodData-CL' + version_added = '1.4' + + flags = re.IGNORECASE + + # Syntax: + # https://github.com/gooddata/GoodData-CL/raw/master/cli/src/main/resources/com/gooddata/processor/COMMANDS.txt + tokens = { + 'root': [ + # Comments + (r'#.*', Comment.Single), + # Function call + (r'[a-z]\w*', Name.Function), + # Argument list + (r'\(', Punctuation, 'args-list'), + # Punctuation + (r';', Punctuation), + # Space is not significant + (r'\s+', Text) + ], + 'args-list': [ + (r'\)', Punctuation, '#pop'), + (r',', Punctuation), + (r'[a-z]\w*', Name.Variable), + (r'=', Operator), + (r'"', String, 'string-literal'), + (r'[0-9]+(?:\.[0-9]+)?(?:e[+-]?[0-9]{1,3})?', Number), + # Space is not significant + (r'\s', Whitespace) + ], + 'string-literal': [ + (r'\\[tnrfbae"\\]', String.Escape), + (r'"', String, '#pop'), + (r'[^\\"]+', String) + ] + } + + +class MaqlLexer(RegexLexer): + """ + Lexer for GoodData MAQL scripts. + """ + + name = 'MAQL' + aliases = ['maql'] + filenames = ['*.maql'] + mimetypes = ['text/x-gooddata-maql', 'application/x-gooddata-maql'] + url = 'https://help.gooddata.com/doc/enterprise/en/dashboards-and-insights/maql-analytical-query-language' + version_added = '1.4' + + 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+', Whitespace) + ], + 'string-literal': [ + (r'\\[tnrfbae"\\]', String.Escape), + (r'"', String, '#pop'), + (r'[^\\"]+', String) + ], + } diff --git a/venv/Lib/site-packages/pygments/lexers/c_cpp.py b/venv/Lib/site-packages/pygments/lexers/c_cpp.py new file mode 100644 index 0000000000000000000000000000000000000000..136448022df1510c5b5efd396269311b2fc1a9e8 --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/c_cpp.py @@ -0,0 +1,481 @@ +""" + pygments.lexers.c_cpp + ~~~~~~~~~~~~~~~~~~~~~ + + Lexers for C/C++ languages. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, include, bygroups, using, \ + this, inherit, default, words +from pygments.util import get_bool_opt +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Whitespace + +__all__ = ['CLexer', 'CppLexer'] + + +class CFamilyLexer(RegexLexer): + """ + For C family source code. This is used as a base class to avoid repetitious + definitions. + """ + + # The trailing ?, rather than *, avoids a geometric performance drop here. + #: only one /* */ style comment + _ws1 = r'\s*(?:/[*].*?[*]/\s*)?' + + # Hexadecimal part in an hexadecimal integer/floating-point literal. + # This includes decimal separators matching. + _hexpart = r'[0-9a-fA-F](\'?[0-9a-fA-F])*' + # Decimal part in an decimal integer/floating-point literal. + # This includes decimal separators matching. + _decpart = r'\d(\'?\d)*' + # Integer literal suffix (e.g. 'ull' or 'll'). + _intsuffix = r'(([uU]?[zZ])|([zZ][uU])|([uU][lL]{0,2})|([lL]{1,2}[uU]?))?' + + # Identifier regex with C and C++ Universal Character Name (UCN) support. + _ident = r'(?!\d)(?:[\w$]|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8})+' + _namespaced_ident = r'(?!\d)(?:[\w$]|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|::)+' + + # Single and multiline comment regexes + # Beware not to use *? for the inner content! When these regexes + # are embedded in larger regexes, that can cause the stuff*? to + # match more than it would have if the regex had been used in + # a standalone way ... + _comment_single = r'//(?:.|(?<=\\)\n)*\n' + _comment_multiline = r'/(?:\\\n)?[*](?:[^*]|[*](?!(?:\\\n)?/))*[*](?:\\\n)?/' + + # Regex to match optional comments + _possible_comments = rf'\s*(?:(?:(?:{_comment_single})|(?:{_comment_multiline}))\s*)*' + + tokens = { + 'whitespace': [ + # preprocessor directives: without whitespace + (r'^#if\s+0', Comment.Preproc, 'if0'), + ('^#', Comment.Preproc, 'macro'), + # or with whitespace + ('^(' + _ws1 + r')(#if\s+0)', + bygroups(using(this), Comment.Preproc), 'if0'), + ('^(' + _ws1 + ')(#)', + bygroups(using(this), Comment.Preproc), 'macro'), + # Labels: + # Line start and possible indentation. + (r'(^[ \t]*)' + # Not followed by keywords which can be mistaken as labels. + r'(?!(?:public|private|protected|default)\b)' + # Actual label, followed by a single colon. + r'(' + _ident + r')(\s*)(:)(?!:)', + bygroups(Whitespace, Name.Label, Whitespace, Punctuation)), + (r'\n', Whitespace), + (r'[^\S\n]+', Whitespace), + (r'\\\n', Text), # line continuation + (_comment_single, Comment.Single), + (_comment_multiline, Comment.Multiline), + # Open until EOF, so no ending delimiter + (r'/(\\\n)?[*][\w\W]*', Comment.Multiline), + ], + 'statements': [ + include('keywords'), + include('types'), + (r'([LuU]|u8)?(")', bygroups(String.Affix, String), 'string'), + (r"([LuU]|u8)?(')(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])(')", + bygroups(String.Affix, String.Char, String.Char, String.Char)), + + # Hexadecimal floating-point literals (C11, C++17) + (r'0[xX](' + _hexpart + r'\.' + _hexpart + r'|\.' + _hexpart + + r'|' + _hexpart + r')[pP][+-]?' + _hexpart + r'[lL]?', Number.Float), + + (r'(-)?(' + _decpart + r'\.' + _decpart + r'|\.' + _decpart + r'|' + + _decpart + r')[eE][+-]?' + _decpart + r'[fFlL]?', Number.Float), + (r'(-)?((' + _decpart + r'\.(' + _decpart + r')?|\.' + + _decpart + r')[fFlL]?)|(' + _decpart + r'[fFlL])', Number.Float), + (r'(-)?0[xX]' + _hexpart + _intsuffix, Number.Hex), + (r'(-)?0[bB][01](\'?[01])*' + _intsuffix, Number.Bin), + (r'(-)?0(\'?[0-7])+' + _intsuffix, Number.Oct), + (r'(-)?' + _decpart + _intsuffix, Number.Integer), + (r'[~!%^&*+=|?:<>/-]', Operator), + (r'[()\[\],.]', Punctuation), + (r'(true|false|NULL|nullptr)\b', Name.Builtin), + (_ident, Name) + ], + 'types': [ + (words(('int8', 'int16', 'int32', 'int64', 'wchar_t'), prefix=r'__', + suffix=r'\b'), Keyword.Reserved), + (words(('bool', 'int', 'long', 'float', 'short', 'double', 'char', + 'unsigned', 'signed', 'void', '_BitInt', + '__int128'), suffix=r'\b'), Keyword.Type) + ], + 'keywords': [ + (r'(struct|union)(\s+)', bygroups(Keyword, Whitespace), 'classname'), + (r'case\b', Keyword, 'case-value'), + (words(('asm', 'auto', 'break', 'const', 'constexpr', 'continue', 'countof', 'default', + 'defer', 'do', 'else', 'enum', 'extern', 'for', 'goto', 'if', 'register', + 'restricted', 'return', 'sizeof', 'struct', 'static', 'switch', + 'typedef', 'typeof', 'typeof_unqual', 'volatile', 'while', 'union', + 'thread_local', 'alignas', 'alignof', 'static_assert', '_Pragma', 'fortran'), + suffix=r'\b'), Keyword), + (words(('inline', '_inline', '__inline', 'naked', 'restrict', + 'thread'), suffix=r'\b'), Keyword.Reserved), + # Vector intrinsics + (r'(__m(128i|128d|128|64))\b', Keyword.Reserved), + # Microsoft-isms + (words(( + 'asm', 'based', 'except', 'stdcall', 'cdecl', + 'fastcall', 'declspec', 'finally', 'try', + 'leave', 'w64', 'unaligned', 'raise', 'noop', + 'identifier', 'forceinline', 'assume', 'null'), + prefix=r'__', suffix=r'\b'), Keyword.Reserved) + ], + 'root': [ + include('whitespace'), + include('keywords'), + # functions + (r'(' + _namespaced_ident + r'(?:[&*\s])+)' # return arguments + r'(' + _possible_comments + r')' + r'(' + _namespaced_ident + r')' # method name + r'(' + _possible_comments + r')' + r'(\([^;"\')]*?\))' # signature + r'(' + _possible_comments + r')' + r'([^;{/"\']*)(\{)', + bygroups(using(this), using(this, state='whitespace'), + Name.Function, using(this, state='whitespace'), + using(this), using(this, state='whitespace'), + using(this), Punctuation), + 'function'), + # function declarations + (r'(' + _namespaced_ident + r'(?:[&*\s])+)' # return arguments + r'(' + _possible_comments + r')' + r'(' + _namespaced_ident + r')' # method name + r'(' + _possible_comments + r')' + r'(\([^;"\')]*?\))' # signature + r'(' + _possible_comments + r')' + r'([^;/"\']*)(;)', + bygroups(using(this), using(this, state='whitespace'), + Name.Function, using(this, state='whitespace'), + using(this), using(this, state='whitespace'), + using(this), Punctuation)), + include('types'), + default('statement'), + ], + 'statement': [ + include('whitespace'), + include('statements'), + (r'\}', Punctuation), + (r'[{;]', Punctuation, '#pop'), + ], + 'function': [ + include('whitespace'), + include('statements'), + (';', Punctuation), + (r'\{', Punctuation, '#push'), + (r'\}', Punctuation, '#pop'), + ], + 'string': [ + (r'"', String, '#pop'), + (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|' + r'u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})', String.Escape), + (r'[^\\"\n]+', String), # all other characters + (r'\\\n', String), # line continuation + (r'\\', String), # stray backslash + ], + 'macro': [ + (r'('+_ws1+r')(include)('+_ws1+r')("[^"]+"|<[^>]+>)([^\S\n]*)([^/\n]*/[*][\s\S]*?[*]/)', + bygroups(using(this), Comment.Preproc, using(this), + Comment.PreprocFile, using(this), Comment.Multiline)), + (r'('+_ws1+r')(include)('+_ws1+r')("[^"]+"|<[^>]+>)([^\S\n]*)([^\n]*)', + bygroups(using(this), Comment.Preproc, using(this), + Comment.PreprocFile, using(this), Comment.Single)), + (r'[^/\n]+', Comment.Preproc), + (r'/[*][\s\S]*?[*]/', Comment.Multiline), + (r'//.*?\n', Comment.Single, '#pop'), + (r'/', Comment.Preproc), + (r'(?<=\\)\n', Comment.Preproc), + (r'\n', Comment.Preproc, '#pop'), + ], + 'if0': [ + (r'^\s*#if.*?(?)', Text, '#pop'), + default('#pop') + ], + # Mark identifiers preceded by `case` keyword as constants. + 'case-value': [ + (r'(?)', Text, '#pop'), + default('#pop') + ], + 'enumname': [ + include('whitespace'), + # 'enum class' and 'enum struct' C++11 support + (words(('class', 'struct'), suffix=r'\b'), Keyword), + # C++26 annotations before enum name + (r'(\[\[)(=)(' + CFamilyLexer._ident + r')', + bygroups(Punctuation, Punctuation, Name.Decorator), 'annotation'), + # C++ attributes before enum name + (r'\[\[(?=[^\[\]]*\]\])', Punctuation, 'attribute'), + (CFamilyLexer._ident, Name.Class, '#pop'), + # template specification + (r'\s*(?=>)', Text, '#pop'), + default('#pop') + ], + 'attribute': [ + (r'using\b', Keyword), + (r':', Punctuation), + inherit, + ], + 'keywords': [ + (r'(class|concept|typename)(\s+)', bygroups(Keyword, Whitespace), 'classname'), + (words(( + 'catch', 'const_cast', 'delete', 'dynamic_cast', 'explicit', + 'export', 'friend', 'mutable', 'new', 'operator', + 'private', 'protected', 'public', 'reinterpret_cast', 'class', + '__restrict', 'static_cast', 'template', 'this', 'throw', 'throws', + 'try', 'typeid', 'using', 'virtual', 'concept', + 'decltype', 'noexcept', 'override', 'final', 'constinit', 'consteval', + 'co_await', 'co_return', 'co_yield', 'requires', 'import', 'module', + 'typename', 'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not', + 'not_eq', 'or', 'or_eq', 'xor', 'xor_eq', 'contract_assert', 'pre', 'post'), + suffix=r'\b'), Keyword), + (r'namespace\b', Keyword, 'namespace'), + (r'(enum)(\s+)', bygroups(Keyword, Whitespace), 'enumname'), + inherit + ], + 'types': [ + (r'char(16_t|32_t|8_t)\b', Keyword.Type), + inherit + ], + 'namespace': [ + (r';', Punctuation, ('#pop', 'root')), + (r'\{', Punctuation, ('#pop', 'namespace-body')), + (r'inline\b', Keyword.Reserved), + (CFamilyLexer._ident, Name.Namespace), + include('statement') + ], + 'namespace-body': [ + (r'\}', Punctuation, '#pop'), + include('root'), + ], + 'annotation': [ + (r'\]\]', Punctuation, '#pop'), + (r'\(', Punctuation, 'annotation-args'), + (r'::', Punctuation), + (r',', Punctuation), + (CFamilyLexer._ident, Name.Decorator), + include('whitespace'), + ], + 'annotation-args': [ + (r'\)', Punctuation, '#pop'), + (r'\(', Punctuation, '#push'), + include('statements'), + ], + } + + def analyse_text(text): + if re.search('#include <[a-z_]+>', text): + return 0.2 + if re.search('using namespace ', text): + return 0.4 diff --git a/venv/Lib/site-packages/pygments/lexers/c_like.py b/venv/Lib/site-packages/pygments/lexers/c_like.py new file mode 100644 index 0000000000000000000000000000000000000000..a5f991cb27e5fba8d4d26686efd0e113682e8f01 --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/c_like.py @@ -0,0 +1,743 @@ +""" + pygments.lexers.c_like + ~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for other C-like languages. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, include, bygroups, inherit, words, \ + default +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Whitespace + +from pygments.lexers.c_cpp import CLexer, CppLexer +from pygments.lexers import _mql_builtins + +__all__ = ['PikeLexer', 'NesCLexer', 'ClayLexer', 'ECLexer', 'ValaLexer', + 'CudaLexer', 'SwigLexer', 'MqlLexer', 'ArduinoLexer', 'CharmciLexer', + 'OmgIdlLexer', 'PromelaLexer'] + + +class PikeLexer(CppLexer): + """ + For `Pike `_ source code. + """ + name = 'Pike' + aliases = ['pike'] + filenames = ['*.pike', '*.pmod'] + mimetypes = ['text/x-pike'] + version_added = '2.0' + + 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, Whitespace), 'classname'), + (r'[~!%^&*+=|?:<>/@-]', Operator), + inherit, + ], + 'classname': [ + (r'[a-zA-Z_]\w*', Name.Class, '#pop'), + # template specification + (r'\s*(?=>)', Whitespace, '#pop'), + ], + } + + +class NesCLexer(CLexer): + """ + For `nesC `_ source code with preprocessor + directives. + """ + name = 'nesC' + aliases = ['nesc'] + filenames = ['*.nc'] + mimetypes = ['text/x-nescsrc'] + version_added = '2.0' + + 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 ClayLexer(RegexLexer): + """ + For Clay source. + """ + name = 'Clay' + filenames = ['*.clay'] + aliases = ['clay'] + mimetypes = ['text/x-clay'] + url = 'http://claylabs.com/clay' + version_added = '2.0' + + tokens = { + 'root': [ + (r'\s+', Whitespace), + (r'//.*?$', Comment.Single), + (r'/(\\\n)?[*][\s\S]*?[*](\\\n)?/', Comment.Multiline), + (words(('public', 'private', 'import', 'as', 'record', 'variant', + 'instance', 'define', 'overload', 'default', + 'external', 'alias', 'rvalue', 'ref', + 'forward', 'inline', 'noinline', + 'forceinline', 'enum', 'var', 'and', 'or', + 'not', 'if', 'else', 'goto', 'return', + 'while', 'switch', 'case', 'break', + 'continue', 'for', 'in', 'true', 'false', + 'try', 'catch', 'throw', 'finally', + 'onerror', 'staticassert', 'eval', 'when', + 'newtype', '__FILE__', '__LINE__', + '__COLUMN__', '__ARG__'), prefix=r'\b', suffix=r'\b'), Keyword), + (r'[~!%^&*+=|:<>/-]', Operator), + (r'[#(){}\[\],;.]', Punctuation), + (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex), + (r'\d+[LlUu]*', Number.Integer), + (r'\b(true|false)\b', Name.Builtin), + (r'(?i)[a-z_?][\w?]*', Name), + (r'"""', String, 'tdqs'), + (r'"', String, 'dqs'), + ], + 'strings': [ + (r'(?i)\\(x[0-9a-f]{2}|.)', String.Escape), + (r'[^\\"]+', String), + ], + 'nl': [ + (r'\n', String), + ], + 'dqs': [ + (r'"', String, '#pop'), + include('strings'), + ], + 'tdqs': [ + (r'"""', String, '#pop'), + include('strings'), + include('nl'), + ], + } + + +class ECLexer(CLexer): + """ + For eC source code with preprocessor directives. + """ + name = 'eC' + aliases = ['ec'] + filenames = ['*.ec', '*.eh'] + mimetypes = ['text/x-echdr', 'text/x-ecsrc'] + url = 'https://ec-lang.org' + version_added = '1.5' + + 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, Whitespace), 'classname'), + (r'(null|value|this)\b', Name.Builtin), + inherit, + ] + } + + +class ValaLexer(RegexLexer): + """ + For Vala source code with preprocessor directives. + """ + name = 'Vala' + aliases = ['vala', 'vapi'] + filenames = ['*.vala', '*.vapi'] + mimetypes = ['text/x-vala'] + url = 'https://vala.dev' + version_added = '1.1' + + tokens = { + 'whitespace': [ + (r'^\s*#if\s+0', Comment.Preproc, 'if0'), + (r'^\s*#(?:if|elif|else|endif)\b[^\n]*', Comment.Preproc), + (r'\n', Whitespace), + (r'\s+', Whitespace), + (r'\\\n', Text), # line continuation + (r'//(\n|[\s\S]*?[^\\]\n)', Comment.Single), + (r'/(\\\n)?[*][\s\S]*?[*](\\\n)?/', Comment.Multiline), + ], + 'statements': [ + (r'(?s)""".*?"""', String), # verbatim strings + (r'[L@]?"', String, 'string'), + (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", + String.Char), + (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), + (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), + (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex), + (r'0[0-7]+[Ll]?', Number.Oct), + (r'\d+[Ll]?', Number.Integer), + (r'[~!%^&*+=|?:<>/-]', Operator), + (r'(\[)(Compact|Immutable|(?:Boolean|Simple)Type)(\])', + bygroups(Punctuation, Name.Decorator, Punctuation)), + # TODO: "correctly" parse complex code attributes + (r'(\[)(CCode|(?:Integer|Floating)Type)', + bygroups(Punctuation, Name.Decorator)), + (r'[()\[\],.]', Punctuation), + (words(( + 'as', 'base', 'break', 'case', 'catch', 'construct', 'continue', + 'default', 'delete', 'do', 'else', 'enum', 'finally', 'for', + 'foreach', 'get', 'if', 'in', 'is', 'lock', 'new', 'out', 'params', + 'return', 'set', 'sizeof', 'switch', 'this', 'throw', 'try', + 'typeof', 'while', 'yield'), suffix=r'\b'), + Keyword), + (words(( + 'abstract', 'const', 'delegate', 'dynamic', 'ensures', 'extern', + 'inline', 'internal', 'override', 'owned', 'private', 'protected', + 'public', 'ref', 'requires', 'signal', 'static', 'throws', 'unowned', + 'var', 'virtual', 'volatile', 'weak', 'yields'), suffix=r'\b'), + Keyword.Declaration), + (r'(namespace|using)(\s+)', bygroups(Keyword.Namespace, Whitespace), + 'namespace'), + (r'(class|errordomain|interface|struct)(\s+)', + bygroups(Keyword.Declaration, Whitespace), 'class'), + (r'(\.)([a-zA-Z_]\w*)', + bygroups(Operator, Name.Attribute)), + # void is an actual keyword, others are in glib-2.0.vapi + (words(( + 'void', 'bool', 'char', 'double', 'float', 'int', 'int8', 'int16', + 'int32', 'int64', 'long', 'short', 'size_t', 'ssize_t', 'string', + 'time_t', 'uchar', 'uint', 'uint8', 'uint16', 'uint32', 'uint64', + 'ulong', 'unichar', 'ushort'), suffix=r'\b'), + Keyword.Type), + (r'(true|false|null)\b', Name.Builtin), + (r'[a-zA-Z_]\w*', Name), + ], + 'root': [ + include('whitespace'), + default('statement'), + ], + 'statement': [ + include('whitespace'), + include('statements'), + ('[{}]', Punctuation), + (';', Punctuation, '#pop'), + ], + 'string': [ + (r'"', String, '#pop'), + (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), + (r'[^\\"\n]+', String), # all other characters + (r'\\\n', String), # line continuation + (r'\\', String), # stray backslash + ], + 'if0': [ + (r'^\s*#if.*?(?>>'} + + def get_tokens_unprocessed(self, text, stack=('root',)): + for index, token, value in CppLexer.get_tokens_unprocessed(self, text, stack): + if token is Name: + if value in self.variable_qualifiers: + token = Keyword.Type + elif value in self.vector_types: + token = Keyword.Type + elif value in self.variables: + token = Name.Builtin + elif value in self.execution_confs: + token = Keyword.Pseudo + elif value in self.function_qualifiers: + token = Keyword.Reserved + elif value in self.functions: + token = Name.Function + yield index, token, value + + +class SwigLexer(CppLexer): + """ + For `SWIG `_ source code. + """ + name = 'SWIG' + aliases = ['swig'] + filenames = ['*.swg', '*.i'] + mimetypes = ['text/swig'] + version_added = '2.0' + priority = 0.04 # Lower than C/C++ and Objective C/C++ + + tokens = { + 'root': [ + # Match it here so it won't be matched as a function in the rest of root + (r'\$\**\&?\w+', Name), + inherit + ], + 'statements': [ + # SWIG directives + (r'(%[a-z_][a-z0-9_]*)', Name.Function), + # Special variables + (r'\$\**\&?\w+', Name), + # Stringification / additional preprocessor directives + (r'##*[a-zA-Z_]\w*', Comment.Preproc), + inherit, + ], + } + + # This is a far from complete set of SWIG directives + swig_directives = { + # Most common directives + '%apply', '%define', '%director', '%enddef', '%exception', '%extend', + '%feature', '%fragment', '%ignore', '%immutable', '%import', '%include', + '%inline', '%insert', '%module', '%newobject', '%nspace', '%pragma', + '%rename', '%shared_ptr', '%template', '%typecheck', '%typemap', + # Less common directives + '%arg', '%attribute', '%bang', '%begin', '%callback', '%catches', '%clear', + '%constant', '%copyctor', '%csconst', '%csconstvalue', '%csenum', + '%csmethodmodifiers', '%csnothrowexception', '%default', '%defaultctor', + '%defaultdtor', '%defined', '%delete', '%delobject', '%descriptor', + '%exceptionclass', '%exceptionvar', '%extend_smart_pointer', '%fragments', + '%header', '%ifcplusplus', '%ignorewarn', '%implicit', '%implicitconv', + '%init', '%javaconst', '%javaconstvalue', '%javaenum', '%javaexception', + '%javamethodmodifiers', '%kwargs', '%luacode', '%mutable', '%naturalvar', + '%nestedworkaround', '%perlcode', '%pythonabc', '%pythonappend', + '%pythoncallback', '%pythoncode', '%pythondynamic', '%pythonmaybecall', + '%pythonnondynamic', '%pythonprepend', '%refobject', '%shadow', '%sizeof', + '%trackobjects', '%types', '%unrefobject', '%varargs', '%warn', + '%warnfilter'} + + def analyse_text(text): + rv = 0 + # Search for SWIG directives, which are conventionally at the beginning of + # a line. The probability of them being within a line is low, so let another + # lexer win in this case. + matches = re.findall(r'^\s*(%[a-z_][a-z0-9_]*)', text, re.M) + for m in matches: + if m in SwigLexer.swig_directives: + rv = 0.98 + break + else: + rv = 0.91 # Fraction higher than MatlabLexer + return rv + + +class MqlLexer(CppLexer): + """ + For `MQL4 `_ and + `MQL5 `_ source code. + """ + name = 'MQL' + aliases = ['mql', 'mq4', 'mq5', 'mql4', 'mql5'] + filenames = ['*.mq4', '*.mq5', '*.mqh'] + mimetypes = ['text/x-mql'] + version_added = '2.0' + + 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 ArduinoLexer(CppLexer): + """ + For `Arduino(tm) `_ source. + + This is an extension of the CppLexer, as the Arduino® Language is a superset + of C++ + """ + + name = 'Arduino' + aliases = ['arduino'] + filenames = ['*.ino'] + mimetypes = ['text/x-arduino'] + version_added = '2.1' + + # Language sketch main structure functions + structure = {'setup', 'loop'} + + # Language operators + operators = {'not', 'or', 'and', 'xor'} + + # Language 'variables' + variables = { + 'DIGITAL_MESSAGE', 'FIRMATA_STRING', 'ANALOG_MESSAGE', 'REPORT_DIGITAL', + 'REPORT_ANALOG', 'INPUT_PULLUP', 'SET_PIN_MODE', 'INTERNAL2V56', 'SYSTEM_RESET', + 'LED_BUILTIN', 'INTERNAL1V1', 'SYSEX_START', 'INTERNAL', 'EXTERNAL', 'HIGH', + 'LOW', 'INPUT', 'OUTPUT', 'INPUT_PULLUP', 'LED_BUILTIN', 'true', 'false', + 'void', 'boolean', 'char', 'unsigned char', 'byte', 'int', 'unsigned int', + 'word', 'long', 'unsigned long', 'short', 'float', 'double', 'string', 'String', + 'array', 'static', 'volatile', 'const', 'boolean', 'byte', 'word', 'string', + 'String', 'array', 'int', 'float', 'private', 'char', 'virtual', 'operator', + 'sizeof', 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int8_t', 'int16_t', + 'int32_t', 'int64_t', 'dynamic_cast', 'typedef', 'const_cast', 'const', + 'struct', 'static_cast', 'union', 'unsigned', 'long', 'volatile', 'static', + 'protected', 'bool', 'public', 'friend', 'auto', 'void', 'enum', 'extern', + 'class', 'short', 'reinterpret_cast', 'double', 'register', 'explicit', + 'signed', 'inline', 'delete', '_Bool', 'complex', '_Complex', '_Imaginary', + 'atomic_bool', 'atomic_char', 'atomic_schar', 'atomic_uchar', 'atomic_short', + 'atomic_ushort', 'atomic_int', 'atomic_uint', 'atomic_long', 'atomic_ulong', + 'atomic_llong', 'atomic_ullong', 'PROGMEM'} + + # Language shipped functions and class ( ) + functions = { + 'KeyboardController', 'MouseController', 'SoftwareSerial', 'EthernetServer', + 'EthernetClient', 'LiquidCrystal', 'RobotControl', 'GSMVoiceCall', + 'EthernetUDP', 'EsploraTFT', 'HttpClient', 'RobotMotor', 'WiFiClient', + 'GSMScanner', 'FileSystem', 'Scheduler', 'GSMServer', 'YunClient', 'YunServer', + 'IPAddress', 'GSMClient', 'GSMModem', 'Keyboard', 'Ethernet', 'Console', + 'GSMBand', 'Esplora', 'Stepper', 'Process', 'WiFiUDP', 'GSM_SMS', 'Mailbox', + 'USBHost', 'Firmata', 'PImage', 'Client', 'Server', 'GSMPIN', 'FileIO', + 'Bridge', 'Serial', 'EEPROM', 'Stream', 'Mouse', 'Audio', 'Servo', 'File', + 'Task', 'GPRS', 'WiFi', 'Wire', 'TFT', 'GSM', 'SPI', 'SD', + 'runShellCommandAsynchronously', 'analogWriteResolution', + 'retrieveCallingNumber', 'printFirmwareVersion', 'analogReadResolution', + 'sendDigitalPortPair', 'noListenOnLocalhost', 'readJoystickButton', + 'setFirmwareVersion', 'readJoystickSwitch', 'scrollDisplayRight', + 'getVoiceCallStatus', 'scrollDisplayLeft', 'writeMicroseconds', + 'delayMicroseconds', 'beginTransmission', 'getSignalStrength', + 'runAsynchronously', 'getAsynchronously', 'listenOnLocalhost', + 'getCurrentCarrier', 'readAccelerometer', 'messageAvailable', + 'sendDigitalPorts', 'lineFollowConfig', 'countryNameWrite', 'runShellCommand', + 'readStringUntil', 'rewindDirectory', 'readTemperature', 'setClockDivider', + 'readLightSensor', 'endTransmission', 'analogReference', 'detachInterrupt', + 'countryNameRead', 'attachInterrupt', 'encryptionType', 'readBytesUntil', + 'robotNameWrite', 'readMicrophone', 'robotNameRead', 'cityNameWrite', + 'userNameWrite', 'readJoystickY', 'readJoystickX', 'mouseReleased', + 'openNextFile', 'scanNetworks', 'noInterrupts', 'digitalWrite', 'beginSpeaker', + 'mousePressed', 'isActionDone', 'mouseDragged', 'displayLogos', 'noAutoscroll', + 'addParameter', 'remoteNumber', 'getModifiers', 'keyboardRead', 'userNameRead', + 'waitContinue', 'processInput', 'parseCommand', 'printVersion', 'readNetworks', + 'writeMessage', 'blinkVersion', 'cityNameRead', 'readMessage', 'setDataMode', + 'parsePacket', 'isListening', 'setBitOrder', 'beginPacket', 'isDirectory', + 'motorsWrite', 'drawCompass', 'digitalRead', 'clearScreen', 'serialEvent', + 'rightToLeft', 'setTextSize', 'leftToRight', 'requestFrom', 'keyReleased', + 'compassRead', 'analogWrite', 'interrupts', 'WiFiServer', 'disconnect', + 'playMelody', 'parseFloat', 'autoscroll', 'getPINUsed', 'setPINUsed', + 'setTimeout', 'sendAnalog', 'readSlider', 'analogRead', 'beginWrite', + 'createChar', 'motorsStop', 'keyPressed', 'tempoWrite', 'readButton', + 'subnetMask', 'debugPrint', 'macAddress', 'writeGreen', 'randomSeed', + 'attachGPRS', 'readString', 'sendString', 'remotePort', 'releaseAll', + 'mouseMoved', 'background', 'getXChange', 'getYChange', 'answerCall', + 'getResult', 'voiceCall', 'endPacket', 'constrain', 'getSocket', 'writeJSON', + 'getButton', 'available', 'connected', 'findUntil', 'readBytes', 'exitValue', + 'readGreen', 'writeBlue', 'startLoop', 'IPAddress', 'isPressed', 'sendSysex', + 'pauseMode', 'gatewayIP', 'setCursor', 'getOemKey', 'tuneWrite', 'noDisplay', + 'loadImage', 'switchPIN', 'onRequest', 'onReceive', 'changePIN', 'playFile', + 'noBuffer', 'parseInt', 'overflow', 'checkPIN', 'knobRead', 'beginTFT', + 'bitClear', 'updateIR', 'bitWrite', 'position', 'writeRGB', 'highByte', + 'writeRed', 'setSpeed', 'readBlue', 'noStroke', 'remoteIP', 'transfer', + 'shutdown', 'hangCall', 'beginSMS', 'endWrite', 'attached', 'maintain', + 'noCursor', 'checkReg', 'checkPUK', 'shiftOut', 'isValid', 'shiftIn', 'pulseIn', + 'connect', 'println', 'localIP', 'pinMode', 'getIMEI', 'display', 'noBlink', + 'process', 'getBand', 'running', 'beginSD', 'drawBMP', 'lowByte', 'setBand', + 'release', 'bitRead', 'prepare', 'pointTo', 'readRed', 'setMode', 'noFill', + 'remove', 'listen', 'stroke', 'detach', 'attach', 'noTone', 'exists', 'buffer', + 'height', 'bitSet', 'circle', 'config', 'cursor', 'random', 'IRread', 'setDNS', + 'endSMS', 'getKey', 'micros', 'millis', 'begin', 'print', 'write', 'ready', + 'flush', 'width', 'isPIN', 'blink', 'clear', 'press', 'mkdir', 'rmdir', 'close', + 'point', 'yield', 'image', 'BSSID', 'click', 'delay', 'read', 'text', 'move', + 'peek', 'beep', 'rect', 'line', 'open', 'seek', 'fill', 'size', 'turn', 'stop', + 'home', 'find', 'step', 'tone', 'sqrt', 'RSSI', 'SSID', 'end', 'bit', 'tan', + 'cos', 'sin', 'pow', 'map', 'abs', 'max', 'min', 'get', 'run', 'put', + 'isAlphaNumeric', 'isAlpha', 'isAscii', 'isWhitespace', 'isControl', 'isDigit', + 'isGraph', 'isLowerCase', 'isPrintable', 'isPunct', 'isSpace', 'isUpperCase', + 'isHexadecimalDigit'} + + # do not highlight + suppress_highlight = { + 'namespace', 'template', 'mutable', 'using', 'asm', 'typeid', + 'typename', 'this', 'alignof', 'constexpr', 'decltype', 'noexcept', + 'static_assert', 'thread_local', 'restrict'} + + def get_tokens_unprocessed(self, text, stack=('root',)): + for index, token, value in CppLexer.get_tokens_unprocessed(self, text, stack): + if value in self.structure: + yield index, Name.Builtin, value + elif value in self.operators: + yield index, Operator, value + elif value in self.variables: + yield index, Keyword.Reserved, value + elif value in self.suppress_highlight: + yield index, Name, value + elif value in self.functions: + yield index, Name.Function, value + else: + yield index, token, value + + +class CharmciLexer(CppLexer): + """ + For `Charm++ `_ interface files (.ci). + """ + + name = 'Charmci' + aliases = ['charmci'] + filenames = ['*.ci'] + version_added = '2.4' + + mimetypes = [] + + tokens = { + 'keywords': [ + (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 OmgIdlLexer(CLexer): + """ + Lexer for Object Management Group Interface Definition Language. + """ + + name = 'OMG Interface Definition Language' + url = 'https://www.omg.org/spec/IDL/About-IDL/' + aliases = ['omg-idl'] + filenames = ['*.idl', '*.pidl'] + mimetypes = [] + version_added = '2.9' + + scoped_name = r'((::)?\w+)+' + + tokens = { + 'values': [ + (words(('true', 'false'), prefix=r'(?i)', suffix=r'\b'), Number), + (r'([Ll]?)(")', bygroups(String.Affix, String.Double), 'string'), + (r'([Ll]?)(\')(\\[^\']+)(\')', + bygroups(String.Affix, String.Char, String.Escape, String.Char)), + (r'([Ll]?)(\')(\\\')(\')', + bygroups(String.Affix, String.Char, String.Escape, String.Char)), + (r'([Ll]?)(\'.\')', bygroups(String.Affix, String.Char)), + (r'[+-]?\d+(\.\d*)?[Ee][+-]?\d+', Number.Float), + (r'[+-]?(\d+\.\d*)|(\d*\.\d+)([Ee][+-]?\d+)?', Number.Float), + (r'(?i)[+-]?0x[0-9a-f]+', Number.Hex), + (r'[+-]?[1-9]\d*', Number.Integer), + (r'[+-]?0[0-7]*', Number.Oct), + (r'[\+\-\*\/%^&\|~]', Operator), + (words(('<<', '>>')), Operator), + (scoped_name, Name), + (r'[{};:,<>\[\]]', Punctuation), + ], + 'annotation_params': [ + include('whitespace'), + (r'\(', Punctuation, '#push'), + include('values'), + (r'=', Punctuation), + (r'\)', Punctuation, '#pop'), + ], + 'annotation_params_maybe': [ + (r'\(', Punctuation, 'annotation_params'), + include('whitespace'), + default('#pop'), + ], + 'annotation_appl': [ + (r'@' + scoped_name, Name.Decorator, 'annotation_params_maybe'), + ], + 'enum': [ + include('whitespace'), + (r'[{,]', Punctuation), + (r'\w+', Name.Constant), + include('annotation_appl'), + (r'\}', Punctuation, '#pop'), + ], + 'root': [ + include('whitespace'), + (words(( + 'typedef', 'const', + 'in', 'out', 'inout', 'local', + ), prefix=r'(?i)', suffix=r'\b'), Keyword.Declaration), + (words(( + 'void', 'any', 'native', 'bitfield', + 'unsigned', 'boolean', 'char', 'wchar', 'octet', 'short', 'long', + 'int8', 'uint8', 'int16', 'int32', 'int64', 'uint16', 'uint32', 'uint64', + 'float', 'double', 'fixed', + 'sequence', 'string', 'wstring', 'map', + ), prefix=r'(?i)', suffix=r'\b'), Keyword.Type), + (words(( + '@annotation', 'struct', 'union', 'bitset', 'interface', + 'exception', 'valuetype', 'eventtype', 'component', + ), prefix=r'(?i)', suffix=r'(\s+)(\w+)'), bygroups(Keyword, Whitespace, Name.Class)), + (words(( + 'abstract', 'alias', 'attribute', 'case', 'connector', + 'consumes', 'context', 'custom', 'default', 'emits', 'factory', + 'finder', 'getraises', 'home', 'import', 'manages', 'mirrorport', + 'multiple', 'Object', 'oneway', 'primarykey', 'private', 'port', + 'porttype', 'provides', 'public', 'publishes', 'raises', + 'readonly', 'setraises', 'supports', 'switch', 'truncatable', + 'typeid', 'typename', 'typeprefix', 'uses', 'ValueBase', + ), prefix=r'(?i)', suffix=r'\b'), Keyword), + (r'(?i)(enum|bitmask)(\s+)(\w+)', + bygroups(Keyword, Whitespace, Name.Class), 'enum'), + (r'(?i)(module)(\s+)(\w+)', + bygroups(Keyword.Namespace, Whitespace, Name.Namespace)), + (r'(\w+)(\s*)(=)', bygroups(Name.Constant, Whitespace, Operator)), + (r'[\(\)]', Punctuation), + include('values'), + include('annotation_appl'), + ], + } + + +class PromelaLexer(CLexer): + """ + For the Promela language used with SPIN. + """ + + name = 'Promela' + aliases = ['promela'] + filenames = ['*.pml', '*.prom', '*.prm', '*.promela', '*.pr', '*.pm'] + mimetypes = ['text/x-promela'] + url = 'https://spinroot.com/spin/whatispin.html' + version_added = '2.18' + + # Promela's language reference: + # https://spinroot.com/spin/Man/promela.html + # Promela's grammar definition: + # https://spinroot.com/spin/Man/grammar.html + + tokens = { + 'statements': [ + (r'(\[\]|<>|/\\|\\/)|(U|W|V)\b', Operator), # LTL Operators + (r'@', Punctuation), #remoterefs + (r'(\.)([a-zA-Z_]\w*)', bygroups(Operator, Name.Attribute)), + inherit + ], + 'types': [ + # Predefined (data types) + (words(( + 'bit', 'bool', 'byte', 'pid', 'short', 'int', 'unsigned'), + suffix=r'\b'), + Keyword.Type), + ], + 'keywords': [ + # ControlFlow + (words(( + 'atomic', 'break', 'd_step', 'do', 'od', 'for', 'in', 'goto', + 'if', 'fi', 'unless'), suffix=r'\b'), + Keyword), + # BasicStatements + (words(( + 'assert', 'get_priority', 'printf', 'printm', 'set_priority'), + suffix=r'\b'), + Name.Function), + # Embedded C Code + (words(( + 'c_code', 'c_decl', 'c_expr', 'c_state', 'c_track'), + suffix=r'\b'), + Keyword), + # Predefined (local/global variables) + (words(( + '_', '_last', '_nr_pr', '_pid', '_priority', 'else', 'np_', + 'STDIN'), suffix=r'\b'), + Name.Builtin), + # Predefined (functions) + (words(( + 'empty', 'enabled', 'eval', 'full', 'len', 'nempty', 'nfull', + 'pc_value'), suffix=r'\b'), + Name.Function), + # Predefined (operators) + (r'run\b', Operator.Word), + # Declarators + (words(( + 'active', 'chan', 'D_proctype', 'hidden', 'init', 'local', + 'mtype', 'never', 'notrace', 'proctype', 'show', 'trace', + 'typedef', 'xr', 'xs'), suffix=r'\b'), + Keyword.Declaration), + # Declarators (suffixes) + (words(( + 'priority', 'provided'), suffix=r'\b'), + Keyword), + # MetaTerms (declarators) + (words(( + 'inline', 'ltl', 'select'), suffix=r'\b'), + Keyword.Declaration), + # MetaTerms (keywords) + (r'skip\b', Keyword), + ], + } diff --git a/venv/Lib/site-packages/pygments/lexers/capnproto.py b/venv/Lib/site-packages/pygments/lexers/capnproto.py new file mode 100644 index 0000000000000000000000000000000000000000..1e819c7f876f06b481d03b15c24e4b5140dc5414 --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/capnproto.py @@ -0,0 +1,74 @@ +""" + pygments.lexers.capnproto + ~~~~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for the Cap'n Proto schema language. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer, default +from pygments.token import Text, Comment, Keyword, Name, Literal, Whitespace + +__all__ = ['CapnProtoLexer'] + + +class CapnProtoLexer(RegexLexer): + """ + For Cap'n Proto source. + """ + name = 'Cap\'n Proto' + url = 'https://capnproto.org' + filenames = ['*.capnp'] + aliases = ['capnp'] + version_added = '2.2' + + tokens = { + 'root': [ + (r'#.*?$', Comment.Single), + (r'@[0-9a-zA-Z]*', Name.Decorator), + (r'=', Literal, 'expression'), + (r':', Name.Class, 'type'), + (r'\$', Name.Attribute, 'annotation'), + (r'(struct|enum|interface|union|import|using|const|annotation|' + r'extends|in|of|on|as|with|from|fixed)\b', + Keyword), + (r'[\w.]+', Name), + (r'[^#@=:$\w\s]+', Text), + (r'\s+', Whitespace), + ], + 'type': [ + (r'[^][=;,(){}$]+', Name.Class), + (r'[\[(]', Name.Class, 'parentype'), + default('#pop'), + ], + 'parentype': [ + (r'[^][;()]+', Name.Class), + (r'[\[(]', Name.Class, '#push'), + (r'[])]', Name.Class, '#pop'), + default('#pop'), + ], + 'expression': [ + (r'[^][;,(){}$]+', Literal), + (r'[\[(]', Literal, 'parenexp'), + default('#pop'), + ], + 'parenexp': [ + (r'[^][;()]+', Literal), + (r'[\[(]', Literal, '#push'), + (r'[])]', Literal, '#pop'), + default('#pop'), + ], + 'annotation': [ + (r'[^][;,(){}=:]+', Name.Attribute), + (r'[\[(]', Name.Attribute, 'annexp'), + default('#pop'), + ], + 'annexp': [ + (r'[^][;()]+', Name.Attribute), + (r'[\[(]', Name.Attribute, '#push'), + (r'[])]', Name.Attribute, '#pop'), + default('#pop'), + ], + } diff --git a/venv/Lib/site-packages/pygments/lexers/carbon.py b/venv/Lib/site-packages/pygments/lexers/carbon.py new file mode 100644 index 0000000000000000000000000000000000000000..d45b78800cd6b9082f5c83950b12761dfe24f74c --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/carbon.py @@ -0,0 +1,95 @@ +""" + pygments.lexers.carbon + ~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for the Carbon programming language. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +import re + +from pygments.lexer import RegexLexer, words +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Whitespace + +__all__ = ['CarbonLexer'] + + +class CarbonLexer(RegexLexer): + """ + For Carbon source. + """ + name = 'Carbon' + url = 'https://github.com/carbon-language/carbon-lang' + filenames = ['*.carbon'] + aliases = ['carbon'] + mimetypes = ['text/x-carbon'] + version_added = '2.15' + + flags = re.MULTILINE | re.DOTALL + + tokens = { + 'root': [ + (r'\n', Whitespace), + (r'\s+', Whitespace), + (r'\\\n', Text), + # comments + (r'//(.*?)\n', Comment.Single), + (r'/(\\\n)?[*].*?[*](\\\n)?/', Comment.Multiline), + # Declaration + (r'(package|import|api|namespace|library)\b', Keyword.Namespace), + (r'(abstract|alias|fn|class|interface|let|var|virtual|external|' + r'base|addr|extends|choice|constraint|impl)\b', Keyword.Declaration), + # Keywords + (words(('as', 'or', 'not', 'and', 'break', 'continue', 'case', + 'default', 'if', 'else', 'destructor', 'for', 'forall', + 'while', 'where', 'then', 'in', 'is', 'return', 'returned', + 'friend', 'partial', 'private', 'protected', 'observe', 'Self', + 'override', 'final', 'match', 'type', 'like'), suffix=r'\b'), Keyword), + (r'(self)\b', Keyword.Pseudo), + (r'(true|false)\b', Keyword.Constant), + (r'(auto|bool|string|i8|i16|i32|i64|u8|u16|u32|u64|' + r'f8|f16|f32|f64)\b', Keyword.Type), + # numeric literals + (r'[0-9]*[.][0-9]+', Number.Double), + (r'0b[01]+', Number.Bin), + (r'0o[0-7]+', Number.Oct), + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'[0-9]+', Number.Integer), + # string literal + (r'"(\\.|[^"\\])*"', String), + # char literal + (r'\'(\\.|[^\'\\])\'', String.Char), + # tokens + (r'<<=|>>=|<<|>>|<=|>=|\+=|-=|\*=|/=|\%=|\|=|&=|\^=|&&|\|\||&|\||' + r'\+\+|--|\%|\^|\~|==|!=|::|[.]{3}|->|=>|[+\-*/&]', Operator), + (r'[|<>=!()\[\]{}.,;:\?]', Punctuation), + # identifiers + (r'[^\W\d]\w*', Name.Other), + ] + } + + def analyse_text(text): + result = 0 + if 'forall' in text: + result += 0.1 + if 'type' in text: + result += 0.1 + if 'Self' in text: + result += 0.1 + if 'observe' in text: + result += 0.1 + if 'package' in text: + result += 0.1 + if 'library' in text: + result += 0.1 + if 'choice' in text: + result += 0.1 + if 'addr' in text: + result += 0.1 + if 'constraint' in text: + result += 0.1 + if 'impl' in text: + result += 0.1 + return result diff --git a/venv/Lib/site-packages/pygments/lexers/cddl.py b/venv/Lib/site-packages/pygments/lexers/cddl.py new file mode 100644 index 0000000000000000000000000000000000000000..38346ddb9ddbba4b9e83488124b56ad372fdcaf6 --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/cddl.py @@ -0,0 +1,172 @@ +""" + pygments.lexers.cddl + ~~~~~~~~~~~~~~~~~~~~ + + Lexer for the Concise data definition language (CDDL), a notational + convention to express CBOR and JSON data structures. + + More information: + https://datatracker.ietf.org/doc/rfc8610/ + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer, bygroups, include, words +from pygments.token import Comment, Error, Keyword, Name, Number, Operator, \ + Punctuation, String, Whitespace + +__all__ = ['CddlLexer'] + + +class CddlLexer(RegexLexer): + """ + Lexer for CDDL definitions. + """ + name = "CDDL" + url = 'https://datatracker.ietf.org/doc/rfc8610/' + aliases = ["cddl"] + filenames = ["*.cddl"] + mimetypes = ["text/x-cddl"] + version_added = '2.8' + + _prelude_types = [ + "any", + "b64legacy", + "b64url", + "bigfloat", + "bigint", + "bignint", + "biguint", + "bool", + "bstr", + "bytes", + "cbor-any", + "decfrac", + "eb16", + "eb64legacy", + "eb64url", + "encoded-cbor", + "false", + "float", + "float16", + "float16-32", + "float32", + "float32-64", + "float64", + "int", + "integer", + "mime-message", + "nil", + "nint", + "null", + "number", + "regexp", + "tdate", + "text", + "time", + "true", + "tstr", + "uint", + "undefined", + "unsigned", + "uri", + ] + + _controls = [ + ".and", + ".bits", + ".cbor", + ".cborseq", + ".default", + ".eq", + ".ge", + ".gt", + ".le", + ".lt", + ".ne", + ".regexp", + ".size", + ".within", + ] + + _re_id = ( + r"[$@A-Z_a-z]" + r"(?:[\-\.]+(?=[$@0-9A-Z_a-z])|[$@0-9A-Z_a-z])*" + + ) + + # While the spec reads more like "an int must not start with 0" we use a + # lookahead here that says "after a 0 there must be no digit". This makes the + # '0' the invalid character in '01', which looks nicer when highlighted. + _re_uint = r"(?:0b[01]+|0x[0-9a-fA-F]+|[1-9]\d*|0(?!\d))" + _re_int = r"-?" + _re_uint + + tokens = { + "commentsandwhitespace": [(r"\s+", Whitespace), (r";.+$", Comment.Single)], + "root": [ + include("commentsandwhitespace"), + # tag types + (rf"#(\d\.{_re_uint})?", Keyword.Type), # type or any + # occurrence + ( + rf"({_re_uint})?(\*)({_re_uint})?", + bygroups(Number, Operator, Number), + ), + (r"\?|\+", Operator), # occurrence + (r"\^", Operator), # cuts + (r"(\.\.\.|\.\.)", Operator), # rangeop + (words(_controls, suffix=r"\b"), Operator.Word), # ctlops + # into choice op + (rf"&(?=\s*({_re_id}|\())", Operator), + (rf"~(?=\s*{_re_id})", Operator), # unwrap op + (r"//|/(?!/)", Operator), # double und single slash + (r"=>|/==|/=|=", Operator), + (r"[\[\]{}\(\),<>:]", Punctuation), + # Bytestrings + (r"(b64)(')", bygroups(String.Affix, String.Single), "bstrb64url"), + (r"(h)(')", bygroups(String.Affix, String.Single), "bstrh"), + (r"'", String.Single, "bstr"), + # Barewords as member keys (must be matched before values, types, typenames, + # groupnames). + # Token type is String as barewords are always interpreted as such. + (rf"({_re_id})(\s*)(:)", + bygroups(String, Whitespace, Punctuation)), + # predefined types + (words(_prelude_types, prefix=r"(?![\-_$@])\b", suffix=r"\b(?![\-_$@])"), + Name.Builtin), + # user-defined groupnames, typenames + (_re_id, Name.Class), + # values + (r"0b[01]+", Number.Bin), + (r"0o[0-7]+", Number.Oct), + (r"0x[0-9a-fA-F]+(\.[0-9a-fA-F]+)?p[+-]?\d+", Number.Hex), # hexfloat + (r"0x[0-9a-fA-F]+", Number.Hex), # hex + # Float + (rf"{_re_int}(?=(\.\d|e[+-]?\d))(?:\.\d+)?(?:e[+-]?\d+)?", + Number.Float), + # Int + (_re_int, Number.Integer), + (r'"(\\\\|\\"|[^"])*"', String.Double), + ], + "bstrb64url": [ + (r"'", String.Single, "#pop"), + include("commentsandwhitespace"), + (r"\\.", String.Escape), + (r"[0-9a-zA-Z\-_=]+", String.Single), + (r".", Error), + # (r";.+$", Token.Other), + ], + "bstrh": [ + (r"'", String.Single, "#pop"), + include("commentsandwhitespace"), + (r"\\.", String.Escape), + (r"[0-9a-fA-F]+", String.Single), + (r".", Error), + ], + "bstr": [ + (r"'", String.Single, "#pop"), + (r"\\.", String.Escape), + (r"[^'\\]+", String.Single), + ], + } diff --git a/venv/Lib/site-packages/pygments/lexers/cel.py b/venv/Lib/site-packages/pygments/lexers/cel.py new file mode 100644 index 0000000000000000000000000000000000000000..f636b6171a9fffd97fadf016d5bef52fc2d5dc99 --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/cel.py @@ -0,0 +1,142 @@ +""" + pygments.lexers.cel + ~~~~~~~~~~~~~~~~~~~ + + Lexer for CEL (Common Expression Language). + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +__all__ = ['CELLexer'] + +import re + +from pygments.lexer import RegexLexer, words +from pygments.token import ( + Comment, Keyword, Name, Number, Operator, Punctuation, String, Whitespace, +) + + +class CELLexer(RegexLexer): + """Lexer for CEL (Common Expression Language).""" + + name = 'CEL' + aliases = ['cel'] + filenames = ['*.cel'] + mimetypes = [] + url = 'https://cel.dev' + version_added = '2.21' + + flags = re.MULTILINE | re.UNICODE + + # Escape sequence per the CEL spec: + # \a \b \f \n \r \t \v \\ \" \' \` \? + # \xHH or \XHH (exactly 2 hex digits) + # \uHHHH (exactly 4 hex digits) + # \UHHHHHHHH (exactly 8 hex digits) + # \OOO (3-digit octal, first digit 0-3) + # \. (fallback for unknown escapes) + _ESCAPE = r"""\\(?:[abfnrtv\\"'`?]|[xX][0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|[0-3][0-7][0-7]|.)""" + + # Raw prefix: r/R alone, or b/B combined with r/R in either order + _RAW = r'(?:[bB][rR]|[rR][bB]|[rR])' + + tokens = { + 'root': [ + (r'\s+', Whitespace), + # CEL only has line comments; no block comments. + (r'//.*$', Comment.Single), + + # Bytes and string literals. + # Raw variants (no escape processing) must be tried before + # non-raw so that br/rb/r prefixes are consumed greedily. + # Triple-quoted raw (br""", rb""", r""") + (_RAW + r'"""', String, 'triple-double-raw'), + (_RAW + r"'''", String, 'triple-single-raw'), + # Triple-quoted non-raw with optional b prefix (b""" or """) + (r'[bB]?"""', String, 'triple-double'), + (r"[bB]?'''", String, 'triple-single'), + # Single-line raw + (_RAW + r'"[^"\r\n]*"', String), + (_RAW + r"'[^'\r\n]*'", String), + # Single-line non-raw with optional b prefix + (r'[bB]?"', String, 'double-string'), + (r"[bB]?'", String, 'single-string'), + + # Numbers. + # uint_literal: integer (decimal or hex) followed by u/U suffix. + (r'(?:0[xX][0-9a-fA-F]+|0|[1-9][0-9]*)[uU]', Number.Integer), + # float_literal: the grammar requires digits on both sides of the + # decimal point for the dotted form — `1.` is not valid CEL. + (r'(?:[0-9]+\.[0-9]+(?:[eE][+-]?[0-9]+)?' + r'|[0-9]+[eE][+-]?[0-9]+' + r'|\.[0-9]+(?:[eE][+-]?[0-9]+)?)', + Number.Float), + # int_literal: hex or decimal. + (r'0[xX][0-9a-fA-F]+|0|[1-9][0-9]*', Number.Integer), + + # Reserved keywords (may not appear as identifiers). + (words(( + 'as', 'break', 'const', 'continue', 'else', 'for', + 'function', 'if', 'import', 'let', 'loop', 'namespace', + 'package', 'return', 'var', 'void', 'while', + ), suffix=r'\b'), Keyword.Reserved), + # `in` is a comparison operator keyword. + (r'in\b', Keyword), + # Built-in literal constants. + (words(('true', 'false', 'null'), suffix=r'\b'), Keyword.Constant), + + # Logical and comparison operators. + (r'&&|\|\|', Operator), + (r'==|!=|<=|>=', Operator), + # Arithmetic, unary, ternary, and remaining comparison operators. + (r'[+\-*/%<>!?]', Operator), + + # Punctuation: brackets, comma, dot, colon. + (r'[(){}\[\]]', Punctuation), + (r'[,.]', Punctuation), + (r':', Punctuation), + + # Identifiers: start with letter or underscore (Unicode-aware). + (r'[^\W\d]\w*', Name), + ], + + # Raw triple-quoted (no escape tokens; content is one big String). + 'triple-double-raw': [ + (r'"""', String, '#pop'), + (r'"(?!"")', String), + (r'[^"]+', String), + ], + 'triple-single-raw': [ + (r"'''", String, '#pop'), + (r"'(?!'')", String), + (r"[^']+", String), + ], + + # Non-raw triple-quoted (escape sequences highlighted separately). + 'triple-double': [ + (r'"""', String, '#pop'), + (_ESCAPE, String.Escape), + (r'"(?!"")', String), + (r'[^"\\]+', String), + ], + 'triple-single': [ + (r"'''", String, '#pop'), + (_ESCAPE, String.Escape), + (r"'(?!'')", String), + (r"[^'\\]+", String), + ], + + # Single-line non-raw strings (cannot span lines). + 'double-string': [ + (r'"', String, '#pop'), + (_ESCAPE, String.Escape), + (r'[^"\\\r\n]+', String), + ], + 'single-string': [ + (r"'", String, '#pop'), + (_ESCAPE, String.Escape), + (r"[^'\\\r\n]+", String), + ], + } diff --git a/venv/Lib/site-packages/pygments/lexers/chapel.py b/venv/Lib/site-packages/pygments/lexers/chapel.py new file mode 100644 index 0000000000000000000000000000000000000000..585be75d8a6ba3d1779c7782b80ce26a018fae8d --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/chapel.py @@ -0,0 +1,139 @@ +""" + pygments.lexers.chapel + ~~~~~~~~~~~~~~~~~~~~~~ + + Lexer for the Chapel language. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer, bygroups, words +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Whitespace + +__all__ = ['ChapelLexer'] + + +class ChapelLexer(RegexLexer): + """ + For Chapel source. + """ + name = 'Chapel' + url = 'https://chapel-lang.org/' + filenames = ['*.chpl'] + aliases = ['chapel', 'chpl'] + version_added = '2.0' + # mimetypes = ['text/x-chapel'] + + known_types = ('bool', 'bytes', 'complex', 'imag', 'int', 'locale', + 'nothing', 'opaque', 'range', 'real', 'string', 'uint', + 'void') + + type_modifiers_par = ('atomic', 'single', 'sync') + type_modifiers_mem = ('borrowed', 'owned', 'shared', 'unmanaged') + type_modifiers = (*type_modifiers_par, *type_modifiers_mem) + + declarations = ('config', 'const', 'in', 'inout', 'out', 'param', 'ref', + 'type', 'var') + + constants = ('false', 'nil', 'none', 'true') + + other_keywords = ('align', 'as', + 'begin', 'break', 'by', + 'catch', 'cobegin', 'coforall', 'continue', + 'defer', 'delete', 'dmapped', 'do', 'domain', + 'else', 'enum', 'except', 'export', 'extern', + 'for', 'forall', 'foreach', 'forwarding', + 'if', 'implements', 'import', 'index', 'init', 'inline', + 'label', 'lambda', 'let', 'lifetime', 'local', + 'new', 'noinit', + 'on', 'only', 'otherwise', 'override', + 'pragma', 'primitive', 'private', 'prototype', 'public', + 'reduce', 'require', 'return', + 'scan', 'select', 'serial', 'sparse', 'subdomain', + 'then', 'this', 'throw', 'throws', 'try', + 'use', + 'when', 'where', 'while', 'with', + 'yield', + 'zip') + + tokens = { + 'root': [ + (r'\n', Whitespace), + (r'\s+', Whitespace), + (r'\\\n', Text), + + (r'//(.*?)\n', Comment.Single), + (r'/(\\\n)?[*][\s\S]*?[*](\\\n)?/', Comment.Multiline), + + (words(declarations, suffix=r'\b'), Keyword.Declaration), + (words(constants, suffix=r'\b'), Keyword.Constant), + (words(known_types, suffix=r'\b'), Keyword.Type), + (words((*type_modifiers, *other_keywords), suffix=r'\b'), Keyword), + + (r'@', Keyword, 'attributename'), + (r'(iter)(\s+)', bygroups(Keyword, Whitespace), 'procname'), + (r'(proc)(\s+)', bygroups(Keyword, Whitespace), 'procname'), + (r'(operator)(\s+)', bygroups(Keyword, Whitespace), 'procname'), + (r'(class|interface|module|record|union)(\s+)', bygroups(Keyword, Whitespace), + 'classname'), + + # imaginary integers + (r'\d+i', Number), + (r'\d+\.\d*([Ee][-+]\d+)?i', Number), + (r'\.\d+([Ee][-+]\d+)?i', Number), + (r'\d+[Ee][-+]\d+i', Number), + + # reals cannot end with a period due to lexical ambiguity with + # .. operator. See reference for rationale. + (r'(\d*\.\d+)([eE][+-]?[0-9]+)?i?', Number.Float), + (r'\d+[eE][+-]?[0-9]+i?', Number.Float), + + # integer literals + # -- binary + (r'0[bB][01]+', Number.Bin), + # -- hex + (r'0[xX][0-9a-fA-F]+', Number.Hex), + # -- octal + (r'0[oO][0-7]+', Number.Oct), + # -- decimal + (r'[0-9]+', Number.Integer), + + # strings + (r'"(\\\\|\\"|[^"])*"', String), + (r"'(\\\\|\\'|[^'])*'", String), + + # tokens + (r'(=|\+=|-=|\*=|/=|\*\*=|%=|&=|\|=|\^=|&&=|\|\|=|<<=|>>=|' + r'<=>|<~>|\.\.|by|#|\.\.\.|' + r'&&|\|\||!|&|\||\^|~|<<|>>|' + r'==|!=|<=|>=|<|>|' + r'[+\-*/%]|\*\*)', Operator), + (r'[:;,.?()\[\]{}]', Punctuation), + + # identifiers + (r'[a-zA-Z_][\w$]*', Name.Other), + ], + 'classname': [ + (r'[a-zA-Z_][\w$]*', Name.Class, '#pop'), + ], + 'procname': [ + (r'([a-zA-Z_][.\w$]*|' # regular function name, including secondary + r'\~[a-zA-Z_][.\w$]*|' # support for legacy destructors + r'[+*/!~%<>=&^|\-:]{1,2})', # operators + Name.Function, '#pop'), + + # allow `proc (atomic T).foo` + (r'\(', Punctuation, "receivertype"), + (r'\)+\.', Punctuation), + ], + 'receivertype': [ + (words(type_modifiers, suffix=r'\b'), Keyword), + (words(known_types, suffix=r'\b'), Keyword.Type), + (r'[^()]*', Name.Other, '#pop'), + ], + 'attributename': [ + (r'[a-zA-Z_][.\w$]*', Name.Decorator, '#pop'), + ], + } diff --git a/venv/Lib/site-packages/pygments/lexers/clean.py b/venv/Lib/site-packages/pygments/lexers/clean.py new file mode 100644 index 0000000000000000000000000000000000000000..1500e2c4c599487665a25b347afeca774fe8224f --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/clean.py @@ -0,0 +1,180 @@ +""" + pygments.lexers.clean + ~~~~~~~~~~~~~~~~~~~~~ + + Lexer for the Clean language. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import ExtendedRegexLexer, words, default, include, bygroups +from pygments.token import Comment, Error, Keyword, Literal, Name, Number, \ + Operator, Punctuation, String, Whitespace + +__all__ = ['CleanLexer'] + + +class CleanLexer(ExtendedRegexLexer): + """ + Lexer for the general purpose, state-of-the-art, pure and lazy functional + programming language Clean. + + .. versionadded: 2.2 + """ + name = 'Clean' + url = 'http://clean.cs.ru.nl/Clean' + aliases = ['clean'] + filenames = ['*.icl', '*.dcl'] + version_added = '' + + keywords = ( + 'case', 'ccall', 'class', 'code', 'code inline', 'derive', 'export', + 'foreign', 'generic', 'if', 'in', 'infix', 'infixl', 'infixr', + 'instance', 'let', 'of', 'otherwise', 'special', 'stdcall', 'where', + 'with') + + modulewords = ('implementation', 'definition', 'system') + + lowerId = r'[a-z`][\w`]*' + upperId = r'[A-Z`][\w`]*' + funnyId = r'[~@#$%\^?!+\-*<>\\/|&=:]+' + scoreUpperId = r'_' + upperId + scoreLowerId = r'_' + lowerId + moduleId = r'[a-zA-Z_][a-zA-Z0-9_.`]+' + classId = '|'.join([lowerId, upperId, funnyId]) + + tokens = { + 'root': [ + include('comments'), + include('keywords'), + include('module'), + include('import'), + include('whitespace'), + include('literals'), + include('operators'), + include('delimiters'), + include('names'), + ], + 'whitespace': [ + (r'\s+', Whitespace), + ], + 'comments': [ + (r'//.*\n', Comment.Single), + (r'/\*', Comment.Multiline, 'comments.in'), + (r'/\*\*', Comment.Special, 'comments.in'), + ], + 'comments.in': [ + (r'\*\/', Comment.Multiline, '#pop'), + (r'/\*', Comment.Multiline, '#push'), + (r'[^*/]+', Comment.Multiline), + (r'\*(?!/)', Comment.Multiline), + (r'/', Comment.Multiline), + ], + 'keywords': [ + (words(keywords, prefix=r'\b', suffix=r'\b'), Keyword), + ], + 'module': [ + (words(modulewords, prefix=r'\b', suffix=r'\b'), Keyword.Namespace), + (r'\bmodule\b', Keyword.Namespace, 'module.name'), + ], + 'module.name': [ + include('whitespace'), + (moduleId, Name.Class, '#pop'), + ], + 'import': [ + (r'\b(import)\b(\s*)', bygroups(Keyword, Whitespace), 'import.module'), + (r'\b(from)\b(\s*)\b(' + moduleId + r')\b(\s*)\b(import)\b', + bygroups(Keyword, Whitespace, Name.Class, Whitespace, Keyword), + 'import.what'), + ], + 'import.module': [ + (r'\b(qualified)\b(\s*)', bygroups(Keyword, Whitespace)), + (r'(\s*)\b(as)\b', bygroups(Whitespace, Keyword), ('#pop', 'import.module.as')), + (moduleId, Name.Class), + (r'(\s*)(,)(\s*)', bygroups(Whitespace, Punctuation, Whitespace)), + (r'\s+', Whitespace), + default('#pop'), + ], + 'import.module.as': [ + include('whitespace'), + (lowerId, Name.Class, '#pop'), + (upperId, Name.Class, '#pop'), + ], + 'import.what': [ + (r'\b(class)\b(\s+)(' + classId + r')', + bygroups(Keyword, Whitespace, Name.Class), 'import.what.class'), + (r'\b(instance)(\s+)(' + classId + r')(\s+)', + bygroups(Keyword, Whitespace, Name.Class, Whitespace), 'import.what.instance'), + (r'(::)(\s*)\b(' + upperId + r')\b', + bygroups(Punctuation, Whitespace, Name.Class), 'import.what.type'), + (r'\b(generic)\b(\s+)\b(' + lowerId + '|' + upperId + r')\b', + bygroups(Keyword, Whitespace, Name)), + include('names'), + (r'(,)(\s+)', bygroups(Punctuation, Whitespace)), + (r'$', Whitespace, '#pop'), + include('whitespace'), + ], + 'import.what.class': [ + (r',', Punctuation, '#pop'), + (r'\(', Punctuation, 'import.what.class.members'), + (r'$', Whitespace, '#pop:2'), + include('whitespace'), + ], + 'import.what.class.members': [ + (r',', Punctuation), + (r'\.\.', Punctuation), + (r'\)', Punctuation, '#pop'), + include('names'), + ], + 'import.what.instance': [ + (r'[,)]', Punctuation, '#pop'), + (r'\(', Punctuation, 'import.what.instance'), + (r'$', Whitespace, '#pop:2'), + include('whitespace'), + include('names'), + ], + 'import.what.type': [ + (r',', Punctuation, '#pop'), + (r'[({]', Punctuation, 'import.what.type.consesandfields'), + (r'$', Whitespace, '#pop:2'), + include('whitespace'), + ], + 'import.what.type.consesandfields': [ + (r',', Punctuation), + (r'\.\.', Punctuation), + (r'[)}]', Punctuation, '#pop'), + include('names'), + ], + 'literals': [ + (r'\'([^\'\\]|\\(x[\da-fA-F]+|\d+|.))\'', Literal.Char), + (r'[+~-]?0[0-7]+\b', Number.Oct), + (r'[+~-]?\d+\.\d+(E[+-]?\d+)?', Number.Float), + (r'[+~-]?\d+\b', Number.Integer), + (r'[+~-]?0x[\da-fA-F]+\b', Number.Hex), + (r'True|False', Literal), + (r'"', String.Double, 'literals.stringd'), + ], + 'literals.stringd': [ + (r'[^\\"\n]+', String.Double), + (r'"', String.Double, '#pop'), + (r'\\.', String.Double), + (r'[$\n]', Error, '#pop'), + ], + 'operators': [ + (r'[-~@#$%\^?!+*<>\\/|&=:.]+', Operator), + (r'\b_+\b', Operator), + ], + 'delimiters': [ + (r'[,;(){}\[\]]', Punctuation), + (r'(\')([\w`.]+)(\')', + bygroups(Punctuation, Name.Class, Punctuation)), + ], + 'names': [ + (lowerId, Name), + (scoreLowerId, Name), + (funnyId, Name.Function), + (upperId, Name.Class), + (scoreUpperId, Name.Class), + ] + } diff --git a/venv/Lib/site-packages/pygments/lexers/codeql.py b/venv/Lib/site-packages/pygments/lexers/codeql.py new file mode 100644 index 0000000000000000000000000000000000000000..ab27bf508311214e062dd88aa8b2247cd3d87cdb --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/codeql.py @@ -0,0 +1,80 @@ +""" + pygments.lexers.codeql + ~~~~~~~~~~~~~~~~~~~~~~ + + Lexer for CodeQL query language. + + The grammar is originating from: + https://github.com/github/vscode-codeql/blob/main/syntaxes/README.md + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +__all__ = ['CodeQLLexer'] + +import re + +from pygments.lexer import RegexLexer, words +from pygments.token import Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Whitespace + +class CodeQLLexer(RegexLexer): + name = 'CodeQL' + aliases = ['codeql', 'ql'] + filenames = ['*.ql', '*.qll'] + mimetypes = [] + url = 'https://github.com/github/codeql' + version_added = '2.19' + + flags = re.MULTILINE | re.UNICODE + + tokens = { + 'root': [ + # Whitespace and comments + (r'\s+', Whitespace), + (r'//.*?\n', Comment.Single), + (r'/\*', Comment.Multiline, 'multiline-comments'), + + # Keywords + (words(( + 'module', 'import', 'class', 'extends', 'implements', + 'predicate', 'select', 'where', 'from', 'as', 'and', 'or', 'not', + 'in', 'if', 'then', 'else', 'exists', 'forall', 'instanceof', + 'private', 'predicate', 'abstract', 'cached', 'external', + 'final', 'library', 'override', 'query' + ), suffix=r'\b'), Keyword.Builtin), + + # Special Keywords + (words(('this'), # class related keywords + prefix=r'\b', suffix=r'\b\??:?'), Name.Builtin.Pseudo), + + # Types + (words(( + 'boolean', 'date', 'float', 'int', 'string' + ), suffix=r'\b'), Keyword.Type), + + # Literals + (r'"(\\\\|\\[^\\]|[^"\\])*"', String), + (r'[0-9]+\.[0-9]+', Number.Float), + (r'[0-9]+', Number.Integer), + + # Operators + (r'<=|>=|<|>|=|!=|\+|-|\*|/', Operator), + + # Punctuation + (r'[.,;:\[\]{}()]+', Punctuation), + + # Identifiers + (r'@[a-zA-Z_]\w*', Name.Variable), # Variables with @ prefix + (r'[A-Z][a-zA-Z0-9_]*', Name.Class), # Types and classes + (r'[a-z][a-zA-Z0-9_]*', Name.Variable), # Variables and predicates + ], + 'multiline-comments': [ + (r'[^*/]+', Comment.Multiline), + (r'/\*', Comment.Multiline, '#push'), + (r'\*/', Comment.Multiline, '#pop'), + (r'[*/]', Comment.Multiline), + ], + + } \ No newline at end of file diff --git a/venv/Lib/site-packages/pygments/lexers/comal.py b/venv/Lib/site-packages/pygments/lexers/comal.py new file mode 100644 index 0000000000000000000000000000000000000000..6b0a8d11a8135f7fdf3424622cb1d5e3c227075a --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/comal.py @@ -0,0 +1,81 @@ +""" + pygments.lexers.comal + ~~~~~~~~~~~~~~~~~~~~~ + + Lexer for COMAL-80. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, words +from pygments.token import Comment, Whitespace, Operator, Keyword, String, \ + Number, Name, Punctuation + +__all__ = ["Comal80Lexer"] + + +class Comal80Lexer(RegexLexer): + """ + For COMAL-80 source code. + """ + + name = 'COMAL-80' + url = 'https://en.wikipedia.org/wiki/COMAL' + aliases = ['comal', 'comal80'] + filenames = ['*.cml', '*.comal'] + version_added = '' + flags = re.IGNORECASE + # + # COMAL allows for some strange characters in names which we list here so + # keywords and word operators will not be recognized at the start of an + # identifier. + # + _suffix = r"\b(?!['\[\]←£\\])" + _identifier = r"[a-z]['\[\]←£\\\w]*" + + tokens = { + 'root': [ + (r'//.*\n', Comment.Single), + (r'\s+', Whitespace), + (r':[=+-]|\<\>|[-+*/^↑<>=]', Operator), + (r'(and +then|or +else)' + _suffix, Operator.Word), + (words([ + 'and', 'bitand', 'bitor', 'bitxor', 'div', 'in', 'mod', 'not', + 'or'], suffix=_suffix,), Operator.Word), + (words([ + 'append', 'at', 'case', 'chain', 'close', 'copy', 'create', 'cursor', + 'data', 'delete', 'dir', 'do', 'elif', 'else', 'end', 'endcase', 'endif', + 'endfor', 'endloop', 'endtrap', 'endwhile', 'exec', 'exit', 'file', + 'for', 'goto', 'handler', 'if', 'input', 'let', 'loop', 'mount', 'null', + 'of', 'open', 'otherwise', 'output', 'page', 'pass', 'poke', 'print', + 'random', 'read', 'repeat', 'report', 'return', 'rename', 'restore', + 'select', 'step', 'stop', 'sys', 'then', 'to', 'trap', 'unit', 'unit$', + 'until', 'using', 'when', 'while', 'write', 'zone'], suffix=_suffix), + Keyword.Reserved), + (words([ + 'closed', 'dim', 'endfunc', 'endproc', 'external', 'func', 'import', + 'proc', 'ref', 'use'], suffix=_suffix), Keyword.Declaration), + (words([ + 'abs', 'atn', 'chr$', 'cos', 'eod', 'eof', 'err', 'errfile', 'errtext', + 'esc', 'exp', 'int', 'key$', 'len', 'log', 'ord', 'peek', 'randomize', + 'rnd', 'sgn', 'sin', 'spc$', 'sqr', 'status$', 'str$', 'tab', 'tan', + 'time', 'val'], suffix=_suffix), Name.Builtin), + (words(['false', 'pi', 'true'], suffix=_suffix), Keyword.Constant), + (r'"', String, 'string'), + (_identifier + r":(?=[ \n/])", Name.Label), + (_identifier + r"[$#]?", Name), + (r'%[01]+', Number.Bin), + (r'\$[0-9a-f]+', Number.Hex), + (r'\d*\.\d*(e[-+]?\d+)?', Number.Float), + (r'\d+', Number.Integer), + (r'[(),:;]', Punctuation), + ], + 'string': [ + (r'[^"]+', String), + (r'"[0-9]*"', String.Escape), + (r'"', String, '#pop'), + ], + } diff --git a/venv/Lib/site-packages/pygments/lexers/compiled.py b/venv/Lib/site-packages/pygments/lexers/compiled.py new file mode 100644 index 0000000000000000000000000000000000000000..fb0a70364dd8b13555b74b31eafcb738972e16b7 --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/compiled.py @@ -0,0 +1,35 @@ +""" + pygments.lexers.compiled + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Just export lexer classes previously contained in this module. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +# ruff: noqa: F401 +from pygments.lexers.jvm import JavaLexer, ScalaLexer +from pygments.lexers.c_cpp import CLexer, CppLexer +from pygments.lexers.d import DLexer +from pygments.lexers.objective import ObjectiveCLexer, \ + ObjectiveCppLexer, LogosLexer +from pygments.lexers.go import GoLexer +from pygments.lexers.rust import RustLexer +from pygments.lexers.c_like import ECLexer, ValaLexer, CudaLexer +from pygments.lexers.pascal import DelphiLexer, PortugolLexer, Modula2Lexer +from pygments.lexers.ada import AdaLexer +from pygments.lexers.business import CobolLexer, CobolFreeformatLexer +from pygments.lexers.fortran import FortranLexer +from pygments.lexers.prolog import PrologLexer +from pygments.lexers.python import CythonLexer +from pygments.lexers.graphics import GLShaderLexer +from pygments.lexers.ml import OcamlLexer +from pygments.lexers.basic import BlitzBasicLexer, BlitzMaxLexer, MonkeyLexer +from pygments.lexers.dylan import DylanLexer, DylanLidLexer, DylanConsoleLexer +from pygments.lexers.ooc import OocLexer +from pygments.lexers.felix import FelixLexer +from pygments.lexers.nimrod import NimrodLexer +from pygments.lexers.crystal import CrystalLexer + +__all__ = [] diff --git a/venv/Lib/site-packages/pygments/lexers/configs.py b/venv/Lib/site-packages/pygments/lexers/configs.py new file mode 100644 index 0000000000000000000000000000000000000000..9f0bb447db9f3c852908378545b1c1344657b845 --- /dev/null +++ b/venv/Lib/site-packages/pygments/lexers/configs.py @@ -0,0 +1,1499 @@ +""" + pygments.lexers.configs + ~~~~~~~~~~~~~~~~~~~~~~~ + + Lexers for configuration file formats. + + :copyright: Copyright 2006-present by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import ExtendedRegexLexer, RegexLexer, default, words, \ + bygroups, include, using, this, line_re +from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ + Number, Punctuation, Whitespace, Literal, Error, Generic +from pygments.lexers.shell import BashLexer +from pygments.lexers.data import JsonLexer + +__all__ = ['IniLexer', 'SystemdLexer', 'DesktopLexer', 'RegeditLexer', 'PropertiesLexer', + 'KconfigLexer', 'Cfengine3Lexer', 'ApacheConfLexer', 'SquidConfLexer', + 'NginxConfLexer', 'LighttpdConfLexer', 'DockerLexer', + 'TerraformLexer', 'TermcapLexer', 'TerminfoLexer', + 'PkgConfigLexer', 'PacmanConfLexer', 'AugeasLexer', 'TOMLLexer', + 'NestedTextLexer', 'SingularityLexer', 'UnixConfigLexer', + 'CaddyfileLexer'] + + +class IniLexer(RegexLexer): + """ + Lexer for configuration files in INI style. + """ + + name = 'INI' + aliases = ['ini', 'cfg', 'dosini'] + filenames = [ + '*.ini', '*.cfg', '*.inf', '.editorconfig', + ] + mimetypes = ['text/x-ini', 'text/inf'] + url = 'https://en.wikipedia.org/wiki/INI_file' + version_added = '' + + tokens = { + 'root': [ + (r'\s+', Whitespace), + (r'[;#].*', Comment.Single), + (r'(\[.*?\])([ \t]*)$', bygroups(Keyword, Whitespace)), + (r'''(.*?)([ \t]*)([=:])([ \t]*)(["'])''', + bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String), + "quoted_value"), + (r'(.*?)([ \t]*)([=:])([ \t]*)([^;#\n]*)(\\)(\s+)', + bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String, + Text, Whitespace), + "value"), + (r'(.*?)([ \t]*)([=:])([ \t]*)([^ ;#\n]*(?: +[^ ;#\n]+)*)', + bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)), + # standalone option, supported by some INI parsers + (r'(.+?)$', Name.Attribute), + ], + 'quoted_value': [ + (r'''([^"'\n]*)(["'])(\s*)''', + bygroups(String, String, Whitespace), "#pop"), + (r'[;#].*', Comment.Single), + (r'$', String, "#pop"), + ], + 'value': [ # line continuation + (r'\s+', Whitespace), + (r'(\s*)(.*)(\\)([ \t]*)', + bygroups(Whitespace, String, Text, Whitespace)), + (r'.*$', String, "#pop"), + ], + } + + def analyse_text(text): + npos = text.find('\n') + if npos < 3: + return False + if text[0] == '[' and text[npos-1] == ']': + return 0.8 + return False + + +class DesktopLexer(RegexLexer): + """ + Lexer for .desktop files. + """ + + name = 'Desktop file' + url = "https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html" + aliases = ['desktop'] + filenames = ['*.desktop'] + mimetypes = ['application/x-desktop'] + version_added = '2.16' + + tokens = { + 'root': [ + (r'^[ \t]*\n', Whitespace), + (r'^(#.*)(\n)', bygroups(Comment.Single, Whitespace)), + (r'(\[[^\]\n]+\])(\n)', bygroups(Keyword, Whitespace)), + (r'([-A-Za-z0-9]+)(\[[^\] \t=]+\])?([ \t]*)(=)([ \t]*)([^\n]*)([ \t\n]*\n)', + bygroups(Name.Attribute, Name.Namespace, Whitespace, Operator, Whitespace, String, Whitespace)), + ], + } + + def analyse_text(text): + if text.startswith("[Desktop Entry]"): + return 1.0 + if re.search(r"^\[Desktop Entry\][ \t]*$", text[:500], re.MULTILINE) is not None: + return 0.9 + return 0.0 + + +class SystemdLexer(RegexLexer): + """ + Lexer for systemd unit files. + """ + + name = 'Systemd' + url = "https://www.freedesktop.org/software/systemd/man/systemd.syntax.html" + aliases = ['systemd'] + filenames = [ + '*.service', '*.socket', '*.device', '*.mount', '*.automount', + '*.swap', '*.target', '*.path', '*.timer', '*.slice', '*.scope', + ] + version_added = '2.16' + + tokens = { + 'root': [ + (r'^[ \t]*\n', Whitespace), + (r'^([;#].*)(\n)', bygroups(Comment.Single, Whitespace)), + (r'(\[[^\]\n]+\])(\n)', bygroups(Keyword, Whitespace)), + (r'([^=]+)([ \t]*)(=)([ \t]*)([^\n]*)(\\)(\n)', + bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String, + Text, Whitespace), + "value"), + (r'([^=]+)([ \t]*)(=)([ \t]*)([^\n]*)(\n)', + bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String, Whitespace)), + ], + 'value': [ + # line continuation + (r'^([;#].*)(\n)', bygroups(Comment.Single, Whitespace)), + (r'([ \t]*)([^\n]*)(\\)(\n)', + bygroups(Whitespace, String, Text, Whitespace)), + (r'([ \t]*)([^\n]*)(\n)', + bygroups(Whitespace, String, Whitespace), "#pop"), + ], + } + + def analyse_text(text): + if text.startswith("[Unit]"): + return 1.0 + if re.search(r"^\[Unit\][ \t]*$", text[:500], re.MULTILINE) is not None: + return 0.9 + return 0.0 + + +class RegeditLexer(RegexLexer): + """ + Lexer for Windows Registry files produced by regedit. + """ + + name = 'reg' + url = 'http://en.wikipedia.org/wiki/Windows_Registry#.REG_files' + aliases = ['registry'] + filenames = ['*.reg'] + mimetypes = ['text/x-windows-registry'] + version_added = '1.6' + + tokens = { + 'root': [ + (r'Windows Registry Editor.*', Text), + (r'\s+', Whitespace), + (r'[;#].*', Comment.Single), + (r'(\[)(-?)(HKEY_[A-Z_]+)(.*?\])$', + bygroups(Keyword, Operator, Name.Builtin, Keyword)), + # String keys, which obey somewhat normal escaping + (r'("(?:\\"|\\\\|[^"])+")([ \t]*)(=)([ \t]*)', + bygroups(Name.Attribute, Whitespace, Operator, Whitespace), + 'value'), + # Bare keys (includes @) + (r'(.*?)([ \t]*)(=)([ \t]*)', + bygroups(Name.Attribute, Whitespace, Operator, Whitespace), + 'value'), + ], + 'value': [ + (r'-', Operator, '#pop'), # delete value + (r'(dword|hex(?:\([0-9a-fA-F]\))?)(:)([0-9a-fA-F,]+)', + bygroups(Name.Variable, Punctuation, Number), '#pop'), + # As far as I know, .reg files do not support line continuation. + (r'.+', String, '#pop'), + default('#pop'), + ] + } + + def analyse_text(text): + return text.startswith('Windows Registry Editor') + + +class PropertiesLexer(RegexLexer): + """ + Lexer for configuration files in Java's properties format. + + Note: trailing whitespace counts as part of the value as per spec + """ + + name = 'Properties' + aliases = ['properties', 'jproperties'] + filenames = ['*.properties'] + mimetypes = ['text/x-java-properties'] + url = 'https://en.wikipedia.org/wiki/.properties' + version_added = '1.4' + + tokens = { + 'root': [ + # comments + (r'[!#].*|/{2}.*', Comment.Single), + # ending a comment or whitespace-only line + (r'\n', Whitespace), + # eat whitespace at the beginning of a line + (r'^[^\S\n]+', Whitespace), + # start lexing a key + default('key'), + ], + 'key': [ + # non-escaped key characters + (r'[^\\:=\s]+', Name.Attribute), + # escapes + include('escapes'), + # separator is the first non-escaped whitespace or colon or '=' on the line; + # if it's whitespace, = and : are gobbled after it + (r'([^\S\n]*)([:=])([^\S\n]*)', + bygroups(Whitespace, Operator, Whitespace), + ('#pop', 'value')), + (r'[^\S\n]+', Whitespace, ('#pop', 'value')), + # maybe we got no value after all + (r'\n', Whitespace, '#pop'), + ], + 'value': [ + # non-escaped value characters + (r'[^\\\n]+', String), + # escapes + include('escapes'), + # end the value on an unescaped newline + (r'\n', Whitespace, '#pop'), + ], + 'escapes': [ + # line continuations; these gobble whitespace at the beginning of the next line + (r'(\\\n)([^\S\n]*)', bygroups(String.Escape, Whitespace)), + # other escapes + (r'\\([\s\S])', String.Escape), + ], + } + + +def _rx_indent(level): + # Kconfig *always* interprets a tab as 8 spaces, so this is the default. + # Edit this if you are in an environment where KconfigLexer gets expanded + # input (tabs expanded to spaces) and the expansion tab width is != 8, + # e.g. in connection with Trac (trac.ini, [mimeviewer], tab_width). + # Value range here is 2 <= {tab_width} <= 8. + tab_width = 8 + # Regex matching a given indentation {level}, assuming that indentation is + # a multiple of {tab_width}. In other cases there might be problems. + if tab_width == 2: + space_repeat = '+' + else: + space_repeat = '{1,%d}' % (tab_width - 1) + if level == 1: + level_repeat = '' + else: + level_repeat = f'{{{level}}}' + return rf'(?:\t| {space_repeat}\t| {{{tab_width}}}){level_repeat}.*\n' + + +class KconfigLexer(RegexLexer): + """ + For Linux-style Kconfig files. + """ + + name = 'Kconfig' + aliases = ['kconfig', 'menuconfig', 'linux-config', 'kernel-config'] + version_added = '1.6' + # Adjust this if new kconfig file names appear in your environment + filenames = ['Kconfig*', '*Config.in*', 'external.in*', + 'standard-modules.in'] + mimetypes = ['text/x-kconfig'] + url = 'https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html' + + # No re.MULTILINE, indentation-aware help text needs line-by-line handling + flags = 0 + + def call_indent(level): + # If indentation >= {level} is detected, enter state 'indent{level}' + return (_rx_indent(level), String.Doc, f'indent{level}') + + def do_indent(level): + # Print paragraphs of indentation level >= {level} as String.Doc, + # ignoring blank lines. Then return to 'root' state. + return [ + (_rx_indent(level), String.Doc), + (r'\s*\n', Text), + default('#pop:2') + ] + + tokens = { + 'root': [ + (r'\s+', Whitespace), + (r'#.*?\n', Comment.Single), + (words(( + 'mainmenu', 'config', 'menuconfig', 'choice', 'endchoice', + 'comment', 'menu', 'endmenu', 'visible if', 'if', 'endif', + 'source', 'prompt', 'select', 'depends on', 'default', + 'range', 'option'), suffix=r'\b'), + Keyword), + (r'(---help---|help)[\t ]*\n', Keyword, 'help'), + (r'(bool|tristate|string|hex|int|defconfig_list|modules|env)\b', + Name.Builtin), + (r'[!=&|]', Operator), + (r'[()]', Punctuation), + (r'[0-9]+', Number.Integer), + (r"'(''|[^'])*'", String.Single), + (r'"(""|[^"])*"', String.Double), + (r'\S+', Text), + ], + # Help text is indented, multi-line and ends when a lower indentation + # level is detected. + 'help': [ + # Skip blank lines after help token, if any + (r'\s*\n', Text), + # Determine the first help line's indentation level heuristically(!). + # Attention: this is not perfect, but works for 99% of "normal" + # indentation schemes up to a max. indentation level of 7. + call_indent(7), + call_indent(6), + call_indent(5), + call_indent(4), + call_indent(3), + call_indent(2), + call_indent(1), + default('#pop'), # for incomplete help sections without text + ], + # Handle text for indentation levels 7 to 1 + 'indent7': do_indent(7), + 'indent6': do_indent(6), + 'indent5': do_indent(5), + 'indent4': do_indent(4), + 'indent3': do_indent(3), + 'indent2': do_indent(2), + 'indent1': do_indent(1), + } + + +class Cfengine3Lexer(RegexLexer): + """ + Lexer for CFEngine3 policy files. + """ + + name = 'CFEngine3' + url = 'http://cfengine.org' + aliases = ['cfengine3', 'cf3'] + filenames = ['*.cf'] + mimetypes = [] + version_added = '1.5' + + tokens = { + 'root': [ + (r'#.*?\n', Comment), + (r'(body)(\s+)(\S+)(\s+)(control)', + bygroups(Keyword, Whitespace, Keyword, Whitespace, Keyword)), + (r'(body|bundle)(\s+)(\S+)(\s+)(\w+)(\()', + bygroups(Keyword, Whitespace, Keyword, Whitespace, Name.Function, Punctuation), + 'arglist'), + (r'(body|bundle)(\s+)(\S+)(\s+)(\w+)', + bygroups(Keyword, Whitespace, Keyword, Whitespace, Name.Function)), + (r'(")([^"]+)(")(\s+)(string|slist|int|real)(\s*)(=>)(\s*)', + bygroups(Punctuation, Name.Variable, Punctuation, + Whitespace, Keyword.Type, Whitespace, Operator, Whitespace)), + (r'(\S+)(\s*)(=>)(\s*)', + bygroups(Keyword.Reserved, Whitespace, Operator, Text)), + (r'"', String, 'string'), + (r'(\w+)(\()', bygroups(Name.Function, Punctuation)), + (r'([\w.!&|()]+)(::)', bygroups(Name.Class, Punctuation)), + (r'(\w+)(:)', bygroups(Keyword.Declaration, Punctuation)), + (r'@[{(][^)}]+[})]', Name.Variable), + (r'[(){},;]', Punctuation), + (r'=>', Operator), + (r'->', Operator), + (r'\d+\.\d+', Number.Float), + (r'\d+', Number.Integer), + (r'\w+', Name.Function), + (r'\s+', Whitespace), + ], + 'string': [ + (r'\$[{(]', String.Interpol, 'interpol'), + (r'\\.', String.Escape), + (r'"', String, '#pop'), + (r'\n', String), + (r'.', String), + ], + 'interpol': [ + (r'\$[{(]', String.Interpol, '#push'), + (r'[})]', String.Interpol, '#pop'), + (r'[^${()}]+', String.Interpol), + ], + 'arglist': [ + (r'\)', Punctuation, '#pop'), + (r',', Punctuation), + (r'\w+', Name.Variable), + (r'\s+', Whitespace), + ], + } + + +class ApacheConfLexer(RegexLexer): + """ + Lexer for configuration files following the Apache config file + format. + """ + + name = 'ApacheConf' + aliases = ['apacheconf', 'aconf', 'apache'] + filenames = ['.htaccess', 'apache.conf', 'apache2.conf'] + mimetypes = ['text/x-apacheconf'] + url = 'https://httpd.apache.org/docs/current/configuring.html' + version_added = '0.6' + flags = re.MULTILINE | re.IGNORECASE + + tokens = { + 'root': [ + (r'\s+', Whitespace), + (r'#(.*\\\n)+.*$|(#.*?)$', Comment), + (r'(<[^\s>/][^\s>]*)(?:(\s+)(.*))?(>)', + bygroups(Name.Tag, Whitespace, String, Name.Tag)), + (r'(]+)(>)', + bygroups(Name.Tag, Name.Tag)), + (r'[a-z]\w*', Name.Builtin, 'value'), + (r'\.+', Text), + ], + 'value': [ + (r'\\\n', Text), + (r'\n+', Whitespace, '#pop'), + (r'\\', Text), + (r'[^\S\n]+', Whitespace), + (r'\d+\.\d+\.\d+\.\d+(?:/\d+)?', Number), + (r'\d+', Number), + (r'/([*a-z0-9][*\w./-]+)', String.Other), + (r'(on|off|none|any|all|double|email|dns|min|minimal|' + r'os|productonly|full|emerg|alert|crit|error|warn|' + r'notice|info|debug|registry|script|inetd|standalone|' + r'user|group)\b', Keyword), + (r'"([^"\\]*(?:\\([\s\S])[^"\\]*)*)"', String.Double), + (r'[^\s"\\]+', Text) + ], + } + + +class SquidConfLexer(RegexLexer): + """ + Lexer for squid configuration files. + """ + + name = 'SquidConf' + url = 'http://www.squid-cache.org/' + aliases = ['squidconf', 'squid.conf', 'squid'] + filenames = ['squid.conf'] + mimetypes = ['text/x-squidconf'] + version_added = '0.9' + flags = re.IGNORECASE + + keywords = ( + "access_log", "acl", "always_direct", "announce_host", + "announce_period", "announce_port", "announce_to", "anonymize_headers", + "append_domain", "as_whois_server", "auth_param_basic", + "authenticate_children", "authenticate_program", "authenticate_ttl", + "broken_posts", "buffered_logs", "cache_access_log", "cache_announce", + "cache_dir", "cache_dns_program", "cache_effective_group", + "cache_effective_user", "cache_host", "cache_host_acl", + "cache_host_domain", "cache_log", "cache_mem", "cache_mem_high", + "cache_mem_low", "cache_mgr", "cachemgr_passwd", "cache_peer", + "cache_peer_access", "cache_replacement_policy", "cache_stoplist", + "cache_stoplist_pattern", "cache_store_log", "cache_swap", + "cache_swap_high", "cache_swap_log", "cache_swap_low", "client_db", + "client_lifetime", "client_netmask", "connect_timeout", "coredump_dir", + "dead_peer_timeout", "debug_options", "delay_access", "delay_class", + "delay_initial_bucket_level", "delay_parameters", "delay_pools", + "deny_info", "dns_children", "dns_defnames", "dns_nameservers", + "dns_testnames", "emulate_httpd_log", "err_html_text", + "fake_user_agent", "firewall_ip", "forwarded_for", "forward_snmpd_port", + "fqdncache_size", "ftpget_options", "ftpget_program", "ftp_list_width", + "ftp_passive", "ftp_user", "half_closed_clients", "header_access", + "header_replace", "hierarchy_stoplist", "high_response_time_warning", + "high_page_fault_warning", "hosts_file", "htcp_port", "http_access", + "http_anonymizer", "httpd_accel", "httpd_accel_host", + "httpd_accel_port", "httpd_accel_uses_host_header", + "httpd_accel_with_proxy", "http_port", "http_reply_access", + "icp_access", "icp_hit_stale", "icp_port", "icp_query_timeout", + "ident_lookup", "ident_lookup_access", "ident_timeout", + "incoming_http_average", "incoming_icp_average", "inside_firewall", + "ipcache_high", "ipcache_low", "ipcache_size", "local_domain", + "local_ip", "logfile_rotate", "log_fqdn", "log_icp_queries", + "log_mime_hdrs", "maximum_object_size", "maximum_single_addr_tries", + "mcast_groups", "mcast_icp_query_timeout", "mcast_miss_addr", + "mcast_miss_encode_key", "mcast_miss_port", "memory_pools", + "memory_pools_limit", "memory_replacement_policy", "mime_table", + "min_http_poll_cnt", "min_icp_poll_cnt", "minimum_direct_hops", + "minimum_object_size", "minimum_retry_timeout", "miss_access", + "negative_dns_ttl", "negative_ttl", "neighbor_timeout", + "neighbor_type_domain", "netdb_high", "netdb_low", "netdb_ping_period", + "netdb_ping_rate", "never_direct", "no_cache", "passthrough_proxy", + "pconn_timeout", "pid_filename", "pinger_program", "positive_dns_ttl", + "prefer_direct", "proxy_auth", "proxy_auth_realm", "query_icmp", + "quick_abort", "quick_abort_max", "quick_abort_min", + "quick_abort_pct", "range_offset_limit", "read_timeout", + "redirect_children", "redirect_program", + "redirect_rewrites_host_header", "reference_age", + "refresh_pattern", "reload_into_ims", "request_body_max_size", + "request_size", "request_timeout", "shutdown_lifetime", + "single_parent_bypass", "siteselect_timeout", "snmp_access", + "snmp_incoming_address", "snmp_port", "source_ping", "ssl_proxy", + "store_avg_object_size", "store_objects_per_bucket", + "strip_query_terms", "swap_level1_dirs", "swap_level2_dirs", + "tcp_incoming_address", "tcp_outgoing_address", "tcp_recv_bufsize", + "test_reachability", "udp_hit_obj", "udp_hit_obj_size", + "udp_incoming_address", "udp_outgoing_address", "unique_hostname", + "unlinkd_program", "uri_whitespace", "useragent_log", + "visible_hostname", "wais_relay", "wais_relay_host", "wais_relay_port", + ) + + opts = ( + "proxy-only", "weight", "ttl", "no-query", "default", "round-robin", + "multicast-responder", "on", "off", "all", "deny", "allow", "via", + "parent", "no-digest", "heap", "lru", "realm", "children", "q1", "q2", + "credentialsttl", "none", "disable", "offline_toggle", "diskd", + ) + + actions = ( + "shutdown", "info", "parameter", "server_list", "client_list", + r'squid.conf', + ) + + actions_stats = ( + "objects", "vm_objects", "utilization", "ipcache", "fqdncache", "dns", + "redirector", "io", "reply_headers", "filedescriptors", "netdb", + ) + + actions_log = ("status", "enable", "disable", "clear") + + acls = ( + "url_regex", "urlpath_regex", "referer_regex", "port", "proto", + "req_mime_type", "rep_mime_type", "method", "browser", "user", "src", + "dst", "time", "dstdomain", "ident", "snmp_community", + ) + + ipv4_group = r'(\d+|0x[0-9a-f]+)' + ipv4 = rf'({ipv4_group}(\.{ipv4_group}){{3}})' + ipv6_group = r'([0-9a-f]{0,4})' + ipv6 = rf'({ipv6_group}(:{ipv6_group}){{1,7}})' + bare_ip = rf'({ipv4}|{ipv6})' + # XXX: /integer is a subnet mark, but what is /IP ? + # There is no test where it is used. + ip = rf'{bare_ip}(/({bare_ip}|\d+))?' + + tokens = { + 'root': [ + (r'\s+', Whitespace), + (r'#', Comment, 'comment'), + (words(keywords, prefix=r'\b', suffix=r'\b'), Keyword), + (words(opts, prefix=r'\b', suffix=r'\b'), Name.Constant), + # Actions + (words(actions, prefix=r'\b', suffix=r'\b'), String), + (words(actions_stats, prefix=r'stats/', suffix=r'\b'), String), + (words(actions_log, prefix=r'log/', suffix=r'='), String), + (words(acls, prefix=r'\b', suffix=r'\b'), Keyword), + (ip, Number.Float), + (r'(?:\b\d+\b(?:-\b\d+|%)?)', Number), + (r'\S+', Text), + ], + 'comment': [ + (r'\s*TAG:.*', String.Escape, '#pop'), + (r'.+', Comment, '#pop'), + default('#pop'), + ], + } + + +class NginxConfLexer(RegexLexer): + """ + Lexer for Nginx configuration files. + """ + name = 'Nginx configuration file' + url = 'http://nginx.net/' + aliases = ['nginx'] + filenames = ['nginx.conf'] + mimetypes = ['text/x-nginx-conf'] + version_added = '0.11' + + tokens = { + 'root': [ + (r'(include)(\s+)([^\s;]+)', bygroups(Keyword, Whitespace, Name)), + (r'[^\s;#]+', Keyword, 'stmt'), + include('base'), + ], + 'block': [ + (r'\}', Punctuation, '#pop:2'), + (r'[^\s;#]+', Keyword.Namespace, 'stmt'), + include('base'), + ], + 'stmt': [ + (r'\{', Punctuation, 'block'), + (r';', Punctuation, '#pop'), + include('base'), + ], + 'base': [ + (r'#.*\n', Comment.Single), + (r'on|off', Name.Constant), + (r'\$[^\s;#()]+', Name.Variable), + (r'([a-z0-9.-]+)(:)([0-9]+)', + bygroups(Name, Punctuation, Number.Integer)), + (r'[a-z-]+/[a-z-+]+', String), # mimetype + # (r'[a-zA-Z._-]+', Keyword), + (r'[0-9]+[km]?\b', Number.Integer), + (r'(~)(\s*)([^\s{]+)', bygroups(Punctuation, Whitespace, String.Regex)), + (r'[:=~]', Punctuation), + (r'[^\s;#{}$]+', String), # catch all + (r'/[^\s;#]*', Name), # pathname + (r'\s+', Whitespace), + (r'[$;]', Text), # leftover characters + ], + } + + +class LighttpdConfLexer(RegexLexer): + """ + Lexer for Lighttpd configuration files. + """ + name = 'Lighttpd configuration file' + url = 'http://lighttpd.net/' + aliases = ['lighttpd', 'lighty'] + filenames = ['lighttpd.conf'] + mimetypes = ['text/x-lighttpd-conf'] + version_added = '0.11' + + tokens = { + 'root': [ + (r'#.*\n', Comment.Single), + (r'/\S*', Name), # pathname + (r'[a-zA-Z._-]+', Keyword), + (r'\d+\.\d+\.\d+\.\d+(?:/\d+)?', Number), + (r'[0-9]+', Number), + (r'=>|=~|\+=|==|=|\+', Operator), + (r'\$[A-Z]+', Name.Builtin), + (r'[(){}\[\],]', Punctuation), + (r'"([^"\\]*(?:\\.[^"\\]*)*)"', String.Double), + (r'\s+', Whitespace), + ], + + } + + +class DockerLexer(RegexLexer): + """ + Lexer for Docker configuration files. + """ + name = 'Docker' + url = 'http://docker.io' + aliases = ['docker', 'dockerfile'] + filenames = ['Dockerfile', '*.docker'] + mimetypes = ['text/x-dockerfile-config'] + version_added = '2.0' + + _keywords = (r'(?:MAINTAINER|EXPOSE|WORKDIR|USER|STOPSIGNAL)') + _bash_keywords = (r'(?:RUN|CMD|ENTRYPOINT|ENV|ARG|LABEL|ADD|COPY)') + _lb = r'(?:\s*\\?\s*)' # dockerfile line break regex + flags = re.IGNORECASE | re.MULTILINE + + tokens = { + 'root': [ + (r'#.*', Comment), + (r'(FROM)([ \t]*)(\S*)([ \t]*)(?:(AS)([ \t]*)(\S*))?', + bygroups(Keyword, Whitespace, String, Whitespace, Keyword, Whitespace, String)), + (rf'(ONBUILD)(\s+)({_lb})', bygroups(Keyword, Whitespace, using(BashLexer))), + (rf'(HEALTHCHECK)(\s+)(({_lb}--\w+=\w+{_lb})*)', + bygroups(Keyword, Whitespace, using(BashLexer))), + (rf'(VOLUME|ENTRYPOINT|CMD|SHELL)(\s+)({_lb})(\[.*?\])', + bygroups(Keyword, Whitespace, using(BashLexer), using(JsonLexer))), + (rf'(LABEL|ENV|ARG)(\s+)(({_lb}\w+=\w+{_lb})*)', + bygroups(Keyword, Whitespace, using(BashLexer))), + (rf'({_keywords}|VOLUME)\b(\s+)(.*)', bygroups(Keyword, Whitespace, String)), + (rf'({_bash_keywords})(\s+)', bygroups(Keyword, Whitespace)), + (r'(.*\\\n)*.+', using(BashLexer)), + ] + } + + +class TerraformLexer(ExtendedRegexLexer): + """ + Lexer for terraformi ``.tf`` files. + """ + + name = 'Terraform' + url = 'https://www.terraform.io/' + aliases = ['terraform', 'tf', 'hcl'] + filenames = ['*.tf', '*.hcl'] + mimetypes = ['application/x-tf', 'application/x-terraform'] + version_added = '2.1' + + classes = ('backend', 'data', 'module', 'output', 'provider', + 'provisioner', 'resource', 'variable') + classes_re = "({})".format(('|').join(classes)) + + types = ('string', 'number', 'bool', 'list', 'tuple', 'map', 'set', 'object', 'null') + + numeric_functions = ('abs', 'ceil', 'floor', 'log', 'max', + 'mix', 'parseint', 'pow', 'signum') + + string_functions = ('chomp', 'format', 'formatlist', 'indent', + 'join', 'lower', 'regex', 'regexall', 'replace', + 'split', 'strrev', 'substr', 'title', 'trim', + 'trimprefix', 'trimsuffix', 'trimspace', 'upper' + ) + + collection_functions = ('alltrue', 'anytrue', 'chunklist', 'coalesce', + 'coalescelist', 'compact', 'concat', 'contains', + 'distinct', 'element', 'flatten', 'index', 'keys', + 'length', 'list', 'lookup', 'map', 'matchkeys', + 'merge', 'range', 'reverse', 'setintersection', + 'setproduct', 'setsubtract', 'setunion', 'slice', + 'sort', 'sum', 'transpose', 'values', 'zipmap' + ) + + encoding_functions = ('base64decode', 'base64encode', 'base64gzip', + 'csvdecode', 'jsondecode', 'jsonencode', 'textdecodebase64', + 'textencodebase64', 'urlencode', 'yamldecode', 'yamlencode') + + filesystem_functions = ('abspath', 'dirname', 'pathexpand', 'basename', + 'file', 'fileexists', 'fileset', 'filebase64', 'templatefile') + + date_time_functions = ('formatdate', 'timeadd', 'timestamp') + + hash_crypto_functions = ('base64sha256', 'base64sha512', 'bcrypt', 'filebase64sha256', + 'filebase64sha512', 'filemd5', 'filesha1', 'filesha256', 'filesha512', + 'md5', 'rsadecrypt', 'sha1', 'sha256', 'sha512', 'uuid', 'uuidv5') + + ip_network_functions = ('cidrhost', 'cidrnetmask', 'cidrsubnet', 'cidrsubnets') + + type_conversion_functions = ('can', 'defaults', 'tobool', 'tolist', 'tomap', + 'tonumber', 'toset', 'tostring', 'try') + + builtins = numeric_functions + string_functions + collection_functions + encoding_functions +\ + filesystem_functions + date_time_functions + hash_crypto_functions + ip_network_functions +\ + type_conversion_functions + builtins_re = "({})".format(('|').join(builtins)) + + def heredoc_callback(self, match, ctx): + # Parse a terraform heredoc + # match: 1 = <<[-]?, 2 = name 3 = rest of line + + start = match.start(1) + yield start, Operator, match.group(1) # <<[-]? + yield match.start(2), String.Delimiter, match.group(2) # heredoc name + + ctx.pos = match.start(3) + ctx.end = match.end(3) + yield ctx.pos, String.Heredoc, match.group(3) + ctx.pos = match.end() + + hdname = match.group(2) + tolerant = True # leading whitespace is always accepted + + lines = [] + + for match in line_re.finditer(ctx.text, ctx.pos): + if tolerant: + check = match.group().strip() + else: + check = match.group().rstrip() + if check == hdname: + for amatch in lines: + yield amatch.start(), String.Heredoc, amatch.group() + yield match.start(), String.Delimiter, match.group() + ctx.pos = match.end() + break + else: + lines.append(match) + else: + # end of heredoc not found -- error! + for amatch in lines: + yield amatch.start(), Error, amatch.group() + ctx.end = len(ctx.text) + + tokens = { + 'root': [ + include('basic'), + include('whitespace'), + + # Strings + (r'(".*")', bygroups(String.Double)), + + # Constants + (words(('true', 'false'), prefix=r'\b', suffix=r'\b'), Name.Constant), + + # Types + (words(types, prefix=r'\b', suffix=r'\b'), Keyword.Type), + + include('identifier'), + include('punctuation'), + (r'[0-9]+', Number), + ], + 'basic': [ + (r'\s*/\*', Comment.Multiline, 'comment'), + (r'\s*(#|//).*\n', Comment.Single), + include('whitespace'), + + # e.g. terraform { + # e.g. egress { + (r'(\s*)([0-9a-zA-Z-_]+)(\s*)(=?)(\s*)(\{)', + bygroups(Whitespace, Name.Builtin, Whitespace, Operator, Whitespace, Punctuation)), + + # Assignment with attributes, e.g. something = ... + (r'(\s*)([0-9a-zA-Z-_]+)(\s*)(=)(\s*)', + bygroups(Whitespace, Name.Attribute, Whitespace, Operator, Whitespace)), + + # Assignment with environment variables and similar, e.g. "something" = ... + # or key value assignment, e.g. "SlotName" : ... + (r'(\s*)("\S+")(\s*)([=:])(\s*)', + bygroups(Whitespace, Literal.String.Double, Whitespace, Operator, Whitespace)), + + # Functions, e.g. jsonencode(element("value")) + (builtins_re + r'(\()', bygroups(Name.Function, Punctuation)), + + # List of attributes, e.g. ignore_changes = [last_modified, filename] + (r'(\[)([a-z_,\s]+)(\])', bygroups(Punctuation, Name.Builtin, Punctuation)), + + # e.g. resource "aws_security_group" "allow_tls" { + # e.g. backend "consul" { + (classes_re + r'(\s+)("[0-9a-zA-Z-_]+")?(\s*)("[0-9a-zA-Z-_]+")(\s+)(\{)', + bygroups(Keyword.Reserved, Whitespace, Name.Class, Whitespace, Name.Variable, Whitespace, Punctuation)), + + # here-doc style delimited strings + (r'(<<-?)\s*([a-zA-Z_]\w*)(.*?\n)', heredoc_callback), + ], + 'identifier': [ + (r'\b(var\.[0-9a-zA-Z-_\.\[\]]+)\b', bygroups(Name.Variable)), + (r'\b([0-9a-zA-Z-_\[\]]+\.[0-9a-zA-Z-_\.\[\]]+)\b', + bygroups(Name.Variable)), + ], + 'punctuation': [ + (r'[\[\]()\{\},.?:!=]', Punctuation), + ], + 'comment': [ + (r'[^*/]', Comment.Multiline), + (r'/\*', Comment.Multiline, '#push'), + (r'\*/', Comment.Multiline, '#pop'), + (r'[*/]', Comment.Multiline) + ], + 'whitespace': [ + (r'\n', Whitespace), + (r'\s+', Whitespace), + (r'(\\)(\n)', bygroups(Text, Whitespace)), + ], + } + + +class TermcapLexer(RegexLexer): + """ + Lexer for termcap database source. + + This is very simple and minimal. + """ + name = 'Termcap' + aliases = ['termcap'] + filenames = ['termcap', 'termcap.src'] + mimetypes = [] + url = 'https://en.wikipedia.org/wiki/Termcap' + version_added = '2.1' + + # NOTE: + # * multiline with trailing backslash + # * separator is ':' + # * to embed colon as data, we must use \072 + # * space after separator is not allowed (mayve) + tokens = { + 'root': [ + (r'^#.*', Comment), + (r'^[^\s#:|]+', Name.Tag, 'names'), + (r'\s+', Whitespace), + ], + 'names': [ + (r'\n', Whitespace, '#pop'), + (r':', Punctuation, 'defs'), + (r'\|', Punctuation), + (r'[^:|]+', Name.Attribute), + ], + 'defs': [ + (r'(\\)(\n[ \t]*)', bygroups(Text, Whitespace)), + (r'\n[ \t]*', Whitespace, '#pop:2'), + (r'(#)([0-9]+)', bygroups(Operator, Number)), + (r'=', Operator, 'data'), + (r':', Punctuation), + (r'[^\s:=#]+', Name.Class), + ], + 'data': [ + (r'\\072', Literal), + (r':', Punctuation, '#pop'), + (r'[^:\\]+', Literal), # for performance + (r'.', Literal), + ], + } + + +class TerminfoLexer(RegexLexer): + """ + Lexer for terminfo database source. + + This is very simple and minimal. + """ + name = 'Terminfo' + aliases = ['terminfo'] + filenames = ['terminfo', 'terminfo.src'] + mimetypes = [] + url = 'https://en.wikipedia.org/wiki/Terminfo' + version_added = '2.1' + + # NOTE: + # * multiline with leading whitespace + # * separator is ',' + # * to embed comma as data, we can use \, + # * space after separator is allowed + tokens = { + 'root': [ + (r'^#.*$', Comment), + (r'^[^\s#,|]+', Name.Tag, 'names'), + (r'\s+', Whitespace), + ], + 'names': [ + (r'\n', Whitespace, '#pop'), + (r'(,)([ \t]*)', bygroups(Punctuation, Whitespace), 'defs'), + (r'\|', Punctuation), + (r'[^,|]+', Name.Attribute), + ], + 'defs': [ + (r'\n[ \t]+', Whitespace), + (r'\n', Whitespace, '#pop:2'), + (r'(#)([0-9]+)', bygroups(Operator, Number)), + (r'=', Operator, 'data'), + (r'(,)([ \t]*)', bygroups(Punctuation, Whitespace)), + (r'[^\s,=#]+', Name.Class), + ], + 'data': [ + (r'\\[,\\]', Literal), + (r'(,)([ \t]*)', bygroups(Punctuation, Whitespace), '#pop'), + (r'[^\\,]+', Literal), # for performance + (r'.', Literal), + ], + } + + +class PkgConfigLexer(RegexLexer): + """ + Lexer for pkg-config + (see also `manual page `_). + """ + + name = 'PkgConfig' + url = 'http://www.freedesktop.org/wiki/Software/pkg-config/' + aliases = ['pkgconfig'] + filenames = ['*.pc'] + mimetypes = [] + version_added = '2.1' + + tokens = { + 'root': [ + (r'#.*$', Comment.Single), + + # variable definitions + (r'^(\w+)(=)', bygroups(Name.Attribute, Operator)), + + # keyword lines + (r'^([\w.]+)(:)', + bygroups(Name.Tag, Punctuation), 'spvalue'), + + # variable references + include('interp'), + + # fallback + (r'\s+', Whitespace), + (r'[^${}#=:\n.]+', Text), + (r'.', Text), + ], + 'interp': [ + # you can escape literal "$" as "$$" + (r'\$\$', Text), + + # variable references + (r'\$\{', String.Interpol, 'curly'), + ], + 'curly': [ + (r'\}', String.Interpol, '#pop'), + (r'\w+', Name.Attribute), + ], + 'spvalue': [ + include('interp'), + + (r'#.*$', Comment.Single, '#pop'), + (r'\n', Whitespace, '#pop'), + + # fallback + (r'\s+', Whitespace), + (r'[^${}#\n\s]+', Text), + (r'.', Text), + ], + } + + +class PacmanConfLexer(RegexLexer): + """ + Lexer for pacman.conf. + + Actually, IniLexer works almost fine for this format, + but it yield error token. It is because pacman.conf has + a form without assignment like: + + UseSyslog + Color + TotalDownload + CheckSpace + VerbosePkgLists + + These are flags to switch on. + """ + + name = 'PacmanConf' + url = 'https://www.archlinux.org/pacman/pacman.conf.5.html' + aliases = ['pacmanconf'] + filenames = ['pacman.conf'] + mimetypes = [] + version_added = '2.1' + + tokens = { + 'root': [ + # comment + (r'#.*$', Comment.Single), + + # section header + (r'^(\s*)(\[.*?\])(\s*)$', bygroups(Whitespace, Keyword, Whitespace)), + + # variable definitions + # (Leading space is allowed...) + (r'(\w+)(\s*)(=)', + bygroups(Name.Attribute, Whitespace, Operator)), + + # flags to on + (r'^(\s*)(\w+)(\s*)$', + bygroups(Whitespace, Name.Attribute, Whitespace)), + + # built-in special values + (words(( + '$repo', # repository + '$arch', # architecture + '%o', # outfile + '%u', # url + ), suffix=r'\b'), + Name.Variable), + + # fallback + (r'\s+', Whitespace), + (r'.', Text), + ], + } + + +class AugeasLexer(RegexLexer): + """ + Lexer for Augeas. + """ + name = 'Augeas' + url = 'http://augeas.net' + aliases = ['augeas'] + filenames = ['*.aug'] + version_added = '2.4' + + tokens = { + 'root': [ + (r'(module)(\s*)([^\s=]+)', bygroups(Keyword.Namespace, Whitespace, Name.Namespace)), + (r'(let)(\s*)([^\s=]+)', bygroups(Keyword.Declaration, Whitespace, Name.Variable)), + (r'(del|store|value|counter|seq|key|label|autoload|incl|excl|transform|test|get|put)(\s+)', bygroups(Name.Builtin, Whitespace)), + (r'(\()([^:]+)(\:)(unit|string|regexp|lens|tree|filter)(\))', bygroups(Punctuation, Name.Variable, Punctuation, Keyword.Type, Punctuation)), + (r'\(\*', Comment.Multiline, 'comment'), + (r'[*+\-.;=?|]', Operator), + (r'[()\[\]{}]', Operator), + (r'"', String.Double, 'string'), + (r'\/', String.Regex, 'regex'), + (r'([A-Z]\w*)(\.)(\w+)', bygroups(Name.Namespace, Punctuation, Name.Variable)), + (r'.', Name.Variable), + (r'\s+', Whitespace), + ], + 'string': [ + (r'\\.', String.Escape), + (r'[^"]', String.Double), + (r'"', String.Double, '#pop'), + ], + 'regex': [ + (r'\\.', String.Escape), + (r'[^/]', String.Regex), + (r'\/', String.Regex, '#pop'), + ], + 'comment': [ + (r'[^*)]', Comment.Multiline), + (r'\(\*', Comment.Multiline, '#push'), + (r'\*\)', Comment.Multiline, '#pop'), + (r'[)*]', Comment.Multiline) + ], + } + + +class TOMLLexer(RegexLexer): + """ + Lexer for TOML, a simple language for config files. + """ + + name = 'TOML' + aliases = ['toml'] + filenames = ['*.toml', 'Pipfile', 'poetry.lock'] + mimetypes = ['application/toml'] + url = 'https://toml.io' + version_added = '2.4' + + # Based on the TOML spec: https://toml.io/en/v1.0.0 + + # The following is adapted from CPython's tomllib: + _time = r"\d\d:\d\d(:\d\d(\.\d+)?)?" + _datetime = rf"""(?x) + \d\d\d\d-\d\d-\d\d # date, e.g., 1988-10-27 + ( + [Tt ] {_time} # optional time + ( + [Zz]|[+-]\d\d:\d\d # optional time offset + )? + )? + """ + + tokens = { + 'root': [ + # Note that we make an effort in order to distinguish + # moments at which we're parsing a key and moments at + # which we're parsing a value. In the TOML code + # + # 1234 = 1234 + # + # the first "1234" should be Name, the second Integer. + + # Whitespace + (r'\s+', Whitespace), + + # Comment + (r'#.*', Comment.Single), + + # Assignment keys + include('key'), + + # After "=", find a value + (r'(=)(\s*)', bygroups(Operator, Whitespace), 'value'), + + # Table header + (r'\[\[?', Keyword, 'table-key'), + ], + 'key': [ + # Start of bare key (only ASCII is allowed here). + (r'[A-Za-z0-9_-]+', Name), + # Quoted key + (r'"', String.Double, 'basic-string'), + (r"'", String.Single, 'literal-string'), + # Dots act as separators in keys + (r'\.', Punctuation), + ], + 'table-key': [ + # This is like 'key', but highlights the name components + # and separating dots as Keyword because it looks better + # when the whole table header is Keyword. We do highlight + # strings as strings though. + # Start of bare key (only ASCII is allowed here). + (r'[A-Za-z0-9_-]+', Keyword), + (r'"', String.Double, 'basic-string'), + (r"'", String.Single, 'literal-string'), + (r'\.', Keyword), + (r'\]\]?', Keyword, '#pop'), + + # Inline whitespace allowed + (r'[ \t]+', Whitespace), + ], + 'value': [ + # Datetime, baretime + (_datetime, Literal.Date, '#pop'), + (_time, Literal.Date, '#pop'), + + # Recognize as float if there is a fractional part + # and/or an exponent. + (r'[+-]?\d[0-9_]*[eE][+-]?\d[0-9_]*', Number.Float, '#pop'), + (r'[+-]?\d[0-9_]*\.\d[0-9_]*([eE][+-]?\d[0-9_]*)?', + Number.Float, '#pop'), + + # Infinities and NaN + (r'[+-]?(inf|nan)', Number.Float, '#pop'), + + # Integers + (r'-?0b[01_]+', Number.Bin, '#pop'), + (r'-?0o[0-7_]+', Number.Oct, '#pop'), + (r'-?0x[0-9a-fA-F_]+', Number.Hex, '#pop'), + (r'[+-]?[0-9_]+', Number.Integer, '#pop'), + + # Strings + (r'"""', String.Double, ('#pop', 'multiline-basic-string')), + (r'"', String.Double, ('#pop', 'basic-string')), + (r"'''", String.Single, ('#pop', 'multiline-literal-string')), + (r"'", String.Single, ('#pop', 'literal-string')), + + # Booleans + (r'true|false', Keyword.Constant, '#pop'), + + # Start of array + (r'\[', Punctuation, ('#pop', 'array')), + + # Start of inline table + (r'\{', Punctuation, ('#pop', 'inline-table')), + ], + 'array': [ + # Whitespace, including newlines, is ignored inside arrays, + # and comments are allowed. + (r'\s+', Whitespace), + (r'#.*', Comment.Single), + + # Delimiters + (r',', Punctuation), + + # End of array + (r'\]', Punctuation, '#pop'), + + # Parse a value and come back + default('value'), + ], + 'inline-table': [ + # Whitespace (since TOML 1.1.0, same as in array) + (r'\s+', Whitespace), + (r'#.*', Comment.Single), + + # Keys + include('key'), + + # Values + (r'(=)(\s*)', bygroups(Punctuation, Whitespace), 'value'), + + # Delimiters + (r',', Punctuation), + + # End of inline table + (r'\}', Punctuation, '#pop'), + ], + 'basic-string': [ + (r'"', String.Double, '#pop'), + include('escapes'), + (r'[^"\\]+', String.Double), + ], + 'literal-string': [ + (r".*?'", String.Single, '#pop'), + ], + 'multiline-basic-string': [ + (r'"""', String.Double, '#pop'), + (r'(\\)(\n)', bygroups(String.Escape, Whitespace)), + include('escapes'), + (r'[^"\\]+', String.Double), + (r'"', String.Double), + ], + 'multiline-literal-string': [ + (r"'''", String.Single, '#pop'), + (r"[^']+", String.Single), + (r"'", String.Single), + ], + 'escapes': [ + (r'\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}', String.Escape), + (r'\\.', String.Escape), + ], + } + +class NestedTextLexer(RegexLexer): + """ + Lexer for *NextedText*, a human-friendly data format. + + .. versionchanged:: 2.16 + Added support for *NextedText* v3.0. + """ + + name = 'NestedText' + url = 'https://nestedtext.org' + aliases = ['nestedtext', 'nt'] + filenames = ['*.nt'] + version_added = '2.9' + + tokens = { + 'root': [ + # Comment: # ... + (r'^([ ]*)(#.*)$', bygroups(Whitespace, Comment)), + + # Inline dictionary: {...} + (r'^([ ]*)(\{)', bygroups(Whitespace, Punctuation), 'inline_dict'), + + # Inline list: [...] + (r'^([ ]*)(\[)', bygroups(Whitespace, Punctuation), 'inline_list'), + + # empty multiline string item: > + (r'^([ ]*)(>)$', bygroups(Whitespace, Punctuation)), + + # multiline string item: > ... + (r'^([ ]*)(>)( )(.*?)([ \t]*)$', bygroups(Whitespace, Punctuation, Whitespace, Text, Whitespace)), + + # empty list item: - + (r'^([ ]*)(-)$', bygroups(Whitespace, Punctuation)), + + # list item: - ... + (r'^([ ]*)(-)( )(.*?)([ \t]*)$', bygroups(Whitespace, Punctuation, Whitespace, Text, Whitespace)), + + # empty multiline key item: : + (r'^([ ]*)(:)$', bygroups(Whitespace, Punctuation)), + + # multiline key item: : ... + (r'^([ ]*)(:)( )([^\n]*?)([ \t]*)$', bygroups(Whitespace, Punctuation, Whitespace, Name.Tag, Whitespace)), + + # empty dict key item: ...: + (r'^([ ]*)([^\{\[\s].*?)(:)$', bygroups(Whitespace, Name.Tag, Punctuation)), + + # dict key item: ...: ... + (r'^([ ]*)([^\{\[\s].*?)(:)( )(.*?)([ \t]*)$', bygroups(Whitespace, Name.Tag, Punctuation, Whitespace, Text, Whitespace)), + ], + 'inline_list': [ + include('whitespace'), + (r'[^\{\}\[\],\s]+', Text), + include('inline_value'), + (r',', Punctuation), + (r'\]', Punctuation, '#pop'), + (r'\n', Error, '#pop'), + ], + 'inline_dict': [ + include('whitespace'), + (r'[^\{\}\[\],:\s]+', Name.Tag), + (r':', Punctuation, 'inline_dict_value'), + (r'\}', Punctuation, '#pop'), + (r'\n', Error, '#pop'), + ], + 'inline_dict_value': [ + include('whitespace'), + (r'[^\{\}\[\],:\s]+', Text), + include('inline_value'), + (r',', Punctuation, '#pop'), + (r'\}', Punctuation, '#pop:2'), + ], + 'inline_value': [ + include('whitespace'), + (r'\{', Punctuation, 'inline_dict'), + (r'\[', Punctuation, 'inline_list'), + ], + 'whitespace': [ + (r'[ \t]+', Whitespace), + ], + } + + +class SingularityLexer(RegexLexer): + """ + Lexer for Singularity definition files. + """ + + name = 'Singularity' + url = 'https://www.sylabs.io/guides/3.0/user-guide/definition_files.html' + aliases = ['singularity'] + filenames = ['*.def', 'Singularity'] + version_added = '2.6' + flags = re.IGNORECASE | re.MULTILINE | re.DOTALL + + _headers = r'^(\s*)(bootstrap|from|osversion|mirrorurl|include|registry|namespace|includecmd)(:)' + _section = r'^(%(?:pre|post|setup|environment|help|labels|test|runscript|files|startscript))(\s*)' + _appsect = r'^(%app(?:install|help|run|labels|env|test|files))(\s*)' + + tokens = { + 'root': [ + (_section, bygroups(Generic.Heading, Whitespace), 'script'), + (_appsect, bygroups(Generic.Heading, Whitespace), 'script'), + (_headers, bygroups(Whitespace, Keyword, Text)), + (r'\s*#.*?\n', Comment), + (r'\b(([0-9]+\.?[0-9]*)|(\.[0-9]+))\b', Number), + (r'[ \t]+', Whitespace), + (r'(?!^\s*%).', Text), + ], + 'script': [ + (r'(.+?(?=^\s*%))|(.*)', using(BashLexer), '#pop'), + ], + } + + def analyse_text(text): + """This is a quite simple script file, but there are a few keywords + which seem unique to this language.""" + result = 0 + if re.search(r'\b(?:osversion|includecmd|mirrorurl)\b', text, re.IGNORECASE): + result += 0.5 + + if re.search(SingularityLexer._section[1:], text): + result += 0.49 + + return result + + +class UnixConfigLexer(RegexLexer): + """ + Lexer for Unix/Linux config files using colon-separated values, e.g. + + * ``/etc/group`` + * ``/etc/passwd`` + * ``/etc/shadow`` + """ + + name = 'Unix/Linux config files' + aliases = ['unixconfig', 'linuxconfig'] + filenames = [] + url = 'https://en.wikipedia.org/wiki/Configuration_file#Unix_and_Unix-like_operating_systems' + version_added = '2.12' + + tokens = { + 'root': [ + (r'^#.*', Comment), + (r'\n', Whitespace), + (r':', Punctuation), + (r'[0-9]+', Number), + (r'((?!\n)[a-zA-Z0-9\_\-\s\(\),]){2,}', Text), + (r'[^:\n]+', String), + ], + } + + +class CaddyfileLexer(RegexLexer): + """ + Lexer for Caddyfile, the configuration file format of the Caddy web server. + """ + + name = 'Caddyfile' + url = 'https://caddyserver.com/docs/caddyfile' + aliases = ['caddyfile', 'caddy'] + filenames = ['Caddyfile'] + version_added = '2.21' + + # The standard HTTP directives shipped with Caddy. + directives = ( + 'abort', 'acme_server', 'basic_auth', 'bind', 'encode', 'error', + 'file_server', 'forward_auth', 'handle', 'handle_errors', + 'handle_path', 'header', 'import', 'invoke', 'log', 'map', 'metrics', + 'php_fastcgi', 'push', 'redir', 'request_body', 'request_header', + 'respond', 'reverse_proxy', 'rewrite', 'root', 'route', 'templates', + 'tls', 'tracing', 'try_files', 'uri', 'vars', + ) + + tokens = { + 'root': [ + # Directives are only keywords as the first token on a line, so + # anchor them to the start of the (possibly indented) line. This + # consumes the preceding newline(s)/indentation itself, otherwise + # the generic whitespace rule below would swallow it first. + (r'((?:\A|\s*\n)[ \t]*)(' + '|'.join(directives) + r')\b', + bygroups(Whitespace, Keyword)), + (r'\s+', Whitespace), + (r'#.*', Comment.Single), + # Heredoc: <