You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2019/07/08 14:49:32 UTC

[GitHub] [netbeans] junichi11 opened a new pull request #1363: [NETBEANS-1696] PHP 7.4 Support Arrow Functions 2.0

junichi11 opened a new pull request #1363:  [NETBEANS-1696] PHP 7.4 Support Arrow Functions 2.0
URL: https://github.com/apache/netbeans/pull/1363
 
 
   ## Arrow Functions 2.0
   
   See https://wiki.php.net/rfc/arrow_functions_v2
   
   ![nb-php74-arrow-functions](https://user-images.githubusercontent.com/738383/60818914-8736c700-a1d9-11e9-8af0-60d1388c0e87.png)
   
   ### 1st commit
   
   - Fix ASTPHP5Parser.cup, ASTPHP5Scanner.flex, and Php5ColoringScanner.flex i.e. parser and lexers
   - Add ArrowFunctionDeclaration as an ASTNode
   - Add ArrowFunctionScope
   - Add code templates for arrow functions
   - Fix PHP74UnhandledError and UnusableTypesUnhandledError
   - Fix GotoDeclaration and MarkOccurrences features
   - Add ASTErrorExpression node to avoid that an ArrowFunctionDeclaration node is handled as an ASTError
   - Add unit tests
   
   ### 2nd commit
   
    - Fix the formatting feature
   
   ### 3rd commit
   
   - Fix the code completion feature
   
   ### the others
   
   Missing changes for `__serialize` and `__unserialize`
   
   ### About ASTErrorExpression node
   
   e.g. these are syntax errors
   ```php
   fn($x) => return $x;
   fn(int $number) =>;
   ```
   
   The parser result(the first case) is like the following:
   <details>
   <summary>parser result: before</summary>
   
   ```
       <Program start='0' end='836'>
           <Statements>
               <ASTError start='815' end='824'/>
               <ReturnStatement start='825' end='835'>
                   <Variable start='832' end='834' isDollared='true'>
                       <Identifier start='833' end='834' name='x'/>
                   </Variable>
               </ReturnStatement>
           </Statements>
       </Program>
   ```
   </details>
   
   The first case is no problem because it is a complete statement and it is a syntax error. But the second case has a problem. It is an incomplete statement(i.e. a user is typing...). That part is handled as an ASTError. So, the parameter is not scanned in the `ModelVisitor`. i.e. `$number` is not added to code completion items.
   
   I would like to avoid that. So I've added `ASTErrorExpression` as an `ASTNode`(see `ASTPHP5Parser.cup`). That way, we can scan parameters even if there is a syntax error in an expression part of `ArrowFunctionDeclaration`.
   
   Parser result after it is added:
   <details>
   <summary>parser result: after</summary>
   
   ```
       <Program start='0' end='836'>
           <Statements>
               <ExpressionStatement start='815' end='835'>
                   <ArrowFunctionDeclaration start='815' end='824' isReference='false' isStatic='false'>
                       <FormalParameter start='818' end='820' isMandatory='true' isVariadic='false'>
                           <ParametrType>
                           </ParametrType>
                           <ParametrName>
                               <Variable start='818' end='820' isDollared='true'>
                                   <Identifier start='819' end='820' name='x'/>
                               </Variable>
                           </ParametrName>
                           <DefaultValue>
                           </DefaultValue>
                       </FormalParameter>
                       <ASTErrorExpression start='822' end='824'/>
                   </ArrowFunctionDeclaration>
               </ExpressionStatement>
           </Statements>
       </Program>
   ```
   </details>
   
   ## Not Yet
   
   - Hint features e.g. UnusedVariablesHint

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists