Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
dotnet.py847 linesDownload Raw Back to lexers
1"""2    pygments.lexers.dotnet3    ~~~~~~~~~~~~~~~~~~~~~~4 5    Lexers for .net languages.6 7    :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.8    :license: BSD, see LICENSE for details.9"""10import re11 12from pygments.lexer import RegexLexer, DelegatingLexer, bygroups, include, \13    using, this, default, words14from pygments.token import Punctuation, Text, Comment, Operator, Keyword, \15    Name, String, Number, Literal, Other, Whitespace16from pygments.util import get_choice_opt17from pygments import unistring as uni18 19from pygments.lexers.html import XmlLexer20 21__all__ = ['CSharpLexer', 'NemerleLexer', 'BooLexer', 'VbNetLexer',22           'CSharpAspxLexer', 'VbNetAspxLexer', 'FSharpLexer', 'XppLexer']23 24 25class CSharpLexer(RegexLexer):26    """27    For C# source code.28 29    Additional options accepted:30 31    `unicodelevel`32      Determines which Unicode characters this lexer allows for identifiers.33      The possible values are:34 35      * ``none`` -- only the ASCII letters and numbers are allowed. This36        is the fastest selection.37      * ``basic`` -- all Unicode characters from the specification except38        category ``Lo`` are allowed.39      * ``full`` -- all Unicode characters as specified in the C# specs40        are allowed.  Note that this means a considerable slowdown since the41        ``Lo`` category has more than 40,000 characters in it!42 43      The default value is ``basic``.44 45      .. versionadded:: 0.846    """47 48    name = 'C#'49    url = 'https://docs.microsoft.com/en-us/dotnet/csharp/'50    aliases = ['csharp', 'c#', 'cs']51    filenames = ['*.cs']52    mimetypes = ['text/x-csharp']  # inferred53    version_added = ''54 55    flags = re.MULTILINE | re.DOTALL56 57    # for the range of allowed unicode characters in identifiers, see58    # http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf59 60    levels = {61        'none': r'@?[_a-zA-Z]\w*',62        'basic': ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' +63                  '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc',64                                    'Cf', 'Mn', 'Mc') + ']*'),65        'full': ('@?(?:_|[^' +66                 uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])' +67                 '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl',68                                      'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'),69    }70 71    tokens = {}72    token_variants = True73 74    for levelname, cs_ident in levels.items():75        tokens[levelname] = {76            'root': [77                # method names78                (r'^([ \t]*)((?:' + cs_ident + r'(?:\[\])?\s+)+?)'  # return type79                 r'(' + cs_ident + ')'                            # method name80                 r'(\s*)(\()',                               # signature start81                 bygroups(Whitespace, using(this), Name.Function, Whitespace,82                          Punctuation)),83                (r'^(\s*)(\[.*?\])', bygroups(Whitespace, Name.Attribute)),84                (r'[^\S\n]+', Whitespace),85                (r'(\\)(\n)', bygroups(Text, Whitespace)),  # line continuation86                (r'//.*?\n', Comment.Single),87                (r'/[*].*?[*]/', Comment.Multiline),88                (r'\n', Whitespace),89                (words((90                    '>>>=', '>>=', '<<=', '<=', '>=', '+=', '-=', '*=', '/=',91                    '%=', '&=', '|=', '^=', '??=', '=>', '??', '?.', '!=', '==',92                    '&&', '||', '>>>', '>>', '<<', '++', '--', '+', '-', '*',93                    '/', '%', '&', '|', '^', '<', '>', '?', '!', '~', '=',94                )), Operator),95                (r'=~|!=|==|<<|>>|[-+/*%=<>&^|]', Operator),96                (r'[()\[\];:,.]', Punctuation),97                (r'[{}]', Punctuation),98                (r'@"(""|[^"])*"', String),99                (r'\$?"(\\\\|\\[^\\]|[^"\\\n])*["\n]', String),100                (r"'\\.'|'[^\\]'", String.Char),101                (r"[0-9]+(\.[0-9]*)?([eE][+-][0-9]+)?"102                 r"[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?", Number),103                (r'(#)([ \t]*)(if|endif|else|elif|define|undef|'104                 r'line|error|warning|region|endregion|pragma)\b(.*?)(\n)',105                 bygroups(Comment.Preproc, Whitespace, Comment.Preproc,106                          Comment.Preproc, Whitespace)),107                (r'\b(extern)(\s+)(alias)\b', bygroups(Keyword, Whitespace,108                 Keyword)),109                (r'(abstract|as|async|await|base|break|by|case|catch|'110                 r'checked|const|continue|default|delegate|'111                 r'do|else|enum|event|explicit|extern|false|finally|'112                 r'fixed|for|foreach|goto|if|implicit|in|interface|'113                 r'internal|is|let|lock|new|null|on|operator|'114                 r'out|override|params|private|protected|public|readonly|'115                 r'ref|return|sealed|sizeof|stackalloc|static|'116                 r'switch|this|throw|true|try|typeof|'117                 r'unchecked|unsafe|virtual|void|while|'118                 r'get|set|new|partial|yield|add|remove|value|alias|ascending|'119                 r'descending|from|group|into|orderby|select|thenby|where|'120                 r'join|equals)\b', Keyword),121                (r'(global)(::)', bygroups(Keyword, Punctuation)),122                (r'(bool|byte|char|decimal|double|dynamic|float|int|long|object|'123                 r'sbyte|short|string|uint|ulong|ushort|var)\b\??', Keyword.Type),124                (r'(class|struct)(\s+)', bygroups(Keyword, Whitespace), 'class'),125                (r'(namespace|using)(\s+)', bygroups(Keyword, Whitespace), 'namespace'),126                (cs_ident, Name),127            ],128            'class': [129                (cs_ident, Name.Class, '#pop'),130                default('#pop'),131            ],132            'namespace': [133                (r'(?=\()', Text, '#pop'),  # using (resource)134                ('(' + cs_ident + r'|\.)+', Name.Namespace, '#pop'),135            ]136        }137 138    def __init__(self, **options):139        level = get_choice_opt(options, 'unicodelevel', list(self.tokens), 'basic')140        if level not in self._all_tokens:141            # compile the regexes now142            self._tokens = self.__class__.process_tokendef(level)143        else:144            self._tokens = self._all_tokens[level]145 146        RegexLexer.__init__(self, **options)147 148 149class NemerleLexer(RegexLexer):150    """151    For Nemerle source code.152 153    Additional options accepted:154 155    `unicodelevel`156      Determines which Unicode characters this lexer allows for identifiers.157      The possible values are:158 159      * ``none`` -- only the ASCII letters and numbers are allowed. This160        is the fastest selection.161      * ``basic`` -- all Unicode characters from the specification except162        category ``Lo`` are allowed.163      * ``full`` -- all Unicode characters as specified in the C# specs164        are allowed.  Note that this means a considerable slowdown since the165        ``Lo`` category has more than 40,000 characters in it!166 167      The default value is ``basic``.168    """169 170    name = 'Nemerle'171    url = 'http://nemerle.org'172    aliases = ['nemerle']173    filenames = ['*.n']174    mimetypes = ['text/x-nemerle']  # inferred175    version_added = '1.5'176 177    flags = re.MULTILINE | re.DOTALL178 179    # for the range of allowed unicode characters in identifiers, see180    # http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf181 182    levels = {183        'none': r'@?[_a-zA-Z]\w*',184        'basic': ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' +185                  '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc',186                                    'Cf', 'Mn', 'Mc') + ']*'),187        'full': ('@?(?:_|[^' +188                 uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])' +189                 '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl',190                                      'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'),191    }192 193    tokens = {}194    token_variants = True195 196    for levelname, cs_ident in levels.items():197        tokens[levelname] = {198            'root': [199                # method names200                (r'^([ \t]*)((?:' + cs_ident + r'(?:\[\])?\s+)+?)'  # return type201                 r'(' + cs_ident + ')'                            # method name202                 r'(\s*)(\()',                               # signature start203                 bygroups(Whitespace, using(this), Name.Function, Whitespace, \204                          Punctuation)),205                (r'^(\s*)(\[.*?\])', bygroups(Whitespace, Name.Attribute)),206                (r'[^\S\n]+', Whitespace),207                (r'(\\)(\n)', bygroups(Text, Whitespace)),  # line continuation208                (r'//.*?\n', Comment.Single),209                (r'/[*].*?[*]/', Comment.Multiline),210                (r'\n', Whitespace),211                (r'(\$)(\s*)(")', bygroups(String, Whitespace, String),212                    'splice-string'),213                (r'(\$)(\s*)(<#)', bygroups(String, Whitespace, String),214                    'splice-string2'),215                (r'<#', String, 'recursive-string'),216 217                (r'(<\[)(\s*)(' + cs_ident + ':)?',218                 bygroups(Keyword, Whitespace, Keyword)),219                (r'\]\>', Keyword),220 221                # quasiquotation only222                (r'\$' + cs_ident, Name),223                (r'(\$)(\()', bygroups(Name, Punctuation),224                 'splice-string-content'),225 226                (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation),227                (r'[{}]', Punctuation),228                (r'@"(""|[^"])*"', String),229                (r'"(\\\\|\\[^\\]|[^"\\\n])*["\n]', String),230                (r"'\\.'|'[^\\]'", String.Char),231                (r"0[xX][0-9a-fA-F]+[Ll]?", Number),232                (r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?[flFLdD]?", Number),233                (r'(#)([ \t]*)(if|endif|else|elif|define|undef|'234                 r'line|error|warning|region|endregion|pragma)\b',235                 bygroups(Comment.Preproc, Whitespace, Comment.Preproc), 'preproc'),236                (r'\b(extern)(\s+)(alias)\b', bygroups(Keyword, Whitespace, Keyword)),237                (r'(abstract|and|as|base|catch|def|delegate|'238                 r'enum|event|extern|false|finally|'239                 r'fun|implements|interface|internal|'240                 r'is|macro|match|matches|module|mutable|new|'241                 r'null|out|override|params|partial|private|'242                 r'protected|public|ref|sealed|static|'243                 r'syntax|this|throw|true|try|type|typeof|'244                 r'virtual|volatile|when|where|with|'245                 r'assert|assert2|async|break|checked|continue|do|else|'246                 r'ensures|for|foreach|if|late|lock|new|nolate|'247                 r'otherwise|regexp|repeat|requires|return|surroundwith|'248                 r'unchecked|unless|using|while|yield)\b', Keyword),249                (r'(global)(::)', bygroups(Keyword, Punctuation)),250                (r'(bool|byte|char|decimal|double|float|int|long|object|sbyte|'251                 r'short|string|uint|ulong|ushort|void|array|list)\b\??',252                 Keyword.Type),253                (r'(:>?)(\s*)(' + cs_ident + r'\??)',254                 bygroups(Punctuation, Whitespace, Keyword.Type)),255                (r'(class|struct|variant|module)(\s+)',256                 bygroups(Keyword, Whitespace), 'class'),257                (r'(namespace|using)(\s+)', bygroups(Keyword, Whitespace),258                 'namespace'),259                (cs_ident, Name),260            ],261            'class': [262                (cs_ident, Name.Class, '#pop')263            ],264            'preproc': [265                (r'\w+', Comment.Preproc),266                (r'[ \t]+', Whitespace),267                (r'\n', Whitespace, '#pop')268            ],269            'namespace': [270                (r'(?=\()', Text, '#pop'),  # using (resource)271                ('(' + cs_ident + r'|\.)+', Name.Namespace, '#pop')272            ],273            'splice-string': [274                (r'[^"$]',  String),275                (r'\$' + cs_ident, Name),276                (r'(\$)(\()', bygroups(Name, Punctuation),277                 'splice-string-content'),278                (r'\\"',  String),279                (r'"',  String, '#pop')280            ],281            'splice-string2': [282                (r'[^#<>$]',  String),283                (r'\$' + cs_ident, Name),284                (r'(\$)(\()', bygroups(Name, Punctuation),285                 'splice-string-content'),286                (r'<#',  String, '#push'),287                (r'#>',  String, '#pop')288            ],289            'recursive-string': [290                (r'[^#<>]',  String),291                (r'<#',  String, '#push'),292                (r'#>',  String, '#pop')293            ],294            'splice-string-content': [295                (r'if|match', Keyword),296                (r'[~!%^&*+=|\[\]:;,.<>/?-\\"$ ]', Punctuation),297                (cs_ident, Name),298                (r'\d+', Number),299                (r'\(', Punctuation, '#push'),300                (r'\)', Punctuation, '#pop')301            ]302        }303 304    def __init__(self, **options):305        level = get_choice_opt(options, 'unicodelevel', list(self.tokens),306                               'basic')307        if level not in self._all_tokens:308            # compile the regexes now309            self._tokens = self.__class__.process_tokendef(level)310        else:311            self._tokens = self._all_tokens[level]312 313        RegexLexer.__init__(self, **options)314 315    def analyse_text(text):316        """Nemerle is quite similar to Python, but @if is relatively uncommon317        elsewhere."""318        result = 0319 320        if '@if' in text:321            result += 0.1322 323        return result324 325 326class BooLexer(RegexLexer):327    """328    For Boo source code.329    """330 331    name = 'Boo'332    url = 'https://github.com/boo-lang/boo'333    aliases = ['boo']334    filenames = ['*.boo']335    mimetypes = ['text/x-boo']336    version_added = ''337 338    tokens = {339        'root': [340            (r'\s+', Whitespace),341            (r'(#|//).*$', Comment.Single),342            (r'/[*]', Comment.Multiline, 'comment'),343            (r'[]{}:(),.;[]', Punctuation),344            (r'(\\)(\n)', bygroups(Text, Whitespace)),345            (r'\\', Text),346            (r'(in|is|and|or|not)\b', Operator.Word),347            (r'/(\\\\|\\[^\\]|[^/\\\s])/', String.Regex),348            (r'@/(\\\\|\\[^\\]|[^/\\])*/', String.Regex),349            (r'=~|!=|==|<<|>>|[-+/*%=<>&^|]', Operator),350            (r'(as|abstract|callable|constructor|destructor|do|import|'351             r'enum|event|final|get|interface|internal|of|override|'352             r'partial|private|protected|public|return|set|static|'353             r'struct|transient|virtual|yield|super|and|break|cast|'354             r'continue|elif|else|ensure|except|for|given|goto|if|in|'355             r'is|isa|not|or|otherwise|pass|raise|ref|try|unless|when|'356             r'while|from|as)\b', Keyword),357            (r'def(?=\s+\(.*?\))', Keyword),358            (r'(def)(\s+)', bygroups(Keyword, Whitespace), 'funcname'),359            (r'(class)(\s+)', bygroups(Keyword, Whitespace), 'classname'),360            (r'(namespace)(\s+)', bygroups(Keyword, Whitespace), 'namespace'),361            (r'(?<!\.)(true|false|null|self|__eval__|__switch__|array|'362             r'assert|checked|enumerate|filter|getter|len|lock|map|'363             r'matrix|max|min|normalArrayIndexing|print|property|range|'364             r'rawArrayIndexing|required|typeof|unchecked|using|'365             r'yieldAll|zip)\b', Name.Builtin),366            (r'"""(\\\\|\\"|.*?)"""', String.Double),367            (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),368            (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),369            (r'[a-zA-Z_]\w*', Name),370            (r'(\d+\.\d*|\d*\.\d+)([fF][+-]?[0-9]+)?', Number.Float),371            (r'[0-9][0-9.]*(ms?|d|h|s)', Number),372            (r'0\d+', Number.Oct),373            (r'0x[a-fA-F0-9]+', Number.Hex),374            (r'\d+L', Number.Integer.Long),375            (r'\d+', Number.Integer),376        ],377        'comment': [378            ('/[*]', Comment.Multiline, '#push'),379            ('[*]/', Comment.Multiline, '#pop'),380            ('[^/*]', Comment.Multiline),381            ('[*/]', Comment.Multiline)382        ],383        'funcname': [384            (r'[a-zA-Z_]\w*', Name.Function, '#pop')385        ],386        'classname': [387            (r'[a-zA-Z_]\w*', Name.Class, '#pop')388        ],389        'namespace': [390            (r'[a-zA-Z_][\w.]*', Name.Namespace, '#pop')391        ]392    }393 394 395class VbNetLexer(RegexLexer):396    """397    For Visual Basic.NET source code.398    Also LibreOffice Basic, OpenOffice Basic, and StarOffice Basic.399    """400 401    name = 'VB.net'402    url = 'https://docs.microsoft.com/en-us/dotnet/visual-basic/'403    aliases = ['vb.net', 'vbnet', 'lobas', 'oobas', 'sobas', 'visual-basic', 'visualbasic']404    filenames = ['*.vb', '*.bas']405    mimetypes = ['text/x-vbnet', 'text/x-vba']  # (?)406    version_added = ''407 408    uni_name = '[_' + uni.combine('Ll', 'Lt', 'Lm', 'Nl') + ']' + \409               '[' + uni.combine('Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc',410                                 'Cf', 'Mn', 'Mc') + ']*'411 412    flags = re.MULTILINE | re.IGNORECASE413    tokens = {414        'root': [415            (r'^\s*<.*?>', Name.Attribute),416            (r'\s+', Whitespace),417            (r'\n', Whitespace),418            (r'(rem\b.*?)(\n)', bygroups(Comment, Whitespace)),419            (r"('.*?)(\n)", bygroups(Comment, Whitespace)),420            (r'#If\s.*?\sThen|#ElseIf\s.*?\sThen|#Else|#End\s+If|#Const|'421             r'#ExternalSource.*?\n|#End\s+ExternalSource|'422             r'#Region.*?\n|#End\s+Region|#ExternalChecksum',423             Comment.Preproc),424            (r'[(){}!#,.:]', Punctuation),425            (r'(Option)(\s+)(Strict|Explicit|Compare)(\s+)'426             r'(On|Off|Binary|Text)',427             bygroups(Keyword.Declaration, Whitespace, Keyword.Declaration,428                      Whitespace, Keyword.Declaration)),429            (words((430                'AddHandler', 'Alias', 'ByRef', 'ByVal', 'Call', 'Case',431                'Catch', 'CBool', 'CByte', 'CChar', 'CDate', 'CDec', 'CDbl',432                'CInt', 'CLng', 'CObj', 'Continue', 'CSByte', 'CShort', 'CSng',433                'CStr', 'CType', 'CUInt', 'CULng', 'CUShort', 'Declare',434                'Default', 'Delegate', 'DirectCast', 'Do', 'Each', 'Else',435                'ElseIf', 'EndIf', 'Erase', 'Error', 'Event', 'Exit', 'False',436                'Finally', 'For', 'Friend', 'Get', 'Global', 'GoSub', 'GoTo',437                'Handles', 'If', 'Implements', 'Inherits', 'Interface', 'Let',438                'Lib', 'Loop', 'Me', 'MustInherit', 'MustOverride', 'MyBase',439                'MyClass', 'Narrowing', 'New', 'Next', 'Not', 'Nothing',440                'NotInheritable', 'NotOverridable', 'Of', 'On', 'Operator',441                'Option', 'Optional', 'Overloads', 'Overridable', 'Overrides',442                'ParamArray', 'Partial', 'Private', 'Protected', 'Public',443                'RaiseEvent', 'ReadOnly', 'ReDim', 'RemoveHandler', 'Resume',444                'Return', 'Select', 'Set', 'Shadows', 'Shared', 'Single',445                'Static', 'Step', 'Stop', 'SyncLock', 'Then', 'Throw', 'To',446                'True', 'Try', 'TryCast', 'Wend', 'Using', 'When', 'While',447                'Widening', 'With', 'WithEvents', 'WriteOnly'),448                   prefix=r'(?<!\.)', suffix=r'\b'), Keyword),449            (r'(?<!\.)End\b', Keyword, 'end'),450            (r'(?<!\.)(Dim|Const)\b', Keyword, 'dim'),451            (r'(?<!\.)(Function|Sub|Property)(\s+)',452             bygroups(Keyword, Whitespace), 'funcname'),453            (r'(?<!\.)(Class|Structure|Enum)(\s+)',454             bygroups(Keyword, Whitespace), 'classname'),455            (r'(?<!\.)(Module|Namespace|Imports)(\s+)',456             bygroups(Keyword, Whitespace), 'namespace'),457            (r'(?<!\.)(Boolean|Byte|Char|Date|Decimal|Double|Integer|Long|'458             r'Object|SByte|Short|Single|String|Variant|UInteger|ULong|'459             r'UShort)\b', Keyword.Type),460            (r'(?<!\.)(AddressOf|And|AndAlso|As|GetType|In|Is|IsNot|Like|Mod|'461             r'Or|OrElse|TypeOf|Xor)\b', Operator.Word),462            (r'&=|[*]=|/=|\\=|\^=|\+=|-=|<<=|>>=|<<|>>|:=|'463             r'<=|>=|<>|[-&*/\\^+=<>\[\]]',464             Operator),465            ('"', String, 'string'),466            (r'(_)(\n)', bygroups(Text, Whitespace)),  # Line continuation  (must be before Name)467            (uni_name + '[%&@!#$]?', Name),468            ('#.*?#', Literal.Date),469            (r'(\d+\.\d*|\d*\.\d+)(F[+-]?[0-9]+)?', Number.Float),470            (r'\d+([SILDFR]|US|UI|UL)?', Number.Integer),471            (r'&H[0-9a-f]+([SILDFR]|US|UI|UL)?', Number.Integer),472            (r'&O[0-7]+([SILDFR]|US|UI|UL)?', Number.Integer),473        ],474        'string': [475            (r'""', String),476            (r'"C?', String, '#pop'),477            (r'[^"]+', String),478        ],479        'dim': [480            (uni_name, Name.Variable, '#pop'),481            default('#pop'),  # any other syntax482        ],483        'funcname': [484            (uni_name, Name.Function, '#pop'),485        ],486        'classname': [487            (uni_name, Name.Class, '#pop'),488        ],489        'namespace': [490            (uni_name, Name.Namespace),491            (r'\.', Name.Namespace),492            default('#pop'),493        ],494        'end': [495            (r'\s+', Whitespace),496            (r'(Function|Sub|Property|Class|Structure|Enum|Module|Namespace)\b',497             Keyword, '#pop'),498            default('#pop'),499        ]500    }501 502    def analyse_text(text):503        if re.search(r'^\s*(#If|Module|Namespace)', text, re.MULTILINE):504            return 0.5505 506 507class GenericAspxLexer(RegexLexer):508    """509    Lexer for ASP.NET pages.510    """511 512    name = 'aspx-gen'513    filenames = []514    mimetypes = []515    url = 'https://dotnet.microsoft.com/en-us/apps/aspnet'516 517    flags = re.DOTALL518 519    tokens = {520        'root': [521            (r'(<%[@=#]?)(.*?)(%>)', bygroups(Name.Tag, Other, Name.Tag)),522            (r'(<script.*?>)(.*?)(</script>)', bygroups(using(XmlLexer),523                                                        Other,524                                                        using(XmlLexer))),525            (r'(.+?)(?=<)', using(XmlLexer)),526            (r'.+', using(XmlLexer)),527        ],528    }529 530 531# TODO support multiple languages within the same source file532class CSharpAspxLexer(DelegatingLexer):533    """534    Lexer for highlighting C# within ASP.NET pages.535    """536 537    name = 'aspx-cs'538    aliases = ['aspx-cs']539    filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd']540    mimetypes = []541    url = 'https://dotnet.microsoft.com/en-us/apps/aspnet'542    version_added = ''543 544    def __init__(self, **options):545        super().__init__(CSharpLexer, GenericAspxLexer, **options)546 547    def analyse_text(text):548        if re.search(r'Page\s*Language="C#"', text, re.I) is not None:549            return 0.2550        elif re.search(r'script[^>]+language=["\']C#', text, re.I) is not None:551            return 0.15552 553 554class VbNetAspxLexer(DelegatingLexer):555    """556    Lexer for highlighting Visual Basic.net within ASP.NET pages.557    """558 559    name = 'aspx-vb'560    aliases = ['aspx-vb']561    filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd']562    mimetypes = []563    url = 'https://dotnet.microsoft.com/en-us/apps/aspnet'564    version_added = ''565 566    def __init__(self, **options):567        super().__init__(VbNetLexer, GenericAspxLexer, **options)568 569    def analyse_text(text):570        if re.search(r'Page\s*Language="Vb"', text, re.I) is not None:571            return 0.2572        elif re.search(r'script[^>]+language=["\']vb', text, re.I) is not None:573            return 0.15574 575 576# Very close to functional.OcamlLexer577class FSharpLexer(RegexLexer):578    """579    For the F# language (version 3.0).580    """581 582    name = 'F#'583    url = 'https://fsharp.org/'584    aliases = ['fsharp', 'f#']585    filenames = ['*.fs', '*.fsi', '*.fsx']586    mimetypes = ['text/x-fsharp']587    version_added = '1.5'588 589    keywords = [590        'abstract', 'as', 'assert', 'base', 'begin', 'class', 'default',591        'delegate', 'do!', 'do', 'done', 'downcast', 'downto', 'elif', 'else',592        'end', 'exception', 'extern', 'false', 'finally', 'for', 'function',593        'fun', 'global', 'if', 'inherit', 'inline', 'interface', 'internal',594        'in', 'lazy', 'let!', 'let', 'match', 'member', 'module', 'mutable',595        'namespace', 'new', 'null', 'of', 'open', 'override', 'private', 'public',596        'rec', 'return!', 'return', 'select', 'static', 'struct', 'then', 'to',597        'true', 'try', 'type', 'upcast', 'use!', 'use', 'val', 'void', 'when',598        'while', 'with', 'yield!', 'yield',599    ]600    # Reserved words; cannot hurt to color them as keywords too.601    keywords += [602        'atomic', 'break', 'checked', 'component', 'const', 'constraint',603        'constructor', 'continue', 'eager', 'event', 'external', 'fixed',604        'functor', 'include', 'method', 'mixin', 'object', 'parallel',605        'process', 'protected', 'pure', 'sealed', 'tailcall', 'trait',606        'virtual', 'volatile',607    ]608    keyopts = [609        '!=', '#', '&&', '&', r'\(', r'\)', r'\*', r'\+', ',', r'-\.',610        '->', '-', r'\.\.', r'\.', '::', ':=', ':>', ':', ';;', ';', '<-',611        r'<\]', '<', r'>\]', '>', r'\?\?', r'\?', r'\[<', r'\[\|', r'\[', r'\]',612        '_', '`', r'\{', r'\|\]', r'\|', r'\}', '~', '<@@', '<@', '=', '@>', '@@>',613    ]614 615    operators = r'[!$%&*+\./:<=>?@^|~-]'616    word_operators = ['and', 'or', 'not']617    prefix_syms = r'[!?~]'618    infix_syms = r'[=<>@^|&+\*/$%-]'619    primitives = [620        'sbyte', 'byte', 'char', 'nativeint', 'unativeint', 'float32', 'single',621        'float', 'double', 'int8', 'uint8', 'int16', 'uint16', 'int32',622        'uint32', 'int64', 'uint64', 'decimal', 'unit', 'bool', 'string',623        'list', 'exn', 'obj', 'enum',624    ]625 626    # See http://msdn.microsoft.com/en-us/library/dd233181.aspx and/or627    # http://fsharp.org/about/files/spec.pdf for reference.  Good luck.628 629    tokens = {630        'escape-sequence': [631            (r'\\[\\"\'ntbrafv]', String.Escape),632            (r'\\[0-9]{3}', String.Escape),633            (r'\\u[0-9a-fA-F]{4}', String.Escape),634            (r'\\U[0-9a-fA-F]{8}', String.Escape),635        ],636        'root': [637            (r'\s+', Whitespace),638            (r'\(\)|\[\]', Name.Builtin.Pseudo),639            (r'\b(?<!\.)([A-Z][\w\']*)(?=\s*\.)',640             Name.Namespace, 'dotted'),641            (r'\b([A-Z][\w\']*)', Name),642            (r'(///.*?)(\n)', bygroups(String.Doc, Whitespace)),643            (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)),644            (r'\(\*(?!\))', Comment, 'comment'),645 646            (r'@"', String, 'lstring'),647            (r'"""', String, 'tqs'),648            (r'"', String, 'string'),649 650            (r'\b(open|module)(\s+)([\w.]+)',651             bygroups(Keyword, Whitespace, Name.Namespace)),652            (r'\b(let!?)(\s+)(\w+)',653             bygroups(Keyword, Whitespace, Name.Variable)),654            (r'\b(type)(\s+)(\w+)',655             bygroups(Keyword, Whitespace, Name.Class)),656            (r'\b(member|override)(\s+)(\w+)(\.)(\w+)',657             bygroups(Keyword, Whitespace, Name, Punctuation, Name.Function)),658            (r'\b({})\b'.format('|'.join(keywords)), Keyword),659            (r'``([^`\n\r\t]|`[^`\n\r\t])+``', Name),660            (r'({})'.format('|'.join(keyopts)), Operator),661            (rf'({infix_syms}|{prefix_syms})?{operators}', Operator),662            (r'\b({})\b'.format('|'.join(word_operators)), Operator.Word),663            (r'\b({})\b'.format('|'.join(primitives)), Keyword.Type),664            (r'(#)([ \t]*)(if|endif|else|line|nowarn|light|\d+)\b(.*?)(\n)',665             bygroups(Comment.Preproc, Whitespace, Comment.Preproc,666                      Comment.Preproc, Whitespace)),667 668            (r"[^\W\d][\w']*", Name),669 670            (r'\d[\d_]*[uU]?[yslLnQRZINGmM]?', Number.Integer),671            (r'0[xX][\da-fA-F][\da-fA-F_]*[uU]?[yslLn]?[fF]?', Number.Hex),672            (r'0[oO][0-7][0-7_]*[uU]?[yslLn]?', Number.Oct),673            (r'0[bB][01][01_]*[uU]?[yslLn]?', Number.Bin),674            (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)[fFmM]?',675             Number.Float),676 677            (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'B?",678             String.Char),679            (r"'.'", String.Char),680            (r"'", Keyword),  # a stray quote is another syntax element681 682            (r'@?"', String.Double, 'string'),683 684            (r'[~?][a-z][\w\']*:', Name.Variable),685        ],686        'dotted': [687            (r'\s+', Whitespace),688            (r'\.', Punctuation),689            (r'[A-Z][\w\']*(?=\s*\.)', Name.Namespace),690            (r'[A-Z][\w\']*', Name, '#pop'),691            (r'[a-z_][\w\']*', Name, '#pop'),692            # e.g. dictionary index access693            default('#pop'),694        ],695        'comment': [696            (r'[^(*)@"]+', Comment),697            (r'\(\*', Comment, '#push'),698            (r'\*\)', Comment, '#pop'),699            # comments cannot be closed within strings in comments700            (r'@"', String, 'lstring'),701            (r'"""', String, 'tqs'),702            (r'"', String, 'string'),703            (r'[(*)@]', Comment),704        ],705        'string': [706            (r'[^\\"]+', String),707            include('escape-sequence'),708            (r'\\\n', String),709            (r'\n', String),  # newlines are allowed in any string710            (r'"B?', String, '#pop'),711        ],712        'lstring': [713            (r'[^"]+', String),714            (r'\n', String),715            (r'""', String),716            (r'"B?', String, '#pop'),717        ],718        'tqs': [719            (r'[^"]+', String),720            (r'\n', String),721            (r'"""B?', String, '#pop'),722            (r'"', String),723        ],724    }725 726    def analyse_text(text):727        """F# doesn't have that many unique features -- |> and <| are weak728        indicators."""729        result = 0730        if '|>' in text:731            result += 0.05732        if '<|' in text:733            result += 0.05734 735        return result736 737 738class XppLexer(RegexLexer):739 740    """741    For X++ source code. This is based loosely on the CSharpLexer742    """743 744    name = 'X++'745    url = 'https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/dev-ref/xpp-language-reference'746    aliases = ['xpp', 'x++']747    filenames = ['*.xpp']748    version_added = '2.15'749 750    flags = re.MULTILINE751 752    XPP_CHARS = ('@?(?:_|[^' +753                 uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])' +754                 '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl',755                                      'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*')756    # Temporary, see757    # https://github.com/thatch/regexlint/pull/49758    XPP_CHARS = XPP_CHARS.replace('\x00', '\x01')759 760    OPERATORS = (761                    '<=', '>=', '+=', '-=', '*=', '/=', '!=', '==',762                    '&&', '||', '>>', '<<', '++', '--', '+', '-', '*',763                    '/', '%', '&', '|', '^', '<', '>', '?', '!', '~', '=',764                )765    KEYWORDS = ('abstract','anytype','as','async','asc','at','avg','break','breakpoint','by','byref','case','catch',766                 'changecompany','client','container','continue','count','crosscompany','default','delegate',767                 'delete_from','desc','display','div','do','edit','else','element','eventhandler','exists','false','final',768                 'firstfast','firstonly','firstonly10','firstonly100','firstonly1000','flush','for','forceliterals',769                 'forcenestedloop','forceplaceholders','forceselectorder','forupdate','from','group','if','insert_recordset',770                 'interface','is','join','like','maxof','minof','mod','new','next','nofetch','notexists','null','optimisticlock','order',771                 'outer','pause','pessimisticlock','print','private','protected','public','repeatableread','retry','return',772                 'reverse','select','server','setting','static','sum','super','switch','tablelock','this','throw','true','try','ttsabort','ttsbegin',773                 'ttscommit','update_recordset','validtimestate','void','where','while','window')774    RUNTIME_FUNCTIONS = ('_duration','abs','acos','any2Date','any2Enum','any2Guid','any2Int','any2Int64','any2Real','any2Str','anytodate',775                 'anytoenum','anytoguid','anytoint','anytoint64','anytoreal','anytostr','asin','atan','beep','cTerm','char2Num','classIdGet',776                 'corrFlagGet','corrFlagSet','cos','cosh','curExt','curUserId','date2Num','date2Str','datetime2Str','dayName','dayOfMth',777                 'dayOfWk','dayOfYr','ddb','decRound','dg','dimOf','endMth','enum2str','exp','exp10','fV','fieldId2Name','fieldId2PName',778                 'fieldName2Id','frac','funcName','getCurrentPartition','getCurrentPartitionRecId','getPrefix','guid2Str','idg','indexId2Name',779                 'indexName2Id','int2Str','int642Str','intvMax','intvName','intvNo','intvNorm','log10','logN','match','max','min','mkDate','mthName',780                 'mthOfYr','newGuid','nextMth','nextQtr','nextYr','num2Char','num2Date','num2Str','pmt','power','prevMth','prevQtr','prevYr',781                 'prmIsDefault','pt','pv','rate','refPrintAll','round','runAs','sessionId','setPrefix','sin','sinh','sleep','sln','str2Date',782                 'str2Datetime','str2Enum','str2Guid','str2Int','str2Int64','str2Num','str2Time','strAlpha','strCmp','strColSeq','strDel',783                 'strFind','strFmt','strIns','strKeep','strLTrim','strLen','strLine','strLwr','strNFind','strPoke','strPrompt','strRTrim',784                 'strRem','strRep','strScan','strUpr','subStr','syd','systemDateGet','systemDateSet','tableId2Name',785                 'tableId2PName','tableName2Id','tan','tanh','term','time2Str','timeNow','today','trunc','typeOf','uint2Str','wkOfYr','year')786    COMPILE_FUNCTIONS = ('attributeStr','classNum','classStr','configurationKeyNum','configurationKeyStr','dataEntityDataSourceStr','delegateStr',787                 'dimensionHierarchyLevelStr','dimensionHierarchyStr','dimensionReferenceStr','dutyStr','enumCnt','enumLiteralStr','enumNum','enumStr',788                 'extendedTypeNum','extendedTypeStr','fieldNum','fieldPName','fieldStr','formControlStr','formDataFieldStr','formDataSourceStr',789                 'formMethodStr','formStr','identifierStr','indexNum','indexStr','licenseCodeNum','licenseCodeStr','literalStr','maxDate','maxInt',790                 'measureStr','measurementStr','menuItemActionStr','menuItemDisplayStr','menuItemOutputStr','menuStr','methodStr','minInt','privilegeStr',791                 'queryDatasourceStr','queryMethodStr','queryStr','reportStr','resourceStr','roleStr','ssrsReportStr','staticDelegateStr','staticMethodStr',792                 'tableCollectionStr','tableFieldGroupStr','tableMethodStr','tableNum','tablePName','tableStaticMethodStr','tableStr','tileStr','varStr',793                 'webActionItemStr','webDisplayContentItemStr','webFormStr','webMenuStr','webOutputContentItemStr','webReportStr','webSiteTempStr',794                 'webStaticFileStr','webUrlItemStr','webWebPartStr','webletItemStr','webpageDefStr','websiteDefStr','workflowApprovalStr',795                 'workflowCategoryStr','workflowTaskStr','workflowTypeStr')796 797    tokens = {}798 799    tokens = {800        'root': [801            # method names802            (r'(\s*)\b(else|if)\b([^\n])', bygroups(Whitespace, Keyword, using(this))), # ensure that if is not treated like a function803            (r'^([ \t]*)((?:' + XPP_CHARS + r'(?:\[\])?\s+)+?)'  # return type804                r'(' + XPP_CHARS + ')'                            # method name805                r'(\s*)(\()',                               # signature start806                bygroups(Whitespace, using(this), Name.Function, Whitespace,807                        Punctuation)),808            (r'^(\s*)(\[)([^\n]*?)(\])', bygroups(Whitespace, Name.Attribute, Name.Variable.Class, Name.Attribute)),809            (r'[^\S\n]+', Whitespace),810            (r'(\\)(\n)', bygroups(Text, Whitespace)),  # line continuation811            (r'//[^\n]*?\n', Comment.Single),812            (r'/[*][^\n]*?[*]/', Comment.Multiline),813            (r'\n', Whitespace),814            (words(OPERATORS), Operator),815            (r'=~|!=|==|<<|>>|[-+/*%=<>&^|]', Operator),816            (r'[()\[\];:,.#@]', Punctuation),817            (r'[{}]', Punctuation),818            (r'@"(""|[^"])*"', String),819            (r'\$?"(\\\\|\\[^\\]|[^"\\\n])*["\n]', String),820            (r"'\\.'|'[^\\]'", String.Char),821            (r"[0-9]+(\.[0-9]*)?([eE][+-][0-9]+)?"822                r"[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?", Number),823            (words(KEYWORDS, suffix=r'\b'), Keyword),824            (r'(boolean|int|int64|str|real|guid|date)\b\??', Keyword.Type),825            (r'(class|struct|extends|implements)(\s+)', bygroups(Keyword, Whitespace), 'class'),826            (r'('+XPP_CHARS+')(::)', bygroups(Name.Variable.Class, Punctuation)),827            (r'(\s*)(\w+)(\s+\w+(,|=)?[^\n]*;)', bygroups(Whitespace, Name.Variable.Class, using(this))), # declaration828            # x++ specific function to get field should highlight the classname829            (r'(fieldNum\()('+XPP_CHARS+r')(\s*,\s*)('+XPP_CHARS+r')(\s*\))',830                bygroups(using(this), Name.Variable.Class, using(this), Name.Property, using(this))),831            # x++ specific function to get table should highlight the classname832            (r'(tableNum\()('+XPP_CHARS+r')(\s*\))',833                bygroups(using(this), Name.Variable.Class, using(this))),834            (words(RUNTIME_FUNCTIONS, suffix=r'(?=\()'), Name.Function.Magic),835            (words(COMPILE_FUNCTIONS, suffix=r'(?=\()'), Name.Function.Magic),836            (XPP_CHARS, Name),837        ],838        'class': [839            (XPP_CHARS, Name.Class, '#pop'),840            default('#pop'),841        ],842        'namespace': [843            (r'(?=\()', Text, '#pop'),  # using (resource)844            ('(' + XPP_CHARS + r'|\.)+', Name.Namespace, '#pop'),845        ]846    }847 
codekingpro/portable-devtools · Team Ai