[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/yaml 9e18a714f5 006/124: completing tracer to parse bas
From: |
ELPA Syncer |
Subject: |
[elpa] externals/yaml 9e18a714f5 006/124: completing tracer to parse basic key-value |
Date: |
Fri, 29 Nov 2024 15:59:52 -0500 (EST) |
branch: externals/yaml
commit 9e18a714f5da92d089aa5ab3b9b6b21c6d07dbeb
Author: Zachary Romero <zacromero@posteo.net>
Commit: Zachary Romero <zacromero@posteo.net>
completing tracer to parse basic key-value
---
yaml.el | 111 ++++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 77 insertions(+), 34 deletions(-)
diff --git a/yaml.el b/yaml.el
index b6f62c6171..e21dc72ee3 100644
--- a/yaml.el
+++ b/yaml.el
@@ -152,6 +152,20 @@
;; Receiver Functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(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)
+
+(defvar yaml--cache nil)
+(defvar yaml--object-stack nil)
+(defvar yaml--state-stack nil
+ "The state that the YAML parser is with regards to incoming events.")
+(defvar yaml--root nil)
+
(defun yaml--add-event (e)
"Add event E."
(message "Adding event: %s" e))
@@ -164,29 +178,52 @@
"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)
+(defun yaml--document-start-event (explicit)
+ '(:document-start))
+(defun yaml--document-end-event (explicit)
+ '(:document-end))
+
+(defun yaml--mapping-start-event (flow)
+ (push :mapping yaml--state-stack)
+ (push (make-hash-table) yaml--object-stack)
+ '(:mapping-start))
+
+(defun yaml--mapping-end-event ()
+ (pop yaml--state-stack)
+ (let ((obj (pop yaml--object-stack)))
+ ;; TODO: Perhaps separate the logic here.
+ (yaml--scalar-event nil obj))
+ '(:mapping-end))
+
+(defun yaml--sequence-start-event (flow)
+ '(:sequence-start))
+
+(defun yaml--sequence-end-event ()
+ '(:sequence-end))
+
+(defun yaml--scalar-event (style value)
+ (let ((top-state (car yaml--state-stack)))
+ (cond
+ ((not top-state)
+ (setq yaml--root value))
+ ((equal top-state :mapping)
+ (progn
+ (push :mapping-value yaml--state-stack)
+ (push value yaml--cache)))
+ ((equal top-state :mapping-value)
+ (progn
+ (let ((key (pop yaml--cache))
+ (table (car yaml--object-stack)))
+ (puthash key value table))
+ (pop yaml--state-stack)))
+ ((equal top-state nil))))
+ '(:scalar))
+
+(defun yaml--alias-event (name)
+ '(:alias))
+
+(defun yaml--check-document-start () t)
+(defun yaml--check-document-end () t)
(defconst yaml--grammar-events-in
'(("l-yaml-stream" . (lambda ()
@@ -194,14 +231,14 @@
(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))))
+ (yaml--add-event (yaml--document-start-event nil))))
("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 ()
+ ("l+block-mapping" . (lambda ()
(yaml--add-event (yaml--mapping-start-event nil))))
- ("l-block-sequence" . (lambda ()
+ ("l+block-sequence" . (lambda ()
(yaml--add-event (yaml--sequence-start-event
nil))))
("ns-l-compact-mapping" . (lambda ()
(yaml--add-event (yaml--mapping-start-event))))
@@ -212,7 +249,7 @@
(defconst yaml--grammar-events-out
'(("l-yaml-stream" . (lambda (text)
- (check-document-end)
+ (yaml--check-document-end)
(yaml--add-event (yaml--stream-end-event))))
("ns-yaml-version" . (lambda (text)
(when yaml--document-start-version
@@ -339,10 +376,11 @@
("c-ns-alias-node" . (lambda (text)
(yaml--add-event (yaml--alias-event (substring text
1)))))))
-(defun yaml--event-walker (tree)
+(defun yaml--walk-events (tree)
"Event walker iterates over the parse TREE and signals events based off of
the parsed rules."
+ ;;(message ">>> %s" tree)
(when (consp tree)
- (if (not (equal (car tree) t))
+ (if (stringp (car tree))
(let ((grammar-rule (car tree))
(text (cadr tree))
(children (caddr tree)))
@@ -350,11 +388,11 @@
(out-fn (cdr (assoc grammar-rule yaml--grammar-events-out))))
(when in-fn
(funcall in-fn))
- (yaml--event-walker children)
+ (yaml--walk-events children)
(when out-fn
(funcall out-fn text))))
- (yaml--event-walker (car tree))
- (yaml--event-walker (cdr tree)))))
+ (yaml--walk-events (car tree))
+ (yaml--walk-events (cdr tree)))))
(defmacro yaml--frame (name rule)
@@ -619,13 +657,18 @@
(defun yaml-parse-string (str)
"Parse STR as YAML."
+ (setq yaml--cache nil)
+ (setq yaml--object-stack nil)
+ (setq yaml--state-stack nil)
+ (setq yaml--root nil)
(let ((res (yaml-parse str
(yaml--top))))
(when (< yaml-parsing-position (length yaml-parsing-input))
(error (format "parser finished before end of input %s/%s"
yaml-parsing-position
- (length yaml-parsing-input)) ))
- res))
+ (length yaml-parsing-input))))
+ (message "Parsed data: %s" res)
+ (yaml--walk-events res)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- [elpa] externals/yaml c07cc6d0f3 089/124: Merge pull request #35 from zkry/fix-yaml-anchor-match-definition, (continued)
- [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, 2024/11/29
- [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 <=
- [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
- [elpa] externals/yaml e32e11be66 026/124: Fix l+block-sequence bug sequence with e-node, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml ab86db9bb2 044/124: Merge pull request #4 from zkry/pcase-related-modifications, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml ada133f0b1 036/124: Fix regexp to match end of string, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 9170ff5cf8 038/124: Add LICENSE; Add documentation, ELPA Syncer, 2024/11/29