verification.py 3.8 KB

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