Function: icalendar-ast-node-valid-value-p
icalendar-ast-node-valid-value-p is a byte-compiled function defined
in icalendar-ast.el.gz.
Signature
(icalendar-ast-node-valid-value-p NODE)
Documentation
Validate that NODE's value satisfies the requirements of its type.
Signals an icalendar-validation-error if NODE's value is
invalid, or returns NODE.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/icalendar-ast.el.gz
(defun ical:ast-node-valid-value-p (node)
"Validate that NODE's value satisfies the requirements of its type.
Signals an `icalendar-validation-error' if NODE's value is
invalid, or returns NODE."
(require 'icalendar-parser) ; for ical:printable-value-type-symbol-p
(declare-function ical:printable-value-type-symbol-p "icalendar-parser")
(let* ((type (ical:ast-node-type node))
(value (ical:ast-node-value node))
(valtype-param (when (ical:property-type-symbol-p type)
(ical:with-param-of node 'ical:valuetypeparam)))
(allowed-types
(cond ((ical:printable-value-type-symbol-p valtype-param)
;; with an explicit `VALUE=sometype' param, this is the
;; only allowed type:
(list valtype-param))
((and (ical:param-type-symbol-p type)
(get type 'ical:value-type))
(list (get type 'ical:value-type)))
((ical:property-type-symbol-p type)
(cons (get type 'ical:default-type)
(get type 'ical:other-types)))
(t nil))))
(cond ((ical:value-type-symbol-p type)
(unless (cl-typep value type) ; see `ical:define-type'
(ical:signal-validation-error
(format "Invalid value for `%s' node: %s" type value)
:node node))
node)
((ical:component-node-p node)
;; component types have no value, so no need to check anything
node)
((and (or (ical:param-type-symbol-p type)
(ical:property-type-symbol-p type))
(null (get type 'ical:value-type))
(stringp value))
;; property and param nodes with no value type are assumed to contain
;; strings which match a value regex:
(unless (string-match (rx-to-string (get type 'ical:value-rx)) value)
(ical:signal-validation-error
(format "Invalid string value for `%s' node: %s" type value)
:node node))
node)
;; otherwise this is a param or property node which itself
;; should have one or more syntax nodes as a value, so
;; recurse on value(s):
((ical:expects-list-of-values-p type)
(unless (listp value)
(ical:signal-validation-error
(format "Expected list of values for `%s' node" type)
:node node))
(when allowed-types
(dolist (v value)
(unless (memq (ical:ast-node-type v) allowed-types)
(ical:signal-validation-error
(format "Value of unexpected type `%s' in `%s' node"
(ical:ast-node-type v) type)
:node node))))
(mapc #'ical:ast-node-valid-value-p value)
node)
(t
(unless (ical:ast-node-p value)
(ical:signal-validation-error
(format "Invalid value for `%s' node: %s" type value)
:node node))
(when allowed-types
(unless (memq (ical:ast-node-type value) allowed-types)
(ical:signal-validation-error
(format "Value of unexpected type `%s' in `%s' node"
(ical:ast-node-type value) type)
:node node)))
(ical:ast-node-valid-value-p value)))))