• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • 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
        • C
          • Syntax-for-tools
            • Formalized-subset
            • Mapping-to-language-definition
            • Input-files
            • Compilation-database
            • Printer
              • Print-exprs/decls/stmts
              • Print-expr
              • Pristate
              • Print-dec/oct/hex-const
              • Priopt
              • Print-fundef
              • Print-filepath-transunit-map
              • Print-s-char
                • Print-c-char
                • Print-q-char
                • Print-h-char
                • Print-fileset
                • Print-typequal/attribspec-list-list
                • Print-file
                • Print-hex-core-fconst
                • Print-dec-core-fconst
                • Print-ident-list
                • Print-fsuffix
                • Print-oct-digit-achar
                • Print-label-declaration-list
                • Print-hex-frac-const
                • Print-hex-digit-achar
                • Print-dec-frac-const
                • Print-dec-digit-achar
                • Print-ext-declon-list
                • Print-asm-clobber-list
                • Print-stringlit-list
                • Print-inc/dec-op-list
                • Print-astring
                • Print-asm-name-spec
                • Print-univ-char-name
                • Print-struni-spec
                • Print-simple-escape
                • Print-label-declaration
                • Print-isuffix-option
                • Print-fsuffix-option
                • Print-eprefix-option
                • Print-cprefix-option
                • Print-char
                • Print-binop
                • Print-attrib-name
                • Print-type-qual
                • Print-s-char-list
                • Print-q-char-list
                • Print-indent
                • Print-ident
                • Print-h-char-list
                • Print-ext-declon
                • Print-c-char-list
                • Print-asm-qual-list
                • Print-stringlit
                • Print-stor-spec
                • Print-sign-option
                • Print-oct-escape
                • Print-header-name
                • Print-escape
                • Print-dexpo-option
                • Print-cconst
                • Print-asm-qual
                • Print-asm-clobber
                • Init-pristate
                • Dec-pristate-indent
                • Print-isuffix
                • Print-fun-spec
                • Print-fconst
                • Print-unop
                • Print-transunit
                • Print-new-line
                • Print-lsuffix
                • Print-inc/dec-op
                • Print-hex-quad
                • Print-eprefix
                • Print-dexprefix
                • Print-dexpo
                • Print-cprefix
                • Print-bexprefix
                • Print-bexpo
                • Print-usuffix
                • Print-iconst
                • Print-hprefix
                • Print-const
                • Print-comp-stmt
                • Print-hex-digit-achars
                • Print-sign
                • Print-oct-digit-achars
                • Print-dec-digit-achars
                • Print-chars
                • Inc-pristate-indent
                • Print-expr-list
                • Print-struct-declon-list
                • Print-stmt
                • Print-param-declor
                • Print-dirdeclor
                • Print-declon-inline
                • Default-priopt
                • Print-struct-declor
                • Print-initer
                • Print-struct-declon
                • Print-genassoc-list
                • Print-enum-spec
                • Print-absdeclor
                • Print-typequal/attribspec-list
                • Print-desiniter-list
                • Print-const-expr
                • Print-attrib
                • Print-tyname
                • Print-struct-declor-list
                • Print-spec/qual-list
                • Print-param-declon-list
                • Print-param-declon
                • Print-init-declor-list
                • Print-designor-list
                • Print-declon-list
                • Print-decl-spec-list
                • Print-attrib-spec-list
                • Print-asm-output-list
                • Print-asm-input-list
                • Print-typequal/attribspec
                • Print-statassert
                • Print-spec/qual
                • Print-member-designor
                • Print-init-declor
                • Print-enumer-list
                • Print-dirabsdeclor
                • Print-desiniter
                • Print-declon
                • Print-decl-spec
                • Print-block-item-list
                • Print-attrib-spec
                • Print-attrib-list
                • Print-asm-output
                • Print-align-spec
                • Print-type-spec
                • Print-label
                • Print-genassoc
                • Print-enumer
                • Print-designor
                • Print-declor
                • Print-block-item
                • Print-asm-stmt
                • Print-asm-input
              • Output-files
              • Abstract-syntax-operations
              • Implementation-environments
              • Abstract-syntax
              • Concrete-syntax
              • Disambiguation
              • Validation
              • Gcc-builtins
              • Preprocessing
              • Parsing
            • Atc
            • Transformation-tools
            • Language
            • Representation
            • Insertion-sort
            • Pack
          • Soft
          • Bv
          • Imp-language
          • Ethereum
          • Event-macros
          • Java
          • Riscv
          • Bitcoin
          • Zcash
          • Yul
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Axe
          • Lists-light
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Printer

    Print-s-char

    Print a character or escape sequence usable in string literals.

    Signature
    (print-s-char schar pstate) → new-pstate
    Arguments
    schar — Guard (s-char-p schar).
    pstate — Guard (pristatep pstate).
    Returns
    new-pstate — Type (pristatep new-pstate).

    The abstract syntax puts no limitation on the character (code), but here we check that it satisfies the requirements in the concrete syntax. It must be a character in the grammar, and in addition it must not be a double quote, a backslash, or a new-line character. The latter check encompasses not only line feed, but also carriage return: recall that both are allowed in our grammar, and that we allow three kinds of new-line characters (line feed alone, carriage return alone, or line feed followed by carriage return).

    Definitions and Theorems

    Function: print-s-char

    (defun print-s-char (schar pstate)
     (declare (xargs :guard (and (s-char-p schar)
                                 (pristatep pstate))))
     (let ((__function__ 'print-s-char))
      (declare (ignorable __function__))
      (s-char-case
       schar :char
       (b*
        (((unless (and (grammar-character-p schar.code)
                       (not (= schar.code (char-code #\")))
                       (not (= schar.code (char-code #\\)))
                       (not (= schar.code 10))
                       (not (= schar.code 13))))
          (raise
           "Misusage error: ~
                           the character code ~x0 is disallowed ~
                           in a string literal."
           schar.code)
          (pristate-fix pstate)))
        (print-char schar.code pstate))
       :escape (print-escape schar.escape pstate))))

    Theorem: pristatep-of-print-s-char

    (defthm pristatep-of-print-s-char
      (b* ((new-pstate (print-s-char schar pstate)))
        (pristatep new-pstate))
      :rule-classes :rewrite)

    Theorem: pristate->gcc-of-print-s-char

    (defthm pristate->gcc-of-print-s-char
      (b* ((?new-pstate (print-s-char schar pstate)))
        (equal (pristate->gcc new-pstate)
               (pristate->gcc pstate))))

    Theorem: print-s-char-of-s-char-fix-schar

    (defthm print-s-char-of-s-char-fix-schar
      (equal (print-s-char (s-char-fix schar) pstate)
             (print-s-char schar pstate)))

    Theorem: print-s-char-s-char-equiv-congruence-on-schar

    (defthm print-s-char-s-char-equiv-congruence-on-schar
      (implies (s-char-equiv schar schar-equiv)
               (equal (print-s-char schar pstate)
                      (print-s-char schar-equiv pstate)))
      :rule-classes :congruence)

    Theorem: print-s-char-of-pristate-fix-pstate

    (defthm print-s-char-of-pristate-fix-pstate
      (equal (print-s-char schar (pristate-fix pstate))
             (print-s-char schar pstate)))

    Theorem: print-s-char-pristate-equiv-congruence-on-pstate

    (defthm print-s-char-pristate-equiv-congruence-on-pstate
      (implies (pristate-equiv pstate pstate-equiv)
               (equal (print-s-char schar pstate)
                      (print-s-char schar pstate-equiv)))
      :rule-classes :congruence)