Skip to content

Commit

Permalink
Expose public API for custom schemas.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmccombs committed Jun 17, 2015
1 parent 9febbe9 commit 41074ad
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
11 changes: 10 additions & 1 deletion package.lisp
Expand Up @@ -11,4 +11,13 @@
(:export #:yaclyaml-parse #:yy-parse
#:ncompose-representation-graph #:construct #:yaml-load #:hash->assoc #:yaml-simple-load
#:yaml-load-file #:define-yaml-config
#:nserialize #:represent-node))
#:nserialize #:represent-node
;; For custom schemas:
#:yaml-schema #:install-converters
#:yaml-schema-unspecific-mixin #:convert-non-specific-scalar
#:failsafe-schema #:json-schema #:core-schema
#:register-schema
;; Conversion of parsed data
#:install-scalar-converter #:install-sequence-converter #:install-mapping-converter
#:convert-scalar #:convert-sequence #:convert-mapping
#:convert-sequence-to-list #:convert-mapping-to-hashtable))
20 changes: 17 additions & 3 deletions schema.lisp
Expand Up @@ -112,7 +112,21 @@ installed by the schema."
"Hash table of available schemas. The keys are symbols and the
values are instances of YAML-SCHEMA.")

(defun register-schema (name class-name &rest init-args)
(declare (type symbol name class-name))
"Register a schema with a symbol. After registering, the symbol can be passed
as the SCHEMA argument to the parsing functions.
This function creates a new instance of CLASS-NAME with the arguments passed as
INIT-ARGS and registers it with the symbol NAME.
NAME: The symbol for the schema to be registered.
CLASS-NAME: The symbol for the name of the class of the schema to create and register.
INIT-ARGS: Additional arguments to pass to MAKE-INSTANCE."
(setf (gethash name schemas)
(apply #'make-instance class-name init-args)))

;;; Initially populate the schemas table.
(setf (gethash :failsafe schemas) (make-instance 'failsafe-schema))
(setf (gethash :json schemas) (make-instance 'json-schema))
(setf (gethash :core schemas) (make-instance 'core-schema))
(register-schema :failsafe 'failsafe-schema)
(register-schema :json 'json-schema)
(register-schema :core 'core-schema)

0 comments on commit 41074ad

Please sign in to comment.