verification.py 3.6 KB

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