Quick actions

cmd+k|ctrl+k

Navigation

Languages

Grammar calculator

Snippet info

Language

Raku

Visibility

public

Author

fernando-correa

Created

2022-01-04T21:05:14.679421Z

Updated

2025-11-12T17:07:02.701333Z

grammar G {
    rule TOP { <a=.num> <sig> <b=.num> }
    token num { \d+ }
    proto token sig {*}
    token sig:sym<+> {<sym>}
    token sig:sym<-> {<sym>}
    token sig:sym<*> {<sym>}
    token sig:sym</> {<sym>}
}

class A {
    method num($/) { make +$/ }
    method sig:sym<+>($/) { make &[+] }
    method sig:sym<->($/) { make &[-] }
    method sig:sym<*>($/) { make &[*] }
    method sig:sym</>($/) { make &[/] }
    method TOP($/) { make $<sig>.made.($<a>.made, $<b>.made) }
}

say G.parse("13 + 29", :actions(A)).made
INFO