PageRenderTime 72ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/pygments/lexers/functional.py

https://bitbucket.org/pnathan/pygments-main
Python | 2395 lines | 1818 code | 216 blank | 361 comment | 25 complexity | db920509ffd7d877e19b47c2d6ceb0aa MD5 | raw file
Possible License(s): BSD-2-Clause
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.functional
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Lexers for functional languages.
  6. :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. import re
  10. from pygments.lexer import Lexer, RegexLexer, bygroups, include, do_insertions
  11. from pygments.token import Text, Comment, Operator, Keyword, Name, \
  12. String, Number, Punctuation, Literal, Generic, Error
  13. __all__ = ['RacketLexer', 'SchemeLexer', 'CommonLispLexer', 'HaskellLexer',
  14. 'LiterateHaskellLexer', 'SMLLexer', 'OcamlLexer', 'ErlangLexer',
  15. 'ErlangShellLexer', 'OpaLexer', 'CoqLexer', 'NewLispLexer',
  16. 'ElixirLexer', 'ElixirConsoleLexer']
  17. class RacketLexer(RegexLexer):
  18. """
  19. Lexer for Racket source code.
  20. *New in Pygments 1.6.*
  21. """
  22. name = 'Racket'
  23. aliases = ['racket', 'rkt']
  24. filenames = ['*.rkt', '*.rktl']
  25. mimetypes = ['text/x-racket', 'application/x-racket']
  26. # From namespace-mapped-symbols
  27. keywords = [
  28. '#%app', '#%datum', '#%expression', '#%module-begin',
  29. '#%plain-app', '#%plain-lambda', '#%plain-module-begin',
  30. '#%provide', '#%require', '#%stratified-body', '#%top',
  31. '#%top-interaction', '#%variable-reference', '...', 'and', 'begin',
  32. 'begin-for-syntax', 'begin0', 'case', 'case-lambda', 'cond',
  33. 'datum->syntax-object', 'define', 'define-for-syntax',
  34. 'define-struct', 'define-syntax', 'define-syntax-rule',
  35. 'define-syntaxes', 'define-values', 'define-values-for-syntax',
  36. 'delay', 'do', 'expand-path', 'fluid-let', 'hash-table-copy',
  37. 'hash-table-count', 'hash-table-for-each', 'hash-table-get',
  38. 'hash-table-iterate-first', 'hash-table-iterate-key',
  39. 'hash-table-iterate-next', 'hash-table-iterate-value',
  40. 'hash-table-map', 'hash-table-put!', 'hash-table-remove!',
  41. 'hash-table?', 'if', 'lambda', 'let', 'let*', 'let*-values',
  42. 'let-struct', 'let-syntax', 'let-syntaxes', 'let-values', 'let/cc',
  43. 'let/ec', 'letrec', 'letrec-syntax', 'letrec-syntaxes',
  44. 'letrec-syntaxes+values', 'letrec-values', 'list-immutable',
  45. 'make-hash-table', 'make-immutable-hash-table', 'make-namespace',
  46. 'module', 'module-identifier=?', 'module-label-identifier=?',
  47. 'module-template-identifier=?', 'module-transformer-identifier=?',
  48. 'namespace-transformer-require', 'or', 'parameterize',
  49. 'parameterize*', 'parameterize-break', 'provide',
  50. 'provide-for-label', 'provide-for-syntax', 'quasiquote',
  51. 'quasisyntax', 'quasisyntax/loc', 'quote', 'quote-syntax',
  52. 'quote-syntax/prune', 'require', 'require-for-label',
  53. 'require-for-syntax', 'require-for-template', 'set!',
  54. 'set!-values', 'syntax', 'syntax-case', 'syntax-case*',
  55. 'syntax-id-rules', 'syntax-object->datum', 'syntax-rules',
  56. 'syntax/loc', 'time', 'transcript-off', 'transcript-on', 'unless',
  57. 'unquote', 'unquote-splicing', 'unsyntax', 'unsyntax-splicing',
  58. 'when', 'with-continuation-mark', 'with-handlers',
  59. 'with-handlers*', 'with-syntax', 'λ'
  60. ]
  61. # From namespace-mapped-symbols
  62. builtins = [
  63. '*', '+', '-', '/', '<', '<=', '=', '>', '>=',
  64. 'abort-current-continuation', 'abs', 'absolute-path?', 'acos',
  65. 'add1', 'alarm-evt', 'always-evt', 'andmap', 'angle', 'append',
  66. 'apply', 'arithmetic-shift', 'arity-at-least',
  67. 'arity-at-least-value', 'arity-at-least?', 'asin', 'assoc', 'assq',
  68. 'assv', 'atan', 'banner', 'bitwise-and', 'bitwise-bit-field',
  69. 'bitwise-bit-set?', 'bitwise-ior', 'bitwise-not', 'bitwise-xor',
  70. 'boolean?', 'bound-identifier=?', 'box', 'box-immutable', 'box?',
  71. 'break-enabled', 'break-thread', 'build-path',
  72. 'build-path/convention-type', 'byte-pregexp', 'byte-pregexp?',
  73. 'byte-ready?', 'byte-regexp', 'byte-regexp?', 'byte?', 'bytes',
  74. 'bytes->immutable-bytes', 'bytes->list', 'bytes->path',
  75. 'bytes->path-element', 'bytes->string/latin-1',
  76. 'bytes->string/locale', 'bytes->string/utf-8', 'bytes-append',
  77. 'bytes-close-converter', 'bytes-convert', 'bytes-convert-end',
  78. 'bytes-converter?', 'bytes-copy', 'bytes-copy!', 'bytes-fill!',
  79. 'bytes-length', 'bytes-open-converter', 'bytes-ref', 'bytes-set!',
  80. 'bytes-utf-8-index', 'bytes-utf-8-length', 'bytes-utf-8-ref',
  81. 'bytes<?', 'bytes=?', 'bytes>?', 'bytes?', 'caaaar', 'caaadr',
  82. 'caaar', 'caadar', 'caaddr', 'caadr', 'caar', 'cadaar', 'cadadr',
  83. 'cadar', 'caddar', 'cadddr', 'caddr', 'cadr',
  84. 'call-in-nested-thread', 'call-with-break-parameterization',
  85. 'call-with-composable-continuation',
  86. 'call-with-continuation-barrier', 'call-with-continuation-prompt',
  87. 'call-with-current-continuation', 'call-with-escape-continuation',
  88. 'call-with-exception-handler',
  89. 'call-with-immediate-continuation-mark', 'call-with-input-file',
  90. 'call-with-output-file', 'call-with-parameterization',
  91. 'call-with-semaphore', 'call-with-semaphore/enable-break',
  92. 'call-with-values', 'call/cc', 'call/ec', 'car', 'cdaaar',
  93. 'cdaadr', 'cdaar', 'cdadar', 'cdaddr', 'cdadr', 'cdar', 'cddaar',
  94. 'cddadr', 'cddar', 'cdddar', 'cddddr', 'cdddr', 'cddr', 'cdr',
  95. 'ceiling', 'channel-get', 'channel-put', 'channel-put-evt',
  96. 'channel-try-get', 'channel?', 'chaperone-box', 'chaperone-evt',
  97. 'chaperone-hash', 'chaperone-of?', 'chaperone-procedure',
  98. 'chaperone-struct', 'chaperone-struct-type', 'chaperone-vector',
  99. 'chaperone?', 'char->integer', 'char-alphabetic?', 'char-blank?',
  100. 'char-ci<=?', 'char-ci<?', 'char-ci=?', 'char-ci>=?', 'char-ci>?',
  101. 'char-downcase', 'char-foldcase', 'char-general-category',
  102. 'char-graphic?', 'char-iso-control?', 'char-lower-case?',
  103. 'char-numeric?', 'char-punctuation?', 'char-ready?',
  104. 'char-symbolic?', 'char-title-case?', 'char-titlecase',
  105. 'char-upcase', 'char-upper-case?', 'char-utf-8-length',
  106. 'char-whitespace?', 'char<=?', 'char<?', 'char=?', 'char>=?',
  107. 'char>?', 'char?', 'check-duplicate-identifier',
  108. 'checked-procedure-check-and-extract', 'choice-evt',
  109. 'cleanse-path', 'close-input-port', 'close-output-port',
  110. 'collect-garbage', 'collection-file-path', 'collection-path',
  111. 'compile', 'compile-allow-set!-undefined',
  112. 'compile-context-preservation-enabled',
  113. 'compile-enforce-module-constants', 'compile-syntax',
  114. 'compiled-expression?', 'compiled-module-expression?',
  115. 'complete-path?', 'complex?', 'cons',
  116. 'continuation-mark-set->context', 'continuation-mark-set->list',
  117. 'continuation-mark-set->list*', 'continuation-mark-set-first',
  118. 'continuation-mark-set?', 'continuation-marks',
  119. 'continuation-prompt-available?', 'continuation-prompt-tag?',
  120. 'continuation?', 'copy-file', 'cos',
  121. 'current-break-parameterization', 'current-code-inspector',
  122. 'current-command-line-arguments', 'current-compile',
  123. 'current-continuation-marks', 'current-custodian',
  124. 'current-directory', 'current-drive', 'current-error-port',
  125. 'current-eval', 'current-evt-pseudo-random-generator',
  126. 'current-gc-milliseconds', 'current-get-interaction-input-port',
  127. 'current-inexact-milliseconds', 'current-input-port',
  128. 'current-inspector', 'current-library-collection-paths',
  129. 'current-load', 'current-load-extension',
  130. 'current-load-relative-directory', 'current-load/use-compiled',
  131. 'current-locale', 'current-memory-use', 'current-milliseconds',
  132. 'current-module-declare-name', 'current-module-declare-source',
  133. 'current-module-name-resolver', 'current-namespace',
  134. 'current-output-port', 'current-parameterization',
  135. 'current-preserved-thread-cell-values', 'current-print',
  136. 'current-process-milliseconds', 'current-prompt-read',
  137. 'current-pseudo-random-generator', 'current-read-interaction',
  138. 'current-reader-guard', 'current-readtable', 'current-seconds',
  139. 'current-security-guard', 'current-subprocess-custodian-mode',
  140. 'current-thread', 'current-thread-group',
  141. 'current-thread-initial-stack-size',
  142. 'current-write-relative-directory', 'custodian-box-value',
  143. 'custodian-box?', 'custodian-limit-memory',
  144. 'custodian-managed-list', 'custodian-memory-accounting-available?',
  145. 'custodian-require-memory', 'custodian-shutdown-all', 'custodian?',
  146. 'custom-print-quotable-accessor', 'custom-print-quotable?',
  147. 'custom-write-accessor', 'custom-write?', 'date', 'date*',
  148. 'date*-nanosecond', 'date*-time-zone-name', 'date*?', 'date-day',
  149. 'date-dst?', 'date-hour', 'date-minute', 'date-month',
  150. 'date-second', 'date-time-zone-offset', 'date-week-day',
  151. 'date-year', 'date-year-day', 'date?', 'datum-intern-literal',
  152. 'default-continuation-prompt-tag', 'delete-directory',
  153. 'delete-file', 'denominator', 'directory-exists?',
  154. 'directory-list', 'display', 'displayln', 'dump-memory-stats',
  155. 'dynamic-require', 'dynamic-require-for-syntax', 'dynamic-wind',
  156. 'eof', 'eof-object?', 'ephemeron-value', 'ephemeron?', 'eprintf',
  157. 'eq-hash-code', 'eq?', 'equal-hash-code',
  158. 'equal-secondary-hash-code', 'equal?', 'equal?/recur',
  159. 'eqv-hash-code', 'eqv?', 'error', 'error-display-handler',
  160. 'error-escape-handler', 'error-print-context-length',
  161. 'error-print-source-location', 'error-print-width',
  162. 'error-value->string-handler', 'eval', 'eval-jit-enabled',
  163. 'eval-syntax', 'even?', 'evt?', 'exact->inexact', 'exact-integer?',
  164. 'exact-nonnegative-integer?', 'exact-positive-integer?', 'exact?',
  165. 'executable-yield-handler', 'exit', 'exit-handler', 'exn',
  166. 'exn-continuation-marks', 'exn-message', 'exn:break',
  167. 'exn:break-continuation', 'exn:break?', 'exn:fail',
  168. 'exn:fail:contract', 'exn:fail:contract:arity',
  169. 'exn:fail:contract:arity?', 'exn:fail:contract:continuation',
  170. 'exn:fail:contract:continuation?',
  171. 'exn:fail:contract:divide-by-zero',
  172. 'exn:fail:contract:divide-by-zero?',
  173. 'exn:fail:contract:non-fixnum-result',
  174. 'exn:fail:contract:non-fixnum-result?',
  175. 'exn:fail:contract:variable', 'exn:fail:contract:variable-id',
  176. 'exn:fail:contract:variable?', 'exn:fail:contract?',
  177. 'exn:fail:filesystem', 'exn:fail:filesystem:exists',
  178. 'exn:fail:filesystem:exists?', 'exn:fail:filesystem:version',
  179. 'exn:fail:filesystem:version?', 'exn:fail:filesystem?',
  180. 'exn:fail:network', 'exn:fail:network?', 'exn:fail:out-of-memory',
  181. 'exn:fail:out-of-memory?', 'exn:fail:read',
  182. 'exn:fail:read-srclocs', 'exn:fail:read:eof', 'exn:fail:read:eof?',
  183. 'exn:fail:read:non-char', 'exn:fail:read:non-char?',
  184. 'exn:fail:read?', 'exn:fail:syntax', 'exn:fail:syntax-exprs',
  185. 'exn:fail:syntax:unbound', 'exn:fail:syntax:unbound?',
  186. 'exn:fail:syntax?', 'exn:fail:unsupported',
  187. 'exn:fail:unsupported?', 'exn:fail:user', 'exn:fail:user?',
  188. 'exn:fail?', 'exn:srclocs-accessor', 'exn:srclocs?', 'exn?', 'exp',
  189. 'expand', 'expand-once', 'expand-syntax', 'expand-syntax-once',
  190. 'expand-syntax-to-top-form', 'expand-to-top-form',
  191. 'expand-user-path', 'expt', 'file-exists?',
  192. 'file-or-directory-identity', 'file-or-directory-modify-seconds',
  193. 'file-or-directory-permissions', 'file-position', 'file-size',
  194. 'file-stream-buffer-mode', 'file-stream-port?',
  195. 'filesystem-root-list', 'find-executable-path',
  196. 'find-library-collection-paths', 'find-system-path', 'fixnum?',
  197. 'floating-point-bytes->real', 'flonum?', 'floor', 'flush-output',
  198. 'for-each', 'force', 'format', 'fprintf', 'free-identifier=?',
  199. 'gcd', 'generate-temporaries', 'gensym', 'get-output-bytes',
  200. 'get-output-string', 'getenv', 'global-port-print-handler',
  201. 'guard-evt', 'handle-evt', 'handle-evt?', 'hash', 'hash-equal?',
  202. 'hash-eqv?', 'hash-has-key?', 'hash-placeholder?', 'hash-ref!',
  203. 'hasheq', 'hasheqv', 'identifier-binding',
  204. 'identifier-label-binding', 'identifier-prune-lexical-context',
  205. 'identifier-prune-to-source-module',
  206. 'identifier-remove-from-definition-context',
  207. 'identifier-template-binding', 'identifier-transformer-binding',
  208. 'identifier?', 'imag-part', 'immutable?', 'impersonate-box',
  209. 'impersonate-hash', 'impersonate-procedure', 'impersonate-struct',
  210. 'impersonate-vector', 'impersonator-of?',
  211. 'impersonator-prop:application-mark',
  212. 'impersonator-property-accessor-procedure?',
  213. 'impersonator-property?', 'impersonator?', 'inexact->exact',
  214. 'inexact-real?', 'inexact?', 'input-port?', 'inspector?',
  215. 'integer->char', 'integer->integer-bytes',
  216. 'integer-bytes->integer', 'integer-length', 'integer-sqrt',
  217. 'integer-sqrt/remainder', 'integer?',
  218. 'internal-definition-context-seal', 'internal-definition-context?',
  219. 'keyword->string', 'keyword<?', 'keyword?', 'kill-thread', 'lcm',
  220. 'length', 'liberal-define-context?', 'link-exists?', 'list',
  221. 'list*', 'list->bytes', 'list->string', 'list->vector', 'list-ref',
  222. 'list-tail', 'list?', 'load', 'load-extension',
  223. 'load-on-demand-enabled', 'load-relative',
  224. 'load-relative-extension', 'load/cd', 'load/use-compiled',
  225. 'local-expand', 'local-expand/capture-lifts',
  226. 'local-transformer-expand',
  227. 'local-transformer-expand/capture-lifts', 'locale-string-encoding',
  228. 'log', 'magnitude', 'make-arity-at-least', 'make-bytes',
  229. 'make-channel', 'make-continuation-prompt-tag', 'make-custodian',
  230. 'make-custodian-box', 'make-date', 'make-date*',
  231. 'make-derived-parameter', 'make-directory', 'make-ephemeron',
  232. 'make-exn', 'make-exn:break', 'make-exn:fail',
  233. 'make-exn:fail:contract', 'make-exn:fail:contract:arity',
  234. 'make-exn:fail:contract:continuation',
  235. 'make-exn:fail:contract:divide-by-zero',
  236. 'make-exn:fail:contract:non-fixnum-result',
  237. 'make-exn:fail:contract:variable', 'make-exn:fail:filesystem',
  238. 'make-exn:fail:filesystem:exists',
  239. 'make-exn:fail:filesystem:version', 'make-exn:fail:network',
  240. 'make-exn:fail:out-of-memory', 'make-exn:fail:read',
  241. 'make-exn:fail:read:eof', 'make-exn:fail:read:non-char',
  242. 'make-exn:fail:syntax', 'make-exn:fail:syntax:unbound',
  243. 'make-exn:fail:unsupported', 'make-exn:fail:user',
  244. 'make-file-or-directory-link', 'make-hash-placeholder',
  245. 'make-hasheq-placeholder', 'make-hasheqv',
  246. 'make-hasheqv-placeholder', 'make-immutable-hasheqv',
  247. 'make-impersonator-property', 'make-input-port', 'make-inspector',
  248. 'make-known-char-range-list', 'make-output-port', 'make-parameter',
  249. 'make-pipe', 'make-placeholder', 'make-polar',
  250. 'make-prefab-struct', 'make-pseudo-random-generator',
  251. 'make-reader-graph', 'make-readtable', 'make-rectangular',
  252. 'make-rename-transformer', 'make-resolved-module-path',
  253. 'make-security-guard', 'make-semaphore', 'make-set!-transformer',
  254. 'make-shared-bytes', 'make-sibling-inspector',
  255. 'make-special-comment', 'make-srcloc', 'make-string',
  256. 'make-struct-field-accessor', 'make-struct-field-mutator',
  257. 'make-struct-type', 'make-struct-type-property',
  258. 'make-syntax-delta-introducer', 'make-syntax-introducer',
  259. 'make-thread-cell', 'make-thread-group', 'make-vector',
  260. 'make-weak-box', 'make-weak-hasheqv', 'make-will-executor', 'map',
  261. 'max', 'mcar', 'mcdr', 'mcons', 'member', 'memq', 'memv', 'min',
  262. 'module->exports', 'module->imports', 'module->language-info',
  263. 'module->namespace', 'module-compiled-exports',
  264. 'module-compiled-imports', 'module-compiled-language-info',
  265. 'module-compiled-name', 'module-path-index-join',
  266. 'module-path-index-resolve', 'module-path-index-split',
  267. 'module-path-index?', 'module-path?', 'module-predefined?',
  268. 'module-provide-protected?', 'modulo', 'mpair?', 'nack-guard-evt',
  269. 'namespace-attach-module', 'namespace-attach-module-declaration',
  270. 'namespace-base-phase', 'namespace-mapped-symbols',
  271. 'namespace-module-identifier', 'namespace-module-registry',
  272. 'namespace-require', 'namespace-require/constant',
  273. 'namespace-require/copy', 'namespace-require/expansion-time',
  274. 'namespace-set-variable-value!', 'namespace-symbol->identifier',
  275. 'namespace-syntax-introduce', 'namespace-undefine-variable!',
  276. 'namespace-unprotect-module', 'namespace-variable-value',
  277. 'namespace?', 'negative?', 'never-evt', 'newline',
  278. 'normal-case-path', 'not', 'null', 'null?', 'number->string',
  279. 'number?', 'numerator', 'object-name', 'odd?', 'open-input-bytes',
  280. 'open-input-file', 'open-input-output-file', 'open-input-string',
  281. 'open-output-bytes', 'open-output-file', 'open-output-string',
  282. 'ormap', 'output-port?', 'pair?', 'parameter-procedure=?',
  283. 'parameter?', 'parameterization?', 'path->bytes',
  284. 'path->complete-path', 'path->directory-path', 'path->string',
  285. 'path-add-suffix', 'path-convention-type', 'path-element->bytes',
  286. 'path-element->string', 'path-for-some-system?',
  287. 'path-list-string->path-list', 'path-replace-suffix',
  288. 'path-string?', 'path?', 'peek-byte', 'peek-byte-or-special',
  289. 'peek-bytes', 'peek-bytes!', 'peek-bytes-avail!',
  290. 'peek-bytes-avail!*', 'peek-bytes-avail!/enable-break',
  291. 'peek-char', 'peek-char-or-special', 'peek-string', 'peek-string!',
  292. 'pipe-content-length', 'placeholder-get', 'placeholder-set!',
  293. 'placeholder?', 'poll-guard-evt', 'port-closed-evt',
  294. 'port-closed?', 'port-commit-peeked', 'port-count-lines!',
  295. 'port-count-lines-enabled', 'port-display-handler',
  296. 'port-file-identity', 'port-file-unlock', 'port-next-location',
  297. 'port-print-handler', 'port-progress-evt',
  298. 'port-provides-progress-evts?', 'port-read-handler',
  299. 'port-try-file-lock?', 'port-write-handler', 'port-writes-atomic?',
  300. 'port-writes-special?', 'port?', 'positive?',
  301. 'prefab-key->struct-type', 'prefab-struct-key', 'pregexp',
  302. 'pregexp?', 'primitive-closure?', 'primitive-result-arity',
  303. 'primitive?', 'print', 'print-as-expression',
  304. 'print-boolean-long-form', 'print-box', 'print-graph',
  305. 'print-hash-table', 'print-mpair-curly-braces',
  306. 'print-pair-curly-braces', 'print-reader-abbreviations',
  307. 'print-struct', 'print-syntax-width', 'print-unreadable',
  308. 'print-vector-length', 'printf', 'procedure->method',
  309. 'procedure-arity', 'procedure-arity-includes?', 'procedure-arity?',
  310. 'procedure-closure-contents-eq?', 'procedure-extract-target',
  311. 'procedure-reduce-arity', 'procedure-rename',
  312. 'procedure-struct-type?', 'procedure?', 'promise?',
  313. 'prop:arity-string', 'prop:checked-procedure',
  314. 'prop:custom-print-quotable', 'prop:custom-write',
  315. 'prop:equal+hash', 'prop:evt', 'prop:exn:srclocs',
  316. 'prop:impersonator-of', 'prop:input-port',
  317. 'prop:liberal-define-context', 'prop:output-port',
  318. 'prop:procedure', 'prop:rename-transformer',
  319. 'prop:set!-transformer', 'pseudo-random-generator->vector',
  320. 'pseudo-random-generator-vector?', 'pseudo-random-generator?',
  321. 'putenv', 'quotient', 'quotient/remainder', 'raise',
  322. 'raise-arity-error', 'raise-mismatch-error', 'raise-syntax-error',
  323. 'raise-type-error', 'raise-user-error', 'random', 'random-seed',
  324. 'rational?', 'rationalize', 'read', 'read-accept-bar-quote',
  325. 'read-accept-box', 'read-accept-compiled', 'read-accept-dot',
  326. 'read-accept-graph', 'read-accept-infix-dot', 'read-accept-lang',
  327. 'read-accept-quasiquote', 'read-accept-reader', 'read-byte',
  328. 'read-byte-or-special', 'read-bytes', 'read-bytes!',
  329. 'read-bytes-avail!', 'read-bytes-avail!*',
  330. 'read-bytes-avail!/enable-break', 'read-bytes-line',
  331. 'read-case-sensitive', 'read-char', 'read-char-or-special',
  332. 'read-curly-brace-as-paren', 'read-decimal-as-inexact',
  333. 'read-eval-print-loop', 'read-language', 'read-line',
  334. 'read-on-demand-source', 'read-square-bracket-as-paren',
  335. 'read-string', 'read-string!', 'read-syntax',
  336. 'read-syntax/recursive', 'read/recursive', 'readtable-mapping',
  337. 'readtable?', 'real->double-flonum', 'real->floating-point-bytes',
  338. 'real->single-flonum', 'real-part', 'real?', 'regexp',
  339. 'regexp-match', 'regexp-match-peek', 'regexp-match-peek-immediate',
  340. 'regexp-match-peek-positions',
  341. 'regexp-match-peek-positions-immediate',
  342. 'regexp-match-peek-positions-immediate/end',
  343. 'regexp-match-peek-positions/end', 'regexp-match-positions',
  344. 'regexp-match-positions/end', 'regexp-match/end', 'regexp-match?',
  345. 'regexp-max-lookbehind', 'regexp-replace', 'regexp-replace*',
  346. 'regexp?', 'relative-path?', 'remainder',
  347. 'rename-file-or-directory', 'rename-transformer-target',
  348. 'rename-transformer?', 'resolve-path', 'resolved-module-path-name',
  349. 'resolved-module-path?', 'reverse', 'round', 'seconds->date',
  350. 'security-guard?', 'semaphore-peek-evt', 'semaphore-post',
  351. 'semaphore-try-wait?', 'semaphore-wait',
  352. 'semaphore-wait/enable-break', 'semaphore?',
  353. 'set!-transformer-procedure', 'set!-transformer?', 'set-box!',
  354. 'set-mcar!', 'set-mcdr!', 'set-port-next-location!',
  355. 'shared-bytes', 'shell-execute', 'simplify-path', 'sin',
  356. 'single-flonum?', 'sleep', 'special-comment-value',
  357. 'special-comment?', 'split-path', 'sqrt', 'srcloc',
  358. 'srcloc-column', 'srcloc-line', 'srcloc-position', 'srcloc-source',
  359. 'srcloc-span', 'srcloc?', 'string', 'string->bytes/latin-1',
  360. 'string->bytes/locale', 'string->bytes/utf-8',
  361. 'string->immutable-string', 'string->keyword', 'string->list',
  362. 'string->number', 'string->path', 'string->path-element',
  363. 'string->symbol', 'string->uninterned-symbol',
  364. 'string->unreadable-symbol', 'string-append', 'string-ci<=?',
  365. 'string-ci<?', 'string-ci=?', 'string-ci>=?', 'string-ci>?',
  366. 'string-copy', 'string-copy!', 'string-downcase', 'string-fill!',
  367. 'string-foldcase', 'string-length', 'string-locale-ci<?',
  368. 'string-locale-ci=?', 'string-locale-ci>?',
  369. 'string-locale-downcase', 'string-locale-upcase',
  370. 'string-locale<?', 'string-locale=?', 'string-locale>?',
  371. 'string-normalize-nfc', 'string-normalize-nfd',
  372. 'string-normalize-nfkc', 'string-normalize-nfkd', 'string-ref',
  373. 'string-set!', 'string-titlecase', 'string-upcase',
  374. 'string-utf-8-length', 'string<=?', 'string<?', 'string=?',
  375. 'string>=?', 'string>?', 'string?', 'struct->vector',
  376. 'struct-accessor-procedure?', 'struct-constructor-procedure?',
  377. 'struct-info', 'struct-mutator-procedure?',
  378. 'struct-predicate-procedure?', 'struct-type-info',
  379. 'struct-type-make-constructor', 'struct-type-make-predicate',
  380. 'struct-type-property-accessor-procedure?',
  381. 'struct-type-property?', 'struct-type?', 'struct:arity-at-least',
  382. 'struct:date', 'struct:date*', 'struct:exn', 'struct:exn:break',
  383. 'struct:exn:fail', 'struct:exn:fail:contract',
  384. 'struct:exn:fail:contract:arity',
  385. 'struct:exn:fail:contract:continuation',
  386. 'struct:exn:fail:contract:divide-by-zero',
  387. 'struct:exn:fail:contract:non-fixnum-result',
  388. 'struct:exn:fail:contract:variable', 'struct:exn:fail:filesystem',
  389. 'struct:exn:fail:filesystem:exists',
  390. 'struct:exn:fail:filesystem:version', 'struct:exn:fail:network',
  391. 'struct:exn:fail:out-of-memory', 'struct:exn:fail:read',
  392. 'struct:exn:fail:read:eof', 'struct:exn:fail:read:non-char',
  393. 'struct:exn:fail:syntax', 'struct:exn:fail:syntax:unbound',
  394. 'struct:exn:fail:unsupported', 'struct:exn:fail:user',
  395. 'struct:srcloc', 'struct?', 'sub1', 'subbytes', 'subprocess',
  396. 'subprocess-group-enabled', 'subprocess-kill', 'subprocess-pid',
  397. 'subprocess-status', 'subprocess-wait', 'subprocess?', 'substring',
  398. 'symbol->string', 'symbol-interned?', 'symbol-unreadable?',
  399. 'symbol?', 'sync', 'sync/enable-break', 'sync/timeout',
  400. 'sync/timeout/enable-break', 'syntax->list', 'syntax-arm',
  401. 'syntax-column', 'syntax-disarm', 'syntax-e', 'syntax-line',
  402. 'syntax-local-bind-syntaxes', 'syntax-local-certifier',
  403. 'syntax-local-context', 'syntax-local-expand-expression',
  404. 'syntax-local-get-shadower', 'syntax-local-introduce',
  405. 'syntax-local-lift-context', 'syntax-local-lift-expression',
  406. 'syntax-local-lift-module-end-declaration',
  407. 'syntax-local-lift-provide', 'syntax-local-lift-require',
  408. 'syntax-local-lift-values-expression',
  409. 'syntax-local-make-definition-context',
  410. 'syntax-local-make-delta-introducer',
  411. 'syntax-local-module-defined-identifiers',
  412. 'syntax-local-module-exports',
  413. 'syntax-local-module-required-identifiers', 'syntax-local-name',
  414. 'syntax-local-phase-level',
  415. 'syntax-local-transforming-module-provides?', 'syntax-local-value',
  416. 'syntax-local-value/immediate', 'syntax-original?',
  417. 'syntax-position', 'syntax-property',
  418. 'syntax-property-symbol-keys', 'syntax-protect', 'syntax-rearm',
  419. 'syntax-recertify', 'syntax-shift-phase-level', 'syntax-source',
  420. 'syntax-source-module', 'syntax-span', 'syntax-taint',
  421. 'syntax-tainted?', 'syntax-track-origin',
  422. 'syntax-transforming-module-expression?', 'syntax-transforming?',
  423. 'syntax?', 'system-big-endian?', 'system-idle-evt',
  424. 'system-language+country', 'system-library-subpath',
  425. 'system-path-convention-type', 'system-type', 'tan',
  426. 'tcp-abandon-port', 'tcp-accept', 'tcp-accept-evt',
  427. 'tcp-accept-ready?', 'tcp-accept/enable-break', 'tcp-addresses',
  428. 'tcp-close', 'tcp-connect', 'tcp-connect/enable-break',
  429. 'tcp-listen', 'tcp-listener?', 'tcp-port?', 'terminal-port?',
  430. 'thread', 'thread-cell-ref', 'thread-cell-set!', 'thread-cell?',
  431. 'thread-dead-evt', 'thread-dead?', 'thread-group?',
  432. 'thread-resume', 'thread-resume-evt', 'thread-rewind-receive',
  433. 'thread-running?', 'thread-suspend', 'thread-suspend-evt',
  434. 'thread-wait', 'thread/suspend-to-kill', 'thread?', 'time-apply',
  435. 'truncate', 'udp-addresses', 'udp-bind!', 'udp-bound?',
  436. 'udp-close', 'udp-connect!', 'udp-connected?', 'udp-open-socket',
  437. 'udp-receive!', 'udp-receive!*', 'udp-receive!-evt',
  438. 'udp-receive!/enable-break', 'udp-receive-ready-evt', 'udp-send',
  439. 'udp-send*', 'udp-send-evt', 'udp-send-ready-evt', 'udp-send-to',
  440. 'udp-send-to*', 'udp-send-to-evt', 'udp-send-to/enable-break',
  441. 'udp-send/enable-break', 'udp?', 'unbox',
  442. 'uncaught-exception-handler', 'use-collection-link-paths',
  443. 'use-compiled-file-paths', 'use-user-specific-search-paths',
  444. 'values', 'variable-reference->empty-namespace',
  445. 'variable-reference->module-base-phase',
  446. 'variable-reference->module-declaration-inspector',
  447. 'variable-reference->module-source',
  448. 'variable-reference->namespace', 'variable-reference->phase',
  449. 'variable-reference->resolved-module-path',
  450. 'variable-reference-constant?', 'variable-reference?', 'vector',
  451. 'vector->immutable-vector', 'vector->list',
  452. 'vector->pseudo-random-generator',
  453. 'vector->pseudo-random-generator!', 'vector->values',
  454. 'vector-fill!', 'vector-immutable', 'vector-length', 'vector-ref',
  455. 'vector-set!', 'vector-set-performance-stats!', 'vector?',
  456. 'version', 'void', 'void?', 'weak-box-value', 'weak-box?',
  457. 'will-execute', 'will-executor?', 'will-register',
  458. 'will-try-execute', 'with-input-from-file', 'with-output-to-file',
  459. 'wrap-evt', 'write', 'write-byte', 'write-bytes',
  460. 'write-bytes-avail', 'write-bytes-avail*', 'write-bytes-avail-evt',
  461. 'write-bytes-avail/enable-break', 'write-char', 'write-special',
  462. 'write-special-avail*', 'write-special-evt', 'write-string', 'zero?'
  463. ]
  464. # From SchemeLexer
  465. valid_name = r'[a-zA-Z0-9!$%&*+,/:<=>?@^_~|-]+'
  466. tokens = {
  467. 'root' : [
  468. (r';.*$', Comment.Single),
  469. (r'#\|[^|]+\|#', Comment.Multiline),
  470. # whitespaces - usually not relevant
  471. (r'\s+', Text),
  472. ## numbers: Keep in mind Racket reader hash prefixes,
  473. ## which can denote the base or the type. These don't map
  474. ## neatly onto pygments token types; some judgment calls
  475. ## here. Note that none of these regexps attempt to
  476. ## exclude identifiers that start with a number, such as a
  477. ## variable named "100-Continue".
  478. # #b
  479. (r'#b[-+]?[01]+\.[01]+', Number.Float),
  480. (r'#b[01]+e[-+]?[01]+', Number.Float),
  481. (r'#b[-+]?[01]/[01]+', Number),
  482. (r'#b[-+]?[01]+', Number.Integer),
  483. (r'#b\S*', Error),
  484. # #d OR no hash prefix
  485. (r'(#d)?[-+]?\d+\.\d+', Number.Float),
  486. (r'(#d)?\d+e[-+]?\d+', Number.Float),
  487. (r'(#d)?[-+]?\d+/\d+', Number),
  488. (r'(#d)?[-+]?\d+', Number.Integer),
  489. (r'#d\S*', Error),
  490. # #e
  491. (r'#e[-+]?\d+\.\d+', Number.Float),
  492. (r'#e\d+e[-+]?\d+', Number.Float),
  493. (r'#e[-+]?\d+/\d+', Number),
  494. (r'#e[-+]?\d+', Number),
  495. (r'#e\S*', Error),
  496. # #i is always inexact-real, i.e. float
  497. (r'#i[-+]?\d+\.\d+', Number.Float),
  498. (r'#i\d+e[-+]?\d+', Number.Float),
  499. (r'#i[-+]?\d+/\d+', Number.Float),
  500. (r'#i[-+]?\d+', Number.Float),
  501. (r'#i\S*', Error),
  502. # #o
  503. (r'#o[-+]?[0-7]+\.[0-7]+', Number.Oct),
  504. (r'#o[0-7]+e[-+]?[0-7]+', Number.Oct),
  505. (r'#o[-+]?[0-7]+/[0-7]+', Number.Oct),
  506. (r'#o[-+]?[0-7]+', Number.Oct),
  507. (r'#o\S*', Error),
  508. # #x
  509. (r'#x[-+]?[0-9a-fA-F]+\.[0-9a-fA-F]+', Number.Hex),
  510. # the exponent variation (e.g. #x1e1) is N/A
  511. (r'#x[-+]?[0-9a-fA-F]+/[0-9a-fA-F]+', Number.Hex),
  512. (r'#x[-+]?[0-9a-fA-F]+', Number.Hex),
  513. (r'#x\S*', Error),
  514. # strings, symbols and characters
  515. (r'"(\\\\|\\"|[^"])*"', String),
  516. (r"'" + valid_name, String.Symbol),
  517. (r"#\\([()/'\"._!§$%& ?=+-]{1}|[a-zA-Z0-9]+)", String.Char),
  518. (r'#rx".+"', String.Regex),
  519. (r'#px".+"', String.Regex),
  520. # constants
  521. (r'(#t|#f)', Name.Constant),
  522. # keyword argument names (e.g. #:keyword)
  523. (r'#:\S+', Keyword.Declaration),
  524. # #lang
  525. (r'#lang \S+', Keyword.Namespace),
  526. # special operators
  527. (r"('|#|`|,@|,|\.)", Operator),
  528. # highlight the keywords
  529. ('(%s)' % '|'.join([
  530. re.escape(entry) + ' ' for entry in keywords]),
  531. Keyword
  532. ),
  533. # first variable in a quoted string like
  534. # '(this is syntactic sugar)
  535. (r"(?<='\()" + valid_name, Name.Variable),
  536. (r"(?<=#\()" + valid_name, Name.Variable),
  537. # highlight the builtins
  538. ("(?<=\()(%s)" % '|'.join([
  539. re.escape(entry) + ' ' for entry in builtins]),
  540. Name.Builtin
  541. ),
  542. # the remaining functions; handle both ( and [
  543. (r'(?<=(\(|\[|\{))' + valid_name, Name.Function),
  544. # find the remaining variables
  545. (valid_name, Name.Variable),
  546. # the famous parentheses!
  547. (r'(\(|\)|\[|\]|\{|\})', Punctuation),
  548. ],
  549. }
  550. class SchemeLexer(RegexLexer):
  551. """
  552. A Scheme lexer, parsing a stream and outputting the tokens
  553. needed to highlight scheme code.
  554. This lexer could be most probably easily subclassed to parse
  555. other LISP-Dialects like Common Lisp, Emacs Lisp or AutoLisp.
  556. This parser is checked with pastes from the LISP pastebin
  557. at http://paste.lisp.org/ to cover as much syntax as possible.
  558. It supports the full Scheme syntax as defined in R5RS.
  559. *New in Pygments 0.6.*
  560. """
  561. name = 'Scheme'
  562. aliases = ['scheme', 'scm']
  563. filenames = ['*.scm', '*.ss']
  564. mimetypes = ['text/x-scheme', 'application/x-scheme']
  565. # list of known keywords and builtins taken form vim 6.4 scheme.vim
  566. # syntax file.
  567. keywords = [
  568. 'lambda', 'define', 'if', 'else', 'cond', 'and', 'or', 'case', 'let',
  569. 'let*', 'letrec', 'begin', 'do', 'delay', 'set!', '=>', 'quote',
  570. 'quasiquote', 'unquote', 'unquote-splicing', 'define-syntax',
  571. 'let-syntax', 'letrec-syntax', 'syntax-rules'
  572. ]
  573. builtins = [
  574. '*', '+', '-', '/', '<', '<=', '=', '>', '>=', 'abs', 'acos', 'angle',
  575. 'append', 'apply', 'asin', 'assoc', 'assq', 'assv', 'atan',
  576. 'boolean?', 'caaaar', 'caaadr', 'caaar', 'caadar', 'caaddr', 'caadr',
  577. 'caar', 'cadaar', 'cadadr', 'cadar', 'caddar', 'cadddr', 'caddr',
  578. 'cadr', 'call-with-current-continuation', 'call-with-input-file',
  579. 'call-with-output-file', 'call-with-values', 'call/cc', 'car',
  580. 'cdaaar', 'cdaadr', 'cdaar', 'cdadar', 'cdaddr', 'cdadr', 'cdar',
  581. 'cddaar', 'cddadr', 'cddar', 'cdddar', 'cddddr', 'cdddr', 'cddr',
  582. 'cdr', 'ceiling', 'char->integer', 'char-alphabetic?', 'char-ci<=?',
  583. 'char-ci<?', 'char-ci=?', 'char-ci>=?', 'char-ci>?', 'char-downcase',
  584. 'char-lower-case?', 'char-numeric?', 'char-ready?', 'char-upcase',
  585. 'char-upper-case?', 'char-whitespace?', 'char<=?', 'char<?', 'char=?',
  586. 'char>=?', 'char>?', 'char?', 'close-input-port', 'close-output-port',
  587. 'complex?', 'cons', 'cos', 'current-input-port', 'current-output-port',
  588. 'denominator', 'display', 'dynamic-wind', 'eof-object?', 'eq?',
  589. 'equal?', 'eqv?', 'eval', 'even?', 'exact->inexact', 'exact?', 'exp',
  590. 'expt', 'floor', 'for-each', 'force', 'gcd', 'imag-part',
  591. 'inexact->exact', 'inexact?', 'input-port?', 'integer->char',
  592. 'integer?', 'interaction-environment', 'lcm', 'length', 'list',
  593. 'list->string', 'list->vector', 'list-ref', 'list-tail', 'list?',
  594. 'load', 'log', 'magnitude', 'make-polar', 'make-rectangular',
  595. 'make-string', 'make-vector', 'map', 'max', 'member', 'memq', 'memv',
  596. 'min', 'modulo', 'negative?', 'newline', 'not', 'null-environment',
  597. 'null?', 'number->string', 'number?', 'numerator', 'odd?',
  598. 'open-input-file', 'open-output-file', 'output-port?', 'pair?',
  599. 'peek-char', 'port?', 'positive?', 'procedure?', 'quotient',
  600. 'rational?', 'rationalize', 'read', 'read-char', 'real-part', 'real?',
  601. 'remainder', 'reverse', 'round', 'scheme-report-environment',
  602. 'set-car!', 'set-cdr!', 'sin', 'sqrt', 'string', 'string->list',
  603. 'string->number', 'string->symbol', 'string-append', 'string-ci<=?',
  604. 'string-ci<?', 'string-ci=?', 'string-ci>=?', 'string-ci>?',
  605. 'string-copy', 'string-fill!', 'string-length', 'string-ref',
  606. 'string-set!', 'string<=?', 'string<?', 'string=?', 'string>=?',
  607. 'string>?', 'string?', 'substring', 'symbol->string', 'symbol?',
  608. 'tan', 'transcript-off', 'transcript-on', 'truncate', 'values',
  609. 'vector', 'vector->list', 'vector-fill!', 'vector-length',
  610. 'vector-ref', 'vector-set!', 'vector?', 'with-input-from-file',
  611. 'with-output-to-file', 'write', 'write-char', 'zero?'
  612. ]
  613. # valid names for identifiers
  614. # well, names can only not consist fully of numbers
  615. # but this should be good enough for now
  616. valid_name = r'[a-zA-Z0-9!$%&*+,/:<=>?@^_~|-]+'
  617. tokens = {
  618. 'root' : [
  619. # the comments - always starting with semicolon
  620. # and going to the end of the line
  621. (r';.*$', Comment.Single),
  622. # whitespaces - usually not relevant
  623. (r'\s+', Text),
  624. # numbers
  625. (r'-?\d+\.\d+', Number.Float),
  626. (r'-?\d+', Number.Integer),
  627. # support for uncommon kinds of numbers -
  628. # have to figure out what the characters mean
  629. #(r'(#e|#i|#b|#o|#d|#x)[\d.]+', Number),
  630. # strings, symbols and characters
  631. (r'"(\\\\|\\"|[^"])*"', String),
  632. (r"'" + valid_name, String.Symbol),
  633. (r"#\\([()/'\"._!§$%& ?=+-]{1}|[a-zA-Z0-9]+)", String.Char),
  634. # constants
  635. (r'(#t|#f)', Name.Constant),
  636. # special operators
  637. (r"('|#|`|,@|,|\.)", Operator),
  638. # highlight the keywords
  639. ('(%s)' % '|'.join([
  640. re.escape(entry) + ' ' for entry in keywords]),
  641. Keyword
  642. ),
  643. # first variable in a quoted string like
  644. # '(this is syntactic sugar)
  645. (r"(?<='\()" + valid_name, Name.Variable),
  646. (r"(?<=#\()" + valid_name, Name.Variable),
  647. # highlight the builtins
  648. ("(?<=\()(%s)" % '|'.join([
  649. re.escape(entry) + ' ' for entry in builtins]),
  650. Name.Builtin
  651. ),
  652. # the remaining functions
  653. (r'(?<=\()' + valid_name, Name.Function),
  654. # find the remaining variables
  655. (valid_name, Name.Variable),
  656. # the famous parentheses!
  657. (r'(\(|\))', Punctuation),
  658. (r'(\[|\])', Punctuation),
  659. ],
  660. }
  661. class CommonLispLexer(RegexLexer):
  662. """
  663. A Common Lisp lexer.
  664. *New in Pygments 0.9.*
  665. """
  666. name = 'Common Lisp'
  667. aliases = ['common-lisp', 'cl']
  668. filenames = ['*.cl', '*.lisp', '*.el'] # use for Elisp too
  669. mimetypes = ['text/x-common-lisp']
  670. flags = re.IGNORECASE | re.MULTILINE
  671. ### couple of useful regexes
  672. # characters that are not macro-characters and can be used to begin a symbol
  673. nonmacro = r'\\.|[a-zA-Z0-9!$%&*+-/<=>?@\[\]^_{}~]'
  674. constituent = nonmacro + '|[#.:]'
  675. terminated = r'(?=[ "()\'\n,;`])' # whitespace or terminating macro characters
  676. ### symbol token, reverse-engineered from hyperspec
  677. # Take a deep breath...
  678. symbol = r'(\|[^|]+\||(?:%s)(?:%s)*)' % (nonmacro, constituent)
  679. def __init__(self, **options):
  680. from pygments.lexers._clbuiltins import BUILTIN_FUNCTIONS, \
  681. SPECIAL_FORMS, MACROS, LAMBDA_LIST_KEYWORDS, DECLARATIONS, \
  682. BUILTIN_TYPES, BUILTIN_CLASSES
  683. self.builtin_function = BUILTIN_FUNCTIONS
  684. self.special_forms = SPECIAL_FORMS
  685. self.macros = MACROS
  686. self.lambda_list_keywords = LAMBDA_LIST_KEYWORDS
  687. self.declarations = DECLARATIONS
  688. self.builtin_types = BUILTIN_TYPES
  689. self.builtin_classes = BUILTIN_CLASSES
  690. RegexLexer.__init__(self, **options)
  691. def get_tokens_unprocessed(self, text):
  692. stack = ['root']
  693. for index, token, value in RegexLexer.get_tokens_unprocessed(self, text, stack):
  694. if token is Name.Variable:
  695. if value in self.builtin_function:
  696. yield index, Name.Builtin, value
  697. continue
  698. if value in self.special_forms:
  699. yield index, Keyword, value
  700. continue
  701. if value in self.macros:
  702. yield index, Name.Builtin, value
  703. continue
  704. if value in self.lambda_list_keywords:
  705. yield index, Keyword, value
  706. continue
  707. if value in self.declarations:
  708. yield index, Keyword, value
  709. continue
  710. if value in self.builtin_types:
  711. yield index, Keyword.Type, value
  712. continue
  713. if value in self.builtin_classes:
  714. yield index, Name.Class, value
  715. continue
  716. yield index, token, value
  717. tokens = {
  718. 'root' : [
  719. ('', Text, 'body'),
  720. ],
  721. 'multiline-comment' : [
  722. (r'#\|', Comment.Multiline, '#push'), # (cf. Hyperspec 2.4.8.19)
  723. (r'\|#', Comment.Multiline, '#pop'),
  724. (r'[^|#]+', Comment.Multiline),
  725. (r'[|#]', Comment.Multiline),
  726. ],
  727. 'commented-form' : [
  728. (r'\(', Comment.Preproc, '#push'),
  729. (r'\)', Comment.Preproc, '#pop'),
  730. (r'[^()]+', Comment.Preproc),
  731. ],
  732. 'body' : [
  733. # whitespace
  734. (r'\s+', Text),
  735. # single-line comment
  736. (r';.*$', Comment.Single),
  737. # multi-line comment
  738. (r'#\|', Comment.Multiline, 'multiline-comment'),
  739. # encoding comment (?)
  740. (r'#\d*Y.*$', Comment.Special),
  741. # strings and characters
  742. (r'"(\\.|\\\n|[^"\\])*"', String),
  743. # quoting
  744. (r":" + symbol, String.Symbol),
  745. (r"'" + symbol, String.Symbol),
  746. (r"'", Operator),
  747. (r"`", Operator),
  748. # decimal numbers
  749. (r'[-+]?\d+\.?' + terminated, Number.Integer),
  750. (r'[-+]?\d+/\d+' + terminated, Number),
  751. (r'[-+]?(\d*\.\d+([defls][-+]?\d+)?|\d+(\.\d*)?[defls][-+]?\d+)' \
  752. + terminated, Number.Float),
  753. # sharpsign strings and characters
  754. (r"#\\." + terminated, String.Char),
  755. (r"#\\" + symbol, String.Char),
  756. # vector
  757. (r'#\(', Operator, 'body'),
  758. # bitstring
  759. (r'#\d*\*[01]*', Literal.Other),
  760. # uninterned symbol
  761. (r'#:' + symbol, String.Symbol),
  762. # read-time and load-time evaluation
  763. (r'#[.,]', Operator),
  764. # function shorthand
  765. (r'#\'', Name.Function),
  766. # binary rational
  767. (r'#[bB][+-]?[01]+(/[01]+)?', Number),
  768. # octal rational
  769. (r'#[oO][+-]?[0-7]+(/[0-7]+)?', Number.Oct),
  770. # hex rational
  771. (r'#[xX][+-]?[0-9a-fA-F]+(/[0-9a-fA-F]+)?', Number.Hex),
  772. # radix rational
  773. (r'#\d+[rR][+-]?[0-9a-zA-Z]+(/[0-9a-zA-Z]+)?', Number),
  774. # complex
  775. (r'(#[cC])(\()', bygroups(Number, Punctuation), 'body'),
  776. # array
  777. (r'(#\d+[aA])(\()', bygroups(Literal.Other, Punctuation), 'body'),
  778. # structure
  779. (r'(#[sS])(\()', bygroups(Literal.Other, Punctuation), 'body'),
  780. # path
  781. (r'#[pP]?"(\\.|[^"])*"', Literal.Other),
  782. # reference
  783. (r'#\d+=', Operator),
  784. (r'#\d+#', Operator),
  785. # read-time comment
  786. (r'#+nil' + terminated + '\s*\(', Comment.Preproc, 'commented-form'),
  787. # read-time conditional
  788. (r'#[+-]', Operator),
  789. # special operators that should have been parsed already
  790. (r'(,@|,|\.)', Operator),
  791. # special constants
  792. (r'(t|nil)' + terminated, Name.Constant),
  793. # functions and variables
  794. (r'\*' + symbol + '\*', Name.Variable.Global),
  795. (symbol, Name.Variable),
  796. # parentheses
  797. (r'\(', Punctuation, 'body'),
  798. (r'\)', Punctuation, '#pop'),
  799. ],
  800. }
  801. class HaskellLexer(RegexLexer):
  802. """
  803. A Haskell lexer based on the lexemes defined in the Haskell 98 Report.
  804. *New in Pygments 0.8.*
  805. """
  806. name = 'Haskell'
  807. aliases = ['haskell', 'hs']
  808. filenames = ['*.hs']
  809. mimetypes = ['text/x-haskell']
  810. reserved = ['case','class','data','default','deriving','do','else',
  811. 'if','in','infix[lr]?','instance',
  812. 'let','newtype','of','then','type','where','_']
  813. ascii = ['NUL','SOH','[SE]TX','EOT','ENQ','ACK',
  814. 'BEL','BS','HT','LF','VT','FF','CR','S[OI]','DLE',
  815. 'DC[1-4]','NAK','SYN','ETB','CAN',
  816. 'EM','SUB','ESC','[FGRU]S','SP','DEL']
  817. tokens = {
  818. 'root': [
  819. # Whitespace:
  820. (r'\s+', Text),
  821. #(r'--\s*|.*$', Comment.Doc),
  822. (r'--(?![!#$%&*+./<=>?@\^|_~:\\]).*?$', Comment.Single),
  823. (r'{-', Comment.Multiline, 'comment'),
  824. # Lexemes:
  825. # Identifiers
  826. (r'\bimport\b', Keyword.Reserved, 'import'),
  827. (r'\bmodule\b', Keyword.Reserved, 'module'),
  828. (r'\berror\b', Name.Exception),
  829. (r'\b(%s)(?!\')\b' % '|'.join(reserved), Keyword.Reserved),
  830. (r'^[_a-z][\w\']*', Name.Function),
  831. (r"'?[_a-z][\w']*", Name),
  832. (r"('')?[A-Z][\w\']*", Keyword.Type),
  833. # Operators
  834. (r'\\(?![:!#$%&*+.\\/<=>?@^|~-]+)', Name.Function), # lambda operator
  835. (r'(<-|::|->|=>|=)(?![:!#$%&*+.\\/<=>?@^|~-]+)', Operator.Word), # specials
  836. (r':[:!#$%&*+.\\/<=>?@^|~-]*', Keyword.Type), # Constructor operators
  837. (r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator), # Other operators
  838. # Numbers
  839. (r'\d+[eE][+-]?\d+', Number.Float),
  840. (r'\d+\.\d+([eE][+-]?\d+)?', Number.Float),
  841. (r'0[oO][0-7]+', Number.Oct),
  842. (r'0[xX][\da-fA-F]+', Number.Hex),
  843. (r'\d+', Number.Integer),
  844. # Character/String Literals
  845. (r"'", String.Char, 'character'),
  846. (r'"', String, 'string'),
  847. # Special
  848. (r'\[\]', Keyword.Type),
  849. (r'\(\)', Name.Builtin),
  850. (r'[][(),;`{}]', Punctuation),
  851. ],
  852. 'import': [
  853. # Import statements
  854. (r'\s+', Text),
  855. (r'"', String, 'string'),
  856. # after "funclist" state
  857. (r'\)', Punctuation, '#pop'),
  858. (r'qualified\b', Keyword),
  859. # import X as Y
  860. (r'([A-Z][a-zA-Z0-9_.]*)(\s+)(as)(\s+)([A-Z][a-zA-Z0-9_.]*)',
  861. bygroups(Name.Namespace, Text, Keyword, Text, Name), '#pop'),
  862. # import X hiding (functions)
  863. (r'([A-Z][a-zA-Z0-9_.]*)(\s+)(hiding)(\s+)(\()',
  864. bygroups(Name.Namespace, Text, Keyword, Text, Punctuation), 'funclist'),
  865. # import X (functions)
  866. (r'([A-Z][a-zA-Z0-9_.]*)(\s+)(\()',
  867. bygroups(Name.Namespace, Text, Punctuation), 'funclist'),
  868. # import X
  869. (r'[a-zA-Z0-9_.]+', Name.Namespace, '#pop'),
  870. ],
  871. 'module': [
  872. (r'\s+', Text),
  873. (r'([A-Z][a-zA-Z0-9_.]*)(\s+)(\()',
  874. bygroups(Name.Namespace, Text, Punctuation), 'funclist'),
  875. (r'[A-Z][a-zA-Z0-9_.]*', Name.Namespace, '#pop'),
  876. ],
  877. 'funclist': [
  878. (r'\s+', Text),
  879. (r'[A-Z][a-zA-Z0-9_]*', Keyword.Type),
  880. (r'(_[\w\']+|[a-z][\w\']*)', Name.Function),
  881. (r'--.*$', Comment.Single),
  882. (r'{-', Comment.Multiline, 'comment'),
  883. (r',', Punctuation),
  884. (r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator),
  885. # (HACK, but it makes sense to push two instances, believe me)
  886. (r'\(', Punctuation, ('funclist', 'funclist')),
  887. (r'\)', Punctuation, '#pop:2'),
  888. ],
  889. 'comment': [
  890. # Multiline Comments
  891. (r'[^-{}]+', Comment.Multiline),
  892. (r'{-', Comment.Multiline, '#push'),
  893. (r'-}', Comment.Multiline, '#pop'),
  894. (r'[-{}]', Comment.Multiline),
  895. ],
  896. 'character': [
  897. # Allows multi-chars, incorrectly.
  898. (r"[^\\']", String.Char),
  899. (r"\\", String.Escape, 'escape'),
  900. ("'", String.Char, '#pop'),
  901. ],
  902. 'string': [
  903. (r'[^\\"]+', String),
  904. (r"\\", String.Escape, 'escape'),
  905. ('"', String, '#pop'),
  906. ],
  907. 'escape': [
  908. (r'[abfnrtv"\'&\\]', String.Escape, '#pop'),
  909. (r'\^[][A-Z@\^_]', String.Escape, '#pop'),
  910. ('|'.join(ascii), String.Escape, '#pop'),
  911. (r'o[0-7]+', String.Escape, '#pop'),
  912. (r'x[\da-fA-F]+', String.Escape, '#pop'),
  913. (r'\d+', String.Escape, '#pop'),
  914. (r'\s+\\', String.Escape, '#pop'),
  915. ],
  916. }
  917. line_re = re.compile('.*?\n')
  918. bird_re = re.compile(r'(>[ \t]*)(.*\n)')
  919. class LiterateHaskellLexer(Lexer):
  920. """
  921. For Literate Haskell (Bird-style or LaTeX) source.
  922. Additional options accepted:
  923. `litstyle`
  924. If given, must be ``"bird"`` or ``"latex"``. If not given, the style
  925. is autodetected: if the first non-whitespace character in the source
  926. is a backslash or percent character, LaTeX is assumed, else Bird.
  927. *New in Pygments 0.9.*
  928. """
  929. name = 'Literate Haskell'
  930. aliases = ['lhs', 'literate-haskell']
  931. filenames = ['*.lhs']
  932. mimetypes = ['text/x-literate-haskell']
  933. def get_tokens_unprocessed(self, text):
  934. hslexer = HaskellLexer(**self.options)
  935. style = self.options.get('litstyle')
  936. if style is None:
  937. style = (text.lstrip()[0:1] in '%\\') and 'latex' or 'bird'
  938. code = ''
  939. insertions = []
  940. if style == 'bird':
  941. # bird-style
  942. for match in line_re.finditer(text):
  943. line = match.group()
  944. m = bird_re.match(line)
  945. if m:
  946. insertions.append((len(code),
  947. [(0, Comment.Special, m.group(1))]))
  948. code += m.group(2)
  949. else:
  950. insertions.append((len(code), [(0, Text, line)]))
  951. else:
  952. # latex-style
  953. from pygments.lexers.text import TexLexer
  954. lxlexer = TexLexer(**self.options)
  955. codelines = 0
  956. latex = ''
  957. for match in line_re.finditer(text):
  958. line = match.group()
  959. if codelines:
  960. if line.lstrip().startswith('\\end{code}'):
  961. codelines = 0
  962. latex += line
  963. else:
  964. code += line
  965. elif line.lstrip().startswith('\\begin{code}'):
  966. codelines = 1
  967. latex += line
  968. insertions.append((len(code),
  969. list(lxlexer.get_tokens_unprocessed(latex))))
  970. latex = ''
  971. else:
  972. latex += line
  973. insertions.append((len(code),
  974. list(lxlexer.get_tokens_unprocessed(latex))))
  975. for item in do_insertions(insertions, hslexer.get_tokens_unprocessed(code)):
  976. yield item
  977. class SMLLexer(RegexLexer):
  978. """
  979. For the Standard ML language.
  980. *New in Pygments 1.5.*
  981. """
  982. name = 'Standard ML'
  983. aliases = ['sml']
  984. filenames = ['*.sml', '*.sig', '*.fun',]
  985. mimetypes = ['text/x-standardml', 'application/x-standardml']
  986. alphanumid_reserved = [
  987. # Core
  988. 'abstype', 'and', 'andalso', 'as', 'case', 'datatype', 'do', 'else',
  989. 'end', 'exception', 'fn', 'fun', 'handle', 'if', 'in', 'infix',
  990. 'infixr', 'let', 'local', 'nonfix', 'of', 'op', 'open', 'orelse',
  991. 'raise', 'rec', 'then', 'type', 'val', 'with', 'withtype', 'while',
  992. # Modules
  993. 'eqtype', 'functor', 'include', 'sharing', 'sig', 'signature',
  994. 'struct', 'structure', 'where',
  995. ]
  996. symbolicid_reserved = [
  997. # Core
  998. ':', '\|', '=', '=>', '->', '#',
  999. # Modules
  1000. ':>',
  1001. ]
  1002. nonid_reserved = [ '(', ')', '[', ']', '{', '}', ',', ';', '...', '_' ]
  1003. alphanumid_re = r"[a-zA-Z][a-zA-Z0-9_']*"
  1004. symbolicid_re = r"[!%&$#+\-/:<=>?@\\~`^|*]+"
  1005. # A character constant is a sequence of the form #s, where s is a string
  1006. # constant denoting a string of size one character. This setup just parses
  1007. # the entire string as either a String.Double or a String.Char (depending
  1008. # on the argument), even if the String.Char is an erronous
  1009. # multiple-character string.
  1010. def stringy (whatkind):
  1011. return [
  1012. (r'[^"\\]', whatkind),
  1013. (r'\\[\\\"abtnvfr]', String.Escape),
  1014. # Control-character notation is used for codes < 32,
  1015. # where \^@ == \000
  1016. (r'\\\^[\x40-\x5e]', String.Escape),
  1017. # Docs say 'decimal digits'
  1018. (r'\\[0-9]{3}', String.Escape),
  1019. (r'\\u[0-9a-fA-F]{4}', String.Escape),
  1020. (r'\\\s+\\', String.Interpol),
  1021. (r'"', whatkind, '#pop'),
  1022. ]
  1023. # Callbacks for distinguishing tokens and reserved words
  1024. def long_id_callback(self, match):
  1025. if match.group(1) in self.alphanumid_reserved: token = Error
  1026. else: token = Name.Namespace
  1027. yield match.start(1), token, match.group(1)
  1028. yield match.start(2), Punctuation, match.group(2)
  1029. def end_id_callback(self, match):
  1030. if match.group(1) in self.alphanumid_reserved: token = Error
  1031. elif match.group(1) in self.symbolicid_reserved: token = Error
  1032. else: token = Name
  1033. yield match.start(1), token, match.group(1)
  1034. def id_callback(self, match):
  1035. str = match.group(1)
  1036. if str in self.alphanumid_reserved: token = Keyword.Reserved
  1037. elif str in self.symbolicid_reserved: token = Punctuation
  1038. else: token = Name
  1039. yield match.start(1), token, str
  1040. tokens = {
  1041. # Whitespace and comments are (almost) everywhere
  1042. 'whitespace': [
  1043. (r'\s+', Text),
  1044. (r'\(\*', Comment.Multiline, 'comment'),
  1045. ],
  1046. 'delimiters': [
  1047. # This lexer treats these delimiters specially:
  1048. # Delimiters define scopes, and the scope is how the meaning of
  1049. # the `|' is resolved - is it a case/handle expression, or function
  1050. # definition by cases? (This is not how the Definition works, but
  1051. # it's how MLton behaves, see http://mlton.org/SMLNJDeviations)
  1052. (r'\(|\[|{', Punctuation, 'main'),
  1053. (r'\)|\]|}', Punctuation, '#pop'),
  1054. (r'\b(let|if|local)\b(?!\')', Keyword.Reserved, ('main', 'main')),
  1055. (r'\b(struct|sig|while)\b(?!\')', Keyword.Reserved, 'main'),
  1056. (r'\b(do|else|end|in|then)\b(?!\')', Keyword.Reserved, '#pop'),
  1057. ],
  1058. 'core': [
  1059. # Punctuation that doesn't overlap symbolic identifiers
  1060. (r'(%s)' % '|'.join([re.escape(z) for z in nonid_reserved]),
  1061. Punctuation),
  1062. # Special constants: strings, floats, numbers in decimal and hex
  1063. (r'#"', String.Char, 'char'),
  1064. (r'"', String.Double, 'string'),
  1065. (r'~?0x[0-9a-fA-F]+', Number.Hex),
  1066. (r'0wx[0-9a-fA-F]+', Number.Hex),
  1067. (r'0w\d+', Number.Integer),
  1068. (r'~?\d+\.\d+[eE]~?\d+', Number.Float),
  1069. (r'~?\d+\.\d+', Number.Float),
  1070. (r'~?\d+[eE]~?\d+', Number.Float),
  1071. (r'~?\d+', Number.Integer),
  1072. # Labels
  1073. (r'#\s*[1-9][0-9]*', Name.Label),
  1074. (r'#\s*(%s)' % alphanumid_re, Name.Label),
  1075. (r'#\s+(%s)' % symbolicid_re, Name.Label),
  1076. # Some reserved words trigger a special, local lexer state change
  1077. (r'\b(datatype|abstype)\b(?!\')', Keyword.Reserved, 'dname'),
  1078. (r'(?=\b(exception)\b(?!\'))', Text, ('ename')),
  1079. (r'\b(functor|include|open|signature|structure)\b(?!\')',
  1080. Keyword.Reserved, 'sname'),
  1081. (r'\b(type|eqtype)\b(?!\')', Keyword.Reserved, 'tname'),
  1082. # Regular identifiers, long and otherwise
  1083. (r'\'[0-9a-zA-Z_\']*', Name.Decorator),
  1084. (r'(%s)(\.)' % alphanumid_re, long_id_callback, "dotted"),
  1085. (r'(%s)' % alphanumid_re, id_callback),
  1086. (r'(%s)' % symbolicid_re, id_callback),
  1087. ],
  1088. 'dotted': [
  1089. (r'(%s)(\.)' % alphanumid_re, long_id_callback),
  1090. (r'(%s)' % alphanumid_re, end_id_callback, "#pop"),
  1091. (r'(%s)' % symbolicid_re, end_id_callback, "#pop"),
  1092. (r'\s+', Error),
  1093. (r'\S+', Error),
  1094. ],
  1095. # Main parser (prevents errors in files that have scoping errors)
  1096. 'root': [ (r'', Text, 'main') ],
  1097. # In this scope, I expect '|' to not be followed by a function name,
  1098. # and I expect 'and' to be followed by a binding site
  1099. 'main': [
  1100. include('whitespace'),
  1101. # Special behavior of val/and/fun
  1102. (r'\b(val|and)\b(?!\')', Keyword.Reserved, 'vname'),
  1103. (r'\b(fun)\b(?!\')', Keyword.Reserved,
  1104. ('#pop', 'main-fun', 'fname')),
  1105. include('delimiters'),
  1106. include('core'),
  1107. (r'\S+', Error),
  1108. ],
  1109. # In this scope, I expect '|' and 'and' to be followed by a function
  1110. 'main-fun': [
  1111. include('whitespace'),
  1112. (r'\s', Text),
  1113. (r'\(\*', Comment.Multiline, 'comment'),
  1114. # Special behavior of val/and/fun
  1115. (r'\b(fun|and)\b(?!\')', Keyword.Reserved, 'fname'),
  1116. (r'\b(val)\b(?!\')', Keyword.Reserved,
  1117. ('#pop', 'main', 'vname')),
  1118. # Special behavior of '|' and '|'-manipulating keywords
  1119. (r'\|', Punctuation, 'fname'),
  1120. (r'\b(case|handle)\b(?!\')', Keyword.Reserved,
  1121. ('#pop', 'main')),
  1122. include('delimiters'),
  1123. include('core'),
  1124. (r'\S+', Error),
  1125. ],
  1126. # Character and string parsers
  1127. 'char': stringy(String.Char),
  1128. 'string': stringy(String.Double),
  1129. 'breakout': [
  1130. (r'(?=\b(%s)\b(?!\'))' % '|'.join(alphanumid_reserved), Text, '#pop'),
  1131. ],
  1132. # Dealing with what comes after module system keywords
  1133. 'sname': [
  1134. include('whitespace'),
  1135. include('breakout'),
  1136. (r'(%s)' % alphanumid_re, Name.Namespace),
  1137. (r'', Text, '#pop'),
  1138. ],
  1139. # Dealing with what comes after the 'fun' (or 'and' or '|') keyword
  1140. 'fname': [
  1141. include('whitespace'),
  1142. (r'\'[0-9a-zA-Z_\']*', Name.Decorator),
  1143. (r'\(', Punctuation, 'tyvarseq'),
  1144. (r'(%s)' % alphanumid_re, Name.Function, '#pop'),
  1145. (r'(%s)' % symbolicid_re, Name.Function, '#pop'),
  1146. # Ignore interesting function declarations like "fun (x + y) = ..."
  1147. (r'', Text, '#pop'),
  1148. ],
  1149. # Dealing with what comes after the 'val' (or 'and') keyword
  1150. 'vname': [
  1151. include('whitespace'),
  1152. (r'\'[0-9a-zA-Z_\']*', Name.Decorator),
  1153. (r'\(', Punctuation, 'tyvarseq'),
  1154. (r'(%s)(\s*)(=(?!%s))' % (alphanumid_re, symbolicid_re),
  1155. bygroups(Name.Variable, Text, Punctuation), '#pop'),
  1156. (r'(%s)(\s*)(=(?!%s))' % (symbolicid_re, symbolicid_re),
  1157. bygroups(Name.Variable, Text, Punctuation), '#pop'),
  1158. (r'(%s)' % alphanumid_re, Name.Variable, '#pop'),
  1159. (r'(%s)' % symbolicid_re, Name.Variable, '#pop'),
  1160. # Ignore interesting patterns like 'val (x, y)'
  1161. (r'', Text, '#pop'),
  1162. ],
  1163. # Dealing with what comes after the 'type' (or 'and') keyword
  1164. 'tname': [
  1165. include('whitespace'),
  1166. include('breakout'),
  1167. (r'\'[0-9a-zA-Z_\']*', Name.Decorator),
  1168. (r'\(', Punctuation, 'tyvarseq'),
  1169. (r'=(?!%s)' % symbolicid_re, Punctuation, ('#pop', 'typbind')),
  1170. (r'(%s)' % alphanumid_re, Keyword.Type),
  1171. (r'(%s)' % symbolicid_re, Keyword.Type),
  1172. (r'\S+', Error, '#pop'),
  1173. ],
  1174. # A type binding includes most identifiers
  1175. 'typbind': [
  1176. include('whitespace'),
  1177. (r'\b(and)\b(?!\')', Keyword.Reserved, ('#pop', 'tname')),
  1178. include('breakout'),
  1179. include('core'),
  1180. (r'\S+', Error, '#pop'),
  1181. ],
  1182. # Dealing with what comes after the 'datatype' (or 'and') keyword
  1183. 'dname': [
  1184. include('whitespace'),
  1185. include('breakout'),
  1186. (r'\'[0-9a-zA-Z_\']*', Name.Decorator),
  1187. (r'\(', Punctuation, 'tyvarseq'),
  1188. (r'(=)(\s*)(datatype)',
  1189. bygroups(Punctuation, Text, Keyword.Reserved), '#pop'),
  1190. (r'=(?!%s)' % symbolicid_re, Punctuation,
  1191. ('#pop', 'datbind', 'datcon')),
  1192. (r'(%s)' % alphanumid_re, Keyword.Type),
  1193. (r'(%s)' % symbolicid_re, Keyword.Type),
  1194. (r'\S+', Error, '#pop'),
  1195. ],
  1196. # common case - A | B | C of int
  1197. 'datbind': [
  1198. include('whitespace'),
  1199. (r'\b(and)\b(?!\')', Keyword.Reserved, ('#pop', 'dname')),
  1200. (r'\b(withtype)\b(?!\')', Keyword.Reserved, ('#pop', 'tname')),
  1201. (r'\b(of)\b(?!\')', Keyword.Reserved),
  1202. (r'(\|)(\s*)(%s)' % alphanumid_re,
  1203. bygroups(Punctuation, Text, Name.Class)),
  1204. (r'(\|)(\s+)(%s)' % symbolicid_re,
  1205. bygroups(Punctuation, Text, Name.Class)),
  1206. include('breakout'),
  1207. include('core'),
  1208. (r'\S+', Error),
  1209. ],
  1210. # Dealing with what comes after an exception
  1211. 'ename': [
  1212. include('whitespace'),
  1213. (r'(exception|and)\b(\s+)(%s)' % alphanumid_re,
  1214. bygroups(Keyword.Reserved, Text, Name.Class)),
  1215. (r'(exception|and)\b(\s*)(%s)' % symbolicid_re,
  1216. bygroups(Keyword.Reserved, Text, Name.Class)),
  1217. (r'\b(of)\b(?!\')', Keyword.Reserved),
  1218. include('breakout'),
  1219. include('core'),
  1220. (r'\S+', Error),
  1221. ],
  1222. 'datcon': [
  1223. include('whitespace'),
  1224. (r'(%s)' % alphanumid_re, Name.Class, '#pop'),
  1225. (r'(%s)' % symbolicid_re, Name.Class, '#pop'),
  1226. (r'\S+', Error, '#pop'),
  1227. ],
  1228. # Series of type variables
  1229. 'tyvarseq': [
  1230. (r'\s', Text),
  1231. (r'\(\*', Comment.Multiline, 'comment'),
  1232. (r'\'[0-9a-zA-Z_\']*', Name.Decorator),
  1233. (alphanumid_re, Name),
  1234. (r',', Punctuation),
  1235. (r'\)', Punctuation, '#pop'),
  1236. (symbolicid_re, Name),
  1237. ],
  1238. 'comment': [
  1239. (r'[^(*)]', Comment.Multiline),
  1240. (r'\(\*', Comment.Multiline, '#push'),
  1241. (r'\*\)', Comment.Multiline, '#pop'),
  1242. (r'[(*)]', Comment.Multiline),
  1243. ],
  1244. }
  1245. class OcamlLexer(RegexLexer):
  1246. """
  1247. For the OCaml language.
  1248. *New in Pygments 0.7.*
  1249. """
  1250. name = 'OCaml'
  1251. aliases = ['ocaml']
  1252. filenames = ['*.ml', '*.mli', '*.mll', '*.mly']
  1253. mimetypes = ['text/x-ocaml']
  1254. keywords = [
  1255. 'as', 'assert', 'begin', 'class', 'constraint', 'do', 'done',
  1256. 'downto', 'else', 'end', 'exception', 'external', 'false',
  1257. 'for', 'fun', 'function', 'functor', 'if', 'in', 'include',
  1258. 'inherit', 'initializer', 'lazy', 'let', 'match', 'method',
  1259. 'module', 'mutable', 'new', 'object', 'of', 'open', 'private',
  1260. 'raise', 'rec', 'sig', 'struct', 'then', 'to', 'true', 'try',
  1261. 'type', 'value', 'val', 'virtual', 'when', 'while', 'with',
  1262. ]
  1263. keyopts = [
  1264. '!=','#','&','&&','\(','\)','\*','\+',',','-',
  1265. '-\.','->','\.','\.\.',':','::',':=',':>',';',';;','<',
  1266. '<-','=','>','>]','>}','\?','\?\?','\[','\[<','\[>','\[\|',
  1267. ']','_','`','{','{<','\|','\|]','}','~'
  1268. ]
  1269. operators = r'[!$%&*+\./:<=>?@^|~-]'
  1270. word_operators = ['and', 'asr', 'land', 'lor', 'lsl', 'lxor', 'mod', 'or']
  1271. prefix_syms = r'[!?~]'
  1272. infix_syms = r'[=<>@^|&+\*/$%-]'
  1273. primitives = ['unit', 'int', 'float', 'bool', 'string', 'char', 'list', 'array']
  1274. tokens = {
  1275. 'escape-sequence': [
  1276. (r'\\[\\\"\'ntbr]', String.Escape),
  1277. (r'\\[0-9]{3}', String.Escape),
  1278. (r'\\x[0-9a-fA-F]{2}', String.Escape),
  1279. ],
  1280. 'root': [
  1281. (r'\s+', Text),
  1282. (r'false|true|\(\)|\[\]', Name.Builtin.Pseudo),
  1283. (r'\b([A-Z][A-Za-z0-9_\']*)(?=\s*\.)',
  1284. Name.Namespace, 'dotted'),
  1285. (r'\b([A-Z][A-Za-z0-9_\']*)', Name.Class),
  1286. (r'\(\*(?![)])', Comment, 'comment'),
  1287. (r'\b(%s)\b' % '|'.join(keywords), Keyword),
  1288. (r'(%s)' % '|'.join(keyopts[::-1]), Operator),
  1289. (r'(%s|%s)?%s' % (infix_syms, prefix_syms, operators), Operator),
  1290. (r'\b(%s)\b' % '|'.join(word_operators), Operator.Word),
  1291. (r'\b(%s)\b' % '|'.join(primitives), Keyword.Type),
  1292. (r"[^\W\d][\w']*", Name),
  1293. (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float),
  1294. (r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex),
  1295. (r'0[oO][0-7][0-7_]*', Number.Oct),
  1296. (r'0[bB][01][01_]*', Number.Binary),
  1297. (r'\d[\d_]*', Number.Integer),
  1298. (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'",
  1299. String.Char),
  1300. (r"'.'", String.Char),
  1301. (r"'", Keyword), # a stray quote is another syntax element
  1302. (r'"', String.Double, 'string'),
  1303. (r'[~?][a-z][\w\']*:', Name.Variable),
  1304. ],
  1305. 'comment': [
  1306. (r'[^(*)]+', Comment),
  1307. (r'\(\*', Comment, '#push'),
  1308. (r'\*\)', Comment, '#pop'),
  1309. (r'[(*)]', Comment),
  1310. ],
  1311. 'string': [
  1312. (r'[^\\"]+', String.Double),
  1313. include('escape-sequence'),
  1314. (r'\\\n', String.Double),
  1315. (r'"', String.Double, '#pop'),
  1316. ],
  1317. 'dotted': [
  1318. (r'\s+', Text),
  1319. (r'\.', Punctuation),
  1320. (r'[A-Z][A-Za-z0-9_\']*(?=\s*\.)', Name.Namespace),
  1321. (r'[A-Z][A-Za-z0-9_\']*', Name.Class, '#pop'),
  1322. (r'[a-z_][A-Za-z0-9_\']*', Name, '#pop'),
  1323. ],
  1324. }
  1325. class ErlangLexer(RegexLexer):
  1326. """
  1327. For the Erlang functional programming language.
  1328. Blame Jeremy Thurgood (http://jerith.za.net/).
  1329. *New in Pygments 0.9.*
  1330. """
  1331. name = 'Erlang'
  1332. aliases = ['erlang']
  1333. filenames = ['*.erl', '*.hrl', '*.es', '*.escript']
  1334. mimetypes = ['text/x-erlang']
  1335. keywords = [
  1336. 'after', 'begin', 'case', 'catch', 'cond', 'end', 'fun', 'if',
  1337. 'let', 'of', 'query', 'receive', 'try', 'when',
  1338. ]
  1339. builtins = [ # See erlang(3) man page
  1340. 'abs', 'append_element', 'apply', 'atom_to_list', 'binary_to_list',
  1341. 'bitstring_to_list', 'binary_to_term', 'bit_size', 'bump_reductions',
  1342. 'byte_size', 'cancel_timer', 'check_process_code', 'delete_module',
  1343. 'demonitor', 'disconnect_node', 'display', 'element', 'erase', 'exit',
  1344. 'float', 'float_to_list', 'fun_info', 'fun_to_list',
  1345. 'function_exported', 'garbage_collect', 'get', 'get_keys',
  1346. 'group_leader', 'hash', 'hd', 'integer_to_list', 'iolist_to_binary',
  1347. 'iolist_size', 'is_atom', 'is_binary', 'is_bitstring', 'is_boolean',
  1348. 'is_builtin', 'is_float', 'is_function', 'is_integer', 'is_list',
  1349. 'is_number', 'is_pid', 'is_port', 'is_process_alive', 'is_record',
  1350. 'is_reference', 'is_tuple', 'length', 'link', 'list_to_atom',
  1351. 'list_to_binary', 'list_to_bitstring', 'list_to_existing_atom',
  1352. 'list_to_float', 'list_to_integer', 'list_to_pid', 'list_to_tuple',
  1353. 'load_module', 'localtime_to_universaltime', 'make_tuple', 'md5',
  1354. 'md5_final', 'md5_update', 'memory', 'module_loaded', 'monitor',
  1355. 'monitor_node', 'node', 'nodes', 'open_port', 'phash', 'phash2',
  1356. 'pid_to_list', 'port_close', 'port_command', 'port_connect',
  1357. 'port_control', 'port_call', 'port_info', 'port_to_list',
  1358. 'process_display', 'process_flag', 'process_info', 'purge_module',
  1359. 'put', 'read_timer', 'ref_to_list', 'register', 'resume_process',
  1360. 'round', 'send', 'send_after', 'send_nosuspend', 'set_cookie',
  1361. 'setelement', 'size', 'spawn', 'spawn_link', 'spawn_monitor',
  1362. 'spawn_opt', 'split_binary', 'start_timer', 'statistics',
  1363. 'suspend_process', 'system_flag', 'system_info', 'system_monitor',
  1364. 'system_profile', 'term_to_binary', 'tl', 'trace', 'trace_delivered',
  1365. 'trace_info', 'trace_pattern', 'trunc', 'tuple_size', 'tuple_to_list',
  1366. 'universaltime_to_localtime', 'unlink', 'unregister', 'whereis'
  1367. ]
  1368. operators = r'(\+\+?|--?|\*|/|<|>|/=|=:=|=/=|=<|>=|==?|<-|!|\?)'
  1369. word_operators = [
  1370. 'and', 'andalso', 'band', 'bnot', 'bor', 'bsl', 'bsr', 'bxor',
  1371. 'div', 'not', 'or', 'orelse', 'rem', 'xor'
  1372. ]
  1373. atom_re = r"(?:[a-z][a-zA-Z0-9_]*|'[^\n']*[^\\]')"
  1374. variable_re = r'(?:[A-Z_][a-zA-Z0-9_]*)'
  1375. escape_re = r'(?:\\(?:[bdefnrstv\'"\\/]|[0-7][0-7]?[0-7]?|\^[a-zA-Z]))'
  1376. macro_re = r'(?:'+variable_re+r'|'+atom_re+r')'
  1377. base_re = r'(?:[2-9]|[12][0-9]|3[0-6])'
  1378. tokens = {
  1379. 'root': [
  1380. (r'\s+', Text),
  1381. (r'%.*\n', Comment),
  1382. ('(' + '|'.join(keywords) + r')\b', Keyword),
  1383. ('(' + '|'.join(builtins) + r')\b', Name.Builtin),
  1384. ('(' + '|'.join(word_operators) + r')\b', Operator.Word),
  1385. (r'^-', Punctuation, 'directive'),
  1386. (operators, Operator),
  1387. (r'"', String, 'string'),
  1388. (r'<<', Name.Label),
  1389. (r'>>', Name.Label),
  1390. ('(' + atom_re + ')(:)', bygroups(Name.Namespace, Punctuation)),
  1391. ('(?:^|(?<=:))(' + atom_re + r')(\s*)(\()',
  1392. bygroups(Name.Function, Text, Punctuation)),
  1393. (r'[+-]?'+base_re+r'#[0-9a-zA-Z]+', Number.Integer),
  1394. (r'[+-]?\d+', Number.Integer),
  1395. (r'[+-]?\d+.\d+', Number.Float),
  1396. (r'[]\[:_@\".{}()|;,]', Punctuation),
  1397. (variable_re, Name.Variable),
  1398. (atom_re, Name),
  1399. (r'\?'+macro_re, Name.Constant),
  1400. (r'\$(?:'+escape_re+r'|\\[ %]|[^\\])', String.Char),
  1401. (r'#'+atom_re+r'(:?\.'+atom_re+r')?', Name.Label),
  1402. ],
  1403. 'string': [
  1404. (escape_re, String.Escape),
  1405. (r'"', String, '#pop'),
  1406. (r'~[0-9.*]*[~#+bBcdefginpPswWxX]', String.Interpol),
  1407. (r'[^"\\~]+', String),
  1408. (r'~', String),
  1409. ],
  1410. 'directive': [
  1411. (r'(define)(\s*)(\()('+macro_re+r')',
  1412. bygroups(Name.Entity, Text, Punctuation, Name.Constant), '#pop'),
  1413. (r'(record)(\s*)(\()('+macro_re+r')',
  1414. bygroups(Name.Entity, Text, Punctuation, Name.Label), '#pop'),
  1415. (atom_re, Name.Entity, '#pop'),
  1416. ],
  1417. }
  1418. class ErlangShellLexer(Lexer):
  1419. """
  1420. Shell sessions in erl (for Erlang code).
  1421. *New in Pygments 1.1.*
  1422. """
  1423. name = 'Erlang erl session'
  1424. aliases = ['erl']
  1425. filenames = ['*.erl-sh']
  1426. mimetypes = ['text/x-erl-shellsession']
  1427. _prompt_re = re.compile(r'\d+>(?=\s|\Z)')
  1428. def get_tokens_unprocessed(self, text):
  1429. erlexer = ErlangLexer(**self.options)
  1430. curcode = ''
  1431. insertions = []
  1432. for match in line_re.finditer(text):
  1433. line = match.group()
  1434. m = self._prompt_re.match(line)
  1435. if m is not None:
  1436. end = m.end()
  1437. insertions.append((len(curcode),
  1438. [(0, Generic.Prompt, line[:end])]))
  1439. curcode += line[end:]
  1440. else:
  1441. if curcode:
  1442. for item in do_insertions(insertions,
  1443. erlexer.get_tokens_unprocessed(curcode)):
  1444. yield item
  1445. curcode = ''
  1446. insertions = []
  1447. if line.startswith('*'):
  1448. yield match.start(), Generic.Traceback, line
  1449. else:
  1450. yield match.start(), Generic.Output, line
  1451. if curcode:
  1452. for item in do_insertions(insertions,
  1453. erlexer.get_tokens_unprocessed(curcode)):
  1454. yield item
  1455. class OpaLexer(RegexLexer):
  1456. """
  1457. Lexer for the Opa language (http://opalang.org).
  1458. *New in Pygments 1.5.*
  1459. """
  1460. name = 'Opa'
  1461. aliases = ['opa']
  1462. filenames = ['*.opa']
  1463. mimetypes = ['text/x-opa']
  1464. # most of these aren't strictly keywords
  1465. # but if you color only real keywords, you might just
  1466. # as well not color anything
  1467. keywords = [
  1468. 'and', 'as', 'begin', 'css', 'database', 'db', 'do', 'else', 'end',
  1469. 'external', 'forall', 'if', 'import', 'match', 'package', 'parser',
  1470. 'rec', 'server', 'then', 'type', 'val', 'with', 'xml_parser'
  1471. ]
  1472. # matches both stuff and `stuff`
  1473. ident_re = r'(([a-zA-Z_]\w*)|(`[^`]*`))'
  1474. op_re = r'[.=\-<>,@~%/+?*&^!]'
  1475. punc_re = r'[()\[\],;|]' # '{' and '}' are treated elsewhere
  1476. # because they are also used for inserts
  1477. tokens = {
  1478. # copied from the caml lexer, should be adapted
  1479. 'escape-sequence': [
  1480. (r'\\[\\\"\'ntr}]', String.Escape),
  1481. (r'\\[0-9]{3}', String.Escape),
  1482. (r'\\x[0-9a-fA-F]{2}', String.Escape),
  1483. ],
  1484. # factorizing these rules, because they are inserted many times
  1485. 'comments': [
  1486. (r'/\*', Comment, 'nested-comment'),
  1487. (r'//.*?$', Comment),
  1488. ],
  1489. 'comments-and-spaces': [
  1490. include('comments'),
  1491. (r'\s+', Text),
  1492. ],
  1493. 'root': [
  1494. include('comments-and-spaces'),
  1495. # keywords
  1496. (r'\b(%s)\b' % '|'.join(keywords), Keyword),
  1497. # directives
  1498. # we could parse the actual set of directives instead of anything
  1499. # starting with @, but this is troublesome
  1500. # because it needs to be adjusted all the time
  1501. # and assuming we parse only sources that compile, it is useless
  1502. (r'@'+ident_re+r'\b', Name.Builtin.Pseudo),
  1503. # number literals
  1504. (r'-?.[\d]+([eE][+\-]?\d+)', Number.Float),
  1505. (r'-?\d+.\d*([eE][+\-]?\d+)', Number.Float),
  1506. (r'-?\d+[eE][+\-]?\d+', Number.Float),
  1507. (r'0[xX][\da-fA-F]+', Number.Hex),
  1508. (r'0[oO][0-7]+', Number.Oct),
  1509. (r'0[bB][01]+', Number.Binary),
  1510. (r'\d+', Number.Integer),
  1511. # color literals
  1512. (r'#[\da-fA-F]{3,6}', Number.Integer),
  1513. # string literals
  1514. (r'"', String.Double, 'string'),
  1515. # char literal, should be checked because this is the regexp from
  1516. # the caml lexer
  1517. (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2})|.)'",
  1518. String.Char),
  1519. # this is meant to deal with embedded exprs in strings
  1520. # every time we find a '}' we pop a state so that if we were
  1521. # inside a string, we are back in the string state
  1522. # as a consequence, we must also push a state every time we find a
  1523. # '{' or else we will have errors when parsing {} for instance
  1524. (r'{', Operator, '#push'),
  1525. (r'}', Operator, '#pop'),
  1526. # html literals
  1527. # this is a much more strict that the actual parser,
  1528. # since a<b would not be parsed as html
  1529. # but then again, the parser is way too lax, and we can't hope
  1530. # to have something as tolerant
  1531. (r'<(?=[a-zA-Z>])', String.Single, 'html-open-tag'),
  1532. # db path
  1533. # matching the '[_]' in '/a[_]' because it is a part
  1534. # of the syntax of the db path definition
  1535. # unfortunately, i don't know how to match the ']' in
  1536. # /a[1], so this is somewhat inconsistent
  1537. (r'[@?!]?(/\w+)+(\[_\])?', Name.Variable),
  1538. # putting the same color on <- as on db path, since
  1539. # it can be used only to mean Db.write
  1540. (r'<-(?!'+op_re+r')', Name.Variable),
  1541. # 'modules'
  1542. # although modules are not distinguished by their names as in caml
  1543. # the standard library seems to follow the convention that modules
  1544. # only area capitalized
  1545. (r'\b([A-Z]\w*)(?=\.)', Name.Namespace),
  1546. # operators
  1547. # = has a special role because this is the only
  1548. # way to syntactic distinguish binding constructions
  1549. # unfortunately, this colors the equal in {x=2} too
  1550. (r'=(?!'+op_re+r')', Keyword),
  1551. (r'(%s)+' % op_re, Operator),
  1552. (r'(%s)+' % punc_re, Operator),
  1553. # coercions
  1554. (r':', Operator, 'type'),
  1555. # type variables
  1556. # we need this rule because we don't parse specially type
  1557. # definitions so in "type t('a) = ...", "'a" is parsed by 'root'
  1558. ("'"+ident_re, Keyword.Type),
  1559. # id literal, #something, or #{expr}
  1560. (r'#'+ident_re, String.Single),
  1561. (r'#(?={)', String.Single),
  1562. # identifiers
  1563. # this avoids to color '2' in 'a2' as an integer
  1564. (ident_re, Text),
  1565. # default, not sure if that is needed or not
  1566. # (r'.', Text),
  1567. ],
  1568. # it is quite painful to have to parse types to know where they end
  1569. # this is the general rule for a type
  1570. # a type is either:
  1571. # * -> ty
  1572. # * type-with-slash
  1573. # * type-with-slash -> ty
  1574. # * type-with-slash (, type-with-slash)+ -> ty
  1575. #
  1576. # the code is pretty funky in here, but this code would roughly
  1577. # translate in caml to:
  1578. # let rec type stream =
  1579. # match stream with
  1580. # | [< "->"; stream >] -> type stream
  1581. # | [< ""; stream >] ->
  1582. # type_with_slash stream
  1583. # type_lhs_1 stream;
  1584. # and type_1 stream = ...
  1585. 'type': [
  1586. include('comments-and-spaces'),
  1587. (r'->', Keyword.Type),
  1588. (r'', Keyword.Type, ('#pop', 'type-lhs-1', 'type-with-slash')),
  1589. ],
  1590. # parses all the atomic or closed constructions in the syntax of type
  1591. # expressions: record types, tuple types, type constructors, basic type
  1592. # and type variables
  1593. 'type-1': [
  1594. include('comments-and-spaces'),
  1595. (r'\(', Keyword.Type, ('#pop', 'type-tuple')),
  1596. (r'~?{', Keyword.Type, ('#pop', 'type-record')),
  1597. (ident_re+r'\(', Keyword.Type, ('#pop', 'type-tuple')),
  1598. (ident_re, Keyword.Type, '#pop'),
  1599. ("'"+ident_re, Keyword.Type),
  1600. # this case is not in the syntax but sometimes
  1601. # we think we are parsing types when in fact we are parsing
  1602. # some css, so we just pop the states until we get back into
  1603. # the root state
  1604. (r'', Keyword.Type, '#pop'),
  1605. ],
  1606. # type-with-slash is either:
  1607. # * type-1
  1608. # * type-1 (/ type-1)+
  1609. 'type-with-slash': [
  1610. include('comments-and-spaces'),
  1611. (r'', Keyword.Type, ('#pop', 'slash-type-1', 'type-1')),
  1612. ],
  1613. 'slash-type-1': [
  1614. include('comments-and-spaces'),
  1615. ('/', Keyword.Type, ('#pop', 'type-1')),
  1616. # same remark as above
  1617. (r'', Keyword.Type, '#pop'),
  1618. ],
  1619. # we go in this state after having parsed a type-with-slash
  1620. # while trying to parse a type
  1621. # and at this point we must determine if we are parsing an arrow
  1622. # type (in which case we must continue parsing) or not (in which
  1623. # case we stop)
  1624. 'type-lhs-1': [
  1625. include('comments-and-spaces'),
  1626. (r'->', Keyword.Type, ('#pop', 'type')),
  1627. (r'(?=,)', Keyword.Type, ('#pop', 'type-arrow')),
  1628. (r'', Keyword.Type, '#pop'),
  1629. ],
  1630. 'type-arrow': [
  1631. include('comments-and-spaces'),
  1632. # the look ahead here allows to parse f(x : int, y : float -> truc)
  1633. # correctly
  1634. (r',(?=[^:]*?->)', Keyword.Type, 'type-with-slash'),
  1635. (r'->', Keyword.Type, ('#pop', 'type')),
  1636. # same remark as above
  1637. (r'', Keyword.Type, '#pop'),
  1638. ],
  1639. # no need to do precise parsing for tuples and records
  1640. # because they are closed constructions, so we can simply
  1641. # find the closing delimiter
  1642. # note that this function would be not work if the source
  1643. # contained identifiers like `{)` (although it could be patched
  1644. # to support it)
  1645. 'type-tuple': [
  1646. include('comments-and-spaces'),
  1647. (r'[^\(\)/*]+', Keyword.Type),
  1648. (r'[/*]', Keyword.Type),
  1649. (r'\(', Keyword.Type, '#push'),
  1650. (r'\)', Keyword.Type, '#pop'),
  1651. ],
  1652. 'type-record': [
  1653. include('comments-and-spaces'),
  1654. (r'[^{}/*]+', Keyword.Type),
  1655. (r'[/*]', Keyword.Type),
  1656. (r'{', Keyword.Type, '#push'),
  1657. (r'}', Keyword.Type, '#pop'),
  1658. ],
  1659. # 'type-tuple': [
  1660. # include('comments-and-spaces'),
  1661. # (r'\)', Keyword.Type, '#pop'),
  1662. # (r'', Keyword.Type, ('#pop', 'type-tuple-1', 'type-1')),
  1663. # ],
  1664. # 'type-tuple-1': [
  1665. # include('comments-and-spaces'),
  1666. # (r',?\s*\)', Keyword.Type, '#pop'), # ,) is a valid end of tuple, in (1,)
  1667. # (r',', Keyword.Type, 'type-1'),
  1668. # ],
  1669. # 'type-record':[
  1670. # include('comments-and-spaces'),
  1671. # (r'}', Keyword.Type, '#pop'),
  1672. # (r'~?(?:\w+|`[^`]*`)', Keyword.Type, 'type-record-field-expr'),
  1673. # ],
  1674. # 'type-record-field-expr': [
  1675. #
  1676. # ],
  1677. 'nested-comment': [
  1678. (r'[^/*]+', Comment),
  1679. (r'/\*', Comment, '#push'),
  1680. (r'\*/', Comment, '#pop'),
  1681. (r'[/*]', Comment),
  1682. ],
  1683. # the coy pasting between string and single-string
  1684. # is kinda sad. Is there a way to avoid that??
  1685. 'string': [
  1686. (r'[^\\"{]+', String.Double),
  1687. (r'"', String.Double, '#pop'),
  1688. (r'{', Operator, 'root'),
  1689. include('escape-sequence'),
  1690. ],
  1691. 'single-string': [
  1692. (r'[^\\\'{]+', String.Double),
  1693. (r'\'', String.Double, '#pop'),
  1694. (r'{', Operator, 'root'),
  1695. include('escape-sequence'),
  1696. ],
  1697. # all the html stuff
  1698. # can't really reuse some existing html parser
  1699. # because we must be able to parse embedded expressions
  1700. # we are in this state after someone parsed the '<' that
  1701. # started the html literal
  1702. 'html-open-tag': [
  1703. (r'[\w\-:]+', String.Single, ('#pop', 'html-attr')),
  1704. (r'>', String.Single, ('#pop', 'html-content')),
  1705. ],
  1706. # we are in this state after someone parsed the '</' that
  1707. # started the end of the closing tag
  1708. 'html-end-tag': [
  1709. # this is a star, because </> is allowed
  1710. (r'[\w\-:]*>', String.Single, '#pop'),
  1711. ],
  1712. # we are in this state after having parsed '<ident(:ident)?'
  1713. # we thus parse a possibly empty list of attributes
  1714. 'html-attr': [
  1715. (r'\s+', Text),
  1716. (r'[\w\-:]+=', String.Single, 'html-attr-value'),
  1717. (r'/>', String.Single, '#pop'),
  1718. (r'>', String.Single, ('#pop', 'html-content')),
  1719. ],
  1720. 'html-attr-value': [
  1721. (r"'", String.Single, ('#pop', 'single-string')),
  1722. (r'"', String.Single, ('#pop', 'string')),
  1723. (r'#'+ident_re, String.Single, '#pop'),
  1724. (r'#(?={)', String.Single, ('#pop', 'root')),
  1725. (r'{', Operator, ('#pop', 'root')), # this is a tail call!
  1726. ],
  1727. # we should probably deal with '\' escapes here
  1728. 'html-content': [
  1729. (r'<!--', Comment, 'html-comment'),
  1730. (r'</', String.Single, ('#pop', 'html-end-tag')),
  1731. (r'<', String.Single, 'html-open-tag'),
  1732. (r'{', Operator, 'root'),
  1733. (r'.|\s+', String.Single),
  1734. ],
  1735. 'html-comment': [
  1736. (r'-->', Comment, '#pop'),
  1737. (r'[^\-]+|-', Comment),
  1738. ],
  1739. }
  1740. class CoqLexer(RegexLexer):
  1741. """
  1742. For the `Coq <http://coq.inria.fr/>`_ theorem prover.
  1743. *New in Pygments 1.5.*
  1744. """
  1745. name = 'Coq'
  1746. aliases = ['coq']
  1747. filenames = ['*.v']
  1748. mimetypes = ['text/x-coq']
  1749. keywords1 = [
  1750. # Vernacular commands
  1751. 'Section', 'Module', 'End', 'Require', 'Import', 'Export', 'Variable',
  1752. 'Variables', 'Parameter', 'Parameters', 'Axiom', 'Hypothesis',
  1753. 'Hypotheses', 'Notation', 'Local', 'Tactic', 'Reserved', 'Scope',
  1754. 'Open', 'Close', 'Bind', 'Delimit', 'Definition', 'Let', 'Ltac',
  1755. 'Fixpoint', 'CoFixpoint', 'Morphism', 'Relation', 'Implicit',
  1756. 'Arguments', 'Set', 'Unset', 'Contextual', 'Strict', 'Prenex',
  1757. 'Implicits', 'Inductive', 'CoInductive', 'Record', 'Structure',
  1758. 'Canonical', 'Coercion', 'Theorem', 'Lemma', 'Corollary',
  1759. 'Proposition', 'Fact', 'Remark', 'Example', 'Proof', 'Goal', 'Save',
  1760. 'Qed', 'Defined', 'Hint', 'Resolve', 'Rewrite', 'View', 'Search',
  1761. 'Show', 'Print', 'Printing', 'All', 'Graph', 'Projections', 'inside',
  1762. 'outside',
  1763. ]
  1764. keywords2 = [
  1765. # Gallina
  1766. 'forall', 'exists', 'exists2', 'fun', 'fix', 'cofix', 'struct',
  1767. 'match', 'end', 'in', 'return', 'let', 'if', 'is', 'then', 'else',
  1768. 'for', 'of', 'nosimpl', 'with', 'as',
  1769. ]
  1770. keywords3 = [
  1771. # Sorts
  1772. 'Type', 'Prop',
  1773. ]
  1774. keywords4 = [
  1775. # Tactics
  1776. 'pose', 'set', 'move', 'case', 'elim', 'apply', 'clear', 'hnf', 'intro',
  1777. 'intros', 'generalize', 'rename', 'pattern', 'after', 'destruct',
  1778. 'induction', 'using', 'refine', 'inversion', 'injection', 'rewrite',
  1779. 'congr', 'unlock', 'compute', 'ring', 'field', 'replace', 'fold',
  1780. 'unfold', 'change', 'cutrewrite', 'simpl', 'have', 'suff', 'wlog',
  1781. 'suffices', 'without', 'loss', 'nat_norm', 'assert', 'cut', 'trivial',
  1782. 'revert', 'bool_congr', 'nat_congr', 'symmetry', 'transitivity', 'auto',
  1783. 'split', 'left', 'right', 'autorewrite',
  1784. ]
  1785. keywords5 = [
  1786. # Terminators
  1787. 'by', 'done', 'exact', 'reflexivity', 'tauto', 'romega', 'omega',
  1788. 'assumption', 'solve', 'contradiction', 'discriminate',
  1789. ]
  1790. keywords6 = [
  1791. # Control
  1792. 'do', 'last', 'first', 'try', 'idtac', 'repeat',
  1793. ]
  1794. # 'as', 'assert', 'begin', 'class', 'constraint', 'do', 'done',
  1795. # 'downto', 'else', 'end', 'exception', 'external', 'false',
  1796. # 'for', 'fun', 'function', 'functor', 'if', 'in', 'include',
  1797. # 'inherit', 'initializer', 'lazy', 'let', 'match', 'method',
  1798. # 'module', 'mutable', 'new', 'object', 'of', 'open', 'private',
  1799. # 'raise', 'rec', 'sig', 'struct', 'then', 'to', 'true', 'try',
  1800. # 'type', 'val', 'virtual', 'when', 'while', 'with'
  1801. keyopts = [
  1802. '!=', '#', '&', '&&', r'\(', r'\)', r'\*', r'\+', ',', '-',
  1803. r'-\.', '->', r'\.', r'\.\.', ':', '::', ':=', ':>', ';', ';;', '<',
  1804. '<-', '=', '>', '>]', '>}', r'\?', r'\?\?', r'\[', r'\[<', r'\[>',
  1805. r'\[\|', ']', '_', '`', '{', '{<', r'\|', r'\|]', '}', '~', '=>',
  1806. r'/\\', r'\\/',
  1807. u'Π', u'λ',
  1808. ]
  1809. operators = r'[!$%&*+\./:<=>?@^|~-]'
  1810. word_operators = ['and', 'asr', 'land', 'lor', 'lsl', 'lxor', 'mod', 'or']
  1811. prefix_syms = r'[!?~]'
  1812. infix_syms = r'[=<>@^|&+\*/$%-]'
  1813. primitives = ['unit', 'int', 'float', 'bool', 'string', 'char', 'list',
  1814. 'array']
  1815. tokens = {
  1816. 'root': [
  1817. (r'\s+', Text),
  1818. (r'false|true|\(\)|\[\]', Name.Builtin.Pseudo),
  1819. (r'\(\*', Comment, 'comment'),
  1820. (r'\b(%s)\b' % '|'.join(keywords1), Keyword.Namespace),
  1821. (r'\b(%s)\b' % '|'.join(keywords2), Keyword),
  1822. (r'\b(%s)\b' % '|'.join(keywords3), Keyword.Type),
  1823. (r'\b(%s)\b' % '|'.join(keywords4), Keyword),
  1824. (r'\b(%s)\b' % '|'.join(keywords5), Keyword.Pseudo),
  1825. (r'\b(%s)\b' % '|'.join(keywords6), Keyword.Reserved),
  1826. (r'\b([A-Z][A-Za-z0-9_\']*)(?=\s*\.)',
  1827. Name.Namespace, 'dotted'),
  1828. (r'\b([A-Z][A-Za-z0-9_\']*)', Name.Class),
  1829. (r'(%s)' % '|'.join(keyopts[::-1]), Operator),
  1830. (r'(%s|%s)?%s' % (infix_syms, prefix_syms, operators), Operator),
  1831. (r'\b(%s)\b' % '|'.join(word_operators), Operator.Word),
  1832. (r'\b(%s)\b' % '|'.join(primitives), Keyword.Type),
  1833. (r"[^\W\d][\w']*", Name),
  1834. (r'\d[\d_]*', Number.Integer),
  1835. (r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex),
  1836. (r'0[oO][0-7][0-7_]*', Number.Oct),
  1837. (r'0[bB][01][01_]*', Number.Binary),
  1838. (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float),
  1839. (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'",
  1840. String.Char),
  1841. (r"'.'", String.Char),
  1842. (r"'", Keyword), # a stray quote is another syntax element
  1843. (r'"', String.Double, 'string'),
  1844. (r'[~?][a-z][\w\']*:', Name.Variable),
  1845. ],
  1846. 'comment': [
  1847. (r'[^(*)]+', Comment),
  1848. (r'\(\*', Comment, '#push'),
  1849. (r'\*\)', Comment, '#pop'),
  1850. (r'[(*)]', Comment),
  1851. ],
  1852. 'string': [
  1853. (r'[^"]+', String.Double),
  1854. (r'""', String.Double),
  1855. (r'"', String.Double, '#pop'),
  1856. ],
  1857. 'dotted': [
  1858. (r'\s+', Text),
  1859. (r'\.', Punctuation),
  1860. (r'[A-Z][A-Za-z0-9_\']*(?=\s*\.)', Name.Namespace),
  1861. (r'[A-Z][A-Za-z0-9_\']*', Name.Class, '#pop'),
  1862. (r'[a-z][a-z0-9_\']*', Name, '#pop'),
  1863. (r'', Text, '#pop')
  1864. ],
  1865. }
  1866. def analyse_text(text):
  1867. if text.startswith('(*'):
  1868. return True
  1869. class NewLispLexer(RegexLexer):
  1870. """
  1871. For `newLISP. <www.newlisp.org>`_ source code (version 10.3.0).
  1872. *New in Pygments 1.5.*
  1873. """
  1874. name = 'NewLisp'
  1875. aliases = ['newlisp']
  1876. filenames = ['*.lsp', '*.nl']
  1877. mimetypes = ['text/x-newlisp', 'application/x-newlisp']
  1878. flags = re.IGNORECASE | re.MULTILINE | re.UNICODE
  1879. # list of built-in functions for newLISP version 10.3
  1880. builtins = [
  1881. '^', '--', '-', ':', '!', '!=', '?', '@', '*', '/', '&', '%', '+', '++',
  1882. '<', '<<', '<=', '=', '>', '>=', '>>', '|', '~', '$', '$0', '$1', '$10',
  1883. '$11', '$12', '$13', '$14', '$15', '$2', '$3', '$4', '$5', '$6', '$7',
  1884. '$8', '$9', '$args', '$idx', '$it', '$main-args', 'abort', 'abs',
  1885. 'acos', 'acosh', 'add', 'address', 'amb', 'and', 'and', 'append-file',
  1886. 'append', 'apply', 'args', 'array-list', 'array?', 'array', 'asin',
  1887. 'asinh', 'assoc', 'atan', 'atan2', 'atanh', 'atom?', 'base64-dec',
  1888. 'base64-enc', 'bayes-query', 'bayes-train', 'begin', 'begin', 'begin',
  1889. 'beta', 'betai', 'bind', 'binomial', 'bits', 'callback', 'case', 'case',
  1890. 'case', 'catch', 'ceil', 'change-dir', 'char', 'chop', 'Class', 'clean',
  1891. 'close', 'command-event', 'cond', 'cond', 'cond', 'cons', 'constant',
  1892. 'context?', 'context', 'copy-file', 'copy', 'cos', 'cosh', 'count',
  1893. 'cpymem', 'crc32', 'crit-chi2', 'crit-z', 'current-line', 'curry',
  1894. 'date-list', 'date-parse', 'date-value', 'date', 'debug', 'dec',
  1895. 'def-new', 'default', 'define-macro', 'define-macro', 'define',
  1896. 'delete-file', 'delete-url', 'delete', 'destroy', 'det', 'device',
  1897. 'difference', 'directory?', 'directory', 'div', 'do-until', 'do-while',
  1898. 'doargs', 'dolist', 'dostring', 'dotimes', 'dotree', 'dump', 'dup',
  1899. 'empty?', 'encrypt', 'ends-with', 'env', 'erf', 'error-event',
  1900. 'eval-string', 'eval', 'exec', 'exists', 'exit', 'exp', 'expand',
  1901. 'explode', 'extend', 'factor', 'fft', 'file-info', 'file?', 'filter',
  1902. 'find-all', 'find', 'first', 'flat', 'float?', 'float', 'floor', 'flt',
  1903. 'fn', 'for-all', 'for', 'fork', 'format', 'fv', 'gammai', 'gammaln',
  1904. 'gcd', 'get-char', 'get-float', 'get-int', 'get-long', 'get-string',
  1905. 'get-url', 'global?', 'global', 'if-not', 'if', 'ifft', 'import', 'inc',
  1906. 'index', 'inf?', 'int', 'integer?', 'integer', 'intersect', 'invert',
  1907. 'irr', 'join', 'lambda-macro', 'lambda?', 'lambda', 'last-error',
  1908. 'last', 'legal?', 'length', 'let', 'let', 'let', 'letex', 'letn',
  1909. 'letn', 'letn', 'list?', 'list', 'load', 'local', 'log', 'lookup',
  1910. 'lower-case', 'macro?', 'main-args', 'MAIN', 'make-dir', 'map', 'mat',
  1911. 'match', 'max', 'member', 'min', 'mod', 'module', 'mul', 'multiply',
  1912. 'NaN?', 'net-accept', 'net-close', 'net-connect', 'net-error',
  1913. 'net-eval', 'net-interface', 'net-ipv', 'net-listen', 'net-local',
  1914. 'net-lookup', 'net-packet', 'net-peek', 'net-peer', 'net-ping',
  1915. 'net-receive-from', 'net-receive-udp', 'net-receive', 'net-select',
  1916. 'net-send-to', 'net-send-udp', 'net-send', 'net-service',
  1917. 'net-sessions', 'new', 'nil?', 'nil', 'normal', 'not', 'now', 'nper',
  1918. 'npv', 'nth', 'null?', 'number?', 'open', 'or', 'ostype', 'pack',
  1919. 'parse-date', 'parse', 'peek', 'pipe', 'pmt', 'pop-assoc', 'pop',
  1920. 'post-url', 'pow', 'prefix', 'pretty-print', 'primitive?', 'print',
  1921. 'println', 'prob-chi2', 'prob-z', 'process', 'prompt-event',
  1922. 'protected?', 'push', 'put-url', 'pv', 'quote?', 'quote', 'rand',
  1923. 'random', 'randomize', 'read', 'read-char', 'read-expr', 'read-file',
  1924. 'read-key', 'read-line', 'read-utf8', 'read', 'reader-event',
  1925. 'real-path', 'receive', 'ref-all', 'ref', 'regex-comp', 'regex',
  1926. 'remove-dir', 'rename-file', 'replace', 'reset', 'rest', 'reverse',
  1927. 'rotate', 'round', 'save', 'search', 'seed', 'seek', 'select', 'self',
  1928. 'semaphore', 'send', 'sequence', 'series', 'set-locale', 'set-ref-all',
  1929. 'set-ref', 'set', 'setf', 'setq', 'sgn', 'share', 'signal', 'silent',
  1930. 'sin', 'sinh', 'sleep', 'slice', 'sort', 'source', 'spawn', 'sqrt',
  1931. 'starts-with', 'string?', 'string', 'sub', 'swap', 'sym', 'symbol?',
  1932. 'symbols', 'sync', 'sys-error', 'sys-info', 'tan', 'tanh', 'term',
  1933. 'throw-error', 'throw', 'time-of-day', 'time', 'timer', 'title-case',
  1934. 'trace-highlight', 'trace', 'transpose', 'Tree', 'trim', 'true?',
  1935. 'true', 'unicode', 'unify', 'unique', 'unless', 'unpack', 'until',
  1936. 'upper-case', 'utf8', 'utf8len', 'uuid', 'wait-pid', 'when', 'while',
  1937. 'write', 'write-char', 'write-file', 'write-line', 'write',
  1938. 'xfer-event', 'xml-error', 'xml-parse', 'xml-type-tags', 'zero?',
  1939. ]
  1940. # valid names
  1941. valid_name = r'([a-zA-Z0-9!$%&*+.,/<=>?@^_~|-])+|(\[.*?\])+'
  1942. tokens = {
  1943. 'root': [
  1944. # shebang
  1945. (r'#!(.*?)$', Comment.Preproc),
  1946. # comments starting with semicolon
  1947. (r';.*$', Comment.Single),
  1948. # comments starting with #
  1949. (r'#.*$', Comment.Single),
  1950. # whitespace
  1951. (r'\s+', Text),
  1952. # strings, symbols and characters
  1953. (r'"(\\\\|\\"|[^"])*"', String),
  1954. # braces
  1955. (r"{", String, "bracestring"),
  1956. # [text] ... [/text] delimited strings
  1957. (r'\[text\]*', String, "tagstring"),
  1958. # 'special' operators...
  1959. (r"('|:)", Operator),
  1960. # highlight the builtins
  1961. ('(%s)' % '|'.join(re.escape(entry) + '\\b' for entry in builtins),
  1962. Keyword),
  1963. # the remaining functions
  1964. (r'(?<=\()' + valid_name, Name.Variable),
  1965. # the remaining variables
  1966. (valid_name, String.Symbol),
  1967. # parentheses
  1968. (r'(\(|\))', Punctuation),
  1969. ],
  1970. # braced strings...
  1971. 'bracestring': [
  1972. ("{", String, "#push"),
  1973. ("}", String, "#pop"),
  1974. ("[^{}]+", String),
  1975. ],
  1976. # tagged [text]...[/text] delimited strings...
  1977. 'tagstring': [
  1978. (r'(?s)(.*?)(\[/text\])', String, '#pop'),
  1979. ],
  1980. }
  1981. class ElixirLexer(RegexLexer):
  1982. """
  1983. For the `Elixir language <http://elixir-lang.org>`_.
  1984. *New in Pygments 1.5.*
  1985. """
  1986. name = 'Elixir'
  1987. aliases = ['elixir', 'ex', 'exs']
  1988. filenames = ['*.ex', '*.exs']
  1989. mimetypes = ['text/x-elixir']
  1990. def gen_elixir_sigil_rules():
  1991. states = {}
  1992. states['strings'] = [
  1993. (r'(%[A-Ba-z])?"""(?:.|\n)*?"""', String.Doc),
  1994. (r"'''(?:.|\n)*?'''", String.Doc),
  1995. (r'"', String.Double, 'dqs'),
  1996. (r"'.*'", String.Single),
  1997. (r'(?<!\w)\?(\\(x\d{1,2}|\h{1,2}(?!\h)\b|0[0-7]{0,2}(?![0-7])\b|'
  1998. r'[^x0MC])|(\\[MC]-)+\w|[^\s\\])', String.Other)
  1999. ]
  2000. for lbrace, rbrace, name, in ('\\{', '\\}', 'cb'), \
  2001. ('\\[', '\\]', 'sb'), \
  2002. ('\\(', '\\)', 'pa'), \
  2003. ('\\<', '\\>', 'lt'):
  2004. states['strings'] += [
  2005. (r'%[a-z]' + lbrace, String.Double, name + 'intp'),
  2006. (r'%[A-Z]' + lbrace, String.Double, name + 'no-intp')
  2007. ]
  2008. states[name +'intp'] = [
  2009. (r'' + rbrace + '[a-z]*', String.Double, "#pop"),
  2010. include('enddoublestr')
  2011. ]
  2012. states[name +'no-intp'] = [
  2013. (r'.*' + rbrace + '[a-z]*', String.Double , "#pop")
  2014. ]
  2015. return states
  2016. tokens = {
  2017. 'root': [
  2018. (r'\s+', Text),
  2019. (r'#.*$', Comment.Single),
  2020. (r'\b(case|cond|end|bc|lc|if|unless|try|loop|receive|fn|defmodule|'
  2021. r'defp?|defprotocol|defimpl|defrecord|defmacrop?|defdelegate|'
  2022. r'defexception|exit|raise|throw|unless|after|rescue|catch|else)\b(?![?!])|'
  2023. r'(?<!\.)\b(do|\-\>)\b\s*', Keyword),
  2024. (r'\b(import|require|use|recur|quote|unquote|super|refer)\b(?![?!])',
  2025. Keyword.Namespace),
  2026. (r'(?<!\.)\b(and|not|or|when|xor|in)\b', Operator.Word),
  2027. (r'%=|\*=|\*\*=|\+=|\-=|\^=|\|\|=|'
  2028. r'<=>|<(?!<|=)|>(?!<|=|>)|<=|>=|===|==|=~|!=|!~|(?=[ \t])\?|'
  2029. r'(?<=[ \t])!+|&&|\|\||\^|\*|\+|\-|/|'
  2030. r'\||\+\+|\-\-|\*\*|\/\/|\<\-|\<\>|<<|>>|=|\.', Operator),
  2031. (r'(?<!:)(:)([a-zA-Z_]\w*([?!]|=(?![>=]))?|\<\>|===?|>=?|<=?|'
  2032. r'<=>|&&?|%\(\)|%\[\]|%\{\}|\+\+?|\-\-?|\|\|?|\!|//|[%&`/\|]|'
  2033. r'\*\*?|=?~|<\-)|([a-zA-Z_]\w*([?!])?)(:)(?!:)', String.Symbol),
  2034. (r':"', String.Symbol, 'interpoling_symbol'),
  2035. (r'\b(nil|true|false)\b(?![?!])|\b[A-Z]\w*\b', Name.Constant),
  2036. (r'\b(__(FILE|LINE|MODULE|MAIN|FUNCTION)__)\b(?![?!])', Name.Builtin.Pseudo),
  2037. (r'[a-zA-Z_!][\w_]*[!\?]?', Name),
  2038. (r'[(){};,/\|:\\\[\]]', Punctuation),
  2039. (r'@[a-zA-Z_]\w*|&\d', Name.Variable),
  2040. (r'\b(0[xX][0-9A-Fa-f]+|\d(_?\d)*(\.(?![^\d\s])'
  2041. r'(_?\d)*)?([eE][-+]?\d(_?\d)*)?|0[bB][01]+)\b', Number),
  2042. (r'%r\/.*\/', String.Regex),
  2043. include('strings'),
  2044. ],
  2045. 'dqs': [
  2046. (r'"', String.Double, "#pop"),
  2047. include('enddoublestr')
  2048. ],
  2049. 'interpoling': [
  2050. (r'#{', String.Interpol, 'interpoling_string'),
  2051. ],
  2052. 'interpoling_string' : [
  2053. (r'}', String.Interpol, "#pop"),
  2054. include('root')
  2055. ],
  2056. 'interpoling_symbol': [
  2057. (r'"', String.Symbol, "#pop"),
  2058. include('interpoling'),
  2059. (r'[^#"]+', String.Symbol),
  2060. ],
  2061. 'enddoublestr' : [
  2062. include('interpoling'),
  2063. (r'[^#"]+', String.Double),
  2064. ]
  2065. }
  2066. tokens.update(gen_elixir_sigil_rules())
  2067. class ElixirConsoleLexer(Lexer):
  2068. """
  2069. For Elixir interactive console (iex) output like:
  2070. .. sourcecode:: iex
  2071. iex> [head | tail] = [1,2,3]
  2072. [1,2,3]
  2073. iex> head
  2074. 1
  2075. iex> tail
  2076. [2,3]
  2077. iex> [head | tail]
  2078. [1,2,3]
  2079. iex> length [head | tail]
  2080. 3
  2081. *New in Pygments 1.5.*
  2082. """
  2083. name = 'Elixir iex session'
  2084. aliases = ['iex']
  2085. mimetypes = ['text/x-elixir-shellsession']
  2086. _prompt_re = re.compile('(iex|\.{3})> ')
  2087. def get_tokens_unprocessed(self, text):
  2088. exlexer = ElixirLexer(**self.options)
  2089. curcode = ''
  2090. insertions = []
  2091. for match in line_re.finditer(text):
  2092. line = match.group()
  2093. if line.startswith(u'** '):
  2094. insertions.append((len(curcode),
  2095. [(0, Generic.Error, line[:-1])]))
  2096. curcode += line[-1:]
  2097. else:
  2098. m = self._prompt_re.match(line)
  2099. if m is not None:
  2100. end = m.end()
  2101. insertions.append((len(curcode),
  2102. [(0, Generic.Prompt, line[:end])]))
  2103. curcode += line[end:]
  2104. else:
  2105. if curcode:
  2106. for item in do_insertions(insertions,
  2107. exlexer.get_tokens_unprocessed(curcode)):
  2108. yield item
  2109. curcode = ''
  2110. insertions = []
  2111. yield match.start(), Generic.Output, line
  2112. if curcode:
  2113. for item in do_insertions(insertions,
  2114. exlexer.get_tokens_unprocessed(curcode)):
  2115. yield item