PageRenderTime 70ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/pygments/pygments/lexers/functional.py

https://bitbucket.org/tcorll/butlertest
Python | 2597 lines | 2017 code | 217 blank | 363 comment | 25 complexity | dc4ba95035313373ea5462615f2136d3 MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0, LGPL-3.0, BSD-2-Clause

Large files files are truncated, but you can click here to view the full file

  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', 'KokaLexer']
  17. class RacketLexer(RegexLexer):
  18. """
  19. Lexer for `Racket <http://racket-lang.org/>`_ source code (formerly known as
  20. PLT Scheme).
  21. *New in Pygments 1.6.*
  22. """
  23. name = 'Racket'
  24. aliases = ['racket', 'rkt']
  25. filenames = ['*.rkt', '*.rktl']
  26. mimetypes = ['text/x-racket', 'application/x-racket']
  27. # From namespace-mapped-symbols
  28. keywords = [
  29. '#%app', '#%datum', '#%expression', '#%module-begin',
  30. '#%plain-app', '#%plain-lambda', '#%plain-module-begin',
  31. '#%provide', '#%require', '#%stratified-body', '#%top',
  32. '#%top-interaction', '#%variable-reference', '...', 'and', 'begin',
  33. 'begin-for-syntax', 'begin0', 'case', 'case-lambda', 'cond',
  34. 'datum->syntax-object', 'define', 'define-for-syntax',
  35. 'define-struct', 'define-syntax', 'define-syntax-rule',
  36. 'define-syntaxes', 'define-values', 'define-values-for-syntax',
  37. 'delay', 'do', 'expand-path', 'fluid-let', 'hash-table-copy',
  38. 'hash-table-count', 'hash-table-for-each', 'hash-table-get',
  39. 'hash-table-iterate-first', 'hash-table-iterate-key',
  40. 'hash-table-iterate-next', 'hash-table-iterate-value',
  41. 'hash-table-map', 'hash-table-put!', 'hash-table-remove!',
  42. 'hash-table?', 'if', 'lambda', 'let', 'let*', 'let*-values',
  43. 'let-struct', 'let-syntax', 'let-syntaxes', 'let-values', 'let/cc',
  44. 'let/ec', 'letrec', 'letrec-syntax', 'letrec-syntaxes',
  45. 'letrec-syntaxes+values', 'letrec-values', 'list-immutable',
  46. 'make-hash-table', 'make-immutable-hash-table', 'make-namespace',
  47. 'module', 'module-identifier=?', 'module-label-identifier=?',
  48. 'module-template-identifier=?', 'module-transformer-identifier=?',
  49. 'namespace-transformer-require', 'or', 'parameterize',
  50. 'parameterize*', 'parameterize-break', 'provide',
  51. 'provide-for-label', 'provide-for-syntax', 'quasiquote',
  52. 'quasisyntax', 'quasisyntax/loc', 'quote', 'quote-syntax',
  53. 'quote-syntax/prune', 'require', 'require-for-label',
  54. 'require-for-syntax', 'require-for-template', 'set!',
  55. 'set!-values', 'syntax', 'syntax-case', 'syntax-case*',
  56. 'syntax-id-rules', 'syntax-object->datum', 'syntax-rules',
  57. 'syntax/loc', 'time', 'transcript-off', 'transcript-on', 'unless',
  58. 'unquote', 'unquote-splicing', 'unsyntax', 'unsyntax-splicing',
  59. 'when', 'with-continuation-mark', 'with-handlers',
  60. 'with-handlers*', 'with-syntax', 'λ'
  61. ]
  62. # From namespace-mapped-symbols
  63. builtins = [
  64. '*', '+', '-', '/', '<', '<=', '=', '>', '>=',
  65. 'abort-current-continuation', 'abs', 'absolute-path?', 'acos',
  66. 'add1', 'alarm-evt', 'always-evt', 'andmap', 'angle', 'append',
  67. 'apply', 'arithmetic-shift', 'arity-at-least',
  68. 'arity-at-least-value', 'arity-at-least?', 'asin', 'assoc', 'assq',
  69. 'assv', 'atan', 'banner', 'bitwise-and', 'bitwise-bit-field',
  70. 'bitwise-bit-set?', 'bitwise-ior', 'bitwise-not', 'bitwise-xor',
  71. 'boolean?', 'bound-identifier=?', 'box', 'box-immutable', 'box?',
  72. 'break-enabled', 'break-thread', 'build-path',
  73. 'build-path/convention-type', 'byte-pregexp', 'byte-pregexp?',
  74. 'byte-ready?', 'byte-regexp', 'byte-regexp?', 'byte?', 'bytes',
  75. 'bytes->immutable-bytes', 'bytes->list', 'bytes->path',
  76. 'bytes->path-element', 'bytes->string/latin-1',
  77. 'bytes->string/locale', 'bytes->string/utf-8', 'bytes-append',
  78. 'bytes-close-converter', 'bytes-convert', 'bytes-convert-end',
  79. 'bytes-converter?', 'bytes-copy', 'bytes-copy!', 'bytes-fill!',
  80. 'bytes-length', 'bytes-open-converter', 'bytes-ref', 'bytes-set!',
  81. 'bytes-utf-8-index', 'bytes-utf-8-length', 'bytes-utf-8-ref',
  82. 'bytes<?', 'bytes=?', 'bytes>?', 'bytes?', 'caaaar', 'caaadr',
  83. 'caaar', 'caadar', 'caaddr', 'caadr', 'caar', 'cadaar', 'cadadr',
  84. 'cadar', 'caddar', 'cadddr', 'caddr', 'cadr',
  85. 'call-in-nested-thread', 'call-with-break-parameterization',
  86. 'call-with-composable-continuation',
  87. 'call-with-continuation-barrier', 'call-with-continuation-prompt',
  88. 'call-with-current-continuation', 'call-with-escape-continuation',
  89. 'call-with-exception-handler',
  90. 'call-with-immediate-continuation-mark', 'call-with-input-file',
  91. 'call-with-output-file', 'call-with-parameterization',
  92. 'call-with-semaphore', 'call-with-semaphore/enable-break',
  93. 'call-with-values', 'call/cc', 'call/ec', 'car', 'cdaaar',
  94. 'cdaadr', 'cdaar', 'cdadar', 'cdaddr', 'cdadr', 'cdar', 'cddaar',
  95. 'cddadr', 'cddar', 'cdddar', 'cddddr', 'cdddr', 'cddr', 'cdr',
  96. 'ceiling', 'channel-get', 'channel-put', 'channel-put-evt',
  97. 'channel-try-get', 'channel?', 'chaperone-box', 'chaperone-evt',
  98. 'chaperone-hash', 'chaperone-of?', 'chaperone-procedure',
  99. 'chaperone-struct', 'chaperone-struct-type', 'chaperone-vector',
  100. 'chaperone?', 'char->integer', 'char-alphabetic?', 'char-blank?',
  101. 'char-ci<=?', 'char-ci<?', 'char-ci=?', 'char-ci>=?', 'char-ci>?',
  102. 'char-downcase', 'char-foldcase', 'char-general-category',
  103. 'char-graphic?', 'char-iso-control?', 'char-lower-case?',
  104. 'char-numeric?', 'char-punctuation?', 'char-ready?',
  105. 'char-symbolic?', 'char-title-case?', 'char-titlecase',
  106. 'char-upcase', 'char-upper-case?', 'char-utf-8-length',
  107. 'char-whitespace?', 'char<=?', 'char<?', 'char=?', 'char>=?',
  108. 'char>?', 'char?', 'check-duplicate-identifier',
  109. 'checked-procedure-check-and-extract', 'choice-evt',
  110. 'cleanse-path', 'close-input-port', 'close-output-port',
  111. 'collect-garbage', 'collection-file-path', 'collection-path',
  112. 'compile', 'compile-allow-set!-undefined',
  113. 'compile-context-preservation-enabled',
  114. 'compile-enforce-module-constants', 'compile-syntax',
  115. 'compiled-expression?', 'compiled-module-expression?',
  116. 'complete-path?', 'complex?', 'cons',
  117. 'continuation-mark-set->context', 'continuation-mark-set->list',
  118. 'continuation-mark-set->list*', 'continuation-mark-set-first',
  119. 'continuation-mark-set?', 'continuation-marks',
  120. 'continuation-prompt-available?', 'continuation-prompt-tag?',
  121. 'continuation?', 'copy-file', 'cos',
  122. 'current-break-parameterization', 'current-code-inspector',
  123. 'current-command-line-arguments', 'current-compile',
  124. 'current-continuation-marks', 'current-custodian',
  125. 'current-directory', 'current-drive', 'current-error-port',
  126. 'current-eval', 'current-evt-pseudo-random-generator',
  127. 'current-gc-milliseconds', 'current-get-interaction-input-port',
  128. 'current-inexact-milliseconds', 'current-input-port',
  129. 'current-inspector', 'current-library-collection-paths',
  130. 'current-load', 'current-load-extension',
  131. 'current-load-relative-directory', 'current-load/use-compiled',
  132. 'current-locale', 'current-memory-use', 'current-milliseconds',
  133. 'current-module-declare-name', 'current-module-declare-source',
  134. 'current-module-name-resolver', 'current-namespace',
  135. 'current-output-port', 'current-parameterization',
  136. 'current-preserved-thread-cell-values', 'current-print',
  137. 'current-process-milliseconds', 'current-prompt-read',
  138. 'current-pseudo-random-generator', 'current-read-interaction',
  139. 'current-reader-guard', 'current-readtable', 'current-seconds',
  140. 'current-security-guard', 'current-subprocess-custodian-mode',
  141. 'current-thread', 'current-thread-group',
  142. 'current-thread-initial-stack-size',
  143. 'current-write-relative-directory', 'custodian-box-value',
  144. 'custodian-box?', 'custodian-limit-memory',
  145. 'custodian-managed-list', 'custodian-memory-accounting-available?',
  146. 'custodian-require-memory', 'custodian-shutdown-all', 'custodian?',
  147. 'custom-print-quotable-accessor', 'custom-print-quotable?',
  148. 'custom-write-accessor', 'custom-write?', 'date', 'date*',
  149. 'date*-nanosecond', 'date*-time-zone-name', 'date*?', 'date-day',
  150. 'date-dst?', 'date-hour', 'date-minute', 'date-month',
  151. 'date-second', 'date-time-zone-offset', 'date-week-day',
  152. 'date-year', 'date-year-day', 'date?', 'datum-intern-literal',
  153. 'default-continuation-prompt-tag', 'delete-directory',
  154. 'delete-file', 'denominator', 'directory-exists?',
  155. 'directory-list', 'display', 'displayln', 'dump-memory-stats',
  156. 'dynamic-require', 'dynamic-require-for-syntax', 'dynamic-wind',
  157. 'eof', 'eof-object?', 'ephemeron-value', 'ephemeron?', 'eprintf',
  158. 'eq-hash-code', 'eq?', 'equal-hash-code',
  159. 'equal-secondary-hash-code', 'equal?', 'equal?/recur',
  160. 'eqv-hash-code', 'eqv?', 'error', 'error-display-handler',
  161. 'error-escape-handler', 'error-print-context-length',
  162. 'error-print-source-location', 'error-print-width',
  163. 'error-value->string-handler', 'eval', 'eval-jit-enabled',
  164. 'eval-syntax', 'even?', 'evt?', 'exact->inexact', 'exact-integer?',
  165. 'exact-nonnegative-integer?', 'exact-positive-integer?', 'exact?',
  166. 'executable-yield-handler', 'exit', 'exit-handler', 'exn',
  167. 'exn-continuation-marks', 'exn-message', 'exn:break',
  168. 'exn:break-continuation', 'exn:break?', 'exn:fail',
  169. 'exn:fail:contract', 'exn:fail:contract:arity',
  170. 'exn:fail:contract:arity?', 'exn:fail:contract:continuation',
  171. 'exn:fail:contract:continuation?',
  172. 'exn:fail:contract:divide-by-zero',
  173. 'exn:fail:contract:divide-by-zero?',
  174. 'exn:fail:contract:non-fixnum-result',
  175. 'exn:fail:contract:non-fixnum-result?',
  176. 'exn:fail:contract:variable', 'exn:fail:contract:variable-id',
  177. 'exn:fail:contract:variable?', 'exn:fail:contract?',
  178. 'exn:fail:filesystem', 'exn:fail:filesystem:exists',
  179. 'exn:fail:filesystem:exists?', 'exn:fail:filesystem:version',
  180. 'exn:fail:filesystem:version?', 'exn:fail:filesystem?',
  181. 'exn:fail:network', 'exn:fail:network?', 'exn:fail:out-of-memory',
  182. 'exn:fail:out-of-memory?', 'exn:fail:read',
  183. 'exn:fail:read-srclocs', 'exn:fail:read:eof', 'exn:fail:read:eof?',
  184. 'exn:fail:read:non-char', 'exn:fail:read:non-char?',
  185. 'exn:fail:read?', 'exn:fail:syntax', 'exn:fail:syntax-exprs',
  186. 'exn:fail:syntax:unbound', 'exn:fail:syntax:unbound?',
  187. 'exn:fail:syntax?', 'exn:fail:unsupported',
  188. 'exn:fail:unsupported?', 'exn:fail:user', 'exn:fail:user?',
  189. 'exn:fail?', 'exn:srclocs-accessor', 'exn:srclocs?', 'exn?', 'exp',
  190. 'expand', 'expand-once', 'expand-syntax', 'expand-syntax-once',
  191. 'expand-syntax-to-top-form', 'expand-to-top-form',
  192. 'expand-user-path', 'expt', 'file-exists?',
  193. 'file-or-directory-identity', 'file-or-directory-modify-seconds',
  194. 'file-or-directory-permissions', 'file-position', 'file-size',
  195. 'file-stream-buffer-mode', 'file-stream-port?',
  196. 'filesystem-root-list', 'find-executable-path',
  197. 'find-library-collection-paths', 'find-system-path', 'fixnum?',
  198. 'floating-point-bytes->real', 'flonum?', 'floor', 'flush-output',
  199. 'for-each', 'force', 'format', 'fprintf', 'free-identifier=?',
  200. 'gcd', 'generate-temporaries', 'gensym', 'get-output-bytes',
  201. 'get-output-string', 'getenv', 'global-port-print-handler',
  202. 'guard-evt', 'handle-evt', 'handle-evt?', 'hash', 'hash-equal?',
  203. 'hash-eqv?', 'hash-has-key?', 'hash-placeholder?', 'hash-ref!',
  204. 'hasheq', 'hasheqv', 'identifier-binding',
  205. 'identifier-label-binding', 'identifier-prune-lexical-context',
  206. 'identifier-prune-to-source-module',
  207. 'identifier-remove-from-definition-context',
  208. 'identifier-template-binding', 'identifier-transformer-binding',
  209. 'identifier?', 'imag-part', 'immutable?', 'impersonate-box',
  210. 'impersonate-hash', 'impersonate-procedure', 'impersonate-struct',
  211. 'impersonate-vector', 'impersonator-of?',
  212. 'impersonator-prop:application-mark',
  213. 'impersonator-property-accessor-procedure?',
  214. 'impersonator-property?', 'impersonator?', 'inexact->exact',
  215. 'inexact-real?', 'inexact?', 'input-port?', 'inspector?',
  216. 'integer->char', 'integer->integer-bytes',
  217. 'integer-bytes->integer', 'integer-length', 'integer-sqrt',
  218. 'integer-sqrt/remainder', 'integer?',
  219. 'internal-definition-context-seal', 'internal-definition-context?',
  220. 'keyword->string', 'keyword<?', 'keyword?', 'kill-thread', 'lcm',
  221. 'length', 'liberal-define-context?', 'link-exists?', 'list',
  222. 'list*', 'list->bytes', 'list->string', 'list->vector', 'list-ref',
  223. 'list-tail', 'list?', 'load', 'load-extension',
  224. 'load-on-demand-enabled', 'load-relative',
  225. 'load-relative-extension', 'load/cd', 'load/use-compiled',
  226. 'local-expand', 'local-expand/capture-lifts',
  227. 'local-transformer-expand',
  228. 'local-transformer-expand/capture-lifts', 'locale-string-encoding',
  229. 'log', 'magnitude', 'make-arity-at-least', 'make-bytes',
  230. 'make-channel', 'make-continuation-prompt-tag', 'make-custodian',
  231. 'make-custodian-box', 'make-date', 'make-date*',
  232. 'make-derived-parameter', 'make-directory', 'make-ephemeron',
  233. 'make-exn', 'make-exn:break', 'make-exn:fail',
  234. 'make-exn:fail:contract', 'make-exn:fail:contract:arity',
  235. 'make-exn:fail:contract:continuation',
  236. 'make-exn:fail:contract:divide-by-zero',
  237. 'make-exn:fail:contract:non-fixnum-result',
  238. 'make-exn:fail:contract:variable', 'make-exn:fail:filesystem',
  239. 'make-exn:fail:filesystem:exists',
  240. 'make-exn:fail:filesystem:version', 'make-exn:fail:network',
  241. 'make-exn:fail:out-of-memory', 'make-exn:fail:read',
  242. 'make-exn:fail:read:eof', 'make-exn:fail:read:non-char',
  243. 'make-exn:fail:syntax', 'make-exn:fail:syntax:unbound',
  244. 'make-exn:fail:unsupported', 'make-exn:fail:user',
  245. 'make-file-or-directory-link', 'make-hash-placeholder',
  246. 'make-hasheq-placeholder', 'make-hasheqv',
  247. 'make-hasheqv-placeholder', 'make-immutable-hasheqv',
  248. 'make-impersonator-property', 'make-input-port', 'make-inspector',
  249. 'make-known-char-range-list', 'make-output-port', 'make-parameter',
  250. 'make-pipe', 'make-placeholder', 'make-polar',
  251. 'make-prefab-struct', 'make-pseudo-random-generator',
  252. 'make-reader-graph', 'make-readtable', 'make-rectangular',
  253. 'make-rename-transformer', 'make-resolved-module-path',
  254. 'make-security-guard', 'make-semaphore', 'make-set!-transformer',
  255. 'make-shared-bytes', 'make-sibling-inspector',
  256. 'make-special-comment', 'make-srcloc', 'make-string',
  257. 'make-struct-field-accessor', 'make-struct-field-mutator',
  258. 'make-struct-type', 'make-struct-type-property',
  259. 'make-syntax-delta-introducer', 'make-syntax-introducer',
  260. 'make-thread-cell', 'make-thread-group', 'make-vector',
  261. 'make-weak-box', 'make-weak-hasheqv', 'make-will-executor', 'map',
  262. 'max', 'mcar', 'mcdr', 'mcons', 'member', 'memq', 'memv', 'min',
  263. 'module->exports', 'module->imports', 'module->language-info',
  264. 'module->namespace', 'module-compiled-exports',
  265. 'module-compiled-imports', 'module-compiled-language-info',
  266. 'module-compiled-name', 'module-path-index-join',
  267. 'module-path-index-resolve', 'module-path-index-split',
  268. 'module-path-index?', 'module-path?', 'module-predefined?',
  269. 'module-provide-protected?', 'modulo', 'mpair?', 'nack-guard-evt',
  270. 'namespace-attach-module', 'namespace-attach-module-declaration',
  271. 'namespace-base-phase', 'namespace-mapped-symbols',
  272. 'namespace-module-identifier', 'namespace-module-registry',
  273. 'namespace-require', 'namespace-require/constant',
  274. 'namespace-require/copy', 'namespace-require/expansion-time',
  275. 'namespace-set-variable-value!', 'namespace-symbol->identifier',
  276. 'namespace-syntax-introduce', 'namespace-undefine-variable!',
  277. 'namespace-unprotect-module', 'namespace-variable-value',
  278. 'namespace?', 'negative?', 'never-evt', 'newline',
  279. 'normal-case-path', 'not', 'null', 'null?', 'number->string',
  280. 'number?', 'numerator', 'object-name', 'odd?', 'open-input-bytes',
  281. 'open-input-file', 'open-input-output-file', 'open-input-string',
  282. 'open-output-bytes', 'open-output-file', 'open-output-string',
  283. 'ormap', 'output-port?', 'pair?', 'parameter-procedure=?',
  284. 'parameter?', 'parameterization?', 'path->bytes',
  285. 'path->complete-path', 'path->directory-path', 'path->string',
  286. 'path-add-suffix', 'path-convention-type', 'path-element->bytes',
  287. 'path-element->string', 'path-for-some-system?',
  288. 'path-list-string->path-list', 'path-replace-suffix',
  289. 'path-string?', 'path?', 'peek-byte', 'peek-byte-or-special',
  290. 'peek-bytes', 'peek-bytes!', 'peek-bytes-avail!',
  291. 'peek-bytes-avail!*', 'peek-bytes-avail!/enable-break',
  292. 'peek-char', 'peek-char-or-special', 'peek-string', 'peek-string!',
  293. 'pipe-content-length', 'placeholder-get', 'placeholder-set!',
  294. 'placeholder?', 'poll-guard-evt', 'port-closed-evt',
  295. 'port-closed?', 'port-commit-peeked', 'port-count-lines!',
  296. 'port-count-lines-enabled', 'port-display-handler',
  297. 'port-file-identity', 'port-file-unlock', 'port-next-location',
  298. 'port-print-handler', 'port-progress-evt',
  299. 'port-provides-progress-evts?', 'port-read-handler',
  300. 'port-try-file-lock?', 'port-write-handler', 'port-writes-atomic?',
  301. 'port-writes-special?', 'port?', 'positive?',
  302. 'prefab-key->struct-type', 'prefab-struct-key', 'pregexp',
  303. 'pregexp?', 'primitive-closure?', 'primitive-result-arity',
  304. 'primitive?', 'print', 'print-as-expression',
  305. 'print-boolean-long-form', 'print-box', 'print-graph',
  306. 'print-hash-table', 'print-mpair-curly-braces',
  307. 'print-pair-curly-braces', 'print-reader-abbreviations',
  308. 'print-struct', 'print-syntax-width', 'print-unreadable',
  309. 'print-vector-length', 'printf', 'procedure->method',
  310. 'procedure-arity', 'procedure-arity-includes?', 'procedure-arity?',
  311. 'procedure-closure-contents-eq?', 'procedure-extract-target',
  312. 'procedure-reduce-arity', 'procedure-rename',
  313. 'procedure-struct-type?', 'procedure?', 'promise?',
  314. 'prop:arity-string', 'prop:checked-procedure',
  315. 'prop:custom-print-quotable', 'prop:custom-write',
  316. 'prop:equal+hash', 'prop:evt', 'prop:exn:srclocs',
  317. 'prop:impersonator-of', 'prop:input-port',
  318. 'prop:liberal-define-context', 'prop:output-port',
  319. 'prop:procedure', 'prop:rename-transformer',
  320. 'prop:set!-transformer', 'pseudo-random-generator->vector',
  321. 'pseudo-random-generator-vector?', 'pseudo-random-generator?',
  322. 'putenv', 'quotient', 'quotient/remainder', 'raise',
  323. 'raise-arity-error', 'raise-mismatch-error', 'raise-syntax-error',
  324. 'raise-type-error', 'raise-user-error', 'random', 'random-seed',
  325. 'rational?', 'rationalize', 'read', 'read-accept-bar-quote',
  326. 'read-accept-box', 'read-accept-compiled', 'read-accept-dot',
  327. 'read-accept-graph', 'read-accept-infix-dot', 'read-accept-lang',
  328. 'read-accept-quasiquote', 'read-accept-reader', 'read-byte',
  329. 'read-byte-or-special', 'read-bytes', 'read-bytes!',
  330. 'read-bytes-avail!', 'read-bytes-avail!*',
  331. 'read-bytes-avail!/enable-break', 'read-bytes-line',
  332. 'read-case-sensitive', 'read-char', 'read-char-or-special',
  333. 'read-curly-brace-as-paren', 'read-decimal-as-inexact',
  334. 'read-eval-print-loop', 'read-language', 'read-line',
  335. 'read-on-demand-source', 'read-square-bracket-as-paren',
  336. 'read-string', 'read-string!', 'read-syntax',
  337. 'read-syntax/recursive', 'read/recursive', 'readtable-mapping',
  338. 'readtable?', 'real->double-flonum', 'real->floating-point-bytes',
  339. 'real->single-flonum', 'real-part', 'real?', 'regexp',
  340. 'regexp-match', 'regexp-match-peek', 'regexp-match-peek-immediate',
  341. 'regexp-match-peek-positions',
  342. 'regexp-match-peek-positions-immediate',
  343. 'regexp-match-peek-positions-immediate/end',
  344. 'regexp-match-peek-positions/end', 'regexp-match-positions',
  345. 'regexp-match-positions/end', 'regexp-match/end', 'regexp-match?',
  346. 'regexp-max-lookbehind', 'regexp-replace', 'regexp-replace*',
  347. 'regexp?', 'relative-path?', 'remainder',
  348. 'rename-file-or-directory', 'rename-transformer-target',
  349. 'rename-transformer?', 'resolve-path', 'resolved-module-path-name',
  350. 'resolved-module-path?', 'reverse', 'round', 'seconds->date',
  351. 'security-guard?', 'semaphore-peek-evt', 'semaphore-post',
  352. 'semaphore-try-wait?', 'semaphore-wait',
  353. 'semaphore-wait/enable-break', 'semaphore?',
  354. 'set!-transformer-procedure', 'set!-transformer?', 'set-box!',
  355. 'set-mcar!', 'set-mcdr!', 'set-port-next-location!',
  356. 'shared-bytes', 'shell-execute', 'simplify-path', 'sin',
  357. 'single-flonum?', 'sleep', 'special-comment-value',
  358. 'special-comment?', 'split-path', 'sqrt', 'srcloc',
  359. 'srcloc-column', 'srcloc-line', 'srcloc-position', 'srcloc-source',
  360. 'srcloc-span', 'srcloc?', 'string', 'string->bytes/latin-1',
  361. 'string->bytes/locale', 'string->bytes/utf-8',
  362. 'string->immutable-string', 'string->keyword', 'string->list',
  363. 'string->number', 'string->path', 'string->path-element',
  364. 'string->symbol', 'string->uninterned-symbol',
  365. 'string->unreadable-symbol', 'string-append', 'string-ci<=?',
  366. 'string-ci<?', 'string-ci=?', 'string-ci>=?', 'string-ci>?',
  367. 'string-copy', 'string-copy!', 'string-downcase', 'string-fill!',
  368. 'string-foldcase', 'string-length', 'string-locale-ci<?',
  369. 'string-locale-ci=?', 'string-locale-ci>?',
  370. 'string-locale-downcase', 'string-locale-upcase',
  371. 'string-locale<?', 'string-locale=?', 'string-locale>?',
  372. 'string-normalize-nfc', 'string-normalize-nfd',
  373. 'string-normalize-nfkc', 'string-normalize-nfkd', 'string-ref',
  374. 'string-set!', 'string-titlecase', 'string-upcase',
  375. 'string-utf-8-length', 'string<=?', 'string<?', 'string=?',
  376. 'string>=?', 'string>?', 'string?', 'struct->vector',
  377. 'struct-accessor-procedure?', 'struct-constructor-procedure?',
  378. 'struct-info', 'struct-mutator-procedure?',
  379. 'struct-predicate-procedure?', 'struct-type-info',
  380. 'struct-type-make-constructor', 'struct-type-make-predicate',
  381. 'struct-type-property-accessor-procedure?',
  382. 'struct-type-property?', 'struct-type?', 'struct:arity-at-least',
  383. 'struct:date', 'struct:date*', 'struct:exn', 'struct:exn:break',
  384. 'struct:exn:fail', 'struct:exn:fail:contract',
  385. 'struct:exn:fail:contract:arity',
  386. 'struct:exn:fail:contract:continuation',
  387. 'struct:exn:fail:contract:divide-by-zero',
  388. 'struct:exn:fail:contract:non-fixnum-result',
  389. 'struct:exn:fail:contract:variable', 'struct:exn:fail:filesystem',
  390. 'struct:exn:fail:filesystem:exists',
  391. 'struct:exn:fail:filesystem:version', 'struct:exn:fail:network',
  392. 'struct:exn:fail:out-of-memory', 'struct:exn:fail:read',
  393. 'struct:exn:fail:read:eof', 'struct:exn:fail:read:non-char',
  394. 'struct:exn:fail:syntax', 'struct:exn:fail:syntax:unbound',
  395. 'struct:exn:fail:unsupported', 'struct:exn:fail:user',
  396. 'struct:srcloc', 'struct?', 'sub1', 'subbytes', 'subprocess',
  397. 'subprocess-group-enabled', 'subprocess-kill', 'subprocess-pid',
  398. 'subprocess-status', 'subprocess-wait', 'subprocess?', 'substring',
  399. 'symbol->string', 'symbol-interned?', 'symbol-unreadable?',
  400. 'symbol?', 'sync', 'sync/enable-break', 'sync/timeout',
  401. 'sync/timeout/enable-break', 'syntax->list', 'syntax-arm',
  402. 'syntax-column', 'syntax-disarm', 'syntax-e', 'syntax-line',
  403. 'syntax-local-bind-syntaxes', 'syntax-local-certifier',
  404. 'syntax-local-context', 'syntax-local-expand-expression',
  405. 'syntax-local-get-shadower', 'syntax-local-introduce',
  406. 'syntax-local-lift-context', 'syntax-local-lift-expression',
  407. 'syntax-local-lift-module-end-declaration',
  408. 'syntax-local-lift-provide', 'syntax-local-lift-require',
  409. 'syntax-local-lift-values-expression',
  410. 'syntax-local-make-definition-context',
  411. 'syntax-local-make-delta-introducer',
  412. 'syntax-local-module-defined-identifiers',
  413. 'syntax-local-module-exports',
  414. 'syntax-local-module-required-identifiers', 'syntax-local-name',
  415. 'syntax-local-phase-level',
  416. 'syntax-local-transforming-module-provides?', 'syntax-local-value',
  417. 'syntax-local-value/immediate', 'syntax-original?',
  418. 'syntax-position', 'syntax-property',
  419. 'syntax-property-symbol-keys', 'syntax-protect', 'syntax-rearm',
  420. 'syntax-recertify', 'syntax-shift-phase-level', 'syntax-source',
  421. 'syntax-source-module', 'syntax-span', 'syntax-taint',
  422. 'syntax-tainted?', 'syntax-track-origin',
  423. 'syntax-transforming-module-expression?', 'syntax-transforming?',
  424. 'syntax?', 'system-big-endian?', 'system-idle-evt',
  425. 'system-language+country', 'system-library-subpath',
  426. 'system-path-convention-type', 'system-type', 'tan',
  427. 'tcp-abandon-port', 'tcp-accept', 'tcp-accept-evt',
  428. 'tcp-accept-ready?', 'tcp-accept/enable-break', 'tcp-addresses',
  429. 'tcp-close', 'tcp-connect', 'tcp-connect/enable-break',
  430. 'tcp-listen', 'tcp-listener?', 'tcp-port?', 'terminal-port?',
  431. 'thread', 'thread-cell-ref', 'thread-cell-set!', 'thread-cell?',
  432. 'thread-dead-evt', 'thread-dead?', 'thread-group?',
  433. 'thread-resume', 'thread-resume-evt', 'thread-rewind-receive',
  434. 'thread-running?', 'thread-suspend', 'thread-suspend-evt',
  435. 'thread-wait', 'thread/suspend-to-kill', 'thread?', 'time-apply',
  436. 'truncate', 'udp-addresses', 'udp-bind!', 'udp-bound?',
  437. 'udp-close', 'udp-connect!', 'udp-connected?', 'udp-open-socket',
  438. 'udp-receive!', 'udp-receive!*', 'udp-receive!-evt',
  439. 'udp-receive!/enable-break', 'udp-receive-ready-evt', 'udp-send',
  440. 'udp-send*', 'udp-send-evt', 'udp-send-ready-evt', 'udp-send-to',
  441. 'udp-send-to*', 'udp-send-to-evt', 'udp-send-to/enable-break',
  442. 'udp-send/enable-break', 'udp?', 'unbox',
  443. 'uncaught-exception-handler', 'use-collection-link-paths',
  444. 'use-compiled-file-paths', 'use-user-specific-search-paths',
  445. 'values', 'variable-reference->empty-namespace',
  446. 'variable-reference->module-base-phase',
  447. 'variable-reference->module-declaration-inspector',
  448. 'variable-reference->module-source',
  449. 'variable-reference->namespace', 'variable-reference->phase',
  450. 'variable-reference->resolved-module-path',
  451. 'variable-reference-constant?', 'variable-reference?', 'vector',
  452. 'vector->immutable-vector', 'vector->list',
  453. 'vector->pseudo-random-generator',
  454. 'vector->pseudo-random-generator!', 'vector->values',
  455. 'vector-fill!', 'vector-immutable', 'vector-length', 'vector-ref',
  456. 'vector-set!', 'vector-set-performance-stats!', 'vector?',
  457. 'version', 'void', 'void?', 'weak-box-value', 'weak-box?',
  458. 'will-execute', 'will-executor?', 'will-register',
  459. 'will-try-execute', 'with-input-from-file', 'with-output-to-file',
  460. 'wrap-evt', 'write', 'write-byte', 'write-bytes',
  461. 'write-bytes-avail', 'write-bytes-avail*', 'write-bytes-avail-evt',
  462. 'write-bytes-avail/enable-break', 'write-char', 'write-special',
  463. 'write-special-avail*', 'write-special-evt', 'write-string', 'zero?'
  464. ]
  465. # From SchemeLexer
  466. valid_name = r'[a-zA-Z0-9!$%&*+,/:<=>?@^_~|-]+'
  467. tokens = {
  468. 'root' : [
  469. (r';.*$', Comment.Single),
  470. (r'#\|[^|]+\|#', Comment.Multiline),
  471. # whitespaces - usually not relevant
  472. (r'\s+', Text),
  473. ## numbers: Keep in mind Racket reader hash prefixes,
  474. ## which can denote the base or the type. These don't map
  475. ## neatly onto pygments token types; some judgment calls
  476. ## here. Note that none of these regexps attempt to
  477. ## exclude identifiers that start with a number, such as a
  478. ## variable named "100-Continue".
  479. # #b
  480. (r'#b[-+]?[01]+\.[01]+', Number.Float),
  481. (r'#b[01]+e[-+]?[01]+', Number.Float),
  482. (r'#b[-+]?[01]/[01]+', Number),
  483. (r'#b[-+]?[01]+', Number.Integer),
  484. (r'#b\S*', Error),
  485. # #d OR no hash prefix
  486. (r'(#d)?[-+]?\d+\.\d+', Number.Float),
  487. (r'(#d)?\d+e[-+]?\d+', Number.Float),
  488. (r'(#d)?[-+]?\d+/\d+', Number),
  489. (r'(#d)?[-+]?\d+', Number.Integer),
  490. (r'#d\S*', Error),
  491. # #e
  492. (r'#e[-+]?\d+\.\d+', Number.Float),
  493. (r'#e\d+e[-+]?\d+', Number.Float),
  494. (r'#e[-+]?\d+/\d+', Number),
  495. (r'#e[-+]?\d+', Number),
  496. (r'#e\S*', Error),
  497. # #i is always inexact-real, i.e. float
  498. (r'#i[-+]?\d+\.\d+', Number.Float),
  499. (r'#i\d+e[-+]?\d+', Number.Float),
  500. (r'#i[-+]?\d+/\d+', Number.Float),
  501. (r'#i[-+]?\d+', Number.Float),
  502. (r'#i\S*', Error),
  503. # #o
  504. (r'#o[-+]?[0-7]+\.[0-7]+', Number.Oct),
  505. (r'#o[0-7]+e[-+]?[0-7]+', Number.Oct),
  506. (r'#o[-+]?[0-7]+/[0-7]+', Number.Oct),
  507. (r'#o[-+]?[0-7]+', Number.Oct),
  508. (r'#o\S*', Error),
  509. # #x
  510. (r'#x[-+]?[0-9a-fA-F]+\.[0-9a-fA-F]+', Number.Hex),
  511. # the exponent variation (e.g. #x1e1) is N/A
  512. (r'#x[-+]?[0-9a-fA-F]+/[0-9a-fA-F]+', Number.Hex),
  513. (r'#x[-+]?[0-9a-fA-F]+', Number.Hex),
  514. (r'#x\S*', Error),
  515. # strings, symbols and characters
  516. (r'"(\\\\|\\"|[^"])*"', String),
  517. (r"'" + valid_name, String.Symbol),
  518. (r"#\\([()/'\"._!§$%& ?=+-]{1}|[a-zA-Z0-9]+)", String.Char),
  519. (r'#rx".+"', String.Regex),
  520. (r'#px".+"', String.Regex),
  521. # constants
  522. (r'(#t|#f)', Name.Constant),
  523. # keyword argument names (e.g. #:keyword)
  524. (r'#:\S+', Keyword.Declaration),
  525. # #lang
  526. (r'#lang \S+', Keyword.Namespace),
  527. # special operators
  528. (r"('|#|`|,@|,|\.)", Operator),
  529. # highlight the keywords
  530. ('(%s)' % '|'.join([
  531. re.escape(entry) + ' ' for entry in keywords]),
  532. Keyword
  533. ),
  534. # first variable in a quoted string like
  535. # '(this is syntactic sugar)
  536. (r"(?<='\()" + valid_name, Name.Variable),
  537. (r"(?<=#\()" + valid_name, Name.Variable),
  538. # highlight the builtins
  539. ("(?<=\()(%s)" % '|'.join([
  540. re.escape(entry) + ' ' for entry in builtins]),
  541. Name.Builtin
  542. ),
  543. # the remaining functions; handle both ( and [
  544. (r'(?<=(\(|\[|\{))' + valid_name, Name.Function),
  545. # find the remaining variables
  546. (valid_name, Name.Variable),
  547. # the famous parentheses!
  548. (r'(\(|\)|\[|\]|\{|\})', Punctuation),
  549. ],
  550. }
  551. class SchemeLexer(RegexLexer):
  552. """
  553. A Scheme lexer, parsing a stream and outputting the tokens
  554. needed to highlight scheme code.
  555. This lexer could be most probably easily subclassed to parse
  556. other LISP-Dialects like Common Lisp, Emacs Lisp or AutoLisp.
  557. This parser is checked with pastes from the LISP pastebin
  558. at http://paste.lisp.org/ to cover as much syntax as possible.
  559. It supports the full Scheme syntax as defined in R5RS.
  560. *New in Pygments 0.6.*
  561. """
  562. name = 'Scheme'
  563. aliases = ['scheme', 'scm']
  564. filenames = ['*.scm', '*.ss']
  565. mimetypes = ['text/x-scheme', 'application/x-scheme']
  566. # list of known keywords and builtins taken form vim 6.4 scheme.vim
  567. # syntax file.
  568. keywords = [
  569. 'lambda', 'define', 'if', 'else', 'cond', 'and', 'or', 'case', 'let',
  570. 'let*', 'letrec', 'begin', 'do', 'delay', 'set!', '=>', 'quote',
  571. 'quasiquote', 'unquote', 'unquote-splicing', 'define-syntax',
  572. 'let-syntax', 'letrec-syntax', 'syntax-rules'
  573. ]
  574. builtins = [
  575. '*', '+', '-', '/', '<', '<=', '=', '>', '>=', 'abs', 'acos', 'angle',
  576. 'append', 'apply', 'asin', 'assoc', 'assq', 'assv', 'atan',
  577. 'boolean?', 'caaaar', 'caaadr', 'caaar', 'caadar', 'caaddr', 'caadr',
  578. 'caar', 'cadaar', 'cadadr', 'cadar', 'caddar', 'cadddr', 'caddr',
  579. 'cadr', 'call-with-current-continuation', 'call-with-input-file',
  580. 'call-with-output-file', 'call-with-values', 'call/cc', 'car',
  581. 'cdaaar', 'cdaadr', 'cdaar', 'cdadar', 'cdaddr', 'cdadr', 'cdar',
  582. 'cddaar', 'cddadr', 'cddar', 'cdddar', 'cddddr', 'cdddr', 'cddr',
  583. 'cdr', 'ceiling', 'char->integer', 'char-alphabetic?', 'char-ci<=?',
  584. 'char-ci<?', 'char-ci=?', 'char-ci>=?', 'char-ci>?', 'char-downcase',
  585. 'char-lower-case?', 'char-numeric?', 'char-ready?', 'char-upcase',
  586. 'char-upper-case?', 'char-whitespace?', 'char<=?', 'char<?', 'char=?',
  587. 'char>=?', 'char>?', 'char?', 'close-input-port', 'close-output-port',
  588. 'complex?', 'cons', 'cos', 'current-input-port', 'current-output-port',
  589. 'denominator', 'display', 'dynamic-wind', 'eof-object?', 'eq?',
  590. 'equal?', 'eqv?', 'eval', 'even?', 'exact->inexact', 'exact?', 'exp',
  591. 'expt', 'floor', 'for-each', 'force', 'gcd', 'imag-part',
  592. 'inexact->exact', 'inexact?', 'input-port?', 'integer->char',
  593. 'integer?', 'interaction-environment', 'lcm', 'length', 'list',
  594. 'list->string', 'list->vector', 'list-ref', 'list-tail', 'list?',
  595. 'load', 'log', 'magnitude', 'make-polar', 'make-rectangular',
  596. 'make-string', 'make-vector', 'map', 'max', 'member', 'memq', 'memv',
  597. 'min', 'modulo', 'negative?', 'newline', 'not', 'null-environment',
  598. 'null?', 'number->string', 'number?', 'numerator', 'odd?',
  599. 'open-input-file', 'open-output-file', 'output-port?', 'pair?',
  600. 'peek-char', 'port?', 'positive?', 'procedure?', 'quotient',
  601. 'rational?', 'rationalize', 'read', 'read-char', 'real-part', 'real?',
  602. 'remainder', 'reverse', 'round', 'scheme-report-environment',
  603. 'set-car!', 'set-cdr!', 'sin', 'sqrt', 'string', 'string->list',
  604. 'string->number', 'string->symbol', 'string-append', 'string-ci<=?',
  605. 'string-ci<?', 'string-ci=?', 'string-ci>=?', 'string-ci>?',
  606. 'string-copy', 'string-fill!', 'string-length', 'string-ref',
  607. 'string-set!', 'string<=?', 'string<?', 'string=?', 'string>=?',
  608. 'string>?', 'string?', 'substring', 'symbol->string', 'symbol?',
  609. 'tan', 'transcript-off', 'transcript-on', 'truncate', 'values',
  610. 'vector', 'vector->list', 'vector-fill!', 'vector-length',
  611. 'vector-ref', 'vector-set!', 'vector?', 'with-input-from-file',
  612. 'with-output-to-file', 'write', 'write-char', 'zero?'
  613. ]
  614. # valid names for identifiers
  615. # well, names can only not consist fully of numbers
  616. # but this should be good enough for now
  617. valid_name = r'[a-zA-Z0-9!$%&*+,/:<=>?@^_~|-]+'
  618. tokens = {
  619. 'root' : [
  620. # the comments - always starting with semicolon
  621. # and going to the end of the line
  622. (r';.*$', Comment.Single),
  623. # whitespaces - usually not relevant
  624. (r'\s+', Text),
  625. # numbers
  626. (r'-?\d+\.\d+', Number.Float),
  627. (r'-?\d+', Number.Integer),
  628. # support for uncommon kinds of numbers -
  629. # have to figure out what the characters mean
  630. #(r'(#e|#i|#b|#o|#d|#x)[\d.]+', Number),
  631. # strings, symbols and characters
  632. (r'"(\\\\|\\"|[^"])*"', String),
  633. (r"'" + valid_name, String.Symbol),
  634. (r"#\\([()/'\"._!§$%& ?=+-]{1}|[a-zA-Z0-9]+)", String.Char),
  635. # constants
  636. (r'(#t|#f)', Name.Constant),
  637. # special operators
  638. (r"('|#|`|,@|,|\.)", Operator),
  639. # highlight the keywords
  640. ('(%s)' % '|'.join([
  641. re.escape(entry) + ' ' for entry in keywords]),
  642. Keyword
  643. ),
  644. # first variable in a quoted string like
  645. # '(this is syntactic sugar)
  646. (r"(?<='\()" + valid_name, Name.Variable),
  647. (r"(?<=#\()" + valid_name, Name.Variable),
  648. # highlight the builtins
  649. ("(?<=\()(%s)" % '|'.join([
  650. re.escape(entry) + ' ' for entry in builtins]),
  651. Name.Builtin
  652. ),
  653. # the remaining functions
  654. (r'(?<=\()' + valid_name, Name.Function),
  655. # find the remaining variables
  656. (valid_name, Name.Variable),
  657. # the famous parentheses!
  658. (r'(\(|\))', Punctuation),
  659. (r'(\[|\])', Punctuation),
  660. ],
  661. }
  662. class CommonLispLexer(RegexLexer):
  663. """
  664. A Common Lisp lexer.
  665. *New in Pygments 0.9.*
  666. """
  667. name = 'Common Lisp'
  668. aliases = ['common-lisp', 'cl']
  669. filenames = ['*.cl', '*.lisp', '*.el'] # use for Elisp too
  670. mimetypes = ['text/x-common-lisp']
  671. flags = re.IGNORECASE | re.MULTILINE
  672. ### couple of useful regexes
  673. # characters that are not macro-characters and can be used to begin a symbol
  674. nonmacro = r'\\.|[a-zA-Z0-9!$%&*+-/<=>?@\[\]^_{}~]'
  675. constituent = nonmacro + '|[#.:]'
  676. terminated = r'(?=[ "()\'\n,;`])' # whitespace or terminating macro characters
  677. ### symbol token, reverse-engineered from hyperspec
  678. # Take a deep breath...
  679. symbol = r'(\|[^|]+\||(?:%s)(?:%s)*)' % (nonmacro, constituent)
  680. def __init__(self, **options):
  681. from pygments.lexers._clbuiltins import BUILTIN_FUNCTIONS, \
  682. SPECIAL_FORMS, MACROS, LAMBDA_LIST_KEYWORDS, DECLARATIONS, \
  683. BUILTIN_TYPES, BUILTIN_CLASSES
  684. self.builtin_function = BUILTIN_FUNCTIONS
  685. self.special_forms = SPECIAL_FORMS
  686. self.macros = MACROS
  687. self.lambda_list_keywords = LAMBDA_LIST_KEYWORDS
  688. self.declarations = DECLARATIONS
  689. self.builtin_types = BUILTIN_TYPES
  690. self.builtin_classes = BUILTIN_CLASSES
  691. RegexLexer.__init__(self, **options)
  692. def get_tokens_unprocessed(self, text):
  693. stack = ['root']
  694. for index, token, value in RegexLexer.get_tokens_unprocessed(self, text, stack):
  695. if token is Name.Variable:
  696. if value in self.builtin_function:
  697. yield index, Name.Builtin, value
  698. continue
  699. if value in self.special_forms:
  700. yield index, Keyword, value
  701. continue
  702. if value in self.macros:
  703. yield index, Name.Builtin, value
  704. continue
  705. if value in self.lambda_list_keywords:
  706. yield index, Keyword, value
  707. continue
  708. if value in self.declarations:
  709. yield index, Keyword, value
  710. continue
  711. if value in self.builtin_types:
  712. yield index, Keyword.Type, value
  713. continue
  714. if value in self.builtin_classes:
  715. yield index, Name.Class, value
  716. continue
  717. yield index, token, value
  718. tokens = {
  719. 'root' : [
  720. ('', Text, 'body'),
  721. ],
  722. 'multiline-comment' : [
  723. (r'#\|', Comment.Multiline, '#push'), # (cf. Hyperspec 2.4.8.19)
  724. (r'\|#', Comment.Multiline, '#pop'),
  725. (r'[^|#]+', Comment.Multiline),
  726. (r'[|#]', Comment.Multiline),
  727. ],
  728. 'commented-form' : [
  729. (r'\(', Comment.Preproc, '#push'),
  730. (r'\)', Comment.Preproc, '#pop'),
  731. (r'[^()]+', Comment.Preproc),
  732. ],
  733. 'body' : [
  734. # whitespace
  735. (r'\s+', Text),
  736. # single-line comment
  737. (r';.*$', Comment.Single),
  738. # multi-line comment
  739. (r'#\|', Comment.Multiline, 'multiline-comment'),
  740. # encoding comment (?)
  741. (r'#\d*Y.*$', Comment.Special),
  742. # strings and characters
  743. (r'"(\\.|\\\n|[^"\\])*"', String),
  744. # quoting
  745. (r":" + symbol, String.Symbol),
  746. (r"'" + symbol, String.Symbol),
  747. (r"'", Operator),
  748. (r"`", Operator),
  749. # decimal numbers
  750. (r'[-+]?\d+\.?' + terminated, Number.Integer),
  751. (r'[-+]?\d+/\d+' + terminated, Number),
  752. (r'[-+]?(\d*\.\d+([defls][-+]?\d+)?|\d+(\.\d*)?[defls][-+]?\d+)' \
  753. + terminated, Number.Float),
  754. # sharpsign strings and characters
  755. (r"#\\." + terminated, String.Char),
  756. (r"#\\" + symbol, String.Char),
  757. # vector
  758. (r'#\(', Operator, 'body'),
  759. # bitstring
  760. (r'#\d*\*[01]*', Literal.Other),
  761. # uninterned symbol
  762. (r'#:' + symbol, String.Symbol),
  763. # read-time and load-time evaluation
  764. (r'#[.,]', Operator),
  765. # function shorthand
  766. (r'#\'', Name.Function),
  767. # binary rational
  768. (r'#[bB][+-]?[01]+(/[01]+)?', Number),
  769. # octal rational
  770. (r'#[oO][+-]?[0-7]+(/[0-7]+)?', Number.Oct),
  771. # hex rational
  772. (r'#[xX][+-]?[0-9a-fA-F]+(/[0-9a-fA-F]+)?', Number.Hex),
  773. # radix rational
  774. (r'#\d+[rR][+-]?[0-9a-zA-Z]+(/[0-9a-zA-Z]+)?', Number),
  775. # complex
  776. (r'(#[cC])(\()', bygroups(Number, Punctuation), 'body'),
  777. # array
  778. (r'(#\d+[aA])(\()', bygroups(Literal.Other, Punctuation), 'body'),
  779. # structure
  780. (r'(#[sS])(\()', bygroups(Literal.Other, Punctuation), 'body'),
  781. # path
  782. (r'#[pP]?"(\\.|[^"])*"', Literal.Other),
  783. # reference
  784. (r'#\d+=', Operator),
  785. (r'#\d+#', Operator),
  786. # read-time comment
  787. (r'#+nil' + terminated + '\s*\(', Comment.Preproc, 'commented-form'),
  788. # read-time conditional
  789. (r'#[+-]', Operator),
  790. # special operators that should have been parsed already
  791. (r'(,@|,|\.)', Operator),
  792. # special constants
  793. (r'(t|nil)' + terminated, Name.Constant),
  794. # functions and variables
  795. (r'\*' + symbol + '\*', Name.Variable.Global),
  796. (symbol, Name.Variable),
  797. # parentheses
  798. (r'\(', Punctuation, 'body'),
  799. (r'\)', Punctuation, '#pop'),
  800. ],
  801. }
  802. class HaskellLexer(RegexLexer):
  803. """
  804. A Haskell lexer based on the lexemes defined in the Haskell 98 Report.
  805. *New in Pygments 0.8.*
  806. """
  807. name = 'Haskell'
  808. aliases = ['haskell', 'hs']
  809. filenames = ['*.hs']
  810. mimetypes = ['text/x-haskell']
  811. reserved = ['case','class','data','default','deriving','do','else',
  812. 'if','in','infix[lr]?','instance',
  813. 'let','newtype','of','then','type','where','_']
  814. ascii = ['NUL','SOH','[SE]TX','EOT','ENQ','ACK',
  815. 'BEL','BS','HT','LF','VT','FF','CR','S[OI]','DLE',
  816. 'DC[1-4]','NAK','SYN','ETB','CAN',
  817. 'EM','SUB','ESC','[FGRU]S','SP','DEL']
  818. tokens = {
  819. 'root': [
  820. # Whitespace:
  821. (r'\s+', Text),
  822. #(r'--\s*|.*$', Comment.Doc),
  823. (r'--(?![!#$%&*+./<=>?@\^|_~:\\]).*?$', Comment.Single),
  824. (r'{-', Comment.Multiline, 'comment'),
  825. # Lexemes:
  826. # Identifiers
  827. (r'\bimport\b', Keyword.Reserved, 'import'),
  828. (r'\bmodule\b', Keyword.Reserved, 'module'),
  829. (r'\berror\b', Name.Exception),
  830. (r'\b(%s)(?!\')\b' % '|'.join(reserved), Keyword.Reserved),
  831. (r'^[_a-z][\w\']*', Name.Function),
  832. (r"'?[_a-z][\w']*", Name),
  833. (r"('')?[A-Z][\w\']*", Keyword.Type),
  834. # Operators
  835. (r'\\(?![:!#$%&*+.\\/<=>?@^|~-]+)', Name.Function), # lambda operator
  836. (r'(<-|::|->|=>|=)(?![:!#$%&*+.\\/<=>?@^|~-]+)', Operator.Word), # specials
  837. (r':[:!#$%&*+.\\/<=>?@^|~-]*', Keyword.Type), # Constructor operators
  838. (r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator), # Other operators
  839. # Numbers
  840. (r'\d+[eE][+-]?\d+', Number.Float),
  841. (r'\d+\.\d+([eE][+-]?\d+)?', Number.Float),
  842. (r'0[oO][0-7]+', Number.Oct),
  843. (r'0[xX][\da-fA-F]+', Number.Hex),
  844. (r'\d+', Number.Integer),
  845. # Character/String Literals
  846. (r"'", String.Char, 'character'),
  847. (r'"', String, 'string'),
  848. # Special
  849. (r'\[\]', Keyword.Type),
  850. (r'\(\)', Name.Builtin),
  851. (r'[][(),;`{}]', Punctuation),
  852. ],
  853. 'import': [
  854. # Import statements
  855. (r'\s+', Text),
  856. (r'"', String, 'string'),
  857. # after "funclist" state
  858. (r'\)', Punctuation, '#pop'),
  859. (r'qualified\b', Keyword),
  860. # import X as Y
  861. (r'([A-Z][a-zA-Z0-9_.]*)(\s+)(as)(\s+)([A-Z][a-zA-Z0-9_.]*)',
  862. bygroups(Name.Namespace, Text, Keyword, Text, Name), '#pop'),
  863. # import X hiding (functions)
  864. (r'([A-Z][a-zA-Z0-9_.]*)(\s+)(hiding)(\s+)(\()',
  865. bygroups(Name.Namespace, Text, Keyword, Text, Punctuation), 'funclist'),
  866. # import X (functions)
  867. (r'([A-Z][a-zA-Z0-9_.]*)(\s+)(\()',
  868. bygroups(Name.Namespace, Text, Punctuation), 'funclist'),
  869. # import X
  870. (r'[a-zA-Z0-9_.]+', Name.Namespace, '#pop'),
  871. ],
  872. 'module': [
  873. (r'\s+', Text),
  874. (r'([A-Z][a-zA-Z0-9_.]*)(\s+)(\()',
  875. bygroups(Name.Namespace, Text, Punctuation), 'funclist'),
  876. (r'[A-Z][a-zA-Z0-9_.]*', Name.Namespace, '#pop'),
  877. ],
  878. 'funclist': [
  879. (r'\s+', Text),
  880. (r'[A-Z][a-zA-Z0-9_]*', Keyword.Type),
  881. (r'(_[\w\']+|[a-z][\w\']*)', Name.Function),
  882. (r'--.*$', Comment.Single),
  883. (r'{-', Comment.Multiline, 'comment'),
  884. (r',', Punctuation),
  885. (r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator),
  886. # (HACK, but it makes sense to push two instances, believe me)
  887. (r'\(', Punctuation, ('funclist', 'funclist')),
  888. (r'\)', Punctuation, '#pop:2'),
  889. ],
  890. 'comment': [
  891. # Multiline Comments
  892. (r'[^-{}]+', Comment.Multiline),
  893. (r'{-', Comment.Multiline, '#push'),
  894. (r'-}', Comment.Multiline, '#pop'),
  895. (r'[-{}]', Comment.Multiline),
  896. ],
  897. 'character': [
  898. # Allows multi-chars, incorrectly.
  899. (r"[^\\']", String.Char),
  900. (r"\\", String.Escape, 'escape'),
  901. ("'", String.Char, '#pop'),
  902. ],
  903. 'string': [
  904. (r'[^\\"]+', String),
  905. (r"\\", String.Escape, 'escape'),
  906. ('"', String, '#pop'),
  907. ],
  908. 'escape': [
  909. (r'[abfnrtv"\'&\\]', String.Escape, '#pop'),
  910. (r'\^[][A-Z@\^_]', String.Escape, '#pop'),
  911. ('|'.join(ascii), String.Escape, '#pop'),
  912. (r'o[0-7]+', String.Escape, '#pop'),
  913. (r'x[\da-fA-F]+', String.Escape, '#pop'),
  914. (r'\d+', String.Escape, '#pop'),
  915. (r'\s+\\', String.Escape, '#pop'),
  916. ],
  917. }
  918. line_re = re.compile('.*?\n')
  919. bird_re = re.compile(r'(>[ \t]*)(.*\n)')
  920. class LiterateHaskellLexer(Lexer):
  921. """
  922. For Literate Haskell (Bird-style or LaTeX) source.
  923. Additional options accepted:
  924. `litstyle`
  925. If given, must be ``"bird"`` or ``"latex"``. If not given, the style
  926. is autodetected: if the first non-whitespace character in the source
  927. is a backslash or percent character, LaTeX is assumed, else Bird.
  928. *New in Pygments 0.9.*
  929. """
  930. name = 'Literate Haskell'
  931. aliases = ['lhs', 'literate-haskell']
  932. filenames = ['*.lhs']
  933. mimetypes = ['text/x-literate-haskell']
  934. def get_tokens_unprocessed(self, text):
  935. hslexer = HaskellLexer(**self.options)
  936. style = self.options.get('litstyle')
  937. if style is None:
  938. style = (text.lstrip()[0:1] in '%\\') and 'latex' or 'bird'
  939. code = ''
  940. insertions = []
  941. if style == 'bird':
  942. # bird-style
  943. for match in line_re.finditer(text):
  944. line = match.group()

Large files files are truncated, but you can click here to view the full file