Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2697

line/column information for parenthesised expression



    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.6-beta-1
    • Fix Version/s: 1.5.6, 1.6-beta-1
    • Component/s: parser
    • Labels:
    • Environment:
    • Flags:


      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. AST after patch.jpg
          21 kB
          Martin Kempf
        2. AST before patch.jpg
          19 kB
          Martin Kempf
        3. parenthesisPatch.patch
          2 kB
          Martin Kempf
        4. testParenthisedExpression.patch
          0.7 kB
          Martin Kempf



            • Assignee:
              blackdrag Jochen Theodorou
              mkempf Martin Kempf
            • Votes:
              1 Vote for this issue
              2 Start watching this issue


              • Created: