Tree-match-element-p
Semantics of elements.
- Signature
(tree-match-element-p tree element rules) → yes/no
- Arguments
- tree — Guard (treep tree).
- element — Guard (elementp element).
- rules — Guard (rulelistp rules).
- Returns
- yes/no — Type (booleanp yes/no).
A tree matches an element iff one of the following conditions holds:
- The element is a rule name,
and the tree is a leaf consisting of the rule name.
In this situation, the rule name is not expanded.
- The element is a rule name,
the tree is a non-leaf with that rule name,
the rules associate an alternation to the rule name,
and the branches of the tree match that alternation.
In this situation, the rule name is expanded.
- The element is a grouped alternation,
the tree is a non-leaf without rule name,
and the branches of the tree match the alternation.
- The element is an optional alternation,
the tree is a non-leaf without rule name,
and either the branches of the tree match the alternation
or the tree has no branches.
- The element is a numeric value notation
and the tree matches it.
- The element is a character value notation
and the tree matches it.
- The element is a prose value notation
and the tree matches it.
Function: tree-match-element-p
(defun tree-match-element-p (tree element rules)
(declare (xargs :guard (and (treep tree)
(elementp element)
(rulelistp rules))))
(element-case
element
:rulename
(tree-case
tree
:leafterm nil
:leafrule (equal tree.get element.get)
:nonleaf
(and (equal tree.rulename? element.get)
(let ((alternation (lookup-rulename element.get rules)))
(tree-list-list-match-alternation-p
tree.branches alternation rules))))
:group
(and
(tree-case tree :nonleaf)
(null (tree-nonleaf->rulename? tree))
(tree-list-list-match-alternation-p (tree-nonleaf->branches tree)
element.get rules))
:option (and (tree-case tree :nonleaf)
(null (tree-nonleaf->rulename? tree))
(or (tree-list-list-match-alternation-p
(tree-nonleaf->branches tree)
element.get rules)
(null (tree-nonleaf->branches tree))))
:char-val (tree-match-char-val-p tree element.get)
:num-val (tree-match-num-val-p tree element.get)
:prose-val (tree-match-prose-val-p tree element.get)))
Subtopics
- Nat-listp-of-tree->string-when-match-element-num/char-val