1476 # tagged [text]...[/text] delimited strings... |
1476 # tagged [text]...[/text] delimited strings... |
1477 'tagstring': [ |
1477 'tagstring': [ |
1478 (r'(?s)(.*?)(\[/text\])', String, '#pop'), |
1478 (r'(?s)(.*?)(\[/text\])', String, '#pop'), |
1479 ], |
1479 ], |
1480 } |
1480 } |
|
1481 |
|
1482 |
|
1483 class EmacsLispLexer(RegexLexer): |
|
1484 """ |
|
1485 An ELisp lexer, parsing a stream and outputting the tokens |
|
1486 needed to highlight elisp code. |
|
1487 |
|
1488 .. versionadded:: 2.1 |
|
1489 """ |
|
1490 name = 'EmacsLisp' |
|
1491 aliases = ['emacs', 'elisp'] |
|
1492 filenames = ['*.el'] |
|
1493 mimetypes = ['text/x-elisp', 'application/x-elisp'] |
|
1494 |
|
1495 flags = re.MULTILINE |
|
1496 |
|
1497 # couple of useful regexes |
|
1498 |
|
1499 # characters that are not macro-characters and can be used to begin a symbol |
|
1500 nonmacro = r'\\.|[\w!$%&*+-/<=>?@^{}~|]' |
|
1501 constituent = nonmacro + '|[#.:]' |
|
1502 terminated = r'(?=[ "()\]\'\n,;`])' # whitespace or terminating macro characters |
|
1503 |
|
1504 # symbol token, reverse-engineered from hyperspec |
|
1505 # Take a deep breath... |
|
1506 symbol = r'((?:%s)(?:%s)*)' % (nonmacro, constituent) |
|
1507 |
|
1508 macros = set(( |
|
1509 'atomic-change-group', 'case', 'block', 'cl-block', 'cl-callf', 'cl-callf2', |
|
1510 'cl-case', 'cl-decf', 'cl-declaim', 'cl-declare', |
|
1511 'cl-define-compiler-macro', 'cl-defmacro', 'cl-defstruct', |
|
1512 'cl-defsubst', 'cl-deftype', 'cl-defun', 'cl-destructuring-bind', |
|
1513 'cl-do', 'cl-do*', 'cl-do-all-symbols', 'cl-do-symbols', 'cl-dolist', |
|
1514 'cl-dotimes', 'cl-ecase', 'cl-etypecase', 'eval-when', 'cl-eval-when', 'cl-flet', |
|
1515 'cl-flet*', 'cl-function', 'cl-incf', 'cl-labels', 'cl-letf', |
|
1516 'cl-letf*', 'cl-load-time-value', 'cl-locally', 'cl-loop', |
|
1517 'cl-macrolet', 'cl-multiple-value-bind', 'cl-multiple-value-setq', |
|
1518 'cl-progv', 'cl-psetf', 'cl-psetq', 'cl-pushnew', 'cl-remf', |
|
1519 'cl-return', 'cl-return-from', 'cl-rotatef', 'cl-shiftf', |
|
1520 'cl-symbol-macrolet', 'cl-tagbody', 'cl-the', 'cl-typecase', |
|
1521 'combine-after-change-calls', 'condition-case-unless-debug', 'decf', |
|
1522 'declaim', 'declare', 'declare-function', 'def-edebug-spec', |
|
1523 'defadvice', 'defclass', 'defcustom', 'defface', 'defgeneric', |
|
1524 'defgroup', 'define-advice', 'define-alternatives', |
|
1525 'define-compiler-macro', 'define-derived-mode', 'define-generic-mode', |
|
1526 'define-global-minor-mode', 'define-globalized-minor-mode', |
|
1527 'define-minor-mode', 'define-modify-macro', |
|
1528 'define-obsolete-face-alias', 'define-obsolete-function-alias', |
|
1529 'define-obsolete-variable-alias', 'define-setf-expander', |
|
1530 'define-skeleton', 'defmacro', 'defmethod', 'defsetf', 'defstruct', |
|
1531 'defsubst', 'deftheme', 'deftype', 'defun', 'defvar-local', |
|
1532 'delay-mode-hooks', 'destructuring-bind', 'do', 'do*', |
|
1533 'do-all-symbols', 'do-symbols', 'dolist', 'dont-compile', 'dotimes', |
|
1534 'dotimes-with-progress-reporter', 'ecase', 'ert-deftest', 'etypecase', |
|
1535 'eval-and-compile', 'eval-when-compile', 'flet', 'ignore-errors', |
|
1536 'incf', 'labels', 'lambda', 'letrec', 'lexical-let', 'lexical-let*', |
|
1537 'loop', 'multiple-value-bind', 'multiple-value-setq', 'noreturn', |
|
1538 'oref', 'oref-default', 'oset', 'oset-default', 'pcase', |
|
1539 'pcase-defmacro', 'pcase-dolist', 'pcase-exhaustive', 'pcase-let', |
|
1540 'pcase-let*', 'pop', 'psetf', 'psetq', 'push', 'pushnew', 'remf', |
|
1541 'return', 'rotatef', 'rx', 'save-match-data', 'save-selected-window', |
|
1542 'save-window-excursion', 'setf', 'setq-local', 'shiftf', |
|
1543 'track-mouse', 'typecase', 'unless', 'use-package', 'when', |
|
1544 'while-no-input', 'with-case-table', 'with-category-table', |
|
1545 'with-coding-priority', 'with-current-buffer', 'with-demoted-errors', |
|
1546 'with-eval-after-load', 'with-file-modes', 'with-local-quit', |
|
1547 'with-output-to-string', 'with-output-to-temp-buffer', |
|
1548 'with-parsed-tramp-file-name', 'with-selected-frame', |
|
1549 'with-selected-window', 'with-silent-modifications', 'with-slots', |
|
1550 'with-syntax-table', 'with-temp-buffer', 'with-temp-file', |
|
1551 'with-temp-message', 'with-timeout', 'with-tramp-connection-property', |
|
1552 'with-tramp-file-property', 'with-tramp-progress-reporter', |
|
1553 'with-wrapper-hook', 'load-time-value', 'locally', 'macrolet', 'progv', |
|
1554 'return-from', |
|
1555 )) |
|
1556 |
|
1557 special_forms = set(( |
|
1558 'and', 'catch', 'cond', 'condition-case', 'defconst', 'defvar', |
|
1559 'function', 'if', 'interactive', 'let', 'let*', 'or', 'prog1', |
|
1560 'prog2', 'progn', 'quote', 'save-current-buffer', 'save-excursion', |
|
1561 'save-restriction', 'setq', 'setq-default', 'subr-arity', |
|
1562 'unwind-protect', 'while', |
|
1563 )) |
|
1564 |
|
1565 builtin_function = set(( |
|
1566 '%', '*', '+', '-', '/', '/=', '1+', '1-', '<', '<=', '=', '>', '>=', |
|
1567 'Snarf-documentation', 'abort-recursive-edit', 'abs', |
|
1568 'accept-process-output', 'access-file', 'accessible-keymaps', 'acos', |
|
1569 'active-minibuffer-window', 'add-face-text-property', |
|
1570 'add-name-to-file', 'add-text-properties', 'all-completions', |
|
1571 'append', 'apply', 'apropos-internal', 'aref', 'arrayp', 'aset', |
|
1572 'ash', 'asin', 'assoc', 'assoc-string', 'assq', 'atan', 'atom', |
|
1573 'autoload', 'autoload-do-load', 'backtrace', 'backtrace--locals', |
|
1574 'backtrace-debug', 'backtrace-eval', 'backtrace-frame', |
|
1575 'backward-char', 'backward-prefix-chars', 'barf-if-buffer-read-only', |
|
1576 'base64-decode-region', 'base64-decode-string', |
|
1577 'base64-encode-region', 'base64-encode-string', 'beginning-of-line', |
|
1578 'bidi-find-overridden-directionality', 'bidi-resolved-levels', |
|
1579 'bitmap-spec-p', 'bobp', 'bolp', 'bool-vector', |
|
1580 'bool-vector-count-consecutive', 'bool-vector-count-population', |
|
1581 'bool-vector-exclusive-or', 'bool-vector-intersection', |
|
1582 'bool-vector-not', 'bool-vector-p', 'bool-vector-set-difference', |
|
1583 'bool-vector-subsetp', 'bool-vector-union', 'boundp', |
|
1584 'buffer-base-buffer', 'buffer-chars-modified-tick', |
|
1585 'buffer-enable-undo', 'buffer-file-name', 'buffer-has-markers-at', |
|
1586 'buffer-list', 'buffer-live-p', 'buffer-local-value', |
|
1587 'buffer-local-variables', 'buffer-modified-p', 'buffer-modified-tick', |
|
1588 'buffer-name', 'buffer-size', 'buffer-string', 'buffer-substring', |
|
1589 'buffer-substring-no-properties', 'buffer-swap-text', 'bufferp', |
|
1590 'bury-buffer-internal', 'byte-code', 'byte-code-function-p', |
|
1591 'byte-to-position', 'byte-to-string', 'byteorder', |
|
1592 'call-interactively', 'call-last-kbd-macro', 'call-process', |
|
1593 'call-process-region', 'cancel-kbd-macro-events', 'capitalize', |
|
1594 'capitalize-region', 'capitalize-word', 'car', 'car-less-than-car', |
|
1595 'car-safe', 'case-table-p', 'category-docstring', |
|
1596 'category-set-mnemonics', 'category-table', 'category-table-p', |
|
1597 'ccl-execute', 'ccl-execute-on-string', 'ccl-program-p', 'cdr', |
|
1598 'cdr-safe', 'ceiling', 'char-after', 'char-before', |
|
1599 'char-category-set', 'char-charset', 'char-equal', 'char-or-string-p', |
|
1600 'char-resolve-modifiers', 'char-syntax', 'char-table-extra-slot', |
|
1601 'char-table-p', 'char-table-parent', 'char-table-range', |
|
1602 'char-table-subtype', 'char-to-string', 'char-width', 'characterp', |
|
1603 'charset-after', 'charset-id-internal', 'charset-plist', |
|
1604 'charset-priority-list', 'charsetp', 'check-coding-system', |
|
1605 'check-coding-systems-region', 'clear-buffer-auto-save-failure', |
|
1606 'clear-charset-maps', 'clear-face-cache', 'clear-font-cache', |
|
1607 'clear-image-cache', 'clear-string', 'clear-this-command-keys', |
|
1608 'close-font', 'clrhash', 'coding-system-aliases', |
|
1609 'coding-system-base', 'coding-system-eol-type', 'coding-system-p', |
|
1610 'coding-system-plist', 'coding-system-priority-list', |
|
1611 'coding-system-put', 'color-distance', 'color-gray-p', |
|
1612 'color-supported-p', 'combine-after-change-execute', |
|
1613 'command-error-default-function', 'command-remapping', 'commandp', |
|
1614 'compare-buffer-substrings', 'compare-strings', |
|
1615 'compare-window-configurations', 'completing-read', |
|
1616 'compose-region-internal', 'compose-string-internal', |
|
1617 'composition-get-gstring', 'compute-motion', 'concat', 'cons', |
|
1618 'consp', 'constrain-to-field', 'continue-process', |
|
1619 'controlling-tty-p', 'coordinates-in-window-p', 'copy-alist', |
|
1620 'copy-category-table', 'copy-file', 'copy-hash-table', 'copy-keymap', |
|
1621 'copy-marker', 'copy-sequence', 'copy-syntax-table', 'copysign', |
|
1622 'cos', 'current-active-maps', 'current-bidi-paragraph-direction', |
|
1623 'current-buffer', 'current-case-table', 'current-column', |
|
1624 'current-global-map', 'current-idle-time', 'current-indentation', |
|
1625 'current-input-mode', 'current-local-map', 'current-message', |
|
1626 'current-minor-mode-maps', 'current-time', 'current-time-string', |
|
1627 'current-time-zone', 'current-window-configuration', |
|
1628 'cygwin-convert-file-name-from-windows', |
|
1629 'cygwin-convert-file-name-to-windows', 'daemon-initialized', |
|
1630 'daemonp', 'dbus--init-bus', 'dbus-get-unique-name', |
|
1631 'dbus-message-internal', 'debug-timer-check', 'declare-equiv-charset', |
|
1632 'decode-big5-char', 'decode-char', 'decode-coding-region', |
|
1633 'decode-coding-string', 'decode-sjis-char', 'decode-time', |
|
1634 'default-boundp', 'default-file-modes', 'default-printer-name', |
|
1635 'default-toplevel-value', 'default-value', 'define-category', |
|
1636 'define-charset-alias', 'define-charset-internal', |
|
1637 'define-coding-system-alias', 'define-coding-system-internal', |
|
1638 'define-fringe-bitmap', 'define-hash-table-test', 'define-key', |
|
1639 'define-prefix-command', 'delete', |
|
1640 'delete-all-overlays', 'delete-and-extract-region', 'delete-char', |
|
1641 'delete-directory-internal', 'delete-field', 'delete-file', |
|
1642 'delete-frame', 'delete-other-windows-internal', 'delete-overlay', |
|
1643 'delete-process', 'delete-region', 'delete-terminal', |
|
1644 'delete-window-internal', 'delq', 'describe-buffer-bindings', |
|
1645 'describe-vector', 'destroy-fringe-bitmap', 'detect-coding-region', |
|
1646 'detect-coding-string', 'ding', 'directory-file-name', |
|
1647 'directory-files', 'directory-files-and-attributes', 'discard-input', |
|
1648 'display-supports-face-attributes-p', 'do-auto-save', 'documentation', |
|
1649 'documentation-property', 'downcase', 'downcase-region', |
|
1650 'downcase-word', 'draw-string', 'dump-colors', 'dump-emacs', |
|
1651 'dump-face', 'dump-frame-glyph-matrix', 'dump-glyph-matrix', |
|
1652 'dump-glyph-row', 'dump-redisplay-history', 'dump-tool-bar-row', |
|
1653 'elt', 'emacs-pid', 'encode-big5-char', 'encode-char', |
|
1654 'encode-coding-region', 'encode-coding-string', 'encode-sjis-char', |
|
1655 'encode-time', 'end-kbd-macro', 'end-of-line', 'eobp', 'eolp', 'eq', |
|
1656 'eql', 'equal', 'equal-including-properties', 'erase-buffer', |
|
1657 'error-message-string', 'eval', 'eval-buffer', 'eval-region', |
|
1658 'event-convert-list', 'execute-kbd-macro', 'exit-recursive-edit', |
|
1659 'exp', 'expand-file-name', 'expt', 'external-debugging-output', |
|
1660 'face-attribute-relative-p', 'face-attributes-as-vector', 'face-font', |
|
1661 'fboundp', 'fceiling', 'fetch-bytecode', 'ffloor', |
|
1662 'field-beginning', 'field-end', 'field-string', |
|
1663 'field-string-no-properties', 'file-accessible-directory-p', |
|
1664 'file-acl', 'file-attributes', 'file-attributes-lessp', |
|
1665 'file-directory-p', 'file-executable-p', 'file-exists-p', |
|
1666 'file-locked-p', 'file-modes', 'file-name-absolute-p', |
|
1667 'file-name-all-completions', 'file-name-as-directory', |
|
1668 'file-name-completion', 'file-name-directory', |
|
1669 'file-name-nondirectory', 'file-newer-than-file-p', 'file-readable-p', |
|
1670 'file-regular-p', 'file-selinux-context', 'file-symlink-p', |
|
1671 'file-system-info', 'file-system-info', 'file-writable-p', |
|
1672 'fillarray', 'find-charset-region', 'find-charset-string', |
|
1673 'find-coding-systems-region-internal', 'find-composition-internal', |
|
1674 'find-file-name-handler', 'find-font', 'find-operation-coding-system', |
|
1675 'float', 'float-time', 'floatp', 'floor', 'fmakunbound', |
|
1676 'following-char', 'font-at', 'font-drive-otf', 'font-face-attributes', |
|
1677 'font-family-list', 'font-get', 'font-get-glyphs', |
|
1678 'font-get-system-font', 'font-get-system-normal-font', 'font-info', |
|
1679 'font-match-p', 'font-otf-alternates', 'font-put', |
|
1680 'font-shape-gstring', 'font-spec', 'font-variation-glyphs', |
|
1681 'font-xlfd-name', 'fontp', 'fontset-font', 'fontset-info', |
|
1682 'fontset-list', 'fontset-list-all', 'force-mode-line-update', |
|
1683 'force-window-update', 'format', 'format-mode-line', |
|
1684 'format-network-address', 'format-time-string', 'forward-char', |
|
1685 'forward-comment', 'forward-line', 'forward-word', |
|
1686 'frame-border-width', 'frame-bottom-divider-width', |
|
1687 'frame-can-run-window-configuration-change-hook', 'frame-char-height', |
|
1688 'frame-char-width', 'frame-face-alist', 'frame-first-window', |
|
1689 'frame-focus', 'frame-font-cache', 'frame-fringe-width', 'frame-list', |
|
1690 'frame-live-p', 'frame-or-buffer-changed-p', 'frame-parameter', |
|
1691 'frame-parameters', 'frame-pixel-height', 'frame-pixel-width', |
|
1692 'frame-pointer-visible-p', 'frame-right-divider-width', |
|
1693 'frame-root-window', 'frame-scroll-bar-height', |
|
1694 'frame-scroll-bar-width', 'frame-selected-window', 'frame-terminal', |
|
1695 'frame-text-cols', 'frame-text-height', 'frame-text-lines', |
|
1696 'frame-text-width', 'frame-total-cols', 'frame-total-lines', |
|
1697 'frame-visible-p', 'framep', 'frexp', 'fringe-bitmaps-at-pos', |
|
1698 'fround', 'fset', 'ftruncate', 'funcall', 'funcall-interactively', |
|
1699 'function-equal', 'functionp', 'gap-position', 'gap-size', |
|
1700 'garbage-collect', 'gc-status', 'generate-new-buffer-name', 'get', |
|
1701 'get-buffer', 'get-buffer-create', 'get-buffer-process', |
|
1702 'get-buffer-window', 'get-byte', 'get-char-property', |
|
1703 'get-char-property-and-overlay', 'get-file-buffer', 'get-file-char', |
|
1704 'get-internal-run-time', 'get-load-suffixes', 'get-pos-property', |
|
1705 'get-process', 'get-screen-color', 'get-text-property', |
|
1706 'get-unicode-property-internal', 'get-unused-category', |
|
1707 'get-unused-iso-final-char', 'getenv-internal', 'gethash', |
|
1708 'gfile-add-watch', 'gfile-rm-watch', 'global-key-binding', |
|
1709 'gnutls-available-p', 'gnutls-boot', 'gnutls-bye', 'gnutls-deinit', |
|
1710 'gnutls-error-fatalp', 'gnutls-error-string', 'gnutls-errorp', |
|
1711 'gnutls-get-initstage', 'gnutls-peer-status', |
|
1712 'gnutls-peer-status-warning-describe', 'goto-char', 'gpm-mouse-start', |
|
1713 'gpm-mouse-stop', 'group-gid', 'group-real-gid', |
|
1714 'handle-save-session', 'handle-switch-frame', 'hash-table-count', |
|
1715 'hash-table-p', 'hash-table-rehash-size', |
|
1716 'hash-table-rehash-threshold', 'hash-table-size', 'hash-table-test', |
|
1717 'hash-table-weakness', 'iconify-frame', 'identity', 'image-flush', |
|
1718 'image-mask-p', 'image-metadata', 'image-size', 'imagemagick-types', |
|
1719 'imagep', 'indent-to', 'indirect-function', 'indirect-variable', |
|
1720 'init-image-library', 'inotify-add-watch', 'inotify-rm-watch', |
|
1721 'input-pending-p', 'insert', 'insert-and-inherit', |
|
1722 'insert-before-markers', 'insert-before-markers-and-inherit', |
|
1723 'insert-buffer-substring', 'insert-byte', 'insert-char', |
|
1724 'insert-file-contents', 'insert-startup-screen', 'int86', |
|
1725 'integer-or-marker-p', 'integerp', 'interactive-form', 'intern', |
|
1726 'intern-soft', 'internal--track-mouse', 'internal-char-font', |
|
1727 'internal-complete-buffer', 'internal-copy-lisp-face', |
|
1728 'internal-default-process-filter', |
|
1729 'internal-default-process-sentinel', 'internal-describe-syntax-value', |
|
1730 'internal-event-symbol-parse-modifiers', |
|
1731 'internal-face-x-get-resource', 'internal-get-lisp-face-attribute', |
|
1732 'internal-lisp-face-attribute-values', 'internal-lisp-face-empty-p', |
|
1733 'internal-lisp-face-equal-p', 'internal-lisp-face-p', |
|
1734 'internal-make-lisp-face', 'internal-make-var-non-special', |
|
1735 'internal-merge-in-global-face', |
|
1736 'internal-set-alternative-font-family-alist', |
|
1737 'internal-set-alternative-font-registry-alist', |
|
1738 'internal-set-font-selection-order', |
|
1739 'internal-set-lisp-face-attribute', |
|
1740 'internal-set-lisp-face-attribute-from-resource', |
|
1741 'internal-show-cursor', 'internal-show-cursor-p', 'interrupt-process', |
|
1742 'invisible-p', 'invocation-directory', 'invocation-name', 'isnan', |
|
1743 'iso-charset', 'key-binding', 'key-description', |
|
1744 'keyboard-coding-system', 'keymap-parent', 'keymap-prompt', 'keymapp', |
|
1745 'keywordp', 'kill-all-local-variables', 'kill-buffer', 'kill-emacs', |
|
1746 'kill-local-variable', 'kill-process', 'last-nonminibuffer-frame', |
|
1747 'lax-plist-get', 'lax-plist-put', 'ldexp', 'length', |
|
1748 'libxml-parse-html-region', 'libxml-parse-xml-region', |
|
1749 'line-beginning-position', 'line-end-position', 'line-pixel-height', |
|
1750 'list', 'list-fonts', 'list-system-processes', 'listp', 'load', |
|
1751 'load-average', 'local-key-binding', 'local-variable-if-set-p', |
|
1752 'local-variable-p', 'locale-info', 'locate-file-internal', |
|
1753 'lock-buffer', 'log', 'logand', 'logb', 'logior', 'lognot', 'logxor', |
|
1754 'looking-at', 'lookup-image', 'lookup-image-map', 'lookup-key', |
|
1755 'lower-frame', 'lsh', 'macroexpand', 'make-bool-vector', |
|
1756 'make-byte-code', 'make-category-set', 'make-category-table', |
|
1757 'make-char', 'make-char-table', 'make-directory-internal', |
|
1758 'make-frame-invisible', 'make-frame-visible', 'make-hash-table', |
|
1759 'make-indirect-buffer', 'make-keymap', 'make-list', |
|
1760 'make-local-variable', 'make-marker', 'make-network-process', |
|
1761 'make-overlay', 'make-serial-process', 'make-sparse-keymap', |
|
1762 'make-string', 'make-symbol', 'make-symbolic-link', 'make-temp-name', |
|
1763 'make-terminal-frame', 'make-variable-buffer-local', |
|
1764 'make-variable-frame-local', 'make-vector', 'makunbound', |
|
1765 'map-char-table', 'map-charset-chars', 'map-keymap', |
|
1766 'map-keymap-internal', 'mapatoms', 'mapc', 'mapcar', 'mapconcat', |
|
1767 'maphash', 'mark-marker', 'marker-buffer', 'marker-insertion-type', |
|
1768 'marker-position', 'markerp', 'match-beginning', 'match-data', |
|
1769 'match-end', 'matching-paren', 'max', 'max-char', 'md5', 'member', |
|
1770 'memory-info', 'memory-limit', 'memory-use-counts', 'memq', 'memql', |
|
1771 'menu-bar-menu-at-x-y', 'menu-or-popup-active-p', |
|
1772 'menu-or-popup-active-p', 'merge-face-attribute', 'message', |
|
1773 'message-box', 'message-or-box', 'min', |
|
1774 'minibuffer-completion-contents', 'minibuffer-contents', |
|
1775 'minibuffer-contents-no-properties', 'minibuffer-depth', |
|
1776 'minibuffer-prompt', 'minibuffer-prompt-end', |
|
1777 'minibuffer-selected-window', 'minibuffer-window', 'minibufferp', |
|
1778 'minor-mode-key-binding', 'mod', 'modify-category-entry', |
|
1779 'modify-frame-parameters', 'modify-syntax-entry', |
|
1780 'mouse-pixel-position', 'mouse-position', 'move-overlay', |
|
1781 'move-point-visually', 'move-to-column', 'move-to-window-line', |
|
1782 'msdos-downcase-filename', 'msdos-long-file-names', 'msdos-memget', |
|
1783 'msdos-memput', 'msdos-mouse-disable', 'msdos-mouse-enable', |
|
1784 'msdos-mouse-init', 'msdos-mouse-p', 'msdos-remember-default-colors', |
|
1785 'msdos-set-keyboard', 'msdos-set-mouse-buttons', |
|
1786 'multibyte-char-to-unibyte', 'multibyte-string-p', 'narrow-to-region', |
|
1787 'natnump', 'nconc', 'network-interface-info', |
|
1788 'network-interface-list', 'new-fontset', 'newline-cache-check', |
|
1789 'next-char-property-change', 'next-frame', 'next-overlay-change', |
|
1790 'next-property-change', 'next-read-file-uses-dialog-p', |
|
1791 'next-single-char-property-change', 'next-single-property-change', |
|
1792 'next-window', 'nlistp', 'nreverse', 'nth', 'nthcdr', 'null', |
|
1793 'number-or-marker-p', 'number-to-string', 'numberp', |
|
1794 'open-dribble-file', 'open-font', 'open-termscript', |
|
1795 'optimize-char-table', 'other-buffer', 'other-window-for-scrolling', |
|
1796 'overlay-buffer', 'overlay-end', 'overlay-get', 'overlay-lists', |
|
1797 'overlay-properties', 'overlay-put', 'overlay-recenter', |
|
1798 'overlay-start', 'overlayp', 'overlays-at', 'overlays-in', |
|
1799 'parse-partial-sexp', 'play-sound-internal', 'plist-get', |
|
1800 'plist-member', 'plist-put', 'point', 'point-marker', 'point-max', |
|
1801 'point-max-marker', 'point-min', 'point-min-marker', |
|
1802 'pos-visible-in-window-p', 'position-bytes', 'posix-looking-at', |
|
1803 'posix-search-backward', 'posix-search-forward', 'posix-string-match', |
|
1804 'posn-at-point', 'posn-at-x-y', 'preceding-char', |
|
1805 'prefix-numeric-value', 'previous-char-property-change', |
|
1806 'previous-frame', 'previous-overlay-change', |
|
1807 'previous-property-change', 'previous-single-char-property-change', |
|
1808 'previous-single-property-change', 'previous-window', 'prin1', |
|
1809 'prin1-to-string', 'princ', 'print', 'process-attributes', |
|
1810 'process-buffer', 'process-coding-system', 'process-command', |
|
1811 'process-connection', 'process-contact', 'process-datagram-address', |
|
1812 'process-exit-status', 'process-filter', 'process-filter-multibyte-p', |
|
1813 'process-id', 'process-inherit-coding-system-flag', 'process-list', |
|
1814 'process-mark', 'process-name', 'process-plist', |
|
1815 'process-query-on-exit-flag', 'process-running-child-p', |
|
1816 'process-send-eof', 'process-send-region', 'process-send-string', |
|
1817 'process-sentinel', 'process-status', 'process-tty-name', |
|
1818 'process-type', 'processp', 'profiler-cpu-log', |
|
1819 'profiler-cpu-running-p', 'profiler-cpu-start', 'profiler-cpu-stop', |
|
1820 'profiler-memory-log', 'profiler-memory-running-p', |
|
1821 'profiler-memory-start', 'profiler-memory-stop', 'propertize', |
|
1822 'purecopy', 'put', 'put-text-property', |
|
1823 'put-unicode-property-internal', 'puthash', 'query-font', |
|
1824 'query-fontset', 'quit-process', 'raise-frame', 'random', 'rassoc', |
|
1825 'rassq', 're-search-backward', 're-search-forward', 'read', |
|
1826 'read-buffer', 'read-char', 'read-char-exclusive', |
|
1827 'read-coding-system', 'read-command', 'read-event', |
|
1828 'read-from-minibuffer', 'read-from-string', 'read-function', |
|
1829 'read-key-sequence', 'read-key-sequence-vector', |
|
1830 'read-no-blanks-input', 'read-non-nil-coding-system', 'read-string', |
|
1831 'read-variable', 'recent-auto-save-p', 'recent-doskeys', |
|
1832 'recent-keys', 'recenter', 'recursion-depth', 'recursive-edit', |
|
1833 'redirect-debugging-output', 'redirect-frame-focus', 'redisplay', |
|
1834 'redraw-display', 'redraw-frame', 'regexp-quote', 'region-beginning', |
|
1835 'region-end', 'register-ccl-program', 'register-code-conversion-map', |
|
1836 'remhash', 'remove-list-of-text-properties', 'remove-text-properties', |
|
1837 'rename-buffer', 'rename-file', 'replace-match', |
|
1838 'reset-this-command-lengths', 'resize-mini-window-internal', |
|
1839 'restore-buffer-modified-p', 'resume-tty', 'reverse', 'round', |
|
1840 'run-hook-with-args', 'run-hook-with-args-until-failure', |
|
1841 'run-hook-with-args-until-success', 'run-hook-wrapped', 'run-hooks', |
|
1842 'run-window-configuration-change-hook', 'run-window-scroll-functions', |
|
1843 'safe-length', 'scan-lists', 'scan-sexps', 'scroll-down', |
|
1844 'scroll-left', 'scroll-other-window', 'scroll-right', 'scroll-up', |
|
1845 'search-backward', 'search-forward', 'secure-hash', 'select-frame', |
|
1846 'select-window', 'selected-frame', 'selected-window', |
|
1847 'self-insert-command', 'send-string-to-terminal', 'sequencep', |
|
1848 'serial-process-configure', 'set', 'set-buffer', |
|
1849 'set-buffer-auto-saved', 'set-buffer-major-mode', |
|
1850 'set-buffer-modified-p', 'set-buffer-multibyte', 'set-case-table', |
|
1851 'set-category-table', 'set-char-table-extra-slot', |
|
1852 'set-char-table-parent', 'set-char-table-range', 'set-charset-plist', |
|
1853 'set-charset-priority', 'set-coding-system-priority', |
|
1854 'set-cursor-size', 'set-default', 'set-default-file-modes', |
|
1855 'set-default-toplevel-value', 'set-file-acl', 'set-file-modes', |
|
1856 'set-file-selinux-context', 'set-file-times', 'set-fontset-font', |
|
1857 'set-frame-height', 'set-frame-position', 'set-frame-selected-window', |
|
1858 'set-frame-size', 'set-frame-width', 'set-fringe-bitmap-face', |
|
1859 'set-input-interrupt-mode', 'set-input-meta-mode', 'set-input-mode', |
|
1860 'set-keyboard-coding-system-internal', 'set-keymap-parent', |
|
1861 'set-marker', 'set-marker-insertion-type', 'set-match-data', |
|
1862 'set-message-beep', 'set-minibuffer-window', |
|
1863 'set-mouse-pixel-position', 'set-mouse-position', |
|
1864 'set-network-process-option', 'set-output-flow-control', |
|
1865 'set-process-buffer', 'set-process-coding-system', |
|
1866 'set-process-datagram-address', 'set-process-filter', |
|
1867 'set-process-filter-multibyte', |
|
1868 'set-process-inherit-coding-system-flag', 'set-process-plist', |
|
1869 'set-process-query-on-exit-flag', 'set-process-sentinel', |
|
1870 'set-process-window-size', 'set-quit-char', |
|
1871 'set-safe-terminal-coding-system-internal', 'set-screen-color', |
|
1872 'set-standard-case-table', 'set-syntax-table', |
|
1873 'set-terminal-coding-system-internal', 'set-terminal-local-value', |
|
1874 'set-terminal-parameter', 'set-text-properties', 'set-time-zone-rule', |
|
1875 'set-visited-file-modtime', 'set-window-buffer', |
|
1876 'set-window-combination-limit', 'set-window-configuration', |
|
1877 'set-window-dedicated-p', 'set-window-display-table', |
|
1878 'set-window-fringes', 'set-window-hscroll', 'set-window-margins', |
|
1879 'set-window-new-normal', 'set-window-new-pixel', |
|
1880 'set-window-new-total', 'set-window-next-buffers', |
|
1881 'set-window-parameter', 'set-window-point', 'set-window-prev-buffers', |
|
1882 'set-window-redisplay-end-trigger', 'set-window-scroll-bars', |
|
1883 'set-window-start', 'set-window-vscroll', 'setcar', 'setcdr', |
|
1884 'setplist', 'show-face-resources', 'signal', 'signal-process', 'sin', |
|
1885 'single-key-description', 'skip-chars-backward', 'skip-chars-forward', |
|
1886 'skip-syntax-backward', 'skip-syntax-forward', 'sleep-for', 'sort', |
|
1887 'sort-charsets', 'special-variable-p', 'split-char', |
|
1888 'split-window-internal', 'sqrt', 'standard-case-table', |
|
1889 'standard-category-table', 'standard-syntax-table', 'start-kbd-macro', |
|
1890 'start-process', 'stop-process', 'store-kbd-macro-event', 'string', |
|
1891 'string-as-multibyte', 'string-as-unibyte', 'string-bytes', |
|
1892 'string-collate-equalp', 'string-collate-lessp', 'string-equal', |
|
1893 'string-lessp', 'string-make-multibyte', 'string-make-unibyte', |
|
1894 'string-match', 'string-to-char', 'string-to-multibyte', |
|
1895 'string-to-number', 'string-to-syntax', 'string-to-unibyte', |
|
1896 'string-width', 'stringp', 'subr-name', 'subrp', |
|
1897 'subst-char-in-region', 'substitute-command-keys', |
|
1898 'substitute-in-file-name', 'substring', 'substring-no-properties', |
|
1899 'suspend-emacs', 'suspend-tty', 'suspicious-object', 'sxhash', |
|
1900 'symbol-function', 'symbol-name', 'symbol-plist', 'symbol-value', |
|
1901 'symbolp', 'syntax-table', 'syntax-table-p', 'system-groups', |
|
1902 'system-move-file-to-trash', 'system-name', 'system-users', 'tan', |
|
1903 'terminal-coding-system', 'terminal-list', 'terminal-live-p', |
|
1904 'terminal-local-value', 'terminal-name', 'terminal-parameter', |
|
1905 'terminal-parameters', 'terpri', 'test-completion', |
|
1906 'text-char-description', 'text-properties-at', 'text-property-any', |
|
1907 'text-property-not-all', 'this-command-keys', |
|
1908 'this-command-keys-vector', 'this-single-command-keys', |
|
1909 'this-single-command-raw-keys', 'time-add', 'time-less-p', |
|
1910 'time-subtract', 'tool-bar-get-system-style', 'tool-bar-height', |
|
1911 'tool-bar-pixel-width', 'top-level', 'trace-redisplay', |
|
1912 'trace-to-stderr', 'translate-region-internal', 'transpose-regions', |
|
1913 'truncate', 'try-completion', 'tty-display-color-cells', |
|
1914 'tty-display-color-p', 'tty-no-underline', |
|
1915 'tty-suppress-bold-inverse-default-colors', 'tty-top-frame', |
|
1916 'tty-type', 'type-of', 'undo-boundary', 'unencodable-char-position', |
|
1917 'unhandled-file-name-directory', 'unibyte-char-to-multibyte', |
|
1918 'unibyte-string', 'unicode-property-table-internal', 'unify-charset', |
|
1919 'unintern', 'unix-sync', 'unlock-buffer', 'upcase', 'upcase-initials', |
|
1920 'upcase-initials-region', 'upcase-region', 'upcase-word', |
|
1921 'use-global-map', 'use-local-map', 'user-full-name', |
|
1922 'user-login-name', 'user-real-login-name', 'user-real-uid', |
|
1923 'user-uid', 'variable-binding-locus', 'vconcat', 'vector', |
|
1924 'vector-or-char-table-p', 'vectorp', 'verify-visited-file-modtime', |
|
1925 'vertical-motion', 'visible-frame-list', 'visited-file-modtime', |
|
1926 'w16-get-clipboard-data', 'w16-selection-exists-p', |
|
1927 'w16-set-clipboard-data', 'w32-battery-status', |
|
1928 'w32-default-color-map', 'w32-define-rgb-color', |
|
1929 'w32-display-monitor-attributes-list', 'w32-frame-menu-bar-size', |
|
1930 'w32-frame-rect', 'w32-get-clipboard-data', |
|
1931 'w32-get-codepage-charset', 'w32-get-console-codepage', |
|
1932 'w32-get-console-output-codepage', 'w32-get-current-locale-id', |
|
1933 'w32-get-default-locale-id', 'w32-get-keyboard-layout', |
|
1934 'w32-get-locale-info', 'w32-get-valid-codepages', |
|
1935 'w32-get-valid-keyboard-layouts', 'w32-get-valid-locale-ids', |
|
1936 'w32-has-winsock', 'w32-long-file-name', 'w32-reconstruct-hot-key', |
|
1937 'w32-register-hot-key', 'w32-registered-hot-keys', |
|
1938 'w32-selection-exists-p', 'w32-send-sys-command', |
|
1939 'w32-set-clipboard-data', 'w32-set-console-codepage', |
|
1940 'w32-set-console-output-codepage', 'w32-set-current-locale', |
|
1941 'w32-set-keyboard-layout', 'w32-set-process-priority', |
|
1942 'w32-shell-execute', 'w32-short-file-name', 'w32-toggle-lock-key', |
|
1943 'w32-unload-winsock', 'w32-unregister-hot-key', 'w32-window-exists-p', |
|
1944 'w32notify-add-watch', 'w32notify-rm-watch', |
|
1945 'waiting-for-user-input-p', 'where-is-internal', 'widen', |
|
1946 'widget-apply', 'widget-get', 'widget-put', |
|
1947 'window-absolute-pixel-edges', 'window-at', 'window-body-height', |
|
1948 'window-body-width', 'window-bottom-divider-width', 'window-buffer', |
|
1949 'window-combination-limit', 'window-configuration-frame', |
|
1950 'window-configuration-p', 'window-dedicated-p', |
|
1951 'window-display-table', 'window-edges', 'window-end', 'window-frame', |
|
1952 'window-fringes', 'window-header-line-height', 'window-hscroll', |
|
1953 'window-inside-absolute-pixel-edges', 'window-inside-edges', |
|
1954 'window-inside-pixel-edges', 'window-left-child', |
|
1955 'window-left-column', 'window-line-height', 'window-list', |
|
1956 'window-list-1', 'window-live-p', 'window-margins', |
|
1957 'window-minibuffer-p', 'window-mode-line-height', 'window-new-normal', |
|
1958 'window-new-pixel', 'window-new-total', 'window-next-buffers', |
|
1959 'window-next-sibling', 'window-normal-size', 'window-old-point', |
|
1960 'window-parameter', 'window-parameters', 'window-parent', |
|
1961 'window-pixel-edges', 'window-pixel-height', 'window-pixel-left', |
|
1962 'window-pixel-top', 'window-pixel-width', 'window-point', |
|
1963 'window-prev-buffers', 'window-prev-sibling', |
|
1964 'window-redisplay-end-trigger', 'window-resize-apply', |
|
1965 'window-resize-apply-total', 'window-right-divider-width', |
|
1966 'window-scroll-bar-height', 'window-scroll-bar-width', |
|
1967 'window-scroll-bars', 'window-start', 'window-system', |
|
1968 'window-text-height', 'window-text-pixel-size', 'window-text-width', |
|
1969 'window-top-child', 'window-top-line', 'window-total-height', |
|
1970 'window-total-width', 'window-use-time', 'window-valid-p', |
|
1971 'window-vscroll', 'windowp', 'write-char', 'write-region', |
|
1972 'x-backspace-delete-keys-p', 'x-change-window-property', |
|
1973 'x-change-window-property', 'x-close-connection', |
|
1974 'x-close-connection', 'x-create-frame', 'x-create-frame', |
|
1975 'x-delete-window-property', 'x-delete-window-property', |
|
1976 'x-disown-selection-internal', 'x-display-backing-store', |
|
1977 'x-display-backing-store', 'x-display-color-cells', |
|
1978 'x-display-color-cells', 'x-display-grayscale-p', |
|
1979 'x-display-grayscale-p', 'x-display-list', 'x-display-list', |
|
1980 'x-display-mm-height', 'x-display-mm-height', 'x-display-mm-width', |
|
1981 'x-display-mm-width', 'x-display-monitor-attributes-list', |
|
1982 'x-display-pixel-height', 'x-display-pixel-height', |
|
1983 'x-display-pixel-width', 'x-display-pixel-width', 'x-display-planes', |
|
1984 'x-display-planes', 'x-display-save-under', 'x-display-save-under', |
|
1985 'x-display-screens', 'x-display-screens', 'x-display-visual-class', |
|
1986 'x-display-visual-class', 'x-family-fonts', 'x-file-dialog', |
|
1987 'x-file-dialog', 'x-file-dialog', 'x-focus-frame', 'x-frame-geometry', |
|
1988 'x-frame-geometry', 'x-get-atom-name', 'x-get-resource', |
|
1989 'x-get-selection-internal', 'x-hide-tip', 'x-hide-tip', |
|
1990 'x-list-fonts', 'x-load-color-file', 'x-menu-bar-open-internal', |
|
1991 'x-menu-bar-open-internal', 'x-open-connection', 'x-open-connection', |
|
1992 'x-own-selection-internal', 'x-parse-geometry', 'x-popup-dialog', |
|
1993 'x-popup-menu', 'x-register-dnd-atom', 'x-select-font', |
|
1994 'x-select-font', 'x-selection-exists-p', 'x-selection-owner-p', |
|
1995 'x-send-client-message', 'x-server-max-request-size', |
|
1996 'x-server-max-request-size', 'x-server-vendor', 'x-server-vendor', |
|
1997 'x-server-version', 'x-server-version', 'x-show-tip', 'x-show-tip', |
|
1998 'x-synchronize', 'x-synchronize', 'x-uses-old-gtk-dialog', |
|
1999 'x-window-property', 'x-window-property', 'x-wm-set-size-hint', |
|
2000 'xw-color-defined-p', 'xw-color-defined-p', 'xw-color-values', |
|
2001 'xw-color-values', 'xw-display-color-p', 'xw-display-color-p', |
|
2002 'yes-or-no-p', 'zlib-available-p', 'zlib-decompress-region', |
|
2003 'forward-point', |
|
2004 )) |
|
2005 |
|
2006 builtin_function_highlighted = set(( |
|
2007 'defvaralias', 'provide', 'require', |
|
2008 'with-no-warnings', 'define-widget', 'with-electric-help', |
|
2009 'throw', 'defalias', 'featurep' |
|
2010 )) |
|
2011 |
|
2012 lambda_list_keywords = set(( |
|
2013 '&allow-other-keys', '&aux', '&body', '&environment', '&key', '&optional', |
|
2014 '&rest', '&whole', |
|
2015 )) |
|
2016 |
|
2017 error_keywords = set(( |
|
2018 'cl-assert', 'cl-check-type', 'error', 'signal', |
|
2019 'user-error', 'warn', |
|
2020 )) |
|
2021 |
|
2022 def get_tokens_unprocessed(self, text): |
|
2023 stack = ['root'] |
|
2024 for index, token, value in RegexLexer.get_tokens_unprocessed(self, text, stack): |
|
2025 if token is Name.Variable: |
|
2026 if value in EmacsLispLexer.builtin_function: |
|
2027 yield index, Name.Function, value |
|
2028 continue |
|
2029 if value in EmacsLispLexer.special_forms: |
|
2030 yield index, Keyword, value |
|
2031 continue |
|
2032 if value in EmacsLispLexer.error_keywords: |
|
2033 yield index, Name.Exception, value |
|
2034 continue |
|
2035 if value in EmacsLispLexer.builtin_function_highlighted: |
|
2036 yield index, Name.Builtin, value |
|
2037 continue |
|
2038 if value in EmacsLispLexer.macros: |
|
2039 yield index, Name.Builtin, value |
|
2040 continue |
|
2041 if value in EmacsLispLexer.lambda_list_keywords: |
|
2042 yield index, Keyword.Pseudo, value |
|
2043 continue |
|
2044 yield index, token, value |
|
2045 |
|
2046 tokens = { |
|
2047 'root': [ |
|
2048 default('body'), |
|
2049 ], |
|
2050 'body': [ |
|
2051 # whitespace |
|
2052 (r'\s+', Text), |
|
2053 |
|
2054 # single-line comment |
|
2055 (r';.*$', Comment.Single), |
|
2056 |
|
2057 # strings and characters |
|
2058 (r'"', String, 'string'), |
|
2059 (r'\?([^\\]|\\.)', String.Char), |
|
2060 # quoting |
|
2061 (r":" + symbol, Name.Builtin), |
|
2062 (r"::" + symbol, String.Symbol), |
|
2063 (r"'" + symbol, String.Symbol), |
|
2064 (r"'", Operator), |
|
2065 (r"`", Operator), |
|
2066 |
|
2067 # decimal numbers |
|
2068 (r'[-+]?\d+\.?' + terminated, Number.Integer), |
|
2069 (r'[-+]?\d+/\d+' + terminated, Number), |
|
2070 (r'[-+]?(\d*\.\d+([defls][-+]?\d+)?|\d+(\.\d*)?[defls][-+]?\d+)' + |
|
2071 terminated, Number.Float), |
|
2072 |
|
2073 # vectors |
|
2074 (r'\[|\]', Punctuation), |
|
2075 |
|
2076 # uninterned symbol |
|
2077 (r'#:' + symbol, String.Symbol), |
|
2078 |
|
2079 # read syntax for char tables |
|
2080 (r'#\^\^?', Operator), |
|
2081 |
|
2082 # function shorthand |
|
2083 (r'#\'', Name.Function), |
|
2084 |
|
2085 # binary rational |
|
2086 (r'#[bB][+-]?[01]+(/[01]+)?', Number.Bin), |
|
2087 |
|
2088 # octal rational |
|
2089 (r'#[oO][+-]?[0-7]+(/[0-7]+)?', Number.Oct), |
|
2090 |
|
2091 # hex rational |
|
2092 (r'#[xX][+-]?[0-9a-fA-F]+(/[0-9a-fA-F]+)?', Number.Hex), |
|
2093 |
|
2094 # radix rational |
|
2095 (r'#\d+r[+-]?[0-9a-zA-Z]+(/[0-9a-zA-Z]+)?', Number), |
|
2096 |
|
2097 # reference |
|
2098 (r'#\d+=', Operator), |
|
2099 (r'#\d+#', Operator), |
|
2100 |
|
2101 # special operators that should have been parsed already |
|
2102 (r'(,@|,|\.|:)', Operator), |
|
2103 |
|
2104 # special constants |
|
2105 (r'(t|nil)' + terminated, Name.Constant), |
|
2106 |
|
2107 # functions and variables |
|
2108 (r'\*' + symbol + '\*', Name.Variable.Global), |
|
2109 (symbol, Name.Variable), |
|
2110 |
|
2111 # parentheses |
|
2112 (r'#\(', Operator, 'body'), |
|
2113 (r'\(', Punctuation, 'body'), |
|
2114 (r'\)', Punctuation, '#pop'), |
|
2115 ], |
|
2116 'string': [ |
|
2117 (r'[^"\\`]+', String), |
|
2118 (r'`%s\'' % symbol, String.Symbol), |
|
2119 (r'`', String), |
|
2120 (r'\\.', String), |
|
2121 (r'\\\n', String), |
|
2122 (r'"', String, '#pop'), |
|
2123 ], |
|
2124 } |
|
2125 |
|
2126 |
|
2127 class ShenLexer(RegexLexer): |
|
2128 """ |
|
2129 Lexer for `Shen <http://shenlanguage.org/>`_ source code. |
|
2130 |
|
2131 .. versionadded:: 2.1 |
|
2132 """ |
|
2133 name = 'Shen' |
|
2134 aliases = ['shen'] |
|
2135 filenames = ['*.shen'] |
|
2136 mimetypes = ['text/x-shen', 'application/x-shen'] |
|
2137 |
|
2138 DECLARATIONS = re.findall(r'\S+', """ |
|
2139 datatype define defmacro defprolog defcc synonyms declare package |
|
2140 type function |
|
2141 """) |
|
2142 |
|
2143 SPECIAL_FORMS = re.findall(r'\S+', """ |
|
2144 lambda get let if cases cond put time freeze value load $ |
|
2145 protect or and not do output prolog? trap-error error |
|
2146 make-string /. set @p @s @v |
|
2147 """) |
|
2148 |
|
2149 BUILTINS = re.findall(r'\S+', """ |
|
2150 == = * + - / < > >= <= <-address <-vector abort absvector |
|
2151 absvector? address-> adjoin append arity assoc bind boolean? |
|
2152 bound? call cd close cn compile concat cons cons? cut destroy |
|
2153 difference element? empty? enable-type-theory error-to-string |
|
2154 eval eval-kl exception explode external fail fail-if file |
|
2155 findall fix fst fwhen gensym get-time hash hd hdstr hdv head |
|
2156 identical implementation in include include-all-but inferences |
|
2157 input input+ integer? intern intersection is kill language |
|
2158 length limit lineread loaded macro macroexpand map mapcan |
|
2159 maxinferences mode n->string nl nth null number? occurrences |
|
2160 occurs-check open os out port porters pos pr preclude |
|
2161 preclude-all-but print profile profile-results ps quit read |
|
2162 read+ read-byte read-file read-file-as-bytelist |
|
2163 read-file-as-string read-from-string release remove return |
|
2164 reverse run save set simple-error snd specialise spy step |
|
2165 stinput stoutput str string->n string->symbol string? subst |
|
2166 symbol? systemf tail tc tc? thaw tl tlstr tlv track tuple? |
|
2167 undefmacro unify unify! union unprofile unspecialise untrack |
|
2168 variable? vector vector-> vector? verified version warn when |
|
2169 write-byte write-to-file y-or-n? |
|
2170 """) |
|
2171 |
|
2172 BUILTINS_ANYWHERE = re.findall(r'\S+', """ |
|
2173 where skip >> _ ! <e> <!> |
|
2174 """) |
|
2175 |
|
2176 MAPPINGS = dict((s, Keyword) for s in DECLARATIONS) |
|
2177 MAPPINGS.update((s, Name.Builtin) for s in BUILTINS) |
|
2178 MAPPINGS.update((s, Keyword) for s in SPECIAL_FORMS) |
|
2179 |
|
2180 valid_symbol_chars = r'[\w!$%*+,<=>?/.\'@&#:_-]' |
|
2181 valid_name = '%s+' % valid_symbol_chars |
|
2182 symbol_name = r'[a-z!$%%*+,<=>?/.\'@&#_-]%s*' % valid_symbol_chars |
|
2183 variable = r'[A-Z]%s*' % valid_symbol_chars |
|
2184 |
|
2185 tokens = { |
|
2186 'string': [ |
|
2187 (r'"', String, '#pop'), |
|
2188 (r'c#\d{1,3};', String.Escape), |
|
2189 (r'~[ARS%]', String.Interpol), |
|
2190 (r'(?s).', String), |
|
2191 ], |
|
2192 |
|
2193 'root': [ |
|
2194 (r'(?s)\\\*.*?\*\\', Comment.Multiline), # \* ... *\ |
|
2195 (r'\\\\.*', Comment.Single), # \\ ... |
|
2196 (r'\s+', Text), |
|
2197 (r'_{5,}', Punctuation), |
|
2198 (r'={5,}', Punctuation), |
|
2199 (r'(;|:=|\||--?>|<--?)', Punctuation), |
|
2200 (r'(:-|:|\{|\})', Literal), |
|
2201 (r'[+-]*\d*\.\d+(e[+-]?\d+)?', Number.Float), |
|
2202 (r'[+-]*\d+', Number.Integer), |
|
2203 (r'"', String, 'string'), |
|
2204 (variable, Name.Variable), |
|
2205 (r'(true|false|<>|\[\])', Keyword.Pseudo), |
|
2206 (symbol_name, Literal), |
|
2207 (r'(\[|\]|\(|\))', Punctuation), |
|
2208 ], |
|
2209 } |
|
2210 |
|
2211 def get_tokens_unprocessed(self, text): |
|
2212 tokens = RegexLexer.get_tokens_unprocessed(self, text) |
|
2213 tokens = self._process_symbols(tokens) |
|
2214 tokens = self._process_declarations(tokens) |
|
2215 return tokens |
|
2216 |
|
2217 def _relevant(self, token): |
|
2218 return token not in (Text, Comment.Single, Comment.Multiline) |
|
2219 |
|
2220 def _process_declarations(self, tokens): |
|
2221 opening_paren = False |
|
2222 for index, token, value in tokens: |
|
2223 yield index, token, value |
|
2224 if self._relevant(token): |
|
2225 if opening_paren and token == Keyword and value in self.DECLARATIONS: |
|
2226 declaration = value |
|
2227 for index, token, value in \ |
|
2228 self._process_declaration(declaration, tokens): |
|
2229 yield index, token, value |
|
2230 opening_paren = value == '(' and token == Punctuation |
|
2231 |
|
2232 def _process_symbols(self, tokens): |
|
2233 opening_paren = False |
|
2234 for index, token, value in tokens: |
|
2235 if opening_paren and token in (Literal, Name.Variable): |
|
2236 token = self.MAPPINGS.get(value, Name.Function) |
|
2237 elif token == Literal and value in self.BUILTINS_ANYWHERE: |
|
2238 token = Name.Builtin |
|
2239 opening_paren = value == '(' and token == Punctuation |
|
2240 yield index, token, value |
|
2241 |
|
2242 def _process_declaration(self, declaration, tokens): |
|
2243 for index, token, value in tokens: |
|
2244 if self._relevant(token): |
|
2245 break |
|
2246 yield index, token, value |
|
2247 |
|
2248 if declaration == 'datatype': |
|
2249 prev_was_colon = False |
|
2250 token = Keyword.Type if token == Literal else token |
|
2251 yield index, token, value |
|
2252 for index, token, value in tokens: |
|
2253 if prev_was_colon and token == Literal: |
|
2254 token = Keyword.Type |
|
2255 yield index, token, value |
|
2256 if self._relevant(token): |
|
2257 prev_was_colon = token == Literal and value == ':' |
|
2258 elif declaration == 'package': |
|
2259 token = Name.Namespace if token == Literal else token |
|
2260 yield index, token, value |
|
2261 elif declaration == 'define': |
|
2262 token = Name.Function if token == Literal else token |
|
2263 yield index, token, value |
|
2264 for index, token, value in tokens: |
|
2265 if self._relevant(token): |
|
2266 break |
|
2267 yield index, token, value |
|
2268 if value == '{' and token == Literal: |
|
2269 yield index, Punctuation, value |
|
2270 for index, token, value in self._process_signature(tokens): |
|
2271 yield index, token, value |
|
2272 else: |
|
2273 yield index, token, value |
|
2274 else: |
|
2275 token = Name.Function if token == Literal else token |
|
2276 yield index, token, value |
|
2277 |
|
2278 raise StopIteration |
|
2279 |
|
2280 def _process_signature(self, tokens): |
|
2281 for index, token, value in tokens: |
|
2282 if token == Literal and value == '}': |
|
2283 yield index, Punctuation, value |
|
2284 raise StopIteration |
|
2285 elif token in (Literal, Name.Function): |
|
2286 token = Name.Variable if value.istitle() else Keyword.Type |
|
2287 yield index, token, value |
|
2288 |
|
2289 |
|
2290 class CPSALexer(SchemeLexer): |
|
2291 """ |
|
2292 A CPSA lexer based on the CPSA language as of version 2.2.12 |
|
2293 |
|
2294 .. versionadded:: 2.1 |
|
2295 """ |
|
2296 name = 'CPSA' |
|
2297 aliases = ['cpsa'] |
|
2298 filenames = ['*.cpsa'] |
|
2299 mimetypes = [] |
|
2300 |
|
2301 # list of known keywords and builtins taken form vim 6.4 scheme.vim |
|
2302 # syntax file. |
|
2303 _keywords = ( |
|
2304 'herald', 'vars', 'defmacro', 'include', 'defprotocol', 'defrole', |
|
2305 'defskeleton', 'defstrand', 'deflistener', 'non-orig', 'uniq-orig', |
|
2306 'pen-non-orig', 'precedes', 'trace', 'send', 'recv', 'name', 'text', |
|
2307 'skey', 'akey', 'data', 'mesg', |
|
2308 ) |
|
2309 _builtins = ( |
|
2310 'cat', 'enc', 'hash', 'privk', 'pubk', 'invk', 'ltk', 'gen', 'exp', |
|
2311 ) |
|
2312 |
|
2313 # valid names for identifiers |
|
2314 # well, names can only not consist fully of numbers |
|
2315 # but this should be good enough for now |
|
2316 valid_name = r'[a-zA-Z0-9!$%&*+,/:<=>?@^_~|-]+' |
|
2317 |
|
2318 tokens = { |
|
2319 'root': [ |
|
2320 # the comments - always starting with semicolon |
|
2321 # and going to the end of the line |
|
2322 (r';.*$', Comment.Single), |
|
2323 |
|
2324 # whitespaces - usually not relevant |
|
2325 (r'\s+', Text), |
|
2326 |
|
2327 # numbers |
|
2328 (r'-?\d+\.\d+', Number.Float), |
|
2329 (r'-?\d+', Number.Integer), |
|
2330 # support for uncommon kinds of numbers - |
|
2331 # have to figure out what the characters mean |
|
2332 # (r'(#e|#i|#b|#o|#d|#x)[\d.]+', Number), |
|
2333 |
|
2334 # strings, symbols and characters |
|
2335 (r'"(\\\\|\\"|[^"])*"', String), |
|
2336 (r"'" + valid_name, String.Symbol), |
|
2337 (r"#\\([()/'\"._!ยง$%& ?=+-]{1}|[a-zA-Z0-9]+)", String.Char), |
|
2338 |
|
2339 # constants |
|
2340 (r'(#t|#f)', Name.Constant), |
|
2341 |
|
2342 # special operators |
|
2343 (r"('|#|`|,@|,|\.)", Operator), |
|
2344 |
|
2345 # highlight the keywords |
|
2346 (words(_keywords, suffix=r'\b'), Keyword), |
|
2347 |
|
2348 # first variable in a quoted string like |
|
2349 # '(this is syntactic sugar) |
|
2350 (r"(?<='\()" + valid_name, Name.Variable), |
|
2351 (r"(?<=#\()" + valid_name, Name.Variable), |
|
2352 |
|
2353 # highlight the builtins |
|
2354 (words(_builtins, prefix=r'(?<=\()', suffix=r'\b'), Name.Builtin), |
|
2355 |
|
2356 # the remaining functions |
|
2357 (r'(?<=\()' + valid_name, Name.Function), |
|
2358 # find the remaining variables |
|
2359 (valid_name, Name.Variable), |
|
2360 |
|
2361 # the famous parentheses! |
|
2362 (r'(\(|\))', Punctuation), |
|
2363 (r'(\[|\])', Punctuation), |
|
2364 ], |
|
2365 } |