1
0
Fork 0

- prefixed all parsing rule for keybindings parsing to avoid clash with other rules in the code.

This commit is contained in:
cage 2024-06-19 15:48:14 +02:00
parent 9c4503e3bd
commit 61f8a68313
1 changed files with 44 additions and 42 deletions

View File

@ -89,49 +89,49 @@
;; FUNCTION-PLACEHOLDER := 'function-placeholder' ;; FUNCTION-PLACEHOLDER := 'function-placeholder'
(defrule function-placeholder "function-placeholder" (defrule keybindings-function-placeholder "function-placeholder"
(:constant +function-placeholder-value+)) (:constant +function-placeholder-value+))
(defrule blank (or #\space #\Newline #\Tab) (defrule keybindings-blank (or #\space #\Newline #\Tab)
(:constant nil)) (:constant nil))
(defrule blanks (* blank) (defrule keybindings-blanks (* blank)
(:constant nil)) (:constant nil))
(defrule escaped-character (and #\\ character) (defrule keybindings-escaped-character (and #\\ character)
(:function (lambda (a) (list (second a))))) (:function (lambda (a) (list (second a)))))
(defrule dash #\- (defrule keybindings-dash #\-
(:text t)) (:text t))
(defrule arrow-right "right" (defrule keybindings-arrow-right "right"
(:constant "key-arrow-right")) (:constant "key-arrow-right"))
(defrule arrow-left "left" (defrule keybindings-arrow-left "left"
(:constant "key-arrow-left")) (:constant "key-arrow-left"))
(defrule arrow-up "up" (defrule keybindings-arrow-up "up"
(:constant "key-arrow-up")) (:constant "key-arrow-up"))
(defrule arrow-down "down" (defrule keybindings-arrow-down "down"
(:constant "key-arrow-down")) (:constant "key-arrow-down"))
(defrule key-home "home" (defrule keybindings-key-home "home"
(:constant "key-home")) (:constant "key-home"))
(defrule key-end "end" (defrule keybindings-key-end "end"
(:constant "key-end")) (:constant "key-end"))
(defrule key-next-page "npage" (defrule keybindings-key-next-page "npage"
(:constant "key-next-page")) (:constant "key-next-page"))
(defrule key-previous-page "ppage" (defrule keybindings-key-previous-page "ppage"
(:constant "key-previous-page")) (:constant "key-previous-page"))
(defrule key-delete-next-char "dc" (defrule keybindings-key-delete-next-char "dc"
(:constant "key-delete-char")) (:constant "key-delete-char"))
(defrule non-printable-key (defrule keybindings-non-printable-key
(or "f10" (or "f10"
"f1" "f1"
"f2" "f2"
@ -163,7 +163,7 @@
(:text t) (:text t)
(:function string-upcase)) (:function string-upcase))
(defrule after-meta-key (defrule keybindings-after-meta-key
(or "right" (or "right"
"left" "left"
"up" "up"
@ -171,29 +171,31 @@
(:text t) (:text t)
(:function string-upcase)) (:function string-upcase))
(defrule char (defrule keybindings-char
(or escaped-character (or keybindings-escaped-character
(not (or dash blank))) (not (or keybindings-dash keybindings-blank)))
(:text t)) (:text t))
(defrule meta-mod #\M (defrule keybindings-meta-mod #\M
(:text t)) (:text t))
(defrule command-mod-1 #\C) (defrule keybindings-command-mod-1 #\C)
(defrule command-mod-2 #\^) (defrule keybindings-command-mod-2 #\^)
(defrule simple-key char) (defrule keybindings-simple-key keybindings-char)
(defrule keycode (or non-printable-key simple-key)) ; keep the order (defrule keybindings-keycode (or keybindings-non-printable-key
keybindings-simple-key)) ; keep the order
(defrule after-meta-keycode (or after-meta-key simple-key)) ; keep the order (defrule keybindings-after-meta-keycode (or keybindings-after-meta-key
keybindings-simple-key)) ; keep the order
(defun to-meta-code-string (command) (defun to-meta-code-string (command)
(strcat +meta-prefix+ (string-upcase (third command)))) (strcat +meta-prefix+ (string-upcase (third command))))
(defrule meta-key (defrule keybindings-meta-key
(and meta-mod dash after-meta-keycode) (and keybindings-meta-mod keybindings-dash keybindings-after-meta-keycode)
(:function to-meta-code-string) (:function to-meta-code-string)
(:text t)) (:text t))
@ -202,28 +204,28 @@
;; not part of the actual grammar, just syntactic sugar ;; not part of the actual grammar, just syntactic sugar
(defrule command-key-1 (defrule keybindings-command-key-1
(and command-mod-1 dash keycode) (and keybindings-command-mod-1 keybindings-dash keybindings-keycode)
(:function to-control-code-string)) (:function to-control-code-string))
(defrule command-key-2 (defrule keybindings-command-key-2
(and command-mod-2 keycode) (and keybindings-command-mod-2 keybindings-keycode)
(:text t)) (:text t))
(defrule command-key (defrule keybindings-command-key
(or command-key-1 (or keybindings-command-key-1
command-key-2)) keybindings-command-key-2))
(defrule key (defrule keybindings-key
(and (or function-placeholder ; keep the order (and (or keybindings-function-placeholder ; keep the order
command-key keybindings-command-key
meta-key keybindings-meta-key
keycode) keybindings-keycode)
(? blanks)) (? keybindings-blanks))
(:function first)) (:function first))
(defrule keypath (defrule keybindings-keypath
(and key (? keypath)) (and keybindings-key (? keybindings-keypath))
(:function (lambda (a) (remove-if-null (flatten a))))) (:function (lambda (a) (remove-if-null (flatten a)))))
(defun make-starting-comand-tree () (defun make-starting-comand-tree ()