Determining ChoiceOf choice

I have something like the following:

ChoiceOf
{
      Regex( /X\ X....../ )
      Regex( /X\ X....../ )
}

Is there some way, beyond the matched substring, of determining which choice was made? I was trying something like:

ChoiceOf
{
         TryCapture{ /XX\ ....../ } transform: { _ in 1}
         TryCapture{ /X\ X....../ } transform: { _ in 2}
}

Which almost worked, but I don't want to create a new tuple element for each match, I'd like to have the expression return (Substring, Int) where the second element of the tuple is the integer.
Thanks.

1 Like

I guess a better question would be: "Is there any way to embed a semantic action (executable Swift code) within a DSL pattern?"

For example:

let r =
   Regex
   {
      "Some String"
      SemanticAction
      {
           print( "Matched 'Some String'" )
      }
      "Some additional text"
   }

Yes, I'm aware that the semantic action would get executed multiple times during backtracking (I have lots of experience with this using Flex and Bison).
Sometimes, however, it's helpful to be able to inject a semantic action into a pattern.