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

22 statements  

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

1""" 

2 pygments.lexers.elpi 

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

4 

5 Lexer for the `Elpi <http://github.com/LPCIC/elpi>`_ programming language. 

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, include 

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

13 Number 

14 

15__all__ = ['ElpiLexer'] 

16 

17 

18class ElpiLexer(RegexLexer): 

19 """ 

20 Lexer for the Elpi programming language. 

21 

22 .. versionadded:: 2.11 

23 """ 

24 

25 name = 'Elpi' 

26 url = 'http://github.com/LPCIC/elpi' 

27 aliases = ['elpi'] 

28 filenames = ['*.elpi'] 

29 mimetypes = ['text/x-elpi'] 

30 

31 lcase_re = r"[a-z]" 

32 ucase_re = r"[A-Z]" 

33 digit_re = r"[0-9]" 

34 schar2_re = r"([+*^?/<>`'@#~=&!])" 

35 schar_re = r"({}|-|\$|_)".format(schar2_re) 

36 idchar_re = r"({}|{}|{}|{})".format(lcase_re,ucase_re,digit_re,schar_re) 

37 idcharstarns_re = r"({}*(\.({}|{}){}*)*)".format(idchar_re, lcase_re, ucase_re, idchar_re) 

38 symbchar_re = r"({}|{}|{}|{}|:)".format(lcase_re, ucase_re, digit_re, schar_re) 

39 constant_re = r"({}{}*|{}{}|{}{}*|_{}+)".format(ucase_re, idchar_re, lcase_re, idcharstarns_re, schar2_re, symbchar_re, idchar_re) 

40 symbol_re = r"(,|<=>|->|:-|;|\?-|->|&|=>|\bas\b|\buvar\b|<|=<|=|==|>=|>|\bi<|\bi=<|\bi>=|\bi>|\bis\b|\br<|\br=<|\br>=|\br>|\bs<|\bs=<|\bs>=|\bs>|@|::|\[\]|`->|`:|`:=|\^|-|\+|\bi-|\bi\+|r-|r\+|/|\*|\bdiv\b|\bi\*|\bmod\b|\br\*|~|\bi~|\br~)" 

41 escape_re = r"\(({}|{})\)".format(constant_re,symbol_re) 

42 const_sym_re = r"({}|{}|{})".format(constant_re,symbol_re,escape_re) 

43 

44 tokens = { 

45 'root': [ 

46 include('elpi') 

47 ], 

48 

49 'elpi': [ 

50 include('_elpi-comment'), 

51 

52 (r"(:before|:after|:if|:name)(\s*)(\")", 

53 bygroups(Keyword.Mode, Text.Whitespace, String.Double), 

54 'elpi-string'), 

55 (r"(:index)(\s*\()", bygroups(Keyword.Mode, Text.Whitespace), 

56 'elpi-indexing-expr'), 

57 (r"\b(external pred|pred)(\s+)({})".format(const_sym_re), 

58 bygroups(Keyword.Declaration, Text.Whitespace, Name.Function), 

59 'elpi-pred-item'), 

60 (r"\b(external type|type)(\s+)(({}(,\s*)?)+)".format(const_sym_re), 

61 bygroups(Keyword.Declaration, Text.Whitespace, Name.Function), 

62 'elpi-type'), 

63 (r"\b(kind)(\s+)(({}|,)+)".format(const_sym_re), 

64 bygroups(Keyword.Declaration, Text.Whitespace, Name.Function), 

65 'elpi-type'), 

66 (r"\b(typeabbrev)(\s+)({})".format(const_sym_re), 

67 bygroups(Keyword.Declaration, Text.Whitespace, Name.Function), 

68 'elpi-type'), 

69 (r"\b(accumulate)(\s+)(\")", 

70 bygroups(Keyword.Declaration, Text.Whitespace, String.Double), 

71 'elpi-string'), 

72 (r"\b(accumulate|namespace|local)(\s+)({})".format(constant_re), 

73 bygroups(Keyword.Declaration, Text.Whitespace, Text)), 

74 (r"\b(shorten)(\s+)({}\.)".format(constant_re), 

75 bygroups(Keyword.Declaration, Text.Whitespace, Text)), 

76 (r"\b(pi|sigma)(\s+)([a-zA-Z][A-Za-z0-9_ ]*)(\\)", 

77 bygroups(Keyword.Declaration, Text.Whitespace, Name.Variable, Text)), 

78 (r"\b(constraint)(\s+)(({}(\s+)?)+)".format(const_sym_re), 

79 bygroups(Keyword.Declaration, Text.Whitespace, Name.Function), 

80 'elpi-chr-rule-start'), 

81 

82 (r"(?=[A-Z_]){}".format(constant_re), Name.Variable), 

83 (r"(?=[a-z_]){}\\".format(constant_re), Name.Variable), 

84 (r"_", Name.Variable), 

85 (r"({}|!|=>|;)".format(symbol_re), Keyword.Declaration), 

86 (constant_re, Text), 

87 (r"\[|\]|\||=>", Keyword.Declaration), 

88 (r'"', String.Double, 'elpi-string'), 

89 (r'`', String.Double, 'elpi-btick'), 

90 (r'\'', String.Double, 'elpi-tick'), 

91 (r'\{[^\{]', Text, 'elpi-spill'), 

92 (r"\(", Text, 'elpi-in-parens'), 

93 (r'\d[\d_]*', Number.Integer), 

94 (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float), 

95 (r"[\+\*\-/\^\.]", Operator), 

96 ], 

97 '_elpi-comment': [ 

98 (r'%[^\n]*\n', Comment), 

99 (r'/\*', Comment, 'elpi-multiline-comment'), 

100 (r"\s+", Text.Whitespace), 

101 ], 

102 'elpi-multiline-comment': [ 

103 (r'\*/', Comment, '#pop'), 

104 (r'.', Comment) 

105 ], 

106 'elpi-indexing-expr':[ 

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

108 (r'\)', Text, '#pop'), 

109 ], 

110 'elpi-type': [ 

111 (r"(ctype\s+)(\")", bygroups(Keyword.Type, String.Double), 'elpi-string'), 

112 (r'->', Keyword.Type), 

113 (constant_re, Keyword.Type), 

114 (r"\(|\)", Keyword.Type), 

115 (r"\.", Text, '#pop'), 

116 include('_elpi-comment'), 

117 ], 

118 'elpi-chr-rule-start': [ 

119 (r"\{", Text, 'elpi-chr-rule'), 

120 include('_elpi-comment'), 

121 ], 

122 'elpi-chr-rule': [ 

123 (r"\brule\b", Keyword.Declaration), 

124 (r"\\", Keyword.Declaration), 

125 (r"\}", Text, '#pop:2'), 

126 include('elpi'), 

127 ], 

128 'elpi-pred-item': [ 

129 (r"[io]:", Keyword.Mode, 'elpi-ctype'), 

130 (r"\.", Text, '#pop'), 

131 include('_elpi-comment'), 

132 ], 

133 'elpi-ctype': [ 

134 (r"(ctype\s+)(\")", bygroups(Keyword.Type, String.Double), 'elpi-string'), 

135 (r'->', Keyword.Type), 

136 (constant_re, Keyword.Type), 

137 (r"\(|\)", Keyword.Type), 

138 (r",", Text, '#pop'), 

139 (r"\.", Text, '#pop:2'), 

140 include('_elpi-comment'), 

141 ], 

142 'elpi-btick': [ 

143 (r'[^` ]+', String.Double), 

144 (r'`', String.Double, '#pop'), 

145 ], 

146 'elpi-tick': [ 

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

148 (r'\'', String.Double, '#pop'), 

149 ], 

150 'elpi-string': [ 

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

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

153 ], 

154 'elpi-spill': [ 

155 (r'\{[^\{]', Text, '#push'), 

156 (r'\}[^\}]', Text, '#pop'), 

157 include('elpi'), 

158 ], 

159 'elpi-in-parens': [ 

160 (r"\(", Operator, '#push'), 

161 (r"\)", Operator, '#pop'), 

162 include('elpi'), 

163 ], 

164 

165 }