title: Capturing what's inside a nested structure in a regex or grammar token
body: <p>I'd like to capture the interior of a <a href="https://docs.raku.org/language/regexes#Tilde_for_nesting_structures" rel="noreferrer">nested structure</a>.</p>
  <pre><code>my $str = &quot;(a)&quot;;
  say $str ~~ /&quot;(&quot; ~ &quot;)&quot; (\w) /;
  say $str ~~ /&quot;(&quot; ~ &quot;)&quot; &lt;(\w)&gt; /;
  say $str ~~ /&quot;(&quot; &lt;(~)&gt; &quot;)&quot; \w /;
  say $str ~~ /&quot;(&quot; &lt;(~ &quot;)&quot; \w /;
  </code></pre>
  <p>The first one works; the last one works but also captures the closing parenthesis. The other two fail, so it's not possible to use capture markers in this case. But the problem is more complicated in the context of a grammar, since capturing groups do not seem to work either, like here:</p>
  <pre><code># Please paste this together with the code above so that it compiles.
  grammar G {
      token TOP {
                '(' ~ ')' $&lt;content&gt; = .+?
      }
  }
  
  grammar H {
      token TOP {
                '(' ~ ')' (.+?)
      }
  }
  
  grammar I {
      token TOP {
                '(' ~ ')' &lt;( .+? )&gt;
      }
  }
  
  $str = &quot;(one of us)&quot;;
  for G,H,I -&gt; $grammar {
      say $grammar.parse( $str );
  }
  </code></pre>
  <p>Since neither capturing grouping or <a href="https://docs.raku.org/language/regexes#Capture_markers:_%3C(_)%3E" rel="noreferrer">capture markers</a> seem to work, except if it's assigned, on the fly, to a variable. This, however, creates an additional token I'd really like to avoid.
  So there are two questions</p>
  <ul>
  <li>What is the right way to make capture markers work in nested structures?</li>
  <li>Is there a way to use either capturing groups or capturing markers in tokens to get the interior of a nested structure?</li>
  </ul>