00:51 jaguart joined
jsef5 Quick question, is there a way to make a global variable between files 01:16
```perl
use lib “.”;
use BL;
use BLActions;
sub MAIN($program-name) {
my $code = $program-name.IO.slurp();
$code = $code.subst(/\n/, " ", :g);
my @tokens = split(' ', $code);
loop (my $idx = 0; $idx < (elems @tokens); $idx++) {
my $cword = @tokens[$idx];
my $res = BL.parse($cword, :actions(BLActions));
say BLActions.$sp;
if ! $res and $cword != '' {
say "\nError occured on parsing word '$cword'";
Rogue declare it with `our` instead of `my` 01:45
jsef5 One more thing, how would i match spaces in tokens? 01:59
```perl
token str_ {
\"^\w+( +\w+)\"
}
```
this doesnt seem to work
quantifier quantifies nothing
One more thing, how would i match something in between quotes including spaces spaces in tokens?
```perl
token str_ {
\"^\w+( +\w+)\"
Nemokosch this seems weird enough 02:04
what are you using the caret for? 02:05
jsef5 not sure actually, found that online, settled on this which i wrote 02:06
```perl
token str_ {
\"([^\"]*)\"
}
```
Nemokosch okay, so basically: a quotation mark, than zero or more something else, then a quotation mark 02:07
okay, so basically: a quotation mark, then zero or more something else, then a quotation mark
jsef5 yes
using it for this kind of use case 02:08
```
"Hello world!" print
```
im working on parsing ``"Hello world!"``
Nemokosch seems fair enough; I think it could work with non-greedy asterisk as well
jsef5 Now im having another issue 02:09
```
Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏\"Hello' (indicated by ⏏)
in sub MAIN at bl.raku line 13
in block <unit> at bl.raku line 4
02:10 discord-raku-bot left, discord-raku-bot joined
Nemokosch m: dd "hello world!" ~~ / \" (.*) \" / 02:10
bruh
I forgot the frugal marker itself 02:12
m: dd "hello world!" ~~ / " (.*?) " /
m: dd "hello world!" ~~ / \" (.*?) \" /
jsef5 lol
Nemokosch now that should be more like it
oh okay, now only the input was wrong
m: dd '"hello world!"' ~~ / \" (.*?) \" / 02:13
oh yeah 02:14
```/ \" (.*?) \" /```
$cword != ""
suspicious
jsef5 yea...
Nemokosch != converts to numeric
I doubt that's what you want
jsef5 it does?? 02:16
Nemokosch yep
jsef5 woopsies
Nemokosch I wish the compiler at least complained when one of the operands is a hardcoded string constant
I actually don't like the empty string to zero conversion, I know it's common but it's still bad
for string comparison, you would use ne 02:17
jsef5 ```perl
if not $res and $cword ne "" {
say "\nError occured on parsing word '$cword'";
exit 1;
}
```
Nemokosch eq and ne are the string operators
jsef5 also 02:18
when splitting, how would i exclude the things in the quotes
Nemokosch what would that mean 🤔
jsef5 cause yknow like
```perl
my @tokens = split(' ', $code);
```
I would not like to split
"Hello world"
into ``"Hello`` and ``world"``
Nemokosch 😬
I'm not familiar with Raku grammars but the feature could be useful here 02:20
also, maybe comb is more useful for you here
jsef5 how would i use comb in this situation
Nemokosch split operates like "what are the separators", comb operates like "what do I want to get"
jsef5 like, ```^(\"([^\"]*)\")``` exlude that 02:21
and split by w+
Nemokosch I think there are word markers 02:22
so I'm thinking of something like 02:24
match a) either <<words>> that don't start with a quotation mark 02:25
b) or quoted strings 02:26
and comb them all
I don't actually know how " is treated, like is it a part of the word or not
hopefully it is
okay, seems like word boundaries just drop quotation marks, then we have to make a little change 02:28
rather than going for <<words>>, we should go for stuff that is preceded and followed by a space
so lookarounds <?after //> and <?before //> 02:29
jsef5 Why would i need that
the code language is similar to forth
guifa okay lemme make sure I get what you want to match 02:30
given a string, you want to stuff between quotes?
Nemokosch that's what you said you wanted
xd
jsef5 wait, but why would i need to check for spaces
is there a way to make word boundries not drop quotes
Nemokosch maybe that's why?
guifa you can have word boundries not drop quotes by adjustng the definition for the <wb> token 02:32
jsef5 guifa: I want to split everything by a space, except for quoted strings something like this
```
"Hello world" top print
```
Would split into ["\"Hello world\"", "top", "print"]
guifa okay, for that you'll need to use an alternation 02:34
<quoted> || <not-quoted>
Nemokosch am I cool? okay, I decided that I am
:DD
guifa has to go afk but will be back
jsef5 you are very cool 02:35
Nemokosch discord has this filthy tendency of hiding backslashes from messages in the name of escaping (but the bot can see them) 02:36
m: dd '"Hello world" top print'.comb: /[<?after ^^|' '> .+? <?before ' '|$$>]|[\" .*? \"]/
and now I need to go to sleep 02:38
bb 02:39
jsef5 bb 02:41
Jaguart @jsef5#7993 what does the text you are parsing look like? You change \n to space and then split by space, to extract words and quoted phrases... and you want to change the loop $idx in another module... it's hard to figure out advice when we don't know what your input or goal is. Also the BL grammar is not clear. One thing to note is that some of your snippets look like Perl regex syntax - Raku rege 02:53
m: dd 'this is wordy "and quoted" with "other things too" tadah"' ~~ m:g/ \" .*? \" || \w+ /
m: say ('this is wordy "and quoted" with "other things too" tadah"' ~~ m:g/ \" .*? \" || \w+ /).gist; 02:55
so the left is your input data, and the numbers on the right are the output? 03:06
jsef5 yea 03:08
i put comments to explain what was being outputted
im writing a small stack based language
Jaguart why do you collapse all the \n - dont they have meaning too? 03:12
jsef5 no
it is all split into "words"
similar to forth
Jaguart ok - well regex dont care about \n so you dont need to replace them with space - \s+ means spaces or newlines
this regex would work on a string even when it contains \n 03:14
m: say ('this is wordy "and quoted" with "other things too" + tadah"' ~~ m:g/ \" .*? \" || <[\w+-]>+ /).gist
You can identify strings - they start and end with \" - you can use $str.chars-2 to get the length
jsef5 ah ok
Jaguart the bit that says <[ \w + - ]>+ means 1-or-more word characters, or + or - characters 03:16
you can add in any other non-alpha chars you need inside the [ ]
jsef5 alright thanks 03:20
Jaguart you can use raku style loops too like this: 03:24
m: for 'this is wordy "and quoted" with "other things too" + tadah"' ~~ m:g/ \" .*? \" || <[\w+-]>+ / -> $m { say $m.Str; } 03:25
just replace the string before the ``~~`` with your ``slurp`` 03:26
let me know if you want a detailed breakdown of the regex 03:32
jsef5 mk 04:11
Jaguart oh - wanting to do some simple stuff in parallel ``race`` - be still my beating heart - fantastic 🙂 04:57
this on concurrency 👏🏼 - jnthn.net/papers/2018-conc-par-8-ways.pdf 04:59
jsef5 That reminds me, is there a way to compile raku to an object file so i can link it with asm and write on os :) 05:22
``` 07:18
5 declare fnum
10 declare snum
fetch snum get top
fetch fnum get top
/ top
declare fnum
fetch fnum get top
```
got something like this to work
this displays 07:24
```
10 5 2 2
```
as it should
Jaguart Is there a Hash implementation in Raku that maintains the declaration order, like PHP associative arrays? 08:24
CIAvash Jaguart: there is raku.land/zef:lizmat/Hash::Ordered 09:23
jaguart @CIAvash - thank you 10:11
10:15 frost joined 11:36 frost left 12:18 frost joined 12:52 frost31 joined, frost left 13:20 razetime joined 14:16 frost31 left 14:26 frost joined, frost left
SmokeMachine m: say '"Hello world" top print' ~~ /['"' ~ '"' .* || \w+]*/ 14:39
camelia 「"Hello world"」
SmokeMachine m: say '"Hello world" top print' ~~ /['"' ~ '"' .* || \w+]* %% <.ws>/ 14:42
camelia 「"Hello world" top print」
15:01 A26F64 joined
A26F64 A question about using exceptions defined in `use`d modules.  I `use JSON::Tiny;`, which will throw JSON::Tiny::X::JSON::Tiny::Invalid (according to `.^name`).  That exception is defined within JSON-Tiny-1.0/.../lib/JSON/Tiny.pm.  If I `CATCH { when JSON::Tiny::X::JSON::Tiny::Invalid { ... } }` Raku doesn't recognize it: "Function 16:58
'JSON::Tiny::X::JSON::Tiny::Invalid' needs parens to avoid gobbling block (or perhaps it's a class that's not declared or available in this scope?)".  Trying to `use` that exception namespace or variations on it also fails (Raku cannot find it anywhere, even though it does find `JSON::Tiny` itself).  Is there a way to catch that particular
exception?
MasterDuke well, you should be able to do something like `when .^name eq 'JSON::Tiny::X::JSON::Tiny::Invalid' { ... }` 17:01
A26F64 That does work; thank you.  I hadn't considered that indirect route: it does seem like we should be able to identify the exception directly, though, doesn't it?  Though I notice that JSON::Tiny's META6 does not `provide` that exception. . . . 17:05
MasterDuke i wonder if you can do something like `when ::('JSON::Tiny::X::JSON::Tiny::Invalid')`, which is still indirect, but maybe one step less hacky 17:06
A26F64 That method doesn't catch that exception. 17:07
17:08 razetime left 17:09 razetime joined
MasterDuke yeah...by .^name is all i'm coming up with right now 17:10
17:13 razetime left 17:14 razetime joined, razetime left, razetime joined 17:15 razetime left
A26F64 No problem.  I said that the META6 doesn't `provide` that exception; am I correct in thinking that it should be available since it is defined as a class within JSON-Tiny-1.0/.../lib/JSON/Tiny.pm, which is of course `provide`d?  Of course it's apparently not but I'd assume that it's just brought in with Tiny.pm. 17:15
MasterDuke it might need to have an `is export` to be automatically available 17:28
19:31 A26F64 left 21:14 discord-raku-bot left, discord-raku-bot joined
jaguart I though the FQN was X::JSON::Tiny::Invalid - i.e. not prefixed as you have it? 23:30
It's declared in JSON::Tiny.pm
So don't you mean ``CATCH { when X::JSON::Tiny::Invalid { ... } }`` 23:32