• 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
          • Syntax-for-tools
            • Disambiguator
            • Abstract-syntax
            • Parser
            • Validator
              • Valid-exprs/decls/stmts
              • Valid-stmt
              • Valid-expr
              • Valid-dirdeclor
              • Valid-type-spec
              • Valid-transunit
              • Valid-stor-spec-list
              • Valid-binary
              • Valid-unary
              • Valid-initdeclor
              • Valid-fundef
              • Valid-type-spec-list-residual
              • Valid-cond
              • Valid-lookup-ord
              • Valid-transunit-ensemble
              • Valid-declor
              • Valid-iconst
              • Valid-initer
              • Valid-c-char
              • Valid-stringlit-list
              • Valid-funcall
              • Valid-add-ord
              • Valid-arrsub
              • Valid-univ-char-name
              • Valid-extdecl
              • Valid-extdecl-list
              • Valid-cast
              • Valid-add-ord-file-scope
              • Valid-spec/qual
              • Valid-sizeof/alignof
              • Valid-memberp
              • Valid-decl-spec
              • Valid-var
              • Valid-param-declon
              • Valid-oct-escape
              • Valid-structdeclor
              • Valid-structdecl
              • Valid-designor
              • Valid-escape
                • Valid-enum-const
                • Valid-cconst
                • Valid-s-char
                • Valid-dec/oct/hex-const
                • Valid-const
                • Valid-gensel
                • Valid-decl-spec-list
                • Valid-lookup-ord-file-scope
                • Valid-member
                • Valid-param-declor
                • Valid-spec/qual-list
                • Valid-fconst
                • Valid-stringlit
                • Valid-s-char-list
                • Valid-c-char-list
                • Valid-block-item
                • Valid-structdeclor-list
                • Valid-simple-escape
                • Valid-align-spec
                • Valid-enumer
                • Valid-dirabsdeclor
                • Valid-decl
                • Valid-pop-scope
                • Valid-enumspec
                • Valid-declor-option
                • Valid-push-scope
                • Valid-initer-option
                • Valid-block-item-list
                • Valid-absdeclor
                • Valid-label
                • Valid-genassoc
                • Valid-tyname
                • Valid-strunispec
                • Valid-structdecl-list
                • Valid-genassoc-list
                • Valid-dirabsdeclor-option
                • Valid-designor-list
                • Valid-const-expr
                • Valid-initdeclor-list
                • Valid-desiniter-list
                • Valid-absdeclor-option
                • Valid-table-num-scopes
                • Valid-expr-list
                • Valid-param-declon-list
                • Valid-desiniter
                • Valid-const-expr-option
                • Valid-expr-option
                • Valid-statassert
                • Valid-enumer-list
                • Valid-init-table
                • Valid-empty-scope
                • Valid-member-designor
                • Valid-decl-list
              • Printer
              • Formalized-subset
              • Mapping-to-language-definition
              • Input-files
              • Defpred
              • Output-files
              • Abstract-syntax-operations
              • Validation-information
              • Implementation-environments
              • Concrete-syntax
              • Unambiguity
              • Ascii-identifiers
              • Preprocessing
              • Abstraction-mapping
            • Atc
            • Language
            • Representation
            • Transformation-tools
            • Insertion-sort
            • Pack
          • Bv
          • Imp-language
          • Event-macros
          • Java
          • Bitcoin
          • Ethereum
          • Yul
          • 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
    • Validator

    Valid-escape

    Validate an escape sequence.

    Signature
    (valid-escape esc max) → (mv erp code)
    Arguments
    esc — Guard (escapep esc).
    max — Guard (natp max).
    Returns
    code — Type (natp code).

    If the escape sequence is valid, we return its character code. For simple and octal escapes, and for universal character names, we use separate validation functions. For a hexadecimal escape, we calculate the numeric value, and we subject them to same restrictions as octal escapes [C17:6.4.4.4/9] [C17:6.4.5/4].

    Although [C17] does not seem to state that explicitly, it seems reasonable that the same restriction applies to universal character names; we will revise this if that turns out to be not the case.

    Definitions and Theorems

    Function: valid-escape

    (defun valid-escape (esc max)
     (declare (xargs :guard (and (escapep esc) (natp max))))
     (let ((__function__ 'valid-escape))
      (declare (ignorable __function__))
      (b* (((reterr) 0))
       (escape-case
        esc :simple
        (retok (valid-simple-escape esc.unwrap))
        :oct (valid-oct-escape esc.unwrap max)
        :hex
        (b* ((code (str::hex-digit-chars-value esc.unwrap)))
         (if (<= code (nfix max))
             (retok code)
          (reterr
           (msg
            "The hexadecimal escape sequence ~x0 ~
                                has value ~x1, which exceeds ~
                                the maximum allowed ~x2, ~
                                required in the context where ~
                                this hexadecimal escape occurs."
            (escape-fix esc)
            code (nfix max)))))
        :univ (valid-univ-char-name esc.unwrap max)))))

    Theorem: natp-of-valid-escape.code

    (defthm natp-of-valid-escape.code
      (b* (((mv acl2::?erp ?code)
            (valid-escape esc max)))
        (natp code))
      :rule-classes :rewrite)

    Theorem: valid-escape-of-escape-fix-esc

    (defthm valid-escape-of-escape-fix-esc
      (equal (valid-escape (escape-fix esc) max)
             (valid-escape esc max)))

    Theorem: valid-escape-escape-equiv-congruence-on-esc

    (defthm valid-escape-escape-equiv-congruence-on-esc
      (implies (escape-equiv esc esc-equiv)
               (equal (valid-escape esc max)
                      (valid-escape esc-equiv max)))
      :rule-classes :congruence)

    Theorem: valid-escape-of-nfix-max

    (defthm valid-escape-of-nfix-max
      (equal (valid-escape esc (nfix max))
             (valid-escape esc max)))

    Theorem: valid-escape-nat-equiv-congruence-on-max

    (defthm valid-escape-nat-equiv-congruence-on-max
      (implies (acl2::nat-equiv max max-equiv)
               (equal (valid-escape esc max)
                      (valid-escape esc max-equiv)))
      :rule-classes :congruence)