groovy
  1. groovy
  2. GROOVY-5159

Grammar could accept nls! before SPREAD_DOT

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 1.8.4
    • Fix Version/s: 2.3.0-beta-1
    • Component/s: parser, parser-antlr
    • Labels:
      None
    • Number of attachments :
      0

      Description

      When laying our code to be readable, the ability to do:

      'name score\ntim 1\ndave 4\ntim 3'.split( /\n/ )               // split on newline
                                        .drop( 1 )                   // drop header
                                        .collect { it.split( / / ) } // split each by space
                                        .groupBy { it[ 0 ] }         // group by name
      

      Makes code fantastically readable when explaining it to people.

      However, if I want to replace the line

                                        .collect { it.split( / / ) } // split each by space
      

      with

                                        *.split( / / )               // split each by space
      

      Then I can't as the parser complains that

      unexpected token: *. at line: 3, column: 35
      

      The only workaround is to place all of the operators at the ends of the lines, which to my eyes looks a bit of a mess (and in my experience is confusing to people)

      ie:

      'name score\ntim 1\ndave 4\ntim 3'.split( /\n/ ).      // split on newline
                                         drop( 1 )*.         // drop header
                                         split( / / ).       // split each by space
                                         groupBy { it[ 0 ] } // group by name
      

      Obviously, I could go for a style of appending the single '.' with appending the '*.', but I feel this makes it more confusing again...

      I've had a look at groovy.g, but can't seem to spot the trick to allow this, without causing ambiguity

        Activity

        Hide
        Paul King added a comment -

        Duplicate of GROOVY-6593

        Show
        Paul King added a comment - Duplicate of GROOVY-6593

          People

          • Assignee:
            Paul King
            Reporter:
            Tim Yates
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: