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

Difference between Antlr2 and parrot parsers for variable declaration optimisation

    XMLWordPrintableJSON

    Details

      Description

      As an optimisation for parsing, both parsers treat statements like:

      int var1
      Foo var2
      Bar var3
      

      as variable declarations due to the starting capital letter of the first term (for non-primitives).

      And the following are treated by both parsers as command expressions:

      foo x
      bar y
      

      due to the lowercase starting letter of the first term. If a class starts with a lowercase letter (valid though not conventional) the workaround where a variable declaration is desired is to use something like:

      import myClass as MyClass
      
      MyClass foo
      

      A difference in behavior can be noted for cases starting with underscore or dollar (the only other characters available for the first letter of a class name):

      _foo bar
      $bar baz
      

      These were command expressions for the old parser and are being coerced to variable declarations in the Parrot parser.

      We need to decide whether to alter these last two cases for backwards compatibility or whether we see this as a breaking change which better aligns with the Java specification.
      I propose we opt for backwards compatibility since the above mentioned workaround would apply equally for classes with these starting characters, whereas renaming a method starting with these characters is more complicated.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 10m
                1h 10m