verification.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. """
  2. pygments.lexers.verification
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for Intermediate Verification Languages (IVLs).
  5. :copyright: Copyright 2006-present 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://github.com/boogie-org/boogie/blob/master/Source/Core/BoogiePL.atg'
  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. 'action', 'assert', 'asserts', 'assume', 'async', 'atomic',
  32. 'axiom', 'break', 'call', 'else', 'ensures', 'exists',
  33. 'false', 'forall', 'free', 'function', 'goto', 'havoc', 'if',
  34. 'implementation', 'invariant', 'lambda', 'left', 'measure', 'modifies',
  35. 'old', 'preserves', 'procedure', 'public', 'requires', 'return', 'returns',
  36. 'right', 'then', 'true', 'type', 'unique', 'var', 'while', 'yield'),
  37. suffix=r'\b'), Keyword),
  38. (words(('const',), suffix=r'\b'), Keyword.Reserved),
  39. (words(('bool', 'int', 'real', 'ref'), suffix=r'\b'), Keyword.Type),
  40. include('numbers'),
  41. (r"(>=|<=|:=|!=|==>|&&|\|\||[+/\-=>*<\[\]])", Operator),
  42. (r'\{.*?\}', Generic.Emph), #triggers
  43. (r"([{}():;,.])", Punctuation),
  44. # Identifier
  45. (r'[a-zA-Z_]\w*', Name),
  46. ],
  47. 'comment': [
  48. (r'[^*/]+', Comment.Multiline),
  49. (r'/\*', Comment.Multiline, '#push'),
  50. (r'\*/', Comment.Multiline, '#pop'),
  51. (r'[*/]', Comment.Multiline),
  52. ],
  53. 'numbers': [
  54. (r'[0-9]+', Number.Integer),
  55. ],
  56. }
  57. class SilverLexer(RegexLexer):
  58. """
  59. For Silver source code.
  60. """
  61. name = 'Silver'
  62. aliases = ['silver']
  63. filenames = ['*.sil', '*.vpr']
  64. url = 'https://github.com/viperproject/silver'
  65. version_added = '2.2'
  66. tokens = {
  67. 'root': [
  68. # Whitespace and Comments
  69. (r'\n', Text),
  70. (r'\s+', Text),
  71. (r'\\\n', Text), # line continuation
  72. (r'//[/!](.*?)\n', Comment.Doc),
  73. (r'//(.*?)\n', Comment.Single),
  74. (r'/\*', Comment.Multiline, 'comment'),
  75. (words((
  76. 'result', 'true', 'false', 'null', 'method', 'function',
  77. 'predicate', 'program', 'domain', 'axiom', 'var', 'returns',
  78. 'field', 'define', 'fold', 'unfold', 'inhale', 'exhale', 'new', 'assert',
  79. 'assume', 'goto', 'while', 'if', 'elseif', 'else', 'fresh',
  80. 'constraining', 'Seq', 'Set', 'Multiset', 'union', 'intersection',
  81. 'setminus', 'subset', 'unfolding', 'in', 'old', 'forall', 'exists',
  82. 'acc', 'wildcard', 'write', 'none', 'epsilon', 'perm', 'unique',
  83. 'apply', 'package', 'folding', 'label', 'forperm'),
  84. suffix=r'\b'), Keyword),
  85. (words(('requires', 'ensures', 'invariant'), suffix=r'\b'), Name.Decorator),
  86. (words(('Int', 'Perm', 'Bool', 'Ref', 'Rational'), suffix=r'\b'), Keyword.Type),
  87. include('numbers'),
  88. (r'[!%&*+=|?:<>/\-\[\]]', Operator),
  89. (r'\{.*?\}', Generic.Emph), #triggers
  90. (r'([{}():;,.])', Punctuation),
  91. # Identifier
  92. (r'[\w$]\w*', Name),
  93. ],
  94. 'comment': [
  95. (r'[^*/]+', Comment.Multiline),
  96. (r'/\*', Comment.Multiline, '#push'),
  97. (r'\*/', Comment.Multiline, '#pop'),
  98. (r'[*/]', Comment.Multiline),
  99. ],
  100. 'numbers': [
  101. (r'[0-9]+', Number.Integer),
  102. ],
  103. }