Token fringe.
(token-fringe tree identifiers) → token-trees
Parsing organizes the sequence of tokens resulting from lexing into expressions, statements, etc. It would be thus natural to define the parsing of a Leo file via a parsing predicate that, analogously to grammar-lexp, relates a sequence of token CSTs to a file CST by saying that the sequence of token CSTs is at the fringe of the file CST.
However, the function abnf::tree->string returns a sequence of naturals, not a sequence of token CSTs. Thus, we need to define a function that returns the sequence of token CSTs at the fringe of a CST; this could be defined similarly to abnf::tree->string, but stopping the recursion when a token tree is encountered, instead of stopping the recursion when a leaf tree is encountered.
But this function cannot be defined exactly as described,
because token CSTs do not actually appear in file CSTs.
Instead, a file CST has subtrees of token CST,
such as identifier CSTs;
the reason should be clear looking at the syntactic grammar,
which never references
The following function, and its mutually recursive companions, formalizes the token fringe of a CST in the sense explained above:
Note that the special treatment, explained above, of leaf CSTs whose strings are identifiers (when the list of identifiers is not empty) does not affect the treatment of identifier CSTs, which are not leaf CSTs. For concrete motivations for this special treatment, see input-file-parsep and output-file-parsep.
Theorem:
(defthm return-type-of-token-fringe.token-trees (b* ((?token-trees (token-fringe tree identifiers))) (abnf::tree-listp token-trees)) :rule-classes :rewrite)
Theorem:
(defthm return-type-of-token-fringe-list.token-trees (b* ((?token-trees (token-fringe-list trees identifiers))) (abnf::tree-listp token-trees)) :rule-classes :rewrite)
Theorem:
(defthm return-type-of-token-fringe-list-list.token-trees (b* ((?token-trees (token-fringe-list-list treess identifiers))) (abnf::tree-listp token-trees)) :rule-classes :rewrite)
Theorem:
(defthm token-fringe-of-tree-fix-tree (equal (token-fringe (abnf::tree-fix tree) identifiers) (token-fringe tree identifiers)))
Theorem:
(defthm token-fringe-of-string-list-fix-identifiers (equal (token-fringe tree (str::string-list-fix identifiers)) (token-fringe tree identifiers)))
Theorem:
(defthm token-fringe-list-of-tree-list-fix-trees (equal (token-fringe-list (abnf::tree-list-fix trees) identifiers) (token-fringe-list trees identifiers)))
Theorem:
(defthm token-fringe-list-of-string-list-fix-identifiers (equal (token-fringe-list trees (str::string-list-fix identifiers)) (token-fringe-list trees identifiers)))
Theorem:
(defthm token-fringe-list-list-of-tree-list-list-fix-treess (equal (token-fringe-list-list (abnf::tree-list-list-fix treess) identifiers) (token-fringe-list-list treess identifiers)))
Theorem:
(defthm token-fringe-list-list-of-string-list-fix-identifiers (equal (token-fringe-list-list treess (str::string-list-fix identifiers)) (token-fringe-list-list treess identifiers)))
Theorem:
(defthm token-fringe-tree-equiv-congruence-on-tree (implies (abnf::tree-equiv tree tree-equiv) (equal (token-fringe tree identifiers) (token-fringe tree-equiv identifiers))) :rule-classes :congruence)
Theorem:
(defthm token-fringe-string-list-equiv-congruence-on-identifiers (implies (str::string-list-equiv identifiers identifiers-equiv) (equal (token-fringe tree identifiers) (token-fringe tree identifiers-equiv))) :rule-classes :congruence)
Theorem:
(defthm token-fringe-list-tree-list-equiv-congruence-on-trees (implies (abnf::tree-list-equiv trees trees-equiv) (equal (token-fringe-list trees identifiers) (token-fringe-list trees-equiv identifiers))) :rule-classes :congruence)
Theorem:
(defthm token-fringe-list-string-list-equiv-congruence-on-identifiers (implies (str::string-list-equiv identifiers identifiers-equiv) (equal (token-fringe-list trees identifiers) (token-fringe-list trees identifiers-equiv))) :rule-classes :congruence)
Theorem:
(defthm token-fringe-list-list-tree-list-list-equiv-congruence-on-treess (implies (abnf::tree-list-list-equiv treess treess-equiv) (equal (token-fringe-list-list treess identifiers) (token-fringe-list-list treess-equiv identifiers))) :rule-classes :congruence)
Theorem:
(defthm token-fringe-list-list-string-list-equiv-congruence-on-identifiers (implies (str::string-list-equiv identifiers identifiers-equiv) (equal (token-fringe-list-list treess identifiers) (token-fringe-list-list treess identifiers-equiv))) :rule-classes :congruence)