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:53
deoac joined
01:29
lizmat_ joined
01:33
lizmat left
02:42
deoac left
06:47
lizmat_ left,
lizmat joined
08:04
Manifest0 joined
08:13
dakkar joined
|
|||
rikashore | Is there an action for raku grammars that get called when all rules fail | 10:33 | |
like a fallback case I can use to handle the failure and move on? | |||
for context I'm building a lexer using raku grammars and I want to be able to produce "error" nodes while then continuing to lex further | 10:34 | ||
nemokosch | when all rules fail to match, not when there is no action defined, right? | 10:35 | |
rikashore | yeah | 10:37 | |
nemokosch | Not that I know of | 10:39 | |
the grammar of Raku itself definitely uses no such thing, it just mixes in statefulness or outright calls error handlers | 10:40 | ||
rikashore | I see | 10:41 | |
I'll probably have to rewrite the lexer then into something more manual | |||
or maybe do some DFA construction and use that, we'll see | |||
nemokosch | I think there are conceptual problems with recovering from syntax errors as well | ||
it implies you know where the faulty part terminates | 10:42 | ||
in which case you can write a rule exactly for that - "eat up everything until this certain pattern where the error must end" | |||
rikashore | yeah this is not for full syntax, its just for tokenisation though | ||
and since the tokens are small enough, I can just assume every unknown character is an error token | 10:43 | ||
nemokosch | in that case you probably really know where a token can end | 10:44 | |
rikashore | yeah | ||
although I've been meaning to play around with lexer construction through automata | |||
so might be a nice detour to try and implement that | |||
nemokosch | fair enough | 10:45 | |
a plain DFA might have less overhead anyway, when implemented at a sufficiently low level | |||
rikashore | yeah true, perf isn't my main goal however right now but I see what you mean | 10:46 | |
nemokosch | fair enough | 10:47 | |
antononcube | @rika "Is there an action for raku grammars that get called when all rules fail." -- I think FALLBACK can be used. In the package "FuncitonalParsers" for the ability to generate grammars from a BNF I had to deal with the cases when the BNF is incomplete, and used FALLBACK. | 12:41 | |
Now, in "FunctionalParsers" the generated random sentences generation code uses FALLBACK , but that should work for grammars too. | 12:42 | ||
@rika Actually, I am not sure I got it right. Where do you want the fallback to happen? In the grammar <TOP> grammar rule you can always define a fallback match, like, TOP { [<rule1> | <rule2> | <rule3>] || <fallback-rule> } | 12:46 | ||
Also, see this discution: stackoverflow.com/a/49200368/14163984 | 12:47 | ||
13:10
stanrifkin joined
|
|||
nemokosch | This is why I asked whether it's about fallback to the matching or fallback to the actions ^^ | 13:51 | |
rikashore | I see | 14:38 | |
thank you | |||
.ohnowendigo | How do I check if a list is an element of another list? I tried l1 (elem) l2 but it always returned false. | 16:29 | |
m: say <1 2> (elem) (<1 2>, ❤️ 4>) | 16:30 | ||
Raku eval | Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Bogus term at /home/glot/main.raku:1 ------> say <1 2> (elem) (<1 2>,⏏ ❤️ 4>) expecting any of: infix infix stopper prefix statement end statement modifier statement modifier loop term | ||
.ohnowendigo | m: say <1 2> (elem) (<1 2>, <3 4>) | ||
Raku eval | False | ||
nemokosch | It's because the list have referential identity | 16:31 | |
m: say <1 2>.WHICH, <1 2>.WHICH | |||
Raku eval | List|6362861461664List|6362861461760 | ||
nemokosch | There is a module called ValueList with the promise that it would get added natively to the next language version | 16:32 | |
16:36
dakkar left
17:26
Chopchop joined
|
|||
wambash | m: say (|<1 2>) (elem) ((|<1 2>), (|<3 4>)) | 18:17 | |
Raku eval | True | ||
nemokosch | This hack used to work but it was decided that it shouldn't | 18:18 | |
github.com/Raku/problem-solving/issues/372 | 18:19 | ||
wambash | oh, that will breake a lot of my code. | 18:23 | |
nemokosch | I have also used it tbh | 18:24 | |
18:27
Chopchop left
|
|||
librasteve | this (|<1 2>) is a Slip, right? so what is the connection to the Capture discussion in that problem solving issue? | 19:39 | |
.ohnowendigo | m: say (|<1 2>) (elem) ((|<1>), (|<2 3 4>)) | 20:08 | |
Raku eval | False | ||
librasteve | yeah - same for me with (|<1 2>) (elem) ((|<1 2>), (|<3 4>)) is False | 20:11 | |
I am on Rakudo™ v2023.08. | 20:16 | ||
.ohnowendigo | Anyway I figured out how to do it wo! | 20:20 | |
m: say so (<1 2>, <3 4>).first(<1 2>) | 20:21 | ||
Raku eval | True | ||
librasteve | nice! | 20:24 | |
21:08
stanrifkin left
21:10
saint- joined
|
|||
nemokosch | m: |<1 2> andthen .&dd | 21:18 | |
Raku eval | slip(IntStr.new(1, "1"), IntStr.new(2, "2")) | ||
nemokosch | m: ((|<1 2>), (|<3 4>)) andthen .&dd | 21:19 | |
Raku eval | (IntStr.new(1, "1"), IntStr.new(2, "2"), IntStr.new(3, "3"), IntStr.new(4, "4")) | ||
nemokosch | not sure why this would ever work | ||
I didn't notice it was with | and honestly I think that was a thinko in the first place | 21:20 | ||
(1, 2) was the one that "used to work" (it still does) but shouldn't | 21:21 | ||
|(1, 2) would have never worked | |||
discord ate the backslash up | |||
so, \(1, 2) was the one that did kinda work | |||
(|<1 2>) is just <1 2> with extra steps | 21:22 | ||
oh right - probably @wambash also used the backlash, and it also got absorbed 🤣 | 21:23 | ||
ha, take this, I can see invisible backslashes | |||
this will work but this is will be a plain linear search, for the record | |||
I wouldn't know by heart but probably it uses smartmatching | 21:24 | ||
m: say so (<1 2>, ❤️ 4>).first((1, 2)) | 21:25 | ||
Raku eval | Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Bogus term at /home/glot/main.raku:1 ------> say so (<1 2>,⏏ ❤️ 4>).first((1, 2)) expecting any of: infix infix stopper prefix statement end statement modifier statement modifier loop term | ||
nemokosch | bruh | ||
m: say so (<1 2>, <3 4>).first((1, 2)) | |||
Raku eval | True | ||
nemokosch | m: <1 2> eqv (1, 2) andthen .say | 21:26 | |
Raku eval | False | ||
nemokosch | yes, it must be smartmatching | ||
m: say so (<1 2>, <3 4>).first((1, *)) | 21:28 | ||
Raku eval | True |