-
Notifications
You must be signed in to change notification settings - Fork 8
/
schema.lisp
53 lines (48 loc) · 2.23 KB
/
schema.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(in-package "NYAML")
(defstruct schema
(null-names (list "null" "Null" "NULL" "~"))
(true-names (list "true" "True" "TRUE"))
(false-names (list "false" "False" "FALSE"))
(decimal-integer-scanner (ppcre:create-scanner "^([-+]?[0-9]+)$"))
(octal-integer-scanner (ppcre:create-scanner "^0o([0-7]+)$"))
(hex-integer-scanner (ppcre:create-scanner "^0x([0-9a-fA-F]+)$"))
(float-scanner (ppcre:create-scanner "^([-+])?(\\.[0-9]+|[0-9]+(?:\\.[0-9]*)?)([eE][-+]?[0-9]+)?$"))
(nan-names (list ".nan" ".NaN" ".NAN"))
(positive-infinity-scanner (ppcre:create-scanner "^[+]?(\\.inf|\\.Inf|\\.INF)$"))
(negative-infinity-scanner (ppcre:create-scanner "^-(\\.inf|\\.Inf|\\.INF)$")))
(defparameter +yaml-12-schema+ (make-schema))
(defparameter +match-nothing+
(cl-ppcre:create-scanner `(:filter ,(lambda (x) (declare (ignore x))nil))))
(defparameter +json-schema+ (make-schema
:null-names '("null")
:true-names '("true")
:false-names '("false")
:decimal-integer-scanner (cl-ppcre:create-scanner "^-?(0|[1-9][0-9]*)$")
:octal-integer-scanner +match-nothing+
:hex-integer-scanner +match-nothing+
:float-scanner (cl-ppcre:create-scanner "^-?(0|[1-9][0-9]*)(\\.[0-9]*)?([eE][-+][0-9]+)?$")
:nan-names nil
:positive-infinity-scanner +match-nothing+
:negative-infinity-scanner +match-nothing+))
;; TODO support base-60 and base-2 types
(defparameter +yaml-11-schema+
(make-schema
;; null-names same as 12
:true-names (let ((v '("y" "yes" "true" "on")))
(concatenate 'list
v
(map 'list 'string-upcase v)
(map 'list 'string-capitalize v)))
:false-names (let ((v '("n" "no" "false" "off")))
(concatenate 'list
v
(map 'list 'string-upcase v)
(map 'list 'string-capitalize v)))
:decimal-integer-scanner (cl-ppcre:create-scanner "^([-+])?(0|[1-9][0-9_]*)$")
:octal-integer-scanner (cl-ppcre:create-scanner "^([-+])?0([0-7_]+)$")
:hex-integer-scanner (cl-ppcre:create-scanner "^([-+])?0x([0-9a-fA-F_]+)$")
:float-scanner (cl-ppcre:create-scanner "^([-+])?([0-9][0-9_]*)?(\\.[0-9_]*)([eE][-+][0-9]+)?$")
;;nan-names same as 12 core
;;positive-infinity same as 12 core
;;negative-infinity same as 12 core
))