verification.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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, Text, Generic
  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', 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 <https://bitbucket.org/viperproject/silver>`_ source code.
  57. .. versionadded:: 2.2
  58. """
  59. name = 'Silver'
  60. aliases = ['silver']
  61. filenames = ['*.sil', '*.vpr']
  62. tokens = {
  63. 'root': [
  64. # Whitespace and Comments
  65. (r'\n', Text),
  66. (r'\s+', Text),
  67. (r'\\\n', Text), # line continuation
  68. (r'//[/!](.*?)\n', Comment.Doc),
  69. (r'//(.*?)\n', Comment.Single),
  70. (r'/\*', Comment.Multiline, 'comment'),
  71. (words((
  72. 'result', 'true', 'false', 'null', 'method', 'function',
  73. 'predicate', 'program', 'domain', 'axiom', 'var', 'returns',
  74. 'field', 'define', 'fold', 'unfold', 'inhale', 'exhale', 'new', 'assert',
  75. 'assume', 'goto', 'while', 'if', 'elseif', 'else', 'fresh',
  76. 'constraining', 'Seq', 'Set', 'Multiset', 'union', 'intersection',
  77. 'setminus', 'subset', 'unfolding', 'in', 'old', 'forall', 'exists',
  78. 'acc', 'wildcard', 'write', 'none', 'epsilon', 'perm', 'unique',
  79. 'apply', 'package', 'folding', 'label', 'forperm'),
  80. suffix=r'\b'), Keyword),
  81. (words(('requires', 'ensures', 'invariant'), suffix=r'\b'), Name.Decorator),
  82. (words(('Int', 'Perm', 'Bool', 'Ref', 'Rational'), suffix=r'\b'), Keyword.Type),
  83. include('numbers'),
  84. (r'[!%&*+=|?:<>/\-\[\]]', Operator),
  85. (r'\{.*?\}', Generic.Emph), #triggers
  86. (r'([{}():;,.])', Punctuation),
  87. # Identifier
  88. (r'[\w$]\w*', Name),
  89. ],
  90. 'comment': [
  91. (r'[^*/]+', Comment.Multiline),
  92. (r'/\*', Comment.Multiline, '#push'),
  93. (r'\*/', Comment.Multiline, '#pop'),
  94. (r'[*/]', Comment.Multiline),
  95. ],
  96. 'numbers': [
  97. (r'[0-9]+', Number.Integer),
  98. ],
  99. }