• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
      • Gl
      • Esim
      • Vl2014
        • Warnings
        • Primitives
        • Use-set
        • Syntax
        • Getting-started
        • Utilities
        • Loader
          • Preprocessor
          • Vl-loadconfig
          • Lexer
          • Vl-loadstate
          • Parser
            • Parse-expressions
            • Parse-udps
            • Vl-genelements
            • Parse-paramdecls
            • Parse-blockitems
            • Parse-utils
              • Defparser
              • Vl-endinfo-p
              • Vl-match-token
              • Vl-match-some-token
                • Vl-match-any-except
                • Vl-type-of-matched-token
                • Vl-maybe-match-token
                • Vl-tokstream-backup-p
                • Vl-parse-error
                • Vl-match
                • Vl-parse-warning
                • Vl-match-any
                • Vl-current-loc
                • Vl-parse-endblock-name
                • Vl-tokenlist-fix
                • Vl-lookahead-is-some-token?
                • Vl-is-some-token?
                • Vl-is-token?
                • Vl-tokstream-save
                • Vl-tokstream-restore
                • Vl-tokstream-fix
                • Vl-lookahead-is-token?
                • Vl-tokstream->tokens
                • Vl-tokstream-add-warning
                • Vl-tokstream->pstate
                • Expand-defparsers
                • *vl-default-token*
              • Parse-insts
              • Parse-datatype
              • Parse-functions
              • Parse-datatypes
              • Parse-strengths
              • Vl-parse-genvar-declaration
              • Vl-parse
              • Parse-ports
              • Seq
              • Parse-packages
            • Vl-load-merge-descriptions
            • Scope-of-defines
            • Vl-load-file
            • Vl-flush-out-descriptions
            • Vl-description
            • Vl-loadresult
            • Vl-read-file
            • Vl-find-basename/extension
            • Vl-find-file
            • Vl-read-files
            • Extended-characters
            • Vl-load
            • Vl-load-main
            • Vl-load-description
            • Vl-descriptions-left-to-load
            • Inject-warnings
            • Vl-load-descriptions
            • Vl-load-files
            • Vl-load-summary
            • Vl-collect-modules-from-descriptions
            • Vl-descriptionlist
          • Transforms
          • Lint
          • Mlib
          • Server
          • Kit
          • Printer
          • Esim-vl
          • Well-formedness
        • Sv
        • Fgl
        • Vwsim
        • Vl
        • X86isa
        • Svl
        • Rtl
      • Software-verification
      • Math
      • Testing-utilities
    • Parse-utils

    Vl-match-some-token

    Compatible with seq. Consume and return a token if it has one of several types. Cause an error if the first token isn't one of the acceptable types.

    Signature
    (vl-match-some-token types &key (function '__function__) 
                         (tokstream 'tokstream)) 
     
      → 
    (mv errmsg? token new-tokstream)
    Arguments
    types — Guard (true-listp types).
    function — Guard (symbolp function).
    Returns
    errmsg? — Type (and (iff errmsg? (not (vl-is-some-token? types))) (iff (vl-warning-p errmsg?) errmsg?)) .
    token — Type (vl-token-p token), given (vl-is-some-token? types).

    Definitions and Theorems

    Function: vl-match-some-token-fn

    (defun vl-match-some-token-fn (types function tokstream)
     (declare (xargs :stobjs (tokstream)))
     (declare (xargs :guard (and (true-listp types)
                                 (symbolp function))))
     (let ((__function__ 'vl-match-some-token))
      (declare (ignorable __function__))
      (b*
       ((tokens (vl-tokstream->tokens))
        ((when (atom tokens))
         (vl-parse-error "Unexpected EOF."
                         :function function))
        (token1 (car tokens))
        ((unless (member-eq (vl-token->type token1)
                            types))
         (mv
          (make-vl-warning
               :type :vl-parse-error
               :msg
               "Parse error at ~a0: expected one of ~x1, but found ~s2."
               :args (list (vl-token->loc token1)
                           types (vl-token->type token1))
               :fatalp t
               :fn function)
          nil tokstream))
        (tokstream (vl-tokstream-update-tokens (cdr tokens))))
       (mv nil token1 tokstream))))

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

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

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

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

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

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

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

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

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

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