theorem.py 19 KB

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