• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defmacro
        • Loop$-primer
        • Fast-alists
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
        • Set-register-invariant-risk
        • Strings
          • Std/strings
            • Pretty-printing
            • Printtree
            • Base64
            • Charset-p
              • Defcharset
              • Count-leading-charset
              • Str-count-leading-charset-fast
              • Str-count-leading-charset
              • Chars-in-charset-p
              • Code-in-charset-p
              • Char-in-charset-p
            • Strtok!
            • Cases
            • Concatenation
            • Html-encoding
            • Character-kinds
            • Substrings
            • Strtok
            • Equivalences
            • Url-encoding
            • Lines
            • Explode-implode-equalities
            • Ordering
            • Numbers
            • Pad-trim
            • Coercion
            • Std/strings/digit-to-char
            • Substitution
            • Symbols
          • String-listp
          • Stringp
          • Length
          • Search
          • Remove-duplicates
          • Position
          • Coerce
          • Concatenate
          • Reverse
          • String
          • Subseq
          • Substitute
          • String-upcase
          • String-downcase
          • Count
          • Char
          • String<
          • String-equal
          • String-utilities
          • String-append
          • String>=
          • String<=
          • String>
          • Hex-digit-char-theorems
          • String-downcase-gen
          • String-upcase-gen
        • Program-wrapper
        • Get-internal-time
        • Basics
        • Packages
        • Oracle-eval
        • Defmacro-untouchable
        • <<
        • Primitive
        • Revert-world
        • Unmemoize
        • Set-duplicate-keys-action
        • Symbols
        • Def-list-constructor
        • Easy-simplify-term
        • Defiteration
        • Fake-oracle-eval
        • Defopen
        • Sleep
      • Operational-semantics
      • Real
      • Start-here
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
      • Interfacing-tools
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
    • Testing-utilities
  • Std/strings

Charset-p

A way to represent a fixed set of characters.

Signature
(charset-p x) → bool
Returns
bool — Type (booleanp bool).

When writing a lexer, it is often useful to introduce character sets that recognize sets of characters such as whitespace, alphabetic characters, digits, and so forth.

A charset-p represents such a set of characters as a natural number. In this representation, the character whose code is i is a member of the set x exactly when the ith bit of x is 1. This may as well be thought of as a bit-array lookup.

To introduce new sets of characters, e.g., to recognize "whitespace characters," or "hex digits," or whatever, we use the defcharset macro.

We generally treat character sets as opaque. It would be quite odd to, e.g., allow the theorem prover to expand a character set's definition into its bit-mask form, or to reason about functions like logbitp in conjunction with character sets. If you find yourself doing this, something is probably wrong.

Definitions and Theorems

Function: charset-p

(defun charset-p (x)
  (declare (xargs :guard t))
  (let ((acl2::__function__ 'charset-p))
    (declare (ignorable acl2::__function__))
    (natp x)))

Theorem: booleanp-of-charset-p

(defthm booleanp-of-charset-p
  (b* ((bool (charset-p x)))
    (booleanp bool))
  :rule-classes :type-prescription)

Subtopics

Defcharset
Define a recognizer for a particular set of characters.
Count-leading-charset
Count how many characters at the start of a list are members of a particular character set.
Str-count-leading-charset-fast
Fixnum optimized version of str-count-leading-charset.
Str-count-leading-charset
String version of count-leading-charset.
Chars-in-charset-p
(chars-in-charset-p x set) recognizes lists of characters x where every character is a member of the charset-p set.
Code-in-charset-p
(code-in-charset-p code set) determines if the character whose code is code is a member of the character set set.
Char-in-charset-p
(char-in-charset-p char set) determines if the character char is a member of the character set set.