├── .classpath ├── .gitignore ├── .hgignore ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs └── org.eclipse.jdt.ui.prefs ├── MANIFEST.MF ├── README.md ├── Rakefile ├── bin ├── generate_parser ├── optimize_parser.rb └── patch_parser.rb ├── build.xml ├── jruby-parser.gemspec ├── lib ├── jruby-parser.rb ├── jruby-parser │ ├── core_ext │ │ ├── array.rb │ │ ├── attr_assign_node.rb │ │ ├── boolean.rb │ │ ├── call_node.rb │ │ ├── fcall_node.rb │ │ ├── list_node.rb │ │ ├── nil.rb │ │ ├── node.rb │ │ ├── numeric.rb │ │ ├── op_element_asgn_node.rb │ │ ├── string.rb │ │ └── super_node.rb │ ├── util │ │ └── coercer.rb │ └── version.rb └── yydebug.jar ├── nbproject ├── build-impl.xml ├── genfiles.properties ├── private │ ├── config.properties │ └── private.xml ├── project.properties └── project.xml ├── pom.xml ├── sample └── simple.rb ├── spec ├── ast │ ├── node │ │ ├── alias_spec.rb │ │ ├── array_spec.rb │ │ ├── break_spec.rb │ │ ├── call_spec.rb │ │ ├── comments_spec.rb │ │ ├── fcall_spec.rb │ │ ├── find_scopes_spec.rb │ │ ├── get_declaration_spec.rb │ │ ├── get_defined_scope_spec.rb │ │ ├── get_node_at_spec.rb │ │ ├── get_occurences_spec.rb │ │ ├── hash_spec.rb │ │ ├── is_block_parameter_spec.rb │ │ ├── is_method_parameter_spec.rb │ │ ├── multiple_asgn_spec.rb │ │ ├── next_spec.rb │ │ ├── not_spec.rb │ │ ├── op_element_asgn_and_spec.rb │ │ ├── op_element_asgn_or_spec.rb │ │ ├── op_element_asgn_spec.rb │ │ ├── return_spec.rb │ │ ├── vcall_spec.rb │ │ └── while_spec.rb │ └── node_path.rb ├── helpers.rb ├── helpers │ ├── node_helpers.rb │ └── parser_helpers.rb ├── jruby-parser │ ├── find_spec.rb │ ├── parse_spec.rb │ ├── rewriting_spec.rb │ └── static_analysis_spec.rb ├── parser │ ├── alias_spec.rb │ ├── broken_spec.rb │ ├── calls_spec.rb │ └── lambda_spec.rb ├── positions │ ├── arg_spec.rb │ ├── attr_asgn_spec.rb │ ├── conditionals_spec.rb │ ├── heredoc_spec.rb │ ├── name_spec.rb │ ├── op_asgn_or_spec.rb │ └── str_spec.rb └── util │ ├── method_def_visitor_spec.rb │ └── node_diff_spec.rb └── src └── org └── jrubyparser ├── BlockStaticScope.java ├── CompatVersion.java ├── IRubyWarnings.java ├── ISourcePositionHolder.java ├── LocalStaticScope.java ├── NodeVisitor.java ├── Parser.java ├── RegexpOptions.java ├── SourcePosition.java ├── StaticScope.java ├── ast ├── AliasNode.java ├── AndNode.java ├── ArgAuxillaryNode.java ├── ArgsCatNode.java ├── ArgsNode.java ├── ArgsPushNode.java ├── ArgumentNode.java ├── ArrayNode.java ├── AssignableNode.java ├── AttrAssignNode.java ├── BackRefNode.java ├── BareKeywordNode.java ├── BeginNode.java ├── BignumNode.java ├── BinaryOperatorBaseNode.java ├── BinaryOperatorNode.java ├── BlockAcceptingNode.java ├── BlockArg18Node.java ├── BlockArgNode.java ├── BlockNode.java ├── BlockPassNode.java ├── BreakNode.java ├── CallNode.java ├── CaseNode.java ├── ClassNode.java ├── ClassVarAsgnNode.java ├── ClassVarDeclNode.java ├── ClassVarNode.java ├── Colon2ConstNode.java ├── Colon2ImplicitNode.java ├── Colon2MethodNode.java ├── Colon2Node.java ├── Colon3Node.java ├── CommentNode.java ├── ComplexNode.java ├── ConstDeclNode.java ├── ConstNode.java ├── DAsgnNode.java ├── DRegexpNode.java ├── DStrNode.java ├── DSymbolNode.java ├── DVarNode.java ├── DXStrNode.java ├── DefinedNode.java ├── DefnNode.java ├── DefsNode.java ├── DotNode.java ├── EncodingNode.java ├── EnsureNode.java ├── EvStrNode.java ├── FCallNode.java ├── FalseNode.java ├── FileNode.java ├── FixnumNode.java ├── FlipNode.java ├── FloatNode.java ├── ForNode.java ├── GlobalAsgnNode.java ├── GlobalVarNode.java ├── HashNode.java ├── IArgumentNode.java ├── IBlockScope.java ├── IClassVariable.java ├── IGlobalVariable.java ├── IInstanceVariable.java ├── ILiteralNode.java ├── ILocalScope.java ├── ILocalVariable.java ├── IModuleScope.java ├── INameMatchable.java ├── INameNode.java ├── IParameter.java ├── IParameterScope.java ├── IScope.java ├── IScopingNode.java ├── IfNode.java ├── ImplicitNilNode.java ├── InstAsgnNode.java ├── InstVarNode.java ├── IterNode.java ├── KeywordArgNode.java ├── KeywordRestArgNode.java ├── LambdaNode.java ├── ListNode.java ├── LiteralNode.java ├── LocalAsgnNode.java ├── LocalVarNode.java ├── Match2Node.java ├── Match3Node.java ├── MatchNode.java ├── MethodDefNode.java ├── MethodNameNode.java ├── ModuleNode.java ├── MultipleAsgnNode.java ├── NamedNode.java ├── NewlineNode.java ├── NextNode.java ├── NilNode.java ├── Node.java ├── NodeType.java ├── NotNode.java ├── NthRefNode.java ├── NumericNode.java ├── OpAsgnAndNode.java ├── OpAsgnNode.java ├── OpAsgnOrNode.java ├── OpElementAsgnAndNode.java ├── OpElementAsgnNode.java ├── OpElementAsgnOrNode.java ├── OptArgNode.java ├── OrNode.java ├── PostExeNode.java ├── PreExe19Node.java ├── PreExeNode.java ├── RationalNode.java ├── RedoNode.java ├── RegexpNode.java ├── RequiredKeywordArgumentValueNode.java ├── RescueBodyNode.java ├── RescueNode.java ├── RestArgNode.java ├── RetryNode.java ├── ReturnNode.java ├── RootNode.java ├── SClassNode.java ├── SValueNode.java ├── SelfNode.java ├── SplatNode.java ├── StarNode.java ├── StrNode.java ├── SuperNode.java ├── SymbolNode.java ├── SyntaxNode.java ├── ToAryNode.java ├── TrueNode.java ├── TypedArgumentNode.java ├── UnaryCallNode.java ├── UndefNode.java ├── UnnamedRestArgNode.java ├── UntilNode.java ├── VAliasNode.java ├── VCallNode.java ├── WhenNode.java ├── WhileNode.java ├── XStrNode.java ├── YieldNode.java ├── ZArrayNode.java ├── ZSuperNode.java ├── ZYieldNode.java └── ZeroArgNode.java ├── lexer ├── HeredocTerm.java ├── Lexer.java ├── LexerSource.java ├── ReaderLexerSource.java ├── StackState.java ├── StrTerm.java ├── StringTerm.java ├── SyntaxException.java └── Token.java ├── parser ├── ArgsTailHolder.java ├── ParserConfiguration.java ├── ParserResult.java ├── ParserState.java ├── ParserSupport.java ├── ParserSupport19.java ├── ReOptions.java ├── Ruby18Parser.java ├── Ruby18Parser.y ├── Ruby18YyTables.java ├── Ruby19Parser.java ├── Ruby19Parser.y ├── Ruby19YyTables.java ├── Ruby20Parser.java ├── Ruby20Parser.y ├── Ruby20YyTables.java ├── Ruby23Parser.java ├── Ruby23Parser.y ├── Ruby23YyTables.java ├── RubyParser.java ├── Tokens.java ├── YyTables.java └── skeleton.parser ├── rewriter ├── ClassBodyWriter.java ├── DefaultFormatHelper.java ├── FormatHelper.java ├── ReWriteVisitor.java ├── ReWriterFactory.java └── utils │ ├── BooleanStateStack.java │ ├── CallDepth.java │ ├── DRegxReWriteVisitor.java │ ├── HereDocReWriteVisitor.java │ ├── HereDocument.java │ ├── IgnoreCommentsReWriteVisitor.java │ ├── Indenter.java │ ├── LocalVariables.java │ ├── MultipleAssignmentReWriteVisitor.java │ ├── Operators.java │ ├── ReWriterContext.java │ └── ShortIfNodeReWriteVisitor.java └── util ├── CStringBuilder.java ├── IInstanceVariableVisitor.java ├── ILocalVariableVisitor.java ├── MethodDefVisitor.java ├── NodePair.java ├── NoopVisitor.java ├── StaticAnalyzerHelper.java ├── VariableHelper.java └── diff ├── Change.java ├── DeepDiff.java ├── IsJunk.java ├── NodeDiff.java └── SequenceMatcher.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | !.gitignore 2 | build 3 | target 4 | dist 5 | *.orig 6 | *.rej 7 | *~ 8 | nbproject/private 9 | lib/jruby-parser.jar 10 | pkg 11 | .ruby-version -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | 3 | nbproject/ 4 | dist/ 5 | build/ 6 | *~ 7 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jruby-parser 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Implementation-Title: JRuby Parser 2 | Implementation-Version: 0.2 3 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | if !defined? RUBY_ENGINE || RUBY_ENGINE != "jruby" 2 | puts "Rake must be run from JRuby for Ant integration" 3 | exit 1 4 | end 5 | 6 | require 'rspec/core/rake_task' 7 | require 'ant' 8 | require 'bundler' 9 | Bundler::GemHelper.install_tasks 10 | 11 | task :default => [:jar, :frobnicate, :spec] 12 | 13 | task :frobnicate do 14 | root = File.dirname(__FILE__) 15 | cp File.join(root, 'dist', 'JRubyParser.jar'), File.join(root, 'lib', 'jruby-parser.jar') 16 | end 17 | 18 | ant_import # load all ant targets as rake tasks 19 | 20 | desc "Run specs" 21 | RSpec::Core::RakeTask.new do |r| 22 | r.ruby_opts = "-J-ea -Ilib" 23 | end 24 | -------------------------------------------------------------------------------- /bin/generate_parser: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Run from your JRuby home directory....More smarts needed here. 4 | 5 | ###### Change these to tastes ###### 6 | JAY=jay 7 | RUBY=/usr/bin/ruby 8 | PARSER_BASE=DefaultRubyParser 9 | YYTABLE_PREFIX= 10 | DEBUG=true 11 | ###### Do not change below ###### 12 | 13 | if [ "$1" != "" ]; then 14 | PARSER_BASE=$1 15 | fi 16 | shift 17 | 18 | if [ "$1" != "" ]; then 19 | YYTABLE_PREFIX=$1 20 | fi 21 | 22 | if [ "$DEBUG" != "" ]; then 23 | DEBUG_FLAG=-t 24 | # Nonesense...my script-fu is weak 25 | DEBUG_STRIP="xdyhbk" 26 | else 27 | DEBUG_FLAG= 28 | DEBUG_STRIP="^//t" 29 | fi 30 | 31 | echo "Generating Parser '$PARSER_BASE' w/ YYTable prefix of '$YYTABLE_PREFIX'" 32 | 33 | PARSER_DIR=src/org/jrubyparser/parser 34 | 35 | pushd $PARSER_DIR 36 | 37 | # Generate grammar as intermediate file 38 | $JAY $DEBUG_FLAG $PARSER_BASE.y < skeleton.parser | grep -v $DEBUG_STRIP >$PARSER_BASE.out 39 | 40 | # Patch file to get around Java static initialization issues plus extract 41 | # a bunch of stuff to seperate file (yytables). 42 | $RUBY ../../../../bin/patch_parser.rb $PARSER_BASE.out $YYTABLE_PREFIX > $PARSER_BASE.out2 43 | $RUBY ../../../../bin/optimize_parser.rb $PARSER_BASE.out2 $YYTABLE_PREFIX > $PARSER_BASE.java 44 | rm -f $PARSER_BASE.out $PARSER_BASE.out2 45 | 46 | popd 47 | -------------------------------------------------------------------------------- /jruby-parser.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | $:.push File.expand_path("../lib", __FILE__) 3 | require "jruby-parser/version" 4 | 5 | files = `git ls-files -- lib/* spec/* sample/*`.split("\n") 6 | files << 'lib/jruby-parser.jar' 7 | 8 | Gem::Specification.new do |s| 9 | s.name = 'jruby-parser' 10 | s.version = JRubyParser::VERSION 11 | s.platform = Gem::Platform::RUBY 12 | s.authors = 'Thomas E. Enebo' 13 | s.email = 'tom.enebo@gmail.com' 14 | s.homepage = 'http://github.com/jruby/jruby-parser' 15 | s.summary = %q{A Gem for syntactically correct parse trees of Ruby source} 16 | s.description = %q{A Gem for syntactically correct parse trees of Ruby source} 17 | 18 | s.files = files 19 | s.test_files = `git ls-files -- spec/*`.split("\n") 20 | s.require_paths = ["lib"] 21 | end 22 | -------------------------------------------------------------------------------- /lib/jruby-parser.rb: -------------------------------------------------------------------------------- 1 | require 'java' 2 | require 'jruby-parser.jar' 3 | require 'jruby-parser/core_ext/array' 4 | require 'jruby-parser/core_ext/boolean' 5 | require 'jruby-parser/core_ext/nil' 6 | require 'jruby-parser/core_ext/call_node' 7 | require 'jruby-parser/core_ext/fcall_node' 8 | require 'jruby-parser/core_ext/list_node' 9 | require 'jruby-parser/core_ext/node' 10 | require 'jruby-parser/core_ext/numeric' # float,fixnum 11 | require 'jruby-parser/core_ext/op_element_asgn_node' 12 | require 'jruby-parser/core_ext/string' 13 | 14 | module JRubyParser 15 | Compat = org.jrubyparser.CompatVersion 16 | 17 | ## 18 | # Parse source string and return a Abstract Syntax Tree (AST) of the source. 19 | # You may also pass in additional options to affect the reported filename 20 | # and which version of Ruby you want to use: 21 | # 22 | # === Parameters 23 | # * _source_string_ source you want to parse 24 | # * _opts_ customize how your source is parsed (:filename, and :version [defaults to 1.9]) 25 | # === Example 26 | # JRubyParser.parse(%q{puts "hello world"}, :version => JRubyParser::Compat::RUBY1_8) 27 | # 28 | def parse(source_string, opts={}) 29 | filename = opts[:filename] ? opts[:filename] : '(string)' 30 | version = opts[:version] ? opts[:version] : Compat::RUBY1_9 31 | config = org.jrubyparser.parser.ParserConfiguration.new(0, version) 32 | reader = java.io.StringReader.new(source_string) 33 | org.jrubyparser.Parser.new.parse(filename, reader, config) 34 | end 35 | module_function :parse 36 | end 37 | -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/array.rb: -------------------------------------------------------------------------------- 1 | require 'jruby' 2 | 3 | class Array 4 | def to_ast_node(position = nil) 5 | inject(org.jrubyparser.ast.ArrayNode.new(position)) do |array, value| 6 | value = value.to_ast_node if value.respond_to? :to_ast_node 7 | array << value 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/attr_assign_node.rb: -------------------------------------------------------------------------------- 1 | require 'java' 2 | require 'jruby-parser/util/coercer' 3 | 4 | class org::jrubyparser::ast::AttrAssignNode 5 | include JRubyParser::Receiver, JRubyParser::Args 6 | end -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/boolean.rb: -------------------------------------------------------------------------------- 1 | class TrueClass 2 | def to_ast_node(position=nil) 3 | org.jrubyparser.ast.TrueNode.new(position) 4 | end 5 | end 6 | 7 | class FalseClass 8 | def to_ast_node(position=nil) 9 | org.jrubyparser.ast.FalseNode.new(position) 10 | end 11 | end -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/call_node.rb: -------------------------------------------------------------------------------- 1 | require 'java' 2 | require 'jruby-parser/util/coercer' 3 | 4 | class org::jrubyparser::ast::CallNode 5 | include JRubyParser::Receiver, JRubyParser::Value, JRubyParser::Args 6 | end -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/fcall_node.rb: -------------------------------------------------------------------------------- 1 | require 'java' 2 | require 'jruby-parser/util/coercer' 3 | 4 | class org::jrubyparser::ast::FCallNode 5 | include JRubyParser::Args 6 | end 7 | -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/list_node.rb: -------------------------------------------------------------------------------- 1 | require 'java' 2 | require 'jruby-parser/util/coercer' 3 | 4 | class org::jrubyparser::ast::ListNode 5 | def <<(value) 6 | value = value.to_ast_node if value.respond_to? :to_ast_node 7 | value.position = getPosition unless value.position 8 | add(value) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/nil.rb: -------------------------------------------------------------------------------- 1 | require 'java' 2 | 3 | class NilClass 4 | def to_ast_node(position=nil) 5 | org.jrubyparser.ast.NilNode.new(position) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/node.rb: -------------------------------------------------------------------------------- 1 | require 'java' 2 | 3 | class org::jrubyparser::ast::Node 4 | include Enumerable 5 | 6 | ## 7 | # Find nth child element of this node 8 | # 9 | def [](value) 10 | child_nodes[value] 11 | end 12 | 13 | ## 14 | # Replace the nth child element of this node with the specified value. 15 | # if the value is an actual Ruby value it will attempt to call to_ast_node 16 | # on it to do automatic coercion to an AST node. If the node does not 17 | # contain positioning information then it will just use the 18 | # old nodes information 19 | def []=(index, value) 20 | value = value.to_ast_node if value.respond_to? :to_ast_node 21 | 22 | old_value = child_nodes[index] 23 | value.position = old_value.position unless value.position 24 | child_nodes[index] = value 25 | end 26 | 27 | ## 28 | # Find first node by name (which is short_name of actual node) 29 | # === parameters 30 | # * _name_ is the name of the class you want to find 31 | # === examples 32 | # 33 | # root.find(:fcall) # Find first child node of type fcall (depth-first) 34 | # 35 | def find_type(name, &block) 36 | name = name.to_s 37 | return self if name == short_name && (!block_given? || yield(self)) 38 | 39 | child_nodes.each do |child| 40 | value = child.find_type(name, &block) 41 | 42 | return value if value 43 | end 44 | nil 45 | end 46 | alias find_node find_type 47 | 48 | def each(&block) 49 | yield self 50 | child_nodes.each { |child| child.each(&block) } 51 | end 52 | 53 | ## 54 | # Convert this node back to human-readable source code. 55 | # 56 | def to_source(opts = {}) 57 | filename = opts[:filename] ? opts[:filename] : '(string)' 58 | java.io.StringWriter.new.tap do |writer| 59 | accept org.jrubyparser.rewriter.ReWriteVisitor.new(writer, filename) 60 | end.to_s 61 | end 62 | 63 | def short_name 64 | java_class.name.gsub(/(^.*\.|Node$)/, '').downcase 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/numeric.rb: -------------------------------------------------------------------------------- 1 | require 'java' 2 | 3 | class Fixnum 4 | def to_ast_node(position=nil) 5 | org.jrubyparser.ast.FixnumNode.new(position, self) 6 | end 7 | end 8 | 9 | class Float 10 | def to_ast_node(position=nil) 11 | org.jrubyparser.ast.FloatNode.new(position, self) 12 | end 13 | end -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/op_element_asgn_node.rb: -------------------------------------------------------------------------------- 1 | require 'java' 2 | require 'jruby-parser/util/coercer' 3 | 4 | class org::jrubyparser::ast::OpElementAsgnNode 5 | include JRubyParser::Receiver, JRubyParser::Value, JRubyParser::Args 6 | end -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/string.rb: -------------------------------------------------------------------------------- 1 | require 'java' 2 | 3 | class String 4 | def to_ast_node(position=nil) 5 | org.jrubyparser.ast.StrNode.new(position, self.to_java(:string)) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/jruby-parser/core_ext/super_node.rb: -------------------------------------------------------------------------------- 1 | require 'java' 2 | require 'jruby-parser/util/coercer' 3 | 4 | class org::jrubyparser::ast::SuperNode 5 | include JRubyParser::Args 6 | end 7 | -------------------------------------------------------------------------------- /lib/jruby-parser/util/coercer.rb: -------------------------------------------------------------------------------- 1 | module JRubyParser 2 | module Receiver 3 | def self.included(cls) 4 | cls.class_eval do 5 | def receiver=(value) 6 | old_value = getReceiver 7 | if value.respond_to? :to_ast_node 8 | value = value.to_ast_node(old_value.position) 9 | end 10 | setReceiver(value) 11 | end 12 | end 13 | end 14 | end 15 | 16 | module Value 17 | def self.included(cls) 18 | cls.class_eval do 19 | def value=(value) 20 | old_value = getValue 21 | if value.respond_to? :to_ast_node 22 | value = value.to_ast_node(old_value.position) 23 | end 24 | 25 | setValue(value) 26 | end 27 | end 28 | end 29 | end 30 | 31 | module Args 32 | def self.included(cls) 33 | cls.class_eval do 34 | def args=(value) 35 | old_value = getArgs 36 | if value.respond_to? :to_ast_node 37 | value = value.to_ast_node(old_value.position) 38 | end 39 | 40 | unless value.position 41 | value.position = old_value.position 42 | value.each { |e| e.position = old_value.position } #if value.respond_to? :each 43 | end 44 | 45 | setArgs(value) 46 | end 47 | end 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /lib/jruby-parser/version.rb: -------------------------------------------------------------------------------- 1 | module JRubyParser 2 | VERSION = "0.5.5" 3 | end 4 | -------------------------------------------------------------------------------- /lib/yydebug.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jruby-parser/099bcd4f895155ae1f97ccfd146540601ca0b44a/lib/yydebug.jar -------------------------------------------------------------------------------- /nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=5ca4dfce 2 | build.xml.script.CRC32=c27bf38b 3 | build.xml.stylesheet.CRC32=958a1d3e 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=c6655dbd 7 | nbproject/build-impl.xml.script.CRC32=8d1709e9 8 | nbproject/build-impl.xml.stylesheet.CRC32=982960f4@1.68.1.46 9 | -------------------------------------------------------------------------------- /nbproject/private/config.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jruby/jruby-parser/099bcd4f895155ae1f97ccfd146540601ca0b44a/nbproject/private/config.properties -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | JRubyParser 7 | 1.6.5 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /sample/simple.rb: -------------------------------------------------------------------------------- 1 | require 'jruby-parser' 2 | 3 | # Extra options hash can be passed in to override parser configuration 4 | # opts = {:version => JRubyParser::Compat::RUBY1_8, :filename => 'name.rb'} 5 | # root = JRubyParser.parse("b = foo(1)", opts) 6 | root = JRubyParser.parse("b = foo(1)") 7 | 8 | # Enumerable is mixed into AST tree 9 | # fcall = foot.find { |e| e.short_name == "fcall" } 10 | # ...but find_node is pretty common for spec writing: 11 | fcall = root.find_node(:fcall) 12 | 13 | # Change the AST. 14 | fcall.name = 'bar' 15 | 16 | # Notice this should be a TrueNode, but true knows to coerce into TrueNode 17 | fcall.args[0] = true 18 | 19 | # Write out the new source "b = bar(1)" 20 | p root.to_source 21 | -------------------------------------------------------------------------------- /spec/ast/node/alias_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.AliasNode do 4 | VERSIONS.each do |v| 5 | it "Should parse alias node of symbols" do 6 | rparse("alias :new_name :old_name", v).find_node(:alias).tap do |a| 7 | a.new_name_string.should == "new_name" 8 | a.old_name_string.should == "old_name" 9 | a.new_name.should have_position(0, 0, 6, 15) 10 | a.old_name.should have_position(0, 0, 16, 25) 11 | end 12 | end 13 | 14 | it "Should parse alias node of CONSTANTS" do 15 | rparse("alias NEW OLD", v).find_node(:alias).tap do |a| 16 | a.new_name_string.should == "NEW" 17 | a.old_name_string.should == "OLD" 18 | a.new_name.should have_position(0, 0, 6, 9) 19 | a.old_name.should have_position(0, 0, 10, 13) 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/ast/node/array_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | tnode, fnode = org.jrubyparser.ast.TrueNode, org.jrubyparser.ast.FalseNode 4 | inil = org.jrubyparser.ast.ImplicitNilNode 5 | 6 | describe org.jrubyparser.ast.ArrayNode do 7 | VERSIONS.each do |v| 8 | it "can have multiple elements [#{v}]" do 9 | parse("[true, false]", v).find_node(:array).tap do |list| 10 | list.should have_position(0, 0, 0, 13) 11 | list.size.should == 2 12 | list.child_nodes.to_a.map(&:class).should == [tnode, fnode] 13 | end 14 | end 15 | 16 | it "can have nasty implcit nil elements [#{v}]" do 17 | parse("[()]", v).find_node(:array).tap do |list| 18 | list.should have_position(0, 0, 0, 4) 19 | list.size.should == 1 20 | list.child_nodes.to_a.map(&:class).should == [inil] 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /spec/ast/node/break_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.BreakNode do 4 | VERSIONS.each do |v| 5 | it "can accept a single value [#{v}]" do 6 | rparse("break true", v).find_node(:break).tap do |b| 7 | b.should have_position(0, 0, 0, 10) 8 | b.value_node.class.should == org.jrubyparser.ast.TrueNode 9 | end 10 | end 11 | 12 | it "can accept no value [#{v}]" do 13 | rparse("break", v).find_node(:break).tap do |b| 14 | b.should have_position(0, 0, 0, 5) 15 | b.value_node.should == nil 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/ast/node/call_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.CallNode do 4 | VERSIONS.each do |v| 5 | it "parses a 0-arg object.method call without parens [#{v}]" do 6 | rparse("Array.new", v).find_node(:call).tap do |call| 7 | call.should have_name_and_position("new", 0, 0, 0, 9) 8 | call.receiver_node.should have_name_and_position("Array", 0, 0, 0, 5) 9 | call.args_node.size.should == 0 10 | end 11 | end 12 | 13 | it "parses a 0-arg object.method call with parens [#{v}]" do 14 | rparse("Array.new()", v).find_node(:call).tap do |call| 15 | call.should have_name_and_position("new", 0, 0, 0, 11) 16 | call.receiver_node.should have_name_and_position("Array", 0, 0, 0, 5) 17 | call.args_node.size.should == 0 18 | end 19 | end 20 | 21 | it "parses a 1-arg object.method call without parens [#{v}]" do 22 | rparse("Array.new 1", v).find_node(:call).tap do |call| 23 | call.should have_name_and_position("new", 0, 0, 0, 11) 24 | call.receiver_node.should have_name_and_position("Array", 0, 0, 0, 5) 25 | call.args_node.size.should == 1 26 | end 27 | end 28 | 29 | it "parses a 1-arg object.method call with parens [#{v}]" do 30 | rparse("Array.new(1)", v).find_node(:call).tap do |call| 31 | call.should have_name_and_position("new", 0, 0, 0, 12) 32 | call.receiver_node.should have_name_and_position("Array", 0, 0, 0, 5) 33 | call.args_node.size.should == 1 34 | end 35 | end 36 | 37 | it "parses a 1-arg infix method [#{v}]" do 38 | rparse("4 + 5", v).find_node(:call).tap do |call| 39 | call.should have_name_and_position("+", 0, 0, 0, 5) 40 | call.receiver_node.should have_position(0, 0, 0, 1) 41 | call.args_node.size.should == 1 42 | end 43 | end 44 | 45 | it "parses a 1-arg object.method call with infix operator as arg [#{v}]" do 46 | rparse("Array.new 4 + 5", v).find_node(:call).tap do |call| 47 | call.should have_name_and_position("new", 0, 0, 0, 15) 48 | call.receiver_node.should have_name_and_position("Array", 0, 0, 0, 5) 49 | call.args_node.size.should == 1 50 | end 51 | end 52 | 53 | if v != 1.8 # In 1.8 this is a NotNode (see not_spec.rb) 54 | it "parses unary ! call with parenthesis [#{v}]" do 55 | rparse("!(x < 5)", v).find_node(:call).tap do |call| 56 | call.should have_name_and_position("!", 0, 0, 0, 8) 57 | end 58 | end 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /spec/ast/node/comments_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.Node do 4 | VERSIONS.each do |v| 5 | it "can see a single previous comment [#{v}]" do 6 | rparse("# c1\ndef foo; end", v).find_node(:defn).tap do |defn| 7 | defn.previous_comments.to_a.map(&:content).should =~ ["# c1"] 8 | end 9 | 10 | rparse("# c1\ndef foo; end\nfoo\n", v).find_node(:defn).tap do |defn| 11 | defn.previous_comments.to_a.map(&:content).should =~ ["# c1"] 12 | end 13 | 14 | rparse("# c1\ndef self.[]\nend", v).find_node(:defs).tap do |defs| 15 | defs.previous_comments.to_a.map(&:content).should =~ ["# c1"] 16 | end 17 | 18 | rparse("# c1\nclass Foo\nend", v).find_node(:class).tap do |defn| 19 | defn.previous_comments.to_a.map(&:content).should =~ ["# c1"] 20 | end 21 | 22 | rparse("# c1\nif 1; end", v).find_node(:if).tap do |ifn| 23 | ifn.previous_comments.to_a.map(&:content).should =~ ["# c1"] 24 | end 25 | end 26 | 27 | it "can see a multiple previous comments [#{v}]" do 28 | rparse("# c1\n# c2\ndef foo; end", v).find_node(:defn).tap do |defn| 29 | defn.previous_comments.to_a.map(&:content).should =~ ["# c1", "# c2"] 30 | end 31 | 32 | rparse("# c1\n# c2\nclass Foo\nend", v).find_node(:class).tap do |defn| 33 | defn.previous_comments.to_a.map(&:content).should =~ ["# c1", "# c2"] 34 | end 35 | 36 | rparse("# c1\n# c2\nif 1\nend", v).find_node(:if).tap do |ifn| 37 | ifn.previous_comments.to_a.map(&:content).should =~ ["# c1", "# c2"] 38 | end 39 | end 40 | 41 | it "can see an inline comment [#{v}]" do 42 | rparse("1 + 2 # inline").find_node(:call).tap do |call| 43 | call.inline_comment.content.should == "# inline" 44 | end 45 | end 46 | 47 | it "places trailing comments as last element in root [#{v}]" do 48 | rparse("def foo\n end\n #trailing").child_nodes.to_a.last.tap do |child| 49 | child.content.should =~ /#trailing/ 50 | end 51 | end 52 | 53 | it "handles a lone comment [#{v}]" do 54 | rparse("#trailing").child_nodes.to_a.last.tap do |child| 55 | child.content.should =~ /#trailing/ 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/ast/node/find_scopes_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | # FIXME: Move each of these methods into their respective spec files (e.g method_for_spec.rb) 4 | describe org.jrubyparser.ast.Node do 5 | VERSIONS.each do |v| 6 | it "children can ask for the method it is contained in [#{v}]" do 7 | parse("def foo; true if false; end").find_node(:defn) do |defn| 8 | defn.find_node(:true).method_for.should == defn 9 | defn.find_node(:false).method_for.should == defn 10 | defn.find_node(:if).method_for.should == defn 11 | end 12 | end 13 | 14 | it "children can ask for the iter/block it is contained in [#{v}]" do 15 | parse("proc { |a| proc { |b| true } }").find_node(:iter) do |iter1| 16 | iter1.find_node(:true).innermost_iter.should_not == iter1 17 | iter1.find_node(:true).outermost_iter.should == iter1 18 | end 19 | end 20 | 21 | it "should not find an innermost block if method is inside block" do 22 | parse("proc { def foo; true; end }").find_node(:true) do |tru| 23 | tru.innermost_iter.should == nil 24 | tru.outermost_iter.should == nil 25 | end 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /spec/ast/node/get_declaration_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.Node do 4 | VERSIONS.each do |v| 5 | it "finds a variable's parameter declaration via get_declaration [#{v}]" do 6 | carets_parse("def foo(^a); ^a; end", v).tap do |_, caret_nodes| 7 | caret_nodes[1].declaration.should == caret_nodes[0] 8 | end 9 | carets_parse("def foo(^a); a = 1; ^a; end", v).tap do |_, caret_nodes| 10 | caret_nodes[1].declaration.should == caret_nodes[0] 11 | end 12 | carets_parse("def foo(*^a); a = 1; ^a; end", v).tap do |_, caret_nodes| 13 | caret_nodes[1].declaration.should == caret_nodes[0] 14 | end 15 | carets_parse("def foo(&^a); a = 1; ^a; end", v).tap do |_, caret_nodes| 16 | caret_nodes[1].declaration.should == caret_nodes[0] 17 | end 18 | carets_parse("def foo(^a=1); a = 1; ^a; end", v).tap do |_, caret_nodes| 19 | caret_nodes[1].declaration.should == caret_nodes[0] 20 | end 21 | end 22 | it "finds a variable's lvar declaration via get_declaration [#{v}]" do 23 | carets_parse("def foo; ^a = 1; ^a; end", v).tap do |_, caret_nodes| 24 | caret_nodes[1].declaration.should == caret_nodes[0] 25 | end 26 | carets_parse("def foo; ^a = 1; a = 2; ^a; end", v).tap do |_, caret_nodes| 27 | caret_nodes[1].declaration.should == caret_nodes[0] 28 | end 29 | end 30 | it "finds a variable's parameter declaration via get_declaration [#{v}]" do 31 | carets_parse("proc {|^a| ^a}", v).tap do |_, caret_nodes| 32 | caret_nodes[1].declaration.should == caret_nodes[0] 33 | end 34 | carets_parse("proc {|^a| a = 1; ^a}", v).tap do |_, caret_nodes| 35 | caret_nodes[1].declaration.should == caret_nodes[0] 36 | end 37 | carets_parse("proc {|*^a| a = 1; ^a}", v).tap do |_, caret_nodes| 38 | caret_nodes[1].declaration.should == caret_nodes[0] 39 | end 40 | carets_parse("proc {|&^a| a = 1; ^a}", v).tap do |_, caret_nodes| 41 | caret_nodes[1].declaration.should == caret_nodes[0] 42 | end 43 | if v != 1.8 44 | carets_parse("proc {|^a=1| a = 1; ^a}", v).tap do |_, caret_nodes| 45 | caret_nodes[1].declaration.should == caret_nodes[0] 46 | end 47 | end 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /spec/ast/node/get_node_at_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.Node do 4 | VERSIONS.each do |v| 5 | it "finds fcall via simple getNodeAt search [#{v}]" do 6 | caret_parse("b = fo^o(1)", v).tap do |root, caret_node| 7 | root.find_node(:fcall).should == caret_node 8 | end 9 | caret_parse("b = foo(^1)", v).tap do |root, caret_node| 10 | root.find_node(:fixnum).should == caret_node 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /spec/ast/node/hash_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.AliasNode do 4 | VERSIONS.each do |v| 5 | it "should parse a hash literal (a=>b) [#{v}]" do 6 | rparse("{:one => 1, :two => 2}", v).find_node(:hash).tap do |hash| 7 | hash.should have_position(0, 0, 0, 22) 8 | end 9 | end 10 | 11 | if v == 1.8 12 | it "should parse a hash literal (a,b) [#{v}]" do 13 | rparse("{:one, 1, :two, 2}", v).find_node(:hash).tap do |hash| 14 | hash.should have_position(0, 0, 0, 18) 15 | end 16 | 17 | rparse("call :one => 2", v).find_node(:hash).tap do |hash| 18 | hash.should have_position(0, 0, 5, 14) 19 | end 20 | end 21 | else 22 | it "should parse a hash literal (a: b) [#{v}]" do 23 | rparse("{one: 1, two: 2}", v).find_node(:hash).tap do |hash| 24 | hash.should have_position(0, 0, 0, 16) 25 | end 26 | 27 | rparse("call one: 2", v).find_node(:hash).tap do |hash| 28 | hash.should have_position(0, 0, 5, 11) 29 | end 30 | end 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /spec/ast/node/is_block_parameter_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.Node do 4 | VERSIONS.each do |v| 5 | it "finds parameter via is_block_parameter [#{v}]" do 6 | caret_parse("proc { |^a| }", v).tap do |root, caret_node| 7 | caret_node.block_parameter?.should == true 8 | end 9 | caret_parse("proc { |^a,b| }", v).tap do |root, caret_node| 10 | caret_node.block_parameter?.should == true 11 | end 12 | caret_parse("proc { |*^a| }", v).tap do |root, caret_node| 13 | caret_node.block_parameter?.should == true 14 | end 15 | caret_parse("proc { |a, (b, ^c)| }", v).tap do |root, caret_node| 16 | caret_node.block_parameter?.should == true 17 | end 18 | caret_parse("proc { |&^a| }", v).tap do |root, caret_node| 19 | caret_node.block_parameter?.should == true 20 | end 21 | 22 | if v != 1.8 23 | caret_parse("proc { |a, ^b=1| }", v).tap do |root, caret_node| 24 | caret_node.block_parameter?.should == true 25 | end 26 | 27 | caret_parse("proc { |c| proc { |a, b=^c| } }", v).tap do |root, caret_node| 28 | caret_node.block_parameter?.should == false 29 | end 30 | 31 | caret_parse("proc { |c; ^d| }", v).tap do |root, caret_node| 32 | caret_node.block_parameter?.should == true 33 | end 34 | 35 | caret_parse("proc { |c; d, ^e| }", v).tap do |root, caret_node| 36 | caret_node.block_parameter?.should == true 37 | end 38 | 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /spec/ast/node/is_method_parameter_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.Node do 4 | VERSIONS.each do |v| 5 | it "finds parameter via is_method_parameter [#{v}]" do 6 | caret_parse("def foo(^a); end", v).tap do |root, caret_node| 7 | caret_node.method_parameter?.should == true 8 | end 9 | caret_parse("def foo(^a,b); end", v).tap do |root, caret_node| 10 | caret_node.method_parameter?.should == true 11 | end 12 | caret_parse("def foo(*^a); end", v).tap do |root, caret_node| 13 | caret_node.method_parameter?.should == true 14 | end 15 | caret_parse("def foo(&^a); end", v).tap do |root, caret_node| 16 | caret_node.method_parameter?.should == true 17 | end 18 | caret_parse("def foo(a, ^b=1); end", v).tap do |root, caret_node| 19 | caret_node.method_parameter?.should == true 20 | end 21 | if v != 1.8 22 | caret_parse("def foo(a, (b, ^c)); end", v).tap do |root, caret_node| 23 | caret_node.method_parameter?.should == true 24 | end 25 | caret_parse("def foo(a, b=1, ^c); end", v).tap do |root, caret_node| 26 | caret_node.method_parameter?.should == true 27 | end 28 | end 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/ast/node/multiple_asgn_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.MultipleAsgnNode do 4 | VERSIONS.each do |v| 5 | it "can tell two nodes with a different rhs apart [#{v}]" do 6 | root = JRubyParser.parse("x, y, z = [1, 2, 3]") 7 | root2 = JRubyParser.parse("x, y, z = [1, 2, 4]") 8 | multi = root.find_node(:multipleasgn) 9 | multi2 = root2.find_node(:multipleasgn) 10 | expect(multi.is_same(multi2)).not_to be true 11 | end 12 | 13 | it "can tell two nodes with a different lhs apart [#{v}]" do 14 | root = JRubyParser.parse("x, y, z = [1, 2, 3]") 15 | root2 = JRubyParser.parse("a, b, c = [1, 2, 3]") 16 | multi = root.find_node(:multipleasgn) 17 | multi2 = root2.find_node(:multipleasgn) 18 | expect(multi.is_same(multi2)).not_to be true 19 | end 20 | 21 | it "can tell two nodes are the same [#{v}]" do 22 | root = JRubyParser.parse("x, y, z = [1, 2, 3]") 23 | root2 = JRubyParser.parse("x, y, z = [1, 2, 3]") 24 | multi = root.find_node(:multipleasgn) 25 | multi2 = root2.find_node(:multipleasgn) 26 | expect(multi.is_same(multi2)).to be true 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /spec/ast/node/next_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.NextNode do 4 | VERSIONS.each do |v| 5 | it "can accept a single value [#{v}]" do 6 | rparse("next true", v).find_node(:next).tap do |b| 7 | b.should have_position(0, 0, 0, 9) 8 | b.value_node.class.should == org.jrubyparser.ast.TrueNode 9 | end 10 | end 11 | 12 | it "can accept no value [#{v}]" do 13 | rparse("next", v).find_node(:next).tap do |b| 14 | b.should have_position(0, 0, 0, 4) 15 | b.value_node.should == nil 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/ast/node/not_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.NotNode do 4 | VERSIONS.each do |v| 5 | if v == 1.8 6 | it "parses unary ! call with parenthesis [#{v}]" do 7 | rparse("!(x < 5)", v).find_node(:not).tap do |call| 8 | call.should have_position(0, 0, 0, 8) 9 | end 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/ast/node/op_element_asgn_and_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.OpElementAsgnAndNode do 4 | VERSIONS.each do |v| 5 | it "can parse simple expr [#{v}]" do 6 | parse("a[1] &&= 2", v).find_node(:opelementasgnand).tap do |op| 7 | op.should have_position(0, 0, 0, 10) 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/ast/node/op_element_asgn_or_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.OpElementAsgnOrNode do 4 | VERSIONS.each do |v| 5 | it "can parse simple expr [#{v}]" do 6 | parse("a[1] ||= 2", v).find_node(:opelementasgnor).tap do |op| 7 | op.should have_position(0, 0, 0, 10) 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/ast/node/op_element_asgn_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.OpElementAsgnNode do 4 | VERSIONS.each do |v| 5 | it "can parse simple expr [#{v}]" do 6 | parse("a[1] += 2", v).find_node(:opelementasgn).tap do |op| 7 | op.should have_position(0, 0, 0, 9) 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/ast/node/return_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.ReturnNode do 4 | VERSIONS.each do |v| 5 | it "can accept a single value [#{v}]" do 6 | rparse("return true", v).find_node(:return).tap do |b| 7 | b.should have_position(0, 0, 0, 11) 8 | b.value_node.class.should == org.jrubyparser.ast.TrueNode 9 | end 10 | end 11 | 12 | it "can accept no value [#{v}]" do 13 | rparse("return", v).find_node(:return).tap do |b| 14 | b.should have_position(0, 0, 0, 6) 15 | b.value_node.should == nil 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/ast/node/vcall_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.VCallNode do 4 | VERSIONS.each do |v| 5 | it "parses a 0-arg method call sans parens +extra line [#{v}]" do 6 | # rparse("\nputs\n", v).find_node(:vcall).tap do |call| 7 | # call.should have_name_and_position("puts", 1, 1, 1, 5) 8 | # end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/ast/node/while_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe org.jrubyparser.ast.WhileNode do 4 | VERSIONS.each do |v| 5 | it "can have an empty body [#{v}]" do 6 | rparse("while true\n;end\n", v).find_node(:while).tap do |b| 7 | b.should have_position(0, 1, 0, 15) 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/ast/node_path.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../helpers' 2 | 3 | describe Parser do 4 | it "should parse alias with quotationmarks" do 5 | root = parse <<-EOF 6 | def foo(arg) 7 | puts arg 8 | end 9 | EOF 10 | list = root.pathTo(root.find_node(:defn)) 11 | list.size.should == 3 12 | list.root.node_name.should == "RootNode" 13 | list.leaf.node_name.should == "DefnNode" 14 | end 15 | end 16 | 17 | -------------------------------------------------------------------------------- /spec/helpers.rb: -------------------------------------------------------------------------------- 1 | require 'jruby-parser' 2 | 3 | require_relative 'helpers/node_helpers' 4 | require_relative 'helpers/parser_helpers' 5 | -------------------------------------------------------------------------------- /spec/jruby-parser/find_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../helpers' 2 | 3 | describe JRubyParser do 4 | VERSIONS.each do |v| 5 | it "finds fcall via simple symbol search [#{v}]" do 6 | parse("b = foo(1)").tap do |root| 7 | fcall = root.find_type(:fcall) 8 | fcall.should_not == nil 9 | end 10 | end 11 | 12 | it "finds specific fcall by block and simple symbol [#{v}]" do 13 | parse("foo(1); bar(2)").tap do |root| 14 | fcall = root.find_type(:fcall) { |n| n.name == "bar" } 15 | fcall.name.should == "bar" 16 | end 17 | end 18 | 19 | it "finds type and method named based on Enumerable find [#{v}]" do 20 | parse("foo(1); bar(2)").tap do |root| 21 | fcall = root.find { |n| n.short_name == "fcall" && n.name == "bar"} 22 | fcall.name.should == "bar" 23 | fcalls = root.find_all { |n| n.short_name == "fcall" } 24 | fcalls.size.should == 2 25 | end 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /spec/jruby-parser/parse_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../helpers' 2 | 3 | describe JRubyParser do 4 | VERSIONS.each do |v| 5 | it "passes in a static scope with defined var [#{v}]" do 6 | parse("b = a", v, scope('a')).tap do |root| 7 | root.find_type(:localvar).should_not == nil # a 8 | end 9 | end 10 | 11 | it "parses hash literal with trailing = at end of key name" do 12 | parse("{:a==>1}").tap do |root| 13 | root.find_type(:symbol).name.should == "a=" 14 | end 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/parser/alias_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../helpers' 2 | 3 | describe Parser do 4 | VERSIONS.each do |v| 5 | it "should parse alias with quotationmarks" do 6 | parse(%Q{alias :'<==>' :"foo"}, v).find_node(:alias).tap do |aliasn| 7 | aliasn.new_name.find_node(:symbol).name.should == "<==>" 8 | aliasn.old_name.find_node(:symbol).name.should == "foo" 9 | aliasn.should have_position(0,0,0,20) 10 | end 11 | end 12 | end 13 | end 14 | 15 | -------------------------------------------------------------------------------- /spec/parser/broken_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../helpers' 2 | 3 | java_import org.jrubyparser.lexer.StringTerm 4 | java_import org.jrubyparser.lexer.SyntaxException 5 | 6 | # tests for broken files 7 | describe Parser do 8 | VERSIONS.each do |v| 9 | it "should raise an unterminated string exception" do 10 | lambda { 11 | parse('str = "', v) 12 | }.should raise_error StringTerm::UnterminatedStringException 13 | end 14 | 15 | it "should raise a syntax exception" do 16 | lambda { 17 | parse("class Foo\n def\nend\n", v) 18 | }.should raise_error SyntaxException 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /spec/parser/lambda_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../helpers' 2 | 3 | describe Parser do 4 | it "parses stabby lambdas with whitespace between () and -> in 2.0 mode" do 5 | parse("hello_world = -> (message) { puts message }", 2.0).find_node(:lambda).tap do |l| 6 | expect(l).to have_position(0, 0, 17, 43) 7 | end 8 | end 9 | end 10 | 11 | -------------------------------------------------------------------------------- /spec/positions/attr_asgn_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../helpers' 2 | 3 | describe Parser do 4 | VERSIONS.each do |v| 5 | it "Should parse attr assign" do 6 | parse("a[1] = 2", v).find_node(:attrassign).tap do |asgn| 7 | asgn.should_not == nil 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/positions/conditionals_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../helpers' 2 | 3 | describe Parser do 4 | VERSIONS.each do |v| 5 | it "should parse an unless on alias [#{v}]" do 6 | ast = parse("alias p ** unless method_defined? :p", v) 7 | ast.find_node(:alias).tap { |a| a.should have_position(0, 0, 0, 10) } 8 | ast.find_node(:if).tap { |i| i.should have_position(0, 0, 0, 36) } 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/positions/name_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../helpers' 2 | 3 | describe Parser do 4 | VERSIONS.each do |v| 5 | it "should get name position for lvars [#{v}]" do 6 | carets_parse("^foo = 1; ^foo", v).tap do |_, (asgn, var)| 7 | asgn.should have_name_position(0, 0, 0, 3) 8 | var.should have_name_position(0, 0, 9, 12) 9 | end 10 | end 11 | it "should get name position for ivars [#{v}]" do 12 | carets_parse("^@foo = 1; ^@foo", v).tap do |_, (asgn, var)| 13 | asgn.should have_name_position(0, 0, 1, 4) 14 | var.should have_name_position(0, 0, 11, 14) 15 | end 16 | end 17 | it "should get name position for cvars [#{v}]" do 18 | carets_parse("^@@foo = 1; ^@@foo", v).tap do |_, (asgn, var)| 19 | asgn.should have_name_position(0, 0, 2, 5) 20 | var.should have_name_position(0, 0, 13, 16) 21 | end 22 | end 23 | it "should get name position for gvars [#{v}]" do 24 | carets_parse("^$foo = 1; ^$foo", v).tap do |_, (asgn, var)| 25 | asgn.should have_name_position(0, 0, 1, 4) 26 | var.should have_name_position(0, 0, 11, 14) 27 | end 28 | end 29 | it "should get name position for constants [#{v}]" do 30 | carets_parse("^FOO = 1; ^FOO", v).tap do |_, (asgn, var)| 31 | asgn.should have_name_position(0, 0, 0, 3) 32 | var.should have_name_position(0, 0, 9, 12) 33 | end 34 | end 35 | it "should get name position for method parameters [#{v}]" do 36 | carets_parse("def foo(^a, ^b=1, *^c, &^d);end", v).tap do |_, (a, b, c, d)| 37 | a.should have_name_position(0, 0, 8, 9) 38 | b.should have_name_position(0, 0, 11, 12) 39 | c.should have_name_position(0, 0, 17, 18) 40 | d.should have_name_position(0, 0, 21, 22) 41 | end 42 | if v != 1.8 43 | carets_parse("def foo(^a, ^b=1, ^c);end", v).tap do |_, (a, b, c)| 44 | c.should have_name_position(0, 0, 16,17) 45 | end 46 | end 47 | end 48 | it "should get name position for block parameters [#{v}]" do 49 | carets_parse("proc {|^a, *^b, &^c|}", v).tap do |_, (a, b, c)| 50 | a.should have_name_position(0, 0, 7, 8) 51 | b.should have_name_position(0, 0, 11, 12) 52 | c.should have_name_position(0, 0, 15, 16) 53 | end 54 | end 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /spec/positions/op_asgn_or_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../helpers' 2 | 3 | describe Parser do 4 | VERSIONS.each do |v| 5 | it "Should parse attr assign" do 6 | parse("foo ||= bar", v).find_node(:opasgnor).tap do |opasgn| 7 | opasgn.should have_position(0, 0, 0, 11) 8 | reference, assignment = opasgn.first, opasgn.second 9 | reference.should have_name_and_position("foo", 0, 0, 0, 3) 10 | # assignment.should have_name_and_position("foo", 0, 0, 0, 11) 11 | assignment.value.should have_name_and_position("bar", 0, 0, 8, 11) 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/positions/str_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../helpers' 2 | 3 | describe Parser do 4 | VERSIONS.each do |v| 5 | it "should parse a string value [#{v}]" do 6 | parse('str = "my str"', v).find_node(:str).value.should == "my str" 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/util/method_def_visitor_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative '../helpers' 2 | 3 | java_import org.jrubyparser.util.MethodDefVisitor 4 | 5 | def modules_in(code) 6 | find_modules(parse(code)) 7 | end 8 | 9 | def find_modules(node) 10 | node.child_nodes.inject([]) do |modules, n| 11 | modules << n if n.kind_of? org.jrubyparser.ast.IModuleScope 12 | modules.concat find_modules(n) 13 | end 14 | end 15 | 16 | describe MethodDefVisitor do 17 | it 'should find no methods defined in a class' do 18 | modules_in("class Example\nend").first.method_defs.should == [] 19 | end 20 | 21 | it 'should find a method defined in a class' do 22 | modz = modules_in("class Example\ndef hello\nend\nend") 23 | modz.first.method_defs.map(&:name).should =~ %w{hello} 24 | end 25 | 26 | it 'should find methods defined in a class' do 27 | modz = modules_in("class Example\ndef hello\nend;def world; end\nend") 28 | modz.first.method_defs.map(&:name).should =~ %w{hello world} 29 | end 30 | 31 | it 'should not find a method defined on an inner class' do 32 | modz = modules_in("module Ex\nclass Example\ndef hello\nend\nend\nend") 33 | modz.first.method_defs.size.should == 0 34 | end 35 | 36 | it 'should not find a method defined inside a method' do 37 | modz = modules_in("class Example\ndef hello\ndef hello_too\nend\nend\nend") 38 | modz.first.method_defs.size.should == 1 39 | end 40 | 41 | it 'should find a method defined in block scope in module body' do 42 | modz = modules_in("module Ex\nloop do\ndef hello\nend\nend\nend") 43 | modz.first.method_defs.size.should == 1 44 | end 45 | end 46 | 47 | -------------------------------------------------------------------------------- /src/org/jrubyparser/CompatVersion.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser; 2 | 3 | public enum CompatVersion { 4 | 5 | RUBY1_8, RUBY1_9, RUBY2_0, RUBY2_3; 6 | 7 | public boolean is1_9() { 8 | return this == RUBY1_9 || this == RUBY2_0; 9 | } 10 | 11 | public boolean is2_0() { 12 | return this == RUBY2_0 || this == RUBY2_3; 13 | } 14 | 15 | public boolean is2_3() { 16 | return this == RUBY2_3; 17 | } 18 | 19 | public static CompatVersion getVersionFromString(String compatString) { 20 | if (compatString.equalsIgnoreCase("RUBY1_8")) { 21 | return CompatVersion.RUBY1_8; 22 | } else if (compatString.equalsIgnoreCase("RUBY1_9")) { 23 | return CompatVersion.RUBY1_9; 24 | } else if (compatString.equalsIgnoreCase("RUBY2_0")) { 25 | return CompatVersion.RUBY2_0; 26 | } else if (compatString.equalsIgnoreCase("RUBY2_3")) { 27 | return CompatVersion.RUBY2_3; 28 | } else { 29 | return null; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ISourcePositionHolder.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2005 Thomas E Enebo 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jrubyparser; 29 | 30 | /** 31 | */ 32 | public interface ISourcePositionHolder { 33 | public SourcePosition getPosition(); 34 | public void setPosition(SourcePosition position); 35 | } 36 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/AndNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents a && (and) operator. 36 | */ 37 | public class AndNode extends BinaryOperatorBaseNode { 38 | public AndNode(SourcePosition position, Node firstNode, Node secondNode) { 39 | super(position, firstNode, secondNode); 40 | } 41 | 42 | public NodeType getNodeType() { 43 | return NodeType.ANDNODE; 44 | } 45 | 46 | public T accept(NodeVisitor iVisitor) { 47 | return iVisitor.visitAndNode(this); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ArgAuxillaryNode.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2009 Thomas E. Enebo 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jrubyparser.ast; 29 | 30 | import org.jrubyparser.NodeVisitor; 31 | import org.jrubyparser.SourcePosition; 32 | /** 33 | * 34 | * @author enebo 35 | */ 36 | public class ArgAuxillaryNode extends Node { 37 | private String name; 38 | private int offset; 39 | 40 | public ArgAuxillaryNode(SourcePosition position, String name, int offset) { 41 | super(position); 42 | this.name = name; 43 | this.offset = offset; 44 | } 45 | 46 | public NodeType getNodeType() { 47 | return NodeType.ARGAUXILIARYNODE; 48 | } 49 | 50 | public int getOffset() { 51 | return offset; 52 | } 53 | 54 | public String getName() { 55 | return name; 56 | } 57 | 58 | @Override 59 | public T accept(NodeVisitor visitor) { 60 | throw new UnsupportedOperationException("Not supported yet."); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ArgsCatNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | public class ArgsCatNode extends BinaryOperatorBaseNode { 35 | public ArgsCatNode(SourcePosition position, Node firstNode, Node secondNode) { 36 | super(position, firstNode, secondNode); 37 | } 38 | 39 | @Override 40 | public NodeType getNodeType() { 41 | return NodeType.ARGSCATNODE; 42 | } 43 | 44 | public T accept(NodeVisitor visitor) { 45 | return visitor.visitArgsCatNode(this); 46 | } 47 | 48 | @Deprecated 49 | public Node getFirstNode() { 50 | return getFirst(); 51 | } 52 | 53 | @Deprecated 54 | public Node getSecondNode() { 55 | return getSecond(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ArrayNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents an array. This could be an array literal, quoted words or some args stuff. 36 | */ 37 | public class ArrayNode extends ListNode implements ILiteralNode { 38 | public ArrayNode(SourcePosition position, Node firstNode) { 39 | super(position, firstNode); 40 | 41 | assert firstNode != null : "ArrayNode.first == null"; 42 | } 43 | 44 | public ArrayNode(SourcePosition position) { 45 | super(position); 46 | } 47 | 48 | @Override 49 | public NodeType getNodeType() { 50 | return NodeType.ARRAYNODE; 51 | } 52 | 53 | /** 54 | * Accept for the visitor pattern. 55 | * @param iVisitor the visitor 56 | **/ 57 | @Override 58 | public T accept(NodeVisitor iVisitor) { 59 | return iVisitor.visitArrayNode(this); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/BareKeywordNode.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import org.jrubyparser.SourcePosition; 4 | 5 | /** 6 | * Ruby keywords like self,true,false,nil. 7 | */ 8 | public abstract class BareKeywordNode extends Node implements INameNode { 9 | private String name; 10 | 11 | public BareKeywordNode(SourcePosition position, String name) { 12 | super(position); 13 | 14 | this.name = name; 15 | } 16 | 17 | 18 | /** 19 | * Checks node for 'sameness' for diffing. 20 | * 21 | * @param other to be compared to 22 | * @return Returns a boolean 23 | */ 24 | @Override 25 | public boolean isSame(Node other) { 26 | return super.isSame(other) && isNameMatch(((BareKeywordNode) other).getName()); 27 | } 28 | 29 | 30 | public String getLexicalName() { 31 | return getName(); 32 | } 33 | 34 | /** 35 | * Get name of self node. 36 | */ 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String newName) { 42 | // FIXME: error or noop? 43 | } 44 | 45 | public boolean isNameMatch(String testName) { 46 | return name.equals(testName); 47 | } 48 | 49 | public SourcePosition getNamePosition() { 50 | return getPosition(); 51 | } 52 | 53 | public SourcePosition getLexicalNamePosition() { 54 | return getPosition(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/BinaryOperatorNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | /** 32 | * Convenience interface for operations which only have two nodes 33 | */ 34 | public interface BinaryOperatorNode { 35 | /** 36 | * Gets the firstNode. 37 | * @return Returns a Node 38 | */ 39 | public abstract Node getFirst(); 40 | 41 | /** 42 | * Gets the secondNode. 43 | * @return Returns a Node 44 | */ 45 | public abstract Node getSecond(); 46 | } 47 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/BlockAcceptingNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | /** 32 | * Any thing which implements this represents a Callable-like node which can have a block 33 | * associated with it as part of that call. The calls which can be this are: CallNode, FCallNode, 34 | * VCallNode, and SuperNode. Blocks (the IterNode that this interface refers to can be either 35 | * an IterNode (
{...}
or
do ... end
) or a BlockPassNode (
&block
). 36 | * 37 | * It is likely we can remove this interface once the parser explicitly passes all iters into 38 | * the callable node during construction. 39 | */ 40 | public interface BlockAcceptingNode { 41 | public Node getIter(); 42 | public void setIter(Node iterNode); 43 | } 44 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/BlockArg18Node.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import org.jrubyparser.NodeVisitor; 4 | import org.jrubyparser.SourcePosition; 5 | 6 | /** 7 | * Similiar to BlockArg, but with idiosyncracies that 1.8.7 allows: 8 | * 9 | *
10 |  * proc { |a,&b| }
11 |  * proc { |a,&FOO| }
12 |  * proc { |a,b.c| }
13 |  * proc { |a,b[0]| }
14 |  * 
15 | * 16 | */ 17 | public class BlockArg18Node extends Node { 18 | private Node normalBlockArgs; 19 | private Node blockArgAssignee; 20 | 21 | public BlockArg18Node(SourcePosition position, Node blockArgAssignee, 22 | Node normalBlockArgs) { 23 | super(position); 24 | 25 | assert blockArgAssignee != null : "Must be a value to assign too"; 26 | 27 | this.blockArgAssignee = adopt(blockArgAssignee); 28 | this.normalBlockArgs = adopt(normalBlockArgs); 29 | } 30 | 31 | 32 | /** 33 | * Checks node for 'sameness' for diffing. 34 | * 35 | * @param node to be compared to 36 | * @return Returns a boolean 37 | */ 38 | @Override 39 | public boolean isSame(Node node) { 40 | if (!super.isSame(node)) return false; 41 | 42 | BlockArg18Node other = (BlockArg18Node) node; 43 | 44 | if (getArgs() == null && other.getArgs() == null) return getBlockArg().isSame(other.getBlockArg()); 45 | if (getArgs() == null || other.getArgs() == null) return false; 46 | 47 | return getArgs().isSame(other.getArgs()) && getBlockArg().isSame(other.getBlockArg()); 48 | } 49 | 50 | 51 | 52 | public Node getArgs() { 53 | return normalBlockArgs; 54 | } 55 | 56 | public Node getBlockArg() { 57 | return blockArgAssignee; 58 | } 59 | 60 | @Override 61 | public T accept(NodeVisitor visitor) { 62 | return visitor.visitBlockArg18Node(this); 63 | } 64 | 65 | @Override 66 | public NodeType getNodeType() { 67 | return NodeType.BLOCKARG18NODE; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/BlockNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents a block of nodes (read that as list). 36 | */ 37 | public class BlockNode extends ListNode { 38 | public BlockNode(SourcePosition position) { 39 | super(position); 40 | } 41 | 42 | @Override 43 | public NodeType getNodeType() { 44 | return NodeType.BLOCKNODE; 45 | } 46 | 47 | /** 48 | * RubyMethod used by visitors. 49 | * accepts the visitor 50 | * @param iVisitor the visitor to accept 51 | **/ 52 | @Override 53 | public T accept(NodeVisitor iVisitor) { 54 | return iVisitor.visitBlockNode(this); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/BreakNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents a 'break' statement. 36 | */ 37 | public class BreakNode extends Node { 38 | private Node valueNode; 39 | 40 | public BreakNode(SourcePosition position, Node valueNode) { 41 | super(position); 42 | 43 | this.valueNode = adopt(valueNode); 44 | } 45 | 46 | public NodeType getNodeType() { 47 | return NodeType.BREAKNODE; 48 | } 49 | 50 | /** 51 | * Accept for the visitor pattern. 52 | * @param iVisitor the visitor 53 | **/ 54 | public T accept(NodeVisitor iVisitor) { 55 | return iVisitor.visitBreakNode(this); 56 | } 57 | 58 | /** 59 | * Gets the valueNode. 60 | * @return Returns a Node 61 | */ 62 | public Node getValue() { 63 | return valueNode; 64 | } 65 | 66 | @Deprecated 67 | public Node getValueNode() { 68 | return getValue(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/Colon2ConstNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package org.jrubyparser.ast; 7 | 8 | import org.jrubyparser.SourcePosition; 9 | 10 | /** 11 | * 12 | * @author enebo 13 | */ 14 | public class Colon2ConstNode extends Colon2Node { 15 | public Colon2ConstNode(SourcePosition position, Node leftNode, String name) { 16 | super(position, leftNode, name); 17 | 18 | assert leftNode != null: "Colon2ConstNode cannot have null leftNode"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/Colon2ImplicitNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.SourcePosition; 32 | 33 | /** 34 | * Represents a bare class declaration (e.g. class Foo/module Foo). This is slightly misnamed 35 | * since it contains no double colons (::), but our cname production needs to be a common type. 36 | * In JRuby 2, we will rename this. 37 | */ 38 | public class Colon2ImplicitNode extends Colon2Node { 39 | public Colon2ImplicitNode(SourcePosition position, String name) { 40 | super(position, null, name); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/Colon2MethodNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package org.jrubyparser.ast; 7 | 8 | import org.jrubyparser.SourcePosition; 9 | 10 | /** 11 | * Represents a constant path which ends in a method (e.g. Foo::bar). Note: methods with 12 | * explicit parameters (e.g. Foo::bar()) will be a CallNode. 13 | */ 14 | public class Colon2MethodNode extends Colon2Node { 15 | public Colon2MethodNode(SourcePosition position, Node leftNode, String name) { 16 | super(position, leftNode, name); 17 | 18 | assert leftNode != null: "class fooBar is not valid"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/CommentNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Representation of a comment. Note that comments are not part of evaluation so you do 36 | * not get the ability to visit this node as part of evaluation. In theory we could add 37 | * this if we envisioned some wacky annotation system, but we have no crazy ideas yet. 38 | * 39 | */ 40 | public class CommentNode extends SyntaxNode { 41 | 42 | public CommentNode(SourcePosition position, String content) { 43 | super(position, content); 44 | } 45 | 46 | @Override 47 | public NodeType getNodeType() { 48 | return NodeType.COMMENTNODE; 49 | } 50 | 51 | @Override 52 | public T accept(NodeVisitor visitor) { 53 | return visitor.visitCommentNode(this); 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "Comment: " + getContent(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ComplexNode.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import java.util.List; 4 | import org.jrubyparser.NodeVisitor; 5 | import org.jrubyparser.SourcePosition; 6 | 7 | /** 8 | * Created by enebo on 5/21/15. 9 | */ 10 | public class ComplexNode extends NumericNode implements ILiteralNode { 11 | private NumericNode y; 12 | 13 | public ComplexNode(SourcePosition position, NumericNode y) { 14 | super(position); 15 | 16 | this.y = (NumericNode) adopt(y); 17 | } 18 | 19 | @Override 20 | public T accept(NodeVisitor visitor) { 21 | return visitor.visitComplexNode(this); 22 | } 23 | 24 | @Override 25 | public List childNodes() { 26 | return createList(y); 27 | } 28 | 29 | @Override 30 | public NodeType getNodeType() { 31 | return NodeType.COMPLEXNODE; 32 | } 33 | 34 | public NumericNode getNumber() { 35 | return y; 36 | } 37 | 38 | public void setNumber(NumericNode y) { 39 | this.y = y; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/DStrNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * A string which contains some dynamic elements which needs to be evaluated (introduced by #). 36 | */ 37 | public class DStrNode extends ListNode implements ILiteralNode { 38 | public DStrNode(SourcePosition position) { 39 | super(position); 40 | } 41 | 42 | @Override 43 | public NodeType getNodeType() { 44 | return NodeType.DSTRNODE; 45 | } 46 | 47 | /** 48 | * Accept for the visitor pattern. 49 | * @param iVisitor the visitor 50 | **/ 51 | @Override 52 | public T accept(NodeVisitor iVisitor) { 53 | return iVisitor.visitDStrNode(this); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/DSymbolNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Node representing symbol in a form like ':"3jane"'. 36 | */ 37 | public class DSymbolNode extends ListNode { 38 | /** 39 | * For mutating from a DStr to a DSym (we just create a new one with same contents). 40 | * 41 | * @param position the position 42 | * @param node to be copied 43 | */ 44 | public DSymbolNode(SourcePosition position, DStrNode node) { 45 | super(position); 46 | 47 | assert node != null : "node is not null"; 48 | 49 | addAll(node); 50 | } 51 | 52 | public DSymbolNode(SourcePosition position) { 53 | super(position); 54 | } 55 | 56 | @Override 57 | public NodeType getNodeType() { 58 | return NodeType.DSYMBOLNODE; 59 | } 60 | 61 | @Override 62 | public T accept(NodeVisitor visitor) { 63 | return visitor.visitDSymbolNode(this); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/DXStrNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Dynamic backquote string. Backquote strings are eXecuted using the shell, hence the X 36 | * or maybe the X is due to the %x general quote syntax? 37 | */ 38 | public class DXStrNode extends ListNode implements ILiteralNode { 39 | public DXStrNode(SourcePosition position, DStrNode node) { 40 | super(position); 41 | addAll(node); 42 | } 43 | 44 | public DXStrNode(SourcePosition position) { 45 | super(position); 46 | } 47 | 48 | @Override 49 | public NodeType getNodeType() { 50 | return NodeType.DXSTRNODE; 51 | } 52 | 53 | /** 54 | * Accept for the visitor pattern. 55 | * @param iVisitor the visitor 56 | **/ 57 | @Override 58 | public T accept(NodeVisitor iVisitor) { 59 | return iVisitor.visitDXStrNode(this); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/DefnNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import java.util.List; 32 | 33 | import org.jrubyparser.NodeVisitor; 34 | import org.jrubyparser.SourcePosition; 35 | import org.jrubyparser.StaticScope; 36 | import org.jrubyparser.util.ILocalVariableVisitor; 37 | 38 | /** 39 | * method definition node. 40 | */ 41 | public class DefnNode extends MethodDefNode { 42 | public DefnNode(SourcePosition position, MethodNameNode nameNode, ArgsNode argsNode, 43 | StaticScope scope, Node bodyNode) { 44 | super(position, nameNode, argsNode, scope, bodyNode); 45 | } 46 | 47 | public NodeType getNodeType() { 48 | return NodeType.DEFNNODE; 49 | } 50 | 51 | public T accept(NodeVisitor iVisitor) { 52 | return iVisitor.visitDefnNode(this); 53 | } 54 | 55 | public List getVariableReferencesNamed(String name) { 56 | return ILocalVariableVisitor.findOccurrencesIn(this, name); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/EncodingNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents __ENCODING__. 36 | */ 37 | public class EncodingNode extends Node { 38 | public EncodingNode(SourcePosition position) { 39 | super(position); 40 | } 41 | 42 | @Override 43 | public T accept(NodeVisitor visitor) { 44 | return visitor.visitEncodingNode(this); 45 | } 46 | 47 | @Override 48 | public NodeType getNodeType() { 49 | return NodeType.ENCODINGNODE; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/FalseNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents a false literal. 36 | */ 37 | public class FalseNode extends BareKeywordNode { 38 | public FalseNode(SourcePosition position) { 39 | super(position, "false"); 40 | } 41 | 42 | public NodeType getNodeType() { 43 | return NodeType.FALSENODE; 44 | } 45 | 46 | /** 47 | * Accept for the visitor pattern. 48 | * @param iVisitor the visitor 49 | **/ 50 | public T accept(NodeVisitor iVisitor) { 51 | return iVisitor.visitFalseNode(this); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/FileNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.SourcePosition; 32 | 33 | /** 34 | * Represents __FILE__ nodes 35 | */ 36 | public class FileNode extends StrNode { 37 | public FileNode(SourcePosition position, String value) { 38 | super(position, value); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/IArgumentNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | /** 32 | * Does the node contain an argument list? 33 | */ 34 | public interface IArgumentNode { 35 | public Node getArgs(); 36 | public void setArgs(Node argsNode); 37 | public boolean hasParens(); 38 | public void setHasParens(boolean hasParens); 39 | } 40 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/IBlockScope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package org.jrubyparser.ast; 6 | 7 | /** 8 | * A Scope which is a variable scope for a block. 9 | */ 10 | public interface IBlockScope extends IScope, IParameterScope { 11 | } 12 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/IClassVariable.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | /** 4 | * Marker for Class variable nodes (ClassVarNode, ClassVarAsgnNode, ClassVarDeclNode). 5 | */ 6 | public interface IClassVariable extends INameNode { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/IGlobalVariable.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | /** 4 | * Besides basic global variables (gvar, gasgn) there are special gvars (backref, nthref). 5 | */ 6 | public interface IGlobalVariable extends INameNode { 7 | } 8 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/IInstanceVariable.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | /** 4 | * Marker interface for instance variable (instasgn, instvar). 5 | */ 6 | public interface IInstanceVariable extends INameNode { 7 | } 8 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ILiteralNode.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2009 Thomas E. Enebo 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jrubyparser.ast; 29 | 30 | /** 31 | * A marker for literal nodes. 32 | */ 33 | public interface ILiteralNode { 34 | // only a marker interface 35 | } 36 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ILocalScope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package org.jrubyparser.ast; 6 | 7 | /** 8 | * Marker Interface to identify local variable scope versus block local variable scopes. 9 | */ 10 | public interface ILocalScope extends IScope { 11 | } 12 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ILocalVariable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package org.jrubyparser.ast; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Simple marker interface to indicate this node type is a type of local variable (block or local). 11 | */ 12 | public interface ILocalVariable extends INameNode { 13 | /** 14 | * Which Variable Scope does this variable belong to? Note that RootNode is a special ILocalScope 15 | * for the implicit scope created at top-level. 16 | * 17 | * @return the defined scope 18 | */ 19 | public IScope getDefinedScope(); 20 | 21 | /** 22 | * Retrieve the node which is responsible for declaring this one. This can be a variable 23 | * or a parameter. 24 | * 25 | * @return the declaration variable 26 | */ 27 | public ILocalVariable getDeclaration(); 28 | 29 | /** 30 | * Find all occurrences of this variable including itself. 31 | * 32 | * @return the list of all occurrences. 33 | */ 34 | public List getOccurrences(); 35 | } 36 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/IModuleScope.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Marker interface to indicate a Module/Class/SClass (all extend module in Ruby semantics). 7 | */ 8 | public interface IModuleScope { 9 | /** 10 | * Methods defined on the module. 11 | * 12 | * @return A List containing all the MethodDefNode's defined on a module. 13 | */ 14 | public List getMethodDefs(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/INameMatchable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package org.jrubyparser.ast; 6 | 7 | /** 8 | * A node of this type can determine whether it matches a supplied String name 9 | */ 10 | public interface INameMatchable { 11 | public boolean isNameMatch(String name); 12 | } 13 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/INameNode.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2009 Thomas E. Enebo 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jrubyparser.ast; 29 | 30 | import org.jrubyparser.SourcePosition; 31 | 32 | public interface INameNode extends INameMatchable { 33 | /** 34 | * Get the plain name without sigils. 35 | * 36 | * @return the name 37 | */ 38 | public String getName(); 39 | 40 | /** 41 | * Get the name including any leading sigils. 42 | * 43 | * @return the lexical name 44 | */ 45 | public String getLexicalName(); 46 | 47 | /** 48 | * Set the name (name should not include sigils). 49 | * 50 | * @param newName the new name 51 | */ 52 | public void setName(String newName); 53 | 54 | /** 55 | * The position of just the name part of the node. 56 | * 57 | * @return the names positions 58 | */ 59 | public SourcePosition getNamePosition(); 60 | 61 | /** 62 | * The position of the name + any sigils that come with it. 63 | * 64 | * @return the lexical names positions 65 | */ 66 | public SourcePosition getLexicalNamePosition(); 67 | } 68 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/IParameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package org.jrubyparser.ast; 6 | 7 | /** 8 | * For 1.9+ we can tell if a node is a parameter or not. This interface makes that 9 | * determination simpler. 10 | */ 11 | public interface IParameter extends ILocalVariable { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/IParameterScope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package org.jrubyparser.ast; 6 | 7 | /** 8 | * 9 | */ 10 | public interface IParameterScope { 11 | public boolean isParameterUsed(String name); 12 | public ILocalVariable getParameterNamed(String name); 13 | } 14 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/IScope.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Represents a variable scope (block or local). 7 | */ 8 | public interface IScope { 9 | public List getVariableReferencesNamed(String name); 10 | } 11 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/IScopingNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | public interface IScopingNode { 32 | public Colon3Node getCPath(); 33 | } 34 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ImplicitNilNode.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import org.jrubyparser.NodeVisitor; 4 | import org.jrubyparser.SourcePosition; 5 | 6 | /** 7 | * This node represent those strange places where we have what it a valid semantic element 8 | * but syntactically it is not there: [1, (), 3]. The parens here are syntax and evaluating 9 | * it will return nil but a nil is not actually there. 10 | */ 11 | public class ImplicitNilNode extends Node { 12 | public ImplicitNilNode(SourcePosition position) { 13 | super(position); 14 | } 15 | 16 | @Override 17 | public T accept(NodeVisitor visitor) { 18 | return visitor.visitImplicitNilNode(this); 19 | } 20 | 21 | @Override 22 | public NodeType getNodeType() { 23 | return NodeType.IMPLICITNILNODE; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/KeywordArgNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package org.jrubyparser.ast; 6 | 7 | import org.jrubyparser.NodeVisitor; 8 | import org.jrubyparser.SourcePosition; 9 | 10 | /** 11 | * 12 | * @author enebo 13 | */ 14 | public class KeywordArgNode extends Node { 15 | private AssignableNode assignable; 16 | 17 | public KeywordArgNode(SourcePosition position, AssignableNode assignable) { 18 | super(position); 19 | this.assignable = assignable; 20 | } 21 | 22 | 23 | /** 24 | * Checks node for 'sameness' for diffing. 25 | * 26 | * @param node to be compared to 27 | * @return Returns a boolean 28 | */ 29 | @Override 30 | public boolean isSame(Node node) { 31 | return super.isSame(node) && getAssignable().isSame(((KeywordArgNode) node).getAssignable()); 32 | } 33 | 34 | 35 | @Override 36 | public T accept(NodeVisitor visitor) { 37 | return visitor.visitKeywordArgNode(this); 38 | } 39 | 40 | @Override 41 | public NodeType getNodeType() { 42 | return NodeType.KEYWORDARGNODE; 43 | } 44 | 45 | public AssignableNode getAssignable() { 46 | return assignable; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/KeywordRestArgNode.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import org.jrubyparser.NodeVisitor; 4 | import org.jrubyparser.SourcePosition; 5 | 6 | /** 7 | * 8 | */ 9 | public class KeywordRestArgNode extends ArgumentNode { 10 | public KeywordRestArgNode(SourcePosition position, String name, int index) { 11 | super(position, name, index); 12 | } 13 | 14 | @Override 15 | public T accept(NodeVisitor visitor) { 16 | return visitor.visitKeywordRestArgNode(this); 17 | } 18 | 19 | @Override 20 | public NodeType getNodeType() { 21 | return NodeType.KEYWORDRESTARGNODE; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/LambdaNode.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2009 Thomas E. Enebo 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jrubyparser.ast; 29 | 30 | import org.jrubyparser.NodeVisitor; 31 | import org.jrubyparser.SourcePosition; 32 | import org.jrubyparser.StaticScope; 33 | 34 | /** 35 | * Stubby lambda node (1.9 only) 36 | */ 37 | public class LambdaNode extends IterNode { 38 | public LambdaNode(SourcePosition position, ArgsNode args, Node body, StaticScope scope) { 39 | super(position, args, body, scope); 40 | } 41 | 42 | @Override 43 | public NodeType getNodeType() { 44 | return NodeType.LAMBDANODE; 45 | } 46 | 47 | public ArgsNode getArgs() { 48 | return (ArgsNode)getVar(); 49 | } 50 | 51 | @Override 52 | public T accept(NodeVisitor visitor) { 53 | return visitor.visitLambdaNode(this); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/LiteralNode.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import org.jrubyparser.NodeVisitor; 4 | import org.jrubyparser.lexer.Token; 5 | 6 | /** 7 | * This is not a node in the classic sense in that it has no defined or 8 | * interpret method which can be called. It just stores the position of 9 | * the literal and the name/value of the literal. We made it a node so that 10 | * the parser needs to work less hard in its productions. dynamic literals 11 | * are nodes and by having literals also be nodes means they have a common 12 | * subtype which is not Object. 13 | */ 14 | public class LiteralNode extends Node { 15 | private String name; 16 | 17 | public LiteralNode(Token token) { 18 | super(token.getPosition()); 19 | 20 | this.name = (String) token.getValue(); 21 | } 22 | 23 | 24 | /** 25 | * Checks node for 'sameness' for diffing. 26 | * 27 | * @param node to be compared to 28 | * @return Returns a boolean 29 | */ 30 | @Override 31 | public boolean isSame(Node node) { 32 | return super.isSame(node) && getName().equals(((LiteralNode) node).getName()); 33 | } 34 | 35 | 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | /** 41 | * Accept for the visitor pattern. 42 | * @param iVisitor the visitor 43 | **/ 44 | public T accept(NodeVisitor iVisitor) { 45 | return iVisitor.visitLiteralNode(this); 46 | } 47 | 48 | @Override 49 | public NodeType getNodeType() { 50 | return NodeType.LITERALNODE; 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/MethodNameNode.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import org.jrubyparser.NodeVisitor; 4 | import org.jrubyparser.SourcePosition; 5 | 6 | /** 7 | * Node to hold string value of a methods name (for either Defn or Defs). 8 | */ 9 | public class MethodNameNode extends NamedNode { 10 | public MethodNameNode(SourcePosition position, String name) { 11 | super(position, name); 12 | } 13 | 14 | public NodeType getNodeType() { 15 | return NodeType.METHODNAMENODE; 16 | } 17 | 18 | public T accept(NodeVisitor visitor) { 19 | return visitor.visitMethodNameNode(this); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/NamedNode.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import org.jrubyparser.SourcePosition; 4 | 5 | /** 6 | * Nodes with string names are very common. 7 | */ 8 | public abstract class NamedNode extends Node implements INameNode { 9 | private String name; 10 | 11 | public NamedNode(SourcePosition position, String name) { 12 | super(position); 13 | 14 | assert name != null : "Name node with no null name"; 15 | 16 | this.name = name; 17 | } 18 | 19 | 20 | /** 21 | * Checks node for 'sameness' for diffing. 22 | * 23 | * @param node to be compared to 24 | * @return Returns a boolean 25 | */ 26 | @Override 27 | public boolean isSame(Node node) { 28 | return super.isSame(node) && isNameMatch(((NamedNode) node).getName()); 29 | } 30 | 31 | 32 | public String getLexicalName() { 33 | return getName(); 34 | } 35 | 36 | /** 37 | * Gets the name. 38 | * @return Returns a String 39 | */ 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | /** 45 | * Sets the name (for refactoring support) 46 | * @param name is the new name 47 | */ 48 | public void setName(String name) { 49 | this.name = name; 50 | } 51 | 52 | /** 53 | * Does the supplied name match this one? 54 | * @param testName name to match 55 | * @return true if the same name 56 | */ 57 | public boolean isNameMatch(String testName) { 58 | return name.equals(testName); 59 | } 60 | 61 | public SourcePosition getNamePosition() { 62 | return getPosition(); 63 | } 64 | 65 | public SourcePosition getLexicalNamePosition() { 66 | return getPosition(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/NextNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents a 'next' statement. 36 | */ 37 | public class NextNode extends Node { 38 | private Node valueNode; 39 | 40 | public NextNode(SourcePosition position, Node valueNode) { 41 | super(position); 42 | 43 | this.valueNode = adopt(valueNode); 44 | } 45 | 46 | public NodeType getNodeType() { 47 | return NodeType.NEXTNODE; 48 | } 49 | 50 | /** 51 | * Accept for the visitor pattern. 52 | * @param iVisitor the visitor 53 | **/ 54 | public T accept(NodeVisitor iVisitor) { 55 | return iVisitor.visitNextNode(this); 56 | } 57 | 58 | /** 59 | * Gets the valueNode. 60 | * @return Returns a Node 61 | */ 62 | public Node getValue() { 63 | return valueNode; 64 | } 65 | 66 | @Deprecated 67 | public Node getValueNode() { 68 | return getValue(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/NilNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * represents 'nil' 36 | */ 37 | public class NilNode extends BareKeywordNode { 38 | public NilNode(SourcePosition position) { 39 | super(position, "nil"); 40 | } 41 | 42 | public NodeType getNodeType() { 43 | return NodeType.NILNODE; 44 | } 45 | 46 | /** 47 | * Accept for the visitor pattern. 48 | * @param iVisitor the visitor 49 | **/ 50 | public T accept(NodeVisitor iVisitor) { 51 | return iVisitor.visitNilNode(this); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/NumericNode.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | 4 | import org.jrubyparser.SourcePosition; 5 | 6 | /** 7 | * Any node representing a numeric value. 8 | */ 9 | public abstract class NumericNode extends Node implements ILiteralNode { 10 | public NumericNode(SourcePosition position) { 11 | super(position); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/OpAsgnAndNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | public class OpAsgnAndNode extends BinaryOperatorBaseNode { 35 | public OpAsgnAndNode(SourcePosition position, Node headNode, Node valueNode) { 36 | super(position, headNode, valueNode); 37 | } 38 | 39 | @Override 40 | public NodeType getNodeType() { 41 | return NodeType.OPASGNANDNODE; 42 | } 43 | 44 | /** 45 | * Accept for the visitor pattern. 46 | * @param iVisitor the visitor 47 | **/ 48 | public T accept(NodeVisitor iVisitor) { 49 | return iVisitor.visitOpAsgnAndNode(this); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/OpAsgnOrNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | public class OpAsgnOrNode extends BinaryOperatorBaseNode { 35 | public OpAsgnOrNode(SourcePosition position, Node headNode, Node valueNode) { 36 | super(position, headNode, valueNode); 37 | } 38 | 39 | @Override 40 | public NodeType getNodeType() { 41 | return NodeType.OPASGNORNODE; 42 | } 43 | 44 | /** 45 | * Accept for the visitor pattern. 46 | * @param iVisitor the visitor 47 | **/ 48 | public T accept(NodeVisitor iVisitor) { 49 | return iVisitor.visitOpAsgnOrNode(this); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/OpElementAsgnAndNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2013 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.SourcePosition; 32 | 33 | /** 34 | * 35 | */ 36 | public class OpElementAsgnAndNode extends OpElementAsgnNode { 37 | public OpElementAsgnAndNode(SourcePosition position, Node receiverNode, String operatorName, Node argsNode, Node valueNode) { 38 | super(position, receiverNode, operatorName, argsNode, valueNode); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/OpElementAsgnOrNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2013 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.SourcePosition; 32 | 33 | /** 34 | * 35 | */ 36 | public class OpElementAsgnOrNode extends OpElementAsgnNode { 37 | public OpElementAsgnOrNode(SourcePosition position, Node receiverNode, String operatorName, Node argsNode, Node valueNode) { 38 | super(position, receiverNode, operatorName, argsNode, valueNode); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/OrNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * represents '||' (or) statements 36 | */ 37 | public class OrNode extends BinaryOperatorBaseNode { 38 | public OrNode(SourcePosition position, Node firstNode, Node secondNode) { 39 | super(position, firstNode, secondNode); 40 | } 41 | 42 | @Override 43 | public NodeType getNodeType() { 44 | return NodeType.ORNODE; 45 | } 46 | 47 | /** 48 | * Accept for the visitor pattern. 49 | * @param iVisitor the visitor 50 | **/ 51 | public T accept(NodeVisitor iVisitor) { 52 | return iVisitor.visitOrNode(this); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/PostExeNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Captures END statements (END {...}) 36 | */ 37 | public class PostExeNode extends IterNode { 38 | public PostExeNode(SourcePosition position, Node body) { 39 | super(position, null, null, body); 40 | } 41 | 42 | @Override 43 | public NodeType getNodeType() { 44 | return NodeType.POSTEXENODE; 45 | } 46 | 47 | /** 48 | * Accept for the visitor pattern. 49 | * @param iVisitor the visitor 50 | **/ 51 | @Override 52 | public T accept(NodeVisitor iVisitor) { 53 | return iVisitor.visitPostExeNode(this); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/PreExe19Node.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2007 Thomas E Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | import org.jrubyparser.StaticScope; 34 | 35 | /** 36 | * A pre-execution construction (BEGIN { ... }). 37 | */ 38 | public class PreExe19Node extends PreExeNode { 39 | public PreExe19Node(SourcePosition position, StaticScope scope, Node body) { 40 | super(position, scope, body); 41 | } 42 | 43 | @Override 44 | public NodeType getNodeType() { 45 | return NodeType.PREEXENODE; 46 | } 47 | 48 | @Override 49 | public T accept(NodeVisitor iVisitor) { 50 | return iVisitor.visitPreExeNode(this); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/PreExeNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | import org.jrubyparser.StaticScope; 34 | 35 | /** 36 | * A pre-execution construction (BEGIN { ... }). 37 | */ 38 | public class PreExeNode extends IterNode { 39 | public PreExeNode(SourcePosition position, StaticScope scope, Node body) { 40 | super(position, null, scope, body); 41 | } 42 | 43 | @Override 44 | public NodeType getNodeType() { 45 | return NodeType.PREEXENODE; 46 | } 47 | 48 | @Override 49 | public T accept(NodeVisitor iVisitor) { 50 | return iVisitor.visitPreExeNode(this); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/RationalNode.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import java.util.List; 4 | import org.jrubyparser.NodeVisitor; 5 | import org.jrubyparser.SourcePosition; 6 | 7 | /** 8 | * Created by enebo on 5/21/15. 9 | */ 10 | public class RationalNode extends NumericNode { 11 | private final long numerator; 12 | private final long denominator; 13 | 14 | public RationalNode(SourcePosition position, long numerator, long denominator) { 15 | super(position); 16 | 17 | this.numerator = numerator; 18 | this.denominator = denominator; 19 | } 20 | 21 | @Override 22 | public T accept(NodeVisitor visitor) { 23 | return visitor.visitRationalNode(this); 24 | } 25 | 26 | @Override 27 | public NodeType getNodeType() { 28 | return NodeType.RATIONALNODE; 29 | } 30 | 31 | public long getNumerator() { 32 | return numerator; 33 | } 34 | 35 | public long getDenominator() { 36 | return denominator; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/RedoNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents a 'redo' 36 | */ 37 | public class RedoNode extends Node { 38 | public RedoNode(SourcePosition position) { 39 | super(position); 40 | } 41 | 42 | public NodeType getNodeType() { 43 | return NodeType.REDONODE; 44 | } 45 | 46 | /** 47 | * Accept for the visitor pattern. 48 | * @param iVisitor the visitor 49 | **/ 50 | public T accept(NodeVisitor iVisitor) { 51 | return iVisitor.visitRedoNode(this); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/RequiredKeywordArgumentValueNode.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import org.jrubyparser.NodeVisitor; 6 | import org.jrubyparser.SourcePosition; 7 | 8 | /** 9 | * Marker to indicate that rather than assigning nil (where in multiple 10 | * places we have nulls getting implicitly converted to nils) we should 11 | * raise an error. 12 | * 13 | * MRI passes a -1 as a special value so we are doing something similar 14 | * but more explicit. 15 | */ 16 | public class RequiredKeywordArgumentValueNode extends Node { 17 | public RequiredKeywordArgumentValueNode(SourcePosition position) { 18 | super(position); 19 | } 20 | 21 | @Override 22 | public T accept(NodeVisitor visitor) { 23 | return visitor.visitRequiredKeywordArgumentValueNode(this); 24 | } 25 | 26 | @Override 27 | public List childNodes() { 28 | return Collections.emptyList(); 29 | } 30 | 31 | @Override 32 | public NodeType getNodeType() { 33 | return NodeType.REQUIREDKEYWORDARGNODE; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/RetryNode.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2009 Thomas E. Enebo 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | package org.jrubyparser.ast; 29 | 30 | import org.jrubyparser.NodeVisitor; 31 | import org.jrubyparser.SourcePosition; 32 | 33 | /** 34 | * Represents a 'retry' statement. 35 | */ 36 | public class RetryNode extends Node { 37 | public RetryNode(SourcePosition position) { 38 | super(position); 39 | } 40 | 41 | public NodeType getNodeType() { 42 | return NodeType.RETRYNODE; 43 | } 44 | 45 | /** 46 | * Accept for the visitor pattern. 47 | * @param iVisitor the visitor 48 | **/ 49 | public T accept(NodeVisitor iVisitor) { 50 | return iVisitor.visitRetryNode(this); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/SValueNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | public class SValueNode extends Node { 35 | private Node node; 36 | 37 | public SValueNode(SourcePosition position, Node node) { 38 | super(position); 39 | 40 | assert node != null : "node is not null"; 41 | 42 | this.node = adopt(node); 43 | } 44 | 45 | @Override 46 | public boolean isSame(Node other) { 47 | return super.isSame(other) && getValue().isSame(((SValueNode) other).getValue()); 48 | } 49 | 50 | public NodeType getNodeType() { 51 | return NodeType.SVALUENODE; 52 | } 53 | 54 | public T accept(NodeVisitor visitor) { 55 | return visitor.visitSValueNode(this); 56 | } 57 | 58 | public Node getValue() { 59 | return node; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/SelfNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents 'self' keyword 36 | */ 37 | public class SelfNode extends BareKeywordNode { 38 | public SelfNode(SourcePosition position) { 39 | super(position, "self"); 40 | } 41 | 42 | public NodeType getNodeType() { 43 | return NodeType.SELFNODE; 44 | } 45 | 46 | /** 47 | * Accept for the visitor pattern. 48 | * @param iVisitor the visitor 49 | **/ 50 | public T accept(NodeVisitor iVisitor) { 51 | return iVisitor.visitSelfNode(this); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/SplatNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | public class SplatNode extends Node { 35 | private Node node; 36 | 37 | public SplatNode(SourcePosition position, Node node) { 38 | super(position); 39 | 40 | assert node != null : "node is not null"; 41 | 42 | this.node = adopt(node); 43 | } 44 | 45 | @Override 46 | public boolean isSame(Node other) { 47 | return super.isSame(other) && getValue().isSame(((SplatNode) other).getValue()); 48 | } 49 | 50 | public NodeType getNodeType() { 51 | return NodeType.SPLATNODE; 52 | } 53 | 54 | public T accept(NodeVisitor visitor) { 55 | return visitor.visitSplatNode(this); 56 | } 57 | 58 | public Node getValue() { 59 | return node; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/StarNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents the unassignable star in a multiple assignent (e.g. a,b,* = arr). 36 | * 37 | * AssignmentVisitor.multiAssign checks for this (this is never visited directly) 38 | */ 39 | public class StarNode extends Node { 40 | /** 41 | * Constructor for StarNode. 42 | * @param position the position 43 | */ 44 | public StarNode(SourcePosition position) { 45 | super(position); 46 | } 47 | 48 | public NodeType getNodeType() { 49 | return NodeType.STARNODE; 50 | } 51 | 52 | /** 53 | * @see Node#accept(NodeVisitor) 54 | */ 55 | public T accept(NodeVisitor visitor) { 56 | return null; // never visited, should be fine 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/SymbolNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | //FIXME: I don't think this should be a namednode/inamenode but I need to audit how it is used. 35 | /** 36 | * Represents a symbol (:symbol_name). 37 | */ 38 | public class SymbolNode extends NamedNode implements ILiteralNode, INameNode { 39 | public SymbolNode(SourcePosition position, String name) { 40 | super(position, name); 41 | } 42 | 43 | public NodeType getNodeType() { 44 | return NodeType.SYMBOLNODE; 45 | } 46 | 47 | public T accept(NodeVisitor iVisitor) { 48 | return iVisitor.visitSymbolNode(this); 49 | } 50 | 51 | @Override 52 | public String getLexicalName() { 53 | return ":" + getName(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ToAryNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | // 1.8-only node 35 | public class ToAryNode extends Node { 36 | private Node node; 37 | 38 | public ToAryNode(SourcePosition position, Node node) { 39 | super(position); 40 | 41 | this.node = adopt(node); 42 | } 43 | 44 | public NodeType getNodeType() { 45 | return NodeType.TOARYNODE; 46 | } 47 | 48 | public T accept(NodeVisitor visitor) { 49 | return visitor.visitToAryNode(this); 50 | } 51 | 52 | public Node getValue() { 53 | return node; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/TrueNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents 'true'. 36 | */ 37 | public class TrueNode extends BareKeywordNode { 38 | public TrueNode(SourcePosition position) { 39 | super(position, "true"); 40 | } 41 | 42 | public NodeType getNodeType() { 43 | return NodeType.TRUENODE; 44 | } 45 | 46 | /** 47 | * Accept for the visitor pattern. 48 | * @param iVisitor the visitor 49 | **/ 50 | public T accept(NodeVisitor iVisitor) { 51 | return iVisitor.visitTrueNode(this); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/TypedArgumentNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package org.jrubyparser.ast; 7 | 8 | import org.jrubyparser.SourcePosition; 9 | 10 | /** 11 | * 12 | * @author enebo 13 | */ 14 | public class TypedArgumentNode extends ArgumentNode { 15 | private Node typeNode; 16 | 17 | public TypedArgumentNode(SourcePosition position, String identifier, Node typeNode) { 18 | super(position, identifier); 19 | 20 | this.typeNode = adopt(typeNode); 21 | } 22 | 23 | public Node getTypeNode() { 24 | return typeNode; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/UndefNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * Represents an 'undef' statement. 36 | */ 37 | public class UndefNode extends Node { 38 | private Node name; 39 | 40 | public UndefNode(SourcePosition position, Node name) { 41 | super(position); 42 | this.name = adopt(name); 43 | } 44 | 45 | @Override 46 | public boolean isSame(Node other) { 47 | return super.isSame(other) && getName().isSame(((UndefNode) other).getName()); 48 | } 49 | 50 | public NodeType getNodeType() { 51 | return NodeType.UNDEFNODE; 52 | } 53 | 54 | /** 55 | * Accept for the visitor pattern. 56 | * @param iVisitor the visitor 57 | **/ 58 | public T accept(NodeVisitor iVisitor) { 59 | return iVisitor.visitUndefNode(this); 60 | } 61 | 62 | /** 63 | * Gets the name. 64 | * @return Returns a String 65 | */ 66 | public Node getName() { 67 | return name; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/UnnamedRestArgNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.SourcePosition; 32 | 33 | /** 34 | * a bare '*' 35 | */ 36 | public class UnnamedRestArgNode extends RestArgNode { 37 | public UnnamedRestArgNode(SourcePosition position, String name, int index) { 38 | super(position, name, index); 39 | } 40 | 41 | public UnnamedRestArgNode(SourcePosition position, int index) { 42 | this(position, "", index); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/VCallNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * RubyMethod call without any arguments 36 | */ 37 | public class VCallNode extends NamedNode implements INameNode { 38 | public VCallNode(SourcePosition position, String name) { 39 | super(position, name); 40 | } 41 | 42 | public NodeType getNodeType() { 43 | return NodeType.VCALLNODE; 44 | } 45 | 46 | /** 47 | * Accept for the visitor pattern. 48 | * @param iVisitor the visitor 49 | **/ 50 | public T accept(NodeVisitor iVisitor) { 51 | return iVisitor.visitVCallNode(this); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ZArrayNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** 35 | * 36 | * zero length list 37 | * 38 | */ 39 | public class ZArrayNode extends Node implements ILiteralNode { 40 | public ZArrayNode(SourcePosition position) { 41 | super(position); 42 | } 43 | 44 | public NodeType getNodeType() { 45 | return NodeType.ZARRAYNODE; 46 | } 47 | 48 | /** 49 | * Accept for the visitor pattern. 50 | * @param iVisitor the visitor 51 | **/ 52 | public T accept(NodeVisitor iVisitor) { 53 | return iVisitor.visitZArrayNode(this); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ZYieldNode.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.ast; 2 | 3 | import org.jrubyparser.SourcePosition; 4 | 5 | /** 6 | * A Yield node with no parens 7 | */ 8 | public class ZYieldNode extends YieldNode { 9 | public ZYieldNode(SourcePosition position) { 10 | super(position, null, true); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/org/jrubyparser/ast/ZeroArgNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E. Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.ast; 30 | 31 | import org.jrubyparser.NodeVisitor; 32 | import org.jrubyparser.SourcePosition; 33 | 34 | /** Represents a zero arg in a block. 35 | * this is never visited and is used only in an instanceof check 36 | *
37 |  * do ||
38 |  * end
39 |  * 
40 | * 41 | */ 42 | public class ZeroArgNode extends Node { 43 | public ZeroArgNode(SourcePosition position) { 44 | super(position); 45 | } 46 | 47 | public NodeType getNodeType() { 48 | return NodeType.ZEROARGNODE; 49 | } 50 | 51 | /** 52 | * @see Node#accept(NodeVisitor) 53 | */ 54 | public T accept(NodeVisitor visitor) { 55 | return null; // never visited, should be ok 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/org/jrubyparser/lexer/StackState.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2002 Jan Arne Petersen 15 | * Copyright (C) 2004 Stefan Matthias Aust 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.lexer; 30 | 31 | /** 32 | * 33 | * @author jpetersen 34 | */ 35 | public class StackState implements Cloneable { 36 | private long stack = 0; 37 | 38 | public void reset() { 39 | reset(0); 40 | } 41 | 42 | public void reset(long backup) { 43 | stack = backup; 44 | } 45 | 46 | // PUSH(1) 47 | public long begin() { 48 | long old = stack; 49 | stack <<= 1; 50 | stack |= 1; 51 | return old; 52 | } 53 | 54 | // POP 55 | public void end() { 56 | stack >>= 1; 57 | } 58 | 59 | // PUSH(0). If you look at original macro: stack |= (n&1) => stack |= 0 => no-change. 60 | public void stop() { 61 | stack <<= 1; 62 | } 63 | 64 | // LEXPOP 65 | public void restart() { 66 | stack |= (stack & 1) << 1; 67 | stack >>= 1; 68 | } 69 | 70 | // SET_P 71 | public boolean isInState() { 72 | return (stack & 1) != 0; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/org/jrubyparser/parser/ArgsTailHolder.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.parser; 2 | 3 | import org.jrubyparser.ISourcePositionHolder; 4 | import org.jrubyparser.SourcePosition; 5 | import org.jrubyparser.ast.BlockArgNode; 6 | import org.jrubyparser.ast.KeywordRestArgNode; 7 | import org.jrubyparser.ast.ListNode; 8 | 9 | /** 10 | * Simple struct to hold values until they can be inserted into the AST. 11 | */ 12 | public class ArgsTailHolder implements ISourcePositionHolder { 13 | private SourcePosition position; 14 | private BlockArgNode blockArg; 15 | private ListNode keywordArgs; 16 | private KeywordRestArgNode keywordRestArg; 17 | 18 | public ArgsTailHolder(SourcePosition position, ListNode keywordArgs, 19 | KeywordRestArgNode keywordRestArg, BlockArgNode blockArg) { 20 | this.position = position; 21 | this.blockArg = blockArg; 22 | this.keywordArgs = keywordArgs; 23 | this.keywordRestArg = keywordRestArg; 24 | } 25 | 26 | public SourcePosition getPosition() { 27 | return position; 28 | } 29 | 30 | public void setPosition(SourcePosition position) { 31 | this.position = position; 32 | } 33 | 34 | public BlockArgNode getBlockArg() { 35 | return blockArg; 36 | } 37 | 38 | public ListNode getKeywordArgs() { 39 | return keywordArgs; 40 | } 41 | 42 | public KeywordRestArgNode getKeywordRestArgNode() { 43 | return keywordRestArg; 44 | } 45 | 46 | /** 47 | * Does this holder support either keyword argument types 48 | * @return true if there are keyword args 49 | */ 50 | public boolean hasKeywordArgs() { 51 | return keywordArgs != null || keywordRestArg != null; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/org/jrubyparser/parser/ParserState.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.parser; 2 | 3 | import org.jrubyparser.lexer.Lexer; 4 | 5 | public interface ParserState { 6 | public Object execute(ParserSupport support, Lexer lexer, Object yyVal, Object[] yyVals, int yyTop); 7 | } 8 | -------------------------------------------------------------------------------- /src/org/jrubyparser/parser/ReOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2009 Thomas E Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.parser; 30 | 31 | public interface ReOptions { 32 | int RE_OPTION_IGNORECASE = 1; 33 | int RE_OPTION_EXTENDED = 2; 34 | int RE_OPTION_MULTILINE = 4; 35 | int RE_OPTION_SINGLELINE = 8; 36 | int RE_OPTION_POSIXLINE = (RE_OPTION_MULTILINE | RE_OPTION_SINGLELINE); 37 | int RE_OPTION_LONGEST = 16; 38 | int RE_MAY_IGNORECASE = 32; 39 | int RE_UNICODE = 64; 40 | int RE_OPTION_ONCE = 0x80; // odd...but it is odd in ruby too. 41 | } 42 | -------------------------------------------------------------------------------- /src/org/jrubyparser/parser/RubyParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | ***** BEGIN LICENSE BLOCK ***** 3 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Common Public 6 | * License Version 1.0 (the "License"); you may not use this file 7 | * except in compliance with the License. You may obtain a copy of 8 | * the License at http://www.eclipse.org/legal/cpl-v10.html 9 | * 10 | * Software distributed under the License is distributed on an "AS 11 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 12 | * implied. See the License for the specific language governing 13 | * rights and limitations under the License. 14 | * 15 | * Copyright (C) 2008 Thomas E Enebo 16 | * 17 | * Alternatively, the contents of this file may be used under the terms of 18 | * either of the GNU General Public License Version 2 or later (the "GPL"), 19 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 20 | * in which case the provisions of the GPL or the LGPL are applicable instead 21 | * of those above. If you wish to allow use of your version of this file only 22 | * under the terms of either the GPL or the LGPL, and not to allow others to 23 | * use your version of this file under the terms of the CPL, indicate your 24 | * decision by deleting the provisions above and replace them with the notice 25 | * and other provisions required by the GPL or the LGPL. If you do not delete 26 | * the provisions above, a recipient may use your version of this file under 27 | * the terms of any one of the CPL, the GPL or the LGPL. 28 | ***** END LICENSE BLOCK *****/ 29 | package org.jrubyparser.parser; 30 | 31 | import java.io.IOException; 32 | import org.jrubyparser.IRubyWarnings; 33 | import org.jrubyparser.lexer.LexerSource; 34 | 35 | /** 36 | * Common interface specifying the contract of Ruby parsers (1.8.6 + 1.9) 37 | */ 38 | public interface RubyParser { 39 | public ParserResult parse(ParserConfiguration configuration, LexerSource source) throws IOException; 40 | public void setWarnings(IRubyWarnings warnings); 41 | } 42 | -------------------------------------------------------------------------------- /src/org/jrubyparser/parser/YyTables.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.parser; 2 | 3 | public class YyTables { 4 | private static short[] combine(short[] t1, short[] t2, 5 | short[] t3, short[] t4) { 6 | short[] t = new short[t1.length + t2.length + t3.length + t4.length]; 7 | int index = 0; 8 | System.arraycopy(t1, 0, t, index, t1.length); 9 | index += t1.length; 10 | System.arraycopy(t2, 0, t, index, t2.length); 11 | index += t2.length; 12 | System.arraycopy(t3, 0, t, index, t3.length); 13 | index += t3.length; 14 | System.arraycopy(t4, 0, t, index, t4.length); 15 | return t; 16 | } 17 | 18 | public static final short[] yyTable() { 19 | return combine(yyTable1(), yyTable2(), yyTable3(), yyTable4()); 20 | } 21 | 22 | public static final short[] yyCheck() { 23 | return combine(yyCheck1(), yyCheck2(), yyCheck3(), yyCheck4()); 24 | } 25 | private static final short[] yyTable1() { 26 | return new short[] { 27 | 28 | }; 29 | } 30 | 31 | private static final short[] yyTable2() { 32 | return new short[] { 33 | 34 | }; 35 | } 36 | 37 | private static final short[] yyTable3() { 38 | return new short[] { 39 | 40 | }; 41 | } 42 | 43 | private static final short[] yyTable4() { 44 | return new short[] { 45 | 46 | }; 47 | } 48 | 49 | private static final short[] yyCheck1() { 50 | return new short[] { 51 | 52 | }; 53 | } 54 | 55 | private static final short[] yyCheck2() { 56 | return new short[] { 57 | 58 | }; 59 | } 60 | 61 | private static final short[] yyCheck3() { 62 | return new short[] { 63 | 64 | }; 65 | } 66 | 67 | private static final short[] yyCheck4() { 68 | return new short[] { 69 | 70 | }; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/ClassBodyWriter.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.rewriter; 2 | 3 | import java.util.Iterator; 4 | 5 | import org.jrubyparser.ast.BlockNode; 6 | import org.jrubyparser.ast.NewlineNode; 7 | import org.jrubyparser.ast.Node; 8 | import org.jrubyparser.rewriter.utils.ReWriterContext; 9 | 10 | 11 | public class ClassBodyWriter { 12 | private ReWriteVisitor visitor; 13 | private Node bodyNode; 14 | private ReWriterContext context; 15 | 16 | public ClassBodyWriter(ReWriteVisitor visitor, Node bodyNode) { 17 | this.visitor = visitor; 18 | this.bodyNode = bodyNode; 19 | this.context = visitor.getConfig(); 20 | } 21 | 22 | public void write(){ 23 | if (bodyNode instanceof BlockNode) { 24 | context.getIndentor().indent(); 25 | writeContent((BlockNode) bodyNode); 26 | context.getIndentor().outdent(); 27 | } else if (bodyNode instanceof NewlineNode) { 28 | visitor.visitNodeInIndentation(bodyNode); 29 | } else { 30 | visitor.visitNode(bodyNode); 31 | } 32 | } 33 | 34 | private void writeContent(BlockNode node) { 35 | for (Iterator it = node.childNodes().iterator(); it.hasNext(); ) { 36 | visitor.visitNode(it.next()); 37 | 38 | if (it.hasNext()) { 39 | context.getOutput().print(context.getFormatHelper().classBodyElementsSeparator()); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/FormatHelper.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.rewriter; 2 | 3 | import org.jrubyparser.rewriter.utils.Indenter; 4 | 5 | public interface FormatHelper { 6 | 7 | public abstract Indenter getIndenter(); 8 | 9 | public abstract String getListSeparator(); 10 | 11 | public abstract String beforeCallArguments(); 12 | 13 | public abstract String afterCallArguments(); 14 | 15 | public abstract String beforeMethodArguments(); 16 | 17 | public abstract String afterMethodArguments(); 18 | 19 | public abstract String hashAssignment(); 20 | 21 | public abstract String beforeHashContent(); 22 | 23 | public abstract String afterHashContent(); 24 | 25 | public abstract String matchOperator(); 26 | 27 | public abstract String beforeAssignment(); 28 | 29 | public abstract String beforeIterBrackets(); 30 | 31 | public abstract String afterAssignment(); 32 | 33 | public abstract String beforeIterVars(); 34 | 35 | public abstract String afterIterVars(); 36 | 37 | public abstract String beforeClosingIterBrackets(); 38 | 39 | public abstract String classBodyElementsSeparator(); 40 | 41 | public abstract String getLineDelimiter(); 42 | } 43 | -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/utils/BooleanStateStack.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Mirko Stocker 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | 29 | package org.jrubyparser.rewriter.utils; 30 | 31 | import java.util.EmptyStackException; 32 | import java.util.Stack; 33 | 34 | public class BooleanStateStack { 35 | 36 | private final Stack states = new Stack(); 37 | private final boolean defaultValue; 38 | 39 | 40 | public BooleanStateStack(boolean b, boolean defaultValue) { 41 | set(b); 42 | this.defaultValue = defaultValue; 43 | } 44 | 45 | public void set(boolean b) { 46 | states.push(Boolean.valueOf(b)); 47 | } 48 | 49 | public void revert() { 50 | states.pop(); 51 | } 52 | 53 | public boolean isTrue() { 54 | try { 55 | return ((Boolean) states.peek()).booleanValue(); 56 | } catch (EmptyStackException e) { 57 | return defaultValue; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/utils/CallDepth.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Mirko Stocker 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | 29 | package org.jrubyparser.rewriter.utils; 30 | 31 | public class CallDepth { 32 | private int nestedCallDepth; 33 | private int savedNestedCallDepth; 34 | 35 | public void enterCall() { 36 | nestedCallDepth++; 37 | } 38 | 39 | public void leaveCall() { 40 | nestedCallDepth--; 41 | if (nestedCallDepth < 0) nestedCallDepth = 0; 42 | } 43 | 44 | public boolean inCall() { 45 | return nestedCallDepth > 0; 46 | } 47 | 48 | /* 49 | * Those methods are used do disable the output of parantheses in arguments 50 | * of operator-calls 51 | */ 52 | public void disableCallDepth() { 53 | savedNestedCallDepth = nestedCallDepth; 54 | nestedCallDepth = 0; 55 | } 56 | 57 | public void enableCallDepth() { 58 | nestedCallDepth = savedNestedCallDepth; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/utils/DRegxReWriteVisitor.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Mirko Stocker 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | 29 | package org.jrubyparser.rewriter.utils; 30 | 31 | import org.jrubyparser.rewriter.ReWriteVisitor; 32 | 33 | 34 | public class DRegxReWriteVisitor extends ReWriteVisitor { 35 | 36 | public DRegxReWriteVisitor(ReWriterContext config) { 37 | super(config); 38 | } 39 | 40 | @Override 41 | protected boolean inDRegxNode() { 42 | return true; 43 | } 44 | } -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/utils/HereDocReWriteVisitor.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Mirko Stocker 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | 29 | package org.jrubyparser.rewriter.utils; 30 | 31 | import org.jrubyparser.ast.StrNode; 32 | import org.jrubyparser.rewriter.ReWriteVisitor; 33 | 34 | public class HereDocReWriteVisitor extends ReWriteVisitor { 35 | 36 | public HereDocReWriteVisitor(ReWriterContext config) { 37 | super(config); 38 | } 39 | 40 | @Override 41 | public Object visitStrNode(StrNode iVisited) { 42 | print(iVisited.getValue().toString()); 43 | return null; 44 | } 45 | } -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/utils/HereDocument.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Mirko Stocker 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | 29 | package org.jrubyparser.rewriter.utils; 30 | 31 | public class HereDocument { 32 | 33 | public String content; 34 | private ReWriterContext config; 35 | 36 | public HereDocument(String content, ReWriterContext config) { 37 | super(); 38 | this.content = content; 39 | this.config = config; 40 | } 41 | 42 | public String getContent() { 43 | return content; 44 | } 45 | 46 | public void print() { 47 | config.setSkipNextNewline(false); 48 | config.getOutput().print('\n'); 49 | config.getOutput().print(getContent()); 50 | config.getIndentor().printIndentation(config.getOutput()); 51 | config.getOutput().print("EOF"); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/utils/IgnoreCommentsReWriteVisitor.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Mirko Stocker 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | 29 | package org.jrubyparser.rewriter.utils; 30 | 31 | import org.jrubyparser.ast.CommentNode; 32 | import org.jrubyparser.rewriter.ReWriteVisitor; 33 | 34 | public class IgnoreCommentsReWriteVisitor extends ReWriteVisitor { 35 | public IgnoreCommentsReWriteVisitor(ReWriterContext config) { 36 | super(config); 37 | } 38 | 39 | @Override 40 | public Object visitCommentNode(CommentNode iVisited) { 41 | return null; 42 | } 43 | } -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/utils/LocalVariables.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Mirko Stocker 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | 29 | package org.jrubyparser.rewriter.utils; 30 | 31 | import java.util.HashMap; 32 | 33 | import org.jrubyparser.StaticScope; 34 | 35 | public class LocalVariables { 36 | 37 | private final HashMap localVariablesMap = new HashMap(); 38 | 39 | public void addLocalVariable(int count, String name) { 40 | localVariablesMap.put(new Integer(count), name); 41 | } 42 | 43 | public void addLocalVariable(StaticScope scope) { 44 | for (int i = 0; i < scope.getVariables().length; i++) { 45 | addLocalVariable(i, scope.getVariables()[i]); 46 | } 47 | } 48 | 49 | public String getLocalVariable(int index) { 50 | return (String) localVariablesMap.get(new Integer(index)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/utils/MultipleAssignmentReWriteVisitor.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Mirko Stocker 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | 29 | package org.jrubyparser.rewriter.utils; 30 | 31 | import java.util.Iterator; 32 | 33 | import org.jrubyparser.ast.ArgumentNode; 34 | import org.jrubyparser.ast.Node; 35 | import org.jrubyparser.rewriter.ReWriteVisitor; 36 | 37 | public class MultipleAssignmentReWriteVisitor extends ReWriteVisitor { 38 | 39 | public MultipleAssignmentReWriteVisitor(ReWriterContext config) { 40 | super(config); 41 | } 42 | 43 | @Override 44 | protected void printAssignmentOperator() { 45 | } 46 | 47 | @Override 48 | protected boolean inMultipleAssignment() { 49 | return true; 50 | } 51 | 52 | // This might lead to a problem with comments 53 | @Override 54 | public void visitAndPrintWithSeparator(Iterator it) { 55 | while (it.hasNext()) { 56 | Node n = (Node) it.next(); 57 | if(n instanceof ArgumentNode) { 58 | config.getOutput().print(((ArgumentNode) n).getName()); 59 | } else { 60 | visitNode(n); 61 | } 62 | if (it.hasNext()) 63 | print(", "); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/utils/Operators.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Mirko Stocker 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | 29 | package org.jrubyparser.rewriter.utils; 30 | 31 | import java.util.HashSet; 32 | 33 | public class Operators { 34 | 35 | private static HashSet operatorSet = new HashSet(); 36 | static { 37 | String[] operators = new String[] { "**", "<=>", "==", "=~", "===", ">=", "<=", "&", "%", 38 | "/", "+", "-", "*", "<", ">", "<<", ">>", "|"}; 39 | 40 | for(int i = 0; i < operators.length; i++) { 41 | operatorSet.add(operators[i]); 42 | } 43 | } 44 | 45 | public static boolean contain(String name) { 46 | return operatorSet.contains(name); 47 | } 48 | } -------------------------------------------------------------------------------- /src/org/jrubyparser/rewriter/utils/ShortIfNodeReWriteVisitor.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: CPL 1.0/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Common Public 5 | * License Version 1.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/cpl-v10.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2006 Mirko Stocker 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * either of the GNU General Public License Version 2 or later (the "GPL"), 18 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 19 | * in which case the provisions of the GPL or the LGPL are applicable instead 20 | * of those above. If you wish to allow use of your version of this file only 21 | * under the terms of either the GPL or the LGPL, and not to allow others to 22 | * use your version of this file under the terms of the CPL, indicate your 23 | * decision by deleting the provisions above and replace them with the notice 24 | * and other provisions required by the GPL or the LGPL. If you do not delete 25 | * the provisions above, a recipient may use your version of this file under 26 | * the terms of any one of the CPL, the GPL or the LGPL. 27 | ***** END LICENSE BLOCK *****/ 28 | 29 | package org.jrubyparser.rewriter.utils; 30 | 31 | import org.jrubyparser.ast.NewlineNode; 32 | import org.jrubyparser.rewriter.ReWriteVisitor; 33 | 34 | public class ShortIfNodeReWriteVisitor extends ReWriteVisitor { 35 | 36 | public ShortIfNodeReWriteVisitor(ReWriterContext config) { 37 | super(config); 38 | } 39 | 40 | @Override 41 | protected void printNewlineAndIndentation() { 42 | print("; "); 43 | } 44 | 45 | @Override 46 | public Object visitNewlineNode(NewlineNode iVisited) { 47 | if (config.getSource().charAt(getEndOffset(iVisited) - 1) == ')') { 48 | print('('); 49 | visitNode(iVisited.getNextNode()); 50 | print(')'); 51 | } else { 52 | print("; "); 53 | visitNode(iVisited.getNextNode()); 54 | } 55 | return null; 56 | } 57 | } -------------------------------------------------------------------------------- /src/org/jrubyparser/util/CStringBuilder.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.util; 2 | 3 | /** 4 | * The sole purpose of this builder is to allow append(int) do a forced cast to a char. 5 | * Our lexer returns int's for each character and builder till convert ints to base-10 6 | * decimal strings. This just makes things less error-prone 7 | */ 8 | public class CStringBuilder implements CharSequence { 9 | private java.lang.StringBuilder builder; 10 | 11 | public CStringBuilder() { 12 | builder = new java.lang.StringBuilder(); 13 | } 14 | 15 | public CStringBuilder(int capacity) { 16 | builder = new java.lang.StringBuilder(capacity); 17 | } 18 | 19 | public CStringBuilder(String initialValue) { 20 | builder = new java.lang.StringBuilder(initialValue); 21 | } 22 | 23 | /** 24 | * This will assume the passed in int is in fact a char. 25 | * @param value char to be consumed 26 | * @return the builder 27 | */ 28 | public CStringBuilder append(int value) { 29 | builder.append((char) value); 30 | 31 | return this; 32 | } 33 | 34 | public CStringBuilder append(byte[] values) { 35 | builder.append(values); 36 | 37 | return this; 38 | } 39 | 40 | public CStringBuilder append(String value) { 41 | builder.append(value); 42 | 43 | return this; 44 | } 45 | 46 | 47 | public CStringBuilder append(boolean value) { 48 | builder.append(value); 49 | 50 | return this; 51 | } 52 | 53 | public CStringBuilder append(Object value) { 54 | builder.append(value); 55 | 56 | return this; 57 | } 58 | 59 | public int length() { 60 | return builder.length(); 61 | } 62 | 63 | public String substring(int startIndex) { 64 | return builder.substring(startIndex); 65 | } 66 | 67 | public void setLength(int length) { 68 | builder.setLength(length); 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return builder.toString(); 74 | } 75 | 76 | public char charAt(int index) { 77 | return builder.charAt(index); 78 | } 79 | 80 | public CharSequence subSequence(int start, int end) { 81 | return builder.subSequence(start, end); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/org/jrubyparser/util/MethodDefVisitor.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.util; 2 | 3 | import org.jrubyparser.ast.*; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | 9 | public class MethodDefVisitor extends NoopVisitor { 10 | private IModuleScope scope; 11 | private List list; 12 | 13 | public static List findMethodsIn(IModuleScope scope) { 14 | MethodDefVisitor visitor = new MethodDefVisitor(scope); 15 | 16 | visitor.run(); 17 | 18 | return visitor.getMethodList(); 19 | } 20 | 21 | public MethodDefVisitor(IModuleScope scope) { 22 | list = new ArrayList(); 23 | this.scope = scope; 24 | } 25 | 26 | public void run() { 27 | for (Node child: ((Node) scope).childNodes()) { 28 | child.accept(this); 29 | } 30 | } 31 | 32 | public List getMethodList() { 33 | return list; 34 | } 35 | 36 | /* 37 | * nested blocks in blocks can have variables masked with same name so we make sure scope is correct. 38 | */ 39 | private void addMethodIfInModule(MethodDefNode method) { 40 | if (method.getClosestModule() == scope ) list.add(method); 41 | } 42 | 43 | 44 | @Override 45 | public Object visitDefnNode(DefnNode iVisited) { 46 | addMethodIfInModule((MethodDefNode) iVisited); 47 | return null; 48 | } 49 | 50 | @Override 51 | public Object visitDefsNode(DefsNode iVisited) { 52 | addMethodIfInModule((MethodDefNode) iVisited); 53 | return null; 54 | } 55 | 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/org/jrubyparser/util/NodePair.java: -------------------------------------------------------------------------------- 1 | package org.jrubyparser.util; 2 | 3 | import org.jrubyparser.ast.Node; 4 | 5 | /** 6 | * Simple struct for holding a pair of nodes 7 | */ 8 | public class NodePair { 9 | private final Node first; 10 | private final Node second; 11 | 12 | public NodePair(Node first, Node second) { 13 | this.first = first; 14 | this.second = second; 15 | } 16 | 17 | public Node getFirst() { 18 | return first; 19 | } 20 | 21 | public Node getSecond() { 22 | return second; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return "NodePair: {" + getFirst() + ", " + getSecond() + "}"; 28 | } 29 | } 30 | --------------------------------------------------------------------------------