branch: externals/yaml commit 37c176fc5cdcccfb1f846b9294b89a97e20a1178 Author: Zachary Romero <zacrom...@posteo.net> Commit: Zachary Romero <zacrom...@posteo.net>
Fix the anchor parse event turning maps into lists --- yaml-tests.el | 15 ++++++++++++++- yaml.el | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/yaml-tests.el b/yaml-tests.el index 9396dd7b32..efa21676ab 100644 --- a/yaml-tests.el +++ b/yaml-tests.el @@ -344,7 +344,20 @@ key-2: |2- ("key-2" . " ---\n ---")))) (should (equal (yaml-parse-string "''") "")) (should (equal (yaml-parse-string "foo: ''" :object-type 'alist) - '((foo . ""))))) + '((foo . "")))) + ;; anchor should produce same parse as without anchor + (should (equal (yaml-parse-string "bill-to: &id001 + city: East Centerville + state: KS +" :object-type 'alist + :object-key-type 'string + :string-values t) + (yaml-parse-string "bill-to: + city: East Centerville + state: KS +" :object-type 'alist + :object-key-type 'string + :string-values t)))) (ert-deftest yaml-parsing-completes () diff --git a/yaml.el b/yaml.el index c6daabe272..11965d3c3b 100644 --- a/yaml.el +++ b/yaml.el @@ -402,28 +402,28 @@ This flag is intended for development purposes.") Note that VALUE may be a complex object here. STYLE is currently unused." (let ((top-state (car yaml--state-stack)) - (value (cond - ((stringp value) (yaml--resolve-scalar-tag value)) - ((listp value) (yaml--format-list value)) - ((hash-table-p value) (yaml--format-object value)) - ((vectorp value) value) - ((not value) nil)))) + (value* (cond + ((stringp value) (yaml--resolve-scalar-tag value)) + ((listp value) (yaml--format-list value)) + ((hash-table-p value) (yaml--format-object value)) + ((vectorp value) value) + ((not value) nil)))) (cond ((not top-state) - (setq yaml--root value)) + (setq yaml--root value*)) ((equal top-state :anchor) (let* ((anchor (pop yaml--object-stack)) (name (nth 1 anchor))) - (puthash name value yaml--anchor-mappings) + (puthash name value* yaml--anchor-mappings) (pop yaml--state-stack) (yaml--scalar-event nil value))) ((equal top-state :sequence) (let ((l (car yaml--object-stack))) - (setcar yaml--object-stack (append l (list value))))) + (setcar yaml--object-stack (append l (list value*))))) ((equal top-state :mapping) (progn (push :mapping-value yaml--state-stack) - (push value yaml--cache))) + (push value* yaml--cache))) ((equal top-state :mapping-value) (progn (let ((key (pop yaml--cache)) @@ -434,18 +434,18 @@ This flag is intended for development purposes.") (setq key (intern key))) ((eql 'keyword yaml--parsing-object-key-type) (setq key (intern (format ":%s" key)))))) - (puthash key value table)) + (puthash key value* table)) (pop yaml--state-stack))) ((equal top-state :trail-comments) (pop yaml--state-stack) (let ((comment-text (pop yaml--object-stack))) - (unless (stringp value) + (unless (stringp value*) (error "Trail-comments can't be nested under non-string")) (yaml--scalar-event style (replace-regexp-in-string (concat (regexp-quote comment-text) "\n*\\'") "" - value )))) + value*)))) ((equal top-state nil)))) '(:scalar)) @@ -1092,7 +1092,7 @@ value. It defaults to the symbol :false." (length yaml--parsing-input))) (when yaml--parse-debug (message "Parsed data: %s" (pp-to-string res))) (yaml--walk-events res) - (if (zerop (hash-table-count yaml--anchor-mappings)) + (if (hash-table-empty-p yaml--anchor-mappings) yaml--root ;; Run event processing twice to resolve aliases. (let ((yaml--root nil)