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

8 statements  

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

1""" 

2 pygments.lexers.qvt 

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

4 

5 Lexer for QVT Operational 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, combined, default, \ 

12 words 

13from pygments.token import Text, Comment, Operator, Keyword, Punctuation, \ 

14 Name, String, Number 

15 

16__all__ = ['QVToLexer'] 

17 

18 

19class QVToLexer(RegexLexer): 

20 """ 

21 For the `QVT Operational Mapping language <http://www.omg.org/spec/QVT/1.1/>`_. 

22 

23 Reference for implementing this: «Meta Object Facility (MOF) 2.0 

24 Query/View/Transformation Specification», Version 1.1 - January 2011 

25 (http://www.omg.org/spec/QVT/1.1/), see §8.4, «Concrete Syntax» in 

26 particular. 

27 

28 Notable tokens assignments: 

29 

30 - Name.Class is assigned to the identifier following any of the following 

31 keywords: metamodel, class, exception, primitive, enum, transformation 

32 or library 

33 

34 - Name.Function is assigned to the names of mappings and queries 

35 

36 - Name.Builtin.Pseudo is assigned to the pre-defined variables 'this', 

37 'self' and 'result'. 

38 """ 

39 # With obvious borrowings & inspiration from the Java, Python and C lexers 

40 

41 name = 'QVTO' 

42 aliases = ['qvto', 'qvt'] 

43 filenames = ['*.qvto'] 

44 

45 tokens = { 

46 'root': [ 

47 (r'\n', Text), 

48 (r'[^\S\n]+', Text), 

49 (r'(--|//)(\s*)(directive:)?(.*)$', 

50 bygroups(Comment, Comment, Comment.Preproc, Comment)), 

51 # Uncomment the following if you want to distinguish between 

52 # '/*' and '/**', à la javadoc 

53 # (r'/[*]{2}(.|\n)*?[*]/', Comment.Multiline), 

54 (r'/[*](.|\n)*?[*]/', Comment.Multiline), 

55 (r'\\\n', Text), 

56 (r'(and|not|or|xor|##?)\b', Operator.Word), 

57 (r'(:{1,2}=|[-+]=)\b', Operator.Word), 

58 (r'(@|<<|>>)\b', Keyword), # stereotypes 

59 (r'!=|<>|==|=|!->|->|>=|<=|[.]{3}|[+/*%=<>&|.~]', Operator), 

60 (r'[]{}:(),;[]', Punctuation), 

61 (r'(true|false|unlimited|null)\b', Keyword.Constant), 

62 (r'(this|self|result)\b', Name.Builtin.Pseudo), 

63 (r'(var)\b', Keyword.Declaration), 

64 (r'(from|import)\b', Keyword.Namespace, 'fromimport'), 

65 (r'(metamodel|class|exception|primitive|enum|transformation|' 

66 r'library)(\s+)(\w+)', 

67 bygroups(Keyword.Word, Text, Name.Class)), 

68 (r'(exception)(\s+)(\w+)', 

69 bygroups(Keyword.Word, Text, Name.Exception)), 

70 (r'(main)\b', Name.Function), 

71 (r'(mapping|helper|query)(\s+)', 

72 bygroups(Keyword.Declaration, Text), 'operation'), 

73 (r'(assert)(\s+)\b', bygroups(Keyword, Text), 'assert'), 

74 (r'(Bag|Collection|Dict|OrderedSet|Sequence|Set|Tuple|List)\b', 

75 Keyword.Type), 

76 include('keywords'), 

77 ('"', String, combined('stringescape', 'dqs')), 

78 ("'", String, combined('stringescape', 'sqs')), 

79 include('name'), 

80 include('numbers'), 

81 # (r'([a-zA-Z_]\w*)(::)([a-zA-Z_]\w*)', 

82 # bygroups(Text, Text, Text)), 

83 ], 

84 

85 'fromimport': [ 

86 (r'(?:[ \t]|\\\n)+', Text), 

87 (r'[a-zA-Z_][\w.]*', Name.Namespace), 

88 default('#pop'), 

89 ], 

90 

91 'operation': [ 

92 (r'::', Text), 

93 (r'(.*::)([a-zA-Z_]\w*)([ \t]*)(\()', 

94 bygroups(Text, Name.Function, Text, Punctuation), '#pop') 

95 ], 

96 

97 'assert': [ 

98 (r'(warning|error|fatal)\b', Keyword, '#pop'), 

99 default('#pop'), # all else: go back 

100 ], 

101 

102 'keywords': [ 

103 (words(( 

104 'abstract', 'access', 'any', 'assert', 'blackbox', 'break', 

105 'case', 'collect', 'collectNested', 'collectOne', 'collectselect', 

106 'collectselectOne', 'composes', 'compute', 'configuration', 

107 'constructor', 'continue', 'datatype', 'default', 'derived', 

108 'disjuncts', 'do', 'elif', 'else', 'end', 'endif', 'except', 

109 'exists', 'extends', 'forAll', 'forEach', 'forOne', 'from', 'if', 

110 'implies', 'in', 'inherits', 'init', 'inout', 'intermediate', 

111 'invresolve', 'invresolveIn', 'invresolveone', 'invresolveoneIn', 

112 'isUnique', 'iterate', 'late', 'let', 'literal', 'log', 'map', 

113 'merges', 'modeltype', 'new', 'object', 'one', 'ordered', 'out', 

114 'package', 'population', 'property', 'raise', 'readonly', 

115 'references', 'refines', 'reject', 'resolve', 'resolveIn', 

116 'resolveone', 'resolveoneIn', 'return', 'select', 'selectOne', 

117 'sortedBy', 'static', 'switch', 'tag', 'then', 'try', 'typedef', 

118 'unlimited', 'uses', 'when', 'where', 'while', 'with', 'xcollect', 

119 'xmap', 'xselect'), suffix=r'\b'), Keyword), 

120 ], 

121 

122 # There is no need to distinguish between String.Single and 

123 # String.Double: 'strings' is factorised for 'dqs' and 'sqs' 

124 'strings': [ 

125 (r'[^\\\'"\n]+', String), 

126 # quotes, percents and backslashes must be parsed one at a time 

127 (r'[\'"\\]', String), 

128 ], 

129 'stringescape': [ 

130 (r'\\([\\btnfr"\']|u[0-3][0-7]{2}|u[0-7]{1,2})', String.Escape) 

131 ], 

132 'dqs': [ # double-quoted string 

133 (r'"', String, '#pop'), 

134 (r'\\\\|\\"', String.Escape), 

135 include('strings') 

136 ], 

137 'sqs': [ # single-quoted string 

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

139 (r"\\\\|\\'", String.Escape), 

140 include('strings') 

141 ], 

142 'name': [ 

143 (r'[a-zA-Z_]\w*', Name), 

144 ], 

145 # numbers: excerpt taken from the python lexer 

146 'numbers': [ 

147 (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), 

148 (r'\d+[eE][+-]?[0-9]+', Number.Float), 

149 (r'\d+', Number.Integer) 

150 ], 

151 }