• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
        • Deftreeops
        • Defdefparse
          • Defdefparse-implementation
            • Defdefparse-event-generation
              • Defdefparse-gen-function-for-rulename
              • Defdefparse-gen-code-for-alternation
              • Defdefparse-gen-code-for-repetition
              • Defdefparse-gen-function-for-group
              • Defdefparse-function-spec
              • Defdefparse-gen-code-for-element
                • Defdefparse-gen-*-group-macro
                • Defdefparse-gen-function-for-option
                • Defdefparse-gen-option-macro
                • Defdefparse-gen-group-macro
                • Defdefparse-gen-function-for-repetition
                • Defdefparse-gen-code-for-concatenation
                • Defdefparse-gen-*-rulename-macro
                • Defdefparse-gen-rulename-macro
                • Defdefparse-gen-repetition-alist
                • Defdefparse-gen-option-alist
                • Defdefparse-gen-group-alist
                • Defdefparse-gen-everything
                • Defdefparse-gen-repetition-table-macro
                • Defdefparse-gen-option-table-macro
                • Defdefparse-gen-group-table-macro
                • Defdefparse-gen-function-for-spec
                • Defdefparse-gen-repetition-table
                • Defdefparse-gen-option-table
                • Defdefparse-gen-group-table
                • Defdefparse-reorder-alternation
                • Defdefparse-order-permutationp
                • Defdefparse-gen-repetition-table-name
                • Defdefparse-gen-option-table-name
                • Defdefparse-gen-group-table-name
                • Defdefparse-alt-symbol-alist
                • Defdefparse-rep-symbol-alist
              • Defdefparse-fn
              • Defdefparse-input-processing
              • Defdefparse-table
              • Defdefparse-macro-definition
          • Defgrammar
          • Tree-utilities
          • Notation
          • Grammar-parser
          • Meta-circular-validation
          • Parsing-primitives-defresult
          • Parsing-primitives-seq
          • Operations
          • Examples
          • Differences-with-paper
          • Constructor-utilities
          • Grammar-printer
          • Parsing-tools
        • Vwsim
        • Isar
        • Wp-gen
        • Dimacs-reader
        • Pfcs
        • Legacy-defrstobj
        • C
        • Proof-checker-array
        • Soft
        • Farray
        • Rp-rewriter
        • Instant-runoff-voting
        • Imp-language
        • Sidekick
        • Ethereum
        • Leftist-trees
        • Java
        • Riscv
        • Taspi
        • Bitcoin
        • Zcash
        • Des
        • X86isa
        • Sha-2
        • Yul
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Axe
        • Poseidon
        • Where-do-i-place-my-book
        • Aleo
        • Bigmems
        • Builtins
        • Execloader
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Community
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Defdefparse-event-generation

    Defdefparse-gen-code-for-element

    Generate code to parse an instance of an ABNF element.

    Signature
    (defdefparse-gen-code-for-element elem check-error-p 
                                      prefix group-table option-table) 
     
      → 
    code
    Arguments
    elem — Guard (elementp elem).
    check-error-p — Guard (booleanp check-error-p).
    prefix — Guard (common-lisp::symbolp prefix).
    group-table — Guard (defdefparse-alt-symbol-alistp group-table).
    option-table — Guard (defdefparse-alt-symbol-alistp option-table).
    Returns
    code — Type (true-listp code).

    Numeric and character value notations are parsed directly. Rule names are parsed by calling the corresponding functions, whose names is derived from the rule names. Groups and options are parsed by calling the corresponding functions, whose names are looked up in the alists.

    We generate a b* binder that binds the parsing results to variables tree (for a tree or error) and input (for the remaining input). If the check-error-p flag is set, we also generate a b* to propagate the error, if tree is an error.

    Definitions and Theorems

    Function: defdefparse-gen-code-for-element

    (defun defdefparse-gen-code-for-element
           (elem check-error-p
                 prefix group-table option-table)
     (declare
      (xargs :guard (and (elementp elem)
                         (booleanp check-error-p)
                         (common-lisp::symbolp prefix)
                         (defdefparse-alt-symbol-alistp group-table)
                         (defdefparse-alt-symbol-alistp option-table))))
     (let ((__function__ 'defdefparse-gen-code-for-element))
      (declare (ignorable __function__))
      (element-case
       elem :num-val
       (num-val-case
        elem.get
        :direct
        (cons
           (cons '(mv tree input)
                 (cons (cons 'parse-direct
                             (cons (cons 'list
                                         (num-val-direct->get elem.get))
                                   '(input)))
                       'nil))
           (and check-error-p
                '(((when (reserrp tree))
                   (mv (reserrf-push tree) input)))))
        :range
        (cons
             (cons '(mv tree input)
                   (cons (cons 'parse-range
                               (cons (num-val-range->min elem.get)
                                     (cons (num-val-range->max elem.get)
                                           '(input))))
                         'nil))
             (and check-error-p
                  '(((when (reserrp tree))
                     (mv (reserrf-push tree) input))))))
       :char-val
       (char-val-case
        elem.get
        :insensitive
        (cons
            (cons '(mv tree input)
                  (cons (cons 'parse-ichars
                              (cons (char-val-insensitive->get elem.get)
                                    '(input)))
                        'nil))
            (and check-error-p
                 '(((when (reserrp tree))
                    (mv (reserrf-push tree) input)))))
        :sensitive
        (cons (cons '(mv tree input)
                    (cons (cons 'parse-schars
                                (cons (char-val-sensitive->get elem.get)
                                      '(input)))
                          'nil))
              (and check-error-p
                   '(((when (reserrp tree))
                      (mv (reserrf-push tree) input))))))
       :rulename
       (b*
        ((parse-rulename-fn
              (packn-pos
                   (list prefix '-
                         (str::upcase-string (rulename->get elem.get)))
                   prefix)))
        (cons (cons '(mv tree input)
                    (cons (cons parse-rulename-fn '(input))
                          'nil))
              (and check-error-p
                   '(((when (reserrp tree))
                      (mv (reserrf-push tree) input))))))
       :group
       (b* ((parse-group-fn (cdr (assoc-equal elem.get group-table))))
         (cons (cons '(mv tree input)
                     (cons (cons parse-group-fn '(input))
                           'nil))
               (and check-error-p
                    '(((when (reserrp tree))
                       (mv (reserrf-push tree) input))))))
       :option
       (b* ((parse-option-fn (cdr (assoc-equal elem.get option-table))))
         (cons (cons '(mv tree input)
                     (cons (cons parse-option-fn '(input))
                           'nil))
               (and check-error-p
                    '(((when (reserrp tree))
                       (mv (reserrf-push tree) input))))))
       :prose-val (raise "Prose value ~x0 not supported."
                         elem.get))))

    Theorem: true-listp-of-defdefparse-gen-code-for-element

    (defthm true-listp-of-defdefparse-gen-code-for-element
      (b* ((code (defdefparse-gen-code-for-element
                      elem check-error-p
                      prefix group-table option-table)))
        (true-listp code))
      :rule-classes :rewrite)