Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/arrow.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:16 +0000

1""" 

2 pygments.lexers.arrow 

3 ~~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexer for Arrow. 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import RegexLexer, bygroups, default, include 

12from pygments.token import Text, Operator, Keyword, Punctuation, Name, \ 

13 String, Number, Whitespace 

14 

15__all__ = ['ArrowLexer'] 

16 

17TYPES = r'\b(int|bool|char)((?:\[\])*)(?=\s+)' 

18IDENT = r'([a-zA-Z_][a-zA-Z0-9_]*)' 

19DECL = TYPES + r'(\s+)' + IDENT 

20 

21 

22class ArrowLexer(RegexLexer): 

23 """ 

24 Lexer for Arrow 

25 

26 .. versionadded:: 2.7 

27 """ 

28 

29 name = 'Arrow' 

30 url = 'https://pypi.org/project/py-arrow-lang/' 

31 aliases = ['arrow'] 

32 filenames = ['*.arw'] 

33 

34 tokens = { 

35 'root': [ 

36 (r'\s+', Whitespace), 

37 (r'^[|\s]+', Punctuation), 

38 include('blocks'), 

39 include('statements'), 

40 include('expressions'), 

41 ], 

42 'blocks': [ 

43 (r'(function)(\n+)(/-->)(\s*)' + 

44 DECL + # 4 groups 

45 r'(\()', bygroups( 

46 Keyword.Reserved, Whitespace, Punctuation, 

47 Whitespace, Keyword.Type, Punctuation, Whitespace, 

48 Name.Function, Punctuation 

49 ), 'fparams'), 

50 (r'/-->$|\\-->$|/--<|\\--<|\^', Punctuation), 

51 ], 

52 'statements': [ 

53 (DECL, bygroups(Keyword.Type, Punctuation, Text, Name.Variable)), 

54 (r'\[', Punctuation, 'index'), 

55 (r'=', Operator), 

56 (r'require|main', Keyword.Reserved), 

57 (r'print', Keyword.Reserved, 'print'), 

58 ], 

59 'expressions': [ 

60 (r'\s+', Whitespace), 

61 (r'[0-9]+', Number.Integer), 

62 (r'true|false', Keyword.Constant), 

63 (r"'", String.Char, 'char'), 

64 (r'"', String.Double, 'string'), 

65 (r'\{', Punctuation, 'array'), 

66 (r'==|!=|<|>|\+|-|\*|/|%', Operator), 

67 (r'and|or|not|length', Operator.Word), 

68 (r'(input)(\s+)(int|char\[\])', bygroups( 

69 Keyword.Reserved, Whitespace, Keyword.Type 

70 )), 

71 (IDENT + r'(\()', bygroups( 

72 Name.Function, Punctuation 

73 ), 'fargs'), 

74 (IDENT, Name.Variable), 

75 (r'\[', Punctuation, 'index'), 

76 (r'\(', Punctuation, 'expressions'), 

77 (r'\)', Punctuation, '#pop'), 

78 ], 

79 'print': [ 

80 include('expressions'), 

81 (r',', Punctuation), 

82 default('#pop'), 

83 ], 

84 'fparams': [ 

85 (DECL, bygroups(Keyword.Type, Punctuation, Whitespace, Name.Variable)), 

86 (r',', Punctuation), 

87 (r'\)', Punctuation, '#pop'), 

88 ], 

89 'escape': [ 

90 (r'\\(["\\/abfnrtv]|[0-9]{1,3}|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4})', 

91 String.Escape), 

92 ], 

93 'char': [ 

94 (r"'", String.Char, '#pop'), 

95 include('escape'), 

96 (r"[^'\\]", String.Char), 

97 ], 

98 'string': [ 

99 (r'"', String.Double, '#pop'), 

100 include('escape'), 

101 (r'[^"\\]+', String.Double), 

102 ], 

103 'array': [ 

104 include('expressions'), 

105 (r'\}', Punctuation, '#pop'), 

106 (r',', Punctuation), 

107 ], 

108 'fargs': [ 

109 include('expressions'), 

110 (r'\)', Punctuation, '#pop'), 

111 (r',', Punctuation), 

112 ], 

113 'index': [ 

114 include('expressions'), 

115 (r'\]', Punctuation, '#pop'), 

116 ], 

117 }