[racket] syntax-parse and matching ordered optional keyworded expressions
I'm trying to improve the struct: form in TR, and one of the things I
need to do is match a sequence of keyworded expressions, add
annotations on the expressions, and then put them back into the same
order.
I can either do a large ~or clause and have optional constraints on
each clause, but If I do this then each kind of clause needs a
different name and then putting them back in the same order is
difficult. If I make a syntax class with each kind of clause then I
don't know how to enforce the at most one constraint.
Is there a way to do this with out duplicating the parsing work?
Method 1:
(~or
(~optional guard:guard-form)
(~optional mutable:mutable-form)
property:struct-property-form) ...
and
#'(guard.contracted mutable.contracted property.contracted ...))
Method 2:
(define-splicing-syntax-class any-form
(pattern :guard-form)
(pattern :mutable-form)
(pattern :struct-property-form))
(form:any-form ...)
and
#'(form.contracted ...)