#'else used in match

<pkgs>/dsl/nested-word-list> (define (tokenize s)
                                (for/list ([str (regexp-match* #px"\\(|\\)|\\w+" s)])   
                                  (match str
                                             ["("
                                              (token 'LEFT-PAREN str)]
                                             [")"
                                              (token 'RIGHT-PAREN str)]
                                             [else
                                              (token 'WORD str)])))
string:8:16: else: not allowed as an expression
  in: (else (token (quote WORD) str))
 [,bt for context]

what happen?

  1. Are you sure that your DSL provides match? Does (match 1 [1 #t]) work? I believe you need (require racket/match) to make the code work.
  2. But even when the code does work, it's still not really correct. match doesn't support the else clause. What it's doing is to bind the value to the identifier else, which is certainly not what you want. You should use _ instead of else.

thanks very much ,I followed your answer and solved the problem
the document brag: a better Racket AST generator 1 Quick start write it this way

An identifier such as foo or else matches anything.
So in your example match isn't looking for else it just uses the normal rules for identifiers.
It is customary to use _ to mean "match anything and I don't care what was matched".