• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
      • Sv
      • Fgl
      • Vwsim
      • Vl
        • Syntax
        • Loader
          • Preprocessor
          • Vl-loadconfig
          • Vl-loadstate
          • Lexer
          • Parser
            • Parse-expressions
            • Parse-udps
            • Parse-statements
            • Parse-property
            • Vl-genelements
            • Parse-paramdecls
            • Parse-blockitems
            • Parse-utils
              • Defparser
              • Vl-endinfo-p
              • Vl-match-token
                • Vl-match-some-token
                • Vl-match-any-except
                • Vl-parse-error
                • Vl-match
                • Vl-type-of-matched-token
                • Vl-tokstream-backup-p
                • Vl-maybe-match-token
                • Vl-parse-warning
                • Vl-match-any
                • Vl-linestart-indent
                • Vl-current-loc
                • Vl-choose-parse-error
                • Vl-parse-endblock-name
                • Vl-tokenlist-fix
                • Vl-lookahead-is-some-token?
                • Vl-tokstream-fix
                • Vl-is-token?
                • Vl-is-some-token?
                • Vl-add-context-to-parser-warning
                • Vl-lookahead-is-token?
                • Vl-tokstream-save
                • Vl-tokstream->tokens
                • Vl-tokstream-restore
                • Vl-tokstream-add-warning
                • Vl-tokstream->pstate
                • Vl-tokstream->position
                • Expand-defparsers
                • Vl-tokstream-pop
                • *vl-default-token*
              • Parse-insts
              • Parse-functions
              • Parse-assignments
              • Parse-clocking
              • Parse-strengths
              • Vl-parse-genvar-declaration
              • Vl-parse
              • Parse-netdecls
              • Parse-asserts
              • Vl-maybe-parse-lifetime
              • Parse-dpi-import-export
              • Parse-ports
              • Parse-timeunits
              • Seq
              • Parse-packages
              • Parse-eventctrl
            • 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
    • Parse-utils

    Vl-match-token

    Compatible with seq. Consume and return a token of exactly some particular type, or cause an error if the desired kind of token is not at the start of the input stream.

    Signature
    (vl-match-token type &key (function '__function__) 
                    (tokstream 'tokstream)) 
     
      → 
    (mv errmsg? token new-tokstream)
    Arguments
    type — Kind of token to match.
        Guard (vl-tokentype-p type).
    function — Guard (symbolp function).
    Returns
    errmsg? — Type (and (iff errmsg? (not (vl-is-token? type))) (iff (vl-warning-p errmsg?) errmsg?)) .
    token — Type (vl-token-p token), given (vl-is-token? type).

    Definitions and Theorems

    Function: vl-match-token-fn

    (defun vl-match-token-fn (type function tokstream)
     (declare (xargs :stobjs (tokstream)))
     (declare (xargs :guard (and (vl-tokentype-p type)
                                 (symbolp function))))
     (let ((__function__ 'vl-match-token))
      (declare (ignorable __function__))
      (b*
       ((tokens (vl-tokstream->tokens))
        ((when (atom tokens))
         (vl-parse-error "Unexpected EOF."
                         :function function))
        (token1 (car tokens))
        ((unless (eq type (vl-token->type token1)))
         (mv (make-vl-warning
                  :type :vl-parse-error
                  :msg "Parse error at ~a0: expected ~s1 but found ~s2."
                  :args (list (vl-token->loc (car tokens))
                              type (vl-token->type token1))
                  :fatalp t
                  :fn function)
             nil tokstream))
        (tokstream (vl-tokstream-pop)))
       (mv nil token1 tokstream))))

    Theorem: return-type-of-vl-match-token.errmsg?

    (defthm return-type-of-vl-match-token.errmsg?
      (b* (((mv ?errmsg? ?token ?new-tokstream)
            (vl-match-token-fn type function tokstream)))
        (and (iff errmsg? (not (vl-is-token? type)))
             (iff (vl-warning-p errmsg?) errmsg?)))
      :rule-classes :rewrite)

    Theorem: vl-token-p-of-vl-match-token.token

    (defthm vl-token-p-of-vl-match-token.token
      (implies (vl-is-token? type)
               (b* (((mv ?errmsg? ?token ?new-tokstream)
                     (vl-match-token-fn type function tokstream)))
                 (vl-token-p token)))
      :rule-classes :rewrite)

    Theorem: vl-match-token-fails-gracefully

    (defthm vl-match-token-fails-gracefully
      (implies (not (vl-is-token? type))
               (equal (mv-nth 1 (vl-match-token type))
                      nil)))

    Theorem: vl-match-token-under-iff

    (defthm vl-match-token-under-iff
      (iff (mv-nth 1 (vl-match-token type))
           (vl-is-token? type)))

    Theorem: vl-token->type-of-vl-match-token

    (defthm vl-token->type-of-vl-match-token
      (implies (vl-is-token? type)
               (equal (vl-token->type (mv-nth 1 (vl-match-token type)))
                      type)))

    Theorem: vl-match-token-count-strong-on-value

    (defthm vl-match-token-count-strong-on-value
      (and (<= (vl-tokstream-measure
                    :tokstream (mv-nth 2 (vl-match-token type)))
               (vl-tokstream-measure))
           (implies (mv-nth 1 (vl-match-token type))
                    (< (vl-tokstream-measure
                            :tokstream (mv-nth 2 (vl-match-token type)))
                       (vl-tokstream-measure))))
      :rule-classes ((:rewrite) (:linear)))

    Theorem: equal-of-vl-match-token-count

    (defthm equal-of-vl-match-token-count
      (equal (equal (vl-tokstream-measure
                         :tokstream (mv-nth 2 (vl-match-token type)))
                    (vl-tokstream-measure))
             (if (mv-nth 0 (vl-match-token type))
                 t
               nil)))