From 03358d5bcfb47bd7c548d519204b90b8e9309b7a Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 23 Mar 2026 13:58:08 -0500 Subject: [PATCH 1/9] Begin splitting the Java artifact into components * The Loader API lives under java/api. * The current native endpoint for the Prism shared library lives under java/native. * The WASM build and binding lives under java/wasm. The libraries will be released together but can be developed and snapshotted independently. Users that copy the source from the previous java/ will want to grab both java/api/src/main/java and java/native/src/main/java contents. --- .github/dependabot.yml | 2 +- .github/workflows/java-wasm-bindings.yml | 6 +- .gitignore | 2 +- Makefile | 4 +- README.md | 6 +- Rakefile | 2 +- java-wasm/pom.xml | 236 - java/.gitignore | 4 + java/README.md | 25 + java/api/pom.xml | 81 + .../ruby_lang/prism/AbstractNodeVisitor.java | 1538 ++ .../main/java/org/ruby_lang/prism/Loader.java | 775 + .../ruby_lang/prism/MarkNewlinesVisitor.java | 0 .../main/java/org/ruby_lang/prism/Nodes.java | 11628 ++++++++++++++++ .../org/ruby_lang/prism/ParseResult.java | 0 .../org/ruby_lang/prism/ParsingOptions.java | 0 java/native/pom.xml | 72 + .../java}/org/ruby_lang/prism/Parser.java | 0 java/pom.xml | 157 + {java-wasm => java/wasm}/.gitignore | 0 {java-wasm => java/wasm}/README.md | 4 +- {java-wasm => java/wasm}/perf-test/.gitignore | 0 {java-wasm => java/wasm}/perf-test/bench.sh | 0 {java-wasm => java/wasm}/perf-test/test | 0 java/wasm/pom.xml | 126 + java/wasm/prism-parser.iml | 9 + .../ruby_lang/prism/wasm/WasmResource.java | 0 .../java/org/ruby_lang/prism/wasm/Prism.java | 0 .../org/jruby/parser/prism/JRubyTest.java | 0 .../java/org/jruby/parser/prism/WASMTest.java | 0 .../wasm}/src/test/resources/.gitignore | 0 rakelib/check_manifest.rake | 2 +- templates/template.rb | 6 +- 33 files changed, 14433 insertions(+), 252 deletions(-) delete mode 100644 java-wasm/pom.xml create mode 100644 java/.gitignore create mode 100644 java/README.md create mode 100644 java/api/pom.xml create mode 100644 java/api/src/main/java/org/ruby_lang/prism/AbstractNodeVisitor.java create mode 100644 java/api/src/main/java/org/ruby_lang/prism/Loader.java rename java/{ => api/src/main/java}/org/ruby_lang/prism/MarkNewlinesVisitor.java (100%) create mode 100644 java/api/src/main/java/org/ruby_lang/prism/Nodes.java rename java/{ => api/src/main/java}/org/ruby_lang/prism/ParseResult.java (100%) rename java/{ => api/src/main/java}/org/ruby_lang/prism/ParsingOptions.java (100%) create mode 100644 java/native/pom.xml rename java/{ => native/src/main/java}/org/ruby_lang/prism/Parser.java (100%) create mode 100644 java/pom.xml rename {java-wasm => java/wasm}/.gitignore (100%) rename {java-wasm => java/wasm}/README.md (88%) rename {java-wasm => java/wasm}/perf-test/.gitignore (100%) rename {java-wasm => java/wasm}/perf-test/bench.sh (100%) rename {java-wasm => java/wasm}/perf-test/test (100%) create mode 100644 java/wasm/pom.xml create mode 100644 java/wasm/prism-parser.iml rename {java-wasm => java/wasm}/src/main/java-templates/org/ruby_lang/prism/wasm/WasmResource.java (100%) rename {java-wasm => java/wasm}/src/main/java/org/ruby_lang/prism/wasm/Prism.java (100%) rename {java-wasm => java/wasm}/src/test/java/org/jruby/parser/prism/JRubyTest.java (100%) rename {java-wasm => java/wasm}/src/test/java/org/jruby/parser/prism/WASMTest.java (100%) rename {java-wasm => java/wasm}/src/test/resources/.gitignore (100%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6e302f18de..bc0a555340 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,7 +9,7 @@ updates: patterns: - "*" - package-ecosystem: 'maven' - directory: '/java-wasm' + directory: '/java/wasm' schedule: interval: 'weekly' groups: diff --git a/.github/workflows/java-wasm-bindings.yml b/.github/workflows/java-wasm-bindings.yml index e3919472c3..352c1f7b4d 100644 --- a/.github/workflows/java-wasm-bindings.yml +++ b/.github/workflows/java-wasm-bindings.yml @@ -8,7 +8,7 @@ on: - "src/" - "*akefile*" - "java/" - - "java-wasm/" + - "java/wasm/" branches: - main - ruby-4.0 @@ -46,9 +46,9 @@ jobs: - name: Run the tests run: mvn -B install - working-directory: java-wasm + working-directory: java/wasm - uses: actions/upload-artifact@v7 with: name: prism.wasm - path: java-wasm/src/test/resources/prism.wasm + path: java/wasm/src/test/resources/prism.wasm diff --git a/.gitignore b/.gitignore index 516e30de3e..fcdec6fb0a 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,7 @@ out.svg /java/org/ruby_lang/prism/AbstractNodeVisitor.java /java/org/ruby_lang/prism/Loader.java /java/org/ruby_lang/prism/Nodes.java -/java-wasm/src/test/resources/prism.wasm +/java/wasm/src/test/resources/prism.wasm /lib/prism/compiler.rb /lib/prism/dispatcher.rb /lib/prism/dot_visitor.rb diff --git a/Makefile b/Makefile index d6d07943c3..039efee72c 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ all: shared static shared: build/libprism.$(SOEXT) static: build/libprism.a wasm: javascript/src/prism.wasm -java-wasm: java-wasm/src/test/resources/prism.wasm +java-wasm: java/wasm/src/test/resources/prism.wasm build/libprism.$(SOEXT): $(SHARED_OBJECTS) $(ECHO) "linking $@ with $(CC)" @@ -51,7 +51,7 @@ javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS) -Oz -g0 -flto -fdata-sections -ffunction-sections \ -o $@ $(SOURCES) -java-wasm/src/test/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS) +java/wasm/src/test/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS) $(ECHO) "building $@" $(Q) $(MAKEDIRS) $(@D) $(Q) $(WASI_SDK_PATH)/bin/clang \ diff --git a/README.md b/README.md index 0805698d93..a4a9b6d340 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,10 @@ The repository contains the infrastructure for both a shared library (libprism) ├── include │   ├── prism header files for the shared library │   └── prism.h main header file for the shared library -├── java Java bindings for the shared library -├── java-wasm Java WASM bindings for the shared library +├── java +| ├── api Java API for Prism +| ├── native Java native bindings for the shared library +| └── wasm Java WASM bindings for the shared library ├── javascript JavaScript WASM bindings for the shared library ├── lib │   ├── prism Ruby library files diff --git a/Rakefile b/Rakefile index 80b00bd913..e6a86cdb15 100644 --- a/Rakefile +++ b/Rakefile @@ -54,7 +54,7 @@ end CLOBBER.concat(Prism::Template::TEMPLATES) CLOBBER.concat(["build"]) CLOBBER << "lib/prism/prism.#{RbConfig::CONFIG["DLEXT"]}" -CLOBBER << "java-wasm/src/main/resources/prism.wasm" +CLOBBER << "java/wasm/src/main/resources/prism.wasm" Prism::Template::TEMPLATES.each do |filepath| desc "Generate #{filepath}" diff --git a/java-wasm/pom.xml b/java-wasm/pom.xml deleted file mode 100644 index 49aae5b3f1..0000000000 --- a/java-wasm/pom.xml +++ /dev/null @@ -1,236 +0,0 @@ - - - 4.0.0 - - org.ruby-lang - prism-parser - 0.0.2-SNAPSHOT - Java Prism - Java API for the Prism Ruby language parser - https://github.com/ruby/prism - - - - MIT - - - - - - Kevin Newton - kddnewton@gmail.com - - - Benoit Daloze - eregontp@gmail.com - - - Charles Oliver Nutter - headius@headius.com - - - Thomas E Enebo - tom.enebo@gmail.com - - - - - https://github.com/ruby/prism - https://github.com/ruby/prism.git - - - - UTF-8 - UTF-8 - 21 - 21 - - 1.7.3 - 6.0.3 - - - - - - com.dylibso.chicory - bom - ${chicory.version} - pom - import - - - - - - - com.dylibso.chicory - runtime - - - com.dylibso.chicory - log - - - com.dylibso.chicory - wasi - - - com.dylibso.chicory - wasm - - - org.junit.jupiter - junit-jupiter-engine - ${junit.version} - test - - - com.dylibso.chicory - annotations - provided - - - org.jruby - jruby-complete - 10.0.4.0 - test - - - - - - release - - - - maven-source-plugin - - - attach-sources - - jar-no-fork - - - - - - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - none - - - - maven-gpg-plugin - 3.2.8 - - - sign-artifacts - verify - - sign - - - - - - --pinentry-mode - loopback - - - - - - - - - - - - org.codehaus.mojo - templating-maven-plugin - 3.1.0 - - - filtering-java-templates - - filter-sources - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.15.0 - - 21 - - - com.dylibso.chicory - annotations-processor - ${chicory.version} - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.5.5 - - - org.codehaus.mojo - build-helper-maven-plugin - 3.6.1 - - - generate-sources - - add-source - - - - ../java - - - - - - - com.dylibso.chicory - chicory-compiler-maven-plugin - ${chicory.version} - - - prism - - compile - - - org.ruby_lang.prism.wasm.PrismParser - src/test/resources/prism.wasm - - - - - - org.sonatype.central - central-publishing-maven-plugin - 0.10.0 - true - - central - - - - - - diff --git a/java/.gitignore b/java/.gitignore new file mode 100644 index 0000000000..a88111250b --- /dev/null +++ b/java/.gitignore @@ -0,0 +1,4 @@ +api/target +native/target +wasm/target +.idea diff --git a/java/README.md b/java/README.md new file mode 100644 index 0000000000..b3062cebd2 --- /dev/null +++ b/java/README.md @@ -0,0 +1,25 @@ +# Prism Java API and bindings + +This is the top-level project for the Java API and backend bindings for the Prism Ruby language parser. + +* api/ contains the API +* native/ contains a native binding for the Prism shared library +* wasm/ contains a Chicory-based WASM build and binding + +## Updating versions + +Run the following command to update all module versions: + +``` +mvn versions:set -DnewVersion=1.2.3-SNAPSHOT +``` + +## Releasing + +Snapshots can be deployed with `mvn deploy` while the versions are `-SNAPSHOT`. + +When releasing to Maven Central, all projects should be released together using the `release` profile: + +``` +mvn clean deploy -Prelease +``` diff --git a/java/api/pom.xml b/java/api/pom.xml new file mode 100644 index 0000000000..6b3bd6d3a8 --- /dev/null +++ b/java/api/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + + + org.ruby-lang + prism-parser + 0.0.2-SNAPSHOT + + + prism-parser-api + Java Prism + Java API for the Prism Ruby language parser + https://github.com/ruby/prism + + + + org.ruby-lang + prism-parser-native + 0.0.2-SNAPSHOT + provided + + + + + + + org.codehaus.mojo + templating-maven-plugin + 3.1.0 + + + filtering-java-templates + + filter-sources + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.15.0 + + 21 + + + com.dylibso.chicory + annotations-processor + ${chicory.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.5 + + + org.codehaus.mojo + build-helper-maven-plugin + 3.6.1 + + + generate-sources + + add-source + + + + ../java + + + + + + + + + diff --git a/java/api/src/main/java/org/ruby_lang/prism/AbstractNodeVisitor.java b/java/api/src/main/java/org/ruby_lang/prism/AbstractNodeVisitor.java new file mode 100644 index 0000000000..9c76b38d8e --- /dev/null +++ b/java/api/src/main/java/org/ruby_lang/prism/AbstractNodeVisitor.java @@ -0,0 +1,1538 @@ +/*----------------------------------------------------------------------------*/ +/* This file is generated by the templates/template.rb script and should not */ +/* be modified manually. See */ +/* templates/java/org/ruby_lang/prism/AbstractNodeVisitor.java.erb */ +/* if you are looking to modify the */ +/* template */ +/*----------------------------------------------------------------------------*/ + +package org.ruby_lang.prism; + +// GENERATED BY AbstractNodeVisitor.java.erb +// @formatter:off +public abstract class AbstractNodeVisitor { + + protected abstract T defaultVisit(Nodes.Node node); + + /** + * Visit a AliasGlobalVariableNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitAliasGlobalVariableNode(Nodes.AliasGlobalVariableNode node) { + return defaultVisit(node); + } + + /** + * Visit a AliasMethodNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitAliasMethodNode(Nodes.AliasMethodNode node) { + return defaultVisit(node); + } + + /** + * Visit a AlternationPatternNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitAlternationPatternNode(Nodes.AlternationPatternNode node) { + return defaultVisit(node); + } + + /** + * Visit a AndNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitAndNode(Nodes.AndNode node) { + return defaultVisit(node); + } + + /** + * Visit a ArgumentsNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitArgumentsNode(Nodes.ArgumentsNode node) { + return defaultVisit(node); + } + + /** + * Visit a ArrayNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitArrayNode(Nodes.ArrayNode node) { + return defaultVisit(node); + } + + /** + * Visit a ArrayPatternNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitArrayPatternNode(Nodes.ArrayPatternNode node) { + return defaultVisit(node); + } + + /** + * Visit a AssocNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitAssocNode(Nodes.AssocNode node) { + return defaultVisit(node); + } + + /** + * Visit a AssocSplatNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitAssocSplatNode(Nodes.AssocSplatNode node) { + return defaultVisit(node); + } + + /** + * Visit a BackReferenceReadNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitBackReferenceReadNode(Nodes.BackReferenceReadNode node) { + return defaultVisit(node); + } + + /** + * Visit a BeginNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitBeginNode(Nodes.BeginNode node) { + return defaultVisit(node); + } + + /** + * Visit a BlockArgumentNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitBlockArgumentNode(Nodes.BlockArgumentNode node) { + return defaultVisit(node); + } + + /** + * Visit a BlockLocalVariableNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitBlockLocalVariableNode(Nodes.BlockLocalVariableNode node) { + return defaultVisit(node); + } + + /** + * Visit a BlockNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitBlockNode(Nodes.BlockNode node) { + return defaultVisit(node); + } + + /** + * Visit a BlockParameterNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitBlockParameterNode(Nodes.BlockParameterNode node) { + return defaultVisit(node); + } + + /** + * Visit a BlockParametersNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitBlockParametersNode(Nodes.BlockParametersNode node) { + return defaultVisit(node); + } + + /** + * Visit a BreakNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitBreakNode(Nodes.BreakNode node) { + return defaultVisit(node); + } + + /** + * Visit a CallAndWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitCallAndWriteNode(Nodes.CallAndWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a CallNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitCallNode(Nodes.CallNode node) { + return defaultVisit(node); + } + + /** + * Visit a CallOperatorWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitCallOperatorWriteNode(Nodes.CallOperatorWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a CallOrWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitCallOrWriteNode(Nodes.CallOrWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a CallTargetNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitCallTargetNode(Nodes.CallTargetNode node) { + return defaultVisit(node); + } + + /** + * Visit a CapturePatternNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitCapturePatternNode(Nodes.CapturePatternNode node) { + return defaultVisit(node); + } + + /** + * Visit a CaseMatchNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitCaseMatchNode(Nodes.CaseMatchNode node) { + return defaultVisit(node); + } + + /** + * Visit a CaseNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitCaseNode(Nodes.CaseNode node) { + return defaultVisit(node); + } + + /** + * Visit a ClassNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitClassNode(Nodes.ClassNode node) { + return defaultVisit(node); + } + + /** + * Visit a ClassVariableAndWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitClassVariableAndWriteNode(Nodes.ClassVariableAndWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a ClassVariableOperatorWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitClassVariableOperatorWriteNode(Nodes.ClassVariableOperatorWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a ClassVariableOrWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitClassVariableOrWriteNode(Nodes.ClassVariableOrWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a ClassVariableReadNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitClassVariableReadNode(Nodes.ClassVariableReadNode node) { + return defaultVisit(node); + } + + /** + * Visit a ClassVariableTargetNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitClassVariableTargetNode(Nodes.ClassVariableTargetNode node) { + return defaultVisit(node); + } + + /** + * Visit a ClassVariableWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitClassVariableWriteNode(Nodes.ClassVariableWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantAndWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantAndWriteNode(Nodes.ConstantAndWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantOperatorWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantOperatorWriteNode(Nodes.ConstantOperatorWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantOrWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantOrWriteNode(Nodes.ConstantOrWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantPathAndWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantPathAndWriteNode(Nodes.ConstantPathAndWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantPathNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantPathNode(Nodes.ConstantPathNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantPathOperatorWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantPathOperatorWriteNode(Nodes.ConstantPathOperatorWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantPathOrWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantPathOrWriteNode(Nodes.ConstantPathOrWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantPathTargetNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantPathTargetNode(Nodes.ConstantPathTargetNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantPathWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantPathWriteNode(Nodes.ConstantPathWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantReadNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantReadNode(Nodes.ConstantReadNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantTargetNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantTargetNode(Nodes.ConstantTargetNode node) { + return defaultVisit(node); + } + + /** + * Visit a ConstantWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitConstantWriteNode(Nodes.ConstantWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a DefNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitDefNode(Nodes.DefNode node) { + return defaultVisit(node); + } + + /** + * Visit a DefinedNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitDefinedNode(Nodes.DefinedNode node) { + return defaultVisit(node); + } + + /** + * Visit a ElseNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitElseNode(Nodes.ElseNode node) { + return defaultVisit(node); + } + + /** + * Visit a EmbeddedStatementsNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitEmbeddedStatementsNode(Nodes.EmbeddedStatementsNode node) { + return defaultVisit(node); + } + + /** + * Visit a EmbeddedVariableNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitEmbeddedVariableNode(Nodes.EmbeddedVariableNode node) { + return defaultVisit(node); + } + + /** + * Visit a EnsureNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitEnsureNode(Nodes.EnsureNode node) { + return defaultVisit(node); + } + + /** + * Visit a FalseNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitFalseNode(Nodes.FalseNode node) { + return defaultVisit(node); + } + + /** + * Visit a FindPatternNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitFindPatternNode(Nodes.FindPatternNode node) { + return defaultVisit(node); + } + + /** + * Visit a FlipFlopNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitFlipFlopNode(Nodes.FlipFlopNode node) { + return defaultVisit(node); + } + + /** + * Visit a FloatNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitFloatNode(Nodes.FloatNode node) { + return defaultVisit(node); + } + + /** + * Visit a ForNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitForNode(Nodes.ForNode node) { + return defaultVisit(node); + } + + /** + * Visit a ForwardingArgumentsNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitForwardingArgumentsNode(Nodes.ForwardingArgumentsNode node) { + return defaultVisit(node); + } + + /** + * Visit a ForwardingParameterNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitForwardingParameterNode(Nodes.ForwardingParameterNode node) { + return defaultVisit(node); + } + + /** + * Visit a ForwardingSuperNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitForwardingSuperNode(Nodes.ForwardingSuperNode node) { + return defaultVisit(node); + } + + /** + * Visit a GlobalVariableAndWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitGlobalVariableAndWriteNode(Nodes.GlobalVariableAndWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a GlobalVariableOperatorWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitGlobalVariableOperatorWriteNode(Nodes.GlobalVariableOperatorWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a GlobalVariableOrWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitGlobalVariableOrWriteNode(Nodes.GlobalVariableOrWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a GlobalVariableReadNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitGlobalVariableReadNode(Nodes.GlobalVariableReadNode node) { + return defaultVisit(node); + } + + /** + * Visit a GlobalVariableTargetNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitGlobalVariableTargetNode(Nodes.GlobalVariableTargetNode node) { + return defaultVisit(node); + } + + /** + * Visit a GlobalVariableWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitGlobalVariableWriteNode(Nodes.GlobalVariableWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a HashNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitHashNode(Nodes.HashNode node) { + return defaultVisit(node); + } + + /** + * Visit a HashPatternNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitHashPatternNode(Nodes.HashPatternNode node) { + return defaultVisit(node); + } + + /** + * Visit a IfNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitIfNode(Nodes.IfNode node) { + return defaultVisit(node); + } + + /** + * Visit a ImaginaryNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitImaginaryNode(Nodes.ImaginaryNode node) { + return defaultVisit(node); + } + + /** + * Visit a ImplicitNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitImplicitNode(Nodes.ImplicitNode node) { + return defaultVisit(node); + } + + /** + * Visit a ImplicitRestNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitImplicitRestNode(Nodes.ImplicitRestNode node) { + return defaultVisit(node); + } + + /** + * Visit a InNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInNode(Nodes.InNode node) { + return defaultVisit(node); + } + + /** + * Visit a IndexAndWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitIndexAndWriteNode(Nodes.IndexAndWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a IndexOperatorWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitIndexOperatorWriteNode(Nodes.IndexOperatorWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a IndexOrWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitIndexOrWriteNode(Nodes.IndexOrWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a IndexTargetNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitIndexTargetNode(Nodes.IndexTargetNode node) { + return defaultVisit(node); + } + + /** + * Visit a InstanceVariableAndWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInstanceVariableAndWriteNode(Nodes.InstanceVariableAndWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a InstanceVariableOperatorWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInstanceVariableOperatorWriteNode(Nodes.InstanceVariableOperatorWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a InstanceVariableOrWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInstanceVariableOrWriteNode(Nodes.InstanceVariableOrWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a InstanceVariableReadNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInstanceVariableReadNode(Nodes.InstanceVariableReadNode node) { + return defaultVisit(node); + } + + /** + * Visit a InstanceVariableTargetNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInstanceVariableTargetNode(Nodes.InstanceVariableTargetNode node) { + return defaultVisit(node); + } + + /** + * Visit a InstanceVariableWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInstanceVariableWriteNode(Nodes.InstanceVariableWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a IntegerNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitIntegerNode(Nodes.IntegerNode node) { + return defaultVisit(node); + } + + /** + * Visit a InterpolatedMatchLastLineNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInterpolatedMatchLastLineNode(Nodes.InterpolatedMatchLastLineNode node) { + return defaultVisit(node); + } + + /** + * Visit a InterpolatedRegularExpressionNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInterpolatedRegularExpressionNode(Nodes.InterpolatedRegularExpressionNode node) { + return defaultVisit(node); + } + + /** + * Visit a InterpolatedStringNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInterpolatedStringNode(Nodes.InterpolatedStringNode node) { + return defaultVisit(node); + } + + /** + * Visit a InterpolatedSymbolNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInterpolatedSymbolNode(Nodes.InterpolatedSymbolNode node) { + return defaultVisit(node); + } + + /** + * Visit a InterpolatedXStringNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitInterpolatedXStringNode(Nodes.InterpolatedXStringNode node) { + return defaultVisit(node); + } + + /** + * Visit a ItLocalVariableReadNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitItLocalVariableReadNode(Nodes.ItLocalVariableReadNode node) { + return defaultVisit(node); + } + + /** + * Visit a ItParametersNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitItParametersNode(Nodes.ItParametersNode node) { + return defaultVisit(node); + } + + /** + * Visit a KeywordHashNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitKeywordHashNode(Nodes.KeywordHashNode node) { + return defaultVisit(node); + } + + /** + * Visit a KeywordRestParameterNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitKeywordRestParameterNode(Nodes.KeywordRestParameterNode node) { + return defaultVisit(node); + } + + /** + * Visit a LambdaNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitLambdaNode(Nodes.LambdaNode node) { + return defaultVisit(node); + } + + /** + * Visit a LocalVariableAndWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitLocalVariableAndWriteNode(Nodes.LocalVariableAndWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a LocalVariableOperatorWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitLocalVariableOperatorWriteNode(Nodes.LocalVariableOperatorWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a LocalVariableOrWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitLocalVariableOrWriteNode(Nodes.LocalVariableOrWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a LocalVariableReadNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitLocalVariableReadNode(Nodes.LocalVariableReadNode node) { + return defaultVisit(node); + } + + /** + * Visit a LocalVariableTargetNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitLocalVariableTargetNode(Nodes.LocalVariableTargetNode node) { + return defaultVisit(node); + } + + /** + * Visit a LocalVariableWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitLocalVariableWriteNode(Nodes.LocalVariableWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a MatchLastLineNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitMatchLastLineNode(Nodes.MatchLastLineNode node) { + return defaultVisit(node); + } + + /** + * Visit a MatchPredicateNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitMatchPredicateNode(Nodes.MatchPredicateNode node) { + return defaultVisit(node); + } + + /** + * Visit a MatchRequiredNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitMatchRequiredNode(Nodes.MatchRequiredNode node) { + return defaultVisit(node); + } + + /** + * Visit a MatchWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitMatchWriteNode(Nodes.MatchWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a MissingNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitMissingNode(Nodes.MissingNode node) { + return defaultVisit(node); + } + + /** + * Visit a ModuleNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitModuleNode(Nodes.ModuleNode node) { + return defaultVisit(node); + } + + /** + * Visit a MultiTargetNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitMultiTargetNode(Nodes.MultiTargetNode node) { + return defaultVisit(node); + } + + /** + * Visit a MultiWriteNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitMultiWriteNode(Nodes.MultiWriteNode node) { + return defaultVisit(node); + } + + /** + * Visit a NextNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitNextNode(Nodes.NextNode node) { + return defaultVisit(node); + } + + /** + * Visit a NilNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitNilNode(Nodes.NilNode node) { + return defaultVisit(node); + } + + /** + * Visit a NoBlockParameterNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitNoBlockParameterNode(Nodes.NoBlockParameterNode node) { + return defaultVisit(node); + } + + /** + * Visit a NoKeywordsParameterNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitNoKeywordsParameterNode(Nodes.NoKeywordsParameterNode node) { + return defaultVisit(node); + } + + /** + * Visit a NumberedParametersNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitNumberedParametersNode(Nodes.NumberedParametersNode node) { + return defaultVisit(node); + } + + /** + * Visit a NumberedReferenceReadNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitNumberedReferenceReadNode(Nodes.NumberedReferenceReadNode node) { + return defaultVisit(node); + } + + /** + * Visit a OptionalKeywordParameterNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitOptionalKeywordParameterNode(Nodes.OptionalKeywordParameterNode node) { + return defaultVisit(node); + } + + /** + * Visit a OptionalParameterNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitOptionalParameterNode(Nodes.OptionalParameterNode node) { + return defaultVisit(node); + } + + /** + * Visit a OrNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitOrNode(Nodes.OrNode node) { + return defaultVisit(node); + } + + /** + * Visit a ParametersNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitParametersNode(Nodes.ParametersNode node) { + return defaultVisit(node); + } + + /** + * Visit a ParenthesesNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitParenthesesNode(Nodes.ParenthesesNode node) { + return defaultVisit(node); + } + + /** + * Visit a PinnedExpressionNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitPinnedExpressionNode(Nodes.PinnedExpressionNode node) { + return defaultVisit(node); + } + + /** + * Visit a PinnedVariableNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitPinnedVariableNode(Nodes.PinnedVariableNode node) { + return defaultVisit(node); + } + + /** + * Visit a PostExecutionNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitPostExecutionNode(Nodes.PostExecutionNode node) { + return defaultVisit(node); + } + + /** + * Visit a PreExecutionNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitPreExecutionNode(Nodes.PreExecutionNode node) { + return defaultVisit(node); + } + + /** + * Visit a ProgramNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitProgramNode(Nodes.ProgramNode node) { + return defaultVisit(node); + } + + /** + * Visit a RangeNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitRangeNode(Nodes.RangeNode node) { + return defaultVisit(node); + } + + /** + * Visit a RationalNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitRationalNode(Nodes.RationalNode node) { + return defaultVisit(node); + } + + /** + * Visit a RedoNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitRedoNode(Nodes.RedoNode node) { + return defaultVisit(node); + } + + /** + * Visit a RegularExpressionNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitRegularExpressionNode(Nodes.RegularExpressionNode node) { + return defaultVisit(node); + } + + /** + * Visit a RequiredKeywordParameterNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitRequiredKeywordParameterNode(Nodes.RequiredKeywordParameterNode node) { + return defaultVisit(node); + } + + /** + * Visit a RequiredParameterNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitRequiredParameterNode(Nodes.RequiredParameterNode node) { + return defaultVisit(node); + } + + /** + * Visit a RescueModifierNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitRescueModifierNode(Nodes.RescueModifierNode node) { + return defaultVisit(node); + } + + /** + * Visit a RescueNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitRescueNode(Nodes.RescueNode node) { + return defaultVisit(node); + } + + /** + * Visit a RestParameterNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitRestParameterNode(Nodes.RestParameterNode node) { + return defaultVisit(node); + } + + /** + * Visit a RetryNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitRetryNode(Nodes.RetryNode node) { + return defaultVisit(node); + } + + /** + * Visit a ReturnNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitReturnNode(Nodes.ReturnNode node) { + return defaultVisit(node); + } + + /** + * Visit a SelfNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitSelfNode(Nodes.SelfNode node) { + return defaultVisit(node); + } + + /** + * Visit a ShareableConstantNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitShareableConstantNode(Nodes.ShareableConstantNode node) { + return defaultVisit(node); + } + + /** + * Visit a SingletonClassNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitSingletonClassNode(Nodes.SingletonClassNode node) { + return defaultVisit(node); + } + + /** + * Visit a SourceEncodingNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitSourceEncodingNode(Nodes.SourceEncodingNode node) { + return defaultVisit(node); + } + + /** + * Visit a SourceFileNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitSourceFileNode(Nodes.SourceFileNode node) { + return defaultVisit(node); + } + + /** + * Visit a SourceLineNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitSourceLineNode(Nodes.SourceLineNode node) { + return defaultVisit(node); + } + + /** + * Visit a SplatNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitSplatNode(Nodes.SplatNode node) { + return defaultVisit(node); + } + + /** + * Visit a StatementsNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitStatementsNode(Nodes.StatementsNode node) { + return defaultVisit(node); + } + + /** + * Visit a StringNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitStringNode(Nodes.StringNode node) { + return defaultVisit(node); + } + + /** + * Visit a SuperNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitSuperNode(Nodes.SuperNode node) { + return defaultVisit(node); + } + + /** + * Visit a SymbolNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitSymbolNode(Nodes.SymbolNode node) { + return defaultVisit(node); + } + + /** + * Visit a TrueNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitTrueNode(Nodes.TrueNode node) { + return defaultVisit(node); + } + + /** + * Visit a UndefNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitUndefNode(Nodes.UndefNode node) { + return defaultVisit(node); + } + + /** + * Visit a UnlessNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitUnlessNode(Nodes.UnlessNode node) { + return defaultVisit(node); + } + + /** + * Visit a UntilNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitUntilNode(Nodes.UntilNode node) { + return defaultVisit(node); + } + + /** + * Visit a WhenNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitWhenNode(Nodes.WhenNode node) { + return defaultVisit(node); + } + + /** + * Visit a WhileNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitWhileNode(Nodes.WhileNode node) { + return defaultVisit(node); + } + + /** + * Visit a XStringNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitXStringNode(Nodes.XStringNode node) { + return defaultVisit(node); + } + + /** + * Visit a YieldNode node. + * + * @param node The node to visit. + * @return The result of visiting the node. + */ + public T visitYieldNode(Nodes.YieldNode node) { + return defaultVisit(node); + } + +} +// @formatter:on diff --git a/java/api/src/main/java/org/ruby_lang/prism/Loader.java b/java/api/src/main/java/org/ruby_lang/prism/Loader.java new file mode 100644 index 0000000000..f084d169ad --- /dev/null +++ b/java/api/src/main/java/org/ruby_lang/prism/Loader.java @@ -0,0 +1,775 @@ +/*----------------------------------------------------------------------------*/ +/* This file is generated by the templates/template.rb script and should not */ +/* be modified manually. See */ +/* templates/java/org/ruby_lang/prism/Loader.java.erb */ +/* if you are looking to modify the */ +/* template */ +/*----------------------------------------------------------------------------*/ + +package org.ruby_lang.prism; + +import java.lang.Short; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.Locale; + +// GENERATED BY Loader.java.erb +// @formatter:off +public class Loader { + + public static ParseResult load(byte[] serialized) { + return new Loader(serialized).load(); + } + + // Overridable methods + + public byte[] bytesToName(byte[] bytes) { + return bytes; + } + + private static final class ConstantPool { + + private final Loader loader; + private final int bufferOffset; + private final byte[][] cache; + + ConstantPool(Loader loader, int bufferOffset, int length) { + this.loader = loader; + this.bufferOffset = bufferOffset; + cache = new byte[length][]; + } + + byte[] get(ByteBuffer buffer, int oneBasedIndex) { + int index = oneBasedIndex - 1; + byte[] constant = cache[index]; + + if (constant == null) { + int offset = bufferOffset + index * 8; + int start = buffer.getInt(offset); + int length = buffer.getInt(offset + 4); + + byte[] bytes = new byte[length]; + buffer.get(start, bytes); + + constant = loader.bytesToName(bytes); + cache[index] = constant; + } + + return constant; + } + + } + + private final ByteBuffer buffer; + protected String encodingName; + private ConstantPool constantPool; + private Nodes.Source source = null; + + protected Loader(byte[] serialized) { + this.buffer = ByteBuffer.wrap(serialized).order(ByteOrder.nativeOrder()); + } + + protected ParseResult load() { + this.source = new Nodes.Source(); + + expect((byte) 'P', "incorrect prism header"); + expect((byte) 'R', "incorrect prism header"); + expect((byte) 'I', "incorrect prism header"); + expect((byte) 'S', "incorrect prism header"); + expect((byte) 'M', "incorrect prism header"); + + expect((byte) 1, "prism major version does not match"); + expect((byte) 9, "prism minor version does not match"); + expect((byte) 0, "prism patch version does not match"); + + expect((byte) 1, "Loader.java requires no location fields in the serialized output"); + + // This loads the name of the encoding. + int encodingLength = loadVarUInt(); + byte[] encodingNameBytes = new byte[encodingLength]; + buffer.get(encodingNameBytes); + this.encodingName = new String(encodingNameBytes, StandardCharsets.US_ASCII); + + source.setStartLine(loadVarSInt()); + source.setLineOffsets(loadLineOffsets()); + + ParseResult.MagicComment[] magicComments = loadMagicComments(); + Nodes.Location dataLocation = loadOptionalLocation(); + ParseResult.Error[] errors = loadErrors(); + ParseResult.Warning[] warnings = loadWarnings(); + boolean continuable = buffer.get() != 0; + + int constantPoolBufferOffset = buffer.getInt(); + int constantPoolLength = loadVarUInt(); + this.constantPool = new ConstantPool(this, constantPoolBufferOffset, constantPoolLength); + + Nodes.Node node; + if (errors.length == 0) { + node = loadNode(); + + int left = constantPoolBufferOffset - buffer.position(); + if (left != 0) { + throw new Error("Expected to consume all bytes while deserializing but there were " + left + " bytes left"); + } + + MarkNewlinesVisitor visitor = new MarkNewlinesVisitor(source); + node.accept(visitor); + } else { + node = null; + } + + return new ParseResult(node, magicComments, dataLocation, errors, warnings, continuable, source); + } + + private byte[] loadString() { + int length = loadVarUInt(); + byte[] bytes = new byte[length]; + buffer.get(bytes); + return bytes; + } + + private int[] loadLineOffsets() { + int count = loadVarUInt(); + int[] lineOffsets = new int[count]; + for (int i = 0; i < count; i++) { + lineOffsets[i] = loadVarUInt(); + } + return lineOffsets; + } + + private ParseResult.MagicComment[] loadMagicComments() { + int count = loadVarUInt(); + ParseResult.MagicComment[] magicComments = new ParseResult.MagicComment[count]; + + for (int i = 0; i < count; i++) { + Nodes.Location keyLocation = loadLocation(); + Nodes.Location valueLocation = loadLocation(); + + ParseResult.MagicComment magicComment = new ParseResult.MagicComment(keyLocation, valueLocation); + magicComments[i] = magicComment; + } + + return magicComments; + } + + private ParseResult.Error[] loadErrors() { + int count = loadVarUInt(); + ParseResult.Error[] errors = new ParseResult.Error[count]; + + // error messages only contain ASCII characters + for (int i = 0; i < count; i++) { + Nodes.ErrorType type = Nodes.ERROR_TYPES[loadVarUInt()]; + byte[] bytes = loadString(); + String message = new String(bytes, StandardCharsets.US_ASCII); + Nodes.Location location = loadLocation(); + ParseResult.ErrorLevel level = ParseResult.ERROR_LEVELS[buffer.get()]; + + ParseResult.Error error = new ParseResult.Error(type, message, location, level); + errors[i] = error; + } + + return errors; + } + + private ParseResult.Warning[] loadWarnings() { + int count = loadVarUInt(); + ParseResult.Warning[] warnings = new ParseResult.Warning[count]; + + // warning messages only contain ASCII characters + for (int i = 0; i < count; i++) { + Nodes.WarningType type = Nodes.WARNING_TYPES[loadVarUInt() - 299]; + byte[] bytes = loadString(); + String message = new String(bytes, StandardCharsets.US_ASCII); + Nodes.Location location = loadLocation(); + ParseResult.WarningLevel level = ParseResult.WARNING_LEVELS[buffer.get()]; + + ParseResult.Warning warning = new ParseResult.Warning(type, message, location, level); + warnings[i] = warning; + } + + return warnings; + } + + private Nodes.Node loadOptionalNode() { + if (buffer.get(buffer.position()) != 0) { + return loadNode(); + } else { + buffer.position(buffer.position() + 1); // continue after the 0 byte + return null; + } + } + + private byte[] loadConstant() { + return constantPool.get(buffer, loadVarUInt()); + } + + private byte[] loadOptionalConstant() { + if (buffer.get(buffer.position()) != 0) { + return loadConstant(); + } else { + buffer.position(buffer.position() + 1); // continue after the 0 byte + return null; + } + } + + private byte[][] loadConstants() { + int length = loadVarUInt(); + if (length == 0) { + return Nodes.EMPTY_IDENTIFIER_ARRAY; + } + byte[][] constants = new byte[length][]; + for (int i = 0; i < length; i++) { + constants[i] = constantPool.get(buffer, loadVarUInt()); + } + return constants; + } + + private Nodes.Location loadLocation() { + return new Nodes.Location(loadVarUInt(), loadVarUInt()); + } + + private Nodes.Location loadOptionalLocation() { + if (buffer.get() != 0) { + return loadLocation(); + } else { + return null; + } + } + + // From https://github.com/protocolbuffers/protobuf/blob/v23.1/java/core/src/main/java/com/google/protobuf/BinaryReader.java#L1507 + private int loadVarUInt() { + int x; + if ((x = buffer.get()) >= 0) { + return x; + } else if ((x ^= (buffer.get() << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (buffer.get() << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (buffer.get() << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + x ^= buffer.get() << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + } + return x; + } + + // From https://github.com/protocolbuffers/protobuf/blob/v25.1/java/core/src/main/java/com/google/protobuf/CodedInputStream.java#L508-L510 + private int loadVarSInt() { + int x = loadVarUInt(); + return (x >>> 1) ^ (-(x & 1)); + } + + private short loadFlags() { + int flags = loadVarUInt(); + assert flags >= 0 && flags <= Short.MAX_VALUE; + return (short) flags; + } + + private static final BigInteger UNSIGNED_LONG_MASK = BigInteger.ONE.shiftLeft(Long.SIZE).subtract(BigInteger.ONE); + + private Object loadInteger() { + boolean negative = buffer.get() != 0; + + int wordsLength = loadVarUInt(); + assert wordsLength > 0; + + // Load the first word. If it's the only word, then return an int if it + // fits into one and a long otherwise. + int firstWord = loadVarUInt(); + if (wordsLength == 1) { + if (firstWord < 0) { + if (negative && firstWord == Integer.MIN_VALUE) { + return Integer.MIN_VALUE; + } + + long words = Integer.toUnsignedLong(firstWord); + return negative ? -words : words; + } + return negative ? -firstWord : firstWord; + } + + // Load the second word. If there are only two words, then return a long + // if it fits into one and a BigInteger otherwise. + int secondWord = loadVarUInt(); + if (wordsLength == 2) { + long words = (((long) secondWord) << 32L) | Integer.toUnsignedLong(firstWord); + if (words < 0L) { + if (negative && words == Long.MIN_VALUE) { + return Long.MIN_VALUE; + } + + BigInteger result = BigInteger.valueOf(words).and(UNSIGNED_LONG_MASK); + return negative ? result.negate() : result; + } + return negative ? -words : words; + } + + // Otherwise, load the remaining words and return a BigInt. + BigInteger result = BigInteger.valueOf(Integer.toUnsignedLong(firstWord)); + result = result.or(BigInteger.valueOf(Integer.toUnsignedLong(secondWord)).shiftLeft(32)); + + for (int wordsIndex = 2; wordsIndex < wordsLength; wordsIndex++) { + result = result.or(BigInteger.valueOf(Integer.toUnsignedLong(loadVarUInt())).shiftLeft(wordsIndex * 32)); + } + + return negative ? result.negate() : result; + } + + private Nodes.Node loadNode() { + int type = buffer.get() & 0xFF; + int startOffset = loadVarUInt(); + int length = loadVarUInt(); + + switch (type) { + case 1: + return new Nodes.AliasGlobalVariableNode(startOffset, length, loadNode(), loadNode()); + case 2: + return new Nodes.AliasMethodNode(startOffset, length, loadNode(), loadNode()); + case 3: + return new Nodes.AlternationPatternNode(startOffset, length, loadNode(), loadNode()); + case 4: + return new Nodes.AndNode(startOffset, length, loadNode(), loadNode()); + case 5: + return new Nodes.ArgumentsNode(startOffset, length, loadFlags(), loadNodes()); + case 6: + return new Nodes.ArrayNode(startOffset, length, loadFlags(), loadNodes()); + case 7: + return new Nodes.ArrayPatternNode(startOffset, length, loadOptionalNode(), loadNodes(), loadOptionalNode(), loadNodes()); + case 8: + return new Nodes.AssocNode(startOffset, length, loadNode(), loadNode()); + case 9: + return new Nodes.AssocSplatNode(startOffset, length, loadOptionalNode()); + case 10: + return new Nodes.BackReferenceReadNode(startOffset, length, loadConstant()); + case 11: + return new Nodes.BeginNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode(), (Nodes.RescueNode) loadOptionalNode(), (Nodes.ElseNode) loadOptionalNode(), (Nodes.EnsureNode) loadOptionalNode()); + case 12: + return new Nodes.BlockArgumentNode(startOffset, length, loadOptionalNode()); + case 13: + return new Nodes.BlockLocalVariableNode(startOffset, length, loadFlags(), loadConstant()); + case 14: + return new Nodes.BlockNode(startOffset, length, loadConstants(), loadOptionalNode(), loadOptionalNode()); + case 15: + return new Nodes.BlockParameterNode(startOffset, length, loadFlags(), loadOptionalConstant()); + case 16: + return new Nodes.BlockParametersNode(startOffset, length, (Nodes.ParametersNode) loadOptionalNode(), loadBlockLocalVariableNodes()); + case 17: + return new Nodes.BreakNode(startOffset, length, (Nodes.ArgumentsNode) loadOptionalNode()); + case 18: + return new Nodes.CallAndWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), loadConstant(), loadConstant(), loadNode()); + case 19: + return new Nodes.CallNode(startOffset, length, loadFlags(), loadOptionalNode(), loadConstant(), (Nodes.ArgumentsNode) loadOptionalNode(), loadOptionalNode()); + case 20: + return new Nodes.CallOperatorWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), loadConstant(), loadConstant(), loadConstant(), loadNode()); + case 21: + return new Nodes.CallOrWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), loadConstant(), loadConstant(), loadNode()); + case 22: + return new Nodes.CallTargetNode(startOffset, length, loadFlags(), loadNode(), loadConstant()); + case 23: + return new Nodes.CapturePatternNode(startOffset, length, loadNode(), (Nodes.LocalVariableTargetNode) loadNode()); + case 24: + return new Nodes.CaseMatchNode(startOffset, length, loadOptionalNode(), loadInNodes(), (Nodes.ElseNode) loadOptionalNode()); + case 25: + return new Nodes.CaseNode(startOffset, length, loadOptionalNode(), loadWhenNodes(), (Nodes.ElseNode) loadOptionalNode()); + case 26: + return new Nodes.ClassNode(startOffset, length, loadConstants(), loadNode(), loadOptionalNode(), loadOptionalNode(), loadConstant()); + case 27: + return new Nodes.ClassVariableAndWriteNode(startOffset, length, loadConstant(), loadNode()); + case 28: + return new Nodes.ClassVariableOperatorWriteNode(startOffset, length, loadConstant(), loadNode(), loadConstant()); + case 29: + return new Nodes.ClassVariableOrWriteNode(startOffset, length, loadConstant(), loadNode()); + case 30: + return new Nodes.ClassVariableReadNode(startOffset, length, loadConstant()); + case 31: + return new Nodes.ClassVariableTargetNode(startOffset, length, loadConstant()); + case 32: + return new Nodes.ClassVariableWriteNode(startOffset, length, loadConstant(), loadNode()); + case 33: + return new Nodes.ConstantAndWriteNode(startOffset, length, loadConstant(), loadNode()); + case 34: + return new Nodes.ConstantOperatorWriteNode(startOffset, length, loadConstant(), loadNode(), loadConstant()); + case 35: + return new Nodes.ConstantOrWriteNode(startOffset, length, loadConstant(), loadNode()); + case 36: + return new Nodes.ConstantPathAndWriteNode(startOffset, length, (Nodes.ConstantPathNode) loadNode(), loadNode()); + case 37: + return new Nodes.ConstantPathNode(startOffset, length, loadOptionalNode(), loadOptionalConstant()); + case 38: + return new Nodes.ConstantPathOperatorWriteNode(startOffset, length, (Nodes.ConstantPathNode) loadNode(), loadNode(), loadConstant()); + case 39: + return new Nodes.ConstantPathOrWriteNode(startOffset, length, (Nodes.ConstantPathNode) loadNode(), loadNode()); + case 40: + return new Nodes.ConstantPathTargetNode(startOffset, length, loadOptionalNode(), loadOptionalConstant()); + case 41: + return new Nodes.ConstantPathWriteNode(startOffset, length, (Nodes.ConstantPathNode) loadNode(), loadNode()); + case 42: + return new Nodes.ConstantReadNode(startOffset, length, loadConstant()); + case 43: + return new Nodes.ConstantTargetNode(startOffset, length, loadConstant()); + case 44: + return new Nodes.ConstantWriteNode(startOffset, length, loadConstant(), loadNode()); + case 45: + return loadDefNode(startOffset, length); + case 46: + return new Nodes.DefinedNode(startOffset, length, loadNode()); + case 47: + return new Nodes.ElseNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode()); + case 48: + return new Nodes.EmbeddedStatementsNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode()); + case 49: + return new Nodes.EmbeddedVariableNode(startOffset, length, loadNode()); + case 50: + return new Nodes.EnsureNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode()); + case 51: + return new Nodes.FalseNode(startOffset, length); + case 52: + return new Nodes.FindPatternNode(startOffset, length, loadOptionalNode(), (Nodes.SplatNode) loadNode(), loadNodes(), (Nodes.SplatNode) loadNode()); + case 53: + return new Nodes.FlipFlopNode(startOffset, length, loadFlags(), loadOptionalNode(), loadOptionalNode()); + case 54: + return new Nodes.FloatNode(startOffset, length, buffer.getDouble()); + case 55: + return new Nodes.ForNode(startOffset, length, loadNode(), loadNode(), (Nodes.StatementsNode) loadOptionalNode()); + case 56: + return new Nodes.ForwardingArgumentsNode(startOffset, length); + case 57: + return new Nodes.ForwardingParameterNode(startOffset, length); + case 58: + return new Nodes.ForwardingSuperNode(startOffset, length, (Nodes.BlockNode) loadOptionalNode()); + case 59: + return new Nodes.GlobalVariableAndWriteNode(startOffset, length, loadConstant(), loadNode()); + case 60: + return new Nodes.GlobalVariableOperatorWriteNode(startOffset, length, loadConstant(), loadNode(), loadConstant()); + case 61: + return new Nodes.GlobalVariableOrWriteNode(startOffset, length, loadConstant(), loadNode()); + case 62: + return new Nodes.GlobalVariableReadNode(startOffset, length, loadConstant()); + case 63: + return new Nodes.GlobalVariableTargetNode(startOffset, length, loadConstant()); + case 64: + return new Nodes.GlobalVariableWriteNode(startOffset, length, loadConstant(), loadNode()); + case 65: + return new Nodes.HashNode(startOffset, length, loadNodes()); + case 66: + return new Nodes.HashPatternNode(startOffset, length, loadOptionalNode(), loadAssocNodes(), loadOptionalNode()); + case 67: + return new Nodes.IfNode(startOffset, length, loadNode(), (Nodes.StatementsNode) loadOptionalNode(), loadOptionalNode()); + case 68: + return new Nodes.ImaginaryNode(startOffset, length, loadNode()); + case 69: + return new Nodes.ImplicitNode(startOffset, length, loadNode()); + case 70: + return new Nodes.ImplicitRestNode(startOffset, length); + case 71: + return new Nodes.InNode(startOffset, length, loadNode(), (Nodes.StatementsNode) loadOptionalNode()); + case 72: + return new Nodes.IndexAndWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), (Nodes.ArgumentsNode) loadOptionalNode(), (Nodes.BlockArgumentNode) loadOptionalNode(), loadNode()); + case 73: + return new Nodes.IndexOperatorWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), (Nodes.ArgumentsNode) loadOptionalNode(), (Nodes.BlockArgumentNode) loadOptionalNode(), loadConstant(), loadNode()); + case 74: + return new Nodes.IndexOrWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), (Nodes.ArgumentsNode) loadOptionalNode(), (Nodes.BlockArgumentNode) loadOptionalNode(), loadNode()); + case 75: + return new Nodes.IndexTargetNode(startOffset, length, loadFlags(), loadNode(), (Nodes.ArgumentsNode) loadOptionalNode(), (Nodes.BlockArgumentNode) loadOptionalNode()); + case 76: + return new Nodes.InstanceVariableAndWriteNode(startOffset, length, loadConstant(), loadNode()); + case 77: + return new Nodes.InstanceVariableOperatorWriteNode(startOffset, length, loadConstant(), loadNode(), loadConstant()); + case 78: + return new Nodes.InstanceVariableOrWriteNode(startOffset, length, loadConstant(), loadNode()); + case 79: + return new Nodes.InstanceVariableReadNode(startOffset, length, loadConstant()); + case 80: + return new Nodes.InstanceVariableTargetNode(startOffset, length, loadConstant()); + case 81: + return new Nodes.InstanceVariableWriteNode(startOffset, length, loadConstant(), loadNode()); + case 82: + return new Nodes.IntegerNode(startOffset, length, loadFlags(), loadInteger()); + case 83: + return new Nodes.InterpolatedMatchLastLineNode(startOffset, length, loadFlags(), loadNodes()); + case 84: + return new Nodes.InterpolatedRegularExpressionNode(startOffset, length, loadFlags(), loadNodes()); + case 85: + return new Nodes.InterpolatedStringNode(startOffset, length, loadFlags(), loadNodes()); + case 86: + return new Nodes.InterpolatedSymbolNode(startOffset, length, loadNodes()); + case 87: + return new Nodes.InterpolatedXStringNode(startOffset, length, loadNodes()); + case 88: + return new Nodes.ItLocalVariableReadNode(startOffset, length); + case 89: + return new Nodes.ItParametersNode(startOffset, length); + case 90: + return new Nodes.KeywordHashNode(startOffset, length, loadFlags(), loadNodes()); + case 91: + return new Nodes.KeywordRestParameterNode(startOffset, length, loadFlags(), loadOptionalConstant()); + case 92: + return new Nodes.LambdaNode(startOffset, length, loadConstants(), loadOptionalNode(), loadOptionalNode()); + case 93: + return new Nodes.LocalVariableAndWriteNode(startOffset, length, loadNode(), loadConstant(), loadVarUInt()); + case 94: + return new Nodes.LocalVariableOperatorWriteNode(startOffset, length, loadNode(), loadConstant(), loadConstant(), loadVarUInt()); + case 95: + return new Nodes.LocalVariableOrWriteNode(startOffset, length, loadNode(), loadConstant(), loadVarUInt()); + case 96: + return new Nodes.LocalVariableReadNode(startOffset, length, loadConstant(), loadVarUInt()); + case 97: + return new Nodes.LocalVariableTargetNode(startOffset, length, loadConstant(), loadVarUInt()); + case 98: + return new Nodes.LocalVariableWriteNode(startOffset, length, loadConstant(), loadVarUInt(), loadNode()); + case 99: + return new Nodes.MatchLastLineNode(startOffset, length, loadFlags(), loadString()); + case 100: + return new Nodes.MatchPredicateNode(startOffset, length, loadNode(), loadNode()); + case 101: + return new Nodes.MatchRequiredNode(startOffset, length, loadNode(), loadNode()); + case 102: + return new Nodes.MatchWriteNode(startOffset, length, (Nodes.CallNode) loadNode(), loadLocalVariableTargetNodes()); + case 103: + return new Nodes.MissingNode(startOffset, length); + case 104: + return new Nodes.ModuleNode(startOffset, length, loadConstants(), loadNode(), loadOptionalNode(), loadConstant()); + case 105: + return new Nodes.MultiTargetNode(startOffset, length, loadNodes(), loadOptionalNode(), loadNodes()); + case 106: + return new Nodes.MultiWriteNode(startOffset, length, loadNodes(), loadOptionalNode(), loadNodes(), loadNode()); + case 107: + return new Nodes.NextNode(startOffset, length, (Nodes.ArgumentsNode) loadOptionalNode()); + case 108: + return new Nodes.NilNode(startOffset, length); + case 109: + return new Nodes.NoBlockParameterNode(startOffset, length); + case 110: + return new Nodes.NoKeywordsParameterNode(startOffset, length); + case 111: + return new Nodes.NumberedParametersNode(startOffset, length, buffer.get()); + case 112: + return new Nodes.NumberedReferenceReadNode(startOffset, length, loadVarUInt()); + case 113: + return new Nodes.OptionalKeywordParameterNode(startOffset, length, loadFlags(), loadConstant(), loadNode()); + case 114: + return new Nodes.OptionalParameterNode(startOffset, length, loadFlags(), loadConstant(), loadNode()); + case 115: + return new Nodes.OrNode(startOffset, length, loadNode(), loadNode()); + case 116: + return new Nodes.ParametersNode(startOffset, length, loadNodes(), loadOptionalParameterNodes(), loadOptionalNode(), loadNodes(), loadNodes(), loadOptionalNode(), loadOptionalNode()); + case 117: + return new Nodes.ParenthesesNode(startOffset, length, loadFlags(), loadOptionalNode()); + case 118: + return new Nodes.PinnedExpressionNode(startOffset, length, loadNode()); + case 119: + return new Nodes.PinnedVariableNode(startOffset, length, loadNode()); + case 120: + return new Nodes.PostExecutionNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode()); + case 121: + return new Nodes.PreExecutionNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode()); + case 122: + return new Nodes.ProgramNode(startOffset, length, loadConstants(), (Nodes.StatementsNode) loadNode()); + case 123: + return new Nodes.RangeNode(startOffset, length, loadFlags(), loadOptionalNode(), loadOptionalNode()); + case 124: + return new Nodes.RationalNode(startOffset, length, loadFlags(), loadInteger(), loadInteger()); + case 125: + return new Nodes.RedoNode(startOffset, length); + case 126: + return new Nodes.RegularExpressionNode(startOffset, length, loadFlags(), loadString()); + case 127: + return new Nodes.RequiredKeywordParameterNode(startOffset, length, loadFlags(), loadConstant()); + case 128: + return new Nodes.RequiredParameterNode(startOffset, length, loadFlags(), loadConstant()); + case 129: + return new Nodes.RescueModifierNode(startOffset, length, loadNode(), loadNode()); + case 130: + return new Nodes.RescueNode(startOffset, length, loadNodes(), loadOptionalNode(), (Nodes.StatementsNode) loadOptionalNode(), (Nodes.RescueNode) loadOptionalNode()); + case 131: + return new Nodes.RestParameterNode(startOffset, length, loadFlags(), loadOptionalConstant()); + case 132: + return new Nodes.RetryNode(startOffset, length); + case 133: + return new Nodes.ReturnNode(startOffset, length, (Nodes.ArgumentsNode) loadOptionalNode()); + case 134: + return new Nodes.SelfNode(startOffset, length); + case 135: + return new Nodes.ShareableConstantNode(startOffset, length, loadFlags(), loadNode()); + case 136: + return new Nodes.SingletonClassNode(startOffset, length, loadConstants(), loadNode(), loadOptionalNode()); + case 137: + return new Nodes.SourceEncodingNode(startOffset, length); + case 138: + return new Nodes.SourceFileNode(startOffset, length, loadFlags(), loadString()); + case 139: + return new Nodes.SourceLineNode(startOffset, length); + case 140: + return new Nodes.SplatNode(startOffset, length, loadOptionalNode()); + case 141: + return new Nodes.StatementsNode(startOffset, length, loadNodes()); + case 142: + return new Nodes.StringNode(startOffset, length, loadFlags(), loadString()); + case 143: + return new Nodes.SuperNode(startOffset, length, (Nodes.ArgumentsNode) loadOptionalNode(), loadOptionalNode()); + case 144: + return new Nodes.SymbolNode(startOffset, length, loadFlags(), loadString()); + case 145: + return new Nodes.TrueNode(startOffset, length); + case 146: + return new Nodes.UndefNode(startOffset, length, loadNodes()); + case 147: + return new Nodes.UnlessNode(startOffset, length, loadNode(), (Nodes.StatementsNode) loadOptionalNode(), (Nodes.ElseNode) loadOptionalNode()); + case 148: + return new Nodes.UntilNode(startOffset, length, loadFlags(), loadNode(), (Nodes.StatementsNode) loadOptionalNode()); + case 149: + return new Nodes.WhenNode(startOffset, length, loadNodes(), (Nodes.StatementsNode) loadOptionalNode()); + case 150: + return new Nodes.WhileNode(startOffset, length, loadFlags(), loadNode(), (Nodes.StatementsNode) loadOptionalNode()); + case 151: + return new Nodes.XStringNode(startOffset, length, loadFlags(), loadString()); + case 152: + return new Nodes.YieldNode(startOffset, length, (Nodes.ArgumentsNode) loadOptionalNode()); + default: + throw new Error("Unknown node type: " + type); + } + } + + // Can be overridden to use createLazyDefNode instead + protected Nodes.DefNode loadDefNode(int startOffset, int length) { + return createDefNode(startOffset, length); + } + + protected Nodes.DefNode createLazyDefNode(int startOffset, int length) { + int bufferPosition = buffer.position(); + int serializedLength = buffer.getInt(); + // Load everything except the body and locals, because the name, receiver, parameters are still needed for lazily defining the method + Nodes.DefNode lazyDefNode = new Nodes.DefNode(startOffset, length, -bufferPosition, this, loadConstant(), loadOptionalNode(), (Nodes.ParametersNode) loadOptionalNode(), null, Nodes.EMPTY_IDENTIFIER_ARRAY); + buffer.position(bufferPosition + serializedLength); // skip past the serialized DefNode + return lazyDefNode; + } + + protected Nodes.DefNode createDefNode(int startOffset, int length) { + return new Nodes.DefNode(startOffset, length, buffer.getInt(), null, loadConstant(), loadOptionalNode(), (Nodes.ParametersNode) loadOptionalNode(), loadOptionalNode(), loadConstants()); + } + + Nodes.DefNode createDefNodeFromSavedPosition(int startOffset, int length, int bufferPosition) { + Nodes.DefNode node; + // This method mutates the buffer position and may be called from different threads so we must synchronize + synchronized (this) { + buffer.position(bufferPosition); + node = createDefNode(startOffset, length); + } + + MarkNewlinesVisitor visitor = new MarkNewlinesVisitor(source); + node.accept(visitor); + + return node; + } + + private static final Nodes.Node[] EMPTY_Node_ARRAY = {}; + + private Nodes.Node[] loadNodes() { + int length = loadVarUInt(); + if (length == 0) { + return EMPTY_Node_ARRAY; + } + Nodes.Node[] nodes = new Nodes.Node[length]; + for (int i = 0; i < length; i++) { + nodes[i] = loadNode(); + } + return nodes; + } + + private static final Nodes.BlockLocalVariableNode[] EMPTY_BlockLocalVariableNode_ARRAY = {}; + + private Nodes.BlockLocalVariableNode[] loadBlockLocalVariableNodes() { + int length = loadVarUInt(); + if (length == 0) { + return EMPTY_BlockLocalVariableNode_ARRAY; + } + Nodes.BlockLocalVariableNode[] nodes = new Nodes.BlockLocalVariableNode[length]; + for (int i = 0; i < length; i++) { + nodes[i] = (Nodes.BlockLocalVariableNode) loadNode(); + } + return nodes; + } + + private static final Nodes.InNode[] EMPTY_InNode_ARRAY = {}; + + private Nodes.InNode[] loadInNodes() { + int length = loadVarUInt(); + if (length == 0) { + return EMPTY_InNode_ARRAY; + } + Nodes.InNode[] nodes = new Nodes.InNode[length]; + for (int i = 0; i < length; i++) { + nodes[i] = (Nodes.InNode) loadNode(); + } + return nodes; + } + + private static final Nodes.WhenNode[] EMPTY_WhenNode_ARRAY = {}; + + private Nodes.WhenNode[] loadWhenNodes() { + int length = loadVarUInt(); + if (length == 0) { + return EMPTY_WhenNode_ARRAY; + } + Nodes.WhenNode[] nodes = new Nodes.WhenNode[length]; + for (int i = 0; i < length; i++) { + nodes[i] = (Nodes.WhenNode) loadNode(); + } + return nodes; + } + + private static final Nodes.AssocNode[] EMPTY_AssocNode_ARRAY = {}; + + private Nodes.AssocNode[] loadAssocNodes() { + int length = loadVarUInt(); + if (length == 0) { + return EMPTY_AssocNode_ARRAY; + } + Nodes.AssocNode[] nodes = new Nodes.AssocNode[length]; + for (int i = 0; i < length; i++) { + nodes[i] = (Nodes.AssocNode) loadNode(); + } + return nodes; + } + + private static final Nodes.LocalVariableTargetNode[] EMPTY_LocalVariableTargetNode_ARRAY = {}; + + private Nodes.LocalVariableTargetNode[] loadLocalVariableTargetNodes() { + int length = loadVarUInt(); + if (length == 0) { + return EMPTY_LocalVariableTargetNode_ARRAY; + } + Nodes.LocalVariableTargetNode[] nodes = new Nodes.LocalVariableTargetNode[length]; + for (int i = 0; i < length; i++) { + nodes[i] = (Nodes.LocalVariableTargetNode) loadNode(); + } + return nodes; + } + + private static final Nodes.OptionalParameterNode[] EMPTY_OptionalParameterNode_ARRAY = {}; + + private Nodes.OptionalParameterNode[] loadOptionalParameterNodes() { + int length = loadVarUInt(); + if (length == 0) { + return EMPTY_OptionalParameterNode_ARRAY; + } + Nodes.OptionalParameterNode[] nodes = new Nodes.OptionalParameterNode[length]; + for (int i = 0; i < length; i++) { + nodes[i] = (Nodes.OptionalParameterNode) loadNode(); + } + return nodes; + } + + private void expect(byte value, String error) { + byte b = buffer.get(); + if (b != value) { + throw new Error("Deserialization error: " + error + " (expected " + value + " but was " + b + " at position " + buffer.position() + ")"); + } + } + +} +// @formatter:on diff --git a/java/org/ruby_lang/prism/MarkNewlinesVisitor.java b/java/api/src/main/java/org/ruby_lang/prism/MarkNewlinesVisitor.java similarity index 100% rename from java/org/ruby_lang/prism/MarkNewlinesVisitor.java rename to java/api/src/main/java/org/ruby_lang/prism/MarkNewlinesVisitor.java diff --git a/java/api/src/main/java/org/ruby_lang/prism/Nodes.java b/java/api/src/main/java/org/ruby_lang/prism/Nodes.java new file mode 100644 index 0000000000..8f032d5fa0 --- /dev/null +++ b/java/api/src/main/java/org/ruby_lang/prism/Nodes.java @@ -0,0 +1,11628 @@ +/*----------------------------------------------------------------------------*/ +/* This file is generated by the templates/template.rb script and should not */ +/* be modified manually. See */ +/* templates/java/org/ruby_lang/prism/Nodes.java.erb */ +/* if you are looking to modify the */ +/* template */ +/*----------------------------------------------------------------------------*/ + +package org.ruby_lang.prism; + +import java.lang.Override; +import java.lang.String; +import java.lang.StringBuilder; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; + +// GENERATED BY Nodes.java.erb +// @formatter:off +public abstract class Nodes { + + public static final byte[][] EMPTY_IDENTIFIER_ARRAY = {}; + + @Target(ElementType.FIELD) + @Retention(RetentionPolicy.SOURCE) + public @interface Nullable { + } + + @Target(ElementType.FIELD) + @Retention(RetentionPolicy.SOURCE) + public @interface UnionType { + Class[] value(); + } + + public static final class Location { + + public static final Location[] EMPTY_ARRAY = {}; + + public final int startOffset; + public final int length; + + public Location(int startOffset, int length) { + this.startOffset = startOffset; + this.length = length; + } + + public int endOffset() { + return startOffset + length; + } + } + + public static final class Source { + private int startLine = 1; + private int[] lineOffsets = null; + + Source() { + } + + void setStartLine(int startLine) { + this.startLine = startLine; + } + + void setLineOffsets(int[] lineOffsets) { + this.lineOffsets = lineOffsets; + } + + // 1-based + public int line(int byteOffset) { + return startLine + findLine(byteOffset); + } + + // 0-based + public int findLine(int byteOffset) { + assert byteOffset >= 0 : byteOffset; + int index = Arrays.binarySearch(lineOffsets, byteOffset); + int line; + if (index < 0) { + line = -index - 2; + } else { + line = index; + } + assert line >= 0 && line <= getLineCount() : line; + return line; + } + + public int getLineCount() { + return lineOffsets.length; + } + } + + public static abstract class Node { + + public static final Node[] EMPTY_ARRAY = {}; + + public final int startOffset; + public final int length; + private boolean newLineFlag = false; + + public Node(int startOffset, int length) { + this.startOffset = startOffset; + this.length = length; + } + + public final int endOffset() { + return startOffset + length; + } + + public final boolean hasNewLineFlag() { + return newLineFlag; + } + + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + int line = source.findLine(this.startOffset); + if (!newlineMarked[line]) { + newlineMarked[line] = true; + this.newLineFlag = true; + } + } + + public void setNewLineFlag(boolean newLineFlag) { + this.newLineFlag = newLineFlag; + } + + public abstract T accept(AbstractNodeVisitor visitor); + + public abstract void visitChildNodes(AbstractNodeVisitor visitor); + + public abstract Node[] childNodes(); + + @Override + public String toString() { + return toString(""); + } + + protected abstract String toString(String indent); + } + + protected static String asString(Object value) { + return value.toString(); + } + + protected static String asString(byte[] value) { + StringBuilder buf = new StringBuilder(value.length); + for (byte b : value) { + if (b >= 0x20 && b <= 0x7e) { + buf.append((char) b); + } else { + buf.append(String.format("\\x%02x", Byte.toUnsignedInt(b))); + } + } + return buf.toString(); + } + + /** + * Flags for arguments nodes. + */ + public static final class ArgumentsNodeFlags implements Comparable { + + // if the arguments contain forwarding + public static final short CONTAINS_FORWARDING = 1 << 2; + + // if the arguments contain keywords + public static final short CONTAINS_KEYWORDS = 1 << 3; + + // if the arguments contain a keyword splat + public static final short CONTAINS_KEYWORD_SPLAT = 1 << 4; + + // if the arguments contain a splat + public static final short CONTAINS_SPLAT = 1 << 5; + + // if the arguments contain multiple splats + public static final short CONTAINS_MULTIPLE_SPLATS = 1 << 6; + + public static boolean isContainsForwarding(short flags) { + return (flags & CONTAINS_FORWARDING) != 0; + } + + public static boolean isContainsKeywords(short flags) { + return (flags & CONTAINS_KEYWORDS) != 0; + } + + public static boolean isContainsKeywordSplat(short flags) { + return (flags & CONTAINS_KEYWORD_SPLAT) != 0; + } + + public static boolean isContainsSplat(short flags) { + return (flags & CONTAINS_SPLAT) != 0; + } + + public static boolean isContainsMultipleSplats(short flags) { + return (flags & CONTAINS_MULTIPLE_SPLATS) != 0; + } + + private final short flags; + + public ArgumentsNodeFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof ArgumentsNodeFlags)) { + return false; + } + + return flags == ((ArgumentsNodeFlags) other).flags; + } + + @Override + public int compareTo(ArgumentsNodeFlags other) { + return flags - other.flags; + } + + public boolean isContainsForwarding() { + return (flags & CONTAINS_FORWARDING) != 0; + } + + public boolean isContainsKeywords() { + return (flags & CONTAINS_KEYWORDS) != 0; + } + + public boolean isContainsKeywordSplat() { + return (flags & CONTAINS_KEYWORD_SPLAT) != 0; + } + + public boolean isContainsSplat() { + return (flags & CONTAINS_SPLAT) != 0; + } + + public boolean isContainsMultipleSplats() { + return (flags & CONTAINS_MULTIPLE_SPLATS) != 0; + } + + } + + /** + * Flags for array nodes. + */ + public static final class ArrayNodeFlags implements Comparable { + + // if array contains splat nodes + public static final short CONTAINS_SPLAT = 1 << 2; + + public static boolean isContainsSplat(short flags) { + return (flags & CONTAINS_SPLAT) != 0; + } + + private final short flags; + + public ArrayNodeFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof ArrayNodeFlags)) { + return false; + } + + return flags == ((ArrayNodeFlags) other).flags; + } + + @Override + public int compareTo(ArrayNodeFlags other) { + return flags - other.flags; + } + + public boolean isContainsSplat() { + return (flags & CONTAINS_SPLAT) != 0; + } + + } + + /** + * Flags for call nodes. + */ + public static final class CallNodeFlags implements Comparable { + + // &. operator + public static final short SAFE_NAVIGATION = 1 << 2; + + // a call that could have been a local variable + public static final short VARIABLE_CALL = 1 << 3; + + // a call that is an attribute write, so the value being written should be returned + public static final short ATTRIBUTE_WRITE = 1 << 4; + + // a call that ignores method visibility + public static final short IGNORE_VISIBILITY = 1 << 5; + + public static boolean isSafeNavigation(short flags) { + return (flags & SAFE_NAVIGATION) != 0; + } + + public static boolean isVariableCall(short flags) { + return (flags & VARIABLE_CALL) != 0; + } + + public static boolean isAttributeWrite(short flags) { + return (flags & ATTRIBUTE_WRITE) != 0; + } + + public static boolean isIgnoreVisibility(short flags) { + return (flags & IGNORE_VISIBILITY) != 0; + } + + private final short flags; + + public CallNodeFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof CallNodeFlags)) { + return false; + } + + return flags == ((CallNodeFlags) other).flags; + } + + @Override + public int compareTo(CallNodeFlags other) { + return flags - other.flags; + } + + public boolean isSafeNavigation() { + return (flags & SAFE_NAVIGATION) != 0; + } + + public boolean isVariableCall() { + return (flags & VARIABLE_CALL) != 0; + } + + public boolean isAttributeWrite() { + return (flags & ATTRIBUTE_WRITE) != 0; + } + + public boolean isIgnoreVisibility() { + return (flags & IGNORE_VISIBILITY) != 0; + } + + } + + /** + * Flags for nodes that have unescaped content. + */ + public static final class EncodingFlags implements Comparable { + + // internal bytes forced the encoding to UTF-8 + public static final short FORCED_UTF8_ENCODING = 1 << 2; + + // internal bytes forced the encoding to binary + public static final short FORCED_BINARY_ENCODING = 1 << 3; + + public static boolean isForcedUtf8Encoding(short flags) { + return (flags & FORCED_UTF8_ENCODING) != 0; + } + + public static boolean isForcedBinaryEncoding(short flags) { + return (flags & FORCED_BINARY_ENCODING) != 0; + } + + private final short flags; + + public EncodingFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof EncodingFlags)) { + return false; + } + + return flags == ((EncodingFlags) other).flags; + } + + @Override + public int compareTo(EncodingFlags other) { + return flags - other.flags; + } + + public boolean isForcedUtf8Encoding() { + return (flags & FORCED_UTF8_ENCODING) != 0; + } + + public boolean isForcedBinaryEncoding() { + return (flags & FORCED_BINARY_ENCODING) != 0; + } + + } + + /** + * Flags for integer nodes that correspond to the base of the integer. + */ + public static final class IntegerBaseFlags implements Comparable { + + // 0b prefix + public static final short BINARY = 1 << 2; + + // 0d or no prefix + public static final short DECIMAL = 1 << 3; + + // 0o or 0 prefix + public static final short OCTAL = 1 << 4; + + // 0x prefix + public static final short HEXADECIMAL = 1 << 5; + + public static boolean isBinary(short flags) { + return (flags & BINARY) != 0; + } + + public static boolean isDecimal(short flags) { + return (flags & DECIMAL) != 0; + } + + public static boolean isOctal(short flags) { + return (flags & OCTAL) != 0; + } + + public static boolean isHexadecimal(short flags) { + return (flags & HEXADECIMAL) != 0; + } + + private final short flags; + + public IntegerBaseFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof IntegerBaseFlags)) { + return false; + } + + return flags == ((IntegerBaseFlags) other).flags; + } + + @Override + public int compareTo(IntegerBaseFlags other) { + return flags - other.flags; + } + + public boolean isBinary() { + return (flags & BINARY) != 0; + } + + public boolean isDecimal() { + return (flags & DECIMAL) != 0; + } + + public boolean isOctal() { + return (flags & OCTAL) != 0; + } + + public boolean isHexadecimal() { + return (flags & HEXADECIMAL) != 0; + } + + } + + /** + * Flags for interpolated string nodes that indicated mutability if they are also marked as literals. + */ + public static final class InterpolatedStringNodeFlags implements Comparable { + + // frozen by virtue of a `frozen_string_literal: true` comment or `--enable-frozen-string-literal`; only for adjacent string literals like `'a' 'b'` + public static final short FROZEN = 1 << 2; + + // mutable by virtue of a `frozen_string_literal: false` comment or `--disable-frozen-string-literal`; only for adjacent string literals like `'a' 'b'` + public static final short MUTABLE = 1 << 3; + + public static boolean isFrozen(short flags) { + return (flags & FROZEN) != 0; + } + + public static boolean isMutable(short flags) { + return (flags & MUTABLE) != 0; + } + + private final short flags; + + public InterpolatedStringNodeFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof InterpolatedStringNodeFlags)) { + return false; + } + + return flags == ((InterpolatedStringNodeFlags) other).flags; + } + + @Override + public int compareTo(InterpolatedStringNodeFlags other) { + return flags - other.flags; + } + + public boolean isFrozen() { + return (flags & FROZEN) != 0; + } + + public boolean isMutable() { + return (flags & MUTABLE) != 0; + } + + } + + /** + * Flags for keyword hash nodes. + */ + public static final class KeywordHashNodeFlags implements Comparable { + + // a keyword hash which only has `AssocNode` elements all with symbol keys, which means the elements can be treated as keyword arguments + public static final short SYMBOL_KEYS = 1 << 2; + + public static boolean isSymbolKeys(short flags) { + return (flags & SYMBOL_KEYS) != 0; + } + + private final short flags; + + public KeywordHashNodeFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof KeywordHashNodeFlags)) { + return false; + } + + return flags == ((KeywordHashNodeFlags) other).flags; + } + + @Override + public int compareTo(KeywordHashNodeFlags other) { + return flags - other.flags; + } + + public boolean isSymbolKeys() { + return (flags & SYMBOL_KEYS) != 0; + } + + } + + /** + * Flags for while and until loop nodes. + */ + public static final class LoopFlags implements Comparable { + + // a loop after a begin statement, so the body is executed first before the condition + public static final short BEGIN_MODIFIER = 1 << 2; + + public static boolean isBeginModifier(short flags) { + return (flags & BEGIN_MODIFIER) != 0; + } + + private final short flags; + + public LoopFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof LoopFlags)) { + return false; + } + + return flags == ((LoopFlags) other).flags; + } + + @Override + public int compareTo(LoopFlags other) { + return flags - other.flags; + } + + public boolean isBeginModifier() { + return (flags & BEGIN_MODIFIER) != 0; + } + + } + + /** + * Flags for parameter nodes. + */ + public static final class ParameterFlags implements Comparable { + + // a parameter name that has been repeated in the method signature + public static final short REPEATED_PARAMETER = 1 << 2; + + public static boolean isRepeatedParameter(short flags) { + return (flags & REPEATED_PARAMETER) != 0; + } + + private final short flags; + + public ParameterFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof ParameterFlags)) { + return false; + } + + return flags == ((ParameterFlags) other).flags; + } + + @Override + public int compareTo(ParameterFlags other) { + return flags - other.flags; + } + + public boolean isRepeatedParameter() { + return (flags & REPEATED_PARAMETER) != 0; + } + + } + + /** + * Flags for parentheses nodes. + */ + public static final class ParenthesesNodeFlags implements Comparable { + + // parentheses that contain multiple potentially void statements + public static final short MULTIPLE_STATEMENTS = 1 << 2; + + public static boolean isMultipleStatements(short flags) { + return (flags & MULTIPLE_STATEMENTS) != 0; + } + + private final short flags; + + public ParenthesesNodeFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof ParenthesesNodeFlags)) { + return false; + } + + return flags == ((ParenthesesNodeFlags) other).flags; + } + + @Override + public int compareTo(ParenthesesNodeFlags other) { + return flags - other.flags; + } + + public boolean isMultipleStatements() { + return (flags & MULTIPLE_STATEMENTS) != 0; + } + + } + + /** + * Flags for range and flip-flop nodes. + */ + public static final class RangeFlags implements Comparable { + + // ... operator + public static final short EXCLUDE_END = 1 << 2; + + public static boolean isExcludeEnd(short flags) { + return (flags & EXCLUDE_END) != 0; + } + + private final short flags; + + public RangeFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof RangeFlags)) { + return false; + } + + return flags == ((RangeFlags) other).flags; + } + + @Override + public int compareTo(RangeFlags other) { + return flags - other.flags; + } + + public boolean isExcludeEnd() { + return (flags & EXCLUDE_END) != 0; + } + + } + + /** + * Flags for regular expression and match last line nodes. + */ + public static final class RegularExpressionFlags implements Comparable { + + // i - ignores the case of characters when matching + public static final short IGNORE_CASE = 1 << 2; + + // x - ignores whitespace and allows comments in regular expressions + public static final short EXTENDED = 1 << 3; + + // m - allows $ to match the end of lines within strings + public static final short MULTI_LINE = 1 << 4; + + // o - only interpolates values into the regular expression once + public static final short ONCE = 1 << 5; + + // e - forces the EUC-JP encoding + public static final short EUC_JP = 1 << 6; + + // n - forces the ASCII-8BIT encoding + public static final short ASCII_8BIT = 1 << 7; + + // s - forces the Windows-31J encoding + public static final short WINDOWS_31J = 1 << 8; + + // u - forces the UTF-8 encoding + public static final short UTF_8 = 1 << 9; + + // internal bytes forced the encoding to UTF-8 + public static final short FORCED_UTF8_ENCODING = 1 << 10; + + // internal bytes forced the encoding to binary + public static final short FORCED_BINARY_ENCODING = 1 << 11; + + // internal bytes forced the encoding to US-ASCII + public static final short FORCED_US_ASCII_ENCODING = 1 << 12; + + public static boolean isIgnoreCase(short flags) { + return (flags & IGNORE_CASE) != 0; + } + + public static boolean isExtended(short flags) { + return (flags & EXTENDED) != 0; + } + + public static boolean isMultiLine(short flags) { + return (flags & MULTI_LINE) != 0; + } + + public static boolean isOnce(short flags) { + return (flags & ONCE) != 0; + } + + public static boolean isEucJp(short flags) { + return (flags & EUC_JP) != 0; + } + + public static boolean isAscii8bit(short flags) { + return (flags & ASCII_8BIT) != 0; + } + + public static boolean isWindows31j(short flags) { + return (flags & WINDOWS_31J) != 0; + } + + public static boolean isUtf8(short flags) { + return (flags & UTF_8) != 0; + } + + public static boolean isForcedUtf8Encoding(short flags) { + return (flags & FORCED_UTF8_ENCODING) != 0; + } + + public static boolean isForcedBinaryEncoding(short flags) { + return (flags & FORCED_BINARY_ENCODING) != 0; + } + + public static boolean isForcedUsAsciiEncoding(short flags) { + return (flags & FORCED_US_ASCII_ENCODING) != 0; + } + + private final short flags; + + public RegularExpressionFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof RegularExpressionFlags)) { + return false; + } + + return flags == ((RegularExpressionFlags) other).flags; + } + + @Override + public int compareTo(RegularExpressionFlags other) { + return flags - other.flags; + } + + public boolean isIgnoreCase() { + return (flags & IGNORE_CASE) != 0; + } + + public boolean isExtended() { + return (flags & EXTENDED) != 0; + } + + public boolean isMultiLine() { + return (flags & MULTI_LINE) != 0; + } + + public boolean isOnce() { + return (flags & ONCE) != 0; + } + + public boolean isEucJp() { + return (flags & EUC_JP) != 0; + } + + public boolean isAscii8bit() { + return (flags & ASCII_8BIT) != 0; + } + + public boolean isWindows31j() { + return (flags & WINDOWS_31J) != 0; + } + + public boolean isUtf8() { + return (flags & UTF_8) != 0; + } + + public boolean isForcedUtf8Encoding() { + return (flags & FORCED_UTF8_ENCODING) != 0; + } + + public boolean isForcedBinaryEncoding() { + return (flags & FORCED_BINARY_ENCODING) != 0; + } + + public boolean isForcedUsAsciiEncoding() { + return (flags & FORCED_US_ASCII_ENCODING) != 0; + } + + } + + /** + * Flags for shareable constant nodes. + */ + public static final class ShareableConstantNodeFlags implements Comparable { + + // constant writes that should be modified with shareable constant value literal + public static final short LITERAL = 1 << 2; + + // constant writes that should be modified with shareable constant value experimental everything + public static final short EXPERIMENTAL_EVERYTHING = 1 << 3; + + // constant writes that should be modified with shareable constant value experimental copy + public static final short EXPERIMENTAL_COPY = 1 << 4; + + public static boolean isLiteral(short flags) { + return (flags & LITERAL) != 0; + } + + public static boolean isExperimentalEverything(short flags) { + return (flags & EXPERIMENTAL_EVERYTHING) != 0; + } + + public static boolean isExperimentalCopy(short flags) { + return (flags & EXPERIMENTAL_COPY) != 0; + } + + private final short flags; + + public ShareableConstantNodeFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof ShareableConstantNodeFlags)) { + return false; + } + + return flags == ((ShareableConstantNodeFlags) other).flags; + } + + @Override + public int compareTo(ShareableConstantNodeFlags other) { + return flags - other.flags; + } + + public boolean isLiteral() { + return (flags & LITERAL) != 0; + } + + public boolean isExperimentalEverything() { + return (flags & EXPERIMENTAL_EVERYTHING) != 0; + } + + public boolean isExperimentalCopy() { + return (flags & EXPERIMENTAL_COPY) != 0; + } + + } + + /** + * Flags for string nodes. + */ + public static final class StringFlags implements Comparable { + + // internal bytes forced the encoding to UTF-8 + public static final short FORCED_UTF8_ENCODING = 1 << 2; + + // internal bytes forced the encoding to binary + public static final short FORCED_BINARY_ENCODING = 1 << 3; + + // frozen by virtue of a `frozen_string_literal: true` comment or `--enable-frozen-string-literal` + public static final short FROZEN = 1 << 4; + + // mutable by virtue of a `frozen_string_literal: false` comment or `--disable-frozen-string-literal` + public static final short MUTABLE = 1 << 5; + + public static boolean isForcedUtf8Encoding(short flags) { + return (flags & FORCED_UTF8_ENCODING) != 0; + } + + public static boolean isForcedBinaryEncoding(short flags) { + return (flags & FORCED_BINARY_ENCODING) != 0; + } + + public static boolean isFrozen(short flags) { + return (flags & FROZEN) != 0; + } + + public static boolean isMutable(short flags) { + return (flags & MUTABLE) != 0; + } + + private final short flags; + + public StringFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof StringFlags)) { + return false; + } + + return flags == ((StringFlags) other).flags; + } + + @Override + public int compareTo(StringFlags other) { + return flags - other.flags; + } + + public boolean isForcedUtf8Encoding() { + return (flags & FORCED_UTF8_ENCODING) != 0; + } + + public boolean isForcedBinaryEncoding() { + return (flags & FORCED_BINARY_ENCODING) != 0; + } + + public boolean isFrozen() { + return (flags & FROZEN) != 0; + } + + public boolean isMutable() { + return (flags & MUTABLE) != 0; + } + + } + + /** + * Flags for symbol nodes. + */ + public static final class SymbolFlags implements Comparable { + + // internal bytes forced the encoding to UTF-8 + public static final short FORCED_UTF8_ENCODING = 1 << 2; + + // internal bytes forced the encoding to binary + public static final short FORCED_BINARY_ENCODING = 1 << 3; + + // internal bytes forced the encoding to US-ASCII + public static final short FORCED_US_ASCII_ENCODING = 1 << 4; + + public static boolean isForcedUtf8Encoding(short flags) { + return (flags & FORCED_UTF8_ENCODING) != 0; + } + + public static boolean isForcedBinaryEncoding(short flags) { + return (flags & FORCED_BINARY_ENCODING) != 0; + } + + public static boolean isForcedUsAsciiEncoding(short flags) { + return (flags & FORCED_US_ASCII_ENCODING) != 0; + } + + private final short flags; + + public SymbolFlags(short flags) { + this.flags = flags; + } + + @Override + public int hashCode() { + return flags; + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof SymbolFlags)) { + return false; + } + + return flags == ((SymbolFlags) other).flags; + } + + @Override + public int compareTo(SymbolFlags other) { + return flags - other.flags; + } + + public boolean isForcedUtf8Encoding() { + return (flags & FORCED_UTF8_ENCODING) != 0; + } + + public boolean isForcedBinaryEncoding() { + return (flags & FORCED_BINARY_ENCODING) != 0; + } + + public boolean isForcedUsAsciiEncoding() { + return (flags & FORCED_US_ASCII_ENCODING) != 0; + } + + } + + /** + *
+     * Represents the use of the `alias` keyword to alias a global variable.
+     *
+     *     alias $foo $bar
+     *     ^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class AliasGlobalVariableNode extends Node { + /** + *
+         * Represents the new name of the global variable that can be used after aliasing.
+         *
+         *     alias $foo $bar
+         *           ^^^^
+         * 
+ */ + @UnionType({ GlobalVariableReadNode.class, BackReferenceReadNode.class, NumberedReferenceReadNode.class }) + public final Node new_name; + /** + *
+         * Represents the old name of the global variable that can be used before aliasing.
+         *
+         *     alias $foo $bar
+         *                ^^^^
+         * 
+ */ + @UnionType({ GlobalVariableReadNode.class, BackReferenceReadNode.class, NumberedReferenceReadNode.class }) + public final Node old_name; + + public AliasGlobalVariableNode(int startOffset, int length, Node new_name, Node old_name) { + super(startOffset, length); + this.new_name = new_name; + this.old_name = old_name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.new_name.accept(visitor); + this.old_name.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.new_name, this.old_name }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitAliasGlobalVariableNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("new_name: "); + builder.append(this.new_name.toString(nextIndent)); + builder.append(nextIndent); + builder.append("old_name: "); + builder.append(this.old_name.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `alias` keyword to alias a method.
+     *
+     *     alias foo bar
+     *     ^^^^^^^^^^^^^
+     * 
+ */ + public static final class AliasMethodNode extends Node { + /** + *
+         * Represents the new name of the method that will be aliased.
+         *
+         *     alias foo bar
+         *           ^^^
+         *
+         *     alias :foo :bar
+         *           ^^^^
+         *
+         *     alias :"#{foo}" :"#{bar}"
+         *           ^^^^^^^^^
+         * 
+ */ + @UnionType({ SymbolNode.class, InterpolatedSymbolNode.class }) + public final Node new_name; + /** + *
+         * Represents the old name of the method that will be aliased.
+         *
+         *     alias foo bar
+         *               ^^^
+         *
+         *     alias :foo :bar
+         *                ^^^^
+         *
+         *     alias :"#{foo}" :"#{bar}"
+         *                     ^^^^^^^^^
+         * 
+ */ + @UnionType({ SymbolNode.class, InterpolatedSymbolNode.class }) + public final Node old_name; + + public AliasMethodNode(int startOffset, int length, Node new_name, Node old_name) { + super(startOffset, length); + this.new_name = new_name; + this.old_name = old_name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.new_name.accept(visitor); + this.old_name.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.new_name, this.old_name }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitAliasMethodNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("new_name: "); + builder.append(this.new_name.toString(nextIndent)); + builder.append(nextIndent); + builder.append("old_name: "); + builder.append(this.old_name.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents an alternation pattern in pattern matching.
+     *
+     *     foo => bar | baz
+     *            ^^^^^^^^^
+     * 
+ */ + public static final class AlternationPatternNode extends Node { + /** + *
+         * Represents the left side of the expression.
+         *
+         *     foo => bar | baz
+         *            ^^^
+         * 
+ */ + public final Node left; + /** + *
+         * Represents the right side of the expression.
+         *
+         *     foo => bar | baz
+         *                  ^^^
+         * 
+ */ + public final Node right; + + public AlternationPatternNode(int startOffset, int length, Node left, Node right) { + super(startOffset, length); + this.left = left; + this.right = right; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.left.accept(visitor); + this.right.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.left, this.right }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitAlternationPatternNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("left: "); + builder.append(this.left.toString(nextIndent)); + builder.append(nextIndent); + builder.append("right: "); + builder.append(this.right.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `&&` operator or the `and` keyword.
+     *
+     *     left and right
+     *     ^^^^^^^^^^^^^^
+     * 
+ */ + public static final class AndNode extends Node { + /** + *
+         * Represents the left side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     left and right
+         *     ^^^^
+         *
+         *     1 && 2
+         *     ^
+         * 
+ */ + public final Node left; + /** + *
+         * Represents the right side of the expression.
+         *
+         *     left && right
+         *             ^^^^^
+         *
+         *     1 and 2
+         *           ^
+         * 
+ */ + public final Node right; + + public AndNode(int startOffset, int length, Node left, Node right) { + super(startOffset, length); + this.left = left; + this.right = right; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.left.accept(visitor); + this.right.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.left, this.right }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitAndNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("left: "); + builder.append(this.left.toString(nextIndent)); + builder.append(nextIndent); + builder.append("right: "); + builder.append(this.right.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a set of arguments to a method or a keyword.
+     *
+     *     return foo, bar, baz
+     *            ^^^^^^^^^^^^^
+     * 
+ */ + public static final class ArgumentsNode extends Node { + public final short flags; + /** + *
+         * The list of arguments, if present. These can be any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     foo(bar, baz)
+         *         ^^^^^^^^
+         * 
+ */ + public final Node[] arguments; + + public ArgumentsNode(int startOffset, int length, short flags, Node[] arguments) { + super(startOffset, length); + this.flags = flags; + this.arguments = arguments; + } + + public boolean isContainsForwarding() { + return ArgumentsNodeFlags.isContainsForwarding(flags); + } + + public boolean isContainsKeywords() { + return ArgumentsNodeFlags.isContainsKeywords(flags); + } + + public boolean isContainsKeywordSplat() { + return ArgumentsNodeFlags.isContainsKeywordSplat(flags); + } + + public boolean isContainsSplat() { + return ArgumentsNodeFlags.isContainsSplat(flags); + } + + public boolean isContainsMultipleSplats() { + return ArgumentsNodeFlags.isContainsMultipleSplats(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.arguments) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.arguments)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitArgumentsNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("ArgumentsNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("arguments: "); + builder.append('\n'); + for (Node child : this.arguments) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents an array literal. This can be a regular array using brackets or a special array using % like %w or %i.
+     *
+     *     [1, 2, 3]
+     *     ^^^^^^^^^
+     * 
+ */ + public static final class ArrayNode extends Node { + public final short flags; + /** + *
+         * Represent the list of zero or more [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression) within the array.
+         * 
+ */ + public final Node[] elements; + + public ArrayNode(int startOffset, int length, short flags, Node[] elements) { + super(startOffset, length); + this.flags = flags; + this.elements = elements; + } + + public boolean isContainsSplat() { + return ArrayNodeFlags.isContainsSplat(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.elements) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.elements)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitArrayNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("ArrayNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("elements: "); + builder.append('\n'); + for (Node child : this.elements) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents an array pattern in pattern matching.
+     *
+     *     foo in 1, 2
+     *            ^^^^
+     *
+     *     foo in [1, 2]
+     *            ^^^^^^
+     *
+     *     foo in *bar
+     *            ^^^^
+     *
+     *     foo in Bar[]
+     *            ^^^^^
+     *
+     *     foo in Bar[1, 2, 3]
+     *            ^^^^^^^^^^^^
+     * 
+ */ + public static final class ArrayPatternNode extends Node { + /** + *
+         * Represents the optional constant preceding the Array
+         *
+         *     foo in Bar[]
+         *            ^^^
+         *
+         *     foo in Bar[1, 2, 3]
+         *            ^^^
+         *
+         *     foo in Bar::Baz[1, 2, 3]
+         *            ^^^^^^^^
+         * 
+ */ + @Nullable + @UnionType({ ConstantPathNode.class, ConstantReadNode.class }) + public final Node constant; + /** + *
+         * Represents the required elements of the array pattern.
+         *
+         *     foo in [1, 2]
+         *             ^  ^
+         * 
+ */ + public final Node[] requireds; + /** + *
+         * Represents the rest element of the array pattern.
+         *
+         *     foo in *bar
+         *            ^^^^
+         * 
+ */ + @Nullable + public final Node rest; + /** + *
+         * Represents the elements after the rest element of the array pattern.
+         *
+         *     foo in *bar, baz
+         *                  ^^^
+         * 
+ */ + public final Node[] posts; + + public ArrayPatternNode(int startOffset, int length, Node constant, Node[] requireds, Node rest, Node[] posts) { + super(startOffset, length); + this.constant = constant; + this.requireds = requireds; + this.rest = rest; + this.posts = posts; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.constant != null) { + this.constant.accept(visitor); + } + for (Nodes.Node child : this.requireds) { + child.accept(visitor); + } + if (this.rest != null) { + this.rest.accept(visitor); + } + for (Nodes.Node child : this.posts) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.add(this.constant); + childNodes.addAll(Arrays.asList(this.requireds)); + childNodes.add(this.rest); + childNodes.addAll(Arrays.asList(this.posts)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitArrayPatternNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("constant: "); + builder.append(this.constant == null ? "null\n" : this.constant.toString(nextIndent)); + builder.append(nextIndent); + builder.append("requireds: "); + builder.append('\n'); + for (Node child : this.requireds) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("rest: "); + builder.append(this.rest == null ? "null\n" : this.rest.toString(nextIndent)); + builder.append(nextIndent); + builder.append("posts: "); + builder.append('\n'); + for (Node child : this.posts) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents a hash key/value pair.
+     *
+     *     { a => b }
+     *       ^^^^^^
+     * 
+ */ + public static final class AssocNode extends Node { + /** + *
+         * The key of the association. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     { a: b }
+         *       ^
+         *
+         *     { foo => bar }
+         *       ^^^
+         *
+         *     { def a; end => 1 }
+         *       ^^^^^^^^^^
+         * 
+ */ + public final Node key; + /** + *
+         * The value of the association, if present. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     { foo => bar }
+         *              ^^^
+         *
+         *     { x: 1 }
+         *          ^
+         * 
+ */ + public final Node value; + + public AssocNode(int startOffset, int length, Node key, Node value) { + super(startOffset, length); + this.key = key; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.key.accept(visitor); + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.key, this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitAssocNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("key: "); + builder.append(this.key.toString(nextIndent)); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a splat in a hash literal.
+     *
+     *     { **foo }
+     *       ^^^^^
+     * 
+ */ + public static final class AssocSplatNode extends Node { + /** + *
+         * The value to be splatted, if present. Will be missing when keyword rest argument forwarding is used.
+         *
+         *     { **foo }
+         *         ^^^
+         * 
+ */ + @Nullable + public final Node value; + + public AssocSplatNode(int startOffset, int length, Node value) { + super(startOffset, length); + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.value != null) { + this.value.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitAssocSplatNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value == null ? "null\n" : this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents reading a reference to a field in the previous match.
+     *
+     *     $'
+     *     ^^
+     * 
+ */ + public static final class BackReferenceReadNode extends Node { + /** + *
+         * The name of the back-reference variable, including the leading `$`.
+         *
+         *     $& # name `:$&`
+         *
+         *     $+ # name `:$+`
+         * 
+ */ + public final byte[] name; + + public BackReferenceReadNode(int startOffset, int length, byte[] name) { + super(startOffset, length); + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitBackReferenceReadNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents a begin statement.
+     *
+     *     begin
+     *       foo
+     *     end
+     *     ^^^^^
+     * 
+ */ + public static final class BeginNode extends Node { + /** + *
+         * Represents the statements within the begin block.
+         *
+         *     begin x end
+         *           ^
+         * 
+ */ + @Nullable + public final StatementsNode statements; + /** + *
+         * Represents the rescue clause within the begin block.
+         *
+         *     begin x; rescue y; end
+         *              ^^^^^^^^
+         * 
+ */ + @Nullable + public final RescueNode rescue_clause; + /** + *
+         * Represents the else clause within the begin block.
+         *
+         *     begin x; rescue y; else z; end
+         *                        ^^^^^^^^^^^
+         * 
+ */ + @Nullable + public final ElseNode else_clause; + /** + *
+         * Represents the ensure clause within the begin block.
+         *
+         *     begin x; ensure y; end
+         *              ^^^^^^^^
+         * 
+ */ + @Nullable + public final EnsureNode ensure_clause; + + public BeginNode(int startOffset, int length, StatementsNode statements, RescueNode rescue_clause, ElseNode else_clause, EnsureNode ensure_clause) { + super(startOffset, length); + this.statements = statements; + this.rescue_clause = rescue_clause; + this.else_clause = else_clause; + this.ensure_clause = ensure_clause; + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + // Never mark BeginNode with a newline flag, mark children instead + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.statements != null) { + this.statements.accept(visitor); + } + if (this.rescue_clause != null) { + this.rescue_clause.accept(visitor); + } + if (this.else_clause != null) { + this.else_clause.accept(visitor); + } + if (this.ensure_clause != null) { + this.ensure_clause.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.statements, this.rescue_clause, this.else_clause, this.ensure_clause }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitBeginNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + builder.append(nextIndent); + builder.append("rescue_clause: "); + builder.append(this.rescue_clause == null ? "null\n" : this.rescue_clause.toString(nextIndent)); + builder.append(nextIndent); + builder.append("else_clause: "); + builder.append(this.else_clause == null ? "null\n" : this.else_clause.toString(nextIndent)); + builder.append(nextIndent); + builder.append("ensure_clause: "); + builder.append(this.ensure_clause == null ? "null\n" : this.ensure_clause.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a block argument using `&`.
+     *
+     *     bar(&args)
+     *         ^^^^^
+     * 
+ */ + public static final class BlockArgumentNode extends Node { + /** + *
+         * The expression that is being passed as a block argument. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     foo(&args)
+         *          ^^^^
+         * 
+ */ + @Nullable + public final Node expression; + + public BlockArgumentNode(int startOffset, int length, Node expression) { + super(startOffset, length); + this.expression = expression; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.expression != null) { + this.expression.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.expression }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitBlockArgumentNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("expression: "); + builder.append(this.expression == null ? "null\n" : this.expression.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a block local variable.
+     *
+     *     a { |; b| }
+     *            ^
+     * 
+ */ + public static final class BlockLocalVariableNode extends Node { + public final short flags; + /** + *
+         * The name of the block local variable.
+         *
+         *     a { |; b| } # name `:b`
+         *            ^
+         * 
+ */ + public final byte[] name; + + public BlockLocalVariableNode(int startOffset, int length, short flags, byte[] name) { + super(startOffset, length); + this.flags = flags; + this.name = name; + } + + public boolean isRepeatedParameter() { + return ParameterFlags.isRepeatedParameter(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitBlockLocalVariableNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("ParameterFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents a block of ruby code.
+     *
+     *     [1, 2, 3].each { |i| puts x }
+     *                    ^^^^^^^^^^^^^^
+     * 
+ */ + public static final class BlockNode extends Node { + /** + *
+         * The local variables declared in the block.
+         *
+         *     [1, 2, 3].each { |i| puts x } # locals: [:i]
+         *                       ^
+         * 
+ */ + public final byte[][] locals; + /** + *
+         * The parameters of the block.
+         *
+         *     [1, 2, 3].each { |i| puts x }
+         *                      ^^^
+         *     [1, 2, 3].each { puts _1 }
+         *                    ^^^^^^^^^^^
+         *     [1, 2, 3].each { puts it }
+         *                    ^^^^^^^^^^^
+         * 
+ */ + @Nullable + @UnionType({ BlockParametersNode.class, NumberedParametersNode.class, ItParametersNode.class }) + public final Node parameters; + /** + *
+         * The body of the block.
+         *
+         *     [1, 2, 3].each { |i| puts x }
+         *                          ^^^^^^
+         * 
+ */ + @Nullable + @UnionType({ StatementsNode.class, BeginNode.class }) + public final Node body; + + public BlockNode(int startOffset, int length, byte[][] locals, Node parameters, Node body) { + super(startOffset, length); + this.locals = locals; + this.parameters = parameters; + this.body = body; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.parameters != null) { + this.parameters.accept(visitor); + } + if (this.body != null) { + this.body.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.parameters, this.body }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitBlockNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("locals: "); + builder.append('\n'); + for (byte[] constant : this.locals) { + builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); + } + builder.append(nextIndent); + builder.append("parameters: "); + builder.append(this.parameters == null ? "null\n" : this.parameters.toString(nextIndent)); + builder.append(nextIndent); + builder.append("body: "); + builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a block parameter of a method, block, or lambda definition.
+     *
+     *     def a(&b)
+     *           ^^
+     *     end
+     * 
+ */ + public static final class BlockParameterNode extends Node { + public final short flags; + /** + *
+         * The name of the block parameter.
+         *
+         *     def a(&b) # name `:b`
+         *            ^
+         *     end
+         * 
+ */ + @Nullable + public final byte[] name; + + public BlockParameterNode(int startOffset, int length, short flags, byte[] name) { + super(startOffset, length); + this.flags = flags; + this.name = name; + } + + public boolean isRepeatedParameter() { + return ParameterFlags.isRepeatedParameter(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitBlockParameterNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("ParameterFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("name: "); + builder.append(this.name == null ? "null" : "\"" + asString(this.name) + "\""); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents a block's parameters declaration.
+     *
+     *     -> (a, b = 1; local) { }
+     *        ^^^^^^^^^^^^^^^^^
+     *
+     *     foo do |a, b = 1; local|
+     *            ^^^^^^^^^^^^^^^^^
+     *     end
+     * 
+ */ + public static final class BlockParametersNode extends Node { + /** + *
+         * Represents the parameters of the block.
+         *
+         *     -> (a, b = 1; local) { }
+         *         ^^^^^^^^
+         *
+         *     foo do |a, b = 1; local|
+         *             ^^^^^^^^
+         *     end
+         * 
+ */ + @Nullable + public final ParametersNode parameters; + /** + *
+         * Represents the local variables of the block.
+         *
+         *     -> (a, b = 1; local) { }
+         *                   ^^^^^
+         *
+         *     foo do |a, b = 1; local|
+         *                       ^^^^^
+         *     end
+         * 
+ */ + public final BlockLocalVariableNode[] locals; + + public BlockParametersNode(int startOffset, int length, ParametersNode parameters, BlockLocalVariableNode[] locals) { + super(startOffset, length); + this.parameters = parameters; + this.locals = locals; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.parameters != null) { + this.parameters.accept(visitor); + } + for (Nodes.Node child : this.locals) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.add(this.parameters); + childNodes.addAll(Arrays.asList(this.locals)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitBlockParametersNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("parameters: "); + builder.append(this.parameters == null ? "null\n" : this.parameters.toString(nextIndent)); + builder.append(nextIndent); + builder.append("locals: "); + builder.append('\n'); + for (Node child : this.locals) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `break` keyword.
+     *
+     *     break foo
+     *     ^^^^^^^^^
+     * 
+ */ + public static final class BreakNode extends Node { + /** + *
+         * The arguments to the break statement, if present. These can be any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     break foo
+         *           ^^^
+         * 
+ */ + @Nullable + public final ArgumentsNode arguments; + + public BreakNode(int startOffset, int length, ArgumentsNode arguments) { + super(startOffset, length); + this.arguments = arguments; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.arguments != null) { + this.arguments.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.arguments }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitBreakNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("arguments: "); + builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `&&=` operator on a call.
+     *
+     *     foo.bar &&= value
+     *     ^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class CallAndWriteNode extends Node { + public final short flags; + /** + *
+         * The object that the method is being called on. This can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     foo.bar &&= value
+         *     ^^^
+         * 
+ */ + @Nullable + public final Node receiver; + /** + *
+         * Represents the name of the method being called.
+         *
+         *     foo.bar &&= value # read_name `:bar`
+         *         ^^^
+         * 
+ */ + public final byte[] read_name; + /** + *
+         * Represents the name of the method being written to.
+         *
+         *     foo.bar &&= value # write_name `:bar=`
+         *         ^^^
+         * 
+ */ + public final byte[] write_name; + /** + *
+         * Represents the value being assigned.
+         *
+         *     foo.bar &&= value
+         *                 ^^^^^
+         * 
+ */ + public final Node value; + + public CallAndWriteNode(int startOffset, int length, short flags, Node receiver, byte[] read_name, byte[] write_name, Node value) { + super(startOffset, length); + this.flags = flags; + this.receiver = receiver; + this.read_name = read_name; + this.write_name = write_name; + this.value = value; + } + + public boolean isSafeNavigation() { + return CallNodeFlags.isSafeNavigation(flags); + } + + public boolean isVariableCall() { + return CallNodeFlags.isVariableCall(flags); + } + + public boolean isAttributeWrite() { + return CallNodeFlags.isAttributeWrite(flags); + } + + public boolean isIgnoreVisibility() { + return CallNodeFlags.isIgnoreVisibility(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.receiver != null) { + this.receiver.accept(visitor); + } + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.receiver, this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitCallAndWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("CallNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("receiver: "); + builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); + builder.append(nextIndent); + builder.append("read_name: "); + builder.append('"').append(asString(this.read_name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("write_name: "); + builder.append('"').append(asString(this.write_name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a method call, in all of the various forms that can take.
+     *
+     *     foo
+     *     ^^^
+     *
+     *     foo()
+     *     ^^^^^
+     *
+     *     +foo
+     *     ^^^^
+     *
+     *     foo + bar
+     *     ^^^^^^^^^
+     *
+     *     foo.bar
+     *     ^^^^^^^
+     *
+     *     foo&.bar
+     *     ^^^^^^^^
+     * 
+ */ + public static final class CallNode extends Node { + public final short flags; + /** + *
+         * The object that the method is being called on. This can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     foo.bar
+         *     ^^^
+         *
+         *     +foo
+         *      ^^^
+         *
+         *     foo + bar
+         *     ^^^
+         * 
+ */ + @Nullable + public final Node receiver; + /** + *
+         * Represents the name of the method being called.
+         *
+         *     foo.bar # name `:foo`
+         *     ^^^
+         * 
+ */ + public final byte[] name; + /** + *
+         * Represents the arguments to the method call. These can be any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     foo(bar)
+         *         ^^^
+         * 
+ */ + @Nullable + public final ArgumentsNode arguments; + /** + *
+         * Represents the block that is being passed to the method.
+         *
+         *     foo { |a| a }
+         *         ^^^^^^^^^
+         * 
+ */ + @Nullable + @UnionType({ BlockNode.class, BlockArgumentNode.class }) + public final Node block; + + public CallNode(int startOffset, int length, short flags, Node receiver, byte[] name, ArgumentsNode arguments, Node block) { + super(startOffset, length); + this.flags = flags; + this.receiver = receiver; + this.name = name; + this.arguments = arguments; + this.block = block; + } + + public boolean isSafeNavigation() { + return CallNodeFlags.isSafeNavigation(flags); + } + + public boolean isVariableCall() { + return CallNodeFlags.isVariableCall(flags); + } + + public boolean isAttributeWrite() { + return CallNodeFlags.isAttributeWrite(flags); + } + + public boolean isIgnoreVisibility() { + return CallNodeFlags.isIgnoreVisibility(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.receiver != null) { + this.receiver.accept(visitor); + } + if (this.arguments != null) { + this.arguments.accept(visitor); + } + if (this.block != null) { + this.block.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.receiver, this.arguments, this.block }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitCallNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("CallNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("receiver: "); + builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("arguments: "); + builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); + builder.append(nextIndent); + builder.append("block: "); + builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of an assignment operator on a call.
+     *
+     *     foo.bar += baz
+     *     ^^^^^^^^^^^^^^
+     * 
+ */ + public static final class CallOperatorWriteNode extends Node { + public final short flags; + /** + *
+         * The object that the method is being called on. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     foo.bar += value
+         *     ^^^
+         * 
+ */ + @Nullable + public final Node receiver; + /** + *
+         * Represents the name of the method being called.
+         *
+         *     foo.bar += value # read_name `:bar`
+         *         ^^^
+         * 
+ */ + public final byte[] read_name; + /** + *
+         * Represents the name of the method being written to.
+         *
+         *     foo.bar += value # write_name `:bar=`
+         *         ^^^
+         * 
+ */ + public final byte[] write_name; + /** + *
+         * Represents the binary operator being used.
+         *
+         *     foo.bar += value # binary_operator `:+`
+         *             ^
+         * 
+ */ + public final byte[] binary_operator; + /** + *
+         * Represents the value being assigned.
+         *
+         *     foo.bar += value
+         *                ^^^^^
+         * 
+ */ + public final Node value; + + public CallOperatorWriteNode(int startOffset, int length, short flags, Node receiver, byte[] read_name, byte[] write_name, byte[] binary_operator, Node value) { + super(startOffset, length); + this.flags = flags; + this.receiver = receiver; + this.read_name = read_name; + this.write_name = write_name; + this.binary_operator = binary_operator; + this.value = value; + } + + public boolean isSafeNavigation() { + return CallNodeFlags.isSafeNavigation(flags); + } + + public boolean isVariableCall() { + return CallNodeFlags.isVariableCall(flags); + } + + public boolean isAttributeWrite() { + return CallNodeFlags.isAttributeWrite(flags); + } + + public boolean isIgnoreVisibility() { + return CallNodeFlags.isIgnoreVisibility(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.receiver != null) { + this.receiver.accept(visitor); + } + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.receiver, this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitCallOperatorWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("CallNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("receiver: "); + builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); + builder.append(nextIndent); + builder.append("read_name: "); + builder.append('"').append(asString(this.read_name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("write_name: "); + builder.append('"').append(asString(this.write_name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("binary_operator: "); + builder.append('"').append(asString(this.binary_operator)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `||=` operator on a call.
+     *
+     *     foo.bar ||= value
+     *     ^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class CallOrWriteNode extends Node { + public final short flags; + /** + *
+         * The object that the method is being called on. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     foo.bar ||= value
+         *     ^^^
+         * 
+ */ + @Nullable + public final Node receiver; + /** + *
+         * Represents the name of the method being called.
+         *
+         *     foo.bar ||= value # read_name `:bar`
+         *         ^^^
+         * 
+ */ + public final byte[] read_name; + /** + *
+         * Represents the name of the method being written to.
+         *
+         *     foo.bar ||= value # write_name `:bar=`
+         *         ^^^
+         * 
+ */ + public final byte[] write_name; + /** + *
+         * Represents the value being assigned.
+         *
+         *     foo.bar ||= value
+         *                 ^^^^^
+         * 
+ */ + public final Node value; + + public CallOrWriteNode(int startOffset, int length, short flags, Node receiver, byte[] read_name, byte[] write_name, Node value) { + super(startOffset, length); + this.flags = flags; + this.receiver = receiver; + this.read_name = read_name; + this.write_name = write_name; + this.value = value; + } + + public boolean isSafeNavigation() { + return CallNodeFlags.isSafeNavigation(flags); + } + + public boolean isVariableCall() { + return CallNodeFlags.isVariableCall(flags); + } + + public boolean isAttributeWrite() { + return CallNodeFlags.isAttributeWrite(flags); + } + + public boolean isIgnoreVisibility() { + return CallNodeFlags.isIgnoreVisibility(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.receiver != null) { + this.receiver.accept(visitor); + } + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.receiver, this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitCallOrWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("CallNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("receiver: "); + builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); + builder.append(nextIndent); + builder.append("read_name: "); + builder.append('"').append(asString(this.read_name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("write_name: "); + builder.append('"').append(asString(this.write_name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents assigning to a method call.
+     *
+     *     foo.bar, = 1
+     *     ^^^^^^^
+     *
+     *     begin
+     *     rescue => foo.bar
+     *               ^^^^^^^
+     *     end
+     *
+     *     for foo.bar in baz do end
+     *         ^^^^^^^
+     * 
+ */ + public static final class CallTargetNode extends Node { + public final short flags; + /** + *
+         * The object that the method is being called on. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     foo.bar = 1
+         *     ^^^
+         * 
+ */ + public final Node receiver; + /** + *
+         * Represents the name of the method being called.
+         *
+         *     foo.bar = 1 # name `:foo`
+         *     ^^^
+         * 
+ */ + public final byte[] name; + + public CallTargetNode(int startOffset, int length, short flags, Node receiver, byte[] name) { + super(startOffset, length); + this.flags = flags; + this.receiver = receiver; + this.name = name; + } + + public boolean isSafeNavigation() { + return CallNodeFlags.isSafeNavigation(flags); + } + + public boolean isVariableCall() { + return CallNodeFlags.isVariableCall(flags); + } + + public boolean isAttributeWrite() { + return CallNodeFlags.isAttributeWrite(flags); + } + + public boolean isIgnoreVisibility() { + return CallNodeFlags.isIgnoreVisibility(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.receiver.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.receiver }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitCallTargetNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("CallNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("receiver: "); + builder.append(this.receiver.toString(nextIndent)); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents assigning to a local variable in pattern matching.
+     *
+     *     foo => [bar => baz]
+     *             ^^^^^^^^^^
+     * 
+ */ + public static final class CapturePatternNode extends Node { + /** + *
+         * Represents the value to capture.
+         *
+         *     foo => bar
+         *            ^^^
+         * 
+ */ + public final Node value; + /** + *
+         * Represents the target of the capture.
+         *
+         *     foo => bar
+         *     ^^^
+         * 
+ */ + public final LocalVariableTargetNode target; + + public CapturePatternNode(int startOffset, int length, Node value, LocalVariableTargetNode target) { + super(startOffset, length); + this.value = value; + this.target = target; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + this.target.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value, this.target }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitCapturePatternNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + builder.append(nextIndent); + builder.append("target: "); + builder.append(this.target.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of a case statement for pattern matching.
+     *
+     *     case true
+     *     in false
+     *     end
+     *     ^^^^^^^^^
+     * 
+ */ + public static final class CaseMatchNode extends Node { + /** + *
+         * Represents the predicate of the case match. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     case true; in false; end
+         *          ^^^^
+         * 
+ */ + @Nullable + public final Node predicate; + /** + *
+         * Represents the conditions of the case match.
+         *
+         *     case true; in false; end
+         *                ^^^^^^^^
+         * 
+ */ + public final InNode[] conditions; + /** + *
+         * Represents the else clause of the case match.
+         *
+         *     case true; in false; else; end
+         *                          ^^^^^^^^^
+         * 
+ */ + @Nullable + public final ElseNode else_clause; + + public CaseMatchNode(int startOffset, int length, Node predicate, InNode[] conditions, ElseNode else_clause) { + super(startOffset, length); + this.predicate = predicate; + this.conditions = conditions; + this.else_clause = else_clause; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.predicate != null) { + this.predicate.accept(visitor); + } + for (Nodes.Node child : this.conditions) { + child.accept(visitor); + } + if (this.else_clause != null) { + this.else_clause.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.add(this.predicate); + childNodes.addAll(Arrays.asList(this.conditions)); + childNodes.add(this.else_clause); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitCaseMatchNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("predicate: "); + builder.append(this.predicate == null ? "null\n" : this.predicate.toString(nextIndent)); + builder.append(nextIndent); + builder.append("conditions: "); + builder.append('\n'); + for (Node child : this.conditions) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("else_clause: "); + builder.append(this.else_clause == null ? "null\n" : this.else_clause.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of a case statement.
+     *
+     *     case true
+     *     when false
+     *     end
+     *     ^^^^^^^^^^
+     * 
+ */ + public static final class CaseNode extends Node { + /** + *
+         * Represents the predicate of the case statement. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     case true; when false; end
+         *          ^^^^
+         * 
+ */ + @Nullable + public final Node predicate; + /** + *
+         * Represents the conditions of the case statement.
+         *
+         *     case true; when false; end
+         *                ^^^^^^^^^^
+         * 
+ */ + public final WhenNode[] conditions; + /** + *
+         * Represents the else clause of the case statement.
+         *
+         *     case true; when false; else; end
+         *                            ^^^^^^^^^
+         * 
+ */ + @Nullable + public final ElseNode else_clause; + + public CaseNode(int startOffset, int length, Node predicate, WhenNode[] conditions, ElseNode else_clause) { + super(startOffset, length); + this.predicate = predicate; + this.conditions = conditions; + this.else_clause = else_clause; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.predicate != null) { + this.predicate.accept(visitor); + } + for (Nodes.Node child : this.conditions) { + child.accept(visitor); + } + if (this.else_clause != null) { + this.else_clause.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.add(this.predicate); + childNodes.addAll(Arrays.asList(this.conditions)); + childNodes.add(this.else_clause); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitCaseNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("predicate: "); + builder.append(this.predicate == null ? "null\n" : this.predicate.toString(nextIndent)); + builder.append(nextIndent); + builder.append("conditions: "); + builder.append('\n'); + for (Node child : this.conditions) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("else_clause: "); + builder.append(this.else_clause == null ? "null\n" : this.else_clause.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a class declaration involving the `class` keyword.
+     *
+     *     class Foo end
+     *     ^^^^^^^^^^^^^
+     * 
+ */ + public static final class ClassNode extends Node { + public final byte[][] locals; + @UnionType({ ConstantReadNode.class, ConstantPathNode.class }) + public final Node constant_path; + /** + *
+         * Represents the superclass of the class.
+         *
+         *     class Foo < Bar
+         *                 ^^^
+         * 
+ */ + @Nullable + public final Node superclass; + /** + *
+         * Represents the body of the class.
+         *
+         *     class Foo; bar; end
+         *                ^^^
+         * 
+ */ + @Nullable + @UnionType({ StatementsNode.class, BeginNode.class }) + public final Node body; + /** + *
+         * The name of the class.
+         *
+         *     class Foo end # name `:Foo`
+         * 
+ */ + public final byte[] name; + + public ClassNode(int startOffset, int length, byte[][] locals, Node constant_path, Node superclass, Node body, byte[] name) { + super(startOffset, length); + this.locals = locals; + this.constant_path = constant_path; + this.superclass = superclass; + this.body = body; + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.constant_path.accept(visitor); + if (this.superclass != null) { + this.superclass.accept(visitor); + } + if (this.body != null) { + this.body.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.constant_path, this.superclass, this.body }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitClassNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("locals: "); + builder.append('\n'); + for (byte[] constant : this.locals) { + builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); + } + builder.append(nextIndent); + builder.append("constant_path: "); + builder.append(this.constant_path.toString(nextIndent)); + builder.append(nextIndent); + builder.append("superclass: "); + builder.append(this.superclass == null ? "null\n" : this.superclass.toString(nextIndent)); + builder.append(nextIndent); + builder.append("body: "); + builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `&&=` operator for assignment to a class variable.
+     *
+     *     @@target &&= value
+     *     ^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ClassVariableAndWriteNode extends Node { + /** + *
+         * The name of the class variable, which is a `@@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
+         *
+         *     @@target &&= value # name `:@@target`
+         *     ^^^^^^^^
+         * 
+ */ + public final byte[] name; + /** + *
+         * Represents the value being assigned. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     @@target &&= value
+         *                  ^^^^^
+         * 
+ */ + public final Node value; + + public ClassVariableAndWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitClassVariableAndWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents assigning to a class variable using an operator that isn't `=`.
+     *
+     *     @@target += value
+     *     ^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ClassVariableOperatorWriteNode extends Node { + public final byte[] name; + public final Node value; + public final byte[] binary_operator; + + public ClassVariableOperatorWriteNode(int startOffset, int length, byte[] name, Node value, byte[] binary_operator) { + super(startOffset, length); + this.name = name; + this.value = value; + this.binary_operator = binary_operator; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitClassVariableOperatorWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + builder.append(nextIndent); + builder.append("binary_operator: "); + builder.append('"').append(asString(this.binary_operator)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `||=` operator for assignment to a class variable.
+     *
+     *     @@target ||= value
+     *     ^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ClassVariableOrWriteNode extends Node { + public final byte[] name; + public final Node value; + + public ClassVariableOrWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitClassVariableOrWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents referencing a class variable.
+     *
+     *     @@foo
+     *     ^^^^^
+     * 
+ */ + public static final class ClassVariableReadNode extends Node { + /** + *
+         * The name of the class variable, which is a `@@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
+         *
+         *     @@abc   # name `:@@abc`
+         *
+         *     @@_test # name `:@@_test`
+         * 
+ */ + public final byte[] name; + + public ClassVariableReadNode(int startOffset, int length, byte[] name) { + super(startOffset, length); + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitClassVariableReadNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to a class variable in a context that doesn't have an explicit value.
+     *
+     *     @@foo, @@bar = baz
+     *     ^^^^^  ^^^^^
+     * 
+ */ + public static final class ClassVariableTargetNode extends Node { + public final byte[] name; + + public ClassVariableTargetNode(int startOffset, int length, byte[] name) { + super(startOffset, length); + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitClassVariableTargetNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to a class variable.
+     *
+     *     @@foo = 1
+     *     ^^^^^^^^^
+     * 
+ */ + public static final class ClassVariableWriteNode extends Node { + /** + *
+         * The name of the class variable, which is a `@@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
+         *
+         *     @@abc = 123     # name `@@abc`
+         *
+         *     @@_test = :test # name `@@_test`
+         * 
+ */ + public final byte[] name; + /** + *
+         * The value to write to the class variable. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     @@foo = :bar
+         *             ^^^^
+         *
+         *     @@_xyz = 123
+         *              ^^^
+         * 
+ */ + public final Node value; + + public ClassVariableWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitClassVariableWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `&&=` operator for assignment to a constant.
+     *
+     *     Target &&= value
+     *     ^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ConstantAndWriteNode extends Node { + public final byte[] name; + public final Node value; + + public ConstantAndWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantAndWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents assigning to a constant using an operator that isn't `=`.
+     *
+     *     Target += value
+     *     ^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ConstantOperatorWriteNode extends Node { + public final byte[] name; + public final Node value; + public final byte[] binary_operator; + + public ConstantOperatorWriteNode(int startOffset, int length, byte[] name, Node value, byte[] binary_operator) { + super(startOffset, length); + this.name = name; + this.value = value; + this.binary_operator = binary_operator; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantOperatorWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + builder.append(nextIndent); + builder.append("binary_operator: "); + builder.append('"').append(asString(this.binary_operator)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `||=` operator for assignment to a constant.
+     *
+     *     Target ||= value
+     *     ^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ConstantOrWriteNode extends Node { + public final byte[] name; + public final Node value; + + public ConstantOrWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantOrWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `&&=` operator for assignment to a constant path.
+     *
+     *     Parent::Child &&= value
+     *     ^^^^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ConstantPathAndWriteNode extends Node { + public final ConstantPathNode target; + public final Node value; + + public ConstantPathAndWriteNode(int startOffset, int length, ConstantPathNode target, Node value) { + super(startOffset, length); + this.target = target; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.target.accept(visitor); + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.target, this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantPathAndWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("target: "); + builder.append(this.target.toString(nextIndent)); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents accessing a constant through a path of `::` operators.
+     *
+     *     Foo::Bar
+     *     ^^^^^^^^
+     * 
+ */ + public static final class ConstantPathNode extends Node { + /** + *
+         * The left-hand node of the path, if present. It can be `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression). It will be `nil` when the constant lookup is at the root of the module tree.
+         *
+         *     Foo::Bar
+         *     ^^^
+         *
+         *     self::Test
+         *     ^^^^
+         *
+         *     a.b::C
+         *     ^^^
+         * 
+ */ + @Nullable + public final Node parent; + /** + *
+         * The name of the constant being accessed. This could be `nil` in the event of a syntax error.
+         * 
+ */ + @Nullable + public final byte[] name; + + public ConstantPathNode(int startOffset, int length, Node parent, byte[] name) { + super(startOffset, length); + this.parent = parent; + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.parent != null) { + this.parent.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.parent }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantPathNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("parent: "); + builder.append(this.parent == null ? "null\n" : this.parent.toString(nextIndent)); + builder.append(nextIndent); + builder.append("name: "); + builder.append(this.name == null ? "null" : "\"" + asString(this.name) + "\""); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents assigning to a constant path using an operator that isn't `=`.
+     *
+     *     Parent::Child += value
+     *     ^^^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ConstantPathOperatorWriteNode extends Node { + public final ConstantPathNode target; + public final Node value; + public final byte[] binary_operator; + + public ConstantPathOperatorWriteNode(int startOffset, int length, ConstantPathNode target, Node value, byte[] binary_operator) { + super(startOffset, length); + this.target = target; + this.value = value; + this.binary_operator = binary_operator; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.target.accept(visitor); + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.target, this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantPathOperatorWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("target: "); + builder.append(this.target.toString(nextIndent)); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + builder.append(nextIndent); + builder.append("binary_operator: "); + builder.append('"').append(asString(this.binary_operator)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `||=` operator for assignment to a constant path.
+     *
+     *     Parent::Child ||= value
+     *     ^^^^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ConstantPathOrWriteNode extends Node { + public final ConstantPathNode target; + public final Node value; + + public ConstantPathOrWriteNode(int startOffset, int length, ConstantPathNode target, Node value) { + super(startOffset, length); + this.target = target; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.target.accept(visitor); + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.target, this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantPathOrWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("target: "); + builder.append(this.target.toString(nextIndent)); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to a constant path in a context that doesn't have an explicit value.
+     *
+     *     Foo::Foo, Bar::Bar = baz
+     *     ^^^^^^^^  ^^^^^^^^
+     * 
+ */ + public static final class ConstantPathTargetNode extends Node { + @Nullable + public final Node parent; + @Nullable + public final byte[] name; + + public ConstantPathTargetNode(int startOffset, int length, Node parent, byte[] name) { + super(startOffset, length); + this.parent = parent; + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.parent != null) { + this.parent.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.parent }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantPathTargetNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("parent: "); + builder.append(this.parent == null ? "null\n" : this.parent.toString(nextIndent)); + builder.append(nextIndent); + builder.append("name: "); + builder.append(this.name == null ? "null" : "\"" + asString(this.name) + "\""); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to a constant path.
+     *
+     *     ::Foo = 1
+     *     ^^^^^^^^^
+     *
+     *     Foo::Bar = 1
+     *     ^^^^^^^^^^^^
+     *
+     *     ::Foo::Bar = 1
+     *     ^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ConstantPathWriteNode extends Node { + /** + *
+         * A node representing the constant path being written to.
+         *
+         *     Foo::Bar = 1
+         *     ^^^^^^^^
+         *
+         *     ::Foo = :abc
+         *     ^^^^^
+         * 
+ */ + public final ConstantPathNode target; + /** + *
+         * The value to write to the constant path. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     FOO::BAR = :abc
+         *                ^^^^
+         * 
+ */ + public final Node value; + + public ConstantPathWriteNode(int startOffset, int length, ConstantPathNode target, Node value) { + super(startOffset, length); + this.target = target; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.target.accept(visitor); + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.target, this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantPathWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("target: "); + builder.append(this.target.toString(nextIndent)); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents referencing a constant.
+     *
+     *     Foo
+     *     ^^^
+     * 
+ */ + public static final class ConstantReadNode extends Node { + /** + *
+         * The name of the [constant](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
+         *
+         *     X              # name `:X`
+         *
+         *     SOME_CONSTANT  # name `:SOME_CONSTANT`
+         * 
+ */ + public final byte[] name; + + public ConstantReadNode(int startOffset, int length, byte[] name) { + super(startOffset, length); + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantReadNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to a constant in a context that doesn't have an explicit value.
+     *
+     *     Foo, Bar = baz
+     *     ^^^  ^^^
+     * 
+ */ + public static final class ConstantTargetNode extends Node { + public final byte[] name; + + public ConstantTargetNode(int startOffset, int length, byte[] name) { + super(startOffset, length); + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantTargetNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to a constant.
+     *
+     *     Foo = 1
+     *     ^^^^^^^
+     * 
+ */ + public static final class ConstantWriteNode extends Node { + /** + *
+         * The name of the [constant](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
+         *
+         *     Foo = :bar # name `:Foo`
+         *
+         *     XYZ = 1    # name `:XYZ`
+         * 
+ */ + public final byte[] name; + /** + *
+         * The value to write to the constant. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     FOO = :bar
+         *           ^^^^
+         *
+         *     MyClass = Class.new
+         *               ^^^^^^^^^
+         * 
+ */ + public final Node value; + + public ConstantWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitConstantWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a method definition.
+     *
+     *     def method
+     *     end
+     *     ^^^^^^^^^^
+     * 
+ */ + public static final class DefNode extends Node { + public final int serializedLength; + public final Loader loader; + public final byte[] name; + @Nullable + public final Node receiver; + @Nullable + public final ParametersNode parameters; + @Nullable + @UnionType({ StatementsNode.class, BeginNode.class }) + public final Node body; + public final byte[][] locals; + + public DefNode(int startOffset, int length, int serializedLength, Loader loader, byte[] name, Node receiver, ParametersNode parameters, Node body, byte[][] locals) { + super(startOffset, length); + this.serializedLength = serializedLength; + this.loader = loader; + this.name = name; + this.receiver = receiver; + this.parameters = parameters; + this.body = body; + this.locals = locals; + } + + public boolean isLazy() { + return serializedLength < 0; + } + + public DefNode getNonLazy() { + if (isLazy()) { + return loader.createDefNodeFromSavedPosition(startOffset, length, -serializedLength); + } else { + return this; + } + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.receiver != null) { + this.receiver.accept(visitor); + } + if (this.parameters != null) { + this.parameters.accept(visitor); + } + if (this.body != null) { + this.body.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.receiver, this.parameters, this.body }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitDefNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("receiver: "); + builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); + builder.append(nextIndent); + builder.append("parameters: "); + builder.append(this.parameters == null ? "null\n" : this.parameters.toString(nextIndent)); + builder.append(nextIndent); + builder.append("body: "); + builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); + builder.append(nextIndent); + builder.append("locals: "); + builder.append('\n'); + for (byte[] constant : this.locals) { + builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); + } + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `defined?` keyword.
+     *
+     *     defined?(a)
+     *     ^^^^^^^^^^^
+     * 
+ */ + public static final class DefinedNode extends Node { + public final Node value; + + public DefinedNode(int startOffset, int length, Node value) { + super(startOffset, length); + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitDefinedNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents an `else` clause in a `case`, `if`, or `unless` statement.
+     *
+     *     if a then b else c end
+     *                 ^^^^^^^^^^
+     * 
+ */ + public static final class ElseNode extends Node { + @Nullable + public final StatementsNode statements; + + public ElseNode(int startOffset, int length, StatementsNode statements) { + super(startOffset, length); + this.statements = statements; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.statements != null) { + this.statements.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.statements }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitElseNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents an interpolated set of statements.
+     *
+     *     "foo #{bar}"
+     *          ^^^^^^
+     * 
+ */ + public static final class EmbeddedStatementsNode extends Node { + @Nullable + public final StatementsNode statements; + + public EmbeddedStatementsNode(int startOffset, int length, StatementsNode statements) { + super(startOffset, length); + this.statements = statements; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.statements != null) { + this.statements.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.statements }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitEmbeddedStatementsNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents an interpolated variable.
+     *
+     *     "foo #@bar"
+     *          ^^^^^
+     * 
+ */ + public static final class EmbeddedVariableNode extends Node { + @UnionType({ InstanceVariableReadNode.class, ClassVariableReadNode.class, GlobalVariableReadNode.class, BackReferenceReadNode.class, NumberedReferenceReadNode.class }) + public final Node variable; + + public EmbeddedVariableNode(int startOffset, int length, Node variable) { + super(startOffset, length); + this.variable = variable; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.variable.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.variable }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitEmbeddedVariableNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("variable: "); + builder.append(this.variable.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents an `ensure` clause in a `begin` statement.
+     *
+     *     begin
+     *       foo
+     *     ensure
+     *     ^^^^^^
+     *       bar
+     *     end
+     * 
+ */ + public static final class EnsureNode extends Node { + @Nullable + public final StatementsNode statements; + + public EnsureNode(int startOffset, int length, StatementsNode statements) { + super(startOffset, length); + this.statements = statements; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.statements != null) { + this.statements.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.statements }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitEnsureNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the literal `false` keyword.
+     *
+     *     false
+     *     ^^^^^
+     * 
+ */ + public static final class FalseNode extends Node { + + public FalseNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitFalseNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents a find pattern in pattern matching.
+     *
+     *     foo in *bar, baz, *qux
+     *            ^^^^^^^^^^^^^^^
+     *
+     *     foo in [*bar, baz, *qux]
+     *            ^^^^^^^^^^^^^^^^^
+     *
+     *     foo in Foo(*bar, baz, *qux)
+     *            ^^^^^^^^^^^^^^^^^^^^
+     *
+     *     foo => *bar, baz, *qux
+     *            ^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class FindPatternNode extends Node { + /** + *
+         * Represents the optional constant preceding the pattern
+         *
+         *     foo in Foo(*bar, baz, *qux)
+         *            ^^^
+         * 
+ */ + @Nullable + @UnionType({ ConstantPathNode.class, ConstantReadNode.class }) + public final Node constant; + /** + *
+         * Represents the first wildcard node in the pattern.
+         *
+         *     foo in *bar, baz, *qux
+         *            ^^^^
+         *
+         *     foo in Foo(*bar, baz, *qux)
+         *                ^^^^
+         * 
+ */ + public final SplatNode left; + /** + *
+         * Represents the nodes in between the wildcards.
+         *
+         *     foo in *bar, baz, *qux
+         *                  ^^^
+         *
+         *     foo in Foo(*bar, baz, 1, *qux)
+         *                      ^^^^^^
+         * 
+ */ + public final Node[] requireds; + /** + *
+         * Represents the second wildcard node in the pattern.
+         *
+         *     foo in *bar, baz, *qux
+         *                       ^^^^
+         *
+         *     foo in Foo(*bar, baz, *qux)
+         *                           ^^^^
+         * 
+ */ + public final SplatNode right; + + public FindPatternNode(int startOffset, int length, Node constant, SplatNode left, Node[] requireds, SplatNode right) { + super(startOffset, length); + this.constant = constant; + this.left = left; + this.requireds = requireds; + this.right = right; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.constant != null) { + this.constant.accept(visitor); + } + this.left.accept(visitor); + for (Nodes.Node child : this.requireds) { + child.accept(visitor); + } + this.right.accept(visitor); + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.add(this.constant); + childNodes.add(this.left); + childNodes.addAll(Arrays.asList(this.requireds)); + childNodes.add(this.right); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitFindPatternNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("constant: "); + builder.append(this.constant == null ? "null\n" : this.constant.toString(nextIndent)); + builder.append(nextIndent); + builder.append("left: "); + builder.append(this.left.toString(nextIndent)); + builder.append(nextIndent); + builder.append("requireds: "); + builder.append('\n'); + for (Node child : this.requireds) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("right: "); + builder.append(this.right.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `..` or `...` operators to create flip flops.
+     *
+     *     baz if foo .. bar
+     *            ^^^^^^^^^^
+     * 
+ */ + public static final class FlipFlopNode extends Node { + public final short flags; + @Nullable + public final Node left; + @Nullable + public final Node right; + + public FlipFlopNode(int startOffset, int length, short flags, Node left, Node right) { + super(startOffset, length); + this.flags = flags; + this.left = left; + this.right = right; + } + + public boolean isExcludeEnd() { + return RangeFlags.isExcludeEnd(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.left != null) { + this.left.accept(visitor); + } + if (this.right != null) { + this.right.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.left, this.right }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitFlipFlopNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("RangeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("left: "); + builder.append(this.left == null ? "null\n" : this.left.toString(nextIndent)); + builder.append(nextIndent); + builder.append("right: "); + builder.append(this.right == null ? "null\n" : this.right.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a floating point number literal.
+     *
+     *     1.0
+     *     ^^^
+     * 
+ */ + public static final class FloatNode extends Node { + /** + *
+         * The value of the floating point number as a Float.
+         * 
+ */ + public final double value; + + public FloatNode(int startOffset, int length, double value) { + super(startOffset, length); + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitFloatNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `for` keyword.
+     *
+     *     for i in a end
+     *     ^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ForNode extends Node { + /** + *
+         * The index expression for `for` loops.
+         *
+         *     for i in a end
+         *         ^
+         * 
+ */ + @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class, MultiTargetNode.class }) + public final Node index; + /** + *
+         * The collection to iterate over.
+         *
+         *     for i in a end
+         *              ^
+         * 
+ */ + public final Node collection; + /** + *
+         * Represents the body of statements to execute for each iteration of the loop.
+         *
+         *     for i in a
+         *       foo(i)
+         *       ^^^^^^
+         *     end
+         * 
+ */ + @Nullable + public final StatementsNode statements; + + public ForNode(int startOffset, int length, Node index, Node collection, StatementsNode statements) { + super(startOffset, length); + this.index = index; + this.collection = collection; + this.statements = statements; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.index.accept(visitor); + this.collection.accept(visitor); + if (this.statements != null) { + this.statements.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.index, this.collection, this.statements }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitForNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("index: "); + builder.append(this.index.toString(nextIndent)); + builder.append(nextIndent); + builder.append("collection: "); + builder.append(this.collection.toString(nextIndent)); + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents forwarding all arguments to this method to another method.
+     *
+     *     def foo(...)
+     *       bar(...)
+     *           ^^^
+     *     end
+     * 
+ */ + public static final class ForwardingArgumentsNode extends Node { + + public ForwardingArgumentsNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitForwardingArgumentsNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the forwarding parameter in a method, block, or lambda declaration.
+     *
+     *     def foo(...)
+     *             ^^^
+     *     end
+     * 
+ */ + public static final class ForwardingParameterNode extends Node { + + public ForwardingParameterNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitForwardingParameterNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `super` keyword without parentheses or arguments, but which might have a block.
+     *
+     *     super
+     *     ^^^^^
+     *
+     *     super { 123 }
+     *     ^^^^^^^^^^^^^
+     *
+     * If it has any other arguments, it would be a `SuperNode` instead.
+     * 
+ */ + public static final class ForwardingSuperNode extends Node { + /** + *
+         * All other arguments are forwarded as normal, except the original block is replaced with the new block.
+         * 
+ */ + @Nullable + public final BlockNode block; + + public ForwardingSuperNode(int startOffset, int length, BlockNode block) { + super(startOffset, length); + this.block = block; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.block != null) { + this.block.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.block }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitForwardingSuperNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("block: "); + builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `&&=` operator for assignment to a global variable.
+     *
+     *     $target &&= value
+     *     ^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class GlobalVariableAndWriteNode extends Node { + public final byte[] name; + public final Node value; + + public GlobalVariableAndWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitGlobalVariableAndWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents assigning to a global variable using an operator that isn't `=`.
+     *
+     *     $target += value
+     *     ^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class GlobalVariableOperatorWriteNode extends Node { + public final byte[] name; + public final Node value; + public final byte[] binary_operator; + + public GlobalVariableOperatorWriteNode(int startOffset, int length, byte[] name, Node value, byte[] binary_operator) { + super(startOffset, length); + this.name = name; + this.value = value; + this.binary_operator = binary_operator; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitGlobalVariableOperatorWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + builder.append(nextIndent); + builder.append("binary_operator: "); + builder.append('"').append(asString(this.binary_operator)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `||=` operator for assignment to a global variable.
+     *
+     *     $target ||= value
+     *     ^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class GlobalVariableOrWriteNode extends Node { + public final byte[] name; + public final Node value; + + public GlobalVariableOrWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitGlobalVariableOrWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents referencing a global variable.
+     *
+     *     $foo
+     *     ^^^^
+     * 
+ */ + public static final class GlobalVariableReadNode extends Node { + /** + *
+         * The name of the global variable, which is a `$` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifier). Alternatively, it can be one of the special global variables designated by a symbol.
+         *
+         *     $foo   # name `:$foo`
+         *
+         *     $_Test # name `:$_Test`
+         * 
+ */ + public final byte[] name; + + public GlobalVariableReadNode(int startOffset, int length, byte[] name) { + super(startOffset, length); + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitGlobalVariableReadNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to a global variable in a context that doesn't have an explicit value.
+     *
+     *     $foo, $bar = baz
+     *     ^^^^  ^^^^
+     * 
+ */ + public static final class GlobalVariableTargetNode extends Node { + public final byte[] name; + + public GlobalVariableTargetNode(int startOffset, int length, byte[] name) { + super(startOffset, length); + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitGlobalVariableTargetNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to a global variable.
+     *
+     *     $foo = 1
+     *     ^^^^^^^^
+     * 
+ */ + public static final class GlobalVariableWriteNode extends Node { + /** + *
+         * The name of the global variable, which is a `$` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifier). Alternatively, it can be one of the special global variables designated by a symbol.
+         *
+         *     $foo = :bar  # name `:$foo`
+         *
+         *     $_Test = 123 # name `:$_Test`
+         * 
+ */ + public final byte[] name; + /** + *
+         * The value to write to the global variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     $foo = :bar
+         *            ^^^^
+         *
+         *     $-xyz = 123
+         *             ^^^
+         * 
+ */ + public final Node value; + + public GlobalVariableWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitGlobalVariableWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a hash literal.
+     *
+     *     { a => b }
+     *     ^^^^^^^^^^
+     * 
+ */ + public static final class HashNode extends Node { + /** + *
+         * The elements of the hash. These can be either `AssocNode`s or `AssocSplatNode`s.
+         *
+         *     { a: b }
+         *       ^^^^
+         *
+         *     { **foo }
+         *       ^^^^^
+         * 
+ */ + @UnionType({ AssocNode.class, AssocSplatNode.class }) + public final Node[] elements; + + public HashNode(int startOffset, int length, Node[] elements) { + super(startOffset, length); + this.elements = elements; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.elements) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.elements)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitHashNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("elements: "); + builder.append('\n'); + for (Node child : this.elements) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents a hash pattern in pattern matching.
+     *
+     *     foo => { a: 1, b: 2 }
+     *            ^^^^^^^^^^^^^^
+     *
+     *     foo => { a: 1, b: 2, **c }
+     *            ^^^^^^^^^^^^^^^^^^^
+     *
+     *     foo => Bar[a: 1, b: 2]
+     *            ^^^^^^^^^^^^^^^
+     *
+     *     foo in { a: 1, b: 2 }
+     *            ^^^^^^^^^^^^^^
+     * 
+ */ + public static final class HashPatternNode extends Node { + /** + *
+         * Represents the optional constant preceding the Hash.
+         *
+         *     foo => Bar[a: 1, b: 2]
+         *          ^^^
+         *
+         *     foo => Bar::Baz[a: 1, b: 2]
+         *          ^^^^^^^^
+         * 
+ */ + @Nullable + @UnionType({ ConstantPathNode.class, ConstantReadNode.class }) + public final Node constant; + /** + *
+         * Represents the explicit named hash keys and values.
+         *
+         *     foo => { a: 1, b:, ** }
+         *              ^^^^^^^^
+         * 
+ */ + public final AssocNode[] elements; + /** + *
+         * Represents the rest of the Hash keys and values. This can be named, unnamed, or explicitly forbidden via `**nil`, this last one results in a `NoKeywordsParameterNode`.
+         *
+         *     foo => { a: 1, b:, **c }
+         *                        ^^^
+         *
+         *     foo => { a: 1, b:, ** }
+         *                        ^^
+         *
+         *     foo => { a: 1, b:, **nil }
+         *                        ^^^^^
+         * 
+ */ + @Nullable + @UnionType({ AssocSplatNode.class, NoKeywordsParameterNode.class }) + public final Node rest; + + public HashPatternNode(int startOffset, int length, Node constant, AssocNode[] elements, Node rest) { + super(startOffset, length); + this.constant = constant; + this.elements = elements; + this.rest = rest; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.constant != null) { + this.constant.accept(visitor); + } + for (Nodes.Node child : this.elements) { + child.accept(visitor); + } + if (this.rest != null) { + this.rest.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.add(this.constant); + childNodes.addAll(Arrays.asList(this.elements)); + childNodes.add(this.rest); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitHashPatternNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("constant: "); + builder.append(this.constant == null ? "null\n" : this.constant.toString(nextIndent)); + builder.append(nextIndent); + builder.append("elements: "); + builder.append('\n'); + for (Node child : this.elements) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("rest: "); + builder.append(this.rest == null ? "null\n" : this.rest.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `if` keyword, either in the block form or the modifier form, or a ternary expression.
+     *
+     *     bar if foo
+     *     ^^^^^^^^^^
+     *
+     *     if foo then bar end
+     *     ^^^^^^^^^^^^^^^^^^^
+     *
+     *     foo ? bar : baz
+     *     ^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class IfNode extends Node { + /** + *
+         * The node for the condition the `IfNode` is testing.
+         *
+         *     if foo
+         *        ^^^
+         *       bar
+         *     end
+         *
+         *     bar if foo
+         *            ^^^
+         *
+         *     foo ? bar : baz
+         *     ^^^
+         * 
+ */ + public final Node predicate; + /** + *
+         * Represents the body of statements that will be executed when the predicate is evaluated as truthy. Will be `nil` when no body is provided.
+         *
+         *     if foo
+         *       bar
+         *       ^^^
+         *       baz
+         *       ^^^
+         *     end
+         * 
+ */ + @Nullable + public final StatementsNode statements; + /** + *
+         * Represents an `ElseNode` or an `IfNode` when there is an `else` or an `elsif` in the `if` statement.
+         *
+         *     if foo
+         *       bar
+         *     elsif baz
+         *     ^^^^^^^^^
+         *       qux
+         *       ^^^
+         *     end
+         *     ^^^
+         *
+         *     if foo then bar else baz end
+         *                     ^^^^^^^^^^^^
+         * 
+ */ + @Nullable + @UnionType({ ElseNode.class, IfNode.class }) + public final Node subsequent; + + public IfNode(int startOffset, int length, Node predicate, StatementsNode statements, Node subsequent) { + super(startOffset, length); + this.predicate = predicate; + this.statements = statements; + this.subsequent = subsequent; + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + this.predicate.setNewLineFlag(source, newlineMarked); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.predicate.accept(visitor); + if (this.statements != null) { + this.statements.accept(visitor); + } + if (this.subsequent != null) { + this.subsequent.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.predicate, this.statements, this.subsequent }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitIfNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("predicate: "); + builder.append(this.predicate.toString(nextIndent)); + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + builder.append(nextIndent); + builder.append("subsequent: "); + builder.append(this.subsequent == null ? "null\n" : this.subsequent.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents an imaginary number literal.
+     *
+     *     1.0i
+     *     ^^^^
+     * 
+ */ + public static final class ImaginaryNode extends Node { + @UnionType({ FloatNode.class, IntegerNode.class, RationalNode.class }) + public final Node numeric; + + public ImaginaryNode(int startOffset, int length, Node numeric) { + super(startOffset, length); + this.numeric = numeric; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.numeric.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.numeric }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitImaginaryNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("numeric: "); + builder.append(this.numeric.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a node that is implicitly being added to the tree but doesn't correspond directly to a node in the source.
+     *
+     *     { foo: }
+     *       ^^^^
+     *
+     *     { Foo: }
+     *       ^^^^
+     *
+     *     foo in { bar: }
+     *              ^^^^
+     * 
+ */ + public static final class ImplicitNode extends Node { + @UnionType({ LocalVariableReadNode.class, CallNode.class, ConstantReadNode.class, LocalVariableTargetNode.class }) + public final Node value; + + public ImplicitNode(int startOffset, int length, Node value) { + super(startOffset, length); + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitImplicitNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents using a trailing comma to indicate an implicit rest parameter.
+     *
+     *     foo { |bar,| }
+     *               ^
+     *
+     *     foo in [bar,]
+     *                ^
+     *
+     *     for foo, in bar do end
+     *            ^
+     *
+     *     foo, = bar
+     *        ^
+     * 
+ */ + public static final class ImplicitRestNode extends Node { + + public ImplicitRestNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitImplicitRestNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `in` keyword in a case statement.
+     *
+     *     case a; in b then c end
+     *             ^^^^^^^^^^^
+     * 
+ */ + public static final class InNode extends Node { + public final Node pattern; + @Nullable + public final StatementsNode statements; + + public InNode(int startOffset, int length, Node pattern, StatementsNode statements) { + super(startOffset, length); + this.pattern = pattern; + this.statements = statements; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.pattern.accept(visitor); + if (this.statements != null) { + this.statements.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.pattern, this.statements }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("pattern: "); + builder.append(this.pattern.toString(nextIndent)); + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `&&=` operator on a call to the `[]` method.
+     *
+     *     foo.bar[baz] &&= value
+     *     ^^^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class IndexAndWriteNode extends Node { + public final short flags; + @Nullable + public final Node receiver; + @Nullable + public final ArgumentsNode arguments; + @Nullable + public final BlockArgumentNode block; + public final Node value; + + public IndexAndWriteNode(int startOffset, int length, short flags, Node receiver, ArgumentsNode arguments, BlockArgumentNode block, Node value) { + super(startOffset, length); + this.flags = flags; + this.receiver = receiver; + this.arguments = arguments; + this.block = block; + this.value = value; + } + + public boolean isSafeNavigation() { + return CallNodeFlags.isSafeNavigation(flags); + } + + public boolean isVariableCall() { + return CallNodeFlags.isVariableCall(flags); + } + + public boolean isAttributeWrite() { + return CallNodeFlags.isAttributeWrite(flags); + } + + public boolean isIgnoreVisibility() { + return CallNodeFlags.isIgnoreVisibility(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.receiver != null) { + this.receiver.accept(visitor); + } + if (this.arguments != null) { + this.arguments.accept(visitor); + } + if (this.block != null) { + this.block.accept(visitor); + } + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.receiver, this.arguments, this.block, this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitIndexAndWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("CallNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("receiver: "); + builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); + builder.append(nextIndent); + builder.append("arguments: "); + builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); + builder.append(nextIndent); + builder.append("block: "); + builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of an assignment operator on a call to `[]`.
+     *
+     *     foo.bar[baz] += value
+     *     ^^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class IndexOperatorWriteNode extends Node { + public final short flags; + @Nullable + public final Node receiver; + @Nullable + public final ArgumentsNode arguments; + @Nullable + public final BlockArgumentNode block; + public final byte[] binary_operator; + public final Node value; + + public IndexOperatorWriteNode(int startOffset, int length, short flags, Node receiver, ArgumentsNode arguments, BlockArgumentNode block, byte[] binary_operator, Node value) { + super(startOffset, length); + this.flags = flags; + this.receiver = receiver; + this.arguments = arguments; + this.block = block; + this.binary_operator = binary_operator; + this.value = value; + } + + public boolean isSafeNavigation() { + return CallNodeFlags.isSafeNavigation(flags); + } + + public boolean isVariableCall() { + return CallNodeFlags.isVariableCall(flags); + } + + public boolean isAttributeWrite() { + return CallNodeFlags.isAttributeWrite(flags); + } + + public boolean isIgnoreVisibility() { + return CallNodeFlags.isIgnoreVisibility(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.receiver != null) { + this.receiver.accept(visitor); + } + if (this.arguments != null) { + this.arguments.accept(visitor); + } + if (this.block != null) { + this.block.accept(visitor); + } + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.receiver, this.arguments, this.block, this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitIndexOperatorWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("CallNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("receiver: "); + builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); + builder.append(nextIndent); + builder.append("arguments: "); + builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); + builder.append(nextIndent); + builder.append("block: "); + builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); + builder.append(nextIndent); + builder.append("binary_operator: "); + builder.append('"').append(asString(this.binary_operator)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `||=` operator on a call to `[]`.
+     *
+     *     foo.bar[baz] ||= value
+     *     ^^^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class IndexOrWriteNode extends Node { + public final short flags; + @Nullable + public final Node receiver; + @Nullable + public final ArgumentsNode arguments; + @Nullable + public final BlockArgumentNode block; + public final Node value; + + public IndexOrWriteNode(int startOffset, int length, short flags, Node receiver, ArgumentsNode arguments, BlockArgumentNode block, Node value) { + super(startOffset, length); + this.flags = flags; + this.receiver = receiver; + this.arguments = arguments; + this.block = block; + this.value = value; + } + + public boolean isSafeNavigation() { + return CallNodeFlags.isSafeNavigation(flags); + } + + public boolean isVariableCall() { + return CallNodeFlags.isVariableCall(flags); + } + + public boolean isAttributeWrite() { + return CallNodeFlags.isAttributeWrite(flags); + } + + public boolean isIgnoreVisibility() { + return CallNodeFlags.isIgnoreVisibility(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.receiver != null) { + this.receiver.accept(visitor); + } + if (this.arguments != null) { + this.arguments.accept(visitor); + } + if (this.block != null) { + this.block.accept(visitor); + } + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.receiver, this.arguments, this.block, this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitIndexOrWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("CallNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("receiver: "); + builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); + builder.append(nextIndent); + builder.append("arguments: "); + builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); + builder.append(nextIndent); + builder.append("block: "); + builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents assigning to an index.
+     *
+     *     foo[bar], = 1
+     *     ^^^^^^^^
+     *
+     *     begin
+     *     rescue => foo[bar]
+     *               ^^^^^^^^
+     *     end
+     *
+     *     for foo[bar] in baz do end
+     *         ^^^^^^^^
+     * 
+ */ + public static final class IndexTargetNode extends Node { + public final short flags; + public final Node receiver; + @Nullable + public final ArgumentsNode arguments; + @Nullable + public final BlockArgumentNode block; + + public IndexTargetNode(int startOffset, int length, short flags, Node receiver, ArgumentsNode arguments, BlockArgumentNode block) { + super(startOffset, length); + this.flags = flags; + this.receiver = receiver; + this.arguments = arguments; + this.block = block; + } + + public boolean isSafeNavigation() { + return CallNodeFlags.isSafeNavigation(flags); + } + + public boolean isVariableCall() { + return CallNodeFlags.isVariableCall(flags); + } + + public boolean isAttributeWrite() { + return CallNodeFlags.isAttributeWrite(flags); + } + + public boolean isIgnoreVisibility() { + return CallNodeFlags.isIgnoreVisibility(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.receiver.accept(visitor); + if (this.arguments != null) { + this.arguments.accept(visitor); + } + if (this.block != null) { + this.block.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.receiver, this.arguments, this.block }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitIndexTargetNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("CallNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("receiver: "); + builder.append(this.receiver.toString(nextIndent)); + builder.append(nextIndent); + builder.append("arguments: "); + builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); + builder.append(nextIndent); + builder.append("block: "); + builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `&&=` operator for assignment to an instance variable.
+     *
+     *     @target &&= value
+     *     ^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class InstanceVariableAndWriteNode extends Node { + public final byte[] name; + public final Node value; + + public InstanceVariableAndWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInstanceVariableAndWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents assigning to an instance variable using an operator that isn't `=`.
+     *
+     *     @target += value
+     *     ^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class InstanceVariableOperatorWriteNode extends Node { + public final byte[] name; + public final Node value; + public final byte[] binary_operator; + + public InstanceVariableOperatorWriteNode(int startOffset, int length, byte[] name, Node value, byte[] binary_operator) { + super(startOffset, length); + this.name = name; + this.value = value; + this.binary_operator = binary_operator; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInstanceVariableOperatorWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + builder.append(nextIndent); + builder.append("binary_operator: "); + builder.append('"').append(asString(this.binary_operator)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `||=` operator for assignment to an instance variable.
+     *
+     *     @target ||= value
+     *     ^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class InstanceVariableOrWriteNode extends Node { + public final byte[] name; + public final Node value; + + public InstanceVariableOrWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInstanceVariableOrWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents referencing an instance variable.
+     *
+     *     @foo
+     *     ^^^^
+     * 
+ */ + public static final class InstanceVariableReadNode extends Node { + /** + *
+         * The name of the instance variable, which is a `@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
+         *
+         *     @x     # name `:@x`
+         *
+         *     @_test # name `:@_test`
+         * 
+ */ + public final byte[] name; + + public InstanceVariableReadNode(int startOffset, int length, byte[] name) { + super(startOffset, length); + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInstanceVariableReadNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to an instance variable in a context that doesn't have an explicit value.
+     *
+     *     @foo, @bar = baz
+     *     ^^^^  ^^^^
+     * 
+ */ + public static final class InstanceVariableTargetNode extends Node { + public final byte[] name; + + public InstanceVariableTargetNode(int startOffset, int length, byte[] name) { + super(startOffset, length); + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInstanceVariableTargetNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to an instance variable.
+     *
+     *     @foo = 1
+     *     ^^^^^^^^
+     * 
+ */ + public static final class InstanceVariableWriteNode extends Node { + /** + *
+         * The name of the instance variable, which is a `@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
+         *
+         *     @x = :y       # name `:@x`
+         *
+         *     @_foo = "bar" # name `@_foo`
+         * 
+ */ + public final byte[] name; + /** + *
+         * The value to write to the instance variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     @foo = :bar
+         *            ^^^^
+         *
+         *     @_x = 1234
+         *           ^^^^
+         * 
+ */ + public final Node value; + + public InstanceVariableWriteNode(int startOffset, int length, byte[] name, Node value) { + super(startOffset, length); + this.name = name; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInstanceVariableWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents an integer number literal.
+     *
+     *     1
+     *     ^
+     * 
+ */ + public static final class IntegerNode extends Node { + public final short flags; + /** + *
+         * The value of the integer literal as a number.
+         * 
+ */ + public final Object value; + + public IntegerNode(int startOffset, int length, short flags, Object value) { + super(startOffset, length); + this.flags = flags; + this.value = value; + } + + public boolean isBinary() { + return IntegerBaseFlags.isBinary(flags); + } + + public boolean isDecimal() { + return IntegerBaseFlags.isDecimal(flags); + } + + public boolean isOctal() { + return IntegerBaseFlags.isOctal(flags); + } + + public boolean isHexadecimal() { + return IntegerBaseFlags.isHexadecimal(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitIntegerNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("IntegerBaseFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents a regular expression literal that contains interpolation that is being used in the predicate of a conditional to implicitly match against the last line read by an IO object.
+     *
+     *     if /foo #{bar} baz/ then end
+     *        ^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class InterpolatedMatchLastLineNode extends Node { + public final short flags; + @UnionType({ StringNode.class, EmbeddedStatementsNode.class, EmbeddedVariableNode.class }) + public final Node[] parts; + + public InterpolatedMatchLastLineNode(int startOffset, int length, short flags, Node[] parts) { + super(startOffset, length); + this.flags = flags; + this.parts = parts; + } + + public boolean isIgnoreCase() { + return RegularExpressionFlags.isIgnoreCase(flags); + } + + public boolean isExtended() { + return RegularExpressionFlags.isExtended(flags); + } + + public boolean isMultiLine() { + return RegularExpressionFlags.isMultiLine(flags); + } + + public boolean isOnce() { + return RegularExpressionFlags.isOnce(flags); + } + + public boolean isEucJp() { + return RegularExpressionFlags.isEucJp(flags); + } + + public boolean isAscii8bit() { + return RegularExpressionFlags.isAscii8bit(flags); + } + + public boolean isWindows31j() { + return RegularExpressionFlags.isWindows31j(flags); + } + + public boolean isUtf8() { + return RegularExpressionFlags.isUtf8(flags); + } + + public boolean isForcedUtf8Encoding() { + return RegularExpressionFlags.isForcedUtf8Encoding(flags); + } + + public boolean isForcedBinaryEncoding() { + return RegularExpressionFlags.isForcedBinaryEncoding(flags); + } + + public boolean isForcedUsAsciiEncoding() { + return RegularExpressionFlags.isForcedUsAsciiEncoding(flags); + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + Node first = this.parts.length > 0 ? this.parts[0] : null; + if (first != null) { + first.setNewLineFlag(source, newlineMarked); + } + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.parts) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.parts)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInterpolatedMatchLastLineNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("RegularExpressionFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("parts: "); + builder.append('\n'); + for (Node child : this.parts) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents a regular expression literal that contains interpolation.
+     *
+     *     /foo #{bar} baz/
+     *     ^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class InterpolatedRegularExpressionNode extends Node { + public final short flags; + @UnionType({ StringNode.class, EmbeddedStatementsNode.class, EmbeddedVariableNode.class }) + public final Node[] parts; + + public InterpolatedRegularExpressionNode(int startOffset, int length, short flags, Node[] parts) { + super(startOffset, length); + this.flags = flags; + this.parts = parts; + } + + public boolean isIgnoreCase() { + return RegularExpressionFlags.isIgnoreCase(flags); + } + + public boolean isExtended() { + return RegularExpressionFlags.isExtended(flags); + } + + public boolean isMultiLine() { + return RegularExpressionFlags.isMultiLine(flags); + } + + public boolean isOnce() { + return RegularExpressionFlags.isOnce(flags); + } + + public boolean isEucJp() { + return RegularExpressionFlags.isEucJp(flags); + } + + public boolean isAscii8bit() { + return RegularExpressionFlags.isAscii8bit(flags); + } + + public boolean isWindows31j() { + return RegularExpressionFlags.isWindows31j(flags); + } + + public boolean isUtf8() { + return RegularExpressionFlags.isUtf8(flags); + } + + public boolean isForcedUtf8Encoding() { + return RegularExpressionFlags.isForcedUtf8Encoding(flags); + } + + public boolean isForcedBinaryEncoding() { + return RegularExpressionFlags.isForcedBinaryEncoding(flags); + } + + public boolean isForcedUsAsciiEncoding() { + return RegularExpressionFlags.isForcedUsAsciiEncoding(flags); + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + Node first = this.parts.length > 0 ? this.parts[0] : null; + if (first != null) { + first.setNewLineFlag(source, newlineMarked); + } + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.parts) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.parts)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInterpolatedRegularExpressionNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("RegularExpressionFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("parts: "); + builder.append('\n'); + for (Node child : this.parts) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents a string literal that contains interpolation.
+     *
+     *     "foo #{bar} baz"
+     *     ^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class InterpolatedStringNode extends Node { + public final short flags; + @UnionType({ StringNode.class, EmbeddedStatementsNode.class, EmbeddedVariableNode.class, InterpolatedStringNode.class }) + public final Node[] parts; + + public InterpolatedStringNode(int startOffset, int length, short flags, Node[] parts) { + super(startOffset, length); + this.flags = flags; + this.parts = parts; + } + + public boolean isFrozen() { + return InterpolatedStringNodeFlags.isFrozen(flags); + } + + public boolean isMutable() { + return InterpolatedStringNodeFlags.isMutable(flags); + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + Node first = this.parts.length > 0 ? this.parts[0] : null; + if (first != null) { + first.setNewLineFlag(source, newlineMarked); + } + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.parts) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.parts)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInterpolatedStringNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("InterpolatedStringNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("parts: "); + builder.append('\n'); + for (Node child : this.parts) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents a symbol literal that contains interpolation.
+     *
+     *     :"foo #{bar} baz"
+     *     ^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class InterpolatedSymbolNode extends Node { + @UnionType({ StringNode.class, EmbeddedStatementsNode.class, EmbeddedVariableNode.class }) + public final Node[] parts; + + public InterpolatedSymbolNode(int startOffset, int length, Node[] parts) { + super(startOffset, length); + this.parts = parts; + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + Node first = this.parts.length > 0 ? this.parts[0] : null; + if (first != null) { + first.setNewLineFlag(source, newlineMarked); + } + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.parts) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.parts)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInterpolatedSymbolNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("parts: "); + builder.append('\n'); + for (Node child : this.parts) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents an xstring literal that contains interpolation.
+     *
+     *     `foo #{bar} baz`
+     *     ^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class InterpolatedXStringNode extends Node { + @UnionType({ StringNode.class, EmbeddedStatementsNode.class, EmbeddedVariableNode.class }) + public final Node[] parts; + + public InterpolatedXStringNode(int startOffset, int length, Node[] parts) { + super(startOffset, length); + this.parts = parts; + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + Node first = this.parts.length > 0 ? this.parts[0] : null; + if (first != null) { + first.setNewLineFlag(source, newlineMarked); + } + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.parts) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.parts)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitInterpolatedXStringNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("parts: "); + builder.append('\n'); + for (Node child : this.parts) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents reading from the implicit `it` local variable.
+     *
+     *     -> { it }
+     *          ^^
+     * 
+ */ + public static final class ItLocalVariableReadNode extends Node { + + public ItLocalVariableReadNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitItLocalVariableReadNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents an implicit set of parameters through the use of the `it` keyword within a block or lambda.
+     *
+     *     -> { it + it }
+     *     ^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ItParametersNode extends Node { + + public ItParametersNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitItParametersNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents a hash literal without opening and closing braces.
+     *
+     *     foo(a: b)
+     *         ^^^^
+     * 
+ */ + public static final class KeywordHashNode extends Node { + public final short flags; + @UnionType({ AssocNode.class, AssocSplatNode.class }) + public final Node[] elements; + + public KeywordHashNode(int startOffset, int length, short flags, Node[] elements) { + super(startOffset, length); + this.flags = flags; + this.elements = elements; + } + + public boolean isSymbolKeys() { + return KeywordHashNodeFlags.isSymbolKeys(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.elements) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.elements)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitKeywordHashNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("KeywordHashNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("elements: "); + builder.append('\n'); + for (Node child : this.elements) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents a keyword rest parameter to a method, block, or lambda definition.
+     *
+     *     def a(**b)
+     *           ^^^
+     *     end
+     * 
+ */ + public static final class KeywordRestParameterNode extends Node { + public final short flags; + @Nullable + public final byte[] name; + + public KeywordRestParameterNode(int startOffset, int length, short flags, byte[] name) { + super(startOffset, length); + this.flags = flags; + this.name = name; + } + + public boolean isRepeatedParameter() { + return ParameterFlags.isRepeatedParameter(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitKeywordRestParameterNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("ParameterFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("name: "); + builder.append(this.name == null ? "null" : "\"" + asString(this.name) + "\""); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents using a lambda literal (not the lambda method call).
+     *
+     *     ->(value) { value * 2 }
+     *     ^^^^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class LambdaNode extends Node { + public final byte[][] locals; + @Nullable + @UnionType({ BlockParametersNode.class, NumberedParametersNode.class, ItParametersNode.class }) + public final Node parameters; + @Nullable + @UnionType({ StatementsNode.class, BeginNode.class }) + public final Node body; + + public LambdaNode(int startOffset, int length, byte[][] locals, Node parameters, Node body) { + super(startOffset, length); + this.locals = locals; + this.parameters = parameters; + this.body = body; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.parameters != null) { + this.parameters.accept(visitor); + } + if (this.body != null) { + this.body.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.parameters, this.body }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitLambdaNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("locals: "); + builder.append('\n'); + for (byte[] constant : this.locals) { + builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); + } + builder.append(nextIndent); + builder.append("parameters: "); + builder.append(this.parameters == null ? "null\n" : this.parameters.toString(nextIndent)); + builder.append(nextIndent); + builder.append("body: "); + builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `&&=` operator for assignment to a local variable.
+     *
+     *     target &&= value
+     *     ^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class LocalVariableAndWriteNode extends Node { + public final Node value; + public final byte[] name; + public final int depth; + + public LocalVariableAndWriteNode(int startOffset, int length, Node value, byte[] name, int depth) { + super(startOffset, length); + this.value = value; + this.name = name; + this.depth = depth; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitLocalVariableAndWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("depth: "); + builder.append(this.depth); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents assigning to a local variable using an operator that isn't `=`.
+     *
+     *     target += value
+     *     ^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class LocalVariableOperatorWriteNode extends Node { + public final Node value; + public final byte[] name; + public final byte[] binary_operator; + public final int depth; + + public LocalVariableOperatorWriteNode(int startOffset, int length, Node value, byte[] name, byte[] binary_operator, int depth) { + super(startOffset, length); + this.value = value; + this.name = name; + this.binary_operator = binary_operator; + this.depth = depth; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitLocalVariableOperatorWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("binary_operator: "); + builder.append('"').append(asString(this.binary_operator)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("depth: "); + builder.append(this.depth); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `||=` operator for assignment to a local variable.
+     *
+     *     target ||= value
+     *     ^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class LocalVariableOrWriteNode extends Node { + public final Node value; + public final byte[] name; + public final int depth; + + public LocalVariableOrWriteNode(int startOffset, int length, Node value, byte[] name, int depth) { + super(startOffset, length); + this.value = value; + this.name = name; + this.depth = depth; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitLocalVariableOrWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("depth: "); + builder.append(this.depth); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents reading a local variable. Note that this requires that a local variable of the same name has already been written to in the same scope, otherwise it is parsed as a method call.
+     *
+     *     foo
+     *     ^^^
+     * 
+ */ + public static final class LocalVariableReadNode extends Node { + /** + *
+         * The name of the local variable, which is an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
+         *
+         *     x      # name `:x`
+         *
+         *     _Test  # name `:_Test`
+         *
+         * Note that this can also be an underscore followed by a number for the default block parameters.
+         *
+         *     _1     # name `:_1`
+         * 
+ */ + public final byte[] name; + /** + *
+         * The number of visible scopes that should be searched to find the origin of this local variable.
+         *
+         *     foo = 1; foo # depth 0
+         *
+         *     bar = 2; tap { bar } # depth 1
+         *
+         * The specific rules for calculating the depth may differ from individual Ruby implementations, as they are not specified by the language. For more information, see [the Prism documentation](https://github.com/ruby/prism/blob/main/docs/local_variable_depth.md).
+         * 
+ */ + public final int depth; + + public LocalVariableReadNode(int startOffset, int length, byte[] name, int depth) { + super(startOffset, length); + this.name = name; + this.depth = depth; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitLocalVariableReadNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("depth: "); + builder.append(this.depth); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to a local variable in a context that doesn't have an explicit value.
+     *
+     *     foo, bar = baz
+     *     ^^^  ^^^
+     *
+     *     foo => baz
+     *            ^^^
+     * 
+ */ + public static final class LocalVariableTargetNode extends Node { + public final byte[] name; + public final int depth; + + public LocalVariableTargetNode(int startOffset, int length, byte[] name, int depth) { + super(startOffset, length); + this.name = name; + this.depth = depth; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitLocalVariableTargetNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("depth: "); + builder.append(this.depth); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents writing to a local variable.
+     *
+     *     foo = 1
+     *     ^^^^^^^
+     * 
+ */ + public static final class LocalVariableWriteNode extends Node { + /** + *
+         * The name of the local variable, which is an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
+         *
+         *     foo = :bar # name `:foo`
+         *
+         *     abc = 123  # name `:abc`
+         * 
+ */ + public final byte[] name; + /** + *
+         * The number of semantic scopes we have to traverse to find the declaration of this variable.
+         *
+         *     foo = 1         # depth 0
+         *
+         *     tap { foo = 1 } # depth 1
+         *
+         * The specific rules for calculating the depth may differ from individual Ruby implementations, as they are not specified by the language. For more information, see [the Prism documentation](https://github.com/ruby/prism/blob/main/docs/local_variable_depth.md).
+         * 
+ */ + public final int depth; + /** + *
+         * The value to write to the local variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     foo = :bar
+         *           ^^^^
+         *
+         *     abc = 1234
+         *           ^^^^
+         *
+         * Note that since the name of a local variable is known before the value is parsed, it is valid for a local variable to appear within the value of its own write.
+         *
+         *     foo = foo
+         * 
+ */ + public final Node value; + + public LocalVariableWriteNode(int startOffset, int length, byte[] name, int depth, Node value) { + super(startOffset, length); + this.name = name; + this.depth = depth; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitLocalVariableWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("depth: "); + builder.append(this.depth); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a regular expression literal used in the predicate of a conditional to implicitly match against the last line read by an IO object.
+     *
+     *     if /foo/i then end
+     *        ^^^^^^
+     * 
+ */ + public static final class MatchLastLineNode extends Node { + public final short flags; + public final byte[] unescaped; + + public MatchLastLineNode(int startOffset, int length, short flags, byte[] unescaped) { + super(startOffset, length); + this.flags = flags; + this.unescaped = unescaped; + } + + public boolean isIgnoreCase() { + return RegularExpressionFlags.isIgnoreCase(flags); + } + + public boolean isExtended() { + return RegularExpressionFlags.isExtended(flags); + } + + public boolean isMultiLine() { + return RegularExpressionFlags.isMultiLine(flags); + } + + public boolean isOnce() { + return RegularExpressionFlags.isOnce(flags); + } + + public boolean isEucJp() { + return RegularExpressionFlags.isEucJp(flags); + } + + public boolean isAscii8bit() { + return RegularExpressionFlags.isAscii8bit(flags); + } + + public boolean isWindows31j() { + return RegularExpressionFlags.isWindows31j(flags); + } + + public boolean isUtf8() { + return RegularExpressionFlags.isUtf8(flags); + } + + public boolean isForcedUtf8Encoding() { + return RegularExpressionFlags.isForcedUtf8Encoding(flags); + } + + public boolean isForcedBinaryEncoding() { + return RegularExpressionFlags.isForcedBinaryEncoding(flags); + } + + public boolean isForcedUsAsciiEncoding() { + return RegularExpressionFlags.isForcedUsAsciiEncoding(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitMatchLastLineNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("RegularExpressionFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("unescaped: "); + builder.append('"' + asString(this.unescaped) + '"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the modifier `in` operator.
+     *
+     *     foo in bar
+     *     ^^^^^^^^^^
+     * 
+ */ + public static final class MatchPredicateNode extends Node { + public final Node value; + public final Node pattern; + + public MatchPredicateNode(int startOffset, int length, Node value, Node pattern) { + super(startOffset, length); + this.value = value; + this.pattern = pattern; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + this.pattern.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value, this.pattern }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitMatchPredicateNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + builder.append(nextIndent); + builder.append("pattern: "); + builder.append(this.pattern.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `=>` operator.
+     *
+     *     foo => bar
+     *     ^^^^^^^^^^
+     * 
+ */ + public static final class MatchRequiredNode extends Node { + /** + *
+         * Represents the left-hand side of the operator.
+         *
+         *     foo => bar
+         *     ^^^
+         * 
+ */ + public final Node value; + /** + *
+         * Represents the right-hand side of the operator. The type of the node depends on the expression.
+         *
+         * Anything that looks like a local variable name (including `_`) will result in a `LocalVariableTargetNode`.
+         *
+         *     foo => a # This is equivalent to writing `a = foo`
+         *            ^
+         *
+         * Using an explicit `Array` or combining expressions with `,` will result in a `ArrayPatternNode`. This can be preceded by a constant.
+         *
+         *     foo => [a]
+         *            ^^^
+         *
+         *     foo => a, b
+         *            ^^^^
+         *
+         *     foo => Bar[a, b]
+         *            ^^^^^^^^^
+         *
+         * If the array pattern contains at least two wildcard matches, a `FindPatternNode` is created instead.
+         *
+         *     foo => *, 1, *a
+         *            ^^^^^
+         *
+         * Using an explicit `Hash` or a constant with square brackets and hash keys in the square brackets will result in a `HashPatternNode`.
+         *
+         *     foo => { a: 1, b: }
+         *
+         *     foo => Bar[a: 1, b:]
+         *
+         *     foo => Bar[**]
+         *
+         * To use any variable that needs run time evaluation, pinning is required. This results in a `PinnedVariableNode`
+         *
+         *     foo => ^a
+         *            ^^
+         *
+         * Similar, any expression can be used with pinning. This results in a `PinnedExpressionNode`.
+         *
+         *     foo => ^(a + 1)
+         *
+         * Anything else will result in the regular node for that expression, for example a `ConstantReadNode`.
+         *
+         *     foo => CONST
+         * 
+ */ + public final Node pattern; + + public MatchRequiredNode(int startOffset, int length, Node value, Node pattern) { + super(startOffset, length); + this.value = value; + this.pattern = pattern; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + this.pattern.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value, this.pattern }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitMatchRequiredNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + builder.append(nextIndent); + builder.append("pattern: "); + builder.append(this.pattern.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents writing local variables using a regular expression match with named capture groups.
+     *
+     *     /(?<foo>bar)/ =~ baz
+     *     ^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class MatchWriteNode extends Node { + public final CallNode call; + public final LocalVariableTargetNode[] targets; + + public MatchWriteNode(int startOffset, int length, CallNode call, LocalVariableTargetNode[] targets) { + super(startOffset, length); + this.call = call; + this.targets = targets; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.call.accept(visitor); + for (Nodes.Node child : this.targets) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.add(this.call); + childNodes.addAll(Arrays.asList(this.targets)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitMatchWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("call: "); + builder.append(this.call.toString(nextIndent)); + builder.append(nextIndent); + builder.append("targets: "); + builder.append('\n'); + for (Node child : this.targets) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents a node that is missing from the source and results in a syntax error.
+     * 
+ */ + public static final class MissingNode extends Node { + + public MissingNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitMissingNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents a module declaration involving the `module` keyword.
+     *
+     *     module Foo end
+     *     ^^^^^^^^^^^^^^
+     * 
+ */ + public static final class ModuleNode extends Node { + public final byte[][] locals; + @UnionType({ ConstantReadNode.class, ConstantPathNode.class }) + public final Node constant_path; + @Nullable + @UnionType({ StatementsNode.class, BeginNode.class }) + public final Node body; + public final byte[] name; + + public ModuleNode(int startOffset, int length, byte[][] locals, Node constant_path, Node body, byte[] name) { + super(startOffset, length); + this.locals = locals; + this.constant_path = constant_path; + this.body = body; + this.name = name; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.constant_path.accept(visitor); + if (this.body != null) { + this.body.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.constant_path, this.body }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitModuleNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("locals: "); + builder.append('\n'); + for (byte[] constant : this.locals) { + builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); + } + builder.append(nextIndent); + builder.append("constant_path: "); + builder.append(this.constant_path.toString(nextIndent)); + builder.append(nextIndent); + builder.append("body: "); + builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents a multi-target expression.
+     *
+     *     a, (b, c) = 1, 2, 3
+     *        ^^^^^^
+     *
+     * This can be a part of `MultiWriteNode` as above, or the target of a `for` loop
+     *
+     *     for a, b in [[1, 2], [3, 4]]
+     *         ^^^^
+     * 
+ */ + public static final class MultiTargetNode extends Node { + /** + *
+         * Represents the targets expressions before a splat node.
+         *
+         *     a, (b, c, *) = 1, 2, 3, 4, 5
+         *         ^^^^
+         *
+         * The splat node can be absent, in that case all target expressions are in the left field.
+         *
+         *     a, (b, c) = 1, 2, 3, 4, 5
+         *         ^^^^
+         * 
+ */ + @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class, MultiTargetNode.class, RequiredParameterNode.class }) + public final Node[] lefts; + /** + *
+         * Represents a splat node in the target expression.
+         *
+         *     a, (b, *c) = 1, 2, 3, 4
+         *            ^^
+         *
+         * The variable can be empty, this results in a `SplatNode` with a `nil` expression field.
+         *
+         *     a, (b, *) = 1, 2, 3, 4
+         *            ^
+         *
+         * If the `*` is omitted, this field will contain an `ImplicitRestNode`
+         *
+         *     a, (b,) = 1, 2, 3, 4
+         *          ^
+         * 
+ */ + @Nullable + @UnionType({ ImplicitRestNode.class, SplatNode.class }) + public final Node rest; + /** + *
+         * Represents the targets expressions after a splat node.
+         *
+         *     a, (*, b, c) = 1, 2, 3, 4, 5
+         *            ^^^^
+         * 
+ */ + @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class, MultiTargetNode.class, RequiredParameterNode.class }) + public final Node[] rights; + + public MultiTargetNode(int startOffset, int length, Node[] lefts, Node rest, Node[] rights) { + super(startOffset, length); + this.lefts = lefts; + this.rest = rest; + this.rights = rights; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.lefts) { + child.accept(visitor); + } + if (this.rest != null) { + this.rest.accept(visitor); + } + for (Nodes.Node child : this.rights) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.lefts)); + childNodes.add(this.rest); + childNodes.addAll(Arrays.asList(this.rights)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitMultiTargetNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("lefts: "); + builder.append('\n'); + for (Node child : this.lefts) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("rest: "); + builder.append(this.rest == null ? "null\n" : this.rest.toString(nextIndent)); + builder.append(nextIndent); + builder.append("rights: "); + builder.append('\n'); + for (Node child : this.rights) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents a write to a multi-target expression.
+     *
+     *     a, b, c = 1, 2, 3
+     *     ^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class MultiWriteNode extends Node { + /** + *
+         * Represents the targets expressions before a splat node.
+         *
+         *     a, b, * = 1, 2, 3, 4, 5
+         *     ^^^^
+         *
+         * The splat node can be absent, in that case all target expressions are in the left field.
+         *
+         *     a, b, c = 1, 2, 3, 4, 5
+         *     ^^^^^^^
+         * 
+ */ + @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class, MultiTargetNode.class }) + public final Node[] lefts; + /** + *
+         * Represents a splat node in the target expression.
+         *
+         *     a, b, *c = 1, 2, 3, 4
+         *           ^^
+         *
+         * The variable can be empty, this results in a `SplatNode` with a `nil` expression field.
+         *
+         *     a, b, * = 1, 2, 3, 4
+         *           ^
+         *
+         * If the `*` is omitted, this field will contain an `ImplicitRestNode`
+         *
+         *     a, b, = 1, 2, 3, 4
+         *         ^
+         * 
+ */ + @Nullable + @UnionType({ ImplicitRestNode.class, SplatNode.class }) + public final Node rest; + /** + *
+         * Represents the targets expressions after a splat node.
+         *
+         *     a, *, b, c = 1, 2, 3, 4, 5
+         *           ^^^^
+         * 
+ */ + @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class, MultiTargetNode.class }) + public final Node[] rights; + /** + *
+         * The value to write to the targets. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     a, b, c = 1, 2, 3
+         *               ^^^^^^^
+         * 
+ */ + public final Node value; + + public MultiWriteNode(int startOffset, int length, Node[] lefts, Node rest, Node[] rights, Node value) { + super(startOffset, length); + this.lefts = lefts; + this.rest = rest; + this.rights = rights; + this.value = value; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.lefts) { + child.accept(visitor); + } + if (this.rest != null) { + this.rest.accept(visitor); + } + for (Nodes.Node child : this.rights) { + child.accept(visitor); + } + this.value.accept(visitor); + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.lefts)); + childNodes.add(this.rest); + childNodes.addAll(Arrays.asList(this.rights)); + childNodes.add(this.value); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitMultiWriteNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("lefts: "); + builder.append('\n'); + for (Node child : this.lefts) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("rest: "); + builder.append(this.rest == null ? "null\n" : this.rest.toString(nextIndent)); + builder.append(nextIndent); + builder.append("rights: "); + builder.append('\n'); + for (Node child : this.rights) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `next` keyword.
+     *
+     *     next 1
+     *     ^^^^^^
+     * 
+ */ + public static final class NextNode extends Node { + @Nullable + public final ArgumentsNode arguments; + + public NextNode(int startOffset, int length, ArgumentsNode arguments) { + super(startOffset, length); + this.arguments = arguments; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.arguments != null) { + this.arguments.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.arguments }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitNextNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("arguments: "); + builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `nil` keyword.
+     *
+     *     nil
+     *     ^^^
+     * 
+ */ + public static final class NilNode extends Node { + + public NilNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitNilNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents the use of `&nil` inside method arguments.
+     *
+     *     def a(&nil)
+     *           ^^^^
+     *     end
+     * 
+ */ + public static final class NoBlockParameterNode extends Node { + + public NoBlockParameterNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitNoBlockParameterNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents the use of `**nil` inside method arguments.
+     *
+     *     def a(**nil)
+     *           ^^^^^
+     *     end
+     * 
+ */ + public static final class NoKeywordsParameterNode extends Node { + + public NoKeywordsParameterNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitNoKeywordsParameterNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents an implicit set of parameters through the use of numbered parameters within a block or lambda.
+     *
+     *     -> { _1 + _2 }
+     *     ^^^^^^^^^^^^^^
+     * 
+ */ + public static final class NumberedParametersNode extends Node { + public final int maximum; + + public NumberedParametersNode(int startOffset, int length, int maximum) { + super(startOffset, length); + this.maximum = maximum; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitNumberedParametersNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("maximum: "); + builder.append(this.maximum); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents reading a numbered reference to a capture in the previous match.
+     *
+     *     $1
+     *     ^^
+     * 
+ */ + public static final class NumberedReferenceReadNode extends Node { + /** + *
+         * The (1-indexed, from the left) number of the capture group. Numbered references that are too large result in this value being `0`.
+         *
+         *     $1          # number `1`
+         *
+         *     $5432       # number `5432`
+         *
+         *     $4294967296 # number `0`
+         * 
+ */ + public final int number; + + public NumberedReferenceReadNode(int startOffset, int length, int number) { + super(startOffset, length); + this.number = number; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitNumberedReferenceReadNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("number: "); + builder.append(this.number); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents an optional keyword parameter to a method, block, or lambda definition.
+     *
+     *     def a(b: 1)
+     *           ^^^^
+     *     end
+     * 
+ */ + public static final class OptionalKeywordParameterNode extends Node { + public final short flags; + public final byte[] name; + public final Node value; + + public OptionalKeywordParameterNode(int startOffset, int length, short flags, byte[] name, Node value) { + super(startOffset, length); + this.flags = flags; + this.name = name; + this.value = value; + } + + public boolean isRepeatedParameter() { + return ParameterFlags.isRepeatedParameter(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitOptionalKeywordParameterNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("ParameterFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents an optional parameter to a method, block, or lambda definition.
+     *
+     *     def a(b = 1)
+     *           ^^^^^
+     *     end
+     * 
+ */ + public static final class OptionalParameterNode extends Node { + public final short flags; + public final byte[] name; + public final Node value; + + public OptionalParameterNode(int startOffset, int length, short flags, byte[] name, Node value) { + super(startOffset, length); + this.flags = flags; + this.name = name; + this.value = value; + } + + public boolean isRepeatedParameter() { + return ParameterFlags.isRepeatedParameter(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.value.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.value }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitOptionalParameterNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("ParameterFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + builder.append(nextIndent); + builder.append("value: "); + builder.append(this.value.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `||` operator or the `or` keyword.
+     *
+     *     left or right
+     *     ^^^^^^^^^^^^^
+     * 
+ */ + public static final class OrNode extends Node { + /** + *
+         * Represents the left side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     left or right
+         *     ^^^^
+         *
+         *     1 || 2
+         *     ^
+         * 
+ */ + public final Node left; + /** + *
+         * Represents the right side of the expression.
+         *
+         *     left || right
+         *             ^^^^^
+         *
+         *     1 or 2
+         *          ^
+         * 
+ */ + public final Node right; + + public OrNode(int startOffset, int length, Node left, Node right) { + super(startOffset, length); + this.left = left; + this.right = right; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.left.accept(visitor); + this.right.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.left, this.right }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitOrNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("left: "); + builder.append(this.left.toString(nextIndent)); + builder.append(nextIndent); + builder.append("right: "); + builder.append(this.right.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the list of parameters on a method, block, or lambda definition.
+     *
+     *     def a(b, c, d)
+     *           ^^^^^^^
+     *     end
+     * 
+ */ + public static final class ParametersNode extends Node { + @UnionType({ RequiredParameterNode.class, MultiTargetNode.class }) + public final Node[] requireds; + public final OptionalParameterNode[] optionals; + @Nullable + @UnionType({ RestParameterNode.class, ImplicitRestNode.class }) + public final Node rest; + @UnionType({ RequiredParameterNode.class, MultiTargetNode.class }) + public final Node[] posts; + @UnionType({ RequiredKeywordParameterNode.class, OptionalKeywordParameterNode.class }) + public final Node[] keywords; + @Nullable + @UnionType({ KeywordRestParameterNode.class, ForwardingParameterNode.class, NoKeywordsParameterNode.class }) + public final Node keyword_rest; + @Nullable + @UnionType({ BlockParameterNode.class, NoBlockParameterNode.class }) + public final Node block; + + public ParametersNode(int startOffset, int length, Node[] requireds, OptionalParameterNode[] optionals, Node rest, Node[] posts, Node[] keywords, Node keyword_rest, Node block) { + super(startOffset, length); + this.requireds = requireds; + this.optionals = optionals; + this.rest = rest; + this.posts = posts; + this.keywords = keywords; + this.keyword_rest = keyword_rest; + this.block = block; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.requireds) { + child.accept(visitor); + } + for (Nodes.Node child : this.optionals) { + child.accept(visitor); + } + if (this.rest != null) { + this.rest.accept(visitor); + } + for (Nodes.Node child : this.posts) { + child.accept(visitor); + } + for (Nodes.Node child : this.keywords) { + child.accept(visitor); + } + if (this.keyword_rest != null) { + this.keyword_rest.accept(visitor); + } + if (this.block != null) { + this.block.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.requireds)); + childNodes.addAll(Arrays.asList(this.optionals)); + childNodes.add(this.rest); + childNodes.addAll(Arrays.asList(this.posts)); + childNodes.addAll(Arrays.asList(this.keywords)); + childNodes.add(this.keyword_rest); + childNodes.add(this.block); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitParametersNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("requireds: "); + builder.append('\n'); + for (Node child : this.requireds) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("optionals: "); + builder.append('\n'); + for (Node child : this.optionals) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("rest: "); + builder.append(this.rest == null ? "null\n" : this.rest.toString(nextIndent)); + builder.append(nextIndent); + builder.append("posts: "); + builder.append('\n'); + for (Node child : this.posts) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("keywords: "); + builder.append('\n'); + for (Node child : this.keywords) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("keyword_rest: "); + builder.append(this.keyword_rest == null ? "null\n" : this.keyword_rest.toString(nextIndent)); + builder.append(nextIndent); + builder.append("block: "); + builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a parenthesized expression
+     *
+     *     (10 + 34)
+     *     ^^^^^^^^^
+     * 
+ */ + public static final class ParenthesesNode extends Node { + public final short flags; + @Nullable + public final Node body; + + public ParenthesesNode(int startOffset, int length, short flags, Node body) { + super(startOffset, length); + this.flags = flags; + this.body = body; + } + + public boolean isMultipleStatements() { + return ParenthesesNodeFlags.isMultipleStatements(flags); + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + // Never mark ParenthesesNode with a newline flag, mark children instead + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.body != null) { + this.body.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.body }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitParenthesesNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("ParenthesesNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("body: "); + builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `^` operator for pinning an expression in a pattern matching expression.
+     *
+     *     foo in ^(bar)
+     *            ^^^^^^
+     * 
+ */ + public static final class PinnedExpressionNode extends Node { + /** + *
+         * The expression used in the pinned expression
+         *
+         *     foo in ^(bar)
+         *              ^^^
+         * 
+ */ + public final Node expression; + + public PinnedExpressionNode(int startOffset, int length, Node expression) { + super(startOffset, length); + this.expression = expression; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.expression.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.expression }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitPinnedExpressionNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("expression: "); + builder.append(this.expression.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `^` operator for pinning a variable in a pattern matching expression.
+     *
+     *     foo in ^bar
+     *            ^^^^
+     * 
+ */ + public static final class PinnedVariableNode extends Node { + /** + *
+         * The variable used in the pinned expression
+         *
+         *     foo in ^bar
+         *             ^^^
+         * 
+ */ + @UnionType({ LocalVariableReadNode.class, InstanceVariableReadNode.class, ClassVariableReadNode.class, GlobalVariableReadNode.class, BackReferenceReadNode.class, NumberedReferenceReadNode.class, ItLocalVariableReadNode.class }) + public final Node variable; + + public PinnedVariableNode(int startOffset, int length, Node variable) { + super(startOffset, length); + this.variable = variable; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.variable.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.variable }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitPinnedVariableNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("variable: "); + builder.append(this.variable.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `END` keyword.
+     *
+     *     END { foo }
+     *     ^^^^^^^^^^^
+     * 
+ */ + public static final class PostExecutionNode extends Node { + @Nullable + public final StatementsNode statements; + + public PostExecutionNode(int startOffset, int length, StatementsNode statements) { + super(startOffset, length); + this.statements = statements; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.statements != null) { + this.statements.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.statements }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitPostExecutionNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `BEGIN` keyword.
+     *
+     *     BEGIN { foo }
+     *     ^^^^^^^^^^^^^
+     * 
+ */ + public static final class PreExecutionNode extends Node { + @Nullable + public final StatementsNode statements; + + public PreExecutionNode(int startOffset, int length, StatementsNode statements) { + super(startOffset, length); + this.statements = statements; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.statements != null) { + this.statements.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.statements }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitPreExecutionNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * The top level node of any parse tree.
+     * 
+ */ + public static final class ProgramNode extends Node { + public final byte[][] locals; + public final StatementsNode statements; + + public ProgramNode(int startOffset, int length, byte[][] locals, StatementsNode statements) { + super(startOffset, length); + this.locals = locals; + this.statements = statements; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.statements.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.statements }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitProgramNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("locals: "); + builder.append('\n'); + for (byte[] constant : this.locals) { + builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); + } + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `..` or `...` operators.
+     *
+     *     1..2
+     *     ^^^^
+     *
+     *     c if a =~ /left/ ... b =~ /right/
+     *          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class RangeNode extends Node { + public final short flags; + /** + *
+         * The left-hand side of the range, if present. It can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     1...
+         *     ^
+         *
+         *     hello...goodbye
+         *     ^^^^^
+         * 
+ */ + @Nullable + public final Node left; + /** + *
+         * The right-hand side of the range, if present. It can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     ..5
+         *       ^
+         *
+         *     1...foo
+         *         ^^^
+         * If neither right-hand or left-hand side was included, this will be a MissingNode.
+         * 
+ */ + @Nullable + public final Node right; + + public RangeNode(int startOffset, int length, short flags, Node left, Node right) { + super(startOffset, length); + this.flags = flags; + this.left = left; + this.right = right; + } + + public boolean isExcludeEnd() { + return RangeFlags.isExcludeEnd(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.left != null) { + this.left.accept(visitor); + } + if (this.right != null) { + this.right.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.left, this.right }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitRangeNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("RangeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("left: "); + builder.append(this.left == null ? "null\n" : this.left.toString(nextIndent)); + builder.append(nextIndent); + builder.append("right: "); + builder.append(this.right == null ? "null\n" : this.right.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a rational number literal.
+     *
+     *     1.0r
+     *     ^^^^
+     * 
+ */ + public static final class RationalNode extends Node { + public final short flags; + /** + *
+         * The numerator of the rational number.
+         *
+         *     1.5r # numerator 3
+         * 
+ */ + public final Object numerator; + /** + *
+         * The denominator of the rational number.
+         *
+         *     1.5r # denominator 2
+         * 
+ */ + public final Object denominator; + + public RationalNode(int startOffset, int length, short flags, Object numerator, Object denominator) { + super(startOffset, length); + this.flags = flags; + this.numerator = numerator; + this.denominator = denominator; + } + + public boolean isBinary() { + return IntegerBaseFlags.isBinary(flags); + } + + public boolean isDecimal() { + return IntegerBaseFlags.isDecimal(flags); + } + + public boolean isOctal() { + return IntegerBaseFlags.isOctal(flags); + } + + public boolean isHexadecimal() { + return IntegerBaseFlags.isHexadecimal(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitRationalNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("IntegerBaseFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("numerator: "); + builder.append(this.numerator); + builder.append('\n'); + builder.append(nextIndent); + builder.append("denominator: "); + builder.append(this.denominator); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `redo` keyword.
+     *
+     *     redo
+     *     ^^^^
+     * 
+ */ + public static final class RedoNode extends Node { + + public RedoNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitRedoNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents a regular expression literal with no interpolation.
+     *
+     *     /foo/i
+     *     ^^^^^^
+     * 
+ */ + public static final class RegularExpressionNode extends Node { + public final short flags; + public final byte[] unescaped; + + public RegularExpressionNode(int startOffset, int length, short flags, byte[] unescaped) { + super(startOffset, length); + this.flags = flags; + this.unescaped = unescaped; + } + + public boolean isIgnoreCase() { + return RegularExpressionFlags.isIgnoreCase(flags); + } + + public boolean isExtended() { + return RegularExpressionFlags.isExtended(flags); + } + + public boolean isMultiLine() { + return RegularExpressionFlags.isMultiLine(flags); + } + + public boolean isOnce() { + return RegularExpressionFlags.isOnce(flags); + } + + public boolean isEucJp() { + return RegularExpressionFlags.isEucJp(flags); + } + + public boolean isAscii8bit() { + return RegularExpressionFlags.isAscii8bit(flags); + } + + public boolean isWindows31j() { + return RegularExpressionFlags.isWindows31j(flags); + } + + public boolean isUtf8() { + return RegularExpressionFlags.isUtf8(flags); + } + + public boolean isForcedUtf8Encoding() { + return RegularExpressionFlags.isForcedUtf8Encoding(flags); + } + + public boolean isForcedBinaryEncoding() { + return RegularExpressionFlags.isForcedBinaryEncoding(flags); + } + + public boolean isForcedUsAsciiEncoding() { + return RegularExpressionFlags.isForcedUsAsciiEncoding(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitRegularExpressionNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("RegularExpressionFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("unescaped: "); + builder.append('"' + asString(this.unescaped) + '"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents a required keyword parameter to a method, block, or lambda definition.
+     *
+     *     def a(b: )
+     *           ^^
+     *     end
+     * 
+ */ + public static final class RequiredKeywordParameterNode extends Node { + public final short flags; + public final byte[] name; + + public RequiredKeywordParameterNode(int startOffset, int length, short flags, byte[] name) { + super(startOffset, length); + this.flags = flags; + this.name = name; + } + + public boolean isRepeatedParameter() { + return ParameterFlags.isRepeatedParameter(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitRequiredKeywordParameterNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("ParameterFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents a required parameter to a method, block, or lambda definition.
+     *
+     *     def a(b)
+     *           ^
+     *     end
+     * 
+ */ + public static final class RequiredParameterNode extends Node { + public final short flags; + public final byte[] name; + + public RequiredParameterNode(int startOffset, int length, short flags, byte[] name) { + super(startOffset, length); + this.flags = flags; + this.name = name; + } + + public boolean isRepeatedParameter() { + return ParameterFlags.isRepeatedParameter(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitRequiredParameterNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("ParameterFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("name: "); + builder.append('"').append(asString(this.name)).append('"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents an expression modified with a rescue.
+     *
+     *     foo rescue nil
+     *     ^^^^^^^^^^^^^^
+     * 
+ */ + public static final class RescueModifierNode extends Node { + public final Node expression; + public final Node rescue_expression; + + public RescueModifierNode(int startOffset, int length, Node expression, Node rescue_expression) { + super(startOffset, length); + this.expression = expression; + this.rescue_expression = rescue_expression; + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + this.expression.setNewLineFlag(source, newlineMarked); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.expression.accept(visitor); + this.rescue_expression.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.expression, this.rescue_expression }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitRescueModifierNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("expression: "); + builder.append(this.expression.toString(nextIndent)); + builder.append(nextIndent); + builder.append("rescue_expression: "); + builder.append(this.rescue_expression.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a rescue statement.
+     *
+     *     begin
+     *     rescue Foo, *splat, Bar => ex
+     *       foo
+     *     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+     *     end
+     *
+     * `Foo, *splat, Bar` are in the `exceptions` field. `ex` is in the `reference` field.
+     * 
+ */ + public static final class RescueNode extends Node { + public final Node[] exceptions; + @Nullable + @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class }) + public final Node reference; + @Nullable + public final StatementsNode statements; + @Nullable + public final RescueNode subsequent; + + public RescueNode(int startOffset, int length, Node[] exceptions, Node reference, StatementsNode statements, RescueNode subsequent) { + super(startOffset, length); + this.exceptions = exceptions; + this.reference = reference; + this.statements = statements; + this.subsequent = subsequent; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.exceptions) { + child.accept(visitor); + } + if (this.reference != null) { + this.reference.accept(visitor); + } + if (this.statements != null) { + this.statements.accept(visitor); + } + if (this.subsequent != null) { + this.subsequent.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.exceptions)); + childNodes.add(this.reference); + childNodes.add(this.statements); + childNodes.add(this.subsequent); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitRescueNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("exceptions: "); + builder.append('\n'); + for (Node child : this.exceptions) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("reference: "); + builder.append(this.reference == null ? "null\n" : this.reference.toString(nextIndent)); + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + builder.append(nextIndent); + builder.append("subsequent: "); + builder.append(this.subsequent == null ? "null\n" : this.subsequent.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a rest parameter to a method, block, or lambda definition.
+     *
+     *     def a(*b)
+     *           ^^
+     *     end
+     * 
+ */ + public static final class RestParameterNode extends Node { + public final short flags; + @Nullable + public final byte[] name; + + public RestParameterNode(int startOffset, int length, short flags, byte[] name) { + super(startOffset, length); + this.flags = flags; + this.name = name; + } + + public boolean isRepeatedParameter() { + return ParameterFlags.isRepeatedParameter(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitRestParameterNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("ParameterFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("name: "); + builder.append(this.name == null ? "null" : "\"" + asString(this.name) + "\""); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `retry` keyword.
+     *
+     *     retry
+     *     ^^^^^
+     * 
+ */ + public static final class RetryNode extends Node { + + public RetryNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitRetryNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `return` keyword.
+     *
+     *     return 1
+     *     ^^^^^^^^
+     * 
+ */ + public static final class ReturnNode extends Node { + @Nullable + public final ArgumentsNode arguments; + + public ReturnNode(int startOffset, int length, ArgumentsNode arguments) { + super(startOffset, length); + this.arguments = arguments; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.arguments != null) { + this.arguments.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.arguments }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitReturnNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("arguments: "); + builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the `self` keyword.
+     *
+     *     self
+     *     ^^^^
+     * 
+ */ + public static final class SelfNode extends Node { + + public SelfNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitSelfNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * This node wraps a constant write to indicate that when the value is written, it should have its shareability state modified.
+     *
+     *     # shareable_constant_value: literal
+     *     C = { a: 1 }
+     *     ^^^^^^^^^^^^
+     * 
+ */ + public static final class ShareableConstantNode extends Node { + public final short flags; + /** + *
+         * The constant write that should be modified with the shareability state.
+         * 
+ */ + @UnionType({ ConstantWriteNode.class, ConstantAndWriteNode.class, ConstantOrWriteNode.class, ConstantOperatorWriteNode.class, ConstantPathWriteNode.class, ConstantPathAndWriteNode.class, ConstantPathOrWriteNode.class, ConstantPathOperatorWriteNode.class }) + public final Node write; + + public ShareableConstantNode(int startOffset, int length, short flags, Node write) { + super(startOffset, length); + this.flags = flags; + this.write = write; + } + + public boolean isLiteral() { + return ShareableConstantNodeFlags.isLiteral(flags); + } + + public boolean isExperimentalEverything() { + return ShareableConstantNodeFlags.isExperimentalEverything(flags); + } + + public boolean isExperimentalCopy() { + return ShareableConstantNodeFlags.isExperimentalCopy(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.write.accept(visitor); + } + + public Node[] childNodes() { + return new Node[] { this.write }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitShareableConstantNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("ShareableConstantNodeFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("write: "); + builder.append(this.write.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a singleton class declaration involving the `class` keyword.
+     *
+     *     class << self end
+     *     ^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class SingletonClassNode extends Node { + public final byte[][] locals; + public final Node expression; + @Nullable + @UnionType({ StatementsNode.class, BeginNode.class }) + public final Node body; + + public SingletonClassNode(int startOffset, int length, byte[][] locals, Node expression, Node body) { + super(startOffset, length); + this.locals = locals; + this.expression = expression; + this.body = body; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.expression.accept(visitor); + if (this.body != null) { + this.body.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.expression, this.body }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitSingletonClassNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("locals: "); + builder.append('\n'); + for (byte[] constant : this.locals) { + builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); + } + builder.append(nextIndent); + builder.append("expression: "); + builder.append(this.expression.toString(nextIndent)); + builder.append(nextIndent); + builder.append("body: "); + builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `__ENCODING__` keyword.
+     *
+     *     __ENCODING__
+     *     ^^^^^^^^^^^^
+     * 
+ */ + public static final class SourceEncodingNode extends Node { + + public SourceEncodingNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitSourceEncodingNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `__FILE__` keyword.
+     *
+     *     __FILE__
+     *     ^^^^^^^^
+     * 
+ */ + public static final class SourceFileNode extends Node { + public final short flags; + /** + *
+         * Represents the file path being parsed. This corresponds directly to the `filepath` option given to the various `Prism.parse*` APIs.
+         * 
+ */ + public final byte[] filepath; + + public SourceFileNode(int startOffset, int length, short flags, byte[] filepath) { + super(startOffset, length); + this.flags = flags; + this.filepath = filepath; + } + + public boolean isForcedUtf8Encoding() { + return StringFlags.isForcedUtf8Encoding(flags); + } + + public boolean isForcedBinaryEncoding() { + return StringFlags.isForcedBinaryEncoding(flags); + } + + public boolean isFrozen() { + return StringFlags.isFrozen(flags); + } + + public boolean isMutable() { + return StringFlags.isMutable(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitSourceFileNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("StringFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("filepath: "); + builder.append('"' + asString(this.filepath) + '"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `__LINE__` keyword.
+     *
+     *     __LINE__
+     *     ^^^^^^^^
+     * 
+ */ + public static final class SourceLineNode extends Node { + + public SourceLineNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitSourceLineNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the splat operator.
+     *
+     *     [*a]
+     *      ^^
+     * 
+ */ + public static final class SplatNode extends Node { + @Nullable + public final Node expression; + + public SplatNode(int startOffset, int length, Node expression) { + super(startOffset, length); + this.expression = expression; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.expression != null) { + this.expression.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.expression }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitSplatNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("expression: "); + builder.append(this.expression == null ? "null\n" : this.expression.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a set of statements contained within some scope.
+     *
+     *     foo; bar; baz
+     *     ^^^^^^^^^^^^^
+     * 
+ */ + public static final class StatementsNode extends Node { + public final Node[] body; + + public StatementsNode(int startOffset, int length, Node[] body) { + super(startOffset, length); + this.body = body; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.body) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.body)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitStatementsNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("body: "); + builder.append('\n'); + for (Node child : this.body) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents a string literal, a string contained within a `%w` list, or plain string content within an interpolated string.
+     *
+     *     "foo"
+     *     ^^^^^
+     *
+     *     %w[foo]
+     *        ^^^
+     *
+     *     "foo #{bar} baz"
+     *      ^^^^      ^^^^
+     * 
+ */ + public static final class StringNode extends Node { + public final short flags; + public final byte[] unescaped; + + public StringNode(int startOffset, int length, short flags, byte[] unescaped) { + super(startOffset, length); + this.flags = flags; + this.unescaped = unescaped; + } + + public boolean isForcedUtf8Encoding() { + return StringFlags.isForcedUtf8Encoding(flags); + } + + public boolean isForcedBinaryEncoding() { + return StringFlags.isForcedBinaryEncoding(flags); + } + + public boolean isFrozen() { + return StringFlags.isFrozen(flags); + } + + public boolean isMutable() { + return StringFlags.isMutable(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitStringNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("StringFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("unescaped: "); + builder.append('"' + asString(this.unescaped) + '"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `super` keyword with parentheses or arguments.
+     *
+     *     super()
+     *     ^^^^^^^
+     *
+     *     super foo, bar
+     *     ^^^^^^^^^^^^^^
+     *
+     * If no arguments are provided (except for a block), it would be a `ForwardingSuperNode` instead.
+     * 
+ */ + public static final class SuperNode extends Node { + /** + *
+         * Can be only `nil` when there are empty parentheses, like `super()`.
+         * 
+ */ + @Nullable + public final ArgumentsNode arguments; + @Nullable + @UnionType({ BlockNode.class, BlockArgumentNode.class }) + public final Node block; + + public SuperNode(int startOffset, int length, ArgumentsNode arguments, Node block) { + super(startOffset, length); + this.arguments = arguments; + this.block = block; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.arguments != null) { + this.arguments.accept(visitor); + } + if (this.block != null) { + this.block.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.arguments, this.block }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitSuperNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("arguments: "); + builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); + builder.append(nextIndent); + builder.append("block: "); + builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents a symbol literal or a symbol contained within a `%i` list.
+     *
+     *     :foo
+     *     ^^^^
+     *
+     *     %i[foo]
+     *        ^^^
+     * 
+ */ + public static final class SymbolNode extends Node { + public final short flags; + public final byte[] unescaped; + + public SymbolNode(int startOffset, int length, short flags, byte[] unescaped) { + super(startOffset, length); + this.flags = flags; + this.unescaped = unescaped; + } + + public boolean isForcedUtf8Encoding() { + return SymbolFlags.isForcedUtf8Encoding(flags); + } + + public boolean isForcedBinaryEncoding() { + return SymbolFlags.isForcedBinaryEncoding(flags); + } + + public boolean isForcedUsAsciiEncoding() { + return SymbolFlags.isForcedUsAsciiEncoding(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitSymbolNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("SymbolFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("unescaped: "); + builder.append('"' + asString(this.unescaped) + '"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the literal `true` keyword.
+     *
+     *     true
+     *     ^^^^
+     * 
+ */ + public static final class TrueNode extends Node { + + public TrueNode(int startOffset, int length) { + super(startOffset, length); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitTrueNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `undef` keyword.
+     *
+     *     undef :foo, :bar, :baz
+     *     ^^^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class UndefNode extends Node { + @UnionType({ SymbolNode.class, InterpolatedSymbolNode.class }) + public final Node[] names; + + public UndefNode(int startOffset, int length, Node[] names) { + super(startOffset, length); + this.names = names; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.names) { + child.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.names)); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitUndefNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("names: "); + builder.append('\n'); + for (Node child : this.names) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `unless` keyword, either in the block form or the modifier form.
+     *
+     *     bar unless foo
+     *     ^^^^^^^^^^^^^^
+     *
+     *     unless foo then bar end
+     *     ^^^^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class UnlessNode extends Node { + /** + *
+         * The condition to be evaluated for the unless expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
+         *
+         *     unless cond then bar end
+         *            ^^^^
+         *
+         *     bar unless cond
+         *                ^^^^
+         * 
+ */ + public final Node predicate; + /** + *
+         * The body of statements that will executed if the unless condition is
+         * falsey. Will be `nil` if no body is provided.
+         *
+         *     unless cond then bar end
+         *                      ^^^
+         * 
+ */ + @Nullable + public final StatementsNode statements; + /** + *
+         * The else clause of the unless expression, if present.
+         *
+         *     unless cond then bar else baz end
+         *                          ^^^^^^^^^^^^
+         * 
+ */ + @Nullable + public final ElseNode else_clause; + + public UnlessNode(int startOffset, int length, Node predicate, StatementsNode statements, ElseNode else_clause) { + super(startOffset, length); + this.predicate = predicate; + this.statements = statements; + this.else_clause = else_clause; + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + this.predicate.setNewLineFlag(source, newlineMarked); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.predicate.accept(visitor); + if (this.statements != null) { + this.statements.accept(visitor); + } + if (this.else_clause != null) { + this.else_clause.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.predicate, this.statements, this.else_clause }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitUnlessNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("predicate: "); + builder.append(this.predicate.toString(nextIndent)); + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + builder.append(nextIndent); + builder.append("else_clause: "); + builder.append(this.else_clause == null ? "null\n" : this.else_clause.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `until` keyword, either in the block form or the modifier form.
+     *
+     *     bar until foo
+     *     ^^^^^^^^^^^^^
+     *
+     *     until foo do bar end
+     *     ^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class UntilNode extends Node { + public final short flags; + public final Node predicate; + @Nullable + public final StatementsNode statements; + + public UntilNode(int startOffset, int length, short flags, Node predicate, StatementsNode statements) { + super(startOffset, length); + this.flags = flags; + this.predicate = predicate; + this.statements = statements; + } + + public boolean isBeginModifier() { + return LoopFlags.isBeginModifier(flags); + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + this.predicate.setNewLineFlag(source, newlineMarked); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.predicate.accept(visitor); + if (this.statements != null) { + this.statements.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.predicate, this.statements }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitUntilNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("LoopFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("predicate: "); + builder.append(this.predicate.toString(nextIndent)); + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `when` keyword within a case statement.
+     *
+     *     case true
+     *     when true
+     *     ^^^^^^^^^
+     *     end
+     * 
+ */ + public static final class WhenNode extends Node { + public final Node[] conditions; + @Nullable + public final StatementsNode statements; + + public WhenNode(int startOffset, int length, Node[] conditions, StatementsNode statements) { + super(startOffset, length); + this.conditions = conditions; + this.statements = statements; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + for (Nodes.Node child : this.conditions) { + child.accept(visitor); + } + if (this.statements != null) { + this.statements.accept(visitor); + } + } + + public Node[] childNodes() { + ArrayList childNodes = new ArrayList<>(); + childNodes.addAll(Arrays.asList(this.conditions)); + childNodes.add(this.statements); + return childNodes.toArray(EMPTY_ARRAY); + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitWhenNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + String nextNextIndent = nextIndent + " "; + builder.append(nextIndent); + builder.append("conditions: "); + builder.append('\n'); + for (Node child : this.conditions) { + builder.append(nextNextIndent).append(child.toString(nextNextIndent)); + } + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `while` keyword, either in the block form or the modifier form.
+     *
+     *     bar while foo
+     *     ^^^^^^^^^^^^^
+     *
+     *     while foo do bar end
+     *     ^^^^^^^^^^^^^^^^^^^^
+     * 
+ */ + public static final class WhileNode extends Node { + public final short flags; + public final Node predicate; + @Nullable + public final StatementsNode statements; + + public WhileNode(int startOffset, int length, short flags, Node predicate, StatementsNode statements) { + super(startOffset, length); + this.flags = flags; + this.predicate = predicate; + this.statements = statements; + } + + public boolean isBeginModifier() { + return LoopFlags.isBeginModifier(flags); + } + + @Override + public void setNewLineFlag(Source source, boolean[] newlineMarked) { + this.predicate.setNewLineFlag(source, newlineMarked); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + this.predicate.accept(visitor); + if (this.statements != null) { + this.statements.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.predicate, this.statements }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitWhileNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("LoopFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("predicate: "); + builder.append(this.predicate.toString(nextIndent)); + builder.append(nextIndent); + builder.append("statements: "); + builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); + return builder.toString(); + } + } + + /** + *
+     * Represents an xstring literal with no interpolation.
+     *
+     *     `foo`
+     *     ^^^^^
+     * 
+ */ + public static final class XStringNode extends Node { + public final short flags; + public final byte[] unescaped; + + public XStringNode(int startOffset, int length, short flags, byte[] unescaped) { + super(startOffset, length); + this.flags = flags; + this.unescaped = unescaped; + } + + public boolean isForcedUtf8Encoding() { + return EncodingFlags.isForcedUtf8Encoding(flags); + } + + public boolean isForcedBinaryEncoding() { + return EncodingFlags.isForcedBinaryEncoding(flags); + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + } + + public Node[] childNodes() { + return EMPTY_ARRAY; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitXStringNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("EncodingFlags: "); + builder.append(flags); + builder.append('\n'); + builder.append(nextIndent); + builder.append("unescaped: "); + builder.append('"' + asString(this.unescaped) + '"'); + builder.append('\n'); + return builder.toString(); + } + } + + /** + *
+     * Represents the use of the `yield` keyword.
+     *
+     *     yield 1
+     *     ^^^^^^^
+     * 
+ */ + public static final class YieldNode extends Node { + @Nullable + public final ArgumentsNode arguments; + + public YieldNode(int startOffset, int length, ArgumentsNode arguments) { + super(startOffset, length); + this.arguments = arguments; + } + + public void visitChildNodes(AbstractNodeVisitor visitor) { + if (this.arguments != null) { + this.arguments.accept(visitor); + } + } + + public Node[] childNodes() { + return new Node[] { this.arguments }; + } + + public T accept(AbstractNodeVisitor visitor) { + return visitor.visitYieldNode(this); + } + + @Override + protected String toString(String indent) { + StringBuilder builder = new StringBuilder(); + builder.append(this.getClass().getSimpleName()); + if (hasNewLineFlag()) { + builder.append("[Li]"); + } + builder.append('\n'); + String nextIndent = indent + " "; + builder.append(nextIndent); + builder.append("arguments: "); + builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); + return builder.toString(); + } + } + + public enum ErrorType { + ALIAS_ARGUMENT, + ALIAS_ARGUMENT_NUMBERED_REFERENCE, + AMPAMPEQ_MULTI_ASSIGN, + ARGUMENT_AFTER_BLOCK, + ARGUMENT_AFTER_FORWARDING_ELLIPSES, + ARGUMENT_BARE_HASH, + ARGUMENT_BLOCK_FORWARDING, + ARGUMENT_BLOCK_MULTI, + ARGUMENT_CONFLICT_AMPERSAND, + ARGUMENT_CONFLICT_STAR, + ARGUMENT_CONFLICT_STAR_STAR, + ARGUMENT_FORMAL_CLASS, + ARGUMENT_FORMAL_CONSTANT, + ARGUMENT_FORMAL_GLOBAL, + ARGUMENT_FORMAL_IVAR, + ARGUMENT_FORWARDING_UNBOUND, + ARGUMENT_NO_FORWARDING_AMPERSAND, + ARGUMENT_NO_FORWARDING_ELLIPSES, + ARGUMENT_NO_FORWARDING_ELLIPSES_LAMBDA, + ARGUMENT_NO_FORWARDING_ELLIPSES_BLOCK, + ARGUMENT_NO_FORWARDING_STAR, + ARGUMENT_NO_FORWARDING_STAR_STAR, + ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT, + ARGUMENT_SPLAT_AFTER_SPLAT, + ARGUMENT_TERM_PAREN, + ARGUMENT_UNEXPECTED_BLOCK, + ARRAY_ELEMENT, + ARRAY_EXPRESSION, + ARRAY_EXPRESSION_AFTER_STAR, + ARRAY_SEPARATOR, + ARRAY_TERM, + BEGIN_LONELY_ELSE, + BEGIN_TERM, + BEGIN_UPCASE_BRACE, + BEGIN_UPCASE_TERM, + BEGIN_UPCASE_TOPLEVEL, + BLOCK_PARAM_LOCAL_VARIABLE, + BLOCK_PARAM_PIPE_TERM, + BLOCK_TERM_BRACE, + BLOCK_TERM_END, + CANNOT_PARSE_EXPRESSION, + CANNOT_PARSE_STRING_PART, + CASE_EXPRESSION_AFTER_CASE, + CASE_EXPRESSION_AFTER_WHEN, + CASE_MATCH_MISSING_PREDICATE, + CASE_MISSING_CONDITIONS, + CASE_TERM, + CLASS_IN_METHOD, + CLASS_NAME, + CLASS_SUPERCLASS, + CLASS_TERM, + CLASS_UNEXPECTED_END, + CLASS_VARIABLE_BARE, + CONDITIONAL_ELSIF_PREDICATE, + CONDITIONAL_IF_PREDICATE, + CONDITIONAL_PREDICATE_TERM, + CONDITIONAL_TERM, + CONDITIONAL_TERM_ELSE, + CONDITIONAL_UNLESS_PREDICATE, + CONDITIONAL_UNTIL_PREDICATE, + CONDITIONAL_WHILE_PREDICATE, + CONSTANT_PATH_COLON_COLON_CONSTANT, + DEF_ENDLESS, + DEF_ENDLESS_PARAMETERS, + DEF_ENDLESS_SETTER, + DEF_ENDLESS_DO_BLOCK, + DEF_NAME, + DEF_PARAMS_TERM, + DEF_PARAMS_TERM_PAREN, + DEF_RECEIVER, + DEF_RECEIVER_TERM, + DEF_TERM, + DEFINED_EXPRESSION, + EMBDOC_TERM, + EMBEXPR_END, + EMBVAR_INVALID, + END_UPCASE_BRACE, + END_UPCASE_TERM, + ESCAPE_INVALID_CONTROL, + ESCAPE_INVALID_CONTROL_REPEAT, + ESCAPE_INVALID_HEXADECIMAL, + ESCAPE_INVALID_META, + ESCAPE_INVALID_META_REPEAT, + ESCAPE_INVALID_UNICODE, + ESCAPE_INVALID_UNICODE_CM_FLAGS, + ESCAPE_INVALID_UNICODE_LIST, + ESCAPE_INVALID_UNICODE_LITERAL, + ESCAPE_INVALID_UNICODE_LONG, + ESCAPE_INVALID_UNICODE_SHORT, + ESCAPE_INVALID_UNICODE_TERM, + EXPECT_ARGUMENT, + EXPECT_EOL_AFTER_STATEMENT, + EXPECT_EXPRESSION_AFTER_AMPAMPEQ, + EXPECT_EXPRESSION_AFTER_COMMA, + EXPECT_EXPRESSION_AFTER_EQUAL, + EXPECT_EXPRESSION_AFTER_LESS_LESS, + EXPECT_EXPRESSION_AFTER_LPAREN, + EXPECT_EXPRESSION_AFTER_OPERATOR, + EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ, + EXPECT_EXPRESSION_AFTER_QUESTION, + EXPECT_EXPRESSION_AFTER_SPLAT, + EXPECT_EXPRESSION_AFTER_SPLAT_HASH, + EXPECT_EXPRESSION_AFTER_STAR, + EXPECT_FOR_DELIMITER, + EXPECT_IDENT_REQ_PARAMETER, + EXPECT_IN_DELIMITER, + EXPECT_LPAREN_AFTER_NOT_LPAREN, + EXPECT_LPAREN_AFTER_NOT_OTHER, + EXPECT_LPAREN_REQ_PARAMETER, + EXPECT_MESSAGE, + EXPECT_RBRACKET, + EXPECT_RPAREN, + EXPECT_RPAREN_AFTER_MULTI, + EXPECT_RPAREN_REQ_PARAMETER, + EXPECT_SINGLETON_CLASS_DELIMITER, + EXPECT_STRING_CONTENT, + EXPECT_WHEN_DELIMITER, + EXPRESSION_BARE_HASH, + EXPRESSION_NOT_WRITABLE, + EXPRESSION_NOT_WRITABLE_ENCODING, + EXPRESSION_NOT_WRITABLE_FALSE, + EXPRESSION_NOT_WRITABLE_FILE, + EXPRESSION_NOT_WRITABLE_LINE, + EXPRESSION_NOT_WRITABLE_NIL, + EXPRESSION_NOT_WRITABLE_NUMBERED, + EXPRESSION_NOT_WRITABLE_SELF, + EXPRESSION_NOT_WRITABLE_TRUE, + FLOAT_PARSE, + FOR_COLLECTION, + FOR_IN, + FOR_INDEX, + FOR_TERM, + GLOBAL_VARIABLE_BARE, + HASH_EXPRESSION_AFTER_LABEL, + HASH_KEY, + HASH_ROCKET, + HASH_TERM, + HASH_VALUE, + HEREDOC_IDENTIFIER, + HEREDOC_TERM, + INCOMPLETE_QUESTION_MARK, + INCOMPLETE_VARIABLE_CLASS, + INCOMPLETE_VARIABLE_CLASS_3_3, + INCOMPLETE_VARIABLE_INSTANCE, + INCOMPLETE_VARIABLE_INSTANCE_3_3, + INSTANCE_VARIABLE_BARE, + INVALID_BLOCK_EXIT, + INVALID_CHARACTER, + INVALID_COMMA, + INVALID_ENCODING_MAGIC_COMMENT, + INVALID_ESCAPE_CHARACTER, + INVALID_FLOAT_EXPONENT, + INVALID_LOCAL_VARIABLE_READ, + INVALID_LOCAL_VARIABLE_WRITE, + INVALID_MULTIBYTE_CHAR, + INVALID_MULTIBYTE_CHARACTER, + INVALID_MULTIBYTE_ESCAPE, + INVALID_NUMBER_BINARY, + INVALID_NUMBER_DECIMAL, + INVALID_NUMBER_FRACTION, + INVALID_NUMBER_HEXADECIMAL, + INVALID_NUMBER_OCTAL, + INVALID_NUMBER_UNDERSCORE_INNER, + INVALID_NUMBER_UNDERSCORE_TRAILING, + INVALID_PERCENT, + INVALID_PERCENT_EOF, + INVALID_PRINTABLE_CHARACTER, + INVALID_RETRY_AFTER_ELSE, + INVALID_RETRY_AFTER_ENSURE, + INVALID_RETRY_WITHOUT_RESCUE, + INVALID_SYMBOL, + INVALID_VARIABLE_GLOBAL, + INVALID_VARIABLE_GLOBAL_3_3, + INVALID_YIELD, + IT_NOT_ALLOWED_NUMBERED, + IT_NOT_ALLOWED_ORDINARY, + LAMBDA_OPEN, + LAMBDA_TERM_BRACE, + LAMBDA_TERM_END, + LIST_I_LOWER_ELEMENT, + LIST_I_LOWER_TERM, + LIST_I_UPPER_ELEMENT, + LIST_I_UPPER_TERM, + LIST_W_LOWER_ELEMENT, + LIST_W_LOWER_TERM, + LIST_W_UPPER_ELEMENT, + LIST_W_UPPER_TERM, + MALLOC_FAILED, + MIXED_ENCODING, + MODULE_IN_METHOD, + MODULE_NAME, + MODULE_TERM, + MULTI_ASSIGN_MULTI_SPLATS, + MULTI_ASSIGN_UNEXPECTED_REST, + NESTING_TOO_DEEP, + NO_LOCAL_VARIABLE, + NON_ASSOCIATIVE_OPERATOR, + NOT_EXPRESSION, + NUMBER_LITERAL_UNDERSCORE, + NUMBERED_PARAMETER_INNER_BLOCK, + NUMBERED_PARAMETER_IT, + NUMBERED_PARAMETER_ORDINARY, + NUMBERED_PARAMETER_OUTER_BLOCK, + OPERATOR_MULTI_ASSIGN, + OPERATOR_WRITE_ARGUMENTS, + OPERATOR_WRITE_BLOCK, + PARAMETER_ASSOC_SPLAT_MULTI, + PARAMETER_BLOCK_MULTI, + PARAMETER_CIRCULAR, + PARAMETER_FORWARDING_AFTER_REST, + PARAMETER_METHOD_NAME, + PARAMETER_NAME_DUPLICATED, + PARAMETER_NO_DEFAULT, + PARAMETER_NO_DEFAULT_KW, + PARAMETER_NUMBERED_RESERVED, + PARAMETER_ORDER, + PARAMETER_SPLAT_MULTI, + PARAMETER_STAR, + PARAMETER_UNEXPECTED_FWD, + PARAMETER_UNEXPECTED_NO_KW, + PARAMETER_WILD_LOOSE_COMMA, + PATTERN_ARRAY_MULTIPLE_RESTS, + PATTERN_CAPTURE_DUPLICATE, + PATTERN_CAPTURE_IN_ALTERNATIVE, + PATTERN_EXPRESSION_AFTER_BRACKET, + PATTERN_EXPRESSION_AFTER_COMMA, + PATTERN_EXPRESSION_AFTER_HROCKET, + PATTERN_EXPRESSION_AFTER_IN, + PATTERN_EXPRESSION_AFTER_KEY, + PATTERN_EXPRESSION_AFTER_PAREN, + PATTERN_EXPRESSION_AFTER_PIN, + PATTERN_EXPRESSION_AFTER_PIPE, + PATTERN_EXPRESSION_AFTER_RANGE, + PATTERN_EXPRESSION_AFTER_REST, + PATTERN_FIND_MISSING_INNER, + PATTERN_HASH_IMPLICIT, + PATTERN_HASH_KEY, + PATTERN_HASH_KEY_DUPLICATE, + PATTERN_HASH_KEY_INTERPOLATED, + PATTERN_HASH_KEY_LABEL, + PATTERN_HASH_KEY_LOCALS, + PATTERN_IDENT_AFTER_HROCKET, + PATTERN_LABEL_AFTER_COMMA, + PATTERN_REST, + PATTERN_TERM_BRACE, + PATTERN_TERM_BRACKET, + PATTERN_TERM_PAREN, + PIPEPIPEEQ_MULTI_ASSIGN, + REGEXP_ENCODING_OPTION_MISMATCH, + REGEXP_ESCAPED_NON_ASCII_IN_UTF8, + REGEXP_INCOMPAT_CHAR_ENCODING, + REGEXP_INVALID_CHAR_PROPERTY, + REGEXP_INVALID_UNICODE_RANGE, + REGEXP_NON_ESCAPED_MBC, + REGEXP_PARSE_ERROR, + REGEXP_TERM, + REGEXP_UNKNOWN_OPTIONS, + REGEXP_UTF8_CHAR_NON_UTF8_REGEXP, + RESCUE_EXPRESSION, + RESCUE_MODIFIER_VALUE, + RESCUE_TERM, + RESCUE_VARIABLE, + RETURN_INVALID, + SCRIPT_NOT_FOUND, + SINGLETON_FOR_LITERALS, + STATEMENT_ALIAS, + STATEMENT_POSTEXE_END, + STATEMENT_PREEXE_BEGIN, + STATEMENT_UNDEF, + STRING_CONCATENATION, + STRING_INTERPOLATED_TERM, + STRING_LITERAL_EOF, + STRING_LITERAL_TERM, + SYMBOL_INVALID, + SYMBOL_TERM_DYNAMIC, + SYMBOL_TERM_INTERPOLATED, + TERNARY_COLON, + TERNARY_EXPRESSION_FALSE, + TERNARY_EXPRESSION_TRUE, + UNARY_DISALLOWED, + UNARY_RECEIVER, + UNDEF_ARGUMENT, + UNEXPECTED_BLOCK_ARGUMENT, + UNEXPECTED_INDEX_BLOCK, + UNEXPECTED_INDEX_KEYWORDS, + UNEXPECTED_LABEL, + UNEXPECTED_MULTI_WRITE, + UNEXPECTED_PARAMETER_DEFAULT_VALUE, + UNEXPECTED_RANGE_OPERATOR, + UNEXPECTED_SAFE_NAVIGATION, + UNEXPECTED_TOKEN_CLOSE_CONTEXT, + UNEXPECTED_TOKEN_IGNORE, + UNTIL_TERM, + VOID_EXPRESSION, + WHILE_TERM, + WRITE_TARGET_IN_METHOD, + WRITE_TARGET_READONLY, + WRITE_TARGET_UNEXPECTED, + XSTRING_TERM, + } + + public static ErrorType[] ERROR_TYPES = ErrorType.values(); + + public enum WarningType { + AMBIGUOUS_BINARY_OPERATOR, + AMBIGUOUS_FIRST_ARGUMENT_MINUS, + AMBIGUOUS_FIRST_ARGUMENT_PLUS, + AMBIGUOUS_PREFIX_AMPERSAND, + AMBIGUOUS_PREFIX_STAR, + AMBIGUOUS_PREFIX_STAR_STAR, + AMBIGUOUS_SLASH, + COMPARISON_AFTER_COMPARISON, + DOT_DOT_DOT_EOL, + EQUAL_IN_CONDITIONAL, + EQUAL_IN_CONDITIONAL_3_3, + END_IN_METHOD, + DUPLICATED_HASH_KEY, + DUPLICATED_WHEN_CLAUSE, + FLOAT_OUT_OF_RANGE, + IGNORED_FROZEN_STRING_LITERAL, + INDENTATION_MISMATCH, + INTEGER_IN_FLIP_FLOP, + INVALID_CHARACTER, + INVALID_MAGIC_COMMENT_VALUE, + INVALID_NUMBERED_REFERENCE, + KEYWORD_EOL, + LITERAL_IN_CONDITION_DEFAULT, + LITERAL_IN_CONDITION_VERBOSE, + SHAREABLE_CONSTANT_VALUE_LINE, + SHEBANG_CARRIAGE_RETURN, + UNEXPECTED_CARRIAGE_RETURN, + UNREACHABLE_STATEMENT, + UNUSED_LOCAL_VARIABLE, + VOID_STATEMENT, + } + + public static WarningType[] WARNING_TYPES = WarningType.values(); +} +// @formatter:on diff --git a/java/org/ruby_lang/prism/ParseResult.java b/java/api/src/main/java/org/ruby_lang/prism/ParseResult.java similarity index 100% rename from java/org/ruby_lang/prism/ParseResult.java rename to java/api/src/main/java/org/ruby_lang/prism/ParseResult.java diff --git a/java/org/ruby_lang/prism/ParsingOptions.java b/java/api/src/main/java/org/ruby_lang/prism/ParsingOptions.java similarity index 100% rename from java/org/ruby_lang/prism/ParsingOptions.java rename to java/api/src/main/java/org/ruby_lang/prism/ParsingOptions.java diff --git a/java/native/pom.xml b/java/native/pom.xml new file mode 100644 index 0000000000..96d6b6e26a --- /dev/null +++ b/java/native/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + + org.ruby-lang + prism-parser + 0.0.2-SNAPSHOT + + + prism-parser-native + Java Prism Native + Java native bindings Prism parser shared library + https://github.com/ruby/prism + + + + + org.codehaus.mojo + templating-maven-plugin + 3.1.0 + + + filtering-java-templates + + filter-sources + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.15.0 + + 21 + + + com.dylibso.chicory + annotations-processor + ${chicory.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.5 + + + org.codehaus.mojo + build-helper-maven-plugin + 3.6.1 + + + generate-sources + + add-source + + + + ../java + + + + + + + + + diff --git a/java/org/ruby_lang/prism/Parser.java b/java/native/src/main/java/org/ruby_lang/prism/Parser.java similarity index 100% rename from java/org/ruby_lang/prism/Parser.java rename to java/native/src/main/java/org/ruby_lang/prism/Parser.java diff --git a/java/pom.xml b/java/pom.xml new file mode 100644 index 0000000000..618b48d71c --- /dev/null +++ b/java/pom.xml @@ -0,0 +1,157 @@ + + + 4.0.0 + + org.ruby-lang + prism-parser + 0.0.2-SNAPSHOT + pom + Java Prism + Java API for the Prism Ruby language parser + https://github.com/ruby/prism + + + + MIT + + + + + + Kevin Newton + kddnewton@gmail.com + + + Benoit Daloze + eregontp@gmail.com + + + Charles Oliver Nutter + headius@headius.com + + + Thomas E Enebo + tom.enebo@gmail.com + + + + + https://github.com/ruby/prism + https://github.com/ruby/prism.git + + + + UTF-8 + UTF-8 + 21 + 21 + + 1.7.3 + 6.0.3 + + + + api + native + wasm + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.2.4 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.15.0 + + + org.apache.maven.plugins + maven-source-plugin + 3.4.0 + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.12.0 + + + org.sonatype.central + central-publishing-maven-plugin + 0.7.0 + + + + + + + release + + + + maven-gpg-plugin + 3.2.4 + + + sign-artifacts + verify + + sign + + + + + + --pinentry-mode + loopback + + + + + + + + + + + + maven-source-plugin + + + attach-sources + + jar-no-fork + + + + + + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + none + + + + org.sonatype.central + central-publishing-maven-plugin + 0.7.0 + true + + central + + + + + + diff --git a/java-wasm/.gitignore b/java/wasm/.gitignore similarity index 100% rename from java-wasm/.gitignore rename to java/wasm/.gitignore diff --git a/java-wasm/README.md b/java/wasm/README.md similarity index 88% rename from java-wasm/README.md rename to java/wasm/README.md index 47aa48a774..64b42732fc 100644 --- a/java-wasm/README.md +++ b/java/wasm/README.md @@ -17,12 +17,12 @@ make java-wasm WASI_SDK_PATH=.../wasi-sdk-25.0-arm64-macos Build the AOT-compiled machine and wrapper library: ``` -mvn -f java-wasm/pom.xml clean package +mvn -f java/wasm/pom.xml clean package ``` This should build the chicory-wasm jar file and pass some basic tests. -The jar will be under `java-wasm/target/chicory-prism-#####-SNAPSHOT.jar` or can be installed by using `install` instead of `pacakge` in the `mvn` command line above. +The jar will be under `java/wasm/target/chicory-prism-#####-SNAPSHOT.jar` or can be installed by using `install` instead of `pacakge` in the `mvn` command line above. ## Releasing diff --git a/java-wasm/perf-test/.gitignore b/java/wasm/perf-test/.gitignore similarity index 100% rename from java-wasm/perf-test/.gitignore rename to java/wasm/perf-test/.gitignore diff --git a/java-wasm/perf-test/bench.sh b/java/wasm/perf-test/bench.sh similarity index 100% rename from java-wasm/perf-test/bench.sh rename to java/wasm/perf-test/bench.sh diff --git a/java-wasm/perf-test/test b/java/wasm/perf-test/test similarity index 100% rename from java-wasm/perf-test/test rename to java/wasm/perf-test/test diff --git a/java/wasm/pom.xml b/java/wasm/pom.xml new file mode 100644 index 0000000000..d652780606 --- /dev/null +++ b/java/wasm/pom.xml @@ -0,0 +1,126 @@ + + + 4.0.0 + + + org.ruby-lang + prism-parser + 0.0.2-SNAPSHOT + + + prism-parser-wasm + Java Prism WASM + Java WASM bindings for the Prism parser shared library + https://github.com/ruby/prism + + + 1.7.3 + + + + + + com.dylibso.chicory + bom + ${chicory.version} + pom + import + + + + + + + org.ruby-lang + prism-parser-api + 0.0.2-SNAPSHOT + + + com.dylibso.chicory + runtime + + + com.dylibso.chicory + log + + + com.dylibso.chicory + wasi + + + com.dylibso.chicory + wasm + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + com.dylibso.chicory + annotations + provided + + + org.jruby + jruby-complete + 10.0.4.0 + test + + + + + + + org.codehaus.mojo + templating-maven-plugin + 3.1.0 + + + filtering-java-templates + + filter-sources + + + + + + maven-compiler-plugin + + 21 + + + com.dylibso.chicory + annotations-processor + ${chicory.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.5 + + + com.dylibso.chicory + chicory-compiler-maven-plugin + ${chicory.version} + + + prism + + compile + + + org.ruby_lang.prism.wasm.PrismParser + src/test/resources/prism.wasm + + + + + + + + diff --git a/java/wasm/prism-parser.iml b/java/wasm/prism-parser.iml new file mode 100644 index 0000000000..99039ba2ed --- /dev/null +++ b/java/wasm/prism-parser.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/java-wasm/src/main/java-templates/org/ruby_lang/prism/wasm/WasmResource.java b/java/wasm/src/main/java-templates/org/ruby_lang/prism/wasm/WasmResource.java similarity index 100% rename from java-wasm/src/main/java-templates/org/ruby_lang/prism/wasm/WasmResource.java rename to java/wasm/src/main/java-templates/org/ruby_lang/prism/wasm/WasmResource.java diff --git a/java-wasm/src/main/java/org/ruby_lang/prism/wasm/Prism.java b/java/wasm/src/main/java/org/ruby_lang/prism/wasm/Prism.java similarity index 100% rename from java-wasm/src/main/java/org/ruby_lang/prism/wasm/Prism.java rename to java/wasm/src/main/java/org/ruby_lang/prism/wasm/Prism.java diff --git a/java-wasm/src/test/java/org/jruby/parser/prism/JRubyTest.java b/java/wasm/src/test/java/org/jruby/parser/prism/JRubyTest.java similarity index 100% rename from java-wasm/src/test/java/org/jruby/parser/prism/JRubyTest.java rename to java/wasm/src/test/java/org/jruby/parser/prism/JRubyTest.java diff --git a/java-wasm/src/test/java/org/jruby/parser/prism/WASMTest.java b/java/wasm/src/test/java/org/jruby/parser/prism/WASMTest.java similarity index 100% rename from java-wasm/src/test/java/org/jruby/parser/prism/WASMTest.java rename to java/wasm/src/test/java/org/jruby/parser/prism/WASMTest.java diff --git a/java-wasm/src/test/resources/.gitignore b/java/wasm/src/test/resources/.gitignore similarity index 100% rename from java-wasm/src/test/resources/.gitignore rename to java/wasm/src/test/resources/.gitignore diff --git a/rakelib/check_manifest.rake b/rakelib/check_manifest.rake index 2c8fced816..ff88543fa9 100644 --- a/rakelib/check_manifest.rake +++ b/rakelib/check_manifest.rake @@ -19,7 +19,7 @@ task check_manifest: :templates do gemfiles javascript java - java-wasm + java/wasm pkg rakelib rust diff --git a/templates/template.rb b/templates/template.rb index 5d1afc9506..c455b36d03 100755 --- a/templates/template.rb +++ b/templates/template.rb @@ -688,9 +688,9 @@ def locals "javascript/src/deserialize.js", "javascript/src/nodes.js", "javascript/src/visitor.js", - "java/org/ruby_lang/prism/Loader.java", - "java/org/ruby_lang/prism/Nodes.java", - "java/org/ruby_lang/prism/AbstractNodeVisitor.java", + "java/api/src/main/java/org/ruby_lang/prism/Loader.java", + "java/api/src/main/java/org/ruby_lang/prism/Nodes.java", + "java/api/src/main/java/org/ruby_lang/prism/AbstractNodeVisitor.java", "lib/prism/compiler.rb", "lib/prism/dispatcher.rb", "lib/prism/dot_visitor.rb", From b257151391dccf14af7a55bfcee0d015c27a0ff5 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 23 Mar 2026 14:49:54 -0500 Subject: [PATCH 2/9] Rework Java template generation for Maven build This uses the JRuby rake-maven-plugin to generate the templates as part of the Maven build. The generated output for the Java templates will be under java/api/target/generated-sources/java. --- java/api/pom.xml | 65 +- .../ruby_lang/prism/AbstractNodeVisitor.java | 1538 -- .../main/java/org/ruby_lang/prism/Loader.java | 775 - .../main/java/org/ruby_lang/prism/Nodes.java | 11628 ---------------- .../prism/AbstractNodeVisitor.java.erb | 0 .../java}/org/ruby_lang/prism/Loader.java.erb | 0 .../java}/org/ruby_lang/prism/Nodes.java.erb | 0 templates/template.rb | 6 +- 8 files changed, 67 insertions(+), 13945 deletions(-) delete mode 100644 java/api/src/main/java/org/ruby_lang/prism/AbstractNodeVisitor.java delete mode 100644 java/api/src/main/java/org/ruby_lang/prism/Loader.java delete mode 100644 java/api/src/main/java/org/ruby_lang/prism/Nodes.java rename templates/java/{ => api/target/generated-sources/java}/org/ruby_lang/prism/AbstractNodeVisitor.java.erb (100%) rename templates/java/{ => api/target/generated-sources/java}/org/ruby_lang/prism/Loader.java.erb (100%) rename templates/java/{ => api/target/generated-sources/java}/org/ruby_lang/prism/Nodes.java.erb (100%) diff --git a/java/api/pom.xml b/java/api/pom.xml index 6b3bd6d3a8..844312d519 100644 --- a/java/api/pom.xml +++ b/java/api/pom.xml @@ -9,10 +9,17 @@ prism-parser-api - Java Prism + Java Prism API Java API for the Prism Ruby language parser https://github.com/ruby/prism + + + mavengems + mavengem:https://rubygems.org + + + org.ruby-lang @@ -20,10 +27,66 @@ 0.0.2-SNAPSHOT provided + + rubygems + rake + 13.0.3 + gem + + + rubygems + rake-compiler + 1.3.1 + gem + + + + org.jruby.maven + mavengem-wagon + 2.0.2 + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.6.1 + + + add-source + generate-sources + + add-source + + + + target/generated-sources/java + + + + + + + org.jruby.maven + rake-maven-plugin + 3.0.6 + + + generate templated Java sources + generate-sources + + rake + + + ${project.basedir}/../.. + PRISM_EXCLUDE_PRETTYPRINT=1 PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS=1 templates + + + + org.codehaus.mojo templating-maven-plugin diff --git a/java/api/src/main/java/org/ruby_lang/prism/AbstractNodeVisitor.java b/java/api/src/main/java/org/ruby_lang/prism/AbstractNodeVisitor.java deleted file mode 100644 index 9c76b38d8e..0000000000 --- a/java/api/src/main/java/org/ruby_lang/prism/AbstractNodeVisitor.java +++ /dev/null @@ -1,1538 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* This file is generated by the templates/template.rb script and should not */ -/* be modified manually. See */ -/* templates/java/org/ruby_lang/prism/AbstractNodeVisitor.java.erb */ -/* if you are looking to modify the */ -/* template */ -/*----------------------------------------------------------------------------*/ - -package org.ruby_lang.prism; - -// GENERATED BY AbstractNodeVisitor.java.erb -// @formatter:off -public abstract class AbstractNodeVisitor { - - protected abstract T defaultVisit(Nodes.Node node); - - /** - * Visit a AliasGlobalVariableNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitAliasGlobalVariableNode(Nodes.AliasGlobalVariableNode node) { - return defaultVisit(node); - } - - /** - * Visit a AliasMethodNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitAliasMethodNode(Nodes.AliasMethodNode node) { - return defaultVisit(node); - } - - /** - * Visit a AlternationPatternNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitAlternationPatternNode(Nodes.AlternationPatternNode node) { - return defaultVisit(node); - } - - /** - * Visit a AndNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitAndNode(Nodes.AndNode node) { - return defaultVisit(node); - } - - /** - * Visit a ArgumentsNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitArgumentsNode(Nodes.ArgumentsNode node) { - return defaultVisit(node); - } - - /** - * Visit a ArrayNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitArrayNode(Nodes.ArrayNode node) { - return defaultVisit(node); - } - - /** - * Visit a ArrayPatternNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitArrayPatternNode(Nodes.ArrayPatternNode node) { - return defaultVisit(node); - } - - /** - * Visit a AssocNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitAssocNode(Nodes.AssocNode node) { - return defaultVisit(node); - } - - /** - * Visit a AssocSplatNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitAssocSplatNode(Nodes.AssocSplatNode node) { - return defaultVisit(node); - } - - /** - * Visit a BackReferenceReadNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitBackReferenceReadNode(Nodes.BackReferenceReadNode node) { - return defaultVisit(node); - } - - /** - * Visit a BeginNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitBeginNode(Nodes.BeginNode node) { - return defaultVisit(node); - } - - /** - * Visit a BlockArgumentNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitBlockArgumentNode(Nodes.BlockArgumentNode node) { - return defaultVisit(node); - } - - /** - * Visit a BlockLocalVariableNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitBlockLocalVariableNode(Nodes.BlockLocalVariableNode node) { - return defaultVisit(node); - } - - /** - * Visit a BlockNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitBlockNode(Nodes.BlockNode node) { - return defaultVisit(node); - } - - /** - * Visit a BlockParameterNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitBlockParameterNode(Nodes.BlockParameterNode node) { - return defaultVisit(node); - } - - /** - * Visit a BlockParametersNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitBlockParametersNode(Nodes.BlockParametersNode node) { - return defaultVisit(node); - } - - /** - * Visit a BreakNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitBreakNode(Nodes.BreakNode node) { - return defaultVisit(node); - } - - /** - * Visit a CallAndWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitCallAndWriteNode(Nodes.CallAndWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a CallNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitCallNode(Nodes.CallNode node) { - return defaultVisit(node); - } - - /** - * Visit a CallOperatorWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitCallOperatorWriteNode(Nodes.CallOperatorWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a CallOrWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitCallOrWriteNode(Nodes.CallOrWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a CallTargetNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitCallTargetNode(Nodes.CallTargetNode node) { - return defaultVisit(node); - } - - /** - * Visit a CapturePatternNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitCapturePatternNode(Nodes.CapturePatternNode node) { - return defaultVisit(node); - } - - /** - * Visit a CaseMatchNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitCaseMatchNode(Nodes.CaseMatchNode node) { - return defaultVisit(node); - } - - /** - * Visit a CaseNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitCaseNode(Nodes.CaseNode node) { - return defaultVisit(node); - } - - /** - * Visit a ClassNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitClassNode(Nodes.ClassNode node) { - return defaultVisit(node); - } - - /** - * Visit a ClassVariableAndWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitClassVariableAndWriteNode(Nodes.ClassVariableAndWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a ClassVariableOperatorWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitClassVariableOperatorWriteNode(Nodes.ClassVariableOperatorWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a ClassVariableOrWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitClassVariableOrWriteNode(Nodes.ClassVariableOrWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a ClassVariableReadNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitClassVariableReadNode(Nodes.ClassVariableReadNode node) { - return defaultVisit(node); - } - - /** - * Visit a ClassVariableTargetNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitClassVariableTargetNode(Nodes.ClassVariableTargetNode node) { - return defaultVisit(node); - } - - /** - * Visit a ClassVariableWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitClassVariableWriteNode(Nodes.ClassVariableWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantAndWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantAndWriteNode(Nodes.ConstantAndWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantOperatorWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantOperatorWriteNode(Nodes.ConstantOperatorWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantOrWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantOrWriteNode(Nodes.ConstantOrWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantPathAndWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantPathAndWriteNode(Nodes.ConstantPathAndWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantPathNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantPathNode(Nodes.ConstantPathNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantPathOperatorWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantPathOperatorWriteNode(Nodes.ConstantPathOperatorWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantPathOrWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantPathOrWriteNode(Nodes.ConstantPathOrWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantPathTargetNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantPathTargetNode(Nodes.ConstantPathTargetNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantPathWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantPathWriteNode(Nodes.ConstantPathWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantReadNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantReadNode(Nodes.ConstantReadNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantTargetNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantTargetNode(Nodes.ConstantTargetNode node) { - return defaultVisit(node); - } - - /** - * Visit a ConstantWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitConstantWriteNode(Nodes.ConstantWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a DefNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitDefNode(Nodes.DefNode node) { - return defaultVisit(node); - } - - /** - * Visit a DefinedNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitDefinedNode(Nodes.DefinedNode node) { - return defaultVisit(node); - } - - /** - * Visit a ElseNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitElseNode(Nodes.ElseNode node) { - return defaultVisit(node); - } - - /** - * Visit a EmbeddedStatementsNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitEmbeddedStatementsNode(Nodes.EmbeddedStatementsNode node) { - return defaultVisit(node); - } - - /** - * Visit a EmbeddedVariableNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitEmbeddedVariableNode(Nodes.EmbeddedVariableNode node) { - return defaultVisit(node); - } - - /** - * Visit a EnsureNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitEnsureNode(Nodes.EnsureNode node) { - return defaultVisit(node); - } - - /** - * Visit a FalseNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitFalseNode(Nodes.FalseNode node) { - return defaultVisit(node); - } - - /** - * Visit a FindPatternNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitFindPatternNode(Nodes.FindPatternNode node) { - return defaultVisit(node); - } - - /** - * Visit a FlipFlopNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitFlipFlopNode(Nodes.FlipFlopNode node) { - return defaultVisit(node); - } - - /** - * Visit a FloatNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitFloatNode(Nodes.FloatNode node) { - return defaultVisit(node); - } - - /** - * Visit a ForNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitForNode(Nodes.ForNode node) { - return defaultVisit(node); - } - - /** - * Visit a ForwardingArgumentsNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitForwardingArgumentsNode(Nodes.ForwardingArgumentsNode node) { - return defaultVisit(node); - } - - /** - * Visit a ForwardingParameterNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitForwardingParameterNode(Nodes.ForwardingParameterNode node) { - return defaultVisit(node); - } - - /** - * Visit a ForwardingSuperNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitForwardingSuperNode(Nodes.ForwardingSuperNode node) { - return defaultVisit(node); - } - - /** - * Visit a GlobalVariableAndWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitGlobalVariableAndWriteNode(Nodes.GlobalVariableAndWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a GlobalVariableOperatorWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitGlobalVariableOperatorWriteNode(Nodes.GlobalVariableOperatorWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a GlobalVariableOrWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitGlobalVariableOrWriteNode(Nodes.GlobalVariableOrWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a GlobalVariableReadNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitGlobalVariableReadNode(Nodes.GlobalVariableReadNode node) { - return defaultVisit(node); - } - - /** - * Visit a GlobalVariableTargetNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitGlobalVariableTargetNode(Nodes.GlobalVariableTargetNode node) { - return defaultVisit(node); - } - - /** - * Visit a GlobalVariableWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitGlobalVariableWriteNode(Nodes.GlobalVariableWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a HashNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitHashNode(Nodes.HashNode node) { - return defaultVisit(node); - } - - /** - * Visit a HashPatternNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitHashPatternNode(Nodes.HashPatternNode node) { - return defaultVisit(node); - } - - /** - * Visit a IfNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitIfNode(Nodes.IfNode node) { - return defaultVisit(node); - } - - /** - * Visit a ImaginaryNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitImaginaryNode(Nodes.ImaginaryNode node) { - return defaultVisit(node); - } - - /** - * Visit a ImplicitNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitImplicitNode(Nodes.ImplicitNode node) { - return defaultVisit(node); - } - - /** - * Visit a ImplicitRestNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitImplicitRestNode(Nodes.ImplicitRestNode node) { - return defaultVisit(node); - } - - /** - * Visit a InNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInNode(Nodes.InNode node) { - return defaultVisit(node); - } - - /** - * Visit a IndexAndWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitIndexAndWriteNode(Nodes.IndexAndWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a IndexOperatorWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitIndexOperatorWriteNode(Nodes.IndexOperatorWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a IndexOrWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitIndexOrWriteNode(Nodes.IndexOrWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a IndexTargetNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitIndexTargetNode(Nodes.IndexTargetNode node) { - return defaultVisit(node); - } - - /** - * Visit a InstanceVariableAndWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInstanceVariableAndWriteNode(Nodes.InstanceVariableAndWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a InstanceVariableOperatorWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInstanceVariableOperatorWriteNode(Nodes.InstanceVariableOperatorWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a InstanceVariableOrWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInstanceVariableOrWriteNode(Nodes.InstanceVariableOrWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a InstanceVariableReadNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInstanceVariableReadNode(Nodes.InstanceVariableReadNode node) { - return defaultVisit(node); - } - - /** - * Visit a InstanceVariableTargetNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInstanceVariableTargetNode(Nodes.InstanceVariableTargetNode node) { - return defaultVisit(node); - } - - /** - * Visit a InstanceVariableWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInstanceVariableWriteNode(Nodes.InstanceVariableWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a IntegerNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitIntegerNode(Nodes.IntegerNode node) { - return defaultVisit(node); - } - - /** - * Visit a InterpolatedMatchLastLineNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInterpolatedMatchLastLineNode(Nodes.InterpolatedMatchLastLineNode node) { - return defaultVisit(node); - } - - /** - * Visit a InterpolatedRegularExpressionNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInterpolatedRegularExpressionNode(Nodes.InterpolatedRegularExpressionNode node) { - return defaultVisit(node); - } - - /** - * Visit a InterpolatedStringNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInterpolatedStringNode(Nodes.InterpolatedStringNode node) { - return defaultVisit(node); - } - - /** - * Visit a InterpolatedSymbolNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInterpolatedSymbolNode(Nodes.InterpolatedSymbolNode node) { - return defaultVisit(node); - } - - /** - * Visit a InterpolatedXStringNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitInterpolatedXStringNode(Nodes.InterpolatedXStringNode node) { - return defaultVisit(node); - } - - /** - * Visit a ItLocalVariableReadNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitItLocalVariableReadNode(Nodes.ItLocalVariableReadNode node) { - return defaultVisit(node); - } - - /** - * Visit a ItParametersNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitItParametersNode(Nodes.ItParametersNode node) { - return defaultVisit(node); - } - - /** - * Visit a KeywordHashNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitKeywordHashNode(Nodes.KeywordHashNode node) { - return defaultVisit(node); - } - - /** - * Visit a KeywordRestParameterNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitKeywordRestParameterNode(Nodes.KeywordRestParameterNode node) { - return defaultVisit(node); - } - - /** - * Visit a LambdaNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitLambdaNode(Nodes.LambdaNode node) { - return defaultVisit(node); - } - - /** - * Visit a LocalVariableAndWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitLocalVariableAndWriteNode(Nodes.LocalVariableAndWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a LocalVariableOperatorWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitLocalVariableOperatorWriteNode(Nodes.LocalVariableOperatorWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a LocalVariableOrWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitLocalVariableOrWriteNode(Nodes.LocalVariableOrWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a LocalVariableReadNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitLocalVariableReadNode(Nodes.LocalVariableReadNode node) { - return defaultVisit(node); - } - - /** - * Visit a LocalVariableTargetNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitLocalVariableTargetNode(Nodes.LocalVariableTargetNode node) { - return defaultVisit(node); - } - - /** - * Visit a LocalVariableWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitLocalVariableWriteNode(Nodes.LocalVariableWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a MatchLastLineNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitMatchLastLineNode(Nodes.MatchLastLineNode node) { - return defaultVisit(node); - } - - /** - * Visit a MatchPredicateNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitMatchPredicateNode(Nodes.MatchPredicateNode node) { - return defaultVisit(node); - } - - /** - * Visit a MatchRequiredNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitMatchRequiredNode(Nodes.MatchRequiredNode node) { - return defaultVisit(node); - } - - /** - * Visit a MatchWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitMatchWriteNode(Nodes.MatchWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a MissingNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitMissingNode(Nodes.MissingNode node) { - return defaultVisit(node); - } - - /** - * Visit a ModuleNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitModuleNode(Nodes.ModuleNode node) { - return defaultVisit(node); - } - - /** - * Visit a MultiTargetNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitMultiTargetNode(Nodes.MultiTargetNode node) { - return defaultVisit(node); - } - - /** - * Visit a MultiWriteNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitMultiWriteNode(Nodes.MultiWriteNode node) { - return defaultVisit(node); - } - - /** - * Visit a NextNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitNextNode(Nodes.NextNode node) { - return defaultVisit(node); - } - - /** - * Visit a NilNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitNilNode(Nodes.NilNode node) { - return defaultVisit(node); - } - - /** - * Visit a NoBlockParameterNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitNoBlockParameterNode(Nodes.NoBlockParameterNode node) { - return defaultVisit(node); - } - - /** - * Visit a NoKeywordsParameterNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitNoKeywordsParameterNode(Nodes.NoKeywordsParameterNode node) { - return defaultVisit(node); - } - - /** - * Visit a NumberedParametersNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitNumberedParametersNode(Nodes.NumberedParametersNode node) { - return defaultVisit(node); - } - - /** - * Visit a NumberedReferenceReadNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitNumberedReferenceReadNode(Nodes.NumberedReferenceReadNode node) { - return defaultVisit(node); - } - - /** - * Visit a OptionalKeywordParameterNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitOptionalKeywordParameterNode(Nodes.OptionalKeywordParameterNode node) { - return defaultVisit(node); - } - - /** - * Visit a OptionalParameterNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitOptionalParameterNode(Nodes.OptionalParameterNode node) { - return defaultVisit(node); - } - - /** - * Visit a OrNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitOrNode(Nodes.OrNode node) { - return defaultVisit(node); - } - - /** - * Visit a ParametersNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitParametersNode(Nodes.ParametersNode node) { - return defaultVisit(node); - } - - /** - * Visit a ParenthesesNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitParenthesesNode(Nodes.ParenthesesNode node) { - return defaultVisit(node); - } - - /** - * Visit a PinnedExpressionNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitPinnedExpressionNode(Nodes.PinnedExpressionNode node) { - return defaultVisit(node); - } - - /** - * Visit a PinnedVariableNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitPinnedVariableNode(Nodes.PinnedVariableNode node) { - return defaultVisit(node); - } - - /** - * Visit a PostExecutionNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitPostExecutionNode(Nodes.PostExecutionNode node) { - return defaultVisit(node); - } - - /** - * Visit a PreExecutionNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitPreExecutionNode(Nodes.PreExecutionNode node) { - return defaultVisit(node); - } - - /** - * Visit a ProgramNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitProgramNode(Nodes.ProgramNode node) { - return defaultVisit(node); - } - - /** - * Visit a RangeNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitRangeNode(Nodes.RangeNode node) { - return defaultVisit(node); - } - - /** - * Visit a RationalNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitRationalNode(Nodes.RationalNode node) { - return defaultVisit(node); - } - - /** - * Visit a RedoNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitRedoNode(Nodes.RedoNode node) { - return defaultVisit(node); - } - - /** - * Visit a RegularExpressionNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitRegularExpressionNode(Nodes.RegularExpressionNode node) { - return defaultVisit(node); - } - - /** - * Visit a RequiredKeywordParameterNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitRequiredKeywordParameterNode(Nodes.RequiredKeywordParameterNode node) { - return defaultVisit(node); - } - - /** - * Visit a RequiredParameterNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitRequiredParameterNode(Nodes.RequiredParameterNode node) { - return defaultVisit(node); - } - - /** - * Visit a RescueModifierNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitRescueModifierNode(Nodes.RescueModifierNode node) { - return defaultVisit(node); - } - - /** - * Visit a RescueNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitRescueNode(Nodes.RescueNode node) { - return defaultVisit(node); - } - - /** - * Visit a RestParameterNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitRestParameterNode(Nodes.RestParameterNode node) { - return defaultVisit(node); - } - - /** - * Visit a RetryNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitRetryNode(Nodes.RetryNode node) { - return defaultVisit(node); - } - - /** - * Visit a ReturnNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitReturnNode(Nodes.ReturnNode node) { - return defaultVisit(node); - } - - /** - * Visit a SelfNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitSelfNode(Nodes.SelfNode node) { - return defaultVisit(node); - } - - /** - * Visit a ShareableConstantNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitShareableConstantNode(Nodes.ShareableConstantNode node) { - return defaultVisit(node); - } - - /** - * Visit a SingletonClassNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitSingletonClassNode(Nodes.SingletonClassNode node) { - return defaultVisit(node); - } - - /** - * Visit a SourceEncodingNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitSourceEncodingNode(Nodes.SourceEncodingNode node) { - return defaultVisit(node); - } - - /** - * Visit a SourceFileNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitSourceFileNode(Nodes.SourceFileNode node) { - return defaultVisit(node); - } - - /** - * Visit a SourceLineNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitSourceLineNode(Nodes.SourceLineNode node) { - return defaultVisit(node); - } - - /** - * Visit a SplatNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitSplatNode(Nodes.SplatNode node) { - return defaultVisit(node); - } - - /** - * Visit a StatementsNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitStatementsNode(Nodes.StatementsNode node) { - return defaultVisit(node); - } - - /** - * Visit a StringNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitStringNode(Nodes.StringNode node) { - return defaultVisit(node); - } - - /** - * Visit a SuperNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitSuperNode(Nodes.SuperNode node) { - return defaultVisit(node); - } - - /** - * Visit a SymbolNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitSymbolNode(Nodes.SymbolNode node) { - return defaultVisit(node); - } - - /** - * Visit a TrueNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitTrueNode(Nodes.TrueNode node) { - return defaultVisit(node); - } - - /** - * Visit a UndefNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitUndefNode(Nodes.UndefNode node) { - return defaultVisit(node); - } - - /** - * Visit a UnlessNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitUnlessNode(Nodes.UnlessNode node) { - return defaultVisit(node); - } - - /** - * Visit a UntilNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitUntilNode(Nodes.UntilNode node) { - return defaultVisit(node); - } - - /** - * Visit a WhenNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitWhenNode(Nodes.WhenNode node) { - return defaultVisit(node); - } - - /** - * Visit a WhileNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitWhileNode(Nodes.WhileNode node) { - return defaultVisit(node); - } - - /** - * Visit a XStringNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitXStringNode(Nodes.XStringNode node) { - return defaultVisit(node); - } - - /** - * Visit a YieldNode node. - * - * @param node The node to visit. - * @return The result of visiting the node. - */ - public T visitYieldNode(Nodes.YieldNode node) { - return defaultVisit(node); - } - -} -// @formatter:on diff --git a/java/api/src/main/java/org/ruby_lang/prism/Loader.java b/java/api/src/main/java/org/ruby_lang/prism/Loader.java deleted file mode 100644 index f084d169ad..0000000000 --- a/java/api/src/main/java/org/ruby_lang/prism/Loader.java +++ /dev/null @@ -1,775 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* This file is generated by the templates/template.rb script and should not */ -/* be modified manually. See */ -/* templates/java/org/ruby_lang/prism/Loader.java.erb */ -/* if you are looking to modify the */ -/* template */ -/*----------------------------------------------------------------------------*/ - -package org.ruby_lang.prism; - -import java.lang.Short; -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.Locale; - -// GENERATED BY Loader.java.erb -// @formatter:off -public class Loader { - - public static ParseResult load(byte[] serialized) { - return new Loader(serialized).load(); - } - - // Overridable methods - - public byte[] bytesToName(byte[] bytes) { - return bytes; - } - - private static final class ConstantPool { - - private final Loader loader; - private final int bufferOffset; - private final byte[][] cache; - - ConstantPool(Loader loader, int bufferOffset, int length) { - this.loader = loader; - this.bufferOffset = bufferOffset; - cache = new byte[length][]; - } - - byte[] get(ByteBuffer buffer, int oneBasedIndex) { - int index = oneBasedIndex - 1; - byte[] constant = cache[index]; - - if (constant == null) { - int offset = bufferOffset + index * 8; - int start = buffer.getInt(offset); - int length = buffer.getInt(offset + 4); - - byte[] bytes = new byte[length]; - buffer.get(start, bytes); - - constant = loader.bytesToName(bytes); - cache[index] = constant; - } - - return constant; - } - - } - - private final ByteBuffer buffer; - protected String encodingName; - private ConstantPool constantPool; - private Nodes.Source source = null; - - protected Loader(byte[] serialized) { - this.buffer = ByteBuffer.wrap(serialized).order(ByteOrder.nativeOrder()); - } - - protected ParseResult load() { - this.source = new Nodes.Source(); - - expect((byte) 'P', "incorrect prism header"); - expect((byte) 'R', "incorrect prism header"); - expect((byte) 'I', "incorrect prism header"); - expect((byte) 'S', "incorrect prism header"); - expect((byte) 'M', "incorrect prism header"); - - expect((byte) 1, "prism major version does not match"); - expect((byte) 9, "prism minor version does not match"); - expect((byte) 0, "prism patch version does not match"); - - expect((byte) 1, "Loader.java requires no location fields in the serialized output"); - - // This loads the name of the encoding. - int encodingLength = loadVarUInt(); - byte[] encodingNameBytes = new byte[encodingLength]; - buffer.get(encodingNameBytes); - this.encodingName = new String(encodingNameBytes, StandardCharsets.US_ASCII); - - source.setStartLine(loadVarSInt()); - source.setLineOffsets(loadLineOffsets()); - - ParseResult.MagicComment[] magicComments = loadMagicComments(); - Nodes.Location dataLocation = loadOptionalLocation(); - ParseResult.Error[] errors = loadErrors(); - ParseResult.Warning[] warnings = loadWarnings(); - boolean continuable = buffer.get() != 0; - - int constantPoolBufferOffset = buffer.getInt(); - int constantPoolLength = loadVarUInt(); - this.constantPool = new ConstantPool(this, constantPoolBufferOffset, constantPoolLength); - - Nodes.Node node; - if (errors.length == 0) { - node = loadNode(); - - int left = constantPoolBufferOffset - buffer.position(); - if (left != 0) { - throw new Error("Expected to consume all bytes while deserializing but there were " + left + " bytes left"); - } - - MarkNewlinesVisitor visitor = new MarkNewlinesVisitor(source); - node.accept(visitor); - } else { - node = null; - } - - return new ParseResult(node, magicComments, dataLocation, errors, warnings, continuable, source); - } - - private byte[] loadString() { - int length = loadVarUInt(); - byte[] bytes = new byte[length]; - buffer.get(bytes); - return bytes; - } - - private int[] loadLineOffsets() { - int count = loadVarUInt(); - int[] lineOffsets = new int[count]; - for (int i = 0; i < count; i++) { - lineOffsets[i] = loadVarUInt(); - } - return lineOffsets; - } - - private ParseResult.MagicComment[] loadMagicComments() { - int count = loadVarUInt(); - ParseResult.MagicComment[] magicComments = new ParseResult.MagicComment[count]; - - for (int i = 0; i < count; i++) { - Nodes.Location keyLocation = loadLocation(); - Nodes.Location valueLocation = loadLocation(); - - ParseResult.MagicComment magicComment = new ParseResult.MagicComment(keyLocation, valueLocation); - magicComments[i] = magicComment; - } - - return magicComments; - } - - private ParseResult.Error[] loadErrors() { - int count = loadVarUInt(); - ParseResult.Error[] errors = new ParseResult.Error[count]; - - // error messages only contain ASCII characters - for (int i = 0; i < count; i++) { - Nodes.ErrorType type = Nodes.ERROR_TYPES[loadVarUInt()]; - byte[] bytes = loadString(); - String message = new String(bytes, StandardCharsets.US_ASCII); - Nodes.Location location = loadLocation(); - ParseResult.ErrorLevel level = ParseResult.ERROR_LEVELS[buffer.get()]; - - ParseResult.Error error = new ParseResult.Error(type, message, location, level); - errors[i] = error; - } - - return errors; - } - - private ParseResult.Warning[] loadWarnings() { - int count = loadVarUInt(); - ParseResult.Warning[] warnings = new ParseResult.Warning[count]; - - // warning messages only contain ASCII characters - for (int i = 0; i < count; i++) { - Nodes.WarningType type = Nodes.WARNING_TYPES[loadVarUInt() - 299]; - byte[] bytes = loadString(); - String message = new String(bytes, StandardCharsets.US_ASCII); - Nodes.Location location = loadLocation(); - ParseResult.WarningLevel level = ParseResult.WARNING_LEVELS[buffer.get()]; - - ParseResult.Warning warning = new ParseResult.Warning(type, message, location, level); - warnings[i] = warning; - } - - return warnings; - } - - private Nodes.Node loadOptionalNode() { - if (buffer.get(buffer.position()) != 0) { - return loadNode(); - } else { - buffer.position(buffer.position() + 1); // continue after the 0 byte - return null; - } - } - - private byte[] loadConstant() { - return constantPool.get(buffer, loadVarUInt()); - } - - private byte[] loadOptionalConstant() { - if (buffer.get(buffer.position()) != 0) { - return loadConstant(); - } else { - buffer.position(buffer.position() + 1); // continue after the 0 byte - return null; - } - } - - private byte[][] loadConstants() { - int length = loadVarUInt(); - if (length == 0) { - return Nodes.EMPTY_IDENTIFIER_ARRAY; - } - byte[][] constants = new byte[length][]; - for (int i = 0; i < length; i++) { - constants[i] = constantPool.get(buffer, loadVarUInt()); - } - return constants; - } - - private Nodes.Location loadLocation() { - return new Nodes.Location(loadVarUInt(), loadVarUInt()); - } - - private Nodes.Location loadOptionalLocation() { - if (buffer.get() != 0) { - return loadLocation(); - } else { - return null; - } - } - - // From https://github.com/protocolbuffers/protobuf/blob/v23.1/java/core/src/main/java/com/google/protobuf/BinaryReader.java#L1507 - private int loadVarUInt() { - int x; - if ((x = buffer.get()) >= 0) { - return x; - } else if ((x ^= (buffer.get() << 7)) < 0) { - x ^= (~0 << 7); - } else if ((x ^= (buffer.get() << 14)) >= 0) { - x ^= (~0 << 7) ^ (~0 << 14); - } else if ((x ^= (buffer.get() << 21)) < 0) { - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); - } else { - x ^= buffer.get() << 28; - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); - } - return x; - } - - // From https://github.com/protocolbuffers/protobuf/blob/v25.1/java/core/src/main/java/com/google/protobuf/CodedInputStream.java#L508-L510 - private int loadVarSInt() { - int x = loadVarUInt(); - return (x >>> 1) ^ (-(x & 1)); - } - - private short loadFlags() { - int flags = loadVarUInt(); - assert flags >= 0 && flags <= Short.MAX_VALUE; - return (short) flags; - } - - private static final BigInteger UNSIGNED_LONG_MASK = BigInteger.ONE.shiftLeft(Long.SIZE).subtract(BigInteger.ONE); - - private Object loadInteger() { - boolean negative = buffer.get() != 0; - - int wordsLength = loadVarUInt(); - assert wordsLength > 0; - - // Load the first word. If it's the only word, then return an int if it - // fits into one and a long otherwise. - int firstWord = loadVarUInt(); - if (wordsLength == 1) { - if (firstWord < 0) { - if (negative && firstWord == Integer.MIN_VALUE) { - return Integer.MIN_VALUE; - } - - long words = Integer.toUnsignedLong(firstWord); - return negative ? -words : words; - } - return negative ? -firstWord : firstWord; - } - - // Load the second word. If there are only two words, then return a long - // if it fits into one and a BigInteger otherwise. - int secondWord = loadVarUInt(); - if (wordsLength == 2) { - long words = (((long) secondWord) << 32L) | Integer.toUnsignedLong(firstWord); - if (words < 0L) { - if (negative && words == Long.MIN_VALUE) { - return Long.MIN_VALUE; - } - - BigInteger result = BigInteger.valueOf(words).and(UNSIGNED_LONG_MASK); - return negative ? result.negate() : result; - } - return negative ? -words : words; - } - - // Otherwise, load the remaining words and return a BigInt. - BigInteger result = BigInteger.valueOf(Integer.toUnsignedLong(firstWord)); - result = result.or(BigInteger.valueOf(Integer.toUnsignedLong(secondWord)).shiftLeft(32)); - - for (int wordsIndex = 2; wordsIndex < wordsLength; wordsIndex++) { - result = result.or(BigInteger.valueOf(Integer.toUnsignedLong(loadVarUInt())).shiftLeft(wordsIndex * 32)); - } - - return negative ? result.negate() : result; - } - - private Nodes.Node loadNode() { - int type = buffer.get() & 0xFF; - int startOffset = loadVarUInt(); - int length = loadVarUInt(); - - switch (type) { - case 1: - return new Nodes.AliasGlobalVariableNode(startOffset, length, loadNode(), loadNode()); - case 2: - return new Nodes.AliasMethodNode(startOffset, length, loadNode(), loadNode()); - case 3: - return new Nodes.AlternationPatternNode(startOffset, length, loadNode(), loadNode()); - case 4: - return new Nodes.AndNode(startOffset, length, loadNode(), loadNode()); - case 5: - return new Nodes.ArgumentsNode(startOffset, length, loadFlags(), loadNodes()); - case 6: - return new Nodes.ArrayNode(startOffset, length, loadFlags(), loadNodes()); - case 7: - return new Nodes.ArrayPatternNode(startOffset, length, loadOptionalNode(), loadNodes(), loadOptionalNode(), loadNodes()); - case 8: - return new Nodes.AssocNode(startOffset, length, loadNode(), loadNode()); - case 9: - return new Nodes.AssocSplatNode(startOffset, length, loadOptionalNode()); - case 10: - return new Nodes.BackReferenceReadNode(startOffset, length, loadConstant()); - case 11: - return new Nodes.BeginNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode(), (Nodes.RescueNode) loadOptionalNode(), (Nodes.ElseNode) loadOptionalNode(), (Nodes.EnsureNode) loadOptionalNode()); - case 12: - return new Nodes.BlockArgumentNode(startOffset, length, loadOptionalNode()); - case 13: - return new Nodes.BlockLocalVariableNode(startOffset, length, loadFlags(), loadConstant()); - case 14: - return new Nodes.BlockNode(startOffset, length, loadConstants(), loadOptionalNode(), loadOptionalNode()); - case 15: - return new Nodes.BlockParameterNode(startOffset, length, loadFlags(), loadOptionalConstant()); - case 16: - return new Nodes.BlockParametersNode(startOffset, length, (Nodes.ParametersNode) loadOptionalNode(), loadBlockLocalVariableNodes()); - case 17: - return new Nodes.BreakNode(startOffset, length, (Nodes.ArgumentsNode) loadOptionalNode()); - case 18: - return new Nodes.CallAndWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), loadConstant(), loadConstant(), loadNode()); - case 19: - return new Nodes.CallNode(startOffset, length, loadFlags(), loadOptionalNode(), loadConstant(), (Nodes.ArgumentsNode) loadOptionalNode(), loadOptionalNode()); - case 20: - return new Nodes.CallOperatorWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), loadConstant(), loadConstant(), loadConstant(), loadNode()); - case 21: - return new Nodes.CallOrWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), loadConstant(), loadConstant(), loadNode()); - case 22: - return new Nodes.CallTargetNode(startOffset, length, loadFlags(), loadNode(), loadConstant()); - case 23: - return new Nodes.CapturePatternNode(startOffset, length, loadNode(), (Nodes.LocalVariableTargetNode) loadNode()); - case 24: - return new Nodes.CaseMatchNode(startOffset, length, loadOptionalNode(), loadInNodes(), (Nodes.ElseNode) loadOptionalNode()); - case 25: - return new Nodes.CaseNode(startOffset, length, loadOptionalNode(), loadWhenNodes(), (Nodes.ElseNode) loadOptionalNode()); - case 26: - return new Nodes.ClassNode(startOffset, length, loadConstants(), loadNode(), loadOptionalNode(), loadOptionalNode(), loadConstant()); - case 27: - return new Nodes.ClassVariableAndWriteNode(startOffset, length, loadConstant(), loadNode()); - case 28: - return new Nodes.ClassVariableOperatorWriteNode(startOffset, length, loadConstant(), loadNode(), loadConstant()); - case 29: - return new Nodes.ClassVariableOrWriteNode(startOffset, length, loadConstant(), loadNode()); - case 30: - return new Nodes.ClassVariableReadNode(startOffset, length, loadConstant()); - case 31: - return new Nodes.ClassVariableTargetNode(startOffset, length, loadConstant()); - case 32: - return new Nodes.ClassVariableWriteNode(startOffset, length, loadConstant(), loadNode()); - case 33: - return new Nodes.ConstantAndWriteNode(startOffset, length, loadConstant(), loadNode()); - case 34: - return new Nodes.ConstantOperatorWriteNode(startOffset, length, loadConstant(), loadNode(), loadConstant()); - case 35: - return new Nodes.ConstantOrWriteNode(startOffset, length, loadConstant(), loadNode()); - case 36: - return new Nodes.ConstantPathAndWriteNode(startOffset, length, (Nodes.ConstantPathNode) loadNode(), loadNode()); - case 37: - return new Nodes.ConstantPathNode(startOffset, length, loadOptionalNode(), loadOptionalConstant()); - case 38: - return new Nodes.ConstantPathOperatorWriteNode(startOffset, length, (Nodes.ConstantPathNode) loadNode(), loadNode(), loadConstant()); - case 39: - return new Nodes.ConstantPathOrWriteNode(startOffset, length, (Nodes.ConstantPathNode) loadNode(), loadNode()); - case 40: - return new Nodes.ConstantPathTargetNode(startOffset, length, loadOptionalNode(), loadOptionalConstant()); - case 41: - return new Nodes.ConstantPathWriteNode(startOffset, length, (Nodes.ConstantPathNode) loadNode(), loadNode()); - case 42: - return new Nodes.ConstantReadNode(startOffset, length, loadConstant()); - case 43: - return new Nodes.ConstantTargetNode(startOffset, length, loadConstant()); - case 44: - return new Nodes.ConstantWriteNode(startOffset, length, loadConstant(), loadNode()); - case 45: - return loadDefNode(startOffset, length); - case 46: - return new Nodes.DefinedNode(startOffset, length, loadNode()); - case 47: - return new Nodes.ElseNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode()); - case 48: - return new Nodes.EmbeddedStatementsNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode()); - case 49: - return new Nodes.EmbeddedVariableNode(startOffset, length, loadNode()); - case 50: - return new Nodes.EnsureNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode()); - case 51: - return new Nodes.FalseNode(startOffset, length); - case 52: - return new Nodes.FindPatternNode(startOffset, length, loadOptionalNode(), (Nodes.SplatNode) loadNode(), loadNodes(), (Nodes.SplatNode) loadNode()); - case 53: - return new Nodes.FlipFlopNode(startOffset, length, loadFlags(), loadOptionalNode(), loadOptionalNode()); - case 54: - return new Nodes.FloatNode(startOffset, length, buffer.getDouble()); - case 55: - return new Nodes.ForNode(startOffset, length, loadNode(), loadNode(), (Nodes.StatementsNode) loadOptionalNode()); - case 56: - return new Nodes.ForwardingArgumentsNode(startOffset, length); - case 57: - return new Nodes.ForwardingParameterNode(startOffset, length); - case 58: - return new Nodes.ForwardingSuperNode(startOffset, length, (Nodes.BlockNode) loadOptionalNode()); - case 59: - return new Nodes.GlobalVariableAndWriteNode(startOffset, length, loadConstant(), loadNode()); - case 60: - return new Nodes.GlobalVariableOperatorWriteNode(startOffset, length, loadConstant(), loadNode(), loadConstant()); - case 61: - return new Nodes.GlobalVariableOrWriteNode(startOffset, length, loadConstant(), loadNode()); - case 62: - return new Nodes.GlobalVariableReadNode(startOffset, length, loadConstant()); - case 63: - return new Nodes.GlobalVariableTargetNode(startOffset, length, loadConstant()); - case 64: - return new Nodes.GlobalVariableWriteNode(startOffset, length, loadConstant(), loadNode()); - case 65: - return new Nodes.HashNode(startOffset, length, loadNodes()); - case 66: - return new Nodes.HashPatternNode(startOffset, length, loadOptionalNode(), loadAssocNodes(), loadOptionalNode()); - case 67: - return new Nodes.IfNode(startOffset, length, loadNode(), (Nodes.StatementsNode) loadOptionalNode(), loadOptionalNode()); - case 68: - return new Nodes.ImaginaryNode(startOffset, length, loadNode()); - case 69: - return new Nodes.ImplicitNode(startOffset, length, loadNode()); - case 70: - return new Nodes.ImplicitRestNode(startOffset, length); - case 71: - return new Nodes.InNode(startOffset, length, loadNode(), (Nodes.StatementsNode) loadOptionalNode()); - case 72: - return new Nodes.IndexAndWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), (Nodes.ArgumentsNode) loadOptionalNode(), (Nodes.BlockArgumentNode) loadOptionalNode(), loadNode()); - case 73: - return new Nodes.IndexOperatorWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), (Nodes.ArgumentsNode) loadOptionalNode(), (Nodes.BlockArgumentNode) loadOptionalNode(), loadConstant(), loadNode()); - case 74: - return new Nodes.IndexOrWriteNode(startOffset, length, loadFlags(), loadOptionalNode(), (Nodes.ArgumentsNode) loadOptionalNode(), (Nodes.BlockArgumentNode) loadOptionalNode(), loadNode()); - case 75: - return new Nodes.IndexTargetNode(startOffset, length, loadFlags(), loadNode(), (Nodes.ArgumentsNode) loadOptionalNode(), (Nodes.BlockArgumentNode) loadOptionalNode()); - case 76: - return new Nodes.InstanceVariableAndWriteNode(startOffset, length, loadConstant(), loadNode()); - case 77: - return new Nodes.InstanceVariableOperatorWriteNode(startOffset, length, loadConstant(), loadNode(), loadConstant()); - case 78: - return new Nodes.InstanceVariableOrWriteNode(startOffset, length, loadConstant(), loadNode()); - case 79: - return new Nodes.InstanceVariableReadNode(startOffset, length, loadConstant()); - case 80: - return new Nodes.InstanceVariableTargetNode(startOffset, length, loadConstant()); - case 81: - return new Nodes.InstanceVariableWriteNode(startOffset, length, loadConstant(), loadNode()); - case 82: - return new Nodes.IntegerNode(startOffset, length, loadFlags(), loadInteger()); - case 83: - return new Nodes.InterpolatedMatchLastLineNode(startOffset, length, loadFlags(), loadNodes()); - case 84: - return new Nodes.InterpolatedRegularExpressionNode(startOffset, length, loadFlags(), loadNodes()); - case 85: - return new Nodes.InterpolatedStringNode(startOffset, length, loadFlags(), loadNodes()); - case 86: - return new Nodes.InterpolatedSymbolNode(startOffset, length, loadNodes()); - case 87: - return new Nodes.InterpolatedXStringNode(startOffset, length, loadNodes()); - case 88: - return new Nodes.ItLocalVariableReadNode(startOffset, length); - case 89: - return new Nodes.ItParametersNode(startOffset, length); - case 90: - return new Nodes.KeywordHashNode(startOffset, length, loadFlags(), loadNodes()); - case 91: - return new Nodes.KeywordRestParameterNode(startOffset, length, loadFlags(), loadOptionalConstant()); - case 92: - return new Nodes.LambdaNode(startOffset, length, loadConstants(), loadOptionalNode(), loadOptionalNode()); - case 93: - return new Nodes.LocalVariableAndWriteNode(startOffset, length, loadNode(), loadConstant(), loadVarUInt()); - case 94: - return new Nodes.LocalVariableOperatorWriteNode(startOffset, length, loadNode(), loadConstant(), loadConstant(), loadVarUInt()); - case 95: - return new Nodes.LocalVariableOrWriteNode(startOffset, length, loadNode(), loadConstant(), loadVarUInt()); - case 96: - return new Nodes.LocalVariableReadNode(startOffset, length, loadConstant(), loadVarUInt()); - case 97: - return new Nodes.LocalVariableTargetNode(startOffset, length, loadConstant(), loadVarUInt()); - case 98: - return new Nodes.LocalVariableWriteNode(startOffset, length, loadConstant(), loadVarUInt(), loadNode()); - case 99: - return new Nodes.MatchLastLineNode(startOffset, length, loadFlags(), loadString()); - case 100: - return new Nodes.MatchPredicateNode(startOffset, length, loadNode(), loadNode()); - case 101: - return new Nodes.MatchRequiredNode(startOffset, length, loadNode(), loadNode()); - case 102: - return new Nodes.MatchWriteNode(startOffset, length, (Nodes.CallNode) loadNode(), loadLocalVariableTargetNodes()); - case 103: - return new Nodes.MissingNode(startOffset, length); - case 104: - return new Nodes.ModuleNode(startOffset, length, loadConstants(), loadNode(), loadOptionalNode(), loadConstant()); - case 105: - return new Nodes.MultiTargetNode(startOffset, length, loadNodes(), loadOptionalNode(), loadNodes()); - case 106: - return new Nodes.MultiWriteNode(startOffset, length, loadNodes(), loadOptionalNode(), loadNodes(), loadNode()); - case 107: - return new Nodes.NextNode(startOffset, length, (Nodes.ArgumentsNode) loadOptionalNode()); - case 108: - return new Nodes.NilNode(startOffset, length); - case 109: - return new Nodes.NoBlockParameterNode(startOffset, length); - case 110: - return new Nodes.NoKeywordsParameterNode(startOffset, length); - case 111: - return new Nodes.NumberedParametersNode(startOffset, length, buffer.get()); - case 112: - return new Nodes.NumberedReferenceReadNode(startOffset, length, loadVarUInt()); - case 113: - return new Nodes.OptionalKeywordParameterNode(startOffset, length, loadFlags(), loadConstant(), loadNode()); - case 114: - return new Nodes.OptionalParameterNode(startOffset, length, loadFlags(), loadConstant(), loadNode()); - case 115: - return new Nodes.OrNode(startOffset, length, loadNode(), loadNode()); - case 116: - return new Nodes.ParametersNode(startOffset, length, loadNodes(), loadOptionalParameterNodes(), loadOptionalNode(), loadNodes(), loadNodes(), loadOptionalNode(), loadOptionalNode()); - case 117: - return new Nodes.ParenthesesNode(startOffset, length, loadFlags(), loadOptionalNode()); - case 118: - return new Nodes.PinnedExpressionNode(startOffset, length, loadNode()); - case 119: - return new Nodes.PinnedVariableNode(startOffset, length, loadNode()); - case 120: - return new Nodes.PostExecutionNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode()); - case 121: - return new Nodes.PreExecutionNode(startOffset, length, (Nodes.StatementsNode) loadOptionalNode()); - case 122: - return new Nodes.ProgramNode(startOffset, length, loadConstants(), (Nodes.StatementsNode) loadNode()); - case 123: - return new Nodes.RangeNode(startOffset, length, loadFlags(), loadOptionalNode(), loadOptionalNode()); - case 124: - return new Nodes.RationalNode(startOffset, length, loadFlags(), loadInteger(), loadInteger()); - case 125: - return new Nodes.RedoNode(startOffset, length); - case 126: - return new Nodes.RegularExpressionNode(startOffset, length, loadFlags(), loadString()); - case 127: - return new Nodes.RequiredKeywordParameterNode(startOffset, length, loadFlags(), loadConstant()); - case 128: - return new Nodes.RequiredParameterNode(startOffset, length, loadFlags(), loadConstant()); - case 129: - return new Nodes.RescueModifierNode(startOffset, length, loadNode(), loadNode()); - case 130: - return new Nodes.RescueNode(startOffset, length, loadNodes(), loadOptionalNode(), (Nodes.StatementsNode) loadOptionalNode(), (Nodes.RescueNode) loadOptionalNode()); - case 131: - return new Nodes.RestParameterNode(startOffset, length, loadFlags(), loadOptionalConstant()); - case 132: - return new Nodes.RetryNode(startOffset, length); - case 133: - return new Nodes.ReturnNode(startOffset, length, (Nodes.ArgumentsNode) loadOptionalNode()); - case 134: - return new Nodes.SelfNode(startOffset, length); - case 135: - return new Nodes.ShareableConstantNode(startOffset, length, loadFlags(), loadNode()); - case 136: - return new Nodes.SingletonClassNode(startOffset, length, loadConstants(), loadNode(), loadOptionalNode()); - case 137: - return new Nodes.SourceEncodingNode(startOffset, length); - case 138: - return new Nodes.SourceFileNode(startOffset, length, loadFlags(), loadString()); - case 139: - return new Nodes.SourceLineNode(startOffset, length); - case 140: - return new Nodes.SplatNode(startOffset, length, loadOptionalNode()); - case 141: - return new Nodes.StatementsNode(startOffset, length, loadNodes()); - case 142: - return new Nodes.StringNode(startOffset, length, loadFlags(), loadString()); - case 143: - return new Nodes.SuperNode(startOffset, length, (Nodes.ArgumentsNode) loadOptionalNode(), loadOptionalNode()); - case 144: - return new Nodes.SymbolNode(startOffset, length, loadFlags(), loadString()); - case 145: - return new Nodes.TrueNode(startOffset, length); - case 146: - return new Nodes.UndefNode(startOffset, length, loadNodes()); - case 147: - return new Nodes.UnlessNode(startOffset, length, loadNode(), (Nodes.StatementsNode) loadOptionalNode(), (Nodes.ElseNode) loadOptionalNode()); - case 148: - return new Nodes.UntilNode(startOffset, length, loadFlags(), loadNode(), (Nodes.StatementsNode) loadOptionalNode()); - case 149: - return new Nodes.WhenNode(startOffset, length, loadNodes(), (Nodes.StatementsNode) loadOptionalNode()); - case 150: - return new Nodes.WhileNode(startOffset, length, loadFlags(), loadNode(), (Nodes.StatementsNode) loadOptionalNode()); - case 151: - return new Nodes.XStringNode(startOffset, length, loadFlags(), loadString()); - case 152: - return new Nodes.YieldNode(startOffset, length, (Nodes.ArgumentsNode) loadOptionalNode()); - default: - throw new Error("Unknown node type: " + type); - } - } - - // Can be overridden to use createLazyDefNode instead - protected Nodes.DefNode loadDefNode(int startOffset, int length) { - return createDefNode(startOffset, length); - } - - protected Nodes.DefNode createLazyDefNode(int startOffset, int length) { - int bufferPosition = buffer.position(); - int serializedLength = buffer.getInt(); - // Load everything except the body and locals, because the name, receiver, parameters are still needed for lazily defining the method - Nodes.DefNode lazyDefNode = new Nodes.DefNode(startOffset, length, -bufferPosition, this, loadConstant(), loadOptionalNode(), (Nodes.ParametersNode) loadOptionalNode(), null, Nodes.EMPTY_IDENTIFIER_ARRAY); - buffer.position(bufferPosition + serializedLength); // skip past the serialized DefNode - return lazyDefNode; - } - - protected Nodes.DefNode createDefNode(int startOffset, int length) { - return new Nodes.DefNode(startOffset, length, buffer.getInt(), null, loadConstant(), loadOptionalNode(), (Nodes.ParametersNode) loadOptionalNode(), loadOptionalNode(), loadConstants()); - } - - Nodes.DefNode createDefNodeFromSavedPosition(int startOffset, int length, int bufferPosition) { - Nodes.DefNode node; - // This method mutates the buffer position and may be called from different threads so we must synchronize - synchronized (this) { - buffer.position(bufferPosition); - node = createDefNode(startOffset, length); - } - - MarkNewlinesVisitor visitor = new MarkNewlinesVisitor(source); - node.accept(visitor); - - return node; - } - - private static final Nodes.Node[] EMPTY_Node_ARRAY = {}; - - private Nodes.Node[] loadNodes() { - int length = loadVarUInt(); - if (length == 0) { - return EMPTY_Node_ARRAY; - } - Nodes.Node[] nodes = new Nodes.Node[length]; - for (int i = 0; i < length; i++) { - nodes[i] = loadNode(); - } - return nodes; - } - - private static final Nodes.BlockLocalVariableNode[] EMPTY_BlockLocalVariableNode_ARRAY = {}; - - private Nodes.BlockLocalVariableNode[] loadBlockLocalVariableNodes() { - int length = loadVarUInt(); - if (length == 0) { - return EMPTY_BlockLocalVariableNode_ARRAY; - } - Nodes.BlockLocalVariableNode[] nodes = new Nodes.BlockLocalVariableNode[length]; - for (int i = 0; i < length; i++) { - nodes[i] = (Nodes.BlockLocalVariableNode) loadNode(); - } - return nodes; - } - - private static final Nodes.InNode[] EMPTY_InNode_ARRAY = {}; - - private Nodes.InNode[] loadInNodes() { - int length = loadVarUInt(); - if (length == 0) { - return EMPTY_InNode_ARRAY; - } - Nodes.InNode[] nodes = new Nodes.InNode[length]; - for (int i = 0; i < length; i++) { - nodes[i] = (Nodes.InNode) loadNode(); - } - return nodes; - } - - private static final Nodes.WhenNode[] EMPTY_WhenNode_ARRAY = {}; - - private Nodes.WhenNode[] loadWhenNodes() { - int length = loadVarUInt(); - if (length == 0) { - return EMPTY_WhenNode_ARRAY; - } - Nodes.WhenNode[] nodes = new Nodes.WhenNode[length]; - for (int i = 0; i < length; i++) { - nodes[i] = (Nodes.WhenNode) loadNode(); - } - return nodes; - } - - private static final Nodes.AssocNode[] EMPTY_AssocNode_ARRAY = {}; - - private Nodes.AssocNode[] loadAssocNodes() { - int length = loadVarUInt(); - if (length == 0) { - return EMPTY_AssocNode_ARRAY; - } - Nodes.AssocNode[] nodes = new Nodes.AssocNode[length]; - for (int i = 0; i < length; i++) { - nodes[i] = (Nodes.AssocNode) loadNode(); - } - return nodes; - } - - private static final Nodes.LocalVariableTargetNode[] EMPTY_LocalVariableTargetNode_ARRAY = {}; - - private Nodes.LocalVariableTargetNode[] loadLocalVariableTargetNodes() { - int length = loadVarUInt(); - if (length == 0) { - return EMPTY_LocalVariableTargetNode_ARRAY; - } - Nodes.LocalVariableTargetNode[] nodes = new Nodes.LocalVariableTargetNode[length]; - for (int i = 0; i < length; i++) { - nodes[i] = (Nodes.LocalVariableTargetNode) loadNode(); - } - return nodes; - } - - private static final Nodes.OptionalParameterNode[] EMPTY_OptionalParameterNode_ARRAY = {}; - - private Nodes.OptionalParameterNode[] loadOptionalParameterNodes() { - int length = loadVarUInt(); - if (length == 0) { - return EMPTY_OptionalParameterNode_ARRAY; - } - Nodes.OptionalParameterNode[] nodes = new Nodes.OptionalParameterNode[length]; - for (int i = 0; i < length; i++) { - nodes[i] = (Nodes.OptionalParameterNode) loadNode(); - } - return nodes; - } - - private void expect(byte value, String error) { - byte b = buffer.get(); - if (b != value) { - throw new Error("Deserialization error: " + error + " (expected " + value + " but was " + b + " at position " + buffer.position() + ")"); - } - } - -} -// @formatter:on diff --git a/java/api/src/main/java/org/ruby_lang/prism/Nodes.java b/java/api/src/main/java/org/ruby_lang/prism/Nodes.java deleted file mode 100644 index 8f032d5fa0..0000000000 --- a/java/api/src/main/java/org/ruby_lang/prism/Nodes.java +++ /dev/null @@ -1,11628 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* This file is generated by the templates/template.rb script and should not */ -/* be modified manually. See */ -/* templates/java/org/ruby_lang/prism/Nodes.java.erb */ -/* if you are looking to modify the */ -/* template */ -/*----------------------------------------------------------------------------*/ - -package org.ruby_lang.prism; - -import java.lang.Override; -import java.lang.String; -import java.lang.StringBuilder; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; - -// GENERATED BY Nodes.java.erb -// @formatter:off -public abstract class Nodes { - - public static final byte[][] EMPTY_IDENTIFIER_ARRAY = {}; - - @Target(ElementType.FIELD) - @Retention(RetentionPolicy.SOURCE) - public @interface Nullable { - } - - @Target(ElementType.FIELD) - @Retention(RetentionPolicy.SOURCE) - public @interface UnionType { - Class[] value(); - } - - public static final class Location { - - public static final Location[] EMPTY_ARRAY = {}; - - public final int startOffset; - public final int length; - - public Location(int startOffset, int length) { - this.startOffset = startOffset; - this.length = length; - } - - public int endOffset() { - return startOffset + length; - } - } - - public static final class Source { - private int startLine = 1; - private int[] lineOffsets = null; - - Source() { - } - - void setStartLine(int startLine) { - this.startLine = startLine; - } - - void setLineOffsets(int[] lineOffsets) { - this.lineOffsets = lineOffsets; - } - - // 1-based - public int line(int byteOffset) { - return startLine + findLine(byteOffset); - } - - // 0-based - public int findLine(int byteOffset) { - assert byteOffset >= 0 : byteOffset; - int index = Arrays.binarySearch(lineOffsets, byteOffset); - int line; - if (index < 0) { - line = -index - 2; - } else { - line = index; - } - assert line >= 0 && line <= getLineCount() : line; - return line; - } - - public int getLineCount() { - return lineOffsets.length; - } - } - - public static abstract class Node { - - public static final Node[] EMPTY_ARRAY = {}; - - public final int startOffset; - public final int length; - private boolean newLineFlag = false; - - public Node(int startOffset, int length) { - this.startOffset = startOffset; - this.length = length; - } - - public final int endOffset() { - return startOffset + length; - } - - public final boolean hasNewLineFlag() { - return newLineFlag; - } - - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - int line = source.findLine(this.startOffset); - if (!newlineMarked[line]) { - newlineMarked[line] = true; - this.newLineFlag = true; - } - } - - public void setNewLineFlag(boolean newLineFlag) { - this.newLineFlag = newLineFlag; - } - - public abstract T accept(AbstractNodeVisitor visitor); - - public abstract void visitChildNodes(AbstractNodeVisitor visitor); - - public abstract Node[] childNodes(); - - @Override - public String toString() { - return toString(""); - } - - protected abstract String toString(String indent); - } - - protected static String asString(Object value) { - return value.toString(); - } - - protected static String asString(byte[] value) { - StringBuilder buf = new StringBuilder(value.length); - for (byte b : value) { - if (b >= 0x20 && b <= 0x7e) { - buf.append((char) b); - } else { - buf.append(String.format("\\x%02x", Byte.toUnsignedInt(b))); - } - } - return buf.toString(); - } - - /** - * Flags for arguments nodes. - */ - public static final class ArgumentsNodeFlags implements Comparable { - - // if the arguments contain forwarding - public static final short CONTAINS_FORWARDING = 1 << 2; - - // if the arguments contain keywords - public static final short CONTAINS_KEYWORDS = 1 << 3; - - // if the arguments contain a keyword splat - public static final short CONTAINS_KEYWORD_SPLAT = 1 << 4; - - // if the arguments contain a splat - public static final short CONTAINS_SPLAT = 1 << 5; - - // if the arguments contain multiple splats - public static final short CONTAINS_MULTIPLE_SPLATS = 1 << 6; - - public static boolean isContainsForwarding(short flags) { - return (flags & CONTAINS_FORWARDING) != 0; - } - - public static boolean isContainsKeywords(short flags) { - return (flags & CONTAINS_KEYWORDS) != 0; - } - - public static boolean isContainsKeywordSplat(short flags) { - return (flags & CONTAINS_KEYWORD_SPLAT) != 0; - } - - public static boolean isContainsSplat(short flags) { - return (flags & CONTAINS_SPLAT) != 0; - } - - public static boolean isContainsMultipleSplats(short flags) { - return (flags & CONTAINS_MULTIPLE_SPLATS) != 0; - } - - private final short flags; - - public ArgumentsNodeFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof ArgumentsNodeFlags)) { - return false; - } - - return flags == ((ArgumentsNodeFlags) other).flags; - } - - @Override - public int compareTo(ArgumentsNodeFlags other) { - return flags - other.flags; - } - - public boolean isContainsForwarding() { - return (flags & CONTAINS_FORWARDING) != 0; - } - - public boolean isContainsKeywords() { - return (flags & CONTAINS_KEYWORDS) != 0; - } - - public boolean isContainsKeywordSplat() { - return (flags & CONTAINS_KEYWORD_SPLAT) != 0; - } - - public boolean isContainsSplat() { - return (flags & CONTAINS_SPLAT) != 0; - } - - public boolean isContainsMultipleSplats() { - return (flags & CONTAINS_MULTIPLE_SPLATS) != 0; - } - - } - - /** - * Flags for array nodes. - */ - public static final class ArrayNodeFlags implements Comparable { - - // if array contains splat nodes - public static final short CONTAINS_SPLAT = 1 << 2; - - public static boolean isContainsSplat(short flags) { - return (flags & CONTAINS_SPLAT) != 0; - } - - private final short flags; - - public ArrayNodeFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof ArrayNodeFlags)) { - return false; - } - - return flags == ((ArrayNodeFlags) other).flags; - } - - @Override - public int compareTo(ArrayNodeFlags other) { - return flags - other.flags; - } - - public boolean isContainsSplat() { - return (flags & CONTAINS_SPLAT) != 0; - } - - } - - /** - * Flags for call nodes. - */ - public static final class CallNodeFlags implements Comparable { - - // &. operator - public static final short SAFE_NAVIGATION = 1 << 2; - - // a call that could have been a local variable - public static final short VARIABLE_CALL = 1 << 3; - - // a call that is an attribute write, so the value being written should be returned - public static final short ATTRIBUTE_WRITE = 1 << 4; - - // a call that ignores method visibility - public static final short IGNORE_VISIBILITY = 1 << 5; - - public static boolean isSafeNavigation(short flags) { - return (flags & SAFE_NAVIGATION) != 0; - } - - public static boolean isVariableCall(short flags) { - return (flags & VARIABLE_CALL) != 0; - } - - public static boolean isAttributeWrite(short flags) { - return (flags & ATTRIBUTE_WRITE) != 0; - } - - public static boolean isIgnoreVisibility(short flags) { - return (flags & IGNORE_VISIBILITY) != 0; - } - - private final short flags; - - public CallNodeFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof CallNodeFlags)) { - return false; - } - - return flags == ((CallNodeFlags) other).flags; - } - - @Override - public int compareTo(CallNodeFlags other) { - return flags - other.flags; - } - - public boolean isSafeNavigation() { - return (flags & SAFE_NAVIGATION) != 0; - } - - public boolean isVariableCall() { - return (flags & VARIABLE_CALL) != 0; - } - - public boolean isAttributeWrite() { - return (flags & ATTRIBUTE_WRITE) != 0; - } - - public boolean isIgnoreVisibility() { - return (flags & IGNORE_VISIBILITY) != 0; - } - - } - - /** - * Flags for nodes that have unescaped content. - */ - public static final class EncodingFlags implements Comparable { - - // internal bytes forced the encoding to UTF-8 - public static final short FORCED_UTF8_ENCODING = 1 << 2; - - // internal bytes forced the encoding to binary - public static final short FORCED_BINARY_ENCODING = 1 << 3; - - public static boolean isForcedUtf8Encoding(short flags) { - return (flags & FORCED_UTF8_ENCODING) != 0; - } - - public static boolean isForcedBinaryEncoding(short flags) { - return (flags & FORCED_BINARY_ENCODING) != 0; - } - - private final short flags; - - public EncodingFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof EncodingFlags)) { - return false; - } - - return flags == ((EncodingFlags) other).flags; - } - - @Override - public int compareTo(EncodingFlags other) { - return flags - other.flags; - } - - public boolean isForcedUtf8Encoding() { - return (flags & FORCED_UTF8_ENCODING) != 0; - } - - public boolean isForcedBinaryEncoding() { - return (flags & FORCED_BINARY_ENCODING) != 0; - } - - } - - /** - * Flags for integer nodes that correspond to the base of the integer. - */ - public static final class IntegerBaseFlags implements Comparable { - - // 0b prefix - public static final short BINARY = 1 << 2; - - // 0d or no prefix - public static final short DECIMAL = 1 << 3; - - // 0o or 0 prefix - public static final short OCTAL = 1 << 4; - - // 0x prefix - public static final short HEXADECIMAL = 1 << 5; - - public static boolean isBinary(short flags) { - return (flags & BINARY) != 0; - } - - public static boolean isDecimal(short flags) { - return (flags & DECIMAL) != 0; - } - - public static boolean isOctal(short flags) { - return (flags & OCTAL) != 0; - } - - public static boolean isHexadecimal(short flags) { - return (flags & HEXADECIMAL) != 0; - } - - private final short flags; - - public IntegerBaseFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof IntegerBaseFlags)) { - return false; - } - - return flags == ((IntegerBaseFlags) other).flags; - } - - @Override - public int compareTo(IntegerBaseFlags other) { - return flags - other.flags; - } - - public boolean isBinary() { - return (flags & BINARY) != 0; - } - - public boolean isDecimal() { - return (flags & DECIMAL) != 0; - } - - public boolean isOctal() { - return (flags & OCTAL) != 0; - } - - public boolean isHexadecimal() { - return (flags & HEXADECIMAL) != 0; - } - - } - - /** - * Flags for interpolated string nodes that indicated mutability if they are also marked as literals. - */ - public static final class InterpolatedStringNodeFlags implements Comparable { - - // frozen by virtue of a `frozen_string_literal: true` comment or `--enable-frozen-string-literal`; only for adjacent string literals like `'a' 'b'` - public static final short FROZEN = 1 << 2; - - // mutable by virtue of a `frozen_string_literal: false` comment or `--disable-frozen-string-literal`; only for adjacent string literals like `'a' 'b'` - public static final short MUTABLE = 1 << 3; - - public static boolean isFrozen(short flags) { - return (flags & FROZEN) != 0; - } - - public static boolean isMutable(short flags) { - return (flags & MUTABLE) != 0; - } - - private final short flags; - - public InterpolatedStringNodeFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof InterpolatedStringNodeFlags)) { - return false; - } - - return flags == ((InterpolatedStringNodeFlags) other).flags; - } - - @Override - public int compareTo(InterpolatedStringNodeFlags other) { - return flags - other.flags; - } - - public boolean isFrozen() { - return (flags & FROZEN) != 0; - } - - public boolean isMutable() { - return (flags & MUTABLE) != 0; - } - - } - - /** - * Flags for keyword hash nodes. - */ - public static final class KeywordHashNodeFlags implements Comparable { - - // a keyword hash which only has `AssocNode` elements all with symbol keys, which means the elements can be treated as keyword arguments - public static final short SYMBOL_KEYS = 1 << 2; - - public static boolean isSymbolKeys(short flags) { - return (flags & SYMBOL_KEYS) != 0; - } - - private final short flags; - - public KeywordHashNodeFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof KeywordHashNodeFlags)) { - return false; - } - - return flags == ((KeywordHashNodeFlags) other).flags; - } - - @Override - public int compareTo(KeywordHashNodeFlags other) { - return flags - other.flags; - } - - public boolean isSymbolKeys() { - return (flags & SYMBOL_KEYS) != 0; - } - - } - - /** - * Flags for while and until loop nodes. - */ - public static final class LoopFlags implements Comparable { - - // a loop after a begin statement, so the body is executed first before the condition - public static final short BEGIN_MODIFIER = 1 << 2; - - public static boolean isBeginModifier(short flags) { - return (flags & BEGIN_MODIFIER) != 0; - } - - private final short flags; - - public LoopFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof LoopFlags)) { - return false; - } - - return flags == ((LoopFlags) other).flags; - } - - @Override - public int compareTo(LoopFlags other) { - return flags - other.flags; - } - - public boolean isBeginModifier() { - return (flags & BEGIN_MODIFIER) != 0; - } - - } - - /** - * Flags for parameter nodes. - */ - public static final class ParameterFlags implements Comparable { - - // a parameter name that has been repeated in the method signature - public static final short REPEATED_PARAMETER = 1 << 2; - - public static boolean isRepeatedParameter(short flags) { - return (flags & REPEATED_PARAMETER) != 0; - } - - private final short flags; - - public ParameterFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof ParameterFlags)) { - return false; - } - - return flags == ((ParameterFlags) other).flags; - } - - @Override - public int compareTo(ParameterFlags other) { - return flags - other.flags; - } - - public boolean isRepeatedParameter() { - return (flags & REPEATED_PARAMETER) != 0; - } - - } - - /** - * Flags for parentheses nodes. - */ - public static final class ParenthesesNodeFlags implements Comparable { - - // parentheses that contain multiple potentially void statements - public static final short MULTIPLE_STATEMENTS = 1 << 2; - - public static boolean isMultipleStatements(short flags) { - return (flags & MULTIPLE_STATEMENTS) != 0; - } - - private final short flags; - - public ParenthesesNodeFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof ParenthesesNodeFlags)) { - return false; - } - - return flags == ((ParenthesesNodeFlags) other).flags; - } - - @Override - public int compareTo(ParenthesesNodeFlags other) { - return flags - other.flags; - } - - public boolean isMultipleStatements() { - return (flags & MULTIPLE_STATEMENTS) != 0; - } - - } - - /** - * Flags for range and flip-flop nodes. - */ - public static final class RangeFlags implements Comparable { - - // ... operator - public static final short EXCLUDE_END = 1 << 2; - - public static boolean isExcludeEnd(short flags) { - return (flags & EXCLUDE_END) != 0; - } - - private final short flags; - - public RangeFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof RangeFlags)) { - return false; - } - - return flags == ((RangeFlags) other).flags; - } - - @Override - public int compareTo(RangeFlags other) { - return flags - other.flags; - } - - public boolean isExcludeEnd() { - return (flags & EXCLUDE_END) != 0; - } - - } - - /** - * Flags for regular expression and match last line nodes. - */ - public static final class RegularExpressionFlags implements Comparable { - - // i - ignores the case of characters when matching - public static final short IGNORE_CASE = 1 << 2; - - // x - ignores whitespace and allows comments in regular expressions - public static final short EXTENDED = 1 << 3; - - // m - allows $ to match the end of lines within strings - public static final short MULTI_LINE = 1 << 4; - - // o - only interpolates values into the regular expression once - public static final short ONCE = 1 << 5; - - // e - forces the EUC-JP encoding - public static final short EUC_JP = 1 << 6; - - // n - forces the ASCII-8BIT encoding - public static final short ASCII_8BIT = 1 << 7; - - // s - forces the Windows-31J encoding - public static final short WINDOWS_31J = 1 << 8; - - // u - forces the UTF-8 encoding - public static final short UTF_8 = 1 << 9; - - // internal bytes forced the encoding to UTF-8 - public static final short FORCED_UTF8_ENCODING = 1 << 10; - - // internal bytes forced the encoding to binary - public static final short FORCED_BINARY_ENCODING = 1 << 11; - - // internal bytes forced the encoding to US-ASCII - public static final short FORCED_US_ASCII_ENCODING = 1 << 12; - - public static boolean isIgnoreCase(short flags) { - return (flags & IGNORE_CASE) != 0; - } - - public static boolean isExtended(short flags) { - return (flags & EXTENDED) != 0; - } - - public static boolean isMultiLine(short flags) { - return (flags & MULTI_LINE) != 0; - } - - public static boolean isOnce(short flags) { - return (flags & ONCE) != 0; - } - - public static boolean isEucJp(short flags) { - return (flags & EUC_JP) != 0; - } - - public static boolean isAscii8bit(short flags) { - return (flags & ASCII_8BIT) != 0; - } - - public static boolean isWindows31j(short flags) { - return (flags & WINDOWS_31J) != 0; - } - - public static boolean isUtf8(short flags) { - return (flags & UTF_8) != 0; - } - - public static boolean isForcedUtf8Encoding(short flags) { - return (flags & FORCED_UTF8_ENCODING) != 0; - } - - public static boolean isForcedBinaryEncoding(short flags) { - return (flags & FORCED_BINARY_ENCODING) != 0; - } - - public static boolean isForcedUsAsciiEncoding(short flags) { - return (flags & FORCED_US_ASCII_ENCODING) != 0; - } - - private final short flags; - - public RegularExpressionFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof RegularExpressionFlags)) { - return false; - } - - return flags == ((RegularExpressionFlags) other).flags; - } - - @Override - public int compareTo(RegularExpressionFlags other) { - return flags - other.flags; - } - - public boolean isIgnoreCase() { - return (flags & IGNORE_CASE) != 0; - } - - public boolean isExtended() { - return (flags & EXTENDED) != 0; - } - - public boolean isMultiLine() { - return (flags & MULTI_LINE) != 0; - } - - public boolean isOnce() { - return (flags & ONCE) != 0; - } - - public boolean isEucJp() { - return (flags & EUC_JP) != 0; - } - - public boolean isAscii8bit() { - return (flags & ASCII_8BIT) != 0; - } - - public boolean isWindows31j() { - return (flags & WINDOWS_31J) != 0; - } - - public boolean isUtf8() { - return (flags & UTF_8) != 0; - } - - public boolean isForcedUtf8Encoding() { - return (flags & FORCED_UTF8_ENCODING) != 0; - } - - public boolean isForcedBinaryEncoding() { - return (flags & FORCED_BINARY_ENCODING) != 0; - } - - public boolean isForcedUsAsciiEncoding() { - return (flags & FORCED_US_ASCII_ENCODING) != 0; - } - - } - - /** - * Flags for shareable constant nodes. - */ - public static final class ShareableConstantNodeFlags implements Comparable { - - // constant writes that should be modified with shareable constant value literal - public static final short LITERAL = 1 << 2; - - // constant writes that should be modified with shareable constant value experimental everything - public static final short EXPERIMENTAL_EVERYTHING = 1 << 3; - - // constant writes that should be modified with shareable constant value experimental copy - public static final short EXPERIMENTAL_COPY = 1 << 4; - - public static boolean isLiteral(short flags) { - return (flags & LITERAL) != 0; - } - - public static boolean isExperimentalEverything(short flags) { - return (flags & EXPERIMENTAL_EVERYTHING) != 0; - } - - public static boolean isExperimentalCopy(short flags) { - return (flags & EXPERIMENTAL_COPY) != 0; - } - - private final short flags; - - public ShareableConstantNodeFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof ShareableConstantNodeFlags)) { - return false; - } - - return flags == ((ShareableConstantNodeFlags) other).flags; - } - - @Override - public int compareTo(ShareableConstantNodeFlags other) { - return flags - other.flags; - } - - public boolean isLiteral() { - return (flags & LITERAL) != 0; - } - - public boolean isExperimentalEverything() { - return (flags & EXPERIMENTAL_EVERYTHING) != 0; - } - - public boolean isExperimentalCopy() { - return (flags & EXPERIMENTAL_COPY) != 0; - } - - } - - /** - * Flags for string nodes. - */ - public static final class StringFlags implements Comparable { - - // internal bytes forced the encoding to UTF-8 - public static final short FORCED_UTF8_ENCODING = 1 << 2; - - // internal bytes forced the encoding to binary - public static final short FORCED_BINARY_ENCODING = 1 << 3; - - // frozen by virtue of a `frozen_string_literal: true` comment or `--enable-frozen-string-literal` - public static final short FROZEN = 1 << 4; - - // mutable by virtue of a `frozen_string_literal: false` comment or `--disable-frozen-string-literal` - public static final short MUTABLE = 1 << 5; - - public static boolean isForcedUtf8Encoding(short flags) { - return (flags & FORCED_UTF8_ENCODING) != 0; - } - - public static boolean isForcedBinaryEncoding(short flags) { - return (flags & FORCED_BINARY_ENCODING) != 0; - } - - public static boolean isFrozen(short flags) { - return (flags & FROZEN) != 0; - } - - public static boolean isMutable(short flags) { - return (flags & MUTABLE) != 0; - } - - private final short flags; - - public StringFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof StringFlags)) { - return false; - } - - return flags == ((StringFlags) other).flags; - } - - @Override - public int compareTo(StringFlags other) { - return flags - other.flags; - } - - public boolean isForcedUtf8Encoding() { - return (flags & FORCED_UTF8_ENCODING) != 0; - } - - public boolean isForcedBinaryEncoding() { - return (flags & FORCED_BINARY_ENCODING) != 0; - } - - public boolean isFrozen() { - return (flags & FROZEN) != 0; - } - - public boolean isMutable() { - return (flags & MUTABLE) != 0; - } - - } - - /** - * Flags for symbol nodes. - */ - public static final class SymbolFlags implements Comparable { - - // internal bytes forced the encoding to UTF-8 - public static final short FORCED_UTF8_ENCODING = 1 << 2; - - // internal bytes forced the encoding to binary - public static final short FORCED_BINARY_ENCODING = 1 << 3; - - // internal bytes forced the encoding to US-ASCII - public static final short FORCED_US_ASCII_ENCODING = 1 << 4; - - public static boolean isForcedUtf8Encoding(short flags) { - return (flags & FORCED_UTF8_ENCODING) != 0; - } - - public static boolean isForcedBinaryEncoding(short flags) { - return (flags & FORCED_BINARY_ENCODING) != 0; - } - - public static boolean isForcedUsAsciiEncoding(short flags) { - return (flags & FORCED_US_ASCII_ENCODING) != 0; - } - - private final short flags; - - public SymbolFlags(short flags) { - this.flags = flags; - } - - @Override - public int hashCode() { - return flags; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof SymbolFlags)) { - return false; - } - - return flags == ((SymbolFlags) other).flags; - } - - @Override - public int compareTo(SymbolFlags other) { - return flags - other.flags; - } - - public boolean isForcedUtf8Encoding() { - return (flags & FORCED_UTF8_ENCODING) != 0; - } - - public boolean isForcedBinaryEncoding() { - return (flags & FORCED_BINARY_ENCODING) != 0; - } - - public boolean isForcedUsAsciiEncoding() { - return (flags & FORCED_US_ASCII_ENCODING) != 0; - } - - } - - /** - *
-     * Represents the use of the `alias` keyword to alias a global variable.
-     *
-     *     alias $foo $bar
-     *     ^^^^^^^^^^^^^^^
-     * 
- */ - public static final class AliasGlobalVariableNode extends Node { - /** - *
-         * Represents the new name of the global variable that can be used after aliasing.
-         *
-         *     alias $foo $bar
-         *           ^^^^
-         * 
- */ - @UnionType({ GlobalVariableReadNode.class, BackReferenceReadNode.class, NumberedReferenceReadNode.class }) - public final Node new_name; - /** - *
-         * Represents the old name of the global variable that can be used before aliasing.
-         *
-         *     alias $foo $bar
-         *                ^^^^
-         * 
- */ - @UnionType({ GlobalVariableReadNode.class, BackReferenceReadNode.class, NumberedReferenceReadNode.class }) - public final Node old_name; - - public AliasGlobalVariableNode(int startOffset, int length, Node new_name, Node old_name) { - super(startOffset, length); - this.new_name = new_name; - this.old_name = old_name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.new_name.accept(visitor); - this.old_name.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.new_name, this.old_name }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitAliasGlobalVariableNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("new_name: "); - builder.append(this.new_name.toString(nextIndent)); - builder.append(nextIndent); - builder.append("old_name: "); - builder.append(this.old_name.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `alias` keyword to alias a method.
-     *
-     *     alias foo bar
-     *     ^^^^^^^^^^^^^
-     * 
- */ - public static final class AliasMethodNode extends Node { - /** - *
-         * Represents the new name of the method that will be aliased.
-         *
-         *     alias foo bar
-         *           ^^^
-         *
-         *     alias :foo :bar
-         *           ^^^^
-         *
-         *     alias :"#{foo}" :"#{bar}"
-         *           ^^^^^^^^^
-         * 
- */ - @UnionType({ SymbolNode.class, InterpolatedSymbolNode.class }) - public final Node new_name; - /** - *
-         * Represents the old name of the method that will be aliased.
-         *
-         *     alias foo bar
-         *               ^^^
-         *
-         *     alias :foo :bar
-         *                ^^^^
-         *
-         *     alias :"#{foo}" :"#{bar}"
-         *                     ^^^^^^^^^
-         * 
- */ - @UnionType({ SymbolNode.class, InterpolatedSymbolNode.class }) - public final Node old_name; - - public AliasMethodNode(int startOffset, int length, Node new_name, Node old_name) { - super(startOffset, length); - this.new_name = new_name; - this.old_name = old_name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.new_name.accept(visitor); - this.old_name.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.new_name, this.old_name }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitAliasMethodNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("new_name: "); - builder.append(this.new_name.toString(nextIndent)); - builder.append(nextIndent); - builder.append("old_name: "); - builder.append(this.old_name.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents an alternation pattern in pattern matching.
-     *
-     *     foo => bar | baz
-     *            ^^^^^^^^^
-     * 
- */ - public static final class AlternationPatternNode extends Node { - /** - *
-         * Represents the left side of the expression.
-         *
-         *     foo => bar | baz
-         *            ^^^
-         * 
- */ - public final Node left; - /** - *
-         * Represents the right side of the expression.
-         *
-         *     foo => bar | baz
-         *                  ^^^
-         * 
- */ - public final Node right; - - public AlternationPatternNode(int startOffset, int length, Node left, Node right) { - super(startOffset, length); - this.left = left; - this.right = right; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.left.accept(visitor); - this.right.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.left, this.right }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitAlternationPatternNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("left: "); - builder.append(this.left.toString(nextIndent)); - builder.append(nextIndent); - builder.append("right: "); - builder.append(this.right.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `&&` operator or the `and` keyword.
-     *
-     *     left and right
-     *     ^^^^^^^^^^^^^^
-     * 
- */ - public static final class AndNode extends Node { - /** - *
-         * Represents the left side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     left and right
-         *     ^^^^
-         *
-         *     1 && 2
-         *     ^
-         * 
- */ - public final Node left; - /** - *
-         * Represents the right side of the expression.
-         *
-         *     left && right
-         *             ^^^^^
-         *
-         *     1 and 2
-         *           ^
-         * 
- */ - public final Node right; - - public AndNode(int startOffset, int length, Node left, Node right) { - super(startOffset, length); - this.left = left; - this.right = right; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.left.accept(visitor); - this.right.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.left, this.right }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitAndNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("left: "); - builder.append(this.left.toString(nextIndent)); - builder.append(nextIndent); - builder.append("right: "); - builder.append(this.right.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a set of arguments to a method or a keyword.
-     *
-     *     return foo, bar, baz
-     *            ^^^^^^^^^^^^^
-     * 
- */ - public static final class ArgumentsNode extends Node { - public final short flags; - /** - *
-         * The list of arguments, if present. These can be any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     foo(bar, baz)
-         *         ^^^^^^^^
-         * 
- */ - public final Node[] arguments; - - public ArgumentsNode(int startOffset, int length, short flags, Node[] arguments) { - super(startOffset, length); - this.flags = flags; - this.arguments = arguments; - } - - public boolean isContainsForwarding() { - return ArgumentsNodeFlags.isContainsForwarding(flags); - } - - public boolean isContainsKeywords() { - return ArgumentsNodeFlags.isContainsKeywords(flags); - } - - public boolean isContainsKeywordSplat() { - return ArgumentsNodeFlags.isContainsKeywordSplat(flags); - } - - public boolean isContainsSplat() { - return ArgumentsNodeFlags.isContainsSplat(flags); - } - - public boolean isContainsMultipleSplats() { - return ArgumentsNodeFlags.isContainsMultipleSplats(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.arguments) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.arguments)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitArgumentsNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("ArgumentsNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("arguments: "); - builder.append('\n'); - for (Node child : this.arguments) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents an array literal. This can be a regular array using brackets or a special array using % like %w or %i.
-     *
-     *     [1, 2, 3]
-     *     ^^^^^^^^^
-     * 
- */ - public static final class ArrayNode extends Node { - public final short flags; - /** - *
-         * Represent the list of zero or more [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression) within the array.
-         * 
- */ - public final Node[] elements; - - public ArrayNode(int startOffset, int length, short flags, Node[] elements) { - super(startOffset, length); - this.flags = flags; - this.elements = elements; - } - - public boolean isContainsSplat() { - return ArrayNodeFlags.isContainsSplat(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.elements) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.elements)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitArrayNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("ArrayNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("elements: "); - builder.append('\n'); - for (Node child : this.elements) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents an array pattern in pattern matching.
-     *
-     *     foo in 1, 2
-     *            ^^^^
-     *
-     *     foo in [1, 2]
-     *            ^^^^^^
-     *
-     *     foo in *bar
-     *            ^^^^
-     *
-     *     foo in Bar[]
-     *            ^^^^^
-     *
-     *     foo in Bar[1, 2, 3]
-     *            ^^^^^^^^^^^^
-     * 
- */ - public static final class ArrayPatternNode extends Node { - /** - *
-         * Represents the optional constant preceding the Array
-         *
-         *     foo in Bar[]
-         *            ^^^
-         *
-         *     foo in Bar[1, 2, 3]
-         *            ^^^
-         *
-         *     foo in Bar::Baz[1, 2, 3]
-         *            ^^^^^^^^
-         * 
- */ - @Nullable - @UnionType({ ConstantPathNode.class, ConstantReadNode.class }) - public final Node constant; - /** - *
-         * Represents the required elements of the array pattern.
-         *
-         *     foo in [1, 2]
-         *             ^  ^
-         * 
- */ - public final Node[] requireds; - /** - *
-         * Represents the rest element of the array pattern.
-         *
-         *     foo in *bar
-         *            ^^^^
-         * 
- */ - @Nullable - public final Node rest; - /** - *
-         * Represents the elements after the rest element of the array pattern.
-         *
-         *     foo in *bar, baz
-         *                  ^^^
-         * 
- */ - public final Node[] posts; - - public ArrayPatternNode(int startOffset, int length, Node constant, Node[] requireds, Node rest, Node[] posts) { - super(startOffset, length); - this.constant = constant; - this.requireds = requireds; - this.rest = rest; - this.posts = posts; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.constant != null) { - this.constant.accept(visitor); - } - for (Nodes.Node child : this.requireds) { - child.accept(visitor); - } - if (this.rest != null) { - this.rest.accept(visitor); - } - for (Nodes.Node child : this.posts) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.add(this.constant); - childNodes.addAll(Arrays.asList(this.requireds)); - childNodes.add(this.rest); - childNodes.addAll(Arrays.asList(this.posts)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitArrayPatternNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("constant: "); - builder.append(this.constant == null ? "null\n" : this.constant.toString(nextIndent)); - builder.append(nextIndent); - builder.append("requireds: "); - builder.append('\n'); - for (Node child : this.requireds) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("rest: "); - builder.append(this.rest == null ? "null\n" : this.rest.toString(nextIndent)); - builder.append(nextIndent); - builder.append("posts: "); - builder.append('\n'); - for (Node child : this.posts) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents a hash key/value pair.
-     *
-     *     { a => b }
-     *       ^^^^^^
-     * 
- */ - public static final class AssocNode extends Node { - /** - *
-         * The key of the association. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     { a: b }
-         *       ^
-         *
-         *     { foo => bar }
-         *       ^^^
-         *
-         *     { def a; end => 1 }
-         *       ^^^^^^^^^^
-         * 
- */ - public final Node key; - /** - *
-         * The value of the association, if present. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     { foo => bar }
-         *              ^^^
-         *
-         *     { x: 1 }
-         *          ^
-         * 
- */ - public final Node value; - - public AssocNode(int startOffset, int length, Node key, Node value) { - super(startOffset, length); - this.key = key; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.key.accept(visitor); - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.key, this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitAssocNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("key: "); - builder.append(this.key.toString(nextIndent)); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a splat in a hash literal.
-     *
-     *     { **foo }
-     *       ^^^^^
-     * 
- */ - public static final class AssocSplatNode extends Node { - /** - *
-         * The value to be splatted, if present. Will be missing when keyword rest argument forwarding is used.
-         *
-         *     { **foo }
-         *         ^^^
-         * 
- */ - @Nullable - public final Node value; - - public AssocSplatNode(int startOffset, int length, Node value) { - super(startOffset, length); - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.value != null) { - this.value.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitAssocSplatNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value == null ? "null\n" : this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents reading a reference to a field in the previous match.
-     *
-     *     $'
-     *     ^^
-     * 
- */ - public static final class BackReferenceReadNode extends Node { - /** - *
-         * The name of the back-reference variable, including the leading `$`.
-         *
-         *     $& # name `:$&`
-         *
-         *     $+ # name `:$+`
-         * 
- */ - public final byte[] name; - - public BackReferenceReadNode(int startOffset, int length, byte[] name) { - super(startOffset, length); - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitBackReferenceReadNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents a begin statement.
-     *
-     *     begin
-     *       foo
-     *     end
-     *     ^^^^^
-     * 
- */ - public static final class BeginNode extends Node { - /** - *
-         * Represents the statements within the begin block.
-         *
-         *     begin x end
-         *           ^
-         * 
- */ - @Nullable - public final StatementsNode statements; - /** - *
-         * Represents the rescue clause within the begin block.
-         *
-         *     begin x; rescue y; end
-         *              ^^^^^^^^
-         * 
- */ - @Nullable - public final RescueNode rescue_clause; - /** - *
-         * Represents the else clause within the begin block.
-         *
-         *     begin x; rescue y; else z; end
-         *                        ^^^^^^^^^^^
-         * 
- */ - @Nullable - public final ElseNode else_clause; - /** - *
-         * Represents the ensure clause within the begin block.
-         *
-         *     begin x; ensure y; end
-         *              ^^^^^^^^
-         * 
- */ - @Nullable - public final EnsureNode ensure_clause; - - public BeginNode(int startOffset, int length, StatementsNode statements, RescueNode rescue_clause, ElseNode else_clause, EnsureNode ensure_clause) { - super(startOffset, length); - this.statements = statements; - this.rescue_clause = rescue_clause; - this.else_clause = else_clause; - this.ensure_clause = ensure_clause; - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - // Never mark BeginNode with a newline flag, mark children instead - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.statements != null) { - this.statements.accept(visitor); - } - if (this.rescue_clause != null) { - this.rescue_clause.accept(visitor); - } - if (this.else_clause != null) { - this.else_clause.accept(visitor); - } - if (this.ensure_clause != null) { - this.ensure_clause.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.statements, this.rescue_clause, this.else_clause, this.ensure_clause }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitBeginNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - builder.append(nextIndent); - builder.append("rescue_clause: "); - builder.append(this.rescue_clause == null ? "null\n" : this.rescue_clause.toString(nextIndent)); - builder.append(nextIndent); - builder.append("else_clause: "); - builder.append(this.else_clause == null ? "null\n" : this.else_clause.toString(nextIndent)); - builder.append(nextIndent); - builder.append("ensure_clause: "); - builder.append(this.ensure_clause == null ? "null\n" : this.ensure_clause.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a block argument using `&`.
-     *
-     *     bar(&args)
-     *         ^^^^^
-     * 
- */ - public static final class BlockArgumentNode extends Node { - /** - *
-         * The expression that is being passed as a block argument. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     foo(&args)
-         *          ^^^^
-         * 
- */ - @Nullable - public final Node expression; - - public BlockArgumentNode(int startOffset, int length, Node expression) { - super(startOffset, length); - this.expression = expression; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.expression != null) { - this.expression.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.expression }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitBlockArgumentNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("expression: "); - builder.append(this.expression == null ? "null\n" : this.expression.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a block local variable.
-     *
-     *     a { |; b| }
-     *            ^
-     * 
- */ - public static final class BlockLocalVariableNode extends Node { - public final short flags; - /** - *
-         * The name of the block local variable.
-         *
-         *     a { |; b| } # name `:b`
-         *            ^
-         * 
- */ - public final byte[] name; - - public BlockLocalVariableNode(int startOffset, int length, short flags, byte[] name) { - super(startOffset, length); - this.flags = flags; - this.name = name; - } - - public boolean isRepeatedParameter() { - return ParameterFlags.isRepeatedParameter(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitBlockLocalVariableNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("ParameterFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents a block of ruby code.
-     *
-     *     [1, 2, 3].each { |i| puts x }
-     *                    ^^^^^^^^^^^^^^
-     * 
- */ - public static final class BlockNode extends Node { - /** - *
-         * The local variables declared in the block.
-         *
-         *     [1, 2, 3].each { |i| puts x } # locals: [:i]
-         *                       ^
-         * 
- */ - public final byte[][] locals; - /** - *
-         * The parameters of the block.
-         *
-         *     [1, 2, 3].each { |i| puts x }
-         *                      ^^^
-         *     [1, 2, 3].each { puts _1 }
-         *                    ^^^^^^^^^^^
-         *     [1, 2, 3].each { puts it }
-         *                    ^^^^^^^^^^^
-         * 
- */ - @Nullable - @UnionType({ BlockParametersNode.class, NumberedParametersNode.class, ItParametersNode.class }) - public final Node parameters; - /** - *
-         * The body of the block.
-         *
-         *     [1, 2, 3].each { |i| puts x }
-         *                          ^^^^^^
-         * 
- */ - @Nullable - @UnionType({ StatementsNode.class, BeginNode.class }) - public final Node body; - - public BlockNode(int startOffset, int length, byte[][] locals, Node parameters, Node body) { - super(startOffset, length); - this.locals = locals; - this.parameters = parameters; - this.body = body; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.parameters != null) { - this.parameters.accept(visitor); - } - if (this.body != null) { - this.body.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.parameters, this.body }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitBlockNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("locals: "); - builder.append('\n'); - for (byte[] constant : this.locals) { - builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); - } - builder.append(nextIndent); - builder.append("parameters: "); - builder.append(this.parameters == null ? "null\n" : this.parameters.toString(nextIndent)); - builder.append(nextIndent); - builder.append("body: "); - builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a block parameter of a method, block, or lambda definition.
-     *
-     *     def a(&b)
-     *           ^^
-     *     end
-     * 
- */ - public static final class BlockParameterNode extends Node { - public final short flags; - /** - *
-         * The name of the block parameter.
-         *
-         *     def a(&b) # name `:b`
-         *            ^
-         *     end
-         * 
- */ - @Nullable - public final byte[] name; - - public BlockParameterNode(int startOffset, int length, short flags, byte[] name) { - super(startOffset, length); - this.flags = flags; - this.name = name; - } - - public boolean isRepeatedParameter() { - return ParameterFlags.isRepeatedParameter(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitBlockParameterNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("ParameterFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("name: "); - builder.append(this.name == null ? "null" : "\"" + asString(this.name) + "\""); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents a block's parameters declaration.
-     *
-     *     -> (a, b = 1; local) { }
-     *        ^^^^^^^^^^^^^^^^^
-     *
-     *     foo do |a, b = 1; local|
-     *            ^^^^^^^^^^^^^^^^^
-     *     end
-     * 
- */ - public static final class BlockParametersNode extends Node { - /** - *
-         * Represents the parameters of the block.
-         *
-         *     -> (a, b = 1; local) { }
-         *         ^^^^^^^^
-         *
-         *     foo do |a, b = 1; local|
-         *             ^^^^^^^^
-         *     end
-         * 
- */ - @Nullable - public final ParametersNode parameters; - /** - *
-         * Represents the local variables of the block.
-         *
-         *     -> (a, b = 1; local) { }
-         *                   ^^^^^
-         *
-         *     foo do |a, b = 1; local|
-         *                       ^^^^^
-         *     end
-         * 
- */ - public final BlockLocalVariableNode[] locals; - - public BlockParametersNode(int startOffset, int length, ParametersNode parameters, BlockLocalVariableNode[] locals) { - super(startOffset, length); - this.parameters = parameters; - this.locals = locals; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.parameters != null) { - this.parameters.accept(visitor); - } - for (Nodes.Node child : this.locals) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.add(this.parameters); - childNodes.addAll(Arrays.asList(this.locals)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitBlockParametersNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("parameters: "); - builder.append(this.parameters == null ? "null\n" : this.parameters.toString(nextIndent)); - builder.append(nextIndent); - builder.append("locals: "); - builder.append('\n'); - for (Node child : this.locals) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `break` keyword.
-     *
-     *     break foo
-     *     ^^^^^^^^^
-     * 
- */ - public static final class BreakNode extends Node { - /** - *
-         * The arguments to the break statement, if present. These can be any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     break foo
-         *           ^^^
-         * 
- */ - @Nullable - public final ArgumentsNode arguments; - - public BreakNode(int startOffset, int length, ArgumentsNode arguments) { - super(startOffset, length); - this.arguments = arguments; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.arguments != null) { - this.arguments.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.arguments }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitBreakNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("arguments: "); - builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `&&=` operator on a call.
-     *
-     *     foo.bar &&= value
-     *     ^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class CallAndWriteNode extends Node { - public final short flags; - /** - *
-         * The object that the method is being called on. This can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     foo.bar &&= value
-         *     ^^^
-         * 
- */ - @Nullable - public final Node receiver; - /** - *
-         * Represents the name of the method being called.
-         *
-         *     foo.bar &&= value # read_name `:bar`
-         *         ^^^
-         * 
- */ - public final byte[] read_name; - /** - *
-         * Represents the name of the method being written to.
-         *
-         *     foo.bar &&= value # write_name `:bar=`
-         *         ^^^
-         * 
- */ - public final byte[] write_name; - /** - *
-         * Represents the value being assigned.
-         *
-         *     foo.bar &&= value
-         *                 ^^^^^
-         * 
- */ - public final Node value; - - public CallAndWriteNode(int startOffset, int length, short flags, Node receiver, byte[] read_name, byte[] write_name, Node value) { - super(startOffset, length); - this.flags = flags; - this.receiver = receiver; - this.read_name = read_name; - this.write_name = write_name; - this.value = value; - } - - public boolean isSafeNavigation() { - return CallNodeFlags.isSafeNavigation(flags); - } - - public boolean isVariableCall() { - return CallNodeFlags.isVariableCall(flags); - } - - public boolean isAttributeWrite() { - return CallNodeFlags.isAttributeWrite(flags); - } - - public boolean isIgnoreVisibility() { - return CallNodeFlags.isIgnoreVisibility(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.receiver != null) { - this.receiver.accept(visitor); - } - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.receiver, this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitCallAndWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("CallNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("receiver: "); - builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); - builder.append(nextIndent); - builder.append("read_name: "); - builder.append('"').append(asString(this.read_name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("write_name: "); - builder.append('"').append(asString(this.write_name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a method call, in all of the various forms that can take.
-     *
-     *     foo
-     *     ^^^
-     *
-     *     foo()
-     *     ^^^^^
-     *
-     *     +foo
-     *     ^^^^
-     *
-     *     foo + bar
-     *     ^^^^^^^^^
-     *
-     *     foo.bar
-     *     ^^^^^^^
-     *
-     *     foo&.bar
-     *     ^^^^^^^^
-     * 
- */ - public static final class CallNode extends Node { - public final short flags; - /** - *
-         * The object that the method is being called on. This can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     foo.bar
-         *     ^^^
-         *
-         *     +foo
-         *      ^^^
-         *
-         *     foo + bar
-         *     ^^^
-         * 
- */ - @Nullable - public final Node receiver; - /** - *
-         * Represents the name of the method being called.
-         *
-         *     foo.bar # name `:foo`
-         *     ^^^
-         * 
- */ - public final byte[] name; - /** - *
-         * Represents the arguments to the method call. These can be any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     foo(bar)
-         *         ^^^
-         * 
- */ - @Nullable - public final ArgumentsNode arguments; - /** - *
-         * Represents the block that is being passed to the method.
-         *
-         *     foo { |a| a }
-         *         ^^^^^^^^^
-         * 
- */ - @Nullable - @UnionType({ BlockNode.class, BlockArgumentNode.class }) - public final Node block; - - public CallNode(int startOffset, int length, short flags, Node receiver, byte[] name, ArgumentsNode arguments, Node block) { - super(startOffset, length); - this.flags = flags; - this.receiver = receiver; - this.name = name; - this.arguments = arguments; - this.block = block; - } - - public boolean isSafeNavigation() { - return CallNodeFlags.isSafeNavigation(flags); - } - - public boolean isVariableCall() { - return CallNodeFlags.isVariableCall(flags); - } - - public boolean isAttributeWrite() { - return CallNodeFlags.isAttributeWrite(flags); - } - - public boolean isIgnoreVisibility() { - return CallNodeFlags.isIgnoreVisibility(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.receiver != null) { - this.receiver.accept(visitor); - } - if (this.arguments != null) { - this.arguments.accept(visitor); - } - if (this.block != null) { - this.block.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.receiver, this.arguments, this.block }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitCallNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("CallNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("receiver: "); - builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("arguments: "); - builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); - builder.append(nextIndent); - builder.append("block: "); - builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of an assignment operator on a call.
-     *
-     *     foo.bar += baz
-     *     ^^^^^^^^^^^^^^
-     * 
- */ - public static final class CallOperatorWriteNode extends Node { - public final short flags; - /** - *
-         * The object that the method is being called on. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     foo.bar += value
-         *     ^^^
-         * 
- */ - @Nullable - public final Node receiver; - /** - *
-         * Represents the name of the method being called.
-         *
-         *     foo.bar += value # read_name `:bar`
-         *         ^^^
-         * 
- */ - public final byte[] read_name; - /** - *
-         * Represents the name of the method being written to.
-         *
-         *     foo.bar += value # write_name `:bar=`
-         *         ^^^
-         * 
- */ - public final byte[] write_name; - /** - *
-         * Represents the binary operator being used.
-         *
-         *     foo.bar += value # binary_operator `:+`
-         *             ^
-         * 
- */ - public final byte[] binary_operator; - /** - *
-         * Represents the value being assigned.
-         *
-         *     foo.bar += value
-         *                ^^^^^
-         * 
- */ - public final Node value; - - public CallOperatorWriteNode(int startOffset, int length, short flags, Node receiver, byte[] read_name, byte[] write_name, byte[] binary_operator, Node value) { - super(startOffset, length); - this.flags = flags; - this.receiver = receiver; - this.read_name = read_name; - this.write_name = write_name; - this.binary_operator = binary_operator; - this.value = value; - } - - public boolean isSafeNavigation() { - return CallNodeFlags.isSafeNavigation(flags); - } - - public boolean isVariableCall() { - return CallNodeFlags.isVariableCall(flags); - } - - public boolean isAttributeWrite() { - return CallNodeFlags.isAttributeWrite(flags); - } - - public boolean isIgnoreVisibility() { - return CallNodeFlags.isIgnoreVisibility(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.receiver != null) { - this.receiver.accept(visitor); - } - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.receiver, this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitCallOperatorWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("CallNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("receiver: "); - builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); - builder.append(nextIndent); - builder.append("read_name: "); - builder.append('"').append(asString(this.read_name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("write_name: "); - builder.append('"').append(asString(this.write_name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("binary_operator: "); - builder.append('"').append(asString(this.binary_operator)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `||=` operator on a call.
-     *
-     *     foo.bar ||= value
-     *     ^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class CallOrWriteNode extends Node { - public final short flags; - /** - *
-         * The object that the method is being called on. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     foo.bar ||= value
-         *     ^^^
-         * 
- */ - @Nullable - public final Node receiver; - /** - *
-         * Represents the name of the method being called.
-         *
-         *     foo.bar ||= value # read_name `:bar`
-         *         ^^^
-         * 
- */ - public final byte[] read_name; - /** - *
-         * Represents the name of the method being written to.
-         *
-         *     foo.bar ||= value # write_name `:bar=`
-         *         ^^^
-         * 
- */ - public final byte[] write_name; - /** - *
-         * Represents the value being assigned.
-         *
-         *     foo.bar ||= value
-         *                 ^^^^^
-         * 
- */ - public final Node value; - - public CallOrWriteNode(int startOffset, int length, short flags, Node receiver, byte[] read_name, byte[] write_name, Node value) { - super(startOffset, length); - this.flags = flags; - this.receiver = receiver; - this.read_name = read_name; - this.write_name = write_name; - this.value = value; - } - - public boolean isSafeNavigation() { - return CallNodeFlags.isSafeNavigation(flags); - } - - public boolean isVariableCall() { - return CallNodeFlags.isVariableCall(flags); - } - - public boolean isAttributeWrite() { - return CallNodeFlags.isAttributeWrite(flags); - } - - public boolean isIgnoreVisibility() { - return CallNodeFlags.isIgnoreVisibility(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.receiver != null) { - this.receiver.accept(visitor); - } - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.receiver, this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitCallOrWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("CallNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("receiver: "); - builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); - builder.append(nextIndent); - builder.append("read_name: "); - builder.append('"').append(asString(this.read_name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("write_name: "); - builder.append('"').append(asString(this.write_name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents assigning to a method call.
-     *
-     *     foo.bar, = 1
-     *     ^^^^^^^
-     *
-     *     begin
-     *     rescue => foo.bar
-     *               ^^^^^^^
-     *     end
-     *
-     *     for foo.bar in baz do end
-     *         ^^^^^^^
-     * 
- */ - public static final class CallTargetNode extends Node { - public final short flags; - /** - *
-         * The object that the method is being called on. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     foo.bar = 1
-         *     ^^^
-         * 
- */ - public final Node receiver; - /** - *
-         * Represents the name of the method being called.
-         *
-         *     foo.bar = 1 # name `:foo`
-         *     ^^^
-         * 
- */ - public final byte[] name; - - public CallTargetNode(int startOffset, int length, short flags, Node receiver, byte[] name) { - super(startOffset, length); - this.flags = flags; - this.receiver = receiver; - this.name = name; - } - - public boolean isSafeNavigation() { - return CallNodeFlags.isSafeNavigation(flags); - } - - public boolean isVariableCall() { - return CallNodeFlags.isVariableCall(flags); - } - - public boolean isAttributeWrite() { - return CallNodeFlags.isAttributeWrite(flags); - } - - public boolean isIgnoreVisibility() { - return CallNodeFlags.isIgnoreVisibility(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.receiver.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.receiver }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitCallTargetNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("CallNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("receiver: "); - builder.append(this.receiver.toString(nextIndent)); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents assigning to a local variable in pattern matching.
-     *
-     *     foo => [bar => baz]
-     *             ^^^^^^^^^^
-     * 
- */ - public static final class CapturePatternNode extends Node { - /** - *
-         * Represents the value to capture.
-         *
-         *     foo => bar
-         *            ^^^
-         * 
- */ - public final Node value; - /** - *
-         * Represents the target of the capture.
-         *
-         *     foo => bar
-         *     ^^^
-         * 
- */ - public final LocalVariableTargetNode target; - - public CapturePatternNode(int startOffset, int length, Node value, LocalVariableTargetNode target) { - super(startOffset, length); - this.value = value; - this.target = target; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - this.target.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value, this.target }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitCapturePatternNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - builder.append(nextIndent); - builder.append("target: "); - builder.append(this.target.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of a case statement for pattern matching.
-     *
-     *     case true
-     *     in false
-     *     end
-     *     ^^^^^^^^^
-     * 
- */ - public static final class CaseMatchNode extends Node { - /** - *
-         * Represents the predicate of the case match. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     case true; in false; end
-         *          ^^^^
-         * 
- */ - @Nullable - public final Node predicate; - /** - *
-         * Represents the conditions of the case match.
-         *
-         *     case true; in false; end
-         *                ^^^^^^^^
-         * 
- */ - public final InNode[] conditions; - /** - *
-         * Represents the else clause of the case match.
-         *
-         *     case true; in false; else; end
-         *                          ^^^^^^^^^
-         * 
- */ - @Nullable - public final ElseNode else_clause; - - public CaseMatchNode(int startOffset, int length, Node predicate, InNode[] conditions, ElseNode else_clause) { - super(startOffset, length); - this.predicate = predicate; - this.conditions = conditions; - this.else_clause = else_clause; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.predicate != null) { - this.predicate.accept(visitor); - } - for (Nodes.Node child : this.conditions) { - child.accept(visitor); - } - if (this.else_clause != null) { - this.else_clause.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.add(this.predicate); - childNodes.addAll(Arrays.asList(this.conditions)); - childNodes.add(this.else_clause); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitCaseMatchNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("predicate: "); - builder.append(this.predicate == null ? "null\n" : this.predicate.toString(nextIndent)); - builder.append(nextIndent); - builder.append("conditions: "); - builder.append('\n'); - for (Node child : this.conditions) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("else_clause: "); - builder.append(this.else_clause == null ? "null\n" : this.else_clause.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of a case statement.
-     *
-     *     case true
-     *     when false
-     *     end
-     *     ^^^^^^^^^^
-     * 
- */ - public static final class CaseNode extends Node { - /** - *
-         * Represents the predicate of the case statement. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     case true; when false; end
-         *          ^^^^
-         * 
- */ - @Nullable - public final Node predicate; - /** - *
-         * Represents the conditions of the case statement.
-         *
-         *     case true; when false; end
-         *                ^^^^^^^^^^
-         * 
- */ - public final WhenNode[] conditions; - /** - *
-         * Represents the else clause of the case statement.
-         *
-         *     case true; when false; else; end
-         *                            ^^^^^^^^^
-         * 
- */ - @Nullable - public final ElseNode else_clause; - - public CaseNode(int startOffset, int length, Node predicate, WhenNode[] conditions, ElseNode else_clause) { - super(startOffset, length); - this.predicate = predicate; - this.conditions = conditions; - this.else_clause = else_clause; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.predicate != null) { - this.predicate.accept(visitor); - } - for (Nodes.Node child : this.conditions) { - child.accept(visitor); - } - if (this.else_clause != null) { - this.else_clause.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.add(this.predicate); - childNodes.addAll(Arrays.asList(this.conditions)); - childNodes.add(this.else_clause); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitCaseNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("predicate: "); - builder.append(this.predicate == null ? "null\n" : this.predicate.toString(nextIndent)); - builder.append(nextIndent); - builder.append("conditions: "); - builder.append('\n'); - for (Node child : this.conditions) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("else_clause: "); - builder.append(this.else_clause == null ? "null\n" : this.else_clause.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a class declaration involving the `class` keyword.
-     *
-     *     class Foo end
-     *     ^^^^^^^^^^^^^
-     * 
- */ - public static final class ClassNode extends Node { - public final byte[][] locals; - @UnionType({ ConstantReadNode.class, ConstantPathNode.class }) - public final Node constant_path; - /** - *
-         * Represents the superclass of the class.
-         *
-         *     class Foo < Bar
-         *                 ^^^
-         * 
- */ - @Nullable - public final Node superclass; - /** - *
-         * Represents the body of the class.
-         *
-         *     class Foo; bar; end
-         *                ^^^
-         * 
- */ - @Nullable - @UnionType({ StatementsNode.class, BeginNode.class }) - public final Node body; - /** - *
-         * The name of the class.
-         *
-         *     class Foo end # name `:Foo`
-         * 
- */ - public final byte[] name; - - public ClassNode(int startOffset, int length, byte[][] locals, Node constant_path, Node superclass, Node body, byte[] name) { - super(startOffset, length); - this.locals = locals; - this.constant_path = constant_path; - this.superclass = superclass; - this.body = body; - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.constant_path.accept(visitor); - if (this.superclass != null) { - this.superclass.accept(visitor); - } - if (this.body != null) { - this.body.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.constant_path, this.superclass, this.body }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitClassNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("locals: "); - builder.append('\n'); - for (byte[] constant : this.locals) { - builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); - } - builder.append(nextIndent); - builder.append("constant_path: "); - builder.append(this.constant_path.toString(nextIndent)); - builder.append(nextIndent); - builder.append("superclass: "); - builder.append(this.superclass == null ? "null\n" : this.superclass.toString(nextIndent)); - builder.append(nextIndent); - builder.append("body: "); - builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `&&=` operator for assignment to a class variable.
-     *
-     *     @@target &&= value
-     *     ^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class ClassVariableAndWriteNode extends Node { - /** - *
-         * The name of the class variable, which is a `@@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
-         *
-         *     @@target &&= value # name `:@@target`
-         *     ^^^^^^^^
-         * 
- */ - public final byte[] name; - /** - *
-         * Represents the value being assigned. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     @@target &&= value
-         *                  ^^^^^
-         * 
- */ - public final Node value; - - public ClassVariableAndWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitClassVariableAndWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents assigning to a class variable using an operator that isn't `=`.
-     *
-     *     @@target += value
-     *     ^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class ClassVariableOperatorWriteNode extends Node { - public final byte[] name; - public final Node value; - public final byte[] binary_operator; - - public ClassVariableOperatorWriteNode(int startOffset, int length, byte[] name, Node value, byte[] binary_operator) { - super(startOffset, length); - this.name = name; - this.value = value; - this.binary_operator = binary_operator; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitClassVariableOperatorWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - builder.append(nextIndent); - builder.append("binary_operator: "); - builder.append('"').append(asString(this.binary_operator)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `||=` operator for assignment to a class variable.
-     *
-     *     @@target ||= value
-     *     ^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class ClassVariableOrWriteNode extends Node { - public final byte[] name; - public final Node value; - - public ClassVariableOrWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitClassVariableOrWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents referencing a class variable.
-     *
-     *     @@foo
-     *     ^^^^^
-     * 
- */ - public static final class ClassVariableReadNode extends Node { - /** - *
-         * The name of the class variable, which is a `@@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
-         *
-         *     @@abc   # name `:@@abc`
-         *
-         *     @@_test # name `:@@_test`
-         * 
- */ - public final byte[] name; - - public ClassVariableReadNode(int startOffset, int length, byte[] name) { - super(startOffset, length); - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitClassVariableReadNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to a class variable in a context that doesn't have an explicit value.
-     *
-     *     @@foo, @@bar = baz
-     *     ^^^^^  ^^^^^
-     * 
- */ - public static final class ClassVariableTargetNode extends Node { - public final byte[] name; - - public ClassVariableTargetNode(int startOffset, int length, byte[] name) { - super(startOffset, length); - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitClassVariableTargetNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to a class variable.
-     *
-     *     @@foo = 1
-     *     ^^^^^^^^^
-     * 
- */ - public static final class ClassVariableWriteNode extends Node { - /** - *
-         * The name of the class variable, which is a `@@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
-         *
-         *     @@abc = 123     # name `@@abc`
-         *
-         *     @@_test = :test # name `@@_test`
-         * 
- */ - public final byte[] name; - /** - *
-         * The value to write to the class variable. This can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     @@foo = :bar
-         *             ^^^^
-         *
-         *     @@_xyz = 123
-         *              ^^^
-         * 
- */ - public final Node value; - - public ClassVariableWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitClassVariableWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `&&=` operator for assignment to a constant.
-     *
-     *     Target &&= value
-     *     ^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class ConstantAndWriteNode extends Node { - public final byte[] name; - public final Node value; - - public ConstantAndWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantAndWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents assigning to a constant using an operator that isn't `=`.
-     *
-     *     Target += value
-     *     ^^^^^^^^^^^^^^^
-     * 
- */ - public static final class ConstantOperatorWriteNode extends Node { - public final byte[] name; - public final Node value; - public final byte[] binary_operator; - - public ConstantOperatorWriteNode(int startOffset, int length, byte[] name, Node value, byte[] binary_operator) { - super(startOffset, length); - this.name = name; - this.value = value; - this.binary_operator = binary_operator; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantOperatorWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - builder.append(nextIndent); - builder.append("binary_operator: "); - builder.append('"').append(asString(this.binary_operator)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `||=` operator for assignment to a constant.
-     *
-     *     Target ||= value
-     *     ^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class ConstantOrWriteNode extends Node { - public final byte[] name; - public final Node value; - - public ConstantOrWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantOrWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `&&=` operator for assignment to a constant path.
-     *
-     *     Parent::Child &&= value
-     *     ^^^^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class ConstantPathAndWriteNode extends Node { - public final ConstantPathNode target; - public final Node value; - - public ConstantPathAndWriteNode(int startOffset, int length, ConstantPathNode target, Node value) { - super(startOffset, length); - this.target = target; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.target.accept(visitor); - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.target, this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantPathAndWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("target: "); - builder.append(this.target.toString(nextIndent)); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents accessing a constant through a path of `::` operators.
-     *
-     *     Foo::Bar
-     *     ^^^^^^^^
-     * 
- */ - public static final class ConstantPathNode extends Node { - /** - *
-         * The left-hand node of the path, if present. It can be `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression). It will be `nil` when the constant lookup is at the root of the module tree.
-         *
-         *     Foo::Bar
-         *     ^^^
-         *
-         *     self::Test
-         *     ^^^^
-         *
-         *     a.b::C
-         *     ^^^
-         * 
- */ - @Nullable - public final Node parent; - /** - *
-         * The name of the constant being accessed. This could be `nil` in the event of a syntax error.
-         * 
- */ - @Nullable - public final byte[] name; - - public ConstantPathNode(int startOffset, int length, Node parent, byte[] name) { - super(startOffset, length); - this.parent = parent; - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.parent != null) { - this.parent.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.parent }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantPathNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("parent: "); - builder.append(this.parent == null ? "null\n" : this.parent.toString(nextIndent)); - builder.append(nextIndent); - builder.append("name: "); - builder.append(this.name == null ? "null" : "\"" + asString(this.name) + "\""); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents assigning to a constant path using an operator that isn't `=`.
-     *
-     *     Parent::Child += value
-     *     ^^^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class ConstantPathOperatorWriteNode extends Node { - public final ConstantPathNode target; - public final Node value; - public final byte[] binary_operator; - - public ConstantPathOperatorWriteNode(int startOffset, int length, ConstantPathNode target, Node value, byte[] binary_operator) { - super(startOffset, length); - this.target = target; - this.value = value; - this.binary_operator = binary_operator; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.target.accept(visitor); - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.target, this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantPathOperatorWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("target: "); - builder.append(this.target.toString(nextIndent)); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - builder.append(nextIndent); - builder.append("binary_operator: "); - builder.append('"').append(asString(this.binary_operator)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `||=` operator for assignment to a constant path.
-     *
-     *     Parent::Child ||= value
-     *     ^^^^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class ConstantPathOrWriteNode extends Node { - public final ConstantPathNode target; - public final Node value; - - public ConstantPathOrWriteNode(int startOffset, int length, ConstantPathNode target, Node value) { - super(startOffset, length); - this.target = target; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.target.accept(visitor); - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.target, this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantPathOrWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("target: "); - builder.append(this.target.toString(nextIndent)); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to a constant path in a context that doesn't have an explicit value.
-     *
-     *     Foo::Foo, Bar::Bar = baz
-     *     ^^^^^^^^  ^^^^^^^^
-     * 
- */ - public static final class ConstantPathTargetNode extends Node { - @Nullable - public final Node parent; - @Nullable - public final byte[] name; - - public ConstantPathTargetNode(int startOffset, int length, Node parent, byte[] name) { - super(startOffset, length); - this.parent = parent; - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.parent != null) { - this.parent.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.parent }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantPathTargetNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("parent: "); - builder.append(this.parent == null ? "null\n" : this.parent.toString(nextIndent)); - builder.append(nextIndent); - builder.append("name: "); - builder.append(this.name == null ? "null" : "\"" + asString(this.name) + "\""); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to a constant path.
-     *
-     *     ::Foo = 1
-     *     ^^^^^^^^^
-     *
-     *     Foo::Bar = 1
-     *     ^^^^^^^^^^^^
-     *
-     *     ::Foo::Bar = 1
-     *     ^^^^^^^^^^^^^^
-     * 
- */ - public static final class ConstantPathWriteNode extends Node { - /** - *
-         * A node representing the constant path being written to.
-         *
-         *     Foo::Bar = 1
-         *     ^^^^^^^^
-         *
-         *     ::Foo = :abc
-         *     ^^^^^
-         * 
- */ - public final ConstantPathNode target; - /** - *
-         * The value to write to the constant path. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     FOO::BAR = :abc
-         *                ^^^^
-         * 
- */ - public final Node value; - - public ConstantPathWriteNode(int startOffset, int length, ConstantPathNode target, Node value) { - super(startOffset, length); - this.target = target; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.target.accept(visitor); - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.target, this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantPathWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("target: "); - builder.append(this.target.toString(nextIndent)); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents referencing a constant.
-     *
-     *     Foo
-     *     ^^^
-     * 
- */ - public static final class ConstantReadNode extends Node { - /** - *
-         * The name of the [constant](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
-         *
-         *     X              # name `:X`
-         *
-         *     SOME_CONSTANT  # name `:SOME_CONSTANT`
-         * 
- */ - public final byte[] name; - - public ConstantReadNode(int startOffset, int length, byte[] name) { - super(startOffset, length); - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantReadNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to a constant in a context that doesn't have an explicit value.
-     *
-     *     Foo, Bar = baz
-     *     ^^^  ^^^
-     * 
- */ - public static final class ConstantTargetNode extends Node { - public final byte[] name; - - public ConstantTargetNode(int startOffset, int length, byte[] name) { - super(startOffset, length); - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantTargetNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to a constant.
-     *
-     *     Foo = 1
-     *     ^^^^^^^
-     * 
- */ - public static final class ConstantWriteNode extends Node { - /** - *
-         * The name of the [constant](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#constants).
-         *
-         *     Foo = :bar # name `:Foo`
-         *
-         *     XYZ = 1    # name `:XYZ`
-         * 
- */ - public final byte[] name; - /** - *
-         * The value to write to the constant. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     FOO = :bar
-         *           ^^^^
-         *
-         *     MyClass = Class.new
-         *               ^^^^^^^^^
-         * 
- */ - public final Node value; - - public ConstantWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitConstantWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a method definition.
-     *
-     *     def method
-     *     end
-     *     ^^^^^^^^^^
-     * 
- */ - public static final class DefNode extends Node { - public final int serializedLength; - public final Loader loader; - public final byte[] name; - @Nullable - public final Node receiver; - @Nullable - public final ParametersNode parameters; - @Nullable - @UnionType({ StatementsNode.class, BeginNode.class }) - public final Node body; - public final byte[][] locals; - - public DefNode(int startOffset, int length, int serializedLength, Loader loader, byte[] name, Node receiver, ParametersNode parameters, Node body, byte[][] locals) { - super(startOffset, length); - this.serializedLength = serializedLength; - this.loader = loader; - this.name = name; - this.receiver = receiver; - this.parameters = parameters; - this.body = body; - this.locals = locals; - } - - public boolean isLazy() { - return serializedLength < 0; - } - - public DefNode getNonLazy() { - if (isLazy()) { - return loader.createDefNodeFromSavedPosition(startOffset, length, -serializedLength); - } else { - return this; - } - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.receiver != null) { - this.receiver.accept(visitor); - } - if (this.parameters != null) { - this.parameters.accept(visitor); - } - if (this.body != null) { - this.body.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.receiver, this.parameters, this.body }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitDefNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("receiver: "); - builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); - builder.append(nextIndent); - builder.append("parameters: "); - builder.append(this.parameters == null ? "null\n" : this.parameters.toString(nextIndent)); - builder.append(nextIndent); - builder.append("body: "); - builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); - builder.append(nextIndent); - builder.append("locals: "); - builder.append('\n'); - for (byte[] constant : this.locals) { - builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); - } - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `defined?` keyword.
-     *
-     *     defined?(a)
-     *     ^^^^^^^^^^^
-     * 
- */ - public static final class DefinedNode extends Node { - public final Node value; - - public DefinedNode(int startOffset, int length, Node value) { - super(startOffset, length); - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitDefinedNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents an `else` clause in a `case`, `if`, or `unless` statement.
-     *
-     *     if a then b else c end
-     *                 ^^^^^^^^^^
-     * 
- */ - public static final class ElseNode extends Node { - @Nullable - public final StatementsNode statements; - - public ElseNode(int startOffset, int length, StatementsNode statements) { - super(startOffset, length); - this.statements = statements; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.statements != null) { - this.statements.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.statements }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitElseNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents an interpolated set of statements.
-     *
-     *     "foo #{bar}"
-     *          ^^^^^^
-     * 
- */ - public static final class EmbeddedStatementsNode extends Node { - @Nullable - public final StatementsNode statements; - - public EmbeddedStatementsNode(int startOffset, int length, StatementsNode statements) { - super(startOffset, length); - this.statements = statements; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.statements != null) { - this.statements.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.statements }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitEmbeddedStatementsNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents an interpolated variable.
-     *
-     *     "foo #@bar"
-     *          ^^^^^
-     * 
- */ - public static final class EmbeddedVariableNode extends Node { - @UnionType({ InstanceVariableReadNode.class, ClassVariableReadNode.class, GlobalVariableReadNode.class, BackReferenceReadNode.class, NumberedReferenceReadNode.class }) - public final Node variable; - - public EmbeddedVariableNode(int startOffset, int length, Node variable) { - super(startOffset, length); - this.variable = variable; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.variable.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.variable }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitEmbeddedVariableNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("variable: "); - builder.append(this.variable.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents an `ensure` clause in a `begin` statement.
-     *
-     *     begin
-     *       foo
-     *     ensure
-     *     ^^^^^^
-     *       bar
-     *     end
-     * 
- */ - public static final class EnsureNode extends Node { - @Nullable - public final StatementsNode statements; - - public EnsureNode(int startOffset, int length, StatementsNode statements) { - super(startOffset, length); - this.statements = statements; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.statements != null) { - this.statements.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.statements }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitEnsureNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the literal `false` keyword.
-     *
-     *     false
-     *     ^^^^^
-     * 
- */ - public static final class FalseNode extends Node { - - public FalseNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitFalseNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents a find pattern in pattern matching.
-     *
-     *     foo in *bar, baz, *qux
-     *            ^^^^^^^^^^^^^^^
-     *
-     *     foo in [*bar, baz, *qux]
-     *            ^^^^^^^^^^^^^^^^^
-     *
-     *     foo in Foo(*bar, baz, *qux)
-     *            ^^^^^^^^^^^^^^^^^^^^
-     *
-     *     foo => *bar, baz, *qux
-     *            ^^^^^^^^^^^^^^^
-     * 
- */ - public static final class FindPatternNode extends Node { - /** - *
-         * Represents the optional constant preceding the pattern
-         *
-         *     foo in Foo(*bar, baz, *qux)
-         *            ^^^
-         * 
- */ - @Nullable - @UnionType({ ConstantPathNode.class, ConstantReadNode.class }) - public final Node constant; - /** - *
-         * Represents the first wildcard node in the pattern.
-         *
-         *     foo in *bar, baz, *qux
-         *            ^^^^
-         *
-         *     foo in Foo(*bar, baz, *qux)
-         *                ^^^^
-         * 
- */ - public final SplatNode left; - /** - *
-         * Represents the nodes in between the wildcards.
-         *
-         *     foo in *bar, baz, *qux
-         *                  ^^^
-         *
-         *     foo in Foo(*bar, baz, 1, *qux)
-         *                      ^^^^^^
-         * 
- */ - public final Node[] requireds; - /** - *
-         * Represents the second wildcard node in the pattern.
-         *
-         *     foo in *bar, baz, *qux
-         *                       ^^^^
-         *
-         *     foo in Foo(*bar, baz, *qux)
-         *                           ^^^^
-         * 
- */ - public final SplatNode right; - - public FindPatternNode(int startOffset, int length, Node constant, SplatNode left, Node[] requireds, SplatNode right) { - super(startOffset, length); - this.constant = constant; - this.left = left; - this.requireds = requireds; - this.right = right; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.constant != null) { - this.constant.accept(visitor); - } - this.left.accept(visitor); - for (Nodes.Node child : this.requireds) { - child.accept(visitor); - } - this.right.accept(visitor); - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.add(this.constant); - childNodes.add(this.left); - childNodes.addAll(Arrays.asList(this.requireds)); - childNodes.add(this.right); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitFindPatternNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("constant: "); - builder.append(this.constant == null ? "null\n" : this.constant.toString(nextIndent)); - builder.append(nextIndent); - builder.append("left: "); - builder.append(this.left.toString(nextIndent)); - builder.append(nextIndent); - builder.append("requireds: "); - builder.append('\n'); - for (Node child : this.requireds) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("right: "); - builder.append(this.right.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `..` or `...` operators to create flip flops.
-     *
-     *     baz if foo .. bar
-     *            ^^^^^^^^^^
-     * 
- */ - public static final class FlipFlopNode extends Node { - public final short flags; - @Nullable - public final Node left; - @Nullable - public final Node right; - - public FlipFlopNode(int startOffset, int length, short flags, Node left, Node right) { - super(startOffset, length); - this.flags = flags; - this.left = left; - this.right = right; - } - - public boolean isExcludeEnd() { - return RangeFlags.isExcludeEnd(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.left != null) { - this.left.accept(visitor); - } - if (this.right != null) { - this.right.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.left, this.right }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitFlipFlopNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("RangeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("left: "); - builder.append(this.left == null ? "null\n" : this.left.toString(nextIndent)); - builder.append(nextIndent); - builder.append("right: "); - builder.append(this.right == null ? "null\n" : this.right.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a floating point number literal.
-     *
-     *     1.0
-     *     ^^^
-     * 
- */ - public static final class FloatNode extends Node { - /** - *
-         * The value of the floating point number as a Float.
-         * 
- */ - public final double value; - - public FloatNode(int startOffset, int length, double value) { - super(startOffset, length); - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitFloatNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `for` keyword.
-     *
-     *     for i in a end
-     *     ^^^^^^^^^^^^^^
-     * 
- */ - public static final class ForNode extends Node { - /** - *
-         * The index expression for `for` loops.
-         *
-         *     for i in a end
-         *         ^
-         * 
- */ - @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class, MultiTargetNode.class }) - public final Node index; - /** - *
-         * The collection to iterate over.
-         *
-         *     for i in a end
-         *              ^
-         * 
- */ - public final Node collection; - /** - *
-         * Represents the body of statements to execute for each iteration of the loop.
-         *
-         *     for i in a
-         *       foo(i)
-         *       ^^^^^^
-         *     end
-         * 
- */ - @Nullable - public final StatementsNode statements; - - public ForNode(int startOffset, int length, Node index, Node collection, StatementsNode statements) { - super(startOffset, length); - this.index = index; - this.collection = collection; - this.statements = statements; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.index.accept(visitor); - this.collection.accept(visitor); - if (this.statements != null) { - this.statements.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.index, this.collection, this.statements }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitForNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("index: "); - builder.append(this.index.toString(nextIndent)); - builder.append(nextIndent); - builder.append("collection: "); - builder.append(this.collection.toString(nextIndent)); - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents forwarding all arguments to this method to another method.
-     *
-     *     def foo(...)
-     *       bar(...)
-     *           ^^^
-     *     end
-     * 
- */ - public static final class ForwardingArgumentsNode extends Node { - - public ForwardingArgumentsNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitForwardingArgumentsNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the forwarding parameter in a method, block, or lambda declaration.
-     *
-     *     def foo(...)
-     *             ^^^
-     *     end
-     * 
- */ - public static final class ForwardingParameterNode extends Node { - - public ForwardingParameterNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitForwardingParameterNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `super` keyword without parentheses or arguments, but which might have a block.
-     *
-     *     super
-     *     ^^^^^
-     *
-     *     super { 123 }
-     *     ^^^^^^^^^^^^^
-     *
-     * If it has any other arguments, it would be a `SuperNode` instead.
-     * 
- */ - public static final class ForwardingSuperNode extends Node { - /** - *
-         * All other arguments are forwarded as normal, except the original block is replaced with the new block.
-         * 
- */ - @Nullable - public final BlockNode block; - - public ForwardingSuperNode(int startOffset, int length, BlockNode block) { - super(startOffset, length); - this.block = block; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.block != null) { - this.block.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.block }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitForwardingSuperNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("block: "); - builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `&&=` operator for assignment to a global variable.
-     *
-     *     $target &&= value
-     *     ^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class GlobalVariableAndWriteNode extends Node { - public final byte[] name; - public final Node value; - - public GlobalVariableAndWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitGlobalVariableAndWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents assigning to a global variable using an operator that isn't `=`.
-     *
-     *     $target += value
-     *     ^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class GlobalVariableOperatorWriteNode extends Node { - public final byte[] name; - public final Node value; - public final byte[] binary_operator; - - public GlobalVariableOperatorWriteNode(int startOffset, int length, byte[] name, Node value, byte[] binary_operator) { - super(startOffset, length); - this.name = name; - this.value = value; - this.binary_operator = binary_operator; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitGlobalVariableOperatorWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - builder.append(nextIndent); - builder.append("binary_operator: "); - builder.append('"').append(asString(this.binary_operator)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `||=` operator for assignment to a global variable.
-     *
-     *     $target ||= value
-     *     ^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class GlobalVariableOrWriteNode extends Node { - public final byte[] name; - public final Node value; - - public GlobalVariableOrWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitGlobalVariableOrWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents referencing a global variable.
-     *
-     *     $foo
-     *     ^^^^
-     * 
- */ - public static final class GlobalVariableReadNode extends Node { - /** - *
-         * The name of the global variable, which is a `$` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifier). Alternatively, it can be one of the special global variables designated by a symbol.
-         *
-         *     $foo   # name `:$foo`
-         *
-         *     $_Test # name `:$_Test`
-         * 
- */ - public final byte[] name; - - public GlobalVariableReadNode(int startOffset, int length, byte[] name) { - super(startOffset, length); - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitGlobalVariableReadNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to a global variable in a context that doesn't have an explicit value.
-     *
-     *     $foo, $bar = baz
-     *     ^^^^  ^^^^
-     * 
- */ - public static final class GlobalVariableTargetNode extends Node { - public final byte[] name; - - public GlobalVariableTargetNode(int startOffset, int length, byte[] name) { - super(startOffset, length); - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitGlobalVariableTargetNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to a global variable.
-     *
-     *     $foo = 1
-     *     ^^^^^^^^
-     * 
- */ - public static final class GlobalVariableWriteNode extends Node { - /** - *
-         * The name of the global variable, which is a `$` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifier). Alternatively, it can be one of the special global variables designated by a symbol.
-         *
-         *     $foo = :bar  # name `:$foo`
-         *
-         *     $_Test = 123 # name `:$_Test`
-         * 
- */ - public final byte[] name; - /** - *
-         * The value to write to the global variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     $foo = :bar
-         *            ^^^^
-         *
-         *     $-xyz = 123
-         *             ^^^
-         * 
- */ - public final Node value; - - public GlobalVariableWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitGlobalVariableWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a hash literal.
-     *
-     *     { a => b }
-     *     ^^^^^^^^^^
-     * 
- */ - public static final class HashNode extends Node { - /** - *
-         * The elements of the hash. These can be either `AssocNode`s or `AssocSplatNode`s.
-         *
-         *     { a: b }
-         *       ^^^^
-         *
-         *     { **foo }
-         *       ^^^^^
-         * 
- */ - @UnionType({ AssocNode.class, AssocSplatNode.class }) - public final Node[] elements; - - public HashNode(int startOffset, int length, Node[] elements) { - super(startOffset, length); - this.elements = elements; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.elements) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.elements)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitHashNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("elements: "); - builder.append('\n'); - for (Node child : this.elements) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents a hash pattern in pattern matching.
-     *
-     *     foo => { a: 1, b: 2 }
-     *            ^^^^^^^^^^^^^^
-     *
-     *     foo => { a: 1, b: 2, **c }
-     *            ^^^^^^^^^^^^^^^^^^^
-     *
-     *     foo => Bar[a: 1, b: 2]
-     *            ^^^^^^^^^^^^^^^
-     *
-     *     foo in { a: 1, b: 2 }
-     *            ^^^^^^^^^^^^^^
-     * 
- */ - public static final class HashPatternNode extends Node { - /** - *
-         * Represents the optional constant preceding the Hash.
-         *
-         *     foo => Bar[a: 1, b: 2]
-         *          ^^^
-         *
-         *     foo => Bar::Baz[a: 1, b: 2]
-         *          ^^^^^^^^
-         * 
- */ - @Nullable - @UnionType({ ConstantPathNode.class, ConstantReadNode.class }) - public final Node constant; - /** - *
-         * Represents the explicit named hash keys and values.
-         *
-         *     foo => { a: 1, b:, ** }
-         *              ^^^^^^^^
-         * 
- */ - public final AssocNode[] elements; - /** - *
-         * Represents the rest of the Hash keys and values. This can be named, unnamed, or explicitly forbidden via `**nil`, this last one results in a `NoKeywordsParameterNode`.
-         *
-         *     foo => { a: 1, b:, **c }
-         *                        ^^^
-         *
-         *     foo => { a: 1, b:, ** }
-         *                        ^^
-         *
-         *     foo => { a: 1, b:, **nil }
-         *                        ^^^^^
-         * 
- */ - @Nullable - @UnionType({ AssocSplatNode.class, NoKeywordsParameterNode.class }) - public final Node rest; - - public HashPatternNode(int startOffset, int length, Node constant, AssocNode[] elements, Node rest) { - super(startOffset, length); - this.constant = constant; - this.elements = elements; - this.rest = rest; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.constant != null) { - this.constant.accept(visitor); - } - for (Nodes.Node child : this.elements) { - child.accept(visitor); - } - if (this.rest != null) { - this.rest.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.add(this.constant); - childNodes.addAll(Arrays.asList(this.elements)); - childNodes.add(this.rest); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitHashPatternNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("constant: "); - builder.append(this.constant == null ? "null\n" : this.constant.toString(nextIndent)); - builder.append(nextIndent); - builder.append("elements: "); - builder.append('\n'); - for (Node child : this.elements) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("rest: "); - builder.append(this.rest == null ? "null\n" : this.rest.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `if` keyword, either in the block form or the modifier form, or a ternary expression.
-     *
-     *     bar if foo
-     *     ^^^^^^^^^^
-     *
-     *     if foo then bar end
-     *     ^^^^^^^^^^^^^^^^^^^
-     *
-     *     foo ? bar : baz
-     *     ^^^^^^^^^^^^^^^
-     * 
- */ - public static final class IfNode extends Node { - /** - *
-         * The node for the condition the `IfNode` is testing.
-         *
-         *     if foo
-         *        ^^^
-         *       bar
-         *     end
-         *
-         *     bar if foo
-         *            ^^^
-         *
-         *     foo ? bar : baz
-         *     ^^^
-         * 
- */ - public final Node predicate; - /** - *
-         * Represents the body of statements that will be executed when the predicate is evaluated as truthy. Will be `nil` when no body is provided.
-         *
-         *     if foo
-         *       bar
-         *       ^^^
-         *       baz
-         *       ^^^
-         *     end
-         * 
- */ - @Nullable - public final StatementsNode statements; - /** - *
-         * Represents an `ElseNode` or an `IfNode` when there is an `else` or an `elsif` in the `if` statement.
-         *
-         *     if foo
-         *       bar
-         *     elsif baz
-         *     ^^^^^^^^^
-         *       qux
-         *       ^^^
-         *     end
-         *     ^^^
-         *
-         *     if foo then bar else baz end
-         *                     ^^^^^^^^^^^^
-         * 
- */ - @Nullable - @UnionType({ ElseNode.class, IfNode.class }) - public final Node subsequent; - - public IfNode(int startOffset, int length, Node predicate, StatementsNode statements, Node subsequent) { - super(startOffset, length); - this.predicate = predicate; - this.statements = statements; - this.subsequent = subsequent; - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - this.predicate.setNewLineFlag(source, newlineMarked); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.predicate.accept(visitor); - if (this.statements != null) { - this.statements.accept(visitor); - } - if (this.subsequent != null) { - this.subsequent.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.predicate, this.statements, this.subsequent }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitIfNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("predicate: "); - builder.append(this.predicate.toString(nextIndent)); - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - builder.append(nextIndent); - builder.append("subsequent: "); - builder.append(this.subsequent == null ? "null\n" : this.subsequent.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents an imaginary number literal.
-     *
-     *     1.0i
-     *     ^^^^
-     * 
- */ - public static final class ImaginaryNode extends Node { - @UnionType({ FloatNode.class, IntegerNode.class, RationalNode.class }) - public final Node numeric; - - public ImaginaryNode(int startOffset, int length, Node numeric) { - super(startOffset, length); - this.numeric = numeric; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.numeric.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.numeric }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitImaginaryNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("numeric: "); - builder.append(this.numeric.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a node that is implicitly being added to the tree but doesn't correspond directly to a node in the source.
-     *
-     *     { foo: }
-     *       ^^^^
-     *
-     *     { Foo: }
-     *       ^^^^
-     *
-     *     foo in { bar: }
-     *              ^^^^
-     * 
- */ - public static final class ImplicitNode extends Node { - @UnionType({ LocalVariableReadNode.class, CallNode.class, ConstantReadNode.class, LocalVariableTargetNode.class }) - public final Node value; - - public ImplicitNode(int startOffset, int length, Node value) { - super(startOffset, length); - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitImplicitNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents using a trailing comma to indicate an implicit rest parameter.
-     *
-     *     foo { |bar,| }
-     *               ^
-     *
-     *     foo in [bar,]
-     *                ^
-     *
-     *     for foo, in bar do end
-     *            ^
-     *
-     *     foo, = bar
-     *        ^
-     * 
- */ - public static final class ImplicitRestNode extends Node { - - public ImplicitRestNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitImplicitRestNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `in` keyword in a case statement.
-     *
-     *     case a; in b then c end
-     *             ^^^^^^^^^^^
-     * 
- */ - public static final class InNode extends Node { - public final Node pattern; - @Nullable - public final StatementsNode statements; - - public InNode(int startOffset, int length, Node pattern, StatementsNode statements) { - super(startOffset, length); - this.pattern = pattern; - this.statements = statements; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.pattern.accept(visitor); - if (this.statements != null) { - this.statements.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.pattern, this.statements }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("pattern: "); - builder.append(this.pattern.toString(nextIndent)); - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `&&=` operator on a call to the `[]` method.
-     *
-     *     foo.bar[baz] &&= value
-     *     ^^^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class IndexAndWriteNode extends Node { - public final short flags; - @Nullable - public final Node receiver; - @Nullable - public final ArgumentsNode arguments; - @Nullable - public final BlockArgumentNode block; - public final Node value; - - public IndexAndWriteNode(int startOffset, int length, short flags, Node receiver, ArgumentsNode arguments, BlockArgumentNode block, Node value) { - super(startOffset, length); - this.flags = flags; - this.receiver = receiver; - this.arguments = arguments; - this.block = block; - this.value = value; - } - - public boolean isSafeNavigation() { - return CallNodeFlags.isSafeNavigation(flags); - } - - public boolean isVariableCall() { - return CallNodeFlags.isVariableCall(flags); - } - - public boolean isAttributeWrite() { - return CallNodeFlags.isAttributeWrite(flags); - } - - public boolean isIgnoreVisibility() { - return CallNodeFlags.isIgnoreVisibility(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.receiver != null) { - this.receiver.accept(visitor); - } - if (this.arguments != null) { - this.arguments.accept(visitor); - } - if (this.block != null) { - this.block.accept(visitor); - } - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.receiver, this.arguments, this.block, this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitIndexAndWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("CallNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("receiver: "); - builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); - builder.append(nextIndent); - builder.append("arguments: "); - builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); - builder.append(nextIndent); - builder.append("block: "); - builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of an assignment operator on a call to `[]`.
-     *
-     *     foo.bar[baz] += value
-     *     ^^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class IndexOperatorWriteNode extends Node { - public final short flags; - @Nullable - public final Node receiver; - @Nullable - public final ArgumentsNode arguments; - @Nullable - public final BlockArgumentNode block; - public final byte[] binary_operator; - public final Node value; - - public IndexOperatorWriteNode(int startOffset, int length, short flags, Node receiver, ArgumentsNode arguments, BlockArgumentNode block, byte[] binary_operator, Node value) { - super(startOffset, length); - this.flags = flags; - this.receiver = receiver; - this.arguments = arguments; - this.block = block; - this.binary_operator = binary_operator; - this.value = value; - } - - public boolean isSafeNavigation() { - return CallNodeFlags.isSafeNavigation(flags); - } - - public boolean isVariableCall() { - return CallNodeFlags.isVariableCall(flags); - } - - public boolean isAttributeWrite() { - return CallNodeFlags.isAttributeWrite(flags); - } - - public boolean isIgnoreVisibility() { - return CallNodeFlags.isIgnoreVisibility(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.receiver != null) { - this.receiver.accept(visitor); - } - if (this.arguments != null) { - this.arguments.accept(visitor); - } - if (this.block != null) { - this.block.accept(visitor); - } - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.receiver, this.arguments, this.block, this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitIndexOperatorWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("CallNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("receiver: "); - builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); - builder.append(nextIndent); - builder.append("arguments: "); - builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); - builder.append(nextIndent); - builder.append("block: "); - builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); - builder.append(nextIndent); - builder.append("binary_operator: "); - builder.append('"').append(asString(this.binary_operator)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `||=` operator on a call to `[]`.
-     *
-     *     foo.bar[baz] ||= value
-     *     ^^^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class IndexOrWriteNode extends Node { - public final short flags; - @Nullable - public final Node receiver; - @Nullable - public final ArgumentsNode arguments; - @Nullable - public final BlockArgumentNode block; - public final Node value; - - public IndexOrWriteNode(int startOffset, int length, short flags, Node receiver, ArgumentsNode arguments, BlockArgumentNode block, Node value) { - super(startOffset, length); - this.flags = flags; - this.receiver = receiver; - this.arguments = arguments; - this.block = block; - this.value = value; - } - - public boolean isSafeNavigation() { - return CallNodeFlags.isSafeNavigation(flags); - } - - public boolean isVariableCall() { - return CallNodeFlags.isVariableCall(flags); - } - - public boolean isAttributeWrite() { - return CallNodeFlags.isAttributeWrite(flags); - } - - public boolean isIgnoreVisibility() { - return CallNodeFlags.isIgnoreVisibility(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.receiver != null) { - this.receiver.accept(visitor); - } - if (this.arguments != null) { - this.arguments.accept(visitor); - } - if (this.block != null) { - this.block.accept(visitor); - } - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.receiver, this.arguments, this.block, this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitIndexOrWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("CallNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("receiver: "); - builder.append(this.receiver == null ? "null\n" : this.receiver.toString(nextIndent)); - builder.append(nextIndent); - builder.append("arguments: "); - builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); - builder.append(nextIndent); - builder.append("block: "); - builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents assigning to an index.
-     *
-     *     foo[bar], = 1
-     *     ^^^^^^^^
-     *
-     *     begin
-     *     rescue => foo[bar]
-     *               ^^^^^^^^
-     *     end
-     *
-     *     for foo[bar] in baz do end
-     *         ^^^^^^^^
-     * 
- */ - public static final class IndexTargetNode extends Node { - public final short flags; - public final Node receiver; - @Nullable - public final ArgumentsNode arguments; - @Nullable - public final BlockArgumentNode block; - - public IndexTargetNode(int startOffset, int length, short flags, Node receiver, ArgumentsNode arguments, BlockArgumentNode block) { - super(startOffset, length); - this.flags = flags; - this.receiver = receiver; - this.arguments = arguments; - this.block = block; - } - - public boolean isSafeNavigation() { - return CallNodeFlags.isSafeNavigation(flags); - } - - public boolean isVariableCall() { - return CallNodeFlags.isVariableCall(flags); - } - - public boolean isAttributeWrite() { - return CallNodeFlags.isAttributeWrite(flags); - } - - public boolean isIgnoreVisibility() { - return CallNodeFlags.isIgnoreVisibility(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.receiver.accept(visitor); - if (this.arguments != null) { - this.arguments.accept(visitor); - } - if (this.block != null) { - this.block.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.receiver, this.arguments, this.block }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitIndexTargetNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("CallNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("receiver: "); - builder.append(this.receiver.toString(nextIndent)); - builder.append(nextIndent); - builder.append("arguments: "); - builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); - builder.append(nextIndent); - builder.append("block: "); - builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `&&=` operator for assignment to an instance variable.
-     *
-     *     @target &&= value
-     *     ^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class InstanceVariableAndWriteNode extends Node { - public final byte[] name; - public final Node value; - - public InstanceVariableAndWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInstanceVariableAndWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents assigning to an instance variable using an operator that isn't `=`.
-     *
-     *     @target += value
-     *     ^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class InstanceVariableOperatorWriteNode extends Node { - public final byte[] name; - public final Node value; - public final byte[] binary_operator; - - public InstanceVariableOperatorWriteNode(int startOffset, int length, byte[] name, Node value, byte[] binary_operator) { - super(startOffset, length); - this.name = name; - this.value = value; - this.binary_operator = binary_operator; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInstanceVariableOperatorWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - builder.append(nextIndent); - builder.append("binary_operator: "); - builder.append('"').append(asString(this.binary_operator)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `||=` operator for assignment to an instance variable.
-     *
-     *     @target ||= value
-     *     ^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class InstanceVariableOrWriteNode extends Node { - public final byte[] name; - public final Node value; - - public InstanceVariableOrWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInstanceVariableOrWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents referencing an instance variable.
-     *
-     *     @foo
-     *     ^^^^
-     * 
- */ - public static final class InstanceVariableReadNode extends Node { - /** - *
-         * The name of the instance variable, which is a `@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
-         *
-         *     @x     # name `:@x`
-         *
-         *     @_test # name `:@_test`
-         * 
- */ - public final byte[] name; - - public InstanceVariableReadNode(int startOffset, int length, byte[] name) { - super(startOffset, length); - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInstanceVariableReadNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to an instance variable in a context that doesn't have an explicit value.
-     *
-     *     @foo, @bar = baz
-     *     ^^^^  ^^^^
-     * 
- */ - public static final class InstanceVariableTargetNode extends Node { - public final byte[] name; - - public InstanceVariableTargetNode(int startOffset, int length, byte[] name) { - super(startOffset, length); - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInstanceVariableTargetNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to an instance variable.
-     *
-     *     @foo = 1
-     *     ^^^^^^^^
-     * 
- */ - public static final class InstanceVariableWriteNode extends Node { - /** - *
-         * The name of the instance variable, which is a `@` followed by an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
-         *
-         *     @x = :y       # name `:@x`
-         *
-         *     @_foo = "bar" # name `@_foo`
-         * 
- */ - public final byte[] name; - /** - *
-         * The value to write to the instance variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     @foo = :bar
-         *            ^^^^
-         *
-         *     @_x = 1234
-         *           ^^^^
-         * 
- */ - public final Node value; - - public InstanceVariableWriteNode(int startOffset, int length, byte[] name, Node value) { - super(startOffset, length); - this.name = name; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInstanceVariableWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents an integer number literal.
-     *
-     *     1
-     *     ^
-     * 
- */ - public static final class IntegerNode extends Node { - public final short flags; - /** - *
-         * The value of the integer literal as a number.
-         * 
- */ - public final Object value; - - public IntegerNode(int startOffset, int length, short flags, Object value) { - super(startOffset, length); - this.flags = flags; - this.value = value; - } - - public boolean isBinary() { - return IntegerBaseFlags.isBinary(flags); - } - - public boolean isDecimal() { - return IntegerBaseFlags.isDecimal(flags); - } - - public boolean isOctal() { - return IntegerBaseFlags.isOctal(flags); - } - - public boolean isHexadecimal() { - return IntegerBaseFlags.isHexadecimal(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitIntegerNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("IntegerBaseFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents a regular expression literal that contains interpolation that is being used in the predicate of a conditional to implicitly match against the last line read by an IO object.
-     *
-     *     if /foo #{bar} baz/ then end
-     *        ^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class InterpolatedMatchLastLineNode extends Node { - public final short flags; - @UnionType({ StringNode.class, EmbeddedStatementsNode.class, EmbeddedVariableNode.class }) - public final Node[] parts; - - public InterpolatedMatchLastLineNode(int startOffset, int length, short flags, Node[] parts) { - super(startOffset, length); - this.flags = flags; - this.parts = parts; - } - - public boolean isIgnoreCase() { - return RegularExpressionFlags.isIgnoreCase(flags); - } - - public boolean isExtended() { - return RegularExpressionFlags.isExtended(flags); - } - - public boolean isMultiLine() { - return RegularExpressionFlags.isMultiLine(flags); - } - - public boolean isOnce() { - return RegularExpressionFlags.isOnce(flags); - } - - public boolean isEucJp() { - return RegularExpressionFlags.isEucJp(flags); - } - - public boolean isAscii8bit() { - return RegularExpressionFlags.isAscii8bit(flags); - } - - public boolean isWindows31j() { - return RegularExpressionFlags.isWindows31j(flags); - } - - public boolean isUtf8() { - return RegularExpressionFlags.isUtf8(flags); - } - - public boolean isForcedUtf8Encoding() { - return RegularExpressionFlags.isForcedUtf8Encoding(flags); - } - - public boolean isForcedBinaryEncoding() { - return RegularExpressionFlags.isForcedBinaryEncoding(flags); - } - - public boolean isForcedUsAsciiEncoding() { - return RegularExpressionFlags.isForcedUsAsciiEncoding(flags); - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - Node first = this.parts.length > 0 ? this.parts[0] : null; - if (first != null) { - first.setNewLineFlag(source, newlineMarked); - } - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.parts) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.parts)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInterpolatedMatchLastLineNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("RegularExpressionFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("parts: "); - builder.append('\n'); - for (Node child : this.parts) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents a regular expression literal that contains interpolation.
-     *
-     *     /foo #{bar} baz/
-     *     ^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class InterpolatedRegularExpressionNode extends Node { - public final short flags; - @UnionType({ StringNode.class, EmbeddedStatementsNode.class, EmbeddedVariableNode.class }) - public final Node[] parts; - - public InterpolatedRegularExpressionNode(int startOffset, int length, short flags, Node[] parts) { - super(startOffset, length); - this.flags = flags; - this.parts = parts; - } - - public boolean isIgnoreCase() { - return RegularExpressionFlags.isIgnoreCase(flags); - } - - public boolean isExtended() { - return RegularExpressionFlags.isExtended(flags); - } - - public boolean isMultiLine() { - return RegularExpressionFlags.isMultiLine(flags); - } - - public boolean isOnce() { - return RegularExpressionFlags.isOnce(flags); - } - - public boolean isEucJp() { - return RegularExpressionFlags.isEucJp(flags); - } - - public boolean isAscii8bit() { - return RegularExpressionFlags.isAscii8bit(flags); - } - - public boolean isWindows31j() { - return RegularExpressionFlags.isWindows31j(flags); - } - - public boolean isUtf8() { - return RegularExpressionFlags.isUtf8(flags); - } - - public boolean isForcedUtf8Encoding() { - return RegularExpressionFlags.isForcedUtf8Encoding(flags); - } - - public boolean isForcedBinaryEncoding() { - return RegularExpressionFlags.isForcedBinaryEncoding(flags); - } - - public boolean isForcedUsAsciiEncoding() { - return RegularExpressionFlags.isForcedUsAsciiEncoding(flags); - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - Node first = this.parts.length > 0 ? this.parts[0] : null; - if (first != null) { - first.setNewLineFlag(source, newlineMarked); - } - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.parts) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.parts)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInterpolatedRegularExpressionNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("RegularExpressionFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("parts: "); - builder.append('\n'); - for (Node child : this.parts) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents a string literal that contains interpolation.
-     *
-     *     "foo #{bar} baz"
-     *     ^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class InterpolatedStringNode extends Node { - public final short flags; - @UnionType({ StringNode.class, EmbeddedStatementsNode.class, EmbeddedVariableNode.class, InterpolatedStringNode.class }) - public final Node[] parts; - - public InterpolatedStringNode(int startOffset, int length, short flags, Node[] parts) { - super(startOffset, length); - this.flags = flags; - this.parts = parts; - } - - public boolean isFrozen() { - return InterpolatedStringNodeFlags.isFrozen(flags); - } - - public boolean isMutable() { - return InterpolatedStringNodeFlags.isMutable(flags); - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - Node first = this.parts.length > 0 ? this.parts[0] : null; - if (first != null) { - first.setNewLineFlag(source, newlineMarked); - } - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.parts) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.parts)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInterpolatedStringNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("InterpolatedStringNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("parts: "); - builder.append('\n'); - for (Node child : this.parts) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents a symbol literal that contains interpolation.
-     *
-     *     :"foo #{bar} baz"
-     *     ^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class InterpolatedSymbolNode extends Node { - @UnionType({ StringNode.class, EmbeddedStatementsNode.class, EmbeddedVariableNode.class }) - public final Node[] parts; - - public InterpolatedSymbolNode(int startOffset, int length, Node[] parts) { - super(startOffset, length); - this.parts = parts; - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - Node first = this.parts.length > 0 ? this.parts[0] : null; - if (first != null) { - first.setNewLineFlag(source, newlineMarked); - } - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.parts) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.parts)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInterpolatedSymbolNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("parts: "); - builder.append('\n'); - for (Node child : this.parts) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents an xstring literal that contains interpolation.
-     *
-     *     `foo #{bar} baz`
-     *     ^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class InterpolatedXStringNode extends Node { - @UnionType({ StringNode.class, EmbeddedStatementsNode.class, EmbeddedVariableNode.class }) - public final Node[] parts; - - public InterpolatedXStringNode(int startOffset, int length, Node[] parts) { - super(startOffset, length); - this.parts = parts; - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - Node first = this.parts.length > 0 ? this.parts[0] : null; - if (first != null) { - first.setNewLineFlag(source, newlineMarked); - } - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.parts) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.parts)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitInterpolatedXStringNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("parts: "); - builder.append('\n'); - for (Node child : this.parts) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents reading from the implicit `it` local variable.
-     *
-     *     -> { it }
-     *          ^^
-     * 
- */ - public static final class ItLocalVariableReadNode extends Node { - - public ItLocalVariableReadNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitItLocalVariableReadNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents an implicit set of parameters through the use of the `it` keyword within a block or lambda.
-     *
-     *     -> { it + it }
-     *     ^^^^^^^^^^^^^^
-     * 
- */ - public static final class ItParametersNode extends Node { - - public ItParametersNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitItParametersNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents a hash literal without opening and closing braces.
-     *
-     *     foo(a: b)
-     *         ^^^^
-     * 
- */ - public static final class KeywordHashNode extends Node { - public final short flags; - @UnionType({ AssocNode.class, AssocSplatNode.class }) - public final Node[] elements; - - public KeywordHashNode(int startOffset, int length, short flags, Node[] elements) { - super(startOffset, length); - this.flags = flags; - this.elements = elements; - } - - public boolean isSymbolKeys() { - return KeywordHashNodeFlags.isSymbolKeys(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.elements) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.elements)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitKeywordHashNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("KeywordHashNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("elements: "); - builder.append('\n'); - for (Node child : this.elements) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents a keyword rest parameter to a method, block, or lambda definition.
-     *
-     *     def a(**b)
-     *           ^^^
-     *     end
-     * 
- */ - public static final class KeywordRestParameterNode extends Node { - public final short flags; - @Nullable - public final byte[] name; - - public KeywordRestParameterNode(int startOffset, int length, short flags, byte[] name) { - super(startOffset, length); - this.flags = flags; - this.name = name; - } - - public boolean isRepeatedParameter() { - return ParameterFlags.isRepeatedParameter(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitKeywordRestParameterNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("ParameterFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("name: "); - builder.append(this.name == null ? "null" : "\"" + asString(this.name) + "\""); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents using a lambda literal (not the lambda method call).
-     *
-     *     ->(value) { value * 2 }
-     *     ^^^^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class LambdaNode extends Node { - public final byte[][] locals; - @Nullable - @UnionType({ BlockParametersNode.class, NumberedParametersNode.class, ItParametersNode.class }) - public final Node parameters; - @Nullable - @UnionType({ StatementsNode.class, BeginNode.class }) - public final Node body; - - public LambdaNode(int startOffset, int length, byte[][] locals, Node parameters, Node body) { - super(startOffset, length); - this.locals = locals; - this.parameters = parameters; - this.body = body; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.parameters != null) { - this.parameters.accept(visitor); - } - if (this.body != null) { - this.body.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.parameters, this.body }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitLambdaNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("locals: "); - builder.append('\n'); - for (byte[] constant : this.locals) { - builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); - } - builder.append(nextIndent); - builder.append("parameters: "); - builder.append(this.parameters == null ? "null\n" : this.parameters.toString(nextIndent)); - builder.append(nextIndent); - builder.append("body: "); - builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `&&=` operator for assignment to a local variable.
-     *
-     *     target &&= value
-     *     ^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class LocalVariableAndWriteNode extends Node { - public final Node value; - public final byte[] name; - public final int depth; - - public LocalVariableAndWriteNode(int startOffset, int length, Node value, byte[] name, int depth) { - super(startOffset, length); - this.value = value; - this.name = name; - this.depth = depth; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitLocalVariableAndWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("depth: "); - builder.append(this.depth); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents assigning to a local variable using an operator that isn't `=`.
-     *
-     *     target += value
-     *     ^^^^^^^^^^^^^^^
-     * 
- */ - public static final class LocalVariableOperatorWriteNode extends Node { - public final Node value; - public final byte[] name; - public final byte[] binary_operator; - public final int depth; - - public LocalVariableOperatorWriteNode(int startOffset, int length, Node value, byte[] name, byte[] binary_operator, int depth) { - super(startOffset, length); - this.value = value; - this.name = name; - this.binary_operator = binary_operator; - this.depth = depth; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitLocalVariableOperatorWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("binary_operator: "); - builder.append('"').append(asString(this.binary_operator)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("depth: "); - builder.append(this.depth); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `||=` operator for assignment to a local variable.
-     *
-     *     target ||= value
-     *     ^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class LocalVariableOrWriteNode extends Node { - public final Node value; - public final byte[] name; - public final int depth; - - public LocalVariableOrWriteNode(int startOffset, int length, Node value, byte[] name, int depth) { - super(startOffset, length); - this.value = value; - this.name = name; - this.depth = depth; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitLocalVariableOrWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("depth: "); - builder.append(this.depth); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents reading a local variable. Note that this requires that a local variable of the same name has already been written to in the same scope, otherwise it is parsed as a method call.
-     *
-     *     foo
-     *     ^^^
-     * 
- */ - public static final class LocalVariableReadNode extends Node { - /** - *
-         * The name of the local variable, which is an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
-         *
-         *     x      # name `:x`
-         *
-         *     _Test  # name `:_Test`
-         *
-         * Note that this can also be an underscore followed by a number for the default block parameters.
-         *
-         *     _1     # name `:_1`
-         * 
- */ - public final byte[] name; - /** - *
-         * The number of visible scopes that should be searched to find the origin of this local variable.
-         *
-         *     foo = 1; foo # depth 0
-         *
-         *     bar = 2; tap { bar } # depth 1
-         *
-         * The specific rules for calculating the depth may differ from individual Ruby implementations, as they are not specified by the language. For more information, see [the Prism documentation](https://github.com/ruby/prism/blob/main/docs/local_variable_depth.md).
-         * 
- */ - public final int depth; - - public LocalVariableReadNode(int startOffset, int length, byte[] name, int depth) { - super(startOffset, length); - this.name = name; - this.depth = depth; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitLocalVariableReadNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("depth: "); - builder.append(this.depth); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to a local variable in a context that doesn't have an explicit value.
-     *
-     *     foo, bar = baz
-     *     ^^^  ^^^
-     *
-     *     foo => baz
-     *            ^^^
-     * 
- */ - public static final class LocalVariableTargetNode extends Node { - public final byte[] name; - public final int depth; - - public LocalVariableTargetNode(int startOffset, int length, byte[] name, int depth) { - super(startOffset, length); - this.name = name; - this.depth = depth; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitLocalVariableTargetNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("depth: "); - builder.append(this.depth); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents writing to a local variable.
-     *
-     *     foo = 1
-     *     ^^^^^^^
-     * 
- */ - public static final class LocalVariableWriteNode extends Node { - /** - *
-         * The name of the local variable, which is an [identifier](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers).
-         *
-         *     foo = :bar # name `:foo`
-         *
-         *     abc = 123  # name `:abc`
-         * 
- */ - public final byte[] name; - /** - *
-         * The number of semantic scopes we have to traverse to find the declaration of this variable.
-         *
-         *     foo = 1         # depth 0
-         *
-         *     tap { foo = 1 } # depth 1
-         *
-         * The specific rules for calculating the depth may differ from individual Ruby implementations, as they are not specified by the language. For more information, see [the Prism documentation](https://github.com/ruby/prism/blob/main/docs/local_variable_depth.md).
-         * 
- */ - public final int depth; - /** - *
-         * The value to write to the local variable. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     foo = :bar
-         *           ^^^^
-         *
-         *     abc = 1234
-         *           ^^^^
-         *
-         * Note that since the name of a local variable is known before the value is parsed, it is valid for a local variable to appear within the value of its own write.
-         *
-         *     foo = foo
-         * 
- */ - public final Node value; - - public LocalVariableWriteNode(int startOffset, int length, byte[] name, int depth, Node value) { - super(startOffset, length); - this.name = name; - this.depth = depth; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitLocalVariableWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("depth: "); - builder.append(this.depth); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a regular expression literal used in the predicate of a conditional to implicitly match against the last line read by an IO object.
-     *
-     *     if /foo/i then end
-     *        ^^^^^^
-     * 
- */ - public static final class MatchLastLineNode extends Node { - public final short flags; - public final byte[] unescaped; - - public MatchLastLineNode(int startOffset, int length, short flags, byte[] unescaped) { - super(startOffset, length); - this.flags = flags; - this.unescaped = unescaped; - } - - public boolean isIgnoreCase() { - return RegularExpressionFlags.isIgnoreCase(flags); - } - - public boolean isExtended() { - return RegularExpressionFlags.isExtended(flags); - } - - public boolean isMultiLine() { - return RegularExpressionFlags.isMultiLine(flags); - } - - public boolean isOnce() { - return RegularExpressionFlags.isOnce(flags); - } - - public boolean isEucJp() { - return RegularExpressionFlags.isEucJp(flags); - } - - public boolean isAscii8bit() { - return RegularExpressionFlags.isAscii8bit(flags); - } - - public boolean isWindows31j() { - return RegularExpressionFlags.isWindows31j(flags); - } - - public boolean isUtf8() { - return RegularExpressionFlags.isUtf8(flags); - } - - public boolean isForcedUtf8Encoding() { - return RegularExpressionFlags.isForcedUtf8Encoding(flags); - } - - public boolean isForcedBinaryEncoding() { - return RegularExpressionFlags.isForcedBinaryEncoding(flags); - } - - public boolean isForcedUsAsciiEncoding() { - return RegularExpressionFlags.isForcedUsAsciiEncoding(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitMatchLastLineNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("RegularExpressionFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("unescaped: "); - builder.append('"' + asString(this.unescaped) + '"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the modifier `in` operator.
-     *
-     *     foo in bar
-     *     ^^^^^^^^^^
-     * 
- */ - public static final class MatchPredicateNode extends Node { - public final Node value; - public final Node pattern; - - public MatchPredicateNode(int startOffset, int length, Node value, Node pattern) { - super(startOffset, length); - this.value = value; - this.pattern = pattern; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - this.pattern.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value, this.pattern }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitMatchPredicateNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - builder.append(nextIndent); - builder.append("pattern: "); - builder.append(this.pattern.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `=>` operator.
-     *
-     *     foo => bar
-     *     ^^^^^^^^^^
-     * 
- */ - public static final class MatchRequiredNode extends Node { - /** - *
-         * Represents the left-hand side of the operator.
-         *
-         *     foo => bar
-         *     ^^^
-         * 
- */ - public final Node value; - /** - *
-         * Represents the right-hand side of the operator. The type of the node depends on the expression.
-         *
-         * Anything that looks like a local variable name (including `_`) will result in a `LocalVariableTargetNode`.
-         *
-         *     foo => a # This is equivalent to writing `a = foo`
-         *            ^
-         *
-         * Using an explicit `Array` or combining expressions with `,` will result in a `ArrayPatternNode`. This can be preceded by a constant.
-         *
-         *     foo => [a]
-         *            ^^^
-         *
-         *     foo => a, b
-         *            ^^^^
-         *
-         *     foo => Bar[a, b]
-         *            ^^^^^^^^^
-         *
-         * If the array pattern contains at least two wildcard matches, a `FindPatternNode` is created instead.
-         *
-         *     foo => *, 1, *a
-         *            ^^^^^
-         *
-         * Using an explicit `Hash` or a constant with square brackets and hash keys in the square brackets will result in a `HashPatternNode`.
-         *
-         *     foo => { a: 1, b: }
-         *
-         *     foo => Bar[a: 1, b:]
-         *
-         *     foo => Bar[**]
-         *
-         * To use any variable that needs run time evaluation, pinning is required. This results in a `PinnedVariableNode`
-         *
-         *     foo => ^a
-         *            ^^
-         *
-         * Similar, any expression can be used with pinning. This results in a `PinnedExpressionNode`.
-         *
-         *     foo => ^(a + 1)
-         *
-         * Anything else will result in the regular node for that expression, for example a `ConstantReadNode`.
-         *
-         *     foo => CONST
-         * 
- */ - public final Node pattern; - - public MatchRequiredNode(int startOffset, int length, Node value, Node pattern) { - super(startOffset, length); - this.value = value; - this.pattern = pattern; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - this.pattern.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value, this.pattern }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitMatchRequiredNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - builder.append(nextIndent); - builder.append("pattern: "); - builder.append(this.pattern.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents writing local variables using a regular expression match with named capture groups.
-     *
-     *     /(?<foo>bar)/ =~ baz
-     *     ^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class MatchWriteNode extends Node { - public final CallNode call; - public final LocalVariableTargetNode[] targets; - - public MatchWriteNode(int startOffset, int length, CallNode call, LocalVariableTargetNode[] targets) { - super(startOffset, length); - this.call = call; - this.targets = targets; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.call.accept(visitor); - for (Nodes.Node child : this.targets) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.add(this.call); - childNodes.addAll(Arrays.asList(this.targets)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitMatchWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("call: "); - builder.append(this.call.toString(nextIndent)); - builder.append(nextIndent); - builder.append("targets: "); - builder.append('\n'); - for (Node child : this.targets) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents a node that is missing from the source and results in a syntax error.
-     * 
- */ - public static final class MissingNode extends Node { - - public MissingNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitMissingNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents a module declaration involving the `module` keyword.
-     *
-     *     module Foo end
-     *     ^^^^^^^^^^^^^^
-     * 
- */ - public static final class ModuleNode extends Node { - public final byte[][] locals; - @UnionType({ ConstantReadNode.class, ConstantPathNode.class }) - public final Node constant_path; - @Nullable - @UnionType({ StatementsNode.class, BeginNode.class }) - public final Node body; - public final byte[] name; - - public ModuleNode(int startOffset, int length, byte[][] locals, Node constant_path, Node body, byte[] name) { - super(startOffset, length); - this.locals = locals; - this.constant_path = constant_path; - this.body = body; - this.name = name; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.constant_path.accept(visitor); - if (this.body != null) { - this.body.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.constant_path, this.body }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitModuleNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("locals: "); - builder.append('\n'); - for (byte[] constant : this.locals) { - builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); - } - builder.append(nextIndent); - builder.append("constant_path: "); - builder.append(this.constant_path.toString(nextIndent)); - builder.append(nextIndent); - builder.append("body: "); - builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents a multi-target expression.
-     *
-     *     a, (b, c) = 1, 2, 3
-     *        ^^^^^^
-     *
-     * This can be a part of `MultiWriteNode` as above, or the target of a `for` loop
-     *
-     *     for a, b in [[1, 2], [3, 4]]
-     *         ^^^^
-     * 
- */ - public static final class MultiTargetNode extends Node { - /** - *
-         * Represents the targets expressions before a splat node.
-         *
-         *     a, (b, c, *) = 1, 2, 3, 4, 5
-         *         ^^^^
-         *
-         * The splat node can be absent, in that case all target expressions are in the left field.
-         *
-         *     a, (b, c) = 1, 2, 3, 4, 5
-         *         ^^^^
-         * 
- */ - @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class, MultiTargetNode.class, RequiredParameterNode.class }) - public final Node[] lefts; - /** - *
-         * Represents a splat node in the target expression.
-         *
-         *     a, (b, *c) = 1, 2, 3, 4
-         *            ^^
-         *
-         * The variable can be empty, this results in a `SplatNode` with a `nil` expression field.
-         *
-         *     a, (b, *) = 1, 2, 3, 4
-         *            ^
-         *
-         * If the `*` is omitted, this field will contain an `ImplicitRestNode`
-         *
-         *     a, (b,) = 1, 2, 3, 4
-         *          ^
-         * 
- */ - @Nullable - @UnionType({ ImplicitRestNode.class, SplatNode.class }) - public final Node rest; - /** - *
-         * Represents the targets expressions after a splat node.
-         *
-         *     a, (*, b, c) = 1, 2, 3, 4, 5
-         *            ^^^^
-         * 
- */ - @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class, MultiTargetNode.class, RequiredParameterNode.class }) - public final Node[] rights; - - public MultiTargetNode(int startOffset, int length, Node[] lefts, Node rest, Node[] rights) { - super(startOffset, length); - this.lefts = lefts; - this.rest = rest; - this.rights = rights; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.lefts) { - child.accept(visitor); - } - if (this.rest != null) { - this.rest.accept(visitor); - } - for (Nodes.Node child : this.rights) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.lefts)); - childNodes.add(this.rest); - childNodes.addAll(Arrays.asList(this.rights)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitMultiTargetNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("lefts: "); - builder.append('\n'); - for (Node child : this.lefts) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("rest: "); - builder.append(this.rest == null ? "null\n" : this.rest.toString(nextIndent)); - builder.append(nextIndent); - builder.append("rights: "); - builder.append('\n'); - for (Node child : this.rights) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents a write to a multi-target expression.
-     *
-     *     a, b, c = 1, 2, 3
-     *     ^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class MultiWriteNode extends Node { - /** - *
-         * Represents the targets expressions before a splat node.
-         *
-         *     a, b, * = 1, 2, 3, 4, 5
-         *     ^^^^
-         *
-         * The splat node can be absent, in that case all target expressions are in the left field.
-         *
-         *     a, b, c = 1, 2, 3, 4, 5
-         *     ^^^^^^^
-         * 
- */ - @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class, MultiTargetNode.class }) - public final Node[] lefts; - /** - *
-         * Represents a splat node in the target expression.
-         *
-         *     a, b, *c = 1, 2, 3, 4
-         *           ^^
-         *
-         * The variable can be empty, this results in a `SplatNode` with a `nil` expression field.
-         *
-         *     a, b, * = 1, 2, 3, 4
-         *           ^
-         *
-         * If the `*` is omitted, this field will contain an `ImplicitRestNode`
-         *
-         *     a, b, = 1, 2, 3, 4
-         *         ^
-         * 
- */ - @Nullable - @UnionType({ ImplicitRestNode.class, SplatNode.class }) - public final Node rest; - /** - *
-         * Represents the targets expressions after a splat node.
-         *
-         *     a, *, b, c = 1, 2, 3, 4, 5
-         *           ^^^^
-         * 
- */ - @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class, MultiTargetNode.class }) - public final Node[] rights; - /** - *
-         * The value to write to the targets. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     a, b, c = 1, 2, 3
-         *               ^^^^^^^
-         * 
- */ - public final Node value; - - public MultiWriteNode(int startOffset, int length, Node[] lefts, Node rest, Node[] rights, Node value) { - super(startOffset, length); - this.lefts = lefts; - this.rest = rest; - this.rights = rights; - this.value = value; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.lefts) { - child.accept(visitor); - } - if (this.rest != null) { - this.rest.accept(visitor); - } - for (Nodes.Node child : this.rights) { - child.accept(visitor); - } - this.value.accept(visitor); - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.lefts)); - childNodes.add(this.rest); - childNodes.addAll(Arrays.asList(this.rights)); - childNodes.add(this.value); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitMultiWriteNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("lefts: "); - builder.append('\n'); - for (Node child : this.lefts) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("rest: "); - builder.append(this.rest == null ? "null\n" : this.rest.toString(nextIndent)); - builder.append(nextIndent); - builder.append("rights: "); - builder.append('\n'); - for (Node child : this.rights) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `next` keyword.
-     *
-     *     next 1
-     *     ^^^^^^
-     * 
- */ - public static final class NextNode extends Node { - @Nullable - public final ArgumentsNode arguments; - - public NextNode(int startOffset, int length, ArgumentsNode arguments) { - super(startOffset, length); - this.arguments = arguments; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.arguments != null) { - this.arguments.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.arguments }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitNextNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("arguments: "); - builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `nil` keyword.
-     *
-     *     nil
-     *     ^^^
-     * 
- */ - public static final class NilNode extends Node { - - public NilNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitNilNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents the use of `&nil` inside method arguments.
-     *
-     *     def a(&nil)
-     *           ^^^^
-     *     end
-     * 
- */ - public static final class NoBlockParameterNode extends Node { - - public NoBlockParameterNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitNoBlockParameterNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents the use of `**nil` inside method arguments.
-     *
-     *     def a(**nil)
-     *           ^^^^^
-     *     end
-     * 
- */ - public static final class NoKeywordsParameterNode extends Node { - - public NoKeywordsParameterNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitNoKeywordsParameterNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents an implicit set of parameters through the use of numbered parameters within a block or lambda.
-     *
-     *     -> { _1 + _2 }
-     *     ^^^^^^^^^^^^^^
-     * 
- */ - public static final class NumberedParametersNode extends Node { - public final int maximum; - - public NumberedParametersNode(int startOffset, int length, int maximum) { - super(startOffset, length); - this.maximum = maximum; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitNumberedParametersNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("maximum: "); - builder.append(this.maximum); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents reading a numbered reference to a capture in the previous match.
-     *
-     *     $1
-     *     ^^
-     * 
- */ - public static final class NumberedReferenceReadNode extends Node { - /** - *
-         * The (1-indexed, from the left) number of the capture group. Numbered references that are too large result in this value being `0`.
-         *
-         *     $1          # number `1`
-         *
-         *     $5432       # number `5432`
-         *
-         *     $4294967296 # number `0`
-         * 
- */ - public final int number; - - public NumberedReferenceReadNode(int startOffset, int length, int number) { - super(startOffset, length); - this.number = number; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitNumberedReferenceReadNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("number: "); - builder.append(this.number); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents an optional keyword parameter to a method, block, or lambda definition.
-     *
-     *     def a(b: 1)
-     *           ^^^^
-     *     end
-     * 
- */ - public static final class OptionalKeywordParameterNode extends Node { - public final short flags; - public final byte[] name; - public final Node value; - - public OptionalKeywordParameterNode(int startOffset, int length, short flags, byte[] name, Node value) { - super(startOffset, length); - this.flags = flags; - this.name = name; - this.value = value; - } - - public boolean isRepeatedParameter() { - return ParameterFlags.isRepeatedParameter(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitOptionalKeywordParameterNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("ParameterFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents an optional parameter to a method, block, or lambda definition.
-     *
-     *     def a(b = 1)
-     *           ^^^^^
-     *     end
-     * 
- */ - public static final class OptionalParameterNode extends Node { - public final short flags; - public final byte[] name; - public final Node value; - - public OptionalParameterNode(int startOffset, int length, short flags, byte[] name, Node value) { - super(startOffset, length); - this.flags = flags; - this.name = name; - this.value = value; - } - - public boolean isRepeatedParameter() { - return ParameterFlags.isRepeatedParameter(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.value.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.value }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitOptionalParameterNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("ParameterFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - builder.append(nextIndent); - builder.append("value: "); - builder.append(this.value.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `||` operator or the `or` keyword.
-     *
-     *     left or right
-     *     ^^^^^^^^^^^^^
-     * 
- */ - public static final class OrNode extends Node { - /** - *
-         * Represents the left side of the expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     left or right
-         *     ^^^^
-         *
-         *     1 || 2
-         *     ^
-         * 
- */ - public final Node left; - /** - *
-         * Represents the right side of the expression.
-         *
-         *     left || right
-         *             ^^^^^
-         *
-         *     1 or 2
-         *          ^
-         * 
- */ - public final Node right; - - public OrNode(int startOffset, int length, Node left, Node right) { - super(startOffset, length); - this.left = left; - this.right = right; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.left.accept(visitor); - this.right.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.left, this.right }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitOrNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("left: "); - builder.append(this.left.toString(nextIndent)); - builder.append(nextIndent); - builder.append("right: "); - builder.append(this.right.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the list of parameters on a method, block, or lambda definition.
-     *
-     *     def a(b, c, d)
-     *           ^^^^^^^
-     *     end
-     * 
- */ - public static final class ParametersNode extends Node { - @UnionType({ RequiredParameterNode.class, MultiTargetNode.class }) - public final Node[] requireds; - public final OptionalParameterNode[] optionals; - @Nullable - @UnionType({ RestParameterNode.class, ImplicitRestNode.class }) - public final Node rest; - @UnionType({ RequiredParameterNode.class, MultiTargetNode.class }) - public final Node[] posts; - @UnionType({ RequiredKeywordParameterNode.class, OptionalKeywordParameterNode.class }) - public final Node[] keywords; - @Nullable - @UnionType({ KeywordRestParameterNode.class, ForwardingParameterNode.class, NoKeywordsParameterNode.class }) - public final Node keyword_rest; - @Nullable - @UnionType({ BlockParameterNode.class, NoBlockParameterNode.class }) - public final Node block; - - public ParametersNode(int startOffset, int length, Node[] requireds, OptionalParameterNode[] optionals, Node rest, Node[] posts, Node[] keywords, Node keyword_rest, Node block) { - super(startOffset, length); - this.requireds = requireds; - this.optionals = optionals; - this.rest = rest; - this.posts = posts; - this.keywords = keywords; - this.keyword_rest = keyword_rest; - this.block = block; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.requireds) { - child.accept(visitor); - } - for (Nodes.Node child : this.optionals) { - child.accept(visitor); - } - if (this.rest != null) { - this.rest.accept(visitor); - } - for (Nodes.Node child : this.posts) { - child.accept(visitor); - } - for (Nodes.Node child : this.keywords) { - child.accept(visitor); - } - if (this.keyword_rest != null) { - this.keyword_rest.accept(visitor); - } - if (this.block != null) { - this.block.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.requireds)); - childNodes.addAll(Arrays.asList(this.optionals)); - childNodes.add(this.rest); - childNodes.addAll(Arrays.asList(this.posts)); - childNodes.addAll(Arrays.asList(this.keywords)); - childNodes.add(this.keyword_rest); - childNodes.add(this.block); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitParametersNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("requireds: "); - builder.append('\n'); - for (Node child : this.requireds) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("optionals: "); - builder.append('\n'); - for (Node child : this.optionals) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("rest: "); - builder.append(this.rest == null ? "null\n" : this.rest.toString(nextIndent)); - builder.append(nextIndent); - builder.append("posts: "); - builder.append('\n'); - for (Node child : this.posts) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("keywords: "); - builder.append('\n'); - for (Node child : this.keywords) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("keyword_rest: "); - builder.append(this.keyword_rest == null ? "null\n" : this.keyword_rest.toString(nextIndent)); - builder.append(nextIndent); - builder.append("block: "); - builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a parenthesized expression
-     *
-     *     (10 + 34)
-     *     ^^^^^^^^^
-     * 
- */ - public static final class ParenthesesNode extends Node { - public final short flags; - @Nullable - public final Node body; - - public ParenthesesNode(int startOffset, int length, short flags, Node body) { - super(startOffset, length); - this.flags = flags; - this.body = body; - } - - public boolean isMultipleStatements() { - return ParenthesesNodeFlags.isMultipleStatements(flags); - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - // Never mark ParenthesesNode with a newline flag, mark children instead - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.body != null) { - this.body.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.body }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitParenthesesNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("ParenthesesNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("body: "); - builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `^` operator for pinning an expression in a pattern matching expression.
-     *
-     *     foo in ^(bar)
-     *            ^^^^^^
-     * 
- */ - public static final class PinnedExpressionNode extends Node { - /** - *
-         * The expression used in the pinned expression
-         *
-         *     foo in ^(bar)
-         *              ^^^
-         * 
- */ - public final Node expression; - - public PinnedExpressionNode(int startOffset, int length, Node expression) { - super(startOffset, length); - this.expression = expression; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.expression.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.expression }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitPinnedExpressionNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("expression: "); - builder.append(this.expression.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `^` operator for pinning a variable in a pattern matching expression.
-     *
-     *     foo in ^bar
-     *            ^^^^
-     * 
- */ - public static final class PinnedVariableNode extends Node { - /** - *
-         * The variable used in the pinned expression
-         *
-         *     foo in ^bar
-         *             ^^^
-         * 
- */ - @UnionType({ LocalVariableReadNode.class, InstanceVariableReadNode.class, ClassVariableReadNode.class, GlobalVariableReadNode.class, BackReferenceReadNode.class, NumberedReferenceReadNode.class, ItLocalVariableReadNode.class }) - public final Node variable; - - public PinnedVariableNode(int startOffset, int length, Node variable) { - super(startOffset, length); - this.variable = variable; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.variable.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.variable }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitPinnedVariableNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("variable: "); - builder.append(this.variable.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `END` keyword.
-     *
-     *     END { foo }
-     *     ^^^^^^^^^^^
-     * 
- */ - public static final class PostExecutionNode extends Node { - @Nullable - public final StatementsNode statements; - - public PostExecutionNode(int startOffset, int length, StatementsNode statements) { - super(startOffset, length); - this.statements = statements; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.statements != null) { - this.statements.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.statements }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitPostExecutionNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `BEGIN` keyword.
-     *
-     *     BEGIN { foo }
-     *     ^^^^^^^^^^^^^
-     * 
- */ - public static final class PreExecutionNode extends Node { - @Nullable - public final StatementsNode statements; - - public PreExecutionNode(int startOffset, int length, StatementsNode statements) { - super(startOffset, length); - this.statements = statements; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.statements != null) { - this.statements.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.statements }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitPreExecutionNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * The top level node of any parse tree.
-     * 
- */ - public static final class ProgramNode extends Node { - public final byte[][] locals; - public final StatementsNode statements; - - public ProgramNode(int startOffset, int length, byte[][] locals, StatementsNode statements) { - super(startOffset, length); - this.locals = locals; - this.statements = statements; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.statements.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.statements }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitProgramNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("locals: "); - builder.append('\n'); - for (byte[] constant : this.locals) { - builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); - } - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `..` or `...` operators.
-     *
-     *     1..2
-     *     ^^^^
-     *
-     *     c if a =~ /left/ ... b =~ /right/
-     *          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class RangeNode extends Node { - public final short flags; - /** - *
-         * The left-hand side of the range, if present. It can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     1...
-         *     ^
-         *
-         *     hello...goodbye
-         *     ^^^^^
-         * 
- */ - @Nullable - public final Node left; - /** - *
-         * The right-hand side of the range, if present. It can be either `nil` or any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     ..5
-         *       ^
-         *
-         *     1...foo
-         *         ^^^
-         * If neither right-hand or left-hand side was included, this will be a MissingNode.
-         * 
- */ - @Nullable - public final Node right; - - public RangeNode(int startOffset, int length, short flags, Node left, Node right) { - super(startOffset, length); - this.flags = flags; - this.left = left; - this.right = right; - } - - public boolean isExcludeEnd() { - return RangeFlags.isExcludeEnd(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.left != null) { - this.left.accept(visitor); - } - if (this.right != null) { - this.right.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.left, this.right }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitRangeNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("RangeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("left: "); - builder.append(this.left == null ? "null\n" : this.left.toString(nextIndent)); - builder.append(nextIndent); - builder.append("right: "); - builder.append(this.right == null ? "null\n" : this.right.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a rational number literal.
-     *
-     *     1.0r
-     *     ^^^^
-     * 
- */ - public static final class RationalNode extends Node { - public final short flags; - /** - *
-         * The numerator of the rational number.
-         *
-         *     1.5r # numerator 3
-         * 
- */ - public final Object numerator; - /** - *
-         * The denominator of the rational number.
-         *
-         *     1.5r # denominator 2
-         * 
- */ - public final Object denominator; - - public RationalNode(int startOffset, int length, short flags, Object numerator, Object denominator) { - super(startOffset, length); - this.flags = flags; - this.numerator = numerator; - this.denominator = denominator; - } - - public boolean isBinary() { - return IntegerBaseFlags.isBinary(flags); - } - - public boolean isDecimal() { - return IntegerBaseFlags.isDecimal(flags); - } - - public boolean isOctal() { - return IntegerBaseFlags.isOctal(flags); - } - - public boolean isHexadecimal() { - return IntegerBaseFlags.isHexadecimal(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitRationalNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("IntegerBaseFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("numerator: "); - builder.append(this.numerator); - builder.append('\n'); - builder.append(nextIndent); - builder.append("denominator: "); - builder.append(this.denominator); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `redo` keyword.
-     *
-     *     redo
-     *     ^^^^
-     * 
- */ - public static final class RedoNode extends Node { - - public RedoNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitRedoNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents a regular expression literal with no interpolation.
-     *
-     *     /foo/i
-     *     ^^^^^^
-     * 
- */ - public static final class RegularExpressionNode extends Node { - public final short flags; - public final byte[] unescaped; - - public RegularExpressionNode(int startOffset, int length, short flags, byte[] unescaped) { - super(startOffset, length); - this.flags = flags; - this.unescaped = unescaped; - } - - public boolean isIgnoreCase() { - return RegularExpressionFlags.isIgnoreCase(flags); - } - - public boolean isExtended() { - return RegularExpressionFlags.isExtended(flags); - } - - public boolean isMultiLine() { - return RegularExpressionFlags.isMultiLine(flags); - } - - public boolean isOnce() { - return RegularExpressionFlags.isOnce(flags); - } - - public boolean isEucJp() { - return RegularExpressionFlags.isEucJp(flags); - } - - public boolean isAscii8bit() { - return RegularExpressionFlags.isAscii8bit(flags); - } - - public boolean isWindows31j() { - return RegularExpressionFlags.isWindows31j(flags); - } - - public boolean isUtf8() { - return RegularExpressionFlags.isUtf8(flags); - } - - public boolean isForcedUtf8Encoding() { - return RegularExpressionFlags.isForcedUtf8Encoding(flags); - } - - public boolean isForcedBinaryEncoding() { - return RegularExpressionFlags.isForcedBinaryEncoding(flags); - } - - public boolean isForcedUsAsciiEncoding() { - return RegularExpressionFlags.isForcedUsAsciiEncoding(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitRegularExpressionNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("RegularExpressionFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("unescaped: "); - builder.append('"' + asString(this.unescaped) + '"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents a required keyword parameter to a method, block, or lambda definition.
-     *
-     *     def a(b: )
-     *           ^^
-     *     end
-     * 
- */ - public static final class RequiredKeywordParameterNode extends Node { - public final short flags; - public final byte[] name; - - public RequiredKeywordParameterNode(int startOffset, int length, short flags, byte[] name) { - super(startOffset, length); - this.flags = flags; - this.name = name; - } - - public boolean isRepeatedParameter() { - return ParameterFlags.isRepeatedParameter(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitRequiredKeywordParameterNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("ParameterFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents a required parameter to a method, block, or lambda definition.
-     *
-     *     def a(b)
-     *           ^
-     *     end
-     * 
- */ - public static final class RequiredParameterNode extends Node { - public final short flags; - public final byte[] name; - - public RequiredParameterNode(int startOffset, int length, short flags, byte[] name) { - super(startOffset, length); - this.flags = flags; - this.name = name; - } - - public boolean isRepeatedParameter() { - return ParameterFlags.isRepeatedParameter(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitRequiredParameterNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("ParameterFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("name: "); - builder.append('"').append(asString(this.name)).append('"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents an expression modified with a rescue.
-     *
-     *     foo rescue nil
-     *     ^^^^^^^^^^^^^^
-     * 
- */ - public static final class RescueModifierNode extends Node { - public final Node expression; - public final Node rescue_expression; - - public RescueModifierNode(int startOffset, int length, Node expression, Node rescue_expression) { - super(startOffset, length); - this.expression = expression; - this.rescue_expression = rescue_expression; - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - this.expression.setNewLineFlag(source, newlineMarked); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.expression.accept(visitor); - this.rescue_expression.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.expression, this.rescue_expression }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitRescueModifierNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("expression: "); - builder.append(this.expression.toString(nextIndent)); - builder.append(nextIndent); - builder.append("rescue_expression: "); - builder.append(this.rescue_expression.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a rescue statement.
-     *
-     *     begin
-     *     rescue Foo, *splat, Bar => ex
-     *       foo
-     *     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-     *     end
-     *
-     * `Foo, *splat, Bar` are in the `exceptions` field. `ex` is in the `reference` field.
-     * 
- */ - public static final class RescueNode extends Node { - public final Node[] exceptions; - @Nullable - @UnionType({ LocalVariableTargetNode.class, InstanceVariableTargetNode.class, ClassVariableTargetNode.class, GlobalVariableTargetNode.class, ConstantTargetNode.class, ConstantPathTargetNode.class, CallTargetNode.class, IndexTargetNode.class }) - public final Node reference; - @Nullable - public final StatementsNode statements; - @Nullable - public final RescueNode subsequent; - - public RescueNode(int startOffset, int length, Node[] exceptions, Node reference, StatementsNode statements, RescueNode subsequent) { - super(startOffset, length); - this.exceptions = exceptions; - this.reference = reference; - this.statements = statements; - this.subsequent = subsequent; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.exceptions) { - child.accept(visitor); - } - if (this.reference != null) { - this.reference.accept(visitor); - } - if (this.statements != null) { - this.statements.accept(visitor); - } - if (this.subsequent != null) { - this.subsequent.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.exceptions)); - childNodes.add(this.reference); - childNodes.add(this.statements); - childNodes.add(this.subsequent); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitRescueNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("exceptions: "); - builder.append('\n'); - for (Node child : this.exceptions) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("reference: "); - builder.append(this.reference == null ? "null\n" : this.reference.toString(nextIndent)); - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - builder.append(nextIndent); - builder.append("subsequent: "); - builder.append(this.subsequent == null ? "null\n" : this.subsequent.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a rest parameter to a method, block, or lambda definition.
-     *
-     *     def a(*b)
-     *           ^^
-     *     end
-     * 
- */ - public static final class RestParameterNode extends Node { - public final short flags; - @Nullable - public final byte[] name; - - public RestParameterNode(int startOffset, int length, short flags, byte[] name) { - super(startOffset, length); - this.flags = flags; - this.name = name; - } - - public boolean isRepeatedParameter() { - return ParameterFlags.isRepeatedParameter(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitRestParameterNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("ParameterFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("name: "); - builder.append(this.name == null ? "null" : "\"" + asString(this.name) + "\""); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `retry` keyword.
-     *
-     *     retry
-     *     ^^^^^
-     * 
- */ - public static final class RetryNode extends Node { - - public RetryNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitRetryNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `return` keyword.
-     *
-     *     return 1
-     *     ^^^^^^^^
-     * 
- */ - public static final class ReturnNode extends Node { - @Nullable - public final ArgumentsNode arguments; - - public ReturnNode(int startOffset, int length, ArgumentsNode arguments) { - super(startOffset, length); - this.arguments = arguments; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.arguments != null) { - this.arguments.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.arguments }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitReturnNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("arguments: "); - builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the `self` keyword.
-     *
-     *     self
-     *     ^^^^
-     * 
- */ - public static final class SelfNode extends Node { - - public SelfNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitSelfNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * This node wraps a constant write to indicate that when the value is written, it should have its shareability state modified.
-     *
-     *     # shareable_constant_value: literal
-     *     C = { a: 1 }
-     *     ^^^^^^^^^^^^
-     * 
- */ - public static final class ShareableConstantNode extends Node { - public final short flags; - /** - *
-         * The constant write that should be modified with the shareability state.
-         * 
- */ - @UnionType({ ConstantWriteNode.class, ConstantAndWriteNode.class, ConstantOrWriteNode.class, ConstantOperatorWriteNode.class, ConstantPathWriteNode.class, ConstantPathAndWriteNode.class, ConstantPathOrWriteNode.class, ConstantPathOperatorWriteNode.class }) - public final Node write; - - public ShareableConstantNode(int startOffset, int length, short flags, Node write) { - super(startOffset, length); - this.flags = flags; - this.write = write; - } - - public boolean isLiteral() { - return ShareableConstantNodeFlags.isLiteral(flags); - } - - public boolean isExperimentalEverything() { - return ShareableConstantNodeFlags.isExperimentalEverything(flags); - } - - public boolean isExperimentalCopy() { - return ShareableConstantNodeFlags.isExperimentalCopy(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.write.accept(visitor); - } - - public Node[] childNodes() { - return new Node[] { this.write }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitShareableConstantNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("ShareableConstantNodeFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("write: "); - builder.append(this.write.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a singleton class declaration involving the `class` keyword.
-     *
-     *     class << self end
-     *     ^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class SingletonClassNode extends Node { - public final byte[][] locals; - public final Node expression; - @Nullable - @UnionType({ StatementsNode.class, BeginNode.class }) - public final Node body; - - public SingletonClassNode(int startOffset, int length, byte[][] locals, Node expression, Node body) { - super(startOffset, length); - this.locals = locals; - this.expression = expression; - this.body = body; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.expression.accept(visitor); - if (this.body != null) { - this.body.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.expression, this.body }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitSingletonClassNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("locals: "); - builder.append('\n'); - for (byte[] constant : this.locals) { - builder.append(nextNextIndent).append('"').append(asString(constant)).append('"').append('\n'); - } - builder.append(nextIndent); - builder.append("expression: "); - builder.append(this.expression.toString(nextIndent)); - builder.append(nextIndent); - builder.append("body: "); - builder.append(this.body == null ? "null\n" : this.body.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `__ENCODING__` keyword.
-     *
-     *     __ENCODING__
-     *     ^^^^^^^^^^^^
-     * 
- */ - public static final class SourceEncodingNode extends Node { - - public SourceEncodingNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitSourceEncodingNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `__FILE__` keyword.
-     *
-     *     __FILE__
-     *     ^^^^^^^^
-     * 
- */ - public static final class SourceFileNode extends Node { - public final short flags; - /** - *
-         * Represents the file path being parsed. This corresponds directly to the `filepath` option given to the various `Prism.parse*` APIs.
-         * 
- */ - public final byte[] filepath; - - public SourceFileNode(int startOffset, int length, short flags, byte[] filepath) { - super(startOffset, length); - this.flags = flags; - this.filepath = filepath; - } - - public boolean isForcedUtf8Encoding() { - return StringFlags.isForcedUtf8Encoding(flags); - } - - public boolean isForcedBinaryEncoding() { - return StringFlags.isForcedBinaryEncoding(flags); - } - - public boolean isFrozen() { - return StringFlags.isFrozen(flags); - } - - public boolean isMutable() { - return StringFlags.isMutable(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitSourceFileNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("StringFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("filepath: "); - builder.append('"' + asString(this.filepath) + '"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `__LINE__` keyword.
-     *
-     *     __LINE__
-     *     ^^^^^^^^
-     * 
- */ - public static final class SourceLineNode extends Node { - - public SourceLineNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitSourceLineNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the splat operator.
-     *
-     *     [*a]
-     *      ^^
-     * 
- */ - public static final class SplatNode extends Node { - @Nullable - public final Node expression; - - public SplatNode(int startOffset, int length, Node expression) { - super(startOffset, length); - this.expression = expression; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.expression != null) { - this.expression.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.expression }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitSplatNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("expression: "); - builder.append(this.expression == null ? "null\n" : this.expression.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a set of statements contained within some scope.
-     *
-     *     foo; bar; baz
-     *     ^^^^^^^^^^^^^
-     * 
- */ - public static final class StatementsNode extends Node { - public final Node[] body; - - public StatementsNode(int startOffset, int length, Node[] body) { - super(startOffset, length); - this.body = body; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.body) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.body)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitStatementsNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("body: "); - builder.append('\n'); - for (Node child : this.body) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents a string literal, a string contained within a `%w` list, or plain string content within an interpolated string.
-     *
-     *     "foo"
-     *     ^^^^^
-     *
-     *     %w[foo]
-     *        ^^^
-     *
-     *     "foo #{bar} baz"
-     *      ^^^^      ^^^^
-     * 
- */ - public static final class StringNode extends Node { - public final short flags; - public final byte[] unescaped; - - public StringNode(int startOffset, int length, short flags, byte[] unescaped) { - super(startOffset, length); - this.flags = flags; - this.unescaped = unescaped; - } - - public boolean isForcedUtf8Encoding() { - return StringFlags.isForcedUtf8Encoding(flags); - } - - public boolean isForcedBinaryEncoding() { - return StringFlags.isForcedBinaryEncoding(flags); - } - - public boolean isFrozen() { - return StringFlags.isFrozen(flags); - } - - public boolean isMutable() { - return StringFlags.isMutable(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitStringNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("StringFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("unescaped: "); - builder.append('"' + asString(this.unescaped) + '"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `super` keyword with parentheses or arguments.
-     *
-     *     super()
-     *     ^^^^^^^
-     *
-     *     super foo, bar
-     *     ^^^^^^^^^^^^^^
-     *
-     * If no arguments are provided (except for a block), it would be a `ForwardingSuperNode` instead.
-     * 
- */ - public static final class SuperNode extends Node { - /** - *
-         * Can be only `nil` when there are empty parentheses, like `super()`.
-         * 
- */ - @Nullable - public final ArgumentsNode arguments; - @Nullable - @UnionType({ BlockNode.class, BlockArgumentNode.class }) - public final Node block; - - public SuperNode(int startOffset, int length, ArgumentsNode arguments, Node block) { - super(startOffset, length); - this.arguments = arguments; - this.block = block; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.arguments != null) { - this.arguments.accept(visitor); - } - if (this.block != null) { - this.block.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.arguments, this.block }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitSuperNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("arguments: "); - builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); - builder.append(nextIndent); - builder.append("block: "); - builder.append(this.block == null ? "null\n" : this.block.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents a symbol literal or a symbol contained within a `%i` list.
-     *
-     *     :foo
-     *     ^^^^
-     *
-     *     %i[foo]
-     *        ^^^
-     * 
- */ - public static final class SymbolNode extends Node { - public final short flags; - public final byte[] unescaped; - - public SymbolNode(int startOffset, int length, short flags, byte[] unescaped) { - super(startOffset, length); - this.flags = flags; - this.unescaped = unescaped; - } - - public boolean isForcedUtf8Encoding() { - return SymbolFlags.isForcedUtf8Encoding(flags); - } - - public boolean isForcedBinaryEncoding() { - return SymbolFlags.isForcedBinaryEncoding(flags); - } - - public boolean isForcedUsAsciiEncoding() { - return SymbolFlags.isForcedUsAsciiEncoding(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitSymbolNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("SymbolFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("unescaped: "); - builder.append('"' + asString(this.unescaped) + '"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the literal `true` keyword.
-     *
-     *     true
-     *     ^^^^
-     * 
- */ - public static final class TrueNode extends Node { - - public TrueNode(int startOffset, int length) { - super(startOffset, length); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitTrueNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `undef` keyword.
-     *
-     *     undef :foo, :bar, :baz
-     *     ^^^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class UndefNode extends Node { - @UnionType({ SymbolNode.class, InterpolatedSymbolNode.class }) - public final Node[] names; - - public UndefNode(int startOffset, int length, Node[] names) { - super(startOffset, length); - this.names = names; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.names) { - child.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.names)); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitUndefNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("names: "); - builder.append('\n'); - for (Node child : this.names) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `unless` keyword, either in the block form or the modifier form.
-     *
-     *     bar unless foo
-     *     ^^^^^^^^^^^^^^
-     *
-     *     unless foo then bar end
-     *     ^^^^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class UnlessNode extends Node { - /** - *
-         * The condition to be evaluated for the unless expression. It can be any [non-void expression](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
-         *
-         *     unless cond then bar end
-         *            ^^^^
-         *
-         *     bar unless cond
-         *                ^^^^
-         * 
- */ - public final Node predicate; - /** - *
-         * The body of statements that will executed if the unless condition is
-         * falsey. Will be `nil` if no body is provided.
-         *
-         *     unless cond then bar end
-         *                      ^^^
-         * 
- */ - @Nullable - public final StatementsNode statements; - /** - *
-         * The else clause of the unless expression, if present.
-         *
-         *     unless cond then bar else baz end
-         *                          ^^^^^^^^^^^^
-         * 
- */ - @Nullable - public final ElseNode else_clause; - - public UnlessNode(int startOffset, int length, Node predicate, StatementsNode statements, ElseNode else_clause) { - super(startOffset, length); - this.predicate = predicate; - this.statements = statements; - this.else_clause = else_clause; - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - this.predicate.setNewLineFlag(source, newlineMarked); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.predicate.accept(visitor); - if (this.statements != null) { - this.statements.accept(visitor); - } - if (this.else_clause != null) { - this.else_clause.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.predicate, this.statements, this.else_clause }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitUnlessNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("predicate: "); - builder.append(this.predicate.toString(nextIndent)); - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - builder.append(nextIndent); - builder.append("else_clause: "); - builder.append(this.else_clause == null ? "null\n" : this.else_clause.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `until` keyword, either in the block form or the modifier form.
-     *
-     *     bar until foo
-     *     ^^^^^^^^^^^^^
-     *
-     *     until foo do bar end
-     *     ^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class UntilNode extends Node { - public final short flags; - public final Node predicate; - @Nullable - public final StatementsNode statements; - - public UntilNode(int startOffset, int length, short flags, Node predicate, StatementsNode statements) { - super(startOffset, length); - this.flags = flags; - this.predicate = predicate; - this.statements = statements; - } - - public boolean isBeginModifier() { - return LoopFlags.isBeginModifier(flags); - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - this.predicate.setNewLineFlag(source, newlineMarked); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.predicate.accept(visitor); - if (this.statements != null) { - this.statements.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.predicate, this.statements }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitUntilNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("LoopFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("predicate: "); - builder.append(this.predicate.toString(nextIndent)); - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `when` keyword within a case statement.
-     *
-     *     case true
-     *     when true
-     *     ^^^^^^^^^
-     *     end
-     * 
- */ - public static final class WhenNode extends Node { - public final Node[] conditions; - @Nullable - public final StatementsNode statements; - - public WhenNode(int startOffset, int length, Node[] conditions, StatementsNode statements) { - super(startOffset, length); - this.conditions = conditions; - this.statements = statements; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - for (Nodes.Node child : this.conditions) { - child.accept(visitor); - } - if (this.statements != null) { - this.statements.accept(visitor); - } - } - - public Node[] childNodes() { - ArrayList childNodes = new ArrayList<>(); - childNodes.addAll(Arrays.asList(this.conditions)); - childNodes.add(this.statements); - return childNodes.toArray(EMPTY_ARRAY); - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitWhenNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - String nextNextIndent = nextIndent + " "; - builder.append(nextIndent); - builder.append("conditions: "); - builder.append('\n'); - for (Node child : this.conditions) { - builder.append(nextNextIndent).append(child.toString(nextNextIndent)); - } - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `while` keyword, either in the block form or the modifier form.
-     *
-     *     bar while foo
-     *     ^^^^^^^^^^^^^
-     *
-     *     while foo do bar end
-     *     ^^^^^^^^^^^^^^^^^^^^
-     * 
- */ - public static final class WhileNode extends Node { - public final short flags; - public final Node predicate; - @Nullable - public final StatementsNode statements; - - public WhileNode(int startOffset, int length, short flags, Node predicate, StatementsNode statements) { - super(startOffset, length); - this.flags = flags; - this.predicate = predicate; - this.statements = statements; - } - - public boolean isBeginModifier() { - return LoopFlags.isBeginModifier(flags); - } - - @Override - public void setNewLineFlag(Source source, boolean[] newlineMarked) { - this.predicate.setNewLineFlag(source, newlineMarked); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - this.predicate.accept(visitor); - if (this.statements != null) { - this.statements.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.predicate, this.statements }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitWhileNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("LoopFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("predicate: "); - builder.append(this.predicate.toString(nextIndent)); - builder.append(nextIndent); - builder.append("statements: "); - builder.append(this.statements == null ? "null\n" : this.statements.toString(nextIndent)); - return builder.toString(); - } - } - - /** - *
-     * Represents an xstring literal with no interpolation.
-     *
-     *     `foo`
-     *     ^^^^^
-     * 
- */ - public static final class XStringNode extends Node { - public final short flags; - public final byte[] unescaped; - - public XStringNode(int startOffset, int length, short flags, byte[] unescaped) { - super(startOffset, length); - this.flags = flags; - this.unescaped = unescaped; - } - - public boolean isForcedUtf8Encoding() { - return EncodingFlags.isForcedUtf8Encoding(flags); - } - - public boolean isForcedBinaryEncoding() { - return EncodingFlags.isForcedBinaryEncoding(flags); - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - } - - public Node[] childNodes() { - return EMPTY_ARRAY; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitXStringNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("EncodingFlags: "); - builder.append(flags); - builder.append('\n'); - builder.append(nextIndent); - builder.append("unescaped: "); - builder.append('"' + asString(this.unescaped) + '"'); - builder.append('\n'); - return builder.toString(); - } - } - - /** - *
-     * Represents the use of the `yield` keyword.
-     *
-     *     yield 1
-     *     ^^^^^^^
-     * 
- */ - public static final class YieldNode extends Node { - @Nullable - public final ArgumentsNode arguments; - - public YieldNode(int startOffset, int length, ArgumentsNode arguments) { - super(startOffset, length); - this.arguments = arguments; - } - - public void visitChildNodes(AbstractNodeVisitor visitor) { - if (this.arguments != null) { - this.arguments.accept(visitor); - } - } - - public Node[] childNodes() { - return new Node[] { this.arguments }; - } - - public T accept(AbstractNodeVisitor visitor) { - return visitor.visitYieldNode(this); - } - - @Override - protected String toString(String indent) { - StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - if (hasNewLineFlag()) { - builder.append("[Li]"); - } - builder.append('\n'); - String nextIndent = indent + " "; - builder.append(nextIndent); - builder.append("arguments: "); - builder.append(this.arguments == null ? "null\n" : this.arguments.toString(nextIndent)); - return builder.toString(); - } - } - - public enum ErrorType { - ALIAS_ARGUMENT, - ALIAS_ARGUMENT_NUMBERED_REFERENCE, - AMPAMPEQ_MULTI_ASSIGN, - ARGUMENT_AFTER_BLOCK, - ARGUMENT_AFTER_FORWARDING_ELLIPSES, - ARGUMENT_BARE_HASH, - ARGUMENT_BLOCK_FORWARDING, - ARGUMENT_BLOCK_MULTI, - ARGUMENT_CONFLICT_AMPERSAND, - ARGUMENT_CONFLICT_STAR, - ARGUMENT_CONFLICT_STAR_STAR, - ARGUMENT_FORMAL_CLASS, - ARGUMENT_FORMAL_CONSTANT, - ARGUMENT_FORMAL_GLOBAL, - ARGUMENT_FORMAL_IVAR, - ARGUMENT_FORWARDING_UNBOUND, - ARGUMENT_NO_FORWARDING_AMPERSAND, - ARGUMENT_NO_FORWARDING_ELLIPSES, - ARGUMENT_NO_FORWARDING_ELLIPSES_LAMBDA, - ARGUMENT_NO_FORWARDING_ELLIPSES_BLOCK, - ARGUMENT_NO_FORWARDING_STAR, - ARGUMENT_NO_FORWARDING_STAR_STAR, - ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT, - ARGUMENT_SPLAT_AFTER_SPLAT, - ARGUMENT_TERM_PAREN, - ARGUMENT_UNEXPECTED_BLOCK, - ARRAY_ELEMENT, - ARRAY_EXPRESSION, - ARRAY_EXPRESSION_AFTER_STAR, - ARRAY_SEPARATOR, - ARRAY_TERM, - BEGIN_LONELY_ELSE, - BEGIN_TERM, - BEGIN_UPCASE_BRACE, - BEGIN_UPCASE_TERM, - BEGIN_UPCASE_TOPLEVEL, - BLOCK_PARAM_LOCAL_VARIABLE, - BLOCK_PARAM_PIPE_TERM, - BLOCK_TERM_BRACE, - BLOCK_TERM_END, - CANNOT_PARSE_EXPRESSION, - CANNOT_PARSE_STRING_PART, - CASE_EXPRESSION_AFTER_CASE, - CASE_EXPRESSION_AFTER_WHEN, - CASE_MATCH_MISSING_PREDICATE, - CASE_MISSING_CONDITIONS, - CASE_TERM, - CLASS_IN_METHOD, - CLASS_NAME, - CLASS_SUPERCLASS, - CLASS_TERM, - CLASS_UNEXPECTED_END, - CLASS_VARIABLE_BARE, - CONDITIONAL_ELSIF_PREDICATE, - CONDITIONAL_IF_PREDICATE, - CONDITIONAL_PREDICATE_TERM, - CONDITIONAL_TERM, - CONDITIONAL_TERM_ELSE, - CONDITIONAL_UNLESS_PREDICATE, - CONDITIONAL_UNTIL_PREDICATE, - CONDITIONAL_WHILE_PREDICATE, - CONSTANT_PATH_COLON_COLON_CONSTANT, - DEF_ENDLESS, - DEF_ENDLESS_PARAMETERS, - DEF_ENDLESS_SETTER, - DEF_ENDLESS_DO_BLOCK, - DEF_NAME, - DEF_PARAMS_TERM, - DEF_PARAMS_TERM_PAREN, - DEF_RECEIVER, - DEF_RECEIVER_TERM, - DEF_TERM, - DEFINED_EXPRESSION, - EMBDOC_TERM, - EMBEXPR_END, - EMBVAR_INVALID, - END_UPCASE_BRACE, - END_UPCASE_TERM, - ESCAPE_INVALID_CONTROL, - ESCAPE_INVALID_CONTROL_REPEAT, - ESCAPE_INVALID_HEXADECIMAL, - ESCAPE_INVALID_META, - ESCAPE_INVALID_META_REPEAT, - ESCAPE_INVALID_UNICODE, - ESCAPE_INVALID_UNICODE_CM_FLAGS, - ESCAPE_INVALID_UNICODE_LIST, - ESCAPE_INVALID_UNICODE_LITERAL, - ESCAPE_INVALID_UNICODE_LONG, - ESCAPE_INVALID_UNICODE_SHORT, - ESCAPE_INVALID_UNICODE_TERM, - EXPECT_ARGUMENT, - EXPECT_EOL_AFTER_STATEMENT, - EXPECT_EXPRESSION_AFTER_AMPAMPEQ, - EXPECT_EXPRESSION_AFTER_COMMA, - EXPECT_EXPRESSION_AFTER_EQUAL, - EXPECT_EXPRESSION_AFTER_LESS_LESS, - EXPECT_EXPRESSION_AFTER_LPAREN, - EXPECT_EXPRESSION_AFTER_OPERATOR, - EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ, - EXPECT_EXPRESSION_AFTER_QUESTION, - EXPECT_EXPRESSION_AFTER_SPLAT, - EXPECT_EXPRESSION_AFTER_SPLAT_HASH, - EXPECT_EXPRESSION_AFTER_STAR, - EXPECT_FOR_DELIMITER, - EXPECT_IDENT_REQ_PARAMETER, - EXPECT_IN_DELIMITER, - EXPECT_LPAREN_AFTER_NOT_LPAREN, - EXPECT_LPAREN_AFTER_NOT_OTHER, - EXPECT_LPAREN_REQ_PARAMETER, - EXPECT_MESSAGE, - EXPECT_RBRACKET, - EXPECT_RPAREN, - EXPECT_RPAREN_AFTER_MULTI, - EXPECT_RPAREN_REQ_PARAMETER, - EXPECT_SINGLETON_CLASS_DELIMITER, - EXPECT_STRING_CONTENT, - EXPECT_WHEN_DELIMITER, - EXPRESSION_BARE_HASH, - EXPRESSION_NOT_WRITABLE, - EXPRESSION_NOT_WRITABLE_ENCODING, - EXPRESSION_NOT_WRITABLE_FALSE, - EXPRESSION_NOT_WRITABLE_FILE, - EXPRESSION_NOT_WRITABLE_LINE, - EXPRESSION_NOT_WRITABLE_NIL, - EXPRESSION_NOT_WRITABLE_NUMBERED, - EXPRESSION_NOT_WRITABLE_SELF, - EXPRESSION_NOT_WRITABLE_TRUE, - FLOAT_PARSE, - FOR_COLLECTION, - FOR_IN, - FOR_INDEX, - FOR_TERM, - GLOBAL_VARIABLE_BARE, - HASH_EXPRESSION_AFTER_LABEL, - HASH_KEY, - HASH_ROCKET, - HASH_TERM, - HASH_VALUE, - HEREDOC_IDENTIFIER, - HEREDOC_TERM, - INCOMPLETE_QUESTION_MARK, - INCOMPLETE_VARIABLE_CLASS, - INCOMPLETE_VARIABLE_CLASS_3_3, - INCOMPLETE_VARIABLE_INSTANCE, - INCOMPLETE_VARIABLE_INSTANCE_3_3, - INSTANCE_VARIABLE_BARE, - INVALID_BLOCK_EXIT, - INVALID_CHARACTER, - INVALID_COMMA, - INVALID_ENCODING_MAGIC_COMMENT, - INVALID_ESCAPE_CHARACTER, - INVALID_FLOAT_EXPONENT, - INVALID_LOCAL_VARIABLE_READ, - INVALID_LOCAL_VARIABLE_WRITE, - INVALID_MULTIBYTE_CHAR, - INVALID_MULTIBYTE_CHARACTER, - INVALID_MULTIBYTE_ESCAPE, - INVALID_NUMBER_BINARY, - INVALID_NUMBER_DECIMAL, - INVALID_NUMBER_FRACTION, - INVALID_NUMBER_HEXADECIMAL, - INVALID_NUMBER_OCTAL, - INVALID_NUMBER_UNDERSCORE_INNER, - INVALID_NUMBER_UNDERSCORE_TRAILING, - INVALID_PERCENT, - INVALID_PERCENT_EOF, - INVALID_PRINTABLE_CHARACTER, - INVALID_RETRY_AFTER_ELSE, - INVALID_RETRY_AFTER_ENSURE, - INVALID_RETRY_WITHOUT_RESCUE, - INVALID_SYMBOL, - INVALID_VARIABLE_GLOBAL, - INVALID_VARIABLE_GLOBAL_3_3, - INVALID_YIELD, - IT_NOT_ALLOWED_NUMBERED, - IT_NOT_ALLOWED_ORDINARY, - LAMBDA_OPEN, - LAMBDA_TERM_BRACE, - LAMBDA_TERM_END, - LIST_I_LOWER_ELEMENT, - LIST_I_LOWER_TERM, - LIST_I_UPPER_ELEMENT, - LIST_I_UPPER_TERM, - LIST_W_LOWER_ELEMENT, - LIST_W_LOWER_TERM, - LIST_W_UPPER_ELEMENT, - LIST_W_UPPER_TERM, - MALLOC_FAILED, - MIXED_ENCODING, - MODULE_IN_METHOD, - MODULE_NAME, - MODULE_TERM, - MULTI_ASSIGN_MULTI_SPLATS, - MULTI_ASSIGN_UNEXPECTED_REST, - NESTING_TOO_DEEP, - NO_LOCAL_VARIABLE, - NON_ASSOCIATIVE_OPERATOR, - NOT_EXPRESSION, - NUMBER_LITERAL_UNDERSCORE, - NUMBERED_PARAMETER_INNER_BLOCK, - NUMBERED_PARAMETER_IT, - NUMBERED_PARAMETER_ORDINARY, - NUMBERED_PARAMETER_OUTER_BLOCK, - OPERATOR_MULTI_ASSIGN, - OPERATOR_WRITE_ARGUMENTS, - OPERATOR_WRITE_BLOCK, - PARAMETER_ASSOC_SPLAT_MULTI, - PARAMETER_BLOCK_MULTI, - PARAMETER_CIRCULAR, - PARAMETER_FORWARDING_AFTER_REST, - PARAMETER_METHOD_NAME, - PARAMETER_NAME_DUPLICATED, - PARAMETER_NO_DEFAULT, - PARAMETER_NO_DEFAULT_KW, - PARAMETER_NUMBERED_RESERVED, - PARAMETER_ORDER, - PARAMETER_SPLAT_MULTI, - PARAMETER_STAR, - PARAMETER_UNEXPECTED_FWD, - PARAMETER_UNEXPECTED_NO_KW, - PARAMETER_WILD_LOOSE_COMMA, - PATTERN_ARRAY_MULTIPLE_RESTS, - PATTERN_CAPTURE_DUPLICATE, - PATTERN_CAPTURE_IN_ALTERNATIVE, - PATTERN_EXPRESSION_AFTER_BRACKET, - PATTERN_EXPRESSION_AFTER_COMMA, - PATTERN_EXPRESSION_AFTER_HROCKET, - PATTERN_EXPRESSION_AFTER_IN, - PATTERN_EXPRESSION_AFTER_KEY, - PATTERN_EXPRESSION_AFTER_PAREN, - PATTERN_EXPRESSION_AFTER_PIN, - PATTERN_EXPRESSION_AFTER_PIPE, - PATTERN_EXPRESSION_AFTER_RANGE, - PATTERN_EXPRESSION_AFTER_REST, - PATTERN_FIND_MISSING_INNER, - PATTERN_HASH_IMPLICIT, - PATTERN_HASH_KEY, - PATTERN_HASH_KEY_DUPLICATE, - PATTERN_HASH_KEY_INTERPOLATED, - PATTERN_HASH_KEY_LABEL, - PATTERN_HASH_KEY_LOCALS, - PATTERN_IDENT_AFTER_HROCKET, - PATTERN_LABEL_AFTER_COMMA, - PATTERN_REST, - PATTERN_TERM_BRACE, - PATTERN_TERM_BRACKET, - PATTERN_TERM_PAREN, - PIPEPIPEEQ_MULTI_ASSIGN, - REGEXP_ENCODING_OPTION_MISMATCH, - REGEXP_ESCAPED_NON_ASCII_IN_UTF8, - REGEXP_INCOMPAT_CHAR_ENCODING, - REGEXP_INVALID_CHAR_PROPERTY, - REGEXP_INVALID_UNICODE_RANGE, - REGEXP_NON_ESCAPED_MBC, - REGEXP_PARSE_ERROR, - REGEXP_TERM, - REGEXP_UNKNOWN_OPTIONS, - REGEXP_UTF8_CHAR_NON_UTF8_REGEXP, - RESCUE_EXPRESSION, - RESCUE_MODIFIER_VALUE, - RESCUE_TERM, - RESCUE_VARIABLE, - RETURN_INVALID, - SCRIPT_NOT_FOUND, - SINGLETON_FOR_LITERALS, - STATEMENT_ALIAS, - STATEMENT_POSTEXE_END, - STATEMENT_PREEXE_BEGIN, - STATEMENT_UNDEF, - STRING_CONCATENATION, - STRING_INTERPOLATED_TERM, - STRING_LITERAL_EOF, - STRING_LITERAL_TERM, - SYMBOL_INVALID, - SYMBOL_TERM_DYNAMIC, - SYMBOL_TERM_INTERPOLATED, - TERNARY_COLON, - TERNARY_EXPRESSION_FALSE, - TERNARY_EXPRESSION_TRUE, - UNARY_DISALLOWED, - UNARY_RECEIVER, - UNDEF_ARGUMENT, - UNEXPECTED_BLOCK_ARGUMENT, - UNEXPECTED_INDEX_BLOCK, - UNEXPECTED_INDEX_KEYWORDS, - UNEXPECTED_LABEL, - UNEXPECTED_MULTI_WRITE, - UNEXPECTED_PARAMETER_DEFAULT_VALUE, - UNEXPECTED_RANGE_OPERATOR, - UNEXPECTED_SAFE_NAVIGATION, - UNEXPECTED_TOKEN_CLOSE_CONTEXT, - UNEXPECTED_TOKEN_IGNORE, - UNTIL_TERM, - VOID_EXPRESSION, - WHILE_TERM, - WRITE_TARGET_IN_METHOD, - WRITE_TARGET_READONLY, - WRITE_TARGET_UNEXPECTED, - XSTRING_TERM, - } - - public static ErrorType[] ERROR_TYPES = ErrorType.values(); - - public enum WarningType { - AMBIGUOUS_BINARY_OPERATOR, - AMBIGUOUS_FIRST_ARGUMENT_MINUS, - AMBIGUOUS_FIRST_ARGUMENT_PLUS, - AMBIGUOUS_PREFIX_AMPERSAND, - AMBIGUOUS_PREFIX_STAR, - AMBIGUOUS_PREFIX_STAR_STAR, - AMBIGUOUS_SLASH, - COMPARISON_AFTER_COMPARISON, - DOT_DOT_DOT_EOL, - EQUAL_IN_CONDITIONAL, - EQUAL_IN_CONDITIONAL_3_3, - END_IN_METHOD, - DUPLICATED_HASH_KEY, - DUPLICATED_WHEN_CLAUSE, - FLOAT_OUT_OF_RANGE, - IGNORED_FROZEN_STRING_LITERAL, - INDENTATION_MISMATCH, - INTEGER_IN_FLIP_FLOP, - INVALID_CHARACTER, - INVALID_MAGIC_COMMENT_VALUE, - INVALID_NUMBERED_REFERENCE, - KEYWORD_EOL, - LITERAL_IN_CONDITION_DEFAULT, - LITERAL_IN_CONDITION_VERBOSE, - SHAREABLE_CONSTANT_VALUE_LINE, - SHEBANG_CARRIAGE_RETURN, - UNEXPECTED_CARRIAGE_RETURN, - UNREACHABLE_STATEMENT, - UNUSED_LOCAL_VARIABLE, - VOID_STATEMENT, - } - - public static WarningType[] WARNING_TYPES = WarningType.values(); -} -// @formatter:on diff --git a/templates/java/org/ruby_lang/prism/AbstractNodeVisitor.java.erb b/templates/java/api/target/generated-sources/java/org/ruby_lang/prism/AbstractNodeVisitor.java.erb similarity index 100% rename from templates/java/org/ruby_lang/prism/AbstractNodeVisitor.java.erb rename to templates/java/api/target/generated-sources/java/org/ruby_lang/prism/AbstractNodeVisitor.java.erb diff --git a/templates/java/org/ruby_lang/prism/Loader.java.erb b/templates/java/api/target/generated-sources/java/org/ruby_lang/prism/Loader.java.erb similarity index 100% rename from templates/java/org/ruby_lang/prism/Loader.java.erb rename to templates/java/api/target/generated-sources/java/org/ruby_lang/prism/Loader.java.erb diff --git a/templates/java/org/ruby_lang/prism/Nodes.java.erb b/templates/java/api/target/generated-sources/java/org/ruby_lang/prism/Nodes.java.erb similarity index 100% rename from templates/java/org/ruby_lang/prism/Nodes.java.erb rename to templates/java/api/target/generated-sources/java/org/ruby_lang/prism/Nodes.java.erb diff --git a/templates/template.rb b/templates/template.rb index c455b36d03..9ab3ab4048 100755 --- a/templates/template.rb +++ b/templates/template.rb @@ -688,9 +688,9 @@ def locals "javascript/src/deserialize.js", "javascript/src/nodes.js", "javascript/src/visitor.js", - "java/api/src/main/java/org/ruby_lang/prism/Loader.java", - "java/api/src/main/java/org/ruby_lang/prism/Nodes.java", - "java/api/src/main/java/org/ruby_lang/prism/AbstractNodeVisitor.java", + "java/api/target/generated-sources/java/org/ruby_lang/prism/Loader.java", + "java/api/target/generated-sources/java/org/ruby_lang/prism/Nodes.java", + "java/api/target/generated-sources/java/org/ruby_lang/prism/AbstractNodeVisitor.java", "lib/prism/compiler.rb", "lib/prism/dispatcher.rb", "lib/prism/dot_visitor.rb", From 2df7c97173384845ec344b996b10d2a632a74eb7 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 23 Mar 2026 15:15:44 -0500 Subject: [PATCH 3/9] Fix up references to the old project structure --- .github/workflows/documentation.yml | 2 +- .github/workflows/github-pages.yml | 2 +- .github/workflows/java-wasm-bindings.yml | 10 +++++++--- docs/configuration.md | 6 +++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index e3fc52303c..c9f7606ebe 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -37,7 +37,7 @@ jobs: run: doxygen Doxyfile - name: Check Java coverage run: javadoc -Xdoclint:all,-missing -d ../doc/java -subpackages * - working-directory: java + working-directory: java/api - name: Generate Rust documentation run: | bundle exec rake cargo:build diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index 217af4a47b..45a5418bb7 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -52,7 +52,7 @@ jobs: run: doxygen Doxyfile - name: Build with JavaDoc run: javadoc -Xdoclint:all,-missing -d ../doc/java -subpackages * - working-directory: java + working-directory: java/api - name: Build with rustdoc run: | bundle exec rake cargo:build diff --git a/.github/workflows/java-wasm-bindings.yml b/.github/workflows/java-wasm-bindings.yml index 352c1f7b4d..1f9434d230 100644 --- a/.github/workflows/java-wasm-bindings.yml +++ b/.github/workflows/java-wasm-bindings.yml @@ -44,9 +44,13 @@ jobs: java-version: '21' cache: maven - - name: Run the tests - run: mvn -B install - working-directory: java/wasm + - name: Build the Java artifacts + run: mvn install + working-directory: java + + - name: Run the tests from the WASM module + run: mvn -pl wasm test + working-directory: java - uses: actions/upload-artifact@v7 with: diff --git a/docs/configuration.md b/docs/configuration.md index 30001b7db7..4b23b7f46d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -8,9 +8,9 @@ A lot of code in prism's repository is templated from a single configuration fil * `include/prism/node_new.h` - for defining the functions that create the nodes in C * `javascript/src/deserialize.js` - for defining how to deserialize the nodes in JavaScript * `javascript/src/nodes.js` - for defining the nodes in JavaScript -* `java/org/ruby_lang/prism/AbstractNodeVisitor.java` - for defining the visitor interface for the nodes in Java -* `java/org/ruby_lang/prism/Loader.java` - for defining how to deserialize the nodes in Java -* `java/org/ruby_lang/prism/Nodes.java` - for defining the nodes in Java +* `java/api/target/generated-sources/java/org/ruby_lang/prism/AbstractNodeVisitor.java` - for defining the visitor interface for the nodes in Java +* `java/api/target/generated-sources/java/org/ruby_lang/prism/Loader.java` - for defining how to deserialize the nodes in Java +* `java/api/target/generated-sources/java/org/ruby_lang/prism/Nodes.java` - for defining the nodes in Java * `lib/prism/compiler.rb` - for defining the compiler for the nodes in Ruby * `lib/prism/dispatcher.rb` - for defining the dispatch visitors for the nodes in Ruby * `lib/prism/dot_visitor.rb` - for defining the dot visitor for the nodes in Ruby From 198338333337a860e49bccf45f74654d8b89a21d Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 23 Mar 2026 15:37:01 -0500 Subject: [PATCH 4/9] Fix documentation job for new layout --- .github/workflows/documentation.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index c9f7606ebe..29cff1cc36 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -35,9 +35,16 @@ jobs: run: bundle exec rake rdoc:coverage - name: Check C coverage run: doxygen Doxyfile + + - name: Set up Java + uses: actions/setup-java@v5 + with: + distribution: 'temurin' + java-version: '21' + cache: maven - name: Check Java coverage - run: javadoc -Xdoclint:all,-missing -d ../doc/java -subpackages * - working-directory: java/api + run: mvn -f java/pom.xml -pl api -pl native install + - name: Generate Rust documentation run: | bundle exec rake cargo:build From 2ea5d59c33c78d8c8c42be6d30b6f3bbeda4a41a Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 23 Mar 2026 17:19:05 -0500 Subject: [PATCH 5/9] Back off Maven template run and build from Rake There's a lot of chicken-and-egg issues with trying to have Maven do all the steps for the Java artifact builds right now, so back off and require that templates (and WASM) are generated before the Maven builds of the relevant modules. --- Rakefile | 2 +- java/api/pom.xml | 65 +----------------------------------------------- 2 files changed, 2 insertions(+), 65 deletions(-) diff --git a/Rakefile b/Rakefile index e6a86cdb15..eb96249985 100644 --- a/Rakefile +++ b/Rakefile @@ -43,7 +43,7 @@ elsif RUBY_ENGINE == "jruby" # This compiles java to make sure any templating changes produces valid code. Rake::JavaExtensionTask.new(:compile) do |ext| ext.name = "prism" - ext.ext_dir = "java" + ext.ext_dir = "java/api" ext.lib_dir = "tmp" ext.release = "21" ext.gem_spec = Gem::Specification.load("prism.gemspec") diff --git a/java/api/pom.xml b/java/api/pom.xml index 844312d519..6b3bd6d3a8 100644 --- a/java/api/pom.xml +++ b/java/api/pom.xml @@ -9,17 +9,10 @@ prism-parser-api - Java Prism API + Java Prism Java API for the Prism Ruby language parser https://github.com/ruby/prism - - - mavengems - mavengem:https://rubygems.org - - - org.ruby-lang @@ -27,66 +20,10 @@ 0.0.2-SNAPSHOT provided - - rubygems - rake - 13.0.3 - gem - - - rubygems - rake-compiler - 1.3.1 - gem - - - - org.jruby.maven - mavengem-wagon - 2.0.2 - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.6.1 - - - add-source - generate-sources - - add-source - - - - target/generated-sources/java - - - - - - - org.jruby.maven - rake-maven-plugin - 3.0.6 - - - generate templated Java sources - generate-sources - - rake - - - ${project.basedir}/../.. - PRISM_EXCLUDE_PRETTYPRINT=1 PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS=1 templates - - - - org.codehaus.mojo templating-maven-plugin From f369cabf7120ca7a03047524a52b1ce5026721ca Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 23 Mar 2026 17:26:34 -0500 Subject: [PATCH 6/9] Fix documentation job for new paths --- .github/workflows/documentation.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 29cff1cc36..5aba27ce9a 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -35,16 +35,8 @@ jobs: run: bundle exec rake rdoc:coverage - name: Check C coverage run: doxygen Doxyfile - - - name: Set up Java - uses: actions/setup-java@v5 - with: - distribution: 'temurin' - java-version: '21' - cache: maven - name: Check Java coverage - run: mvn -f java/pom.xml -pl api -pl native install - + run: javadoc -Xdoclint:all,-missing -d doc/java -sourcepath java/api/target/generated-sources/java/:java/api/src/main/java org.ruby_lang.prism - name: Generate Rust documentation run: | bundle exec rake cargo:build From 32661ee0248ab0f030fc45aa508946da5402b672 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 23 Mar 2026 19:17:34 -0500 Subject: [PATCH 7/9] Re-fix Java build for new layout --- .github/workflows/java-wasm-bindings.yml | 4 ++-- java/api/pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/java-wasm-bindings.yml b/.github/workflows/java-wasm-bindings.yml index 1f9434d230..3f39c7a1d6 100644 --- a/.github/workflows/java-wasm-bindings.yml +++ b/.github/workflows/java-wasm-bindings.yml @@ -45,11 +45,11 @@ jobs: cache: maven - name: Build the Java artifacts - run: mvn install + run: mvn -ntp install working-directory: java - name: Run the tests from the WASM module - run: mvn -pl wasm test + run: mvn -ntp test working-directory: java - uses: actions/upload-artifact@v7 diff --git a/java/api/pom.xml b/java/api/pom.xml index 6b3bd6d3a8..2005f962d6 100644 --- a/java/api/pom.xml +++ b/java/api/pom.xml @@ -69,7 +69,7 @@ - ../java + target/generated-sources/java From d746c2ae9aff58425c4121b65b11f021935cc2c2 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 23 Mar 2026 21:40:25 -0500 Subject: [PATCH 8/9] Clean up Maven build for split artifacts --- java/api/pom.xml | 42 ---------------------------------- java/native/pom.xml | 56 --------------------------------------------- java/pom.xml | 46 ++++++++++++------------------------- 3 files changed, 14 insertions(+), 130 deletions(-) diff --git a/java/api/pom.xml b/java/api/pom.xml index 2005f962d6..043173366c 100644 --- a/java/api/pom.xml +++ b/java/api/pom.xml @@ -13,50 +13,8 @@ Java API for the Prism Ruby language parser https://github.com/ruby/prism - - - org.ruby-lang - prism-parser-native - 0.0.2-SNAPSHOT - provided - - - - - org.codehaus.mojo - templating-maven-plugin - 3.1.0 - - - filtering-java-templates - - filter-sources - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.15.0 - - 21 - - - com.dylibso.chicory - annotations-processor - ${chicory.version} - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.5.5 - org.codehaus.mojo build-helper-maven-plugin diff --git a/java/native/pom.xml b/java/native/pom.xml index 96d6b6e26a..06f866858c 100644 --- a/java/native/pom.xml +++ b/java/native/pom.xml @@ -13,60 +13,4 @@ Java native bindings Prism parser shared library https://github.com/ruby/prism - - - - org.codehaus.mojo - templating-maven-plugin - 3.1.0 - - - filtering-java-templates - - filter-sources - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.15.0 - - 21 - - - com.dylibso.chicory - annotations-processor - ${chicory.version} - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.5.5 - - - org.codehaus.mojo - build-helper-maven-plugin - 3.6.1 - - - generate-sources - - add-source - - - - ../java - - - - - - - - diff --git a/java/pom.xml b/java/pom.xml index 618b48d71c..1085477010 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -45,8 +45,6 @@ UTF-8 21 21 - - 1.7.3 6.0.3 @@ -56,36 +54,6 @@ wasm - - - - org.apache.maven.plugins - maven-gpg-plugin - 3.2.4 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.15.0 - - - org.apache.maven.plugins - maven-source-plugin - 3.4.0 - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.12.0 - - - org.sonatype.central - central-publishing-maven-plugin - 0.7.0 - - - - release @@ -117,8 +85,16 @@ + + maven-compiler-plugin + 3.15.0 + + 21 + + maven-source-plugin + 3.4.0 attach-sources @@ -128,8 +104,14 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.5 + maven-javadoc-plugin + 3.12.0 attach-javadocs From 1f824a884e5ae7aea70a472902da5ff71b403abd Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 23 Mar 2026 21:50:01 -0500 Subject: [PATCH 9/9] Clean up Java readme --- java/README.md | 45 +++++++++++++++++++++++++++++++++++++++++---- java/wasm/README.md | 29 ----------------------------- 2 files changed, 41 insertions(+), 33 deletions(-) delete mode 100644 java/wasm/README.md diff --git a/java/README.md b/java/README.md index b3062cebd2..6380850e00 100644 --- a/java/README.md +++ b/java/README.md @@ -6,20 +6,57 @@ This is the top-level project for the Java API and backend bindings for the Pris * native/ contains a native binding for the Prism shared library * wasm/ contains a Chicory-based WASM build and binding +## Building the Java components + +Some files need to be generated before the Maven artifacts can build: + +### Templated sources + +Sources under `api` are generated from templates in `../templates`. Those sources are generated using the follow command line: + +``` +$ PRISM_EXCLUDE_PRETTYPRINT=1 PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS=1 bundle exec rake templates +``` + +The files go under `api/target/generated-sources/java` and will be removed with `mvn clean`. + +### WASM build of Prism + +The `wasm` project needs a WASM build of Prism to be generated with the following command: + +``` +$ make java-wasm WASI_SDK_PATH= +``` + +The files go under `wasm/target/generated-sources/wasm` and will be removed with `mvn clean`. + +### Build and install + +The projects can be built and installed into a local Maven repository by running the following command: + +``` +$ mvn install +``` + ## Updating versions Run the following command to update all module versions: ``` -mvn versions:set -DnewVersion=1.2.3-SNAPSHOT +$ mvn versions:set -DnewVersion=1.2.3-SNAPSHOT ``` ## Releasing -Snapshots can be deployed with `mvn deploy` while the versions are `-SNAPSHOT`. +Snapshots can be deployed to the Maven snapshot repository while the versions end with `-SNAPSHOT`: -When releasing to Maven Central, all projects should be released together using the `release` profile: +``` +$ mvn deploy +``` + +When releasing to Maven Central, all projects should be released together using the `release` profile, which will use the local default GPG key to sign the packages: ``` -mvn clean deploy -Prelease +$ mvn deploy -Prelease ``` + diff --git a/java/wasm/README.md b/java/wasm/README.md deleted file mode 100644 index 64b42732fc..0000000000 --- a/java/wasm/README.md +++ /dev/null @@ -1,29 +0,0 @@ -This dir contains the chicory-prism artifact, a version of prism compiled to WASM and then AOT compiled to JVM bytecode by the Chicory project. - -## Building - -Generate the templated sources: - -``` -PRISM_EXCLUDE_PRETTYPRINT=1 PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS=1 bundle exec rake templates -``` - -Compile to WASM using WASI SDK version 25: - -``` -make java-wasm WASI_SDK_PATH=.../wasi-sdk-25.0-arm64-macos -``` - -Build the AOT-compiled machine and wrapper library: - -``` -mvn -f java/wasm/pom.xml clean package -``` - -This should build the chicory-wasm jar file and pass some basic tests. - -The jar will be under `java/wasm/target/chicory-prism-#####-SNAPSHOT.jar` or can be installed by using `install` instead of `pacakge` in the `mvn` command line above. - -## Releasing - -Pass `-Prelease` to enable release plugins for Maven Central (optional for snapshots) and run the `deploy` target for `mvn`.