Quick actions

cmd+k|ctrl+k

Navigation

Languages

Untitled

Snippet info

Language

Raku

Visibility

unlisted

Author

raiph

Created

2025-04-10T23:26:02.362542Z

Updated

2025-04-19T05:21:43.65198Z

grammar example {                 #= `grammar` is Raku's construct for writing parsers

    token str-open   { \" }       # A practical parser might support other delims
    token str-close  { \" }       # including paired (balanced) quotes like “ and ” 

    token code-open  { \{ }       # Assume interpolations are written like { ... }
    token code-close { \} }

    token string { <.str-open>  <str-content>  <.str-close>  }
    rule interp  { <.code-open> <code-content> <.code-close> } # `rule` automatically
                                                               # handles whitespace
    token str-content  { [ <interp> | <!str-close>  . ]* }
    rule  code-content { [ <string> | <!code-close> . ]* }
}

say example .parse: rule => 'string',
    '"outer string { "interpolated string  { "nested interpolated string" } " } "'
INFO