-
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
block and hash disambiguation #2
Comments
Personally, I like option 3 the best. It is the biggest change to the language, but it makes all blocks parse the same. |
Let's embrace the solution then? |
Before we embrace it, I want to prove that this solution works by implementing it in the Marpa parser. I already have code blocks and hash literals implemented, and tests that check for ambiguity in the parser. |
I think we resolved this using The rule, for posterity, is:
For example, using
There is still the case of @vickenty did I miss anything? |
sort has multiple options: 1. sort { $a <=> $b } @foo; 2. sort @foo; 3. sort $subname @foo; 4. sort subname @foo; Option #1, #2, and #3 are supported. Option #3 requires explicitly a scalar variable, not an expression. Option #4 is very odd. It explicitly wants a bareword of a sub name. Option #4 is *NOT* supported.
This may require some fine tuning later: We also removed comma and fatcomma as top-level operators in blocks: |
This happens when a pair of curly braces is used as a stand-alone statement in a code block (sub, eval, etc), or as the first argument to one of the operators below:
print
,printf
,say
system
,exec
sort
,grep
,map
(This is not related to prototypes, these operators are always parsed using special rules, even if parenthesis are used around the arguments. In expressions, after
return
keyword curlies are always treated as a hash literal.)While a sufficiently powerful parser can probably handle this, rules used for this disambiguation are rather unique and would complicate the parser too much. The disambiguation rules are also not documented in full. In brief, perl checks if there's a comma right after first thing inside the braces (full disclosure below).
I'd like to make curlies always interpreted as a block:
map
context;do "config.pl"
orsub { { foo => 1 } }
).Several possible solutions:
Require a semicolon after opening brace in ambiguous situations.
Require parens around expressions with comma or fat-comma inside ambiguous blocks.
Require parens around all expressions with comma or fat-comma, if not inside an expression. This is global change, but in return code block syntax becomes the same everywhere (unless I missed anything).
Disambiguation rules
Exact details are not really important to this issue, but I put them here for reference and entertainment.
Perl parses a pair of curly braces as a hash if one of the following is true:
Here token means a quoted string or command (
''
,""
, ````,q{}
, `qq{}` and `qx{}`) or a sequence of word characters.The text was updated successfully, but these errors were encountered: