Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
savi.py172 linesDownload Raw Back to lexers
1"""2    pygments.lexers.savi3    ~~~~~~~~~~~~~~~~~~~~4 5    Lexer for Savi.6 7    :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.8    :license: BSD, see LICENSE for details.9"""10 11from pygments.lexer import RegexLexer, bygroups, include12from pygments.token import Whitespace, Keyword, Name, String, Number, \13  Operator, Punctuation, Comment, Generic, Error14 15__all__ = ['SaviLexer']16 17 18# The canonical version of this file can be found in the following repository,19# where it is kept in sync with any language changes, as well as the other20# pygments-like lexers that are maintained for use with other tools:21# - https://github.com/savi-lang/savi/blob/main/tooling/pygments/lexers/savi.py22#23# If you're changing this file in the pygments repository, please ensure that24# any changes you make are also propagated to the official Savi repository,25# in order to avoid accidental clobbering of your changes later when an update26# from the Savi repository flows forward into the pygments repository.27#28# If you're changing this file in the Savi repository, please ensure that29# any changes you make are also reflected in the other pygments-like lexers30# (rouge, vscode, etc) so that all of the lexers can be kept cleanly in sync.31 32class SaviLexer(RegexLexer):33    """34    For Savi source code.35 36    .. versionadded: 2.1037    """38 39    name = 'Savi'40    url = 'https://github.com/savi-lang/savi'41    aliases = ['savi']42    filenames = ['*.savi']43    version_added = ''44 45    tokens = {46      "root": [47        # Line Comment48        (r'//.*?$', Comment.Single),49 50        # Doc Comment51        (r'::.*?$', Comment.Single),52 53        # Capability Operator54        (r'(\')(\w+)(?=[^\'])', bygroups(Operator, Name)),55 56        # Double-Quote String57        (r'\w?"', String.Double, "string.double"),58 59        # Single-Char String60        (r"'", String.Char, "string.char"),61 62        # Type Name63        (r'(_?[A-Z]\w*)', Name.Class),64 65        # Nested Type Name66        (r'(\.)(\s*)(_?[A-Z]\w*)', bygroups(Punctuation, Whitespace, Name.Class)),67 68        # Declare69        (r'^([ \t]*)(:\w+)',70          bygroups(Whitespace, Name.Tag),71          "decl"),72 73        # Error-Raising Calls/Names74        (r'((\w+|\+|\-|\*)\!)', Generic.Deleted),75 76        # Numeric Values77        (r'\b\d([\d_]*(\.[\d_]+)?)\b', Number),78 79        # Hex Numeric Values80        (r'\b0x([0-9a-fA-F_]+)\b', Number.Hex),81 82        # Binary Numeric Values83        (r'\b0b([01_]+)\b', Number.Bin),84 85        # Function Call (with braces)86        (r'\w+(?=\()', Name.Function),87 88        # Function Call (with receiver)89        (r'(\.)(\s*)(\w+)', bygroups(Punctuation, Whitespace, Name.Function)),90 91        # Function Call (with self receiver)92        (r'(@)(\w+)', bygroups(Punctuation, Name.Function)),93 94        # Parenthesis95        (r'\(', Punctuation, "root"),96        (r'\)', Punctuation, "#pop"),97 98        # Brace99        (r'\{', Punctuation, "root"),100        (r'\}', Punctuation, "#pop"),101 102        # Bracket103        (r'\[', Punctuation, "root"),104        (r'(\])(\!)', bygroups(Punctuation, Generic.Deleted), "#pop"),105        (r'\]', Punctuation, "#pop"),106 107        # Punctuation108        (r'[,;:\.@]', Punctuation),109 110        # Piping Operators111        (r'(\|\>)', Operator),112 113        # Branching Operators114        (r'(\&\&|\|\||\?\?|\&\?|\|\?|\.\?)', Operator),115 116        # Comparison Operators117        (r'(\<\=\>|\=\~|\=\=|\<\=|\>\=|\<|\>)', Operator),118 119        # Arithmetic Operators120        (r'(\+|\-|\/|\*|\%)', Operator),121 122        # Assignment Operators123        (r'(\=)', Operator),124 125        # Other Operators126        (r'(\!|\<\<|\<|\&|\|)', Operator),127 128        # Identifiers129        (r'\b\w+\b', Name),130 131        # Whitespace132        (r'[ \t\r]+\n*|\n+', Whitespace),133      ],134 135      # Declare (nested rules)136      "decl": [137        (r'\b[a-z_]\w*\b(?!\!)', Keyword.Declaration),138        (r':', Punctuation, "#pop"),139        (r'\n', Whitespace, "#pop"),140        include("root"),141      ],142 143      # Double-Quote String (nested rules)144      "string.double": [145        (r'\\\(', String.Interpol, "string.interpolation"),146        (r'\\u[0-9a-fA-F]{4}', String.Escape),147        (r'\\x[0-9a-fA-F]{2}', String.Escape),148        (r'\\[bfnrt\\\']', String.Escape),149        (r'\\"', String.Escape),150        (r'"', String.Double, "#pop"),151        (r'[^\\"]+', String.Double),152        (r'.', Error),153      ],154 155      # Single-Char String (nested rules)156      "string.char": [157        (r'\\u[0-9a-fA-F]{4}', String.Escape),158        (r'\\x[0-9a-fA-F]{2}', String.Escape),159        (r'\\[bfnrt\\\']', String.Escape),160        (r"\\'", String.Escape),161        (r"'", String.Char, "#pop"),162        (r"[^\\']+", String.Char),163        (r'.', Error),164      ],165 166      # Interpolation inside String (nested rules)167      "string.interpolation": [168        (r"\)", String.Interpol, "#pop"),169        include("root"),170      ]171    }172 
codekingpro/portable-devtools · Team Ai