-
Notifications
You must be signed in to change notification settings - Fork 8
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
s///ee parses, but eval("") does not, and related topics #108
Comments
This is a tough one. Yes, we can allow However, while we can argue that Guacamole (as a parser) can support more than Standard Perl (which can enforce using policies), I think the two are also intertwined in the sense that Guacamole is a parser for the Standard Perl syntax definition. To view this from each component's perspective:
Now, if the assumption that all |
I avoid eval STRING in production code as much as my imagination allows, and here are the reasons I use it in Marpa::R2. 1.) Paranoia about $VERSION conversions:
2.) Getting the result of a run-time "require":
3.) A "developer-safe" coding hack:
The forgoing is developer safe because each of the characters \t, etc. need only be specified once, making it unlikely that yours truly will specify them inconsistently. :-) |
Gaucamole has very strict version numbers, but I don't think it helps considering people use these versions in strings because then they need to be The only way to deal with this, I guess, is requiring module versions not be set in strings and then it can be parsed by both Perl and Guacamole natively. I think this does expose an interesting perspective of people using code (and values) which are not being natively parsed by Perl and run another Perl instead to then parse them. It's hard to see this as a good practice, though.
When I can't avoid runtime loading of a module name in a string, I use
I can understand this use, but it's not a big concern for me. It's definitely a helpful trick. I hope the following is readable enough to avoid doing it with $escape2[ ord $_->[0] ] = $_->[1]
for
[ "\t" => '\t' ],
[ "\r" => '\r' ],
[ "\f" => '\f' ],
[ "\b" => '\b' ],
[ "\a" => '\a' ],
[ "\e" => '\e' ]; I'm still undecided if to allow |
Sure, that makes sense. I am happy this project exists, because I think a Perl that is parseable by more than just I have a largeish (for one author) codebase that I'm considering porting to standard.pm, and one of the things I really miss in standard.pm is hash key autoquoting. I could of course fork Guacamole, but that's probably the least favorable option this early on, cooler would be if there were an extension mechanism built in (so I could make my own
That would seem like an argument for disallowing
I did a quick grep of my codebase and I use it a bit in testing, I have a few instances of Also, I think templating engines make heavy use of I personally don't need |
Don't dare worry that you're "complaining too much." :) Your feedback is very valuable for making the project both better and more production-ready.
That is one of the hard-stops in Guacamole because the quoting is a bit subtle and a thorny problem for beginners. Like many things, it's great until you hit the edge-cases: $foo{bar} = "foo"; # auto-quoted
$foo{
bar
} = "foo"; # not auto-quoted
$foo{
caller} = "foo"; # also, not auto-quoted and runs caller()
$foo{+bar} = -foo; # left-side isn't auto-quoted, right-side is - what a mess (For the record, I've hit those cases and it was not fun.) I started writing a tool for adding quotes to code so I wouldn't have to do it myself. This is what I got so far.
#23 is indeed the idea of doing it. Unfortunately, I couldn't yet come up with the mechanism. If you have any thoughts or would like to help with this, I'd be more than happy to go into it together and see what's possible.
I don't fully understand this one, sorry.
Why would you have to
That's fair. What I'm worried about is adding to the syntax definition something that - from the start - has a label of "please don't even do this. You really, really, really shouldn't use this unless you're doing some very low-level stuff." But I guess it might be impossible to entirely avoid it in the parser. |
In my list of uses of eval STRING in Marpa::R2, I omitted the uses in my test suite. Actually, testing is essential, and eval STRING does prove very handy in testing. |
Yes, I get that (I even wrote about it myself on PerlMonks). To separate the two topics: Hash subscripts: My understanding is that Standard Perl doesn't accept barewords anywhere (except the Fat comma: This one is actually more important to me personally than the hash subscripts, since it's basically "the" way to write named parameters in Perl, and those names usually match the Anyway, getting a little off topic :-)
Sure! Currently, I'm approaching this from the viewpoint of my use case, i.e. how I could port my codebase to a Perl that is statically parseable, while still allowing me to keep some of my personal style (like e.g. hash key autoquoting, and I would love to get certain sub calls without parens back, if I can think of a safe way to implement that). I will think about this some more, and I'll look at the suggested extension mechanism, but since I'm currently working on a bunch of different things, I'm currently operating on somewhat longer time scales (as evidenced by my delayed reply) - I'll of course report back once I have something interesting.
Its value looks like
Yes, sorry, the second sentence is just a scenario in my imagination :-) The main question is: You said "Standard Perl's syntax definition intends to be both clearer and simpler", then why is So I'm basically just saying: IMHO, either disallow |
I've just pushed support for |
This is correct.
I think that might be possible (currently, we're managing a lot of whitespace rules through Marpa, but there's a ticket for manually handling all whitespace. I'm not sure it's worth the effort and initial picking at it failed miserably. I think we're now entering user behavior: If By having strings always be strings, the entire issue is avoided. If you come from another language, strings being quoted is not an unreasonable thing.
I think you hit an edge case where we could probably (phrasing it cautiously here) but we would create a situation that I think adds a burden of difference between Guacamole and Perl (and other parts of Guacamole) that might cause more confusion than relief.
LHS of fat comma is not a fun thing to tackle and includes edge-cases just the same.
I just pushed a commit that adds methods for extending the grammar, specifically with raw lexemes and with keywords. Here is a sample addition of
I'm willing to be more flexible to help Guacamole be supported. I've updated it to support
This should now be supported with
You make a good argument. I hope the |
As kind of a continuation of #106, this is a bit more philosophical. In that issue, I assumed that even though Guacamole should be capable of parsing
eval("code")
, it was chosen not to support it becauseeval EXPR
should not be part ofstandard.pm
.If that's the case, then IMHO
s///ee
should not be supported either (and as a related issue, couldn'ts///e
parse the replacement part accordingly?).However, I had a different thought: Since I'm guessing
eval STRING
is not supported for policy reasons, and not for technical reasons, would it make sense to implement it differently in Guacamole? That is, alloweval("code")
to be parsed, but then reject it after parsing as a matter of policy (similar to Perl::Critic's ProhibitStringyEval)? This would allow Guacamole's parser to be used for projects that do want to supporteval
, i.e. to adjust the policies.And as another side note: I can also work around the missing support for
eval EXPR
withdo FILE
...The text was updated successfully, but these errors were encountered: