• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
      • Sv
      • Fgl
      • Vwsim
      • Vl
        • Syntax
        • Loader
          • Preprocessor
          • Vl-loadconfig
          • Vl-loadstate
          • Lexer
            • Lex-strings
              • Vl-read-string-aux
              • Vl-read-octal-string-escape
              • Vl-read-string-escape-sequence
                • Vl-string-self-escape-p
                • Vl-read-string-escape-sequence-prefix/remainder-thms
                • Vl-string-self-escape-list-p
              • Vl-read-hex-string-escape
              • Vl-read-string
              • Vl-lex-string
            • Lex-identifiers
            • Vl-typo-uppercase-p
            • Vl-typo-number-p
            • Vl-typo-lowercase-p
            • Lex-numbers
            • Chartypes
            • Vl-lex
            • Defchar
            • Tokens
            • Lex-keywords
            • Lexstate
            • Make-test-tokens
            • Lexer-utils
            • Lex-comments
            • Vl-typo-uppercase-list-p
            • Vl-typo-lowercase-list-p
            • Vl-typo-number-list-p
          • Parser
          • Vl-load-merge-descriptions
          • Vl-find-basename/extension
          • Vl-load-file
          • Vl-loadresult
          • Scope-of-defines
          • Vl-find-file
          • Vl-flush-out-descriptions
          • Vl-description
          • Vl-read-file
          • Vl-includeskips-report-gather
          • Vl-load-main
          • Extended-characters
          • Vl-load
          • Vl-load-description
          • Vl-descriptions-left-to-load
          • Inject-warnings
          • Vl-preprocess-debug
          • Vl-write-preprocessor-debug-file
          • Vl-read-file-report-gather
          • Vl-load-descriptions
          • Vl-load-files
          • Translate-off
          • Vl-load-read-file-hook
          • Vl-read-file-report
          • Vl-loadstate-pad
          • Vl-load-summary
          • Vl-collect-modules-from-descriptions
          • Vl-loadstate->warnings
          • Vl-iskips-report
          • Vl-descriptionlist
        • Warnings
        • Getting-started
        • Utilities
        • Printer
        • Kit
        • Mlib
        • Transforms
      • X86isa
      • Svl
      • Rtl
    • Software-verification
    • Math
    • Testing-utilities
  • Lex-strings

Vl-read-string-escape-sequence

Try to read a string escape sequence.

Signature
(vl-read-string-escape-sequence echars st) 
  → 
(mv char/nil prefix remainder)
Arguments
echars — Characters we're lexing, starting with the leading backslash.
    Guard (and (vl-echarlist-p echars) (consp echars) (equal (vl-echar->char (car echars)) #\\)) .
st — Governs which escape sequences are allowed.
    Guard (vl-lexstate-p st).
Returns
char/nil — The interpretation of this escape sequence if any. This will be nil for line continuations, and also in case of any error.
    Type (equal (characterp char/nil) (if char/nil t nil)).
prefix — The matched characters on success. You have to check the prefix rather than char/nil to determine success, because line continuations don't result in any character.

Definitions and Theorems

Function: vl-read-string-escape-sequence

(defun vl-read-string-escape-sequence (echars st)
 (declare
      (xargs :guard (and (and (vl-echarlist-p echars)
                              (consp echars)
                              (equal (vl-echar->char (car echars))
                                     #\\))
                         (vl-lexstate-p st))))
 (let ((__function__ 'vl-read-string-escape-sequence))
  (declare (ignorable __function__))
  (b* (((unless (consp (cdr echars)))
        (mv nil nil echars))
       (echar1 (first echars))
       (echar2 (second echars))
       (char2 (vl-echar->char echar2))
       ((when (eql char2 #\n))
        (mv #\Newline (list echar1 echar2)
            (cddr echars)))
       ((when (eql char2 #\t))
        (mv #\Tab (list echar1 echar2)
            (cddr echars)))
       ((when (eql char2 #\\))
        (mv #\\ (list echar1 echar2)
            (cddr echars)))
       ((when (eql char2 #\"))
        (mv #\" (list echar1 echar2)
            (cddr echars)))
       ((when (vl-echar-digit-value echar2 8))
        (vl-read-octal-string-escape echars))
       ((vl-lexstate st) st)
       ((unless st.strextsp)
        (mv nil nil echars))
       ((when (eql char2 #\Newline))
        (mv nil (list echar1 echar2)
            (cddr echars)))
       ((when (eql char2 #\v))
        (mv (vertical-tab-char)
            (list echar1 echar2)
            (cddr echars)))
       ((when (eql char2 #\f))
        (mv #\Page (list echar1 echar2)
            (cddr echars)))
       ((when (eql char2 #\a))
        (mv (code-char 7)
            (list echar1 echar2)
            (cddr echars)))
       ((when (eql char2 #\x))
        (vl-read-hex-string-escape echars))
       ((when (vl-string-self-escape-p char2))
        (mv char2 (list echar1 echar2)
            (cddr echars))))
   (mv
      (cw "Lexer error (~s0): invalid string escape sequence: ~s1~%"
          (vl-location-string (vl-echar->loc (car echars)))
          (vl-echarlist->string (list echar1 echar2)))
      nil echars))))

Theorem: return-type-of-vl-read-string-escape-sequence.char/nil

(defthm return-type-of-vl-read-string-escape-sequence.char/nil
  (b* (((mv ?char/nil ?prefix ?remainder)
        (vl-read-string-escape-sequence echars st)))
    (equal (characterp char/nil)
           (if char/nil t nil)))
  :rule-classes :rewrite)

Subtopics

Vl-string-self-escape-p
I'm not sure the standard really says this is OK, but it seems like these characters escape to themselves when preceded by a backslash on other tools.
Vl-read-string-escape-sequence-prefix/remainder-thms
Prefix and remainder theorems for vl-read-string-escape-sequence, automatically generated by def-prefix/remainder-thms.
Vl-string-self-escape-list-p
(vl-string-self-escape-list-p x) recognizes lists where every element satisfies vl-string-self-escape-p.