[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/yaml 5c52737f17 005/124: Start on event handling
From: |
ELPA Syncer |
Subject: |
[elpa] externals/yaml 5c52737f17 005/124: Start on event handling |
Date: |
Fri, 29 Nov 2024 15:59:52 -0500 (EST) |
branch: externals/yaml
commit 5c52737f17c843fabaf53c9ce1439b3f05d7c3e7
Author: Zachary Romero <zacromero@posteo.net>
Commit: Zachary Romero <zacromero@posteo.net>
Start on event handling
---
yaml.el | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 215 insertions(+), 2 deletions(-)
diff --git a/yaml.el b/yaml.el
index 5357d156db..b6f62c6171 100644
--- a/yaml.el
+++ b/yaml.el
@@ -147,10 +147,216 @@
:end nil))))
(defconst yaml--grammar-resolution-rules
- '(("ns-plain" . literal)
- ("ns-s-block-map-implicit-key" . list))
+ '(("ns-plain" . literal))
"Alist determining how to resolve grammar rule.")
+;; Receiver Functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun yaml--add-event (e)
+ "Add event E."
+ (message "Adding event: %s" e))
+
+(defun yaml--stream-start-event ()
+ "Create the data for a stream-start event."
+ '(:stream-start))
+
+(defun yaml--stream-end-event ()
+ "Create the data for a stream-end event."
+ '(:stream-end))
+
+(defun yaml--document-start-event (explicit))
+(defun yaml--document-end-event (explicit))
+
+(defun yaml--mapping-start-event (flow))
+(defun yaml--mapping-end-event ())
+
+(defun yaml--sequence-start-event (flow))
+(defun yaml--sequence-end-event ())
+
+(defun yaml--scalar-event (style value))
+
+(defun yaml--alias-event (name))
+
+(defun yaml--check-document-start ())
+(defun yaml--check-document-end ())
+
+(defvar yaml--document-start-version nil)
+(defvar yaml--document-start-explicit nil)
+(defvar yaml--document-end-explicit nil)
+(defvar yaml--tag-map nil)
+(defvar yaml--tag-handle nil)
+(defvar yaml--anchor nil)
+(defvar yaml--document-end nil)
+
+(defconst yaml--grammar-events-in
+ '(("l-yaml-stream" . (lambda ()
+ (yaml--add-event (yaml--stream-start-event))
+ (setq yaml--document-start-version nil)
+ (setq yaml--document-start-explicit nil)
+ (setq yaml--tag-map (make-hash-table))
+ (yaml--add-event (yaml--document-start-event false))))
+ ("c-flow-mapping" . (lambda ()
+ (yaml--add-event (yaml--mapping-start-event t))))
+ ("c-flow-sequence" . (lambda ()
+ (yaml--add-event (yaml--sequence-start-event nil))))
+ ("l-block-mapping" . (lambda ()
+ (yaml--add-event (yaml--mapping-start-event nil))))
+ ("l-block-sequence" . (lambda ()
+ (yaml--add-event (yaml--sequence-start-event
nil))))
+ ("ns-l-compact-mapping" . (lambda ()
+ (yaml--add-event (yaml--mapping-start-event))))
+ ("ns-l-compact-sequence" . (lambda ()
+ (yaml--add-event (yaml--sequence-start-event
nil))))
+ ("ns-flow-pair" . (lambda ()
+ (yaml--add-event (yaml--mapping-start-event t))))))
+
+(defconst yaml--grammar-events-out
+ '(("l-yaml-stream" . (lambda (text)
+ (check-document-end)
+ (yaml--add-event (yaml--stream-end-event))))
+ ("ns-yaml-version" . (lambda (text)
+ (when yaml--document-start-version
+ (throw 'error "Multiple %YAML directives not
allowed."))
+ (setq yaml--document-start-version text)))
+ ("c-tag-handle" . (lambda (text)
+ (setq yaml--tag-handle text)))
+ ("ns-tag-prefix" . (lambda (text)
+ (puthash yaml--tag-handle text yaml--tag-map)))
+ ("c-directives-end" . (lambda (text)
+ (yaml--check-document-end)
+ (setq yaml--document-start-explicit t)))
+ ("c-document-end" . (lambda (text)
+ (when (not yaml--document-end)
+ (setq yaml--document-end-explicit t))
+ (yaml--check-document-end)))
+ ("c-flow-mapping" . (lambda (text)
+ (yaml--add-event (yaml--mapping-end-event t))))
+ ("c-flow-sequence" . (lambda (text)
+ (yaml--add-event (yaml--sequence-end-event ))))
+ ("l+block-mapping" . (lambda (text)
+ (yaml--add-event (yaml--mapping-end-event))))
+ ("l+block-sequence" . (lambda (text)
+ (yaml--add-event (yaml--sequence-end-event nil))))
+ ("ns-l-compact-mapping" . (lambda (text)
+ (yaml--add-event (yaml--mapping-end-event))))
+ ("ns-l-compact-sequence" . (lambda (text)
+ (yaml--add-event (yaml--sequence-end-event
nil))))
+ ("ns-flow-pair" . (lambda (text)
+ (yaml--add-event (yaml--mapping-end-event))))
+ ("ns-plain" . (lambda (text)
+ (let* ((replaced (replace-regexp-in-string
+ "\\(?:[ \t]*\r?\n[ \t]*\\)"
+ "\n"
+ text))
+ (replaced (replace-regexp-in-string
+ "\\(\n\\)\\(\n*\\)"
+ (lambda (x)
+ (if (> (length x) 1)
+ (substring x 1)
+ " "))
+ replaced)))
+ (yaml--add-event (yaml--scalar-event "plain"
replaced)))))
+ ("c-single-quoted" . (lambda (text)
+ (let* ((replaced (replace-regexp-in-string
+ "\\(?:[ \t]*\r?\n[ \t]*\\)"
+ "\n"
+ text))
+ (replaced (replace-regexp-in-string
+ "\\(\n\\)\\(\n*\\)"
+ (lambda (x)
+ (if (> (length x) 1)
+ (substring x 1)
+ " "))
+ replaced))
+ (replaced (replace-regexp-in-string
+ "''"
+ (lambda (x)
+ (if (> (length x) 1)
+ (substring x 1)
+ "'"))
+ replaced)))
+ (yaml--add-event (yaml--scalar-event "single"
replaced)))))
+ ("c-double-quoted" . (lambda (text)
+ (let* ((replaced (replace-regexp-in-string
+ "\\(?:[ \t]*\r?\n[ \t]*\\)"
+ "\n"
+ text))
+ (replaced (replace-regexp-in-string
+ "\\(\n\\)\\(\n*\\)"
+ (lambda (x)
+ (if (> (length x) 1)
+ (substring x 1)
+ " "))
+ replaced))
+ (replaced (replace-regexp-in-string
"\\\\\\([\"\\/]\\)" "\\1" replaced))
+ (replaced (replace-regexp-in-string "\\\\ "
" " replaced))
+ (replaced (replace-regexp-in-string "\\\\ "
" " replaced))
+ (replaced (replace-regexp-in-string "\\\\b"
"\b" replaced))
+ (replaced (replace-regexp-in-string "\\\\t"
"\t" replaced))
+ (replaced (replace-regexp-in-string "\\\\n"
"\n" replaced))
+ (replaced (replace-regexp-in-string "\\\\r"
"\r" replaced))
+ (replaced (replace-regexp-in-string "\\\\r"
"\r" replaced))
+ (replaced (replace-regexp-in-string
+ "\\\\x\\([0-9a-fA-F]\\{2\\}\\)"
+ (lambda (x)
+ (let ((char-pt (substring 2 x)))
+ (string (string-to-number
char-pt 16))))
+ replaced))
+ (replaced (replace-regexp-in-string
+ "\\\\x\\([0-9a-fA-F]\\{2\\}\\)"
+ (lambda (x)
+ (let ((char-pt (substring x 2)))
+ (string (string-to-number
char-pt 16))))
+ replaced))
+ (replaced (replace-regexp-in-string
+ "\\\\x\\([0-9a-fA-F]\\{4\\}\\)"
+ (lambda (x)
+ (let ((char-pt (substring x 2)))
+ (string (string-to-number
char-pt 16))))
+ replaced))
+ (replaced (replace-regexp-in-string
+ "\\\\x\\([0-9a-fA-F]\\{8\\}\\)"
+ (lambda (x)
+ (let ((char-pt (substring x 2)))
+ (string (string-to-number
char-pt 16))))
+ replaced))
+ (replaced (replace-regexp-in-string
+ "\\\\\\\\"
+ "\\"
+ replaced)))
+ (yaml--add-event (yaml--scalar-event "double"
replaced)))))
+ ("c-l+literal" . (lambda (text)
+ ;; TODO
+ (yaml--add-event (yaml--scalar-event "literal" text))))
+ ("c-l+folded" . (lambda (text)
+ (yaml--add-event (yaml--scalar-event "folded" text))))
+ ("e-scalar" . (lambda (text)
+ (yaml--add-event (yaml--scalar-event "plain" ""))))
+ ("c-ns-anchor-property" . (lambda (text)
+ (setq yaml--anchor (substring text 1))))
+ ("c-ns-tag-property" . (lambda (text)
+ (error "not implemented")))
+ ("c-ns-alias-node" . (lambda (text)
+ (yaml--add-event (yaml--alias-event (substring text
1)))))))
+
+(defun yaml--event-walker (tree)
+ "Event walker iterates over the parse TREE and signals events based off of
the parsed rules."
+ (when (consp tree)
+ (if (not (equal (car tree) t))
+ (let ((grammar-rule (car tree))
+ (text (cadr tree))
+ (children (caddr tree)))
+ (let ((in-fn (cdr (assoc grammar-rule yaml--grammar-events-in)))
+ (out-fn (cdr (assoc grammar-rule yaml--grammar-events-out))))
+ (when in-fn
+ (funcall in-fn))
+ (yaml--event-walker children)
+ (when out-fn
+ (funcall out-fn text))))
+ (yaml--event-walker (car tree))
+ (yaml--event-walker (cdr tree)))))
+
+
(defmacro yaml--frame (name rule)
"Add a new state frame of NAME for RULE."
(declare (indent defun))
@@ -188,6 +394,9 @@
nil
(let ((res-type (cdr (assoc ,name yaml--grammar-resolution-rules))))
(cond
+ ((or (assoc ,name yaml--grammar-events-in)
+ (assoc ,name yaml--grammar-events-out))
+ (list ,name (substring yaml-parsing-input beg
yaml-parsing-position) ,res-symbol))
((equal res-type 'list) (list ,name ,res-symbol))
((equal res-type 'literal) (substring yaml-parsing-input beg
yaml-parsing-position))
(t ,res-symbol))))))))
@@ -279,6 +488,10 @@
"Return non-nil."
'empty)
+(defun yaml--sub (a b)
+ "Return A minus B."
+ (- a b))
+
(defun yaml--match ()
""
(let* ((states yaml-states)
- [elpa] externals/yaml bda9a00090 058/124: return alist key as a symbol as a default, (continued)
- [elpa] externals/yaml bda9a00090 058/124: return alist key as a symbol as a default, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 45aa819a4f 068/124: Add MELPA tag to README, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 37c176fc5c 086/124: Fix the anchor parse event turning maps into lists, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml f546dac2a8 082/124: Initial implementation of position storage, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml c07cc6d0f3 089/124: Merge pull request #35 from zkry/fix-yaml-anchor-match-definition, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 14e6e4bc3d 095/124: Merge pull request #37 from zkry/fix-folded-block-parsing-error, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 0ac7f365bb 104/124: Merge pull request #41 from zkry/fix-property-prop-bug, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 900ca55584 119/124: Fix failing test for parsing scalars, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 964ef3b105 014/124: process literal and folded, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml a1d6e3211c 007/124: Initial working yaml-parser, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 5c52737f17 005/124: Start on event handling,
ELPA Syncer <=
- [elpa] externals/yaml aba7c19c47 020/124: Remove yaml spec, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 7c6c1e1abf 017/124: Rename names according to elisp standards, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 9a8ae65986 016/124: Reduce stack usage, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 9e18a714f5 006/124: completing tracer to parse basic key-value, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 0c51603d6d 018/124: Add tracing; fix linting errors, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 49f4ebd8ab 011/124: Minor bug fixes, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 70429bd21b 025/124: Fix s-l+block-indented bug; fix auto-detect-indent bug, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml ed9dded709 027/124: Fix l+block-mapping auto-detect-indent bug, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 837e3e3080 028/124: Format grammar code, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml b7cffd6d3e 021/124: Add .gitattributes file, ELPA Syncer, 2024/11/29