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

Grammar could accept nls! before SPREAD_DOT

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.8.4
    • 2.3.0-beta-1
    • parser, parser-antlr2
    • 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

      Attachments

        Activity

          People

            paulk Paul King
            tim_yates Tim Yates
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: