blob: 50a3639603a64bfaa782da16ad393b863fb9c3e3 [file] [log] [blame]
//////////////////////////////////////////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
//////////////////////////////////////////
== This is the home of the new parser Parrot, which is based on Antlr4.
The new parser(Parrot) can parse Groovy source code and construct the related AST, which is almost identical to the one generated by the old parser(except the corrected node position, e.g. line, column of node). Currently all features of Groovy are available. In addition, **the following new features have been added:**
* do-while loop, standard loop(e.g. `for(int i = 0, j = 10; i < j; i++, j--) {..}`)
* lambda expression
* method reference and constructor reference
* try-with-resources(i.e. ARM)
* code block(i.e. `{..}`)
* array initializer of Java style(e.g. `new int[] {1, 2, 3}`)
* default method of interface
* new operators: identity operators(`===`, `!==`), elvis assignment(`?=`), `!in`, `!instanceof`
* safe index(e.g. `nullableVar?[1, 2]`)
* runtime groovydoc(i.e. groovydoc with `@Groovydoc`), groovydoc attached to AST node as metadata
=== How to enable the new parser
* In the gradle build the property useAntlr4 has to be set to enable the build of the parser and the execution of all tests with it. Command line example:
```
./gradlew -PuseAntlr4=true bootstrapJar
```
* To enable the new parser automatically at runtime the system property groovy.antlr4 has to be set. Command line example:
```
export JAVA_OPTS="-Dgroovy.antlr4=true"
groovy foo.groovy
```
* This system property also controls groovyc and has to be used in case it is used outside of this build, for example with:
```
groovyOptions.forkOptions.jvmArgs += ["-Dgroovy.antlr4=true"]
```
=== JVM system properties to control parsing
* `groovy.antlr4.cache.threshold`: how frequently to clear DFA cache(default: 50). **Notice:** The more frequently the DFA cache is cleared, the poorer parsing performance will be(you can not set the value that is less than the default value). But the DFA cache has to be cleared to avoid OutOfMemoryError's occurring.
* `groovy.attach.groovydoc`: whether to attach groovydoc to node as metadata while parsing groovy source code(default: false)
* `groovy.attach.runtime.groovydoc`: whether to attach `@Groovydoc` annotation to all members which have groovydoc(i.e. `/** ... */`).
*P.S. Parrot is based on the highly optimized version of antlr4(com.tunnelvisionlabs:antlr4), which is licensed under BSD.*