• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
        • Bitcoin
        • Ethereum
        • Yul
          • Transformations
          • Language
            • Abstract-syntax
            • Dynamic-semantics
            • Concrete-syntax
              • Lexer
              • Parser
                • Parse-keyword
                • Parse-variable-declaration
                • Parse-symbol
                • Parse-literal
                  • Parse-identifier
                  • Hex-chars-and-uscores-to-hex-string-rest-element-list
                  • Parse-assignment-statement
                  • Parse-identifier-and-open-paren
                  • Parse-*-comma-identifier
                  • Parse-*-.-identifier
                  • Parse-continue-statement
                  • Parse-*-comma-path
                  • Parse-path
                  • Parse-leave-statement
                  • Parse-break-statement
                  • Cst2ast-hex-string
                  • Cst2ast-string-literal-content
                  • Cst2ast-escape-sequence
                  • Cst2ast-string-literal-contents
                  • Cst2ast-quoted-printable
                  • Parse-yul
                  • Cst2ast-string-literal
                  • Parse-yul-bytes
                  • Cst2ast-hex-number
                  • Cst2ast-uhhhh
                  • Cst2ast-literal-kind
                  • Cst2ast-decimal-number
                  • Cst2ast-xhh
                  • Cst2ast-single-char
                  • Cst2ast-boolean
                  • Parse-*-case-clause
                  • Looks-like-hex-string-fringe
                  • Cst2ast-hex-digit-char-list
                  • Parse-*-statement
                  • Parse-*-comma-expression
                  • Parse-switch-statement
                  • Parse-if-statement
                  • Parse-for-statement
                  • Parse-expression
                  • Parse-case-clause
                  • Parse-fundef
                  • Parse-function-call
                  • Parse-block
                  • *single-quote-tree-list*
                  • *double-quote-tree-list*
                  • *yul-keywords*
                  • *single-quoted-content-rulenames*
                  • *list-leafterm-x*
                  • *list-leafterm-u*
                  • *list-leafterm-92*
                  • *double-quoted-content-rulenames*
                  • *yul-symbols*
                • Grammar-old
                • Grammar
                • Tokenizer
              • Static-soundness
              • Static-semantics
              • Errors
            • Yul-json
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Parser

    Parse-literal

    Attempts to eat a literal and build a literal AST node.

    Signature
    (parse-literal tokens) 
      → 
    (mv ast-node tokens-after-literal-or-reserr)
    Arguments
    tokens — Guard (abnf::tree-listp tokens).
    Returns
    ast-node — Type (literal-optionp ast-node).
    tokens-after-literal-or-reserr — Type (abnf::tree-list-resultp tokens-after-literal-or-reserr).

    Returns two values: an optional literal AST node and either the list of remaining tokens or a reserr.

    If a valid literal token is found, the first value returned is a literal AST node of the appropriate kind. Different kinds have different substructure.

    If no literal is found, the first value returned is NIL and the second value is a reserr.

    Definitions and Theorems

    Function: parse-literal

    (defun parse-literal (tokens)
     (declare (xargs :guard (abnf::tree-listp tokens)))
     (let ((__function__ 'parse-literal))
      (declare (ignorable __function__))
      (b*
       (((when (endp tokens))
         (mv nil
             (reserrf
                  (cons "ran out of tokens when trying to parse literal"
                        tokens))))
        ((unless (abnf::tree-listp tokens))
         (mv nil (reserrf "guard of parse-literal")))
        (putative-literal-tree (first tokens))
        ((unless
          (and
            (abnf::tree-case putative-literal-tree :nonleaf)
            (equal (abnf::tree-nonleaf->rulename? putative-literal-tree)
                   (abnf::rulename "literal"))))
         (mv nil
             (reserrf (cons "token is not a literal" tokens))))
        (branches (abnf::tree-nonleaf->branches putative-literal-tree))
        ((unless (and (listp branches)
                      (equal (len branches) 1)
                      (listp (car branches))
                      (equal (len (car branches)) 1)
                      (abnf::treep (caar branches))
                      (abnf::tree-case (caar branches)
                                       :nonleaf)))
         (prog2$
          (er
           hard? 'top-level
           "literal token seems to have the wrong structure for a literal")
          (mv nil
              (reserrf (cons "program logic error 2" tokens)))))
        (parsed-literal-kind (cst2ast-literal-kind (caar branches)))
        ((when (null parsed-literal-kind))
         (mv nil
             (reserrf "problem with literal substructure"))))
       (mv parsed-literal-kind (rest tokens)))))

    Theorem: literal-optionp-of-parse-literal.ast-node

    (defthm literal-optionp-of-parse-literal.ast-node
      (b* (((mv ?ast-node
                ?tokens-after-literal-or-reserr)
            (parse-literal tokens)))
        (literal-optionp ast-node))
      :rule-classes :rewrite)

    Theorem: tree-list-resultp-of-parse-literal.tokens-after-literal-or-reserr

    (defthm
      tree-list-resultp-of-parse-literal.tokens-after-literal-or-reserr
      (b* (((mv ?ast-node
                ?tokens-after-literal-or-reserr)
            (parse-literal tokens)))
        (abnf::tree-list-resultp tokens-after-literal-or-reserr))
      :rule-classes :rewrite)

    Theorem: len-of-parse-literal-<

    (defthm len-of-parse-literal-<
      (b* (((mv ?ast-node
                ?tokens-after-literal-or-reserr)
            (parse-literal tokens)))
        (implies (not (reserrp tokens-after-literal-or-reserr))
                 (< (len tokens-after-literal-or-reserr)
                    (len tokens))))
      :rule-classes :linear)