This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html Set by lizmat on 8 June 2022. |
|||
00:14
MasterDuke79 left
00:43
MasterDuke joined
00:52
Heptite joined
01:24
MasterDuke left
02:14
tea3po joined
02:15
MasterDuke joined
02:16
Heptite left
02:17
teatwo left
04:00
razetime joined
04:15
razetime left
05:24
razetime joined
05:59
c3388 joined
07:15
razetime left
07:38
razetime joined
07:56
razetime left
07:57
Manifest0 joined
09:14
Heptite joined
09:25
Heptite left
11:36
Heptite joined
12:14
jaguart joined
12:44
ab5tract joined
13:01
c3388 left
13:24
jgaz joined
13:27
jaguart left
13:34
ab5tract left
14:13
tea3po left,
tea3po joined
15:25
ab5tract joined
15:43
ab5tract left
17:13
jgaz left
17:35
jgaz joined
18:16
tea3po left
18:18
teatime joined
19:05
teatwo joined
19:08
teatime left
20:56
rje joined
|
|||
rje | I started learning Raku around the first week of April. This week I wrote my first Grammar, but I am still not sure why it works the way it does. | 20:59 | |
The nice thing is, the Grammar and Actions total about 14 lines. Is there a place here where I can paste in code? | 21:01 | ||
Maybe there's a Raku channel on Discord. | 21:02 | ||
Rob Eaglestone 鷲 石 | Ah and here it is. | 21:04 | |
So here's what I did. Constructive criticism welcome. grammar GTXGrammar { rule TOP { \s* <context>+ } rule context { <key> '{' <pair>+ '}' } rule pair { <key> <value> } token key { <[\w-]>+ } token value { <-[\n]>+ } } class GTXActions { method TOP ($/) { make $<context>>>.made } method context ($/) { make $<key>.made => | |||
$<pair>>>.made.flat.hash } method pair ($/) { make $<key>.made => $<value>.made } method key ($/) { make ~$/ } method value ($/) { make ~$/ } } | |||
So this parses a file as a two-layer hash, where leaf values are read as strings. | 21:05 | ||
21:06
rje left
|
|||
For example cow { radius 15 center -5,16 } default { order virus wave } virus { preserve-by-allegiances ImDd kill-hexes 1805 1905 2105 2109 2309 2405 2406 2407 2409 2411 2412 2413 2424 2425 2506 2512 2515 2523 2615 2713 2715 2716 2717 2721 2807 2810 2812 2813 2820 2905 2906 2907 2908 2910 2913 2918 3005 3008 3011 3013 3015 3016 3110 3111 3112 3113 3213 3115 3116 } | 21:06 | ||
location { y -1 x -2 } | |||
p6steve | Grammar::Tracer is your friend | 22:20 | |
TOP | context | | key | | * MATCH "cow" | | pair | | | key | | | * MATCH "radius" | | | value | | | * MATCH "15" | | * MATCH "radius 15\n " | | pair | | | key | | | * MATCH "center" | | | value | | | * MATCH "-5,16" | | * MATCH "center -5,16\n" | | pair | | | key | | | * FAIL | | * FAIL | * MATCH "cow \{\n radius 15\n center -5,16\n}\n" | 22:21 | ||
afaict this is a very strong first cut ... and yes, raku Grammars are killer | 22:22 | ||
it seems a bit odd that <[\w-]> is not built in (this is a critique of raku) | 22:26 | ||
there appears to be a bit of loose whitespace after the match | 22:29 | ||
say $match.made[0]<cow><center>; #-5,16 | 23:00 | ||
my $match = GTXGrammar.parse($txt, actions => GTXActions.new); my %h = $match.made; say %h.keys; say %h<location>; | 23:05 | ||
(default cow location virus) {x => -2, y => -1} | 23:06 | ||
works for me ;-) | |||
23:11
habere-et-disper joined
23:43
habere-et-disper left
|