Ancestors

Toot

Written by Profoundly Nerdy on 2025-01-29 at 16:17

[#]Rakulang grammar question. Given something like:

[#] Ex. 1
grammar CSV {
    TOP {} # ??
    token column { [ '"' ]? .* \, [ '"']? }
}

[#] Ex. 2
grammar USD {
    TOP {} # ??
    token dollars { \d ** 3 [',']? } 
    token cents   { \. \d ** 2     }
}

  1. How do I tell the grammar's TOP that a given token could potentially repeat an arbitrary number of times?

  1. Can I mix in range validation somehow? So that 1,234.56 is a valid capture but 0,123.45 is not.

[#]programming #linux

=> More informations about this toot | More toots from profoundlynerdy@bitbang.social

Descendants

Written by Profoundly Nerdy on 2025-01-29 at 18:38

@smonff I know you're big into #Perl and know it better than I do. I'm not sure if you know Raku well enough to comment but I figured I could ask.

Feel free to reply with a Perl-lish example, even if it isn't valid Raku. 😀

=> More informations about this toot | More toots from profoundlynerdy@bitbang.social

Written by Mike Clarke on 2025-01-29 at 16:57

@profoundlynerdy For example two, you could consider starting the match with [1-9] instead of \d, to prohibit leading zeros

=> More informations about this toot | More toots from clarkema@mastodon.social

Written by Profoundly Nerdy on 2025-01-29 at 17:31

@clarkema So, something like this:

[1..9] \d 0..2 [',']?

Is that right, or did I screw something up?

=> More informations about this toot | More toots from profoundlynerdy@bitbang.social

Written by Mike Clarke on 2025-01-29 at 18:24

@profoundlynerdy Had to go and scratch my head for a while! This is not exhaustively tested, but should be a starting point:

=> View attached media

=> More informations about this toot | More toots from clarkema@mastodon.social

Written by Profoundly Nerdy on 2025-01-29 at 19:07

@clarkema That's interesting. I'm going to have to play with that.

=> More informations about this toot | More toots from profoundlynerdy@bitbang.social

Written by Mike Clarke on 2025-01-29 at 21:03

@profoundlynerdy I think the main points are:

a) splitting out the two cases of with and without commas, so you can think about one at a time rather than coming up with one monster regexp (which is the whole benefit of grammars) and

b) matching the comma before a fixed group of 3, rather than as an option after a variable-length group.

Would be interested to see other solutions though!

=> More informations about this toot | More toots from clarkema@mastodon.social

Written by Profoundly Nerdy on 2025-01-29 at 19:08

@clarkema Does order of token declaration matter in this (or any) case?

=> More informations about this toot | More toots from profoundlynerdy@bitbang.social

Written by Mike Clarke on 2025-01-29 at 20:12

@profoundlynerdy Nope

=> More informations about this toot | More toots from clarkema@mastodon.social

Written by sebi on 2025-01-29 at 19:48

Sorry @profoundlynerdy but I am afraid that I cannot help. I took a look at Raku a long time ago, but then, mostly ignored it as I realized I’ll have to focus more on Perl. I am not even sure I could explain what a grammar is!

=> More informations about this toot | More toots from smonff@rivals.space

Written by Profoundly Nerdy on 2025-01-29 at 19:56

@smonff Gotcha.

Grammars are regexes on steroids! https://docs.raku.org/language/grammars

=> More informations about this toot | More toots from profoundlynerdy@bitbang.social

Written by ianto on 2025-02-03 at 13:10

@profoundlynerdy @smonff i was going to ignore this but now that its been highlighted that this is a regexy thing, i'm going to have to revisit #rakulang

=> More informations about this toot | More toots from bocs@toot.wales

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113912543862118380
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
446.446195 milliseconds
Gemini-to-HTML Time
4.521173 milliseconds

This content has been proxied by September (3851b).