theorem.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. """
  2. pygments.lexers.theorem
  3. ~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for theorem-proving languages.
  5. :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. import re
  9. from pygments.lexer import RegexLexer, default, words, include
  10. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  11. Number, Punctuation, Generic, Whitespace
  12. __all__ = ['CoqLexer', 'IsabelleLexer', 'LeanLexer']
  13. class CoqLexer(RegexLexer):
  14. """
  15. For the Coq theorem prover.
  16. .. versionadded:: 1.5
  17. """
  18. name = 'Coq'
  19. url = 'http://coq.inria.fr/'
  20. aliases = ['coq']
  21. filenames = ['*.v']
  22. mimetypes = ['text/x-coq']
  23. flags = 0 # no re.MULTILINE
  24. keywords1 = (
  25. # Vernacular commands
  26. 'Section', 'Module', 'End', 'Require', 'Import', 'Export', 'Variable',
  27. 'Variables', 'Parameter', 'Parameters', 'Axiom', 'Axioms', 'Hypothesis',
  28. 'Hypotheses', 'Notation', 'Local', 'Tactic', 'Reserved', 'Scope',
  29. 'Open', 'Close', 'Bind', 'Delimit', 'Definition', 'Example', 'Let',
  30. 'Ltac', 'Fixpoint', 'CoFixpoint', 'Morphism', 'Relation', 'Implicit',
  31. 'Arguments', 'Types', 'Unset', 'Contextual', 'Strict', 'Prenex',
  32. 'Implicits', 'Inductive', 'CoInductive', 'Record', 'Structure',
  33. 'Variant', 'Canonical', 'Coercion', 'Theorem', 'Lemma', 'Fact',
  34. 'Remark', 'Corollary', 'Proposition', 'Property', 'Goal',
  35. 'Proof', 'Restart', 'Save', 'Qed', 'Defined', 'Abort', 'Admitted',
  36. 'Hint', 'Resolve', 'Rewrite', 'View', 'Search', 'Compute', 'Eval',
  37. 'Show', 'Print', 'Printing', 'All', 'Graph', 'Projections', 'inside',
  38. 'outside', 'Check', 'Global', 'Instance', 'Class', 'Existing',
  39. 'Universe', 'Polymorphic', 'Monomorphic', 'Context', 'Scheme', 'From',
  40. 'Undo', 'Fail', 'Function',
  41. )
  42. keywords2 = (
  43. # Gallina
  44. 'forall', 'exists', 'exists2', 'fun', 'fix', 'cofix', 'struct',
  45. 'match', 'end', 'in', 'return', 'let', 'if', 'is', 'then', 'else',
  46. 'for', 'of', 'nosimpl', 'with', 'as',
  47. )
  48. keywords3 = (
  49. # Sorts
  50. 'Type', 'Prop', 'SProp', 'Set',
  51. )
  52. keywords4 = (
  53. # Tactics
  54. 'pose', 'set', 'move', 'case', 'elim', 'apply', 'clear', 'hnf', 'intro',
  55. 'intros', 'generalize', 'rename', 'pattern', 'after', 'destruct',
  56. 'induction', 'using', 'refine', 'inversion', 'injection', 'rewrite',
  57. 'congr', 'unlock', 'compute', 'ring', 'field', 'replace', 'fold',
  58. 'unfold', 'change', 'cutrewrite', 'simpl', 'have', 'suff', 'wlog',
  59. 'suffices', 'without', 'loss', 'nat_norm', 'assert', 'cut', 'trivial',
  60. 'revert', 'bool_congr', 'nat_congr', 'symmetry', 'transitivity', 'auto',
  61. 'split', 'left', 'right', 'autorewrite', 'tauto', 'setoid_rewrite',
  62. 'intuition', 'eauto', 'eapply', 'econstructor', 'etransitivity',
  63. 'constructor', 'erewrite', 'red', 'cbv', 'lazy', 'vm_compute',
  64. 'native_compute', 'subst',
  65. )
  66. keywords5 = (
  67. # Terminators
  68. 'by', 'now', 'done', 'exact', 'reflexivity',
  69. 'tauto', 'romega', 'omega', 'lia', 'nia', 'lra', 'nra', 'psatz',
  70. 'assumption', 'solve', 'contradiction', 'discriminate',
  71. 'congruence', 'admit'
  72. )
  73. keywords6 = (
  74. # Control
  75. 'do', 'last', 'first', 'try', 'idtac', 'repeat',
  76. )
  77. # 'as', 'assert', 'begin', 'class', 'constraint', 'do', 'done',
  78. # 'downto', 'else', 'end', 'exception', 'external', 'false',
  79. # 'for', 'fun', 'function', 'functor', 'if', 'in', 'include',
  80. # 'inherit', 'initializer', 'lazy', 'let', 'match', 'method',
  81. # 'module', 'mutable', 'new', 'object', 'of', 'open', 'private',
  82. # 'raise', 'rec', 'sig', 'struct', 'then', 'to', 'true', 'try',
  83. # 'type', 'val', 'virtual', 'when', 'while', 'with'
  84. keyopts = (
  85. '!=', '#', '&', '&&', r'\(', r'\)', r'\*', r'\+', ',', '-', r'-\.',
  86. '->', r'\.', r'\.\.', ':', '::', ':=', ':>', ';', ';;', '<', '<-',
  87. '<->', '=', '>', '>]', r'>\}', r'\?', r'\?\?', r'\[', r'\[<', r'\[>',
  88. r'\[\|', ']', '_', '`', r'\{', r'\{<', r'\|', r'\|]', r'\}', '~', '=>',
  89. r'/\\', r'\\/', r'\{\|', r'\|\}',
  90. # 'Π', 'Σ', # Not defined in the standard library
  91. 'λ', '¬', '∧', '∨', '∀', '∃', '→', '↔', '≠', '≤', '≥',
  92. )
  93. operators = r'[!$%&*+\./:<=>?@^|~-]'
  94. prefix_syms = r'[!?~]'
  95. infix_syms = r'[=<>@^|&+\*/$%-]'
  96. tokens = {
  97. 'root': [
  98. (r'\s+', Text),
  99. (r'false|true|\(\)|\[\]', Name.Builtin.Pseudo),
  100. (r'\(\*', Comment, 'comment'),
  101. (r'\b(?:[^\W\d][\w\']*\.)+[^\W\d][\w\']*\b', Name),
  102. (r'\bEquations\b\??', Keyword.Namespace),
  103. # Very weak heuristic to distinguish the Set vernacular from the Set sort
  104. (r'\bSet(?=[ \t]+[A-Z][a-z][^\n]*?\.)', Keyword.Namespace),
  105. (words(keywords1, prefix=r'\b', suffix=r'\b'), Keyword.Namespace),
  106. (words(keywords2, prefix=r'\b', suffix=r'\b'), Keyword),
  107. (words(keywords3, prefix=r'\b', suffix=r'\b'), Keyword.Type),
  108. (words(keywords4, prefix=r'\b', suffix=r'\b'), Keyword),
  109. (words(keywords5, prefix=r'\b', suffix=r'\b'), Keyword.Pseudo),
  110. (words(keywords6, prefix=r'\b', suffix=r'\b'), Keyword.Reserved),
  111. # (r'\b([A-Z][\w\']*)(\.)', Name.Namespace, 'dotted'),
  112. (r'\b([A-Z][\w\']*)', Name),
  113. (r'(%s)' % '|'.join(keyopts[::-1]), Operator),
  114. (r'(%s|%s)?%s' % (infix_syms, prefix_syms, operators), Operator),
  115. (r"[^\W\d][\w']*", Name),
  116. (r'\d[\d_]*', Number.Integer),
  117. (r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex),
  118. (r'0[oO][0-7][0-7_]*', Number.Oct),
  119. (r'0[bB][01][01_]*', Number.Bin),
  120. (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float),
  121. (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'", String.Char),
  122. (r"'.'", String.Char),
  123. (r"'", Keyword), # a stray quote is another syntax element
  124. (r'"', String.Double, 'string'),
  125. (r'[~?][a-z][\w\']*:', Name),
  126. (r'\S', Name.Builtin.Pseudo),
  127. ],
  128. 'comment': [
  129. (r'[^(*)]+', Comment),
  130. (r'\(\*', Comment, '#push'),
  131. (r'\*\)', Comment, '#pop'),
  132. (r'[(*)]', Comment),
  133. ],
  134. 'string': [
  135. (r'[^"]+', String.Double),
  136. (r'""', String.Double),
  137. (r'"', String.Double, '#pop'),
  138. ],
  139. 'dotted': [
  140. (r'\s+', Text),
  141. (r'\.', Punctuation),
  142. (r'[A-Z][\w\']*(?=\s*\.)', Name.Namespace),
  143. (r'[A-Z][\w\']*', Name.Class, '#pop'),
  144. (r'[a-z][a-z0-9_\']*', Name, '#pop'),
  145. default('#pop')
  146. ],
  147. }
  148. def analyse_text(text):
  149. if 'Qed' in text and 'Proof' in text:
  150. return 1
  151. class IsabelleLexer(RegexLexer):
  152. """
  153. For the Isabelle proof assistant.
  154. .. versionadded:: 2.0
  155. """
  156. name = 'Isabelle'
  157. url = 'https://isabelle.in.tum.de/'
  158. aliases = ['isabelle']
  159. filenames = ['*.thy']
  160. mimetypes = ['text/x-isabelle']
  161. keyword_minor = (
  162. 'and', 'assumes', 'attach', 'avoids', 'binder', 'checking',
  163. 'class_instance', 'class_relation', 'code_module', 'congs',
  164. 'constant', 'constrains', 'datatypes', 'defines', 'file', 'fixes',
  165. 'for', 'functions', 'hints', 'identifier', 'if', 'imports', 'in',
  166. 'includes', 'infix', 'infixl', 'infixr', 'is', 'keywords', 'lazy',
  167. 'module_name', 'monos', 'morphisms', 'no_discs_sels', 'notes',
  168. 'obtains', 'open', 'output', 'overloaded', 'parametric', 'permissive',
  169. 'pervasive', 'rep_compat', 'shows', 'structure', 'type_class',
  170. 'type_constructor', 'unchecked', 'unsafe', 'where',
  171. )
  172. keyword_diag = (
  173. 'ML_command', 'ML_val', 'class_deps', 'code_deps', 'code_thms',
  174. 'display_drafts', 'find_consts', 'find_theorems', 'find_unused_assms',
  175. 'full_prf', 'help', 'locale_deps', 'nitpick', 'pr', 'prf',
  176. 'print_abbrevs', 'print_antiquotations', 'print_attributes',
  177. 'print_binds', 'print_bnfs', 'print_bundles',
  178. 'print_case_translations', 'print_cases', 'print_claset',
  179. 'print_classes', 'print_codeproc', 'print_codesetup',
  180. 'print_coercions', 'print_commands', 'print_context',
  181. 'print_defn_rules', 'print_dependencies', 'print_facts',
  182. 'print_induct_rules', 'print_inductives', 'print_interps',
  183. 'print_locale', 'print_locales', 'print_methods', 'print_options',
  184. 'print_orders', 'print_quot_maps', 'print_quotconsts',
  185. 'print_quotients', 'print_quotientsQ3', 'print_quotmapsQ3',
  186. 'print_rules', 'print_simpset', 'print_state', 'print_statement',
  187. 'print_syntax', 'print_theorems', 'print_theory', 'print_trans_rules',
  188. 'prop', 'pwd', 'quickcheck', 'refute', 'sledgehammer', 'smt_status',
  189. 'solve_direct', 'spark_status', 'term', 'thm', 'thm_deps', 'thy_deps',
  190. 'try', 'try0', 'typ', 'unused_thms', 'value', 'values', 'welcome',
  191. 'print_ML_antiquotations', 'print_term_bindings', 'values_prolog',
  192. )
  193. keyword_thy = ('theory', 'begin', 'end')
  194. keyword_section = ('header', 'chapter')
  195. keyword_subsection = (
  196. 'section', 'subsection', 'subsubsection', 'sect', 'subsect',
  197. 'subsubsect',
  198. )
  199. keyword_theory_decl = (
  200. 'ML', 'ML_file', 'abbreviation', 'adhoc_overloading', 'arities',
  201. 'atom_decl', 'attribute_setup', 'axiomatization', 'bundle',
  202. 'case_of_simps', 'class', 'classes', 'classrel', 'codatatype',
  203. 'code_abort', 'code_class', 'code_const', 'code_datatype',
  204. 'code_identifier', 'code_include', 'code_instance', 'code_modulename',
  205. 'code_monad', 'code_printing', 'code_reflect', 'code_reserved',
  206. 'code_type', 'coinductive', 'coinductive_set', 'consts', 'context',
  207. 'datatype', 'datatype_new', 'datatype_new_compat', 'declaration',
  208. 'declare', 'default_sort', 'defer_recdef', 'definition', 'defs',
  209. 'domain', 'domain_isomorphism', 'domaindef', 'equivariance',
  210. 'export_code', 'extract', 'extract_type', 'fixrec', 'fun',
  211. 'fun_cases', 'hide_class', 'hide_const', 'hide_fact', 'hide_type',
  212. 'import_const_map', 'import_file', 'import_tptp', 'import_type_map',
  213. 'inductive', 'inductive_set', 'instantiation', 'judgment', 'lemmas',
  214. 'lifting_forget', 'lifting_update', 'local_setup', 'locale',
  215. 'method_setup', 'nitpick_params', 'no_adhoc_overloading',
  216. 'no_notation', 'no_syntax', 'no_translations', 'no_type_notation',
  217. 'nominal_datatype', 'nonterminal', 'notation', 'notepad', 'oracle',
  218. 'overloading', 'parse_ast_translation', 'parse_translation',
  219. 'partial_function', 'primcorec', 'primrec', 'primrec_new',
  220. 'print_ast_translation', 'print_translation', 'quickcheck_generator',
  221. 'quickcheck_params', 'realizability', 'realizers', 'recdef', 'record',
  222. 'refute_params', 'setup', 'setup_lifting', 'simproc_setup',
  223. 'simps_of_case', 'sledgehammer_params', 'spark_end', 'spark_open',
  224. 'spark_open_siv', 'spark_open_vcg', 'spark_proof_functions',
  225. 'spark_types', 'statespace', 'syntax', 'syntax_declaration', 'text',
  226. 'text_raw', 'theorems', 'translations', 'type_notation',
  227. 'type_synonym', 'typed_print_translation', 'typedecl', 'hoarestate',
  228. 'install_C_file', 'install_C_types', 'wpc_setup', 'c_defs', 'c_types',
  229. 'memsafe', 'SML_export', 'SML_file', 'SML_import', 'approximate',
  230. 'bnf_axiomatization', 'cartouche', 'datatype_compat',
  231. 'free_constructors', 'functor', 'nominal_function',
  232. 'nominal_termination', 'permanent_interpretation',
  233. 'binds', 'defining', 'smt2_status', 'term_cartouche',
  234. 'boogie_file', 'text_cartouche',
  235. )
  236. keyword_theory_script = ('inductive_cases', 'inductive_simps')
  237. keyword_theory_goal = (
  238. 'ax_specification', 'bnf', 'code_pred', 'corollary', 'cpodef',
  239. 'crunch', 'crunch_ignore',
  240. 'enriched_type', 'function', 'instance', 'interpretation', 'lemma',
  241. 'lift_definition', 'nominal_inductive', 'nominal_inductive2',
  242. 'nominal_primrec', 'pcpodef', 'primcorecursive',
  243. 'quotient_definition', 'quotient_type', 'recdef_tc', 'rep_datatype',
  244. 'schematic_corollary', 'schematic_lemma', 'schematic_theorem',
  245. 'spark_vc', 'specification', 'subclass', 'sublocale', 'termination',
  246. 'theorem', 'typedef', 'wrap_free_constructors',
  247. )
  248. keyword_qed = ('by', 'done', 'qed')
  249. keyword_abandon_proof = ('sorry', 'oops')
  250. keyword_proof_goal = ('have', 'hence', 'interpret')
  251. keyword_proof_block = ('next', 'proof')
  252. keyword_proof_chain = (
  253. 'finally', 'from', 'then', 'ultimately', 'with',
  254. )
  255. keyword_proof_decl = (
  256. 'ML_prf', 'also', 'include', 'including', 'let', 'moreover', 'note',
  257. 'txt', 'txt_raw', 'unfolding', 'using', 'write',
  258. )
  259. keyword_proof_asm = ('assume', 'case', 'def', 'fix', 'presume')
  260. keyword_proof_asm_goal = ('guess', 'obtain', 'show', 'thus')
  261. keyword_proof_script = (
  262. 'apply', 'apply_end', 'apply_trace', 'back', 'defer', 'prefer',
  263. )
  264. operators = (
  265. '::', ':', '(', ')', '[', ']', '_', '=', ',', '|',
  266. '+', '-', '!', '?',
  267. )
  268. proof_operators = ('{', '}', '.', '..')
  269. tokens = {
  270. 'root': [
  271. (r'\s+', Whitespace),
  272. (r'\(\*', Comment, 'comment'),
  273. (r'\\<open>', String.Symbol, 'cartouche'),
  274. (r'\{\*|‹', String, 'cartouche'),
  275. (words(operators), Operator),
  276. (words(proof_operators), Operator.Word),
  277. (words(keyword_minor, prefix=r'\b', suffix=r'\b'), Keyword.Pseudo),
  278. (words(keyword_diag, prefix=r'\b', suffix=r'\b'), Keyword.Type),
  279. (words(keyword_thy, prefix=r'\b', suffix=r'\b'), Keyword),
  280. (words(keyword_theory_decl, prefix=r'\b', suffix=r'\b'), Keyword),
  281. (words(keyword_section, prefix=r'\b', suffix=r'\b'), Generic.Heading),
  282. (words(keyword_subsection, prefix=r'\b', suffix=r'\b'), Generic.Subheading),
  283. (words(keyword_theory_goal, prefix=r'\b', suffix=r'\b'), Keyword.Namespace),
  284. (words(keyword_theory_script, prefix=r'\b', suffix=r'\b'), Keyword.Namespace),
  285. (words(keyword_abandon_proof, prefix=r'\b', suffix=r'\b'), Generic.Error),
  286. (words(keyword_qed, prefix=r'\b', suffix=r'\b'), Keyword),
  287. (words(keyword_proof_goal, prefix=r'\b', suffix=r'\b'), Keyword),
  288. (words(keyword_proof_block, prefix=r'\b', suffix=r'\b'), Keyword),
  289. (words(keyword_proof_decl, prefix=r'\b', suffix=r'\b'), Keyword),
  290. (words(keyword_proof_chain, prefix=r'\b', suffix=r'\b'), Keyword),
  291. (words(keyword_proof_asm, prefix=r'\b', suffix=r'\b'), Keyword),
  292. (words(keyword_proof_asm_goal, prefix=r'\b', suffix=r'\b'), Keyword),
  293. (words(keyword_proof_script, prefix=r'\b', suffix=r'\b'), Keyword.Pseudo),
  294. (r'\\<(\w|\^)*>', Text.Symbol),
  295. (r"'[^\W\d][.\w']*", Name.Type),
  296. (r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex),
  297. (r'0[oO][0-7][0-7_]*', Number.Oct),
  298. (r'0[bB][01][01_]*', Number.Bin),
  299. (r'"', String, 'string'),
  300. (r'`', String.Other, 'fact'),
  301. (r'[^\s:|\[\]\-()=,+!?{}._][^\s:|\[\]\-()=,+!?{}]*', Name),
  302. ],
  303. 'comment': [
  304. (r'[^(*)]+', Comment),
  305. (r'\(\*', Comment, '#push'),
  306. (r'\*\)', Comment, '#pop'),
  307. (r'[(*)]', Comment),
  308. ],
  309. 'cartouche': [
  310. (r'[^{*}\\‹›]+', String),
  311. (r'\\<open>', String.Symbol, '#push'),
  312. (r'\{\*|‹', String, '#push'),
  313. (r'\\<close>', String.Symbol, '#pop'),
  314. (r'\*\}|›', String, '#pop'),
  315. (r'\\<(\w|\^)*>', String.Symbol),
  316. (r'[{*}\\]', String),
  317. ],
  318. 'string': [
  319. (r'[^"\\]+', String),
  320. (r'\\<(\w|\^)*>', String.Symbol),
  321. (r'\\"', String),
  322. (r'\\', String),
  323. (r'"', String, '#pop'),
  324. ],
  325. 'fact': [
  326. (r'[^`\\]+', String.Other),
  327. (r'\\<(\w|\^)*>', String.Symbol),
  328. (r'\\`', String.Other),
  329. (r'\\', String.Other),
  330. (r'`', String.Other, '#pop'),
  331. ],
  332. }
  333. class LeanLexer(RegexLexer):
  334. """
  335. For the Lean theorem prover.
  336. .. versionadded:: 2.0
  337. """
  338. name = 'Lean'
  339. url = 'https://github.com/leanprover/lean'
  340. aliases = ['lean']
  341. filenames = ['*.lean']
  342. mimetypes = ['text/x-lean']
  343. tokens = {
  344. 'expression': [
  345. (r'\s+', Text),
  346. (r'/--', String.Doc, 'docstring'),
  347. (r'/-', Comment, 'comment'),
  348. (r'--.*?$', Comment.Single),
  349. (words((
  350. 'forall', 'fun', 'Pi', 'from', 'have', 'show', 'assume', 'suffices',
  351. 'let', 'if', 'else', 'then', 'in', 'with', 'calc', 'match',
  352. 'do'
  353. ), prefix=r'\b', suffix=r'\b'), Keyword),
  354. (words(('sorry', 'admit'), prefix=r'\b', suffix=r'\b'), Generic.Error),
  355. (words(('Sort', 'Prop', 'Type'), prefix=r'\b', suffix=r'\b'), Keyword.Type),
  356. (words((
  357. '(', ')', ':', '{', '}', '[', ']', '⟨', '⟩', '‹', '›', '⦃', '⦄', ':=', ',',
  358. )), Operator),
  359. (r'[A-Za-z_\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2100-\u214f]'
  360. r'[.A-Za-z_\'\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2070-\u2079'
  361. r'\u207f-\u2089\u2090-\u209c\u2100-\u214f0-9]*', Name),
  362. (r'0x[A-Za-z0-9]+', Number.Integer),
  363. (r'0b[01]+', Number.Integer),
  364. (r'\d+', Number.Integer),
  365. (r'"', String.Double, 'string'),
  366. (r"'(?:(\\[\\\"'nt])|(\\x[0-9a-fA-F]{2})|(\\u[0-9a-fA-F]{4})|.)'", String.Char),
  367. (r'[~?][a-z][\w\']*:', Name.Variable),
  368. (r'\S', Name.Builtin.Pseudo),
  369. ],
  370. 'root': [
  371. (words((
  372. 'import', 'renaming', 'hiding',
  373. 'namespace',
  374. 'local',
  375. 'private', 'protected', 'section',
  376. 'include', 'omit', 'section',
  377. 'protected', 'export',
  378. 'open',
  379. 'attribute',
  380. ), prefix=r'\b', suffix=r'\b'), Keyword.Namespace),
  381. (words((
  382. 'lemma', 'theorem', 'def', 'definition', 'example',
  383. 'axiom', 'axioms', 'constant', 'constants',
  384. 'universe', 'universes',
  385. 'inductive', 'coinductive', 'structure', 'extends',
  386. 'class', 'instance',
  387. 'abbreviation',
  388. 'noncomputable theory',
  389. 'noncomputable', 'mutual', 'meta',
  390. 'attribute',
  391. 'parameter', 'parameters',
  392. 'variable', 'variables',
  393. 'reserve', 'precedence',
  394. 'postfix', 'prefix', 'notation', 'infix', 'infixl', 'infixr',
  395. 'begin', 'by', 'end',
  396. 'set_option',
  397. 'run_cmd',
  398. ), prefix=r'\b', suffix=r'\b'), Keyword.Declaration),
  399. (r'@\[', Keyword.Declaration, 'attribute'),
  400. (words((
  401. '#eval', '#check', '#reduce', '#exit',
  402. '#print', '#help',
  403. ), suffix=r'\b'), Keyword),
  404. include('expression')
  405. ],
  406. 'attribute': [
  407. (r'\]', Keyword.Declaration, '#pop'),
  408. include('expression'),
  409. ],
  410. 'comment': [
  411. (r'[^/-]', Comment.Multiline),
  412. (r'/-', Comment.Multiline, '#push'),
  413. (r'-/', Comment.Multiline, '#pop'),
  414. (r'[/-]', Comment.Multiline)
  415. ],
  416. 'docstring': [
  417. (r'[^/-]', String.Doc),
  418. (r'-/', String.Doc, '#pop'),
  419. (r'[/-]', String.Doc)
  420. ],
  421. 'string': [
  422. (r'[^\\"]+', String.Double),
  423. (r"(?:(\\[\\\"'nt])|(\\x[0-9a-fA-F]{2})|(\\u[0-9a-fA-F]{4}))", String.Escape),
  424. ('"', String.Double, '#pop'),
  425. ],
  426. }