verification.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. """
  2. pygments.lexers.verification
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for Intermediate Verification Languages (IVLs).
  5. :copyright: Copyright 2006-2021 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 <https://boogie.codeplex.com/>`_ source code.
  15. .. versionadded:: 2.1
  16. """
  17. name = 'Boogie'
  18. aliases = ['boogie']
  19. filenames = ['*.bpl']
  20. tokens = {
  21. 'root': [
  22. # Whitespace and Comments
  23. (r'\n', Text),
  24. (r'\s+', Text),
  25. (r'\\\n', Text), # line continuation
  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'\{.*?\}', Generic.Emph), #triggers
  39. (r"([{}():;,.])", Punctuation),
  40. # Identifier
  41. (r'[a-zA-Z_]\w*', Name),
  42. ],
  43. 'comment': [
  44. (r'[^*/]+', Comment.Multiline),
  45. (r'/\*', Comment.Multiline, '#push'),
  46. (r'\*/', Comment.Multiline, '#pop'),
  47. (r'[*/]', Comment.Multiline),
  48. ],
  49. 'numbers': [
  50. (r'[0-9]+', Number.Integer),
  51. ],
  52. }
  53. class SilverLexer(RegexLexer):
  54. """
  55. For `Silver <https://bitbucket.org/viperproject/silver>`_ source code.
  56. .. versionadded:: 2.2
  57. """
  58. name = 'Silver'
  59. aliases = ['silver']
  60. filenames = ['*.sil', '*.vpr']
  61. tokens = {
  62. 'root': [
  63. # Whitespace and Comments
  64. (r'\n', Text),
  65. (r'\s+', Text),
  66. (r'\\\n', Text), # line continuation
  67. (r'//[/!](.*?)\n', Comment.Doc),
  68. (r'//(.*?)\n', Comment.Single),
  69. (r'/\*', Comment.Multiline, 'comment'),
  70. (words((
  71. 'result', 'true', 'false', 'null', 'method', 'function',
  72. 'predicate', 'program', 'domain', 'axiom', 'var', 'returns',
  73. 'field', 'define', 'fold', 'unfold', 'inhale', 'exhale', 'new', 'assert',
  74. 'assume', 'goto', 'while', 'if', 'elseif', 'else', 'fresh',
  75. 'constraining', 'Seq', 'Set', 'Multiset', 'union', 'intersection',
  76. 'setminus', 'subset', 'unfolding', 'in', 'old', 'forall', 'exists',
  77. 'acc', 'wildcard', 'write', 'none', 'epsilon', 'perm', 'unique',
  78. 'apply', 'package', 'folding', 'label', 'forperm'),
  79. suffix=r'\b'), Keyword),
  80. (words(('requires', 'ensures', 'invariant'), suffix=r'\b'), Name.Decorator),
  81. (words(('Int', 'Perm', 'Bool', 'Ref', 'Rational'), suffix=r'\b'), Keyword.Type),
  82. include('numbers'),
  83. (r'[!%&*+=|?:<>/\-\[\]]', Operator),
  84. (r'\{.*?\}', Generic.Emph), #triggers
  85. (r'([{}():;,.])', Punctuation),
  86. # Identifier
  87. (r'[\w$]\w*', Name),
  88. ],
  89. 'comment': [
  90. (r'[^*/]+', Comment.Multiline),
  91. (r'/\*', Comment.Multiline, '#push'),
  92. (r'\*/', Comment.Multiline, '#pop'),
  93. (r'[*/]', Comment.Multiline),
  94. ],
  95. 'numbers': [
  96. (r'[0-9]+', Number.Integer),
  97. ],
  98. }