Groovy
  1. Groovy
  2. GROOVY-5159

Grammar could accept nls! before SPREAD_DOT

    Details

    • Type: Improvement Improvement
    • Status: 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

      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

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        825d 16h 30m 1 Paul King 06/Mar/14 20:57
        Resolved Resolved Closed Closed
        29d 3h 3m 1 Paul King 05/Apr/14 00:00
        Mark Thomas made changes -
        Workflow jira [ 12973746 ] Default workflow, editable Closed status [ 12980894 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12734083 ] Default workflow, editable Closed status [ 12745910 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Paul King made changes -
        Resolution Duplicate [ 3 ]
        Fix Version/s 4.0 [ 18928 ]
        Assignee Paul King [ paulk ]
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.3.0 [ 19608 ]
        Hide
        Paul King added a comment -

        Duplicate of GROOVY-6593

        Show
        Paul King added a comment - Duplicate of GROOVY-6593
        Jochen Theodorou made changes -
        Field Original Value New Value
        Assignee blackdrag blackdrag [ blackdrag ]
        Fix Version/s 4.0 [ 18928 ]
        Tim Yates created issue -

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development