• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • 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-maybe-match-token

    Compatible with seq. Consume and return a token if it is of the given type, but if not, don't consume anything and return nil.

    Signature
    (vl-maybe-match-token type &key (tokstream 'tokstream)) 
      → 
    (mv errmsg? token new-tokstream)
    Arguments
    type — Kind of token to match.
        Guard (vl-tokentype-p type).
    Returns
    errmsg? — Type (equal errmsg? nil).
    token — Type (and (iff (vl-token-p token) (vl-is-token? type)) (iff token (vl-is-token? type))) .

    Definitions and Theorems

    Function: vl-maybe-match-token-fn

    (defun vl-maybe-match-token-fn (type tokstream)
      (declare (xargs :stobjs (tokstream)))
      (declare (xargs :guard (vl-tokentype-p type)))
      (let ((__function__ 'vl-maybe-match-token))
        (declare (ignorable __function__))
        (b* ((tokens (vl-tokstream->tokens))
             ((when (atom tokens))
              (mv nil nil tokstream))
             (token1 (car tokens))
             ((unless (eq type (vl-token->type token1)))
              (mv nil nil tokstream))
             (tokstream (vl-tokstream-pop)))
          (mv nil token1 tokstream))))

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

    (defthm return-type-of-vl-maybe-match-token.errmsg?
      (b* (((mv ?errmsg? ?token ?new-tokstream)
            (vl-maybe-match-token-fn type tokstream)))
        (equal errmsg? nil))
      :rule-classes :rewrite)

    Theorem: return-type-of-vl-maybe-match-token.token

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

    Theorem: vl-maybe-match-token-fails-gracefully

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

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

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

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

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