codekingpro/portable-devtools
114k
1"""2 pygments.lexers.arrow3 ~~~~~~~~~~~~~~~~~~~~~4 5 Lexer for Arrow.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, default, include12from pygments.token import Text, Operator, Keyword, Punctuation, Name, \13 String, Number, Whitespace14 15__all__ = ['ArrowLexer']16 17TYPES = r'\b(int|bool|char)((?:\[\])*)(?=\s+)'18IDENT = r'([a-zA-Z_][a-zA-Z0-9_]*)'19DECL = TYPES + r'(\s+)' + IDENT20 21 22class ArrowLexer(RegexLexer):23 """24 Lexer for Arrow25 """26 27 name = 'Arrow'28 url = 'https://pypi.org/project/py-arrow-lang/'29 aliases = ['arrow']30 filenames = ['*.arw']31 version_added = '2.7'32 33 tokens = {34 'root': [35 (r'\s+', Whitespace),36 (r'^[|\s]+', Punctuation),37 include('blocks'),38 include('statements'),39 include('expressions'),40 ],41 'blocks': [42 (r'(function)(\n+)(/-->)(\s*)' +43 DECL + # 4 groups44 r'(\()', bygroups(45 Keyword.Reserved, Whitespace, Punctuation,46 Whitespace, Keyword.Type, Punctuation, Whitespace,47 Name.Function, Punctuation48 ), 'fparams'),49 (r'/-->$|\\-->$|/--<|\\--<|\^', Punctuation),50 ],51 'statements': [52 (DECL, bygroups(Keyword.Type, Punctuation, Text, Name.Variable)),53 (r'\[', Punctuation, 'index'),54 (r'=', Operator),55 (r'require|main', Keyword.Reserved),56 (r'print', Keyword.Reserved, 'print'),57 ],58 'expressions': [59 (r'\s+', Whitespace),60 (r'[0-9]+', Number.Integer),61 (r'true|false', Keyword.Constant),62 (r"'", String.Char, 'char'),63 (r'"', String.Double, 'string'),64 (r'\{', Punctuation, 'array'),65 (r'==|!=|<|>|\+|-|\*|/|%', Operator),66 (r'and|or|not|length', Operator.Word),67 (r'(input)(\s+)(int|char\[\])', bygroups(68 Keyword.Reserved, Whitespace, Keyword.Type69 )),70 (IDENT + r'(\()', bygroups(71 Name.Function, Punctuation72 ), 'fargs'),73 (IDENT, Name.Variable),74 (r'\[', Punctuation, 'index'),75 (r'\(', Punctuation, 'expressions'),76 (r'\)', Punctuation, '#pop'),77 ],78 'print': [79 include('expressions'),80 (r',', Punctuation),81 default('#pop'),82 ],83 'fparams': [84 (DECL, bygroups(Keyword.Type, Punctuation, Whitespace, Name.Variable)),85 (r',', Punctuation),86 (r'\)', Punctuation, '#pop'),87 ],88 'escape': [89 (r'\\(["\\/abfnrtv]|[0-9]{1,3}|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4})',90 String.Escape),91 ],92 'char': [93 (r"'", String.Char, '#pop'),94 include('escape'),95 (r"[^'\\]", String.Char),96 ],97 'string': [98 (r'"', String.Double, '#pop'),99 include('escape'),100 (r'[^"\\]+', String.Double),101 ],102 'array': [103 include('expressions'),104 (r'\}', Punctuation, '#pop'),105 (r',', Punctuation),106 ],107 'fargs': [108 include('expressions'),109 (r'\)', Punctuation, '#pop'),110 (r',', Punctuation),111 ],112 'index': [113 include('expressions'),114 (r'\]', Punctuation, '#pop'),115 ],116 }117 