[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/yaml a45f60c999 051/124: Merge pull request #8 from zkr
From: |
ELPA Syncer |
Subject: |
[elpa] externals/yaml a45f60c999 051/124: Merge pull request #8 from zkry/symbol-keys |
Date: |
Fri, 29 Nov 2024 16:00:00 -0500 (EST) |
branch: externals/yaml
commit a45f60c999bf1a3c860bb5138e26d48fef666b6f
Merge: 51023c4551 10af746dad
Author: Zachary Romero <zacromero@posteo.net>
Commit: GitHub <noreply@github.com>
Merge pull request #8 from zkry/symbol-keys
Add option to convert string keys to symbols
---
README.md | 5 ++++-
yaml-tests.el | 13 ++++++++++++-
yaml.el | 12 ++++++++++++
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 91c635d32b..11026f1559 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,10 @@ The following keyword args are accepted:
objects data in. It takes the following symbols:
- `hash-table` (default)
- `alist`
-n - `plist`
+ - `plist`
+- `:object-key-type` specifies how map keys should be handled. It takes the
following symbols:
+ - `string` (default)
+ - `symbol` keys of maps will be converted to symbols. Not that this matches
the behavior of the JSON parser.
- `:sequence-type` specifies the Lisp data structure to store the
parsed sequences in. It takes the following symbols:
- `array` (default)
diff --git a/yaml-tests.el b/yaml-tests.el
index 3b0c3fd8dd..67e0805b90 100644
--- a/yaml-tests.el
+++ b/yaml-tests.el
@@ -330,7 +330,18 @@ key-2: |2-
---"
:object-type 'alist)
'(("key-1" . " ---\n ---")
- ("key-2" . " ---\n ---")))))
+ ("key-2" . " ---\n ---"))))
+ (should (equal (yaml-parse-string "
+key-1: |-2
+ ---
+ ---
+key-2: |2-
+ ---
+ ---"
+ :object-key-type 'symbol
+ :object-type 'alist)
+ '((key-1 . " ---\n ---")
+ (key-2 . " ---\n ---")))))
(ert-deftest yaml-parsing-completes ()
diff --git a/yaml.el b/yaml.el
index 1184cadf67..aa9c812f75 100644
--- a/yaml.el
+++ b/yaml.el
@@ -74,6 +74,7 @@ This flag is intended for development purposes.")
"Stack of parsing states.")
(defvar yaml--parsing-object-type nil)
+(defvar yaml--parsing-object-key-type nil)
(defvar yaml--parsing-sequence-type nil)
(defvar yaml--parsing-null-object nil)
(defvar yaml--parsing-false-object nil)
@@ -412,6 +413,9 @@ This flag is intended for development purposes.")
(progn
(let ((key (pop yaml--cache))
(table (car yaml--object-stack)))
+ (when (and (eql 'symbol yaml--parsing-object-key-type)
+ (stringp key))
+ (setq key (intern key)))
(puthash key value table))
(pop yaml--state-stack)))
((equal top-state :trail-comments)
@@ -947,6 +951,7 @@ value. It defaults to the symbol :false."
(setq yaml--anchor-mappings (make-hash-table :test 'equal))
(setq yaml--resolve-aliases nil)
(let ((object-type (plist-get args :object-type))
+ (object-key-type (plist-get args :object-key-type))
(sequence-type (plist-get args :sequence-type))
(null-object (plist-get args :null-object))
(false-object (plist-get args :false-object)))
@@ -959,6 +964,13 @@ value. It defaults to the symbol :false."
((equal 'plist object-type)
(setq yaml--parsing-object-type 'plist))
(t (error "Invalid object-type. object-type must be hash-table, alist,
or plist")))
+ (cond
+ ((or (not object-key-type)
+ (equal 'string object-key-type))
+ (setq yaml--parsing-object-key-type 'string))
+ ((equal 'symbol object-key-type)
+ (setq yaml--parsing-object-key-type 'symbol))
+ (t (error "Invalid object-key-type. object-key-type must be string, or
symbol")))
(cond
((or (not sequence-type)
(equal sequence-type 'array))
- [elpa] externals/yaml e32e11be66 026/124: Fix l+block-sequence bug sequence with e-node, (continued)
- [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
- [elpa] externals/yaml 1fb0519023 039/124: Fix static check warnings, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml fbf28ffb1d 041/124: Add yaml-spec-1.2.json file, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml d8f676b54d 037/124: Add require for cl-lib, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml a90fc1580c 045/124: Update commentary file, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 79a6bbc1e1 040/124: Fix various parsing bugs; reduce stack usage of parsing strings, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 367f470203 029/124: Add github action file, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml a45f60c999 051/124: Merge pull request #8 from zkry/symbol-keys,
ELPA Syncer <=
- [elpa] externals/yaml 10af746dad 050/124: Add option to convert string keys to symbols, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 96d3e51aeb 048/124: Add yaml-encode feature, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 51023c4551 049/124: Merge pull request #7 from zkry/add-yaml-encode, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 8903b6c7e4 055/124: return plist key as a keyword as a default, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml ed108ab526 084/124: add option for skipping processing of scalars, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml a2ed8f1fd6 072/124: Fix empty single quote string bug, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 419e85fbce 094/124: fix folding block parsing error, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 0bf6a1b686 088/124: YAML anchor should match exactly how it was defined, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 2aa5a6faf7 056/124: Merge pull request #16 from conao3/indent, ELPA Syncer, 2024/11/29
- [elpa] externals/yaml 5b352258f5 067/124: Merge pull request #24 from j-shilling/fix-alist-to-hash, ELPA Syncer, 2024/11/29