verifpal.py 2.6 KB

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