Refactor rx code to fix import error with gdscript-rx macro

This commit is contained in:
Nathan Lovato
2020-02-17 07:36:34 -06:00
parent 92a1087a30
commit c633a6f4d1
5 changed files with 1512 additions and 1471 deletions

1424
emacs-rx.el Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -35,6 +35,7 @@
(require 'gdscript-customization)
(require 'gdscript-indent-and-nav)
(require 'gdscript-rx)
;; NOTE: this and the fill docstring function can be simplified. They're
;; originally from the Python package, which supports multiple docstrings fill

View File

@@ -31,6 +31,7 @@
;;; Code:
(require 'gdscript-utils)
(require 'gdscript-rx)
;;; Indentation

View File

@@ -36,11 +36,8 @@
(require 'gdscript-imenu)
(require 'gdscript-fill-paragraph)
(require 'gdscript-completion)
;; gdscript-rx is a copy of Emacs 27's rx module, to ensure compatibility with
;; Emacs 26
(if (version< emacs-version "27")
(require 'gdscript-rx))
(require 'gdscript-format)
(require 'gdscript-rx)
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.gd\\'" . gdscript-mode))
@@ -59,51 +56,10 @@
;; Indent specific
(define-key map "\177" 'gdscript-indent-dedent-line-backspace)
(define-key map (kbd "<backtab>") 'gdscript-indent-dedent-line)
(define-key map (kbd "\t") 'company-complete)
map)
"Keymap for `gdscript-mode'.")
;;; GDScript regex
(defmacro gdscript-rx (&rest regexps)
"Gdscript mode specialized rx macro.
This variant of `rx' supports common Gdscript named REGEXPS."
`(rx-let ((block-start (seq symbol-start
(or "func" "static" "class" "if" "elif" "else"
"for" "while" "match")
symbol-end))
(dedenter (seq symbol-start
(or "elif" "else")
symbol-end))
(block-ender (seq symbol-start
(or "break" "continue" "pass" "return")
symbol-end))
(defun (seq symbol-start
(or "func" "class" "static func")
symbol-end))
(symbol-name (seq (any letter ?_) (* (any word ?_))))
(open-paren (or "{" "[" "("))
(close-paren (or "}" "]" ")"))
(simple-operator (any ?+ ?- ?/ ?& ?^ ?~ ?| ?* ?< ?> ?= ?%))
(not-simple-operator (not simple-operator))
;; TODO: clean up operators that don't exist in GDScript
(operator (or "==" ">=" "is" "not"
"**" "//" "<<" ">>" "<=" "!="
"+" "-" "/" "&" "^" "~" "|" "*" "<" ">"
"=" "%"))
(assignment-operator (or "+=" "-=" "*=" "/=" "//=" "%=" "**="
">>=" "<<=" "&=" "^=" "|="
"="))
(string-delimiter (seq
;; Match even number of backslashes.
(or (not (any ?\\ ?\' ?\")) point
;; Quotes might be preceded by an
;; escaped quote.
(and (or (not (any ?\\)) point) ?\\
(* ?\\ ?\\) (any ?\' ?\")))
(* ?\\ ?\\)
;; Match single or triple quotes of any kind.
(group (or "\"\"\"" "\"" "'''" "'")))))
(rx ,@regexps)))
(defun gdscript-hideshow-forward-sexp-function (_arg)
"Gdscript specific `forward-sexp' function for `hs-minor-mode'.
Argument ARG is ignored."

File diff suppressed because it is too large Load Diff