Follow

part of why regexes feel like dark magic to a lot of people is that they look like symbol vomit. you could probably make them a lot more usable if you made them more verbose... somehow made it easier to insert nonsignificant whitespace and comments...

ooh, maybe you could package it in a nifty little functional programming style syntax and extend its functionality a little bit...

wait, i just invented parser combinators again

@typhlosion parser combinators but you can use them in mainstream programming languages

@00dani python has an excellent parser combinator library

rust has a few but i haven't tried them yet

@hy lots of languages have parser combinator libraries, if that's what you mean! haskell's parsec is arguably the most famous

@typhlosion At least Ruby has an "extended regex" mode, where you can insert nonsignificant whitespace and comments (enabled with the /x flag IIRC)

@typhlosion that's why people tend to get parts like 0x\d+ into a HEX_NUM variable and then concatenate a bunch of them to form the final regex

@typhlosion I really feel like parser expression grammars should be taught as part of like, 101 level programming, just because like... They make input parsing so much easier than manually reading in numbers of characters and such

@typhlosion I've been thinking for a while that I just usually want an AST and constructors for regular expressions, rather than the string syntax. then you never have to escape anything and, more importantly, you can safely compose language fragments constructed in different parts of your program.

of course the downside is frequently that expressions can be quite a bit more verbose, but that's kinda what we wanted too...

I've used and written some libraries like that. my favorite for several reasons is sebfisch.github.io/haskell-reg but I think it doesn't compile with current GHC. I wrote a proof of concept of a similar thing in Rust (github.com/jameysharp/weighted) though it has plenty of sharp corners and I was also using it to explore parsing techniques for non-regular languages.

@Xarph no, perl's regexes are no more readable than any other regexes

Sign in to participate in the conversation
Awoo Space

Awoo.space is a Mastodon instance where members can rely on a team of moderators to help resolve conflict, and limits federation with other instances using a specific access list to minimize abuse.

While mature content is allowed here, we strongly believe in being able to choose to engage with content on your own terms, so please make sure to put mature and potentially sensitive content behind the CW feature with enough description that people know what it's about.

Before signing up, please read our community guidelines. While it's a very broad swath of topics it covers, please do your best! We believe that as long as you're putting forth genuine effort to limit harm you might cause – even if you haven't read the document – you'll be okay!