1"""
2 pygments.lexers.verifpal
3 ~~~~~~~~~~~~~~~~~~~~~~~~
4
5 Lexers for Verifpal languages.
6
7 :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
10
11from pygments.lexer import RegexLexer, words, bygroups, default
12from pygments.token import Comment, Keyword, Name, String, Punctuation, \
13 Whitespace
14
15__all__ = ['VerifpalLexer']
16
17
18class VerifpalLexer(RegexLexer):
19 """
20 For Verifpal code.
21 """
22
23 name = 'Verifpal'
24 aliases = ['verifpal']
25 filenames = ['*.vp']
26 mimetypes = ['text/x-verifpal']
27 url = 'https://verifpal.com'
28 version_added = '2.16'
29
30 tokens = {
31 'root': [
32 (r'//.*$', Comment.Single),
33 (r'(principal)( +)(\w+)( *)(\[)(.*)$', bygroups(Name.Builtin, Whitespace, String, Whitespace, Punctuation, Whitespace)),
34 (r'(attacker)( *)(\[)( *)(passive|active)( *)(\])( *)$', bygroups(Name.Builtin, Whitespace, Punctuation, Whitespace, String, Whitespace, Punctuation, Whitespace)),
35 (r'(knows)( +)(private|public)( +)', bygroups(Name.Builtin, Whitespace, Keyword.Constant, Whitespace), 'shared'),
36 (r'(queries)( +)(\[)', bygroups(Name.Builtin, Whitespace, Punctuation), 'queries'),
37 (r'(\w+)( +)(->|→)( *)(\w+)( *)(\:)', bygroups(String, Whitespace, Punctuation, Whitespace, String, Whitespace, Punctuation), 'shared'),
38 (words(('generates', 'leaks'), suffix=r'\b'), Name.Builtin, 'shared'),
39 (words(( 'phase', 'precondition',), suffix=r'\b'), Name.Builtin),
40 (r'[\[\(\)\]\?:=→^,]', Punctuation),
41 (r'->', Punctuation),
42 (words(('password',), suffix=r'\b'), Keyword.Constant),
43 (words(('AEAD_DEC', 'AEAD_ENC', 'ASSERT', 'BLIND', 'CONCAT',
44 'DEC', 'ENC', 'G', 'HASH', 'HKDF', 'MAC', 'PKE_DEC',
45 'PKE_ENC', 'PW_HASH', 'RINGSIGN', 'RINGSIGNVERIF',
46 'SHAMIR_JOIN', 'SHAMIR_SPLIT', 'SIGN', 'SIGNVERIF',
47 'SPLIT', 'UNBLIND', '_', 'nil'), suffix=r'\b'),
48 Name.Function),
49 (r'\s+', Whitespace),
50 (r'\w+', Name.Variable),
51 ],
52 'shared': [
53 (r'[\^\[\],]', Punctuation),
54 (r' +', Whitespace),
55 (r'\w+', Name.Variable),
56 default('#pop')
57 ],
58 'queries': [
59 (r'\s+', Name.Variable),
60 (words(('confidentiality?', 'authentication?', 'freshness?',
61 'unlinkability?', 'equivalence?'), suffix='( )'),
62 bygroups(Keyword.Pseudo, Whitespace), 'shared'),
63 default('#pop')
64 ]
65 }