|
00:13
lichtkind_ left
00:46
kylese left
00:49
kylese joined
01:07
wayland joined,
wayland76 left
01:38
hulk joined
01:39
kylese left
01:40
newbie27 joined
|
|||
| newbie27 | hi all | 01:41 | |
| is it possible to place `use some_module` somewhere the module will be available everywhere ? thanx a lot | 01:45 | ||
| [Coke] | m: pass "this works" ; use Test; | 02:00 | |
| camelia | ok 1 - this works | ||
| [Coke] | the use happens at compile time, so you can put it anywhere in the lexical scope you need. | ||
|
02:01
leppard left
|
|||
| newbie27 | thanx a lot. And where can i put the `use` to made the module available in all scopes, everywhere ? | 02:10 | |
|
02:15
hulk left,
kylese joined
03:10
newbie27 left
04:14
ShimmerFairy left
04:17
rmv joined,
rmv left,
rmv joined
04:22
rmv left
06:55
ShimmerFairy joined
06:59
ShimmerFairy left,
ShimmerFairy joined
07:19
rmv joined,
rmv left,
rmv joined
08:14
dano left
08:59
johnjay joined
09:00
shiuanyi joined
09:01
rmv left
09:04
shiuanyi left
10:25
Sgeo left
10:59
rmv joined,
rmv left,
rmv joined
11:03
rmv left,
shiuanyi joined
|
|||
| shiuanyi | Is there a way to print a message, when a token or rule fails to parse? This is something like FAILGOAL, but not limited to the tilde structure. | 11:07 | |
|
11:13
shiuanyi22 joined
11:14
shiuanyi22 left,
shiuanyi left,
shiuanyi85 joined
11:15
shiuanyi85 left
11:16
shiuanyi joined,
shiuanyi left
11:31
rmv joined,
rmv left,
rmv joined
11:36
rmv left
11:38
shiuanyi joined,
shiuanyi left
|
|||
| wayland | newbie27: If you do it at the top level, it will be available eveywhere in the current file; I think that's about the closest we can get. | 11:50 | |
| tellable6 | wayland, I'll pass your message to newbie27 | 11:51 | |
| wayland | shiuanyi: In a grammar? | ||
| tellable6 | wayland, I'll pass your message to shiuanyi | ||
| wayland | token number { \d+ || <!> "Expected a number" } | 11:54 | |
| Wouldn't that do it? | |||
|
11:55
lichtkind joined
12:13
shiuanyi joined
|
|||
| shiuanyi | wayland | 12:26 | |
| tellable6 | 2026-07-12T11:51:33Z #raku <wayland> shiuanyi: In a grammar? | ||
| shiuanyi | I tried to test the following code. But it printed no message. Did I do something wrong? | ||
| grammar Test{ | |||
| token number { \d+ || <!> "Expected a number"} | |||
| } | |||
| sub MAIN(){ | |||
| Test.parse('abc', :rule('number')); | |||
| } | |||
| timo | m: grammar A { token TOP { "hello" || { die "oh no!" } } }; note A.parse("hello"); note A.parse("99") | 12:27 | |
| camelia | 「hello」 oh no! in regex TOP at <tmp> line 1 in block <unit> at <tmp> line 1 |
||
| timo | but be careful: if you're relying on backtracking in parts of your grammar, then hitting the "die" will immediately abort parsing right then and there | 12:28 | |
| `<!>` is a token that will never succeed to parse, so you can use that to prevent a token from returning success, but it doesn't have a mechanism to pass a message about the reason for parse-failure upwards | 12:29 | ||
| in general, generating a helpful error from parsing while backtracking is involved can be extra tricky, since you're usually interested in the branch that got the furthest before a cascade of backtracking attempts that didn't succeed happened | 12:30 | ||
| the common way to handle this is by keeping a "high water mark", what part of the grammar has reached the furthest in the string | 12:31 | ||
| i'm not sure if the built-in one can be accessed by user space without internals-digging? | 12:32 | ||
| cursors and match objects have private methods !highwater, !highexpect, and the methods to handle those | 12:33 | ||
|
12:35
shiuanyi left
|
|||
| timo | oh the docs have a fun little trick for you | 12:35 | |
|
12:35
shiuanyi joined
|
|||
| shiuanyi | timo | 12:37 | |
| I tried your idea and changed the code to the following. It worked as expected. Thank you for your help. | |||
| token number { \d+ || {say "Expected a number"}} | |||
| timo | depending on your circumstances, you may want `note` instead of `say`, because note goes to stderr and say goes to stdout. if you care about keeping error-like messages on stderr and data-like output on stdout | 12:38 | |
| you can even use `warn` which is possible to catch because it's exception-like | |||
| the default FAILGOAL doesn't output a message or throw an exception or anything? I didn't realize you are expected to implement it yourself if you want that | 12:40 | ||
| docs.raku.org/language/regexes#Til...structures - here's some interesting stuff, including how to use tilde without having to have an explicit surrounding thing by replacing the token before the tilde with <?> which is the token that always matches | |||
| shiuanyi | very helpful information of 'warn' and 'note'. I'll read the docs later. | 12:41 | |
| I thought that FAILGOAL is the method to implement, when parsing fails. It seems that it only applied to tilde, not to others. | 12:45 | ||
| timo | yeah, you usually want a failing token or rule to not abort parsing altogether, but to go back and try the next alternative or try stepping back a quantifier or something | 12:51 | |
| sometimes you know that having parsed a '(' in some place means there's no way for the full grammar to succeed if the corresponding ')' can't be found | 12:52 | ||
| in that situation it can be fine to have a FAILGOAL that throws an exception, though especially with nested structures you have to be careful that the "inner" stuff doesn't swallow the ")" too early and causes the tilde construct to throw the exception | 12:53 | ||
|
13:05
shiuanyi left
|
|||
| tbrowder | ref docs @todd said he now uses chatgpt instead of the docs. i must admit with my declining memory i often do the same | 13:24 | |
| works well for bash, debian stuff, etc. | 13:25 | ||
| if i can remember what i was looking for :-D | 13:26 | ||
| but i a, | 13:35 | ||
| *most always backup anything i'm not real sure about with a test | 13:37 | ||
|
14:02
rmv joined,
rmv left,
rmv joined
14:07
rmv left
14:32
rmv joined
14:54
apogee_ntv left
14:56
apogee_ntv joined
15:06
hurufu joined
15:24
apogee_ntv left
15:25
apogee_ntv joined,
rmv left
17:24
rmv joined,
rmv left,
rmv joined
17:28
rmv left
18:34
Sgeo joined
18:46
gabiruh left
|
|||
| [Coke] | IWBNI when raku found a bug in META6.json's JSON that it said what it was parsing to generate "Invalid JSON" | 18:58 | |
| I have something that is doing a bunch of other JSON parsing, that would have helped. :) | 18:59 | ||
|
19:04
gabiruh joined
19:41
vlad joined
19:53
rmv joined
20:51
ShimmerFairy left,
ShimmerFairy joined
21:07
wayland76 joined
21:08
wayland left
22:30
rmv left
22:52
hurufu left
22:59
rmv joined,
rmv left,
rmv joined
|
|||