• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • 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
        • Aleobft
        • Aleovm
        • Leo
          • Grammar
          • Early-version
            • Json2ast
            • Testing
            • Definition
              • Flattening
              • Abstract-syntax
              • Dynamic-semantics
              • Compilation
              • Static-semantics
              • Concrete-syntax
                • Pretty-printer
                • Grammar
                • Lexing-and-parsing
                  • Lexer
                  • Parser
                  • Token-fringe
                  • Longest-lexp
                  • Parser-interface
                  • Grammar-lexp
                  • Identifier-lexp
                  • Output-file-parsep
                  • Input-file-parsep
                  • File-lex-parse-p
                  • Filter-tokens
                  • Lexp
                  • File-parsep
                  • Input-parser
                  • Output-file-lex-parse-p
                  • Input-file-lex-parse-p
                  • Parser-abstractor-interface
                    • Ast-from-fragment
                      • Ast-from-string
                      • Ast-from-file-at-path
                    • Identifier-abnf-stringp
                    • Symbol-abnf-stringp
                    • Keyword-abnf-stringp
                    • Output-parser
                    • Tokenizer
                  • Input-pretty-printer
                  • Output-pretty-printer
                  • Unicode-characters
                  • Concrete-syntax-trees
                  • Symbols
                  • Keywords
        • 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
    • Parser-abstractor-interface

    Ast-from-fragment

    Parse and abstract to AST.

    Signature
    (ast-from-fragment rule-name source-code) → ast-result
    Arguments
    rule-name — Guard (stringp rule-name).
    source-code — Guard (stringp source-code).
    Returns
    ast-result — Type (or (file-resultp ast-result) (statement-resultp ast-result) (expression-resultp ast-result) (identifier-resultp ast-result) (literal-resultp ast-result)) .

    Supported grammar rule names are file, statement, expression, and token.

    If the given rule cannot be parsed or if there are tokens left over, or if the resulting CST cannot be abstracted to AST, then a reserr is returned.

    Since ACL2 strings are sequences of characters with codes from 0 to 255, source-code, when converted to codes, is required to be valid UTF-8.

    Definitions and Theorems

    Function: ast-from-fragment

    (defun ast-from-fragment (rule-name source-code)
     (declare (xargs :guard (and (stringp rule-name)
                                 (stringp source-code))))
     (let ((__function__ 'ast-from-fragment))
      (declare (ignorable __function__))
      (b* ((cst (parse-fragment-to-cst rule-name source-code))
           ((when (reserrp cst)) cst))
       (if (equal rule-name "file")
           (abs-file cst)
        (if (equal rule-name "statement")
            (abs-statement cst)
         (if (equal rule-name "expression")
             (abs-expression cst)
          (if
            (equal rule-name "token")
            (b* (((okf rulename?)
                  (abnf::check-tree-nonleaf? cst))
                 ((when (equal rulename? "identifier"))
                  (abs-identifier cst))
                 ((when (equal rulename? "atomic-literal"))
                  (abs-atomic-literal cst)))
              (reserrf (cons :not-yet-supported-token-type rulename?)))
           (reserrf
            (cons
               :not-yet-supported-top-level-rule-name rule-name)))))))))

    Theorem: return-type-of-ast-from-fragment

    (defthm return-type-of-ast-from-fragment
      (b* ((ast-result (ast-from-fragment rule-name source-code)))
        (or (file-resultp ast-result)
            (statement-resultp ast-result)
            (expression-resultp ast-result)
            (identifier-resultp ast-result)
            (literal-resultp ast-result)))
      :rule-classes :rewrite)