[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tomelr 1d65064ffa 20/84: feat: Recognize local date for
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tomelr 1d65064ffa 20/84: feat: Recognize local date format YYYY-MM-DD |
Date: |
Tue, 3 May 2022 09:58:09 -0400 (EDT) |
branch: externals/tomelr
commit 1d65064ffa0c6e1d5e9cb14a31de8ada38dc3395
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>
feat: Recognize local date format YYYY-MM-DD
---
README.org | 49 ++++++++++++++++++--------------
test/tscalar.el | 10 +++++++
tomelr.el | 86 ++++++++++++++++++++++++++++++++++-----------------------
3 files changed, 90 insertions(+), 55 deletions(-)
diff --git a/README.org b/README.org
index 6583e6dcca..757e641f7b 100644
--- a/README.org
+++ b/README.org
@@ -24,8 +24,8 @@ specification defined below.
- [X] Integer
- [X] Float
- [X] String
+ - [X] Date
- [ ] Date + Time with Offset
- - [ ] Date
- [ ] Nil
- [ ] Arrays
- [ ] Array of Arrays
@@ -181,51 +181,58 @@ Violets are blue"""
: "str1": "Roses are red",
: "str2": "Roses are red\nViolets are blue"
: }
-*** Date + Time with Offset
-https://toml.io/en/v1.0.0#offset-date-time
+*** DONE Date
+CLOSED: [2022-04-28 Thu 22:40]
+https://toml.io/en/v1.0.0#local-date
**** S-expression
-#+begin_src emacs-lisp :eval no :noweb-ref scalar-odt
-'((odt1 . "1979-05-27T07:32:00Z")
- (odt2 . "1979-05-27T00:32:00-07:00")
- (odt3 . "1979-05-27T00:32:00.999999-07:00"))
+#+begin_src emacs-lisp :eval no :noweb-ref scalar-date
+'((ld1 . "1979-05-27"))
#+end_src
**** TOML
+#+begin_src emacs-lisp :noweb yes :exports results :wrap src toml
+(tomelr-encode
+ <<scalar-date>>)
+#+end_src
+
+#+RESULTS:
#+begin_src toml
-odt1 = 1979-05-27T07:32:00Z
-odt2 = 1979-05-27T00:32:00-07:00
-odt3 = 1979-05-27T00:32:00.999999-07:00
+ld1 = 1979-05-27
#+end_src
**** JSON Reference
#+begin_src emacs-lisp :noweb yes :exports results
(json-encode-pretty
- <<scalar-odt>>)
+ <<scalar-date>>)
#+end_src
#+RESULTS:
: {
-: "odt1": "1979-05-27T07:32:00Z",
-: "odt2": "1979-05-27T00:32:00-07:00",
-: "odt3": "1979-05-27T00:32:00.999999-07:00"
+: "ld1": "1979-05-27"
: }
-*** Date
-https://toml.io/en/v1.0.0#local-date
+*** Date + Time with Offset
+https://toml.io/en/v1.0.0#offset-date-time
**** S-expression
-#+begin_src emacs-lisp :eval no :noweb-ref scalar-date
-'((ld1 . "1979-05-27"))
+#+begin_src emacs-lisp :eval no :noweb-ref scalar-odt
+'((odt1 . "1979-05-27T07:32:00Z")
+ (odt2 . "1979-05-27T00:32:00-07:00")
+ (odt3 . "1979-05-27T00:32:00.999999-07:00"))
#+end_src
**** TOML
#+begin_src toml
-ld1 = 1979-05-27
+odt1 = 1979-05-27T07:32:00Z
+odt2 = 1979-05-27T00:32:00-07:00
+odt3 = 1979-05-27T00:32:00.999999-07:00
#+end_src
**** JSON Reference
#+begin_src emacs-lisp :noweb yes :exports results
(json-encode-pretty
- <<scalar-date>>)
+ <<scalar-odt>>)
#+end_src
#+RESULTS:
: {
-: "ld1": "1979-05-27"
+: "odt1": "1979-05-27T07:32:00Z",
+: "odt2": "1979-05-27T00:32:00-07:00",
+: "odt3": "1979-05-27T00:32:00.999999-07:00"
: }
** TOML Arrays: Lists
https://toml.io/en/v1.0.0#array
diff --git a/test/tscalar.el b/test/tscalar.el
index 27fd940d00..12ebb081fa 100644
--- a/test/tscalar.el
+++ b/test/tscalar.el
@@ -90,5 +90,15 @@ Violets are blue\"\"\""
(push (tomelr-encode el) out))
(should (equal ref (nreverse out)))))
+;;;; Scalar - Local Date
+(ert-deftest test-scalar-date ()
+ (let ((inp '(((date . "1979-05-27"))))
+ (ref '("date = 1979-05-27"))
+ out)
+ (dolist (el inp)
+ (push (tomelr-encode el) out))
+ (should (equal ref (nreverse out)))))
+
+
(provide 'tscalar)
diff --git a/tomelr.el b/tomelr.el
index 342ba01a5d..28cf4b242d 100644
--- a/tomelr.el
+++ b/tomelr.el
@@ -60,6 +60,22 @@ Dictates repetitions of
`tomelr-encoding-default-indentation'.")
(defvar tomelr--print-keyval-separator " = "
"String used to separate key-value pairs during encoding.")
+(defvar tomelr--date-time-regexp
+ (concat "\\`[[:digit:]]\\{4\\}-[[:digit:]]\\{2\\}-[[:digit:]]\\{2\\}"
+ "\\(?:[T
][[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}\\(?:\\.[[:digit:]]+\\)*"
+ "\\(?:Z\\|[+-][[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}\\)*\\)*\\'")
+ "Regexp to match RFC 3339 formatted date-time with offset.
+
+- https://toml.io/en/v1.0.0#offset-date-time
+- https://tools.ietf.org/html/rfc3339#section-5.8
+
+Examples:
+ 1979-05-27
+ 1979-05-27T07:32:00Z
+ 1979-05-27 07:32:00Z
+ 1979-05-27T00:32:00-07:00
+ 1979-05-27T00:32:00.999999+04:00.")
+
;;; Error conditions
@@ -142,43 +158,45 @@ Return the same STRING passed as input."
(?\\ . ?\\)))
special-chars-re
begin-q end-q)
- ;; Use multi-line string quotation if the string contains a " char
- ;; or a newline.
- (if (string-match-p "\n\\|\"" string)
- (progn ;Triple quotation """STRING"""
- ;; From https://toml.io/en/v1.0.0#string, Any Unicode
- ;; character may be used except those that must be escaped:
- ;; backslash and the control characters other than tab, line
- ;; feed, and carriage return (U+0000 to U+0008, U+000B,
- ;; U+000C, U+000E to U+001F, U+007F).
- (setq special-chars-re (rx (in ?\\
- (?\u0000 . ?\u0008)
- ?\u000B ?\u000C
- (?\u000E . ?\u001F)
- ?\u007F)))
- (setq begin-q "\"\"\"\n")
- (setq end-q "\"\"\""))
- (progn ;Basic quotation "STRING"
- (setq special-chars-re (rx (in ?\" ?\\ cntrl ?\u007F))) ;cntrl is same
as (?\u0000 . ?\u001F)
- (push '(?\" . ?\") special-chars)
- (push '(?t . ?\t) special-chars) ;U+0009
- (push '(?n . ?\n) special-chars) ;U+000A
- (push '(?r . ?\r) special-chars) ;U+000D
- (setq begin-q "\"")
- (setq end-q begin-q)))
+ (cond
+ ((string-match-p tomelr--date-time-regexp string)) ;RFC 3339 formatted
date-time with offset
+ ;; Use multi-line string quotation if the string contains a " char
+ ;; or a newline - """STRING"""
+ ((string-match-p "\n\\|\"" string)
+ ;; From https://toml.io/en/v1.0.0#string, Any Unicode
+ ;; character may be used except those that must be escaped:
+ ;; backslash and the control characters other than tab, line
+ ;; feed, and carriage return (U+0000 to U+0008, U+000B,
+ ;; U+000C, U+000E to U+001F, U+007F).
+ (setq special-chars-re (rx (in ?\\
+ (?\u0000 . ?\u0008)
+ ?\u000B ?\u000C
+ (?\u000E . ?\u001F)
+ ?\u007F)))
+ (setq begin-q "\"\"\"\n")
+ (setq end-q "\"\"\""))
+ (t ;Basic quotation "STRING"
+ (setq special-chars-re (rx (in ?\" ?\\ cntrl ?\u007F))) ;cntrl is same
as (?\u0000 . ?\u001F)
+ (push '(?\" . ?\") special-chars)
+ (push '(?t . ?\t) special-chars) ;U+0009
+ (push '(?n . ?\n) special-chars) ;U+000A
+ (push '(?r . ?\r) special-chars) ;U+000D
+ (setq begin-q "\"")
+ (setq end-q begin-q)))
;; (message "[tomelr--print-string DBG] string = `%s'" string)
- (insert begin-q)
+ (and begin-q (insert begin-q))
(goto-char (prog1 (point) (princ string)))
(and trim-init-chars (delete-char trim-init-chars))
- (while (re-search-forward special-chars-re nil :noerror)
- (let ((char (preceding-char)))
- (delete-char -1)
- (insert ?\\ (or
- ;; Escape special characters
- (car (rassq char special-chars))
- ;; Fallback: UCS code point in \uNNNN form.
- (format "u%04x" char)))))
- (insert end-q)
+ (when special-chars-re
+ (while (re-search-forward special-chars-re nil :noerror)
+ (let ((char (preceding-char)))
+ (delete-char -1)
+ (insert ?\\ (or
+ ;; Escape special characters
+ (car (rassq char special-chars))
+ ;; Fallback: UCS code point in \uNNNN form.
+ (format "u%04x" char))))))
+ (and end-q (insert end-q))
string))
(defun tomelr-encode-string (string)
- [elpa] externals/tomelr 2ea3b5e032 03/84: fix!: Set boolean false using :false value, (continued)
- [elpa] externals/tomelr 2ea3b5e032 03/84: fix!: Set boolean false using :false value, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 28642f2e78 05/84: fix: dates will be strings in Lisp, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 52dc93201d 08/84: feat: First cut -- Port json-encode from json.el to tomelr-encode, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 7cd15e79b8 10/84: tool(ci): Add GHA setup, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr c872e9efc1 17/84: test: Add test for integer scalar key-value pairs, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr a1f434f03a 31/84: feat: Support nested TOML tables, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 6bbe740e52 28/84: test: Test that 'false is also considered as boolean false in TOML, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 9c91e0dc07 18/84: test: Add test for float scalar key-value pairs, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 96c890a68b 23/84: feat: Convert Lisp lists to TOML arrays, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr bb85106ee9 27/84: doc: Add spec for nested tables and arrays of tables, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 1d65064ffa 20/84: feat: Recognize local date format YYYY-MM-DD,
ELPA Syncer <=
- [elpa] externals/tomelr 2810504e84 32/84: feat: Add basic support for S-exp plists -> TOML conversion, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 0f4e7b4f2c 47/84: fix: Better detection of nested TTA, but still wip, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr cff1f8aa89 38/84: fix: Support TOML tables arrays specified as plist vector, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 4c419bcee2 37/84: fix: Support TOML tables specified as plists, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr baf81228bc 45/84: fix: Correct the spec for nested array of tables, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 4dda8e6be3 46/84: chore: Style edits in a test, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 5959b90ffa 44/84: fix: Don't let TOML tables be recognized as TOML tables arrays, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr b64eb07e99 49/84: fix: Detect TT with sub-tables correctly, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 4386d99a85 65/84: refactor(minor): Use `tomelr--toml-table-p`, ELPA Syncer, 2022/05/03
- [elpa] externals/tomelr 26f1fc2f3c 55/84: doc: Update the medley example, ELPA Syncer, 2022/05/03