groovy

line/column information for parenthesised expression

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.6-beta-1
  • Fix Version/s: 1.5.6, 1.6-beta-1
  • Component/s: parser
  • Labels:
    None
  • Environment:
    WinXP
  • Testcase included:
    yes
  • Patch Submitted:
    Yes
  • Number of attachments :
    4

Description

One way to find out if an expression like x = 3 * (2 + 1) has parenthesis is to have a look in the original file.
(2 + 1) represents a BinaryExpression in the AST but the line information does not include the parenthesis.
There were several problem with that:

  • Need of search back the opening parenthesis from the beginning of the BinaryExpression to find out if parenthesis were used.
  • in "for (i = 0; i < 10; i++)" i = 0 represents a BinaryExpression too. Applying the solution above would cause parenthesis around the
    expression i = 0 because an opening parenthesis would be found. But its the parenthesis of the for-statement.

With the patch the line information of every parenthised expression (e.g. BinaryExpression) contains the parenthesis if there are any.
This is reached by wrapping the EXPR node for the parenthised expression with a new EXPR node that has line information including the parenthesis.
During the conversion from the CST to the AST the new added EXPR node is used to set the line information for the BinaryExpression. (have a look at the screenshots)

Well, it's nowhere documented how the line information must be in situation like that. But it simplifies to find out whether parenthesis are used or not.

The tests provided depend on the test environment in GROOVY-259

  1. parenthesisPatch.patch
    19/Mar/08 9:12 AM
    2 kB
    Martin Kempf
  2. testParenthisedExpression.patch
    19/Mar/08 9:12 AM
    0.7 kB
    Martin Kempf
  1. AST after patch.jpg
    21 kB
    19/Mar/08 9:19 AM
  2. AST before patch.jpg
    19 kB
    19/Mar/08 9:17 AM

Activity

Hide
Martin Kempf added a comment -

CST of x = 3 * (2 + 1) before patch

Show
Martin Kempf added a comment - CST of x = 3 * (2 + 1) before patch
Hide
Martin Kempf added a comment -

CST of x = 3 * (2 + 1) after patch

Show
Martin Kempf added a comment - CST of x = 3 * (2 + 1) after patch

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: