-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regex literals #4
Comments
The big thing I'd like to avoid here is setting a global variable. Ruby sets However, the current semantics of the pattern-match operator are to return the right-hand-side value to allow pattern-matching assignments to be chained inline with simple assignments: all = {thing1: :a, thing2: :b} =: function_call_returning_map() I don't remember my particular reasoning for that decision, but I'd probably be open to returning the left-hand-side instead as an anonymous value on the stack, though that may have some implications to the syntax of pattern-matched function parameters. |
I read something a week or so ago giving a general dissent about using While that ambiguity isn't really accurate from a parsing standpoint (the grammar essentially enforces that where a division would occur, a regex would be invalid, and vise-versa), I can agree with the visual ambiguity. I'm not sure what I would prefer as an alternative, though. Elixir uses a |
While I was originally against them, Sigils are a decent solution for non-literal literals (regexes, datetimes as shown in #5, etc.). I still don't want to implement them in quite the same way (user-defined sigils seem a bit messy), but I could see having a few defined by the language. |
Just a slight variation on sigils: I like the lack of tilde, it's also not syntactically ambiguous with division. |
Im all for the In this examle i'll call it sigil because I've no better name atm. It'd be better if we came up with some cool name of our own imo. I think that it should be possible for people to define their own sigil
The smallest possible sigil defineable should be So just like regexes really, the main difference being the For example we could (pretending we have a sigil s(in : String, [String, String] =: args, opts : List)
when opts.includes? "g"
return in.gsub(args[0], args[1])
else
return in.sub(args[0], args[1])
end
end (Sorry about all my Myst syntax problems.) Note that all of this is just something that popped into my head while reading (@faultyserver)s earlier suggestions, and I just posted them during class. Take everything with a grain of salt. WDYT? |
While I generally like your idea for implementing sigils, I don't think it would fit well in Myst. The sigil style itself has a pretty universally understood pattern, and is a very clean way of representing textual operations, even outside of text editors. But, applying that into expressions for a programming language seems a bit awkward. I've never really been a fan of the I'm also not entirely sold on the combination of that operator with the sigil, which is essentially another operator in the expression. In particular, with the example you've given, it's not really any shorter or cleaner than just using the
Obviously this is just one example and it could be more effective in other cases, but I much prefer the obvious call and implied operation of the method syntax over the operator+sigil style. If we can come up with a different way to apply the sigil to the receiver, I would gladly be open to it. |
And for the record, I really like the pattern-matching syntax you suggested. It might be difficult to implement, but if that can be done without complicating the backend logic too much, then it will have been worth the effort. Do you have an idea of which file(s) would have to be updated to process this type of syntax? |
From a parsing standpoint, everything would live in A Interpreter-wise, And of course specs for all of these changes in their respective spec files, which should all exist and be named appropriately in the That’s all that i can think of that needs updating at a glance. It’s quite a lot but most of the changes are pretty minor. |
Regex literals are an important part of modern scripting languages. Having a concise syntax for instantiating patterns and performing matches is important.
For actually performing matches, I think using the existing pattern-matching syntax would be nice:
This syntax would only work with named subgroups, but seems incredibly clear and concise in terms of extracting values. Compare this to the Ruby equivalent:
Crystal has direct support for PCRE regexes, so the actual matching aspect should be simple to implement.
This needs more thought for unnamed captures, interpolation, and other edge cases, but these are my initial thoughts.
The text was updated successfully, but these errors were encountered: