1"""
2 pygments.lexers.verification
3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5 Lexer for Intermediate Verification Languages (IVLs).
6
7 :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
10
11from pygments.lexer import RegexLexer, include, words
12from pygments.token import Comment, Operator, Keyword, Name, Number, \
13 Punctuation, Text, Generic
14
15__all__ = ['BoogieLexer', 'SilverLexer']
16
17
18class BoogieLexer(RegexLexer):
19 """
20 For Boogie source code.
21 """
22 name = 'Boogie'
23 url = 'https://github.com/boogie-org/boogie/blob/master/Source/Core/BoogiePL.atg'
24 aliases = ['boogie']
25 filenames = ['*.bpl']
26 version_added = '2.1'
27
28 tokens = {
29 'root': [
30 # Whitespace and Comments
31 (r'\n', Text),
32 (r'\s+', Text),
33 (r'\\\n', Text), # line continuation
34 (r'//[/!](.*?)\n', Comment.Doc),
35 (r'//(.*?)\n', Comment.Single),
36 (r'/\*', Comment.Multiline, 'comment'),
37
38 (words((
39 'action', 'assert', 'asserts', 'assume', 'async', 'atomic',
40 'axiom', 'break', 'call', 'else', 'ensures', 'exists',
41 'false', 'forall', 'free', 'function', 'goto', 'havoc', 'if',
42 'implementation', 'invariant', 'lambda', 'left', 'measure', 'modifies',
43 'old', 'preserves', 'procedure', 'public', 'requires', 'return', 'returns',
44 'right', 'then', 'true', 'type', 'unique', 'var', 'while', 'yield'),
45 suffix=r'\b'), Keyword),
46 (words(('const',), suffix=r'\b'), Keyword.Reserved),
47
48 (words(('bool', 'int', 'real', 'ref'), suffix=r'\b'), Keyword.Type),
49 include('numbers'),
50 (r"(>=|<=|:=|!=|==>|&&|\|\||[+/\-=>*<\[\]])", Operator),
51 (r'\{.*?\}', Generic.Emph), #triggers
52 (r"([{}():;,.])", Punctuation),
53 # Identifier
54 (r'[a-zA-Z_]\w*', Name),
55 ],
56 'comment': [
57 (r'[^*/]+', Comment.Multiline),
58 (r'/\*', Comment.Multiline, '#push'),
59 (r'\*/', Comment.Multiline, '#pop'),
60 (r'[*/]', Comment.Multiline),
61 ],
62 'numbers': [
63 (r'[0-9]+', Number.Integer),
64 ],
65 }
66
67
68class SilverLexer(RegexLexer):
69 """
70 For Silver source code.
71 """
72 name = 'Silver'
73 aliases = ['silver']
74 filenames = ['*.sil', '*.vpr']
75 url = 'https://github.com/viperproject/silver'
76 version_added = '2.2'
77
78 tokens = {
79 'root': [
80 # Whitespace and Comments
81 (r'\n', Text),
82 (r'\s+', Text),
83 (r'\\\n', Text), # line continuation
84 (r'//[/!](.*?)\n', Comment.Doc),
85 (r'//(.*?)\n', Comment.Single),
86 (r'/\*', Comment.Multiline, 'comment'),
87
88 (words((
89 'result', 'true', 'false', 'null', 'method', 'function',
90 'predicate', 'program', 'domain', 'axiom', 'var', 'returns',
91 'field', 'define', 'fold', 'unfold', 'inhale', 'exhale', 'new', 'assert',
92 'assume', 'goto', 'while', 'if', 'elseif', 'else', 'fresh',
93 'constraining', 'Seq', 'Set', 'Multiset', 'union', 'intersection',
94 'setminus', 'subset', 'unfolding', 'in', 'old', 'forall', 'exists',
95 'acc', 'wildcard', 'write', 'none', 'epsilon', 'perm', 'unique',
96 'apply', 'package', 'folding', 'label', 'forperm'),
97 suffix=r'\b'), Keyword),
98 (words(('requires', 'ensures', 'invariant'), suffix=r'\b'), Name.Decorator),
99 (words(('Int', 'Perm', 'Bool', 'Ref', 'Rational'), suffix=r'\b'), Keyword.Type),
100 include('numbers'),
101 (r'[!%&*+=|?:<>/\-\[\]]', Operator),
102 (r'\{.*?\}', Generic.Emph), #triggers
103 (r'([{}():;,.])', Punctuation),
104 # Identifier
105 (r'[\w$]\w*', Name),
106 ],
107 'comment': [
108 (r'[^*/]+', Comment.Multiline),
109 (r'/\*', Comment.Multiline, '#push'),
110 (r'\*/', Comment.Multiline, '#pop'),
111 (r'[*/]', Comment.Multiline),
112 ],
113 'numbers': [
114 (r'[0-9]+', Number.Integer),
115 ],
116 }