Class: SyntaxTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

This is the parent node of all of the syntax tree nodes. It’s pretty much exclusively here to make it easier to operate with the tree in cases where you’re trying to monkey-patch or strictly type.

Direct Known Subclasses

ARef, ARefField, AliasNode, ArgBlock, ArgParen, ArgStar, Args, ArgsForward, ArrayLiteral, AryPtn, Assign, Assoc, AssocSplat, BEGINBlock, Backref, Backtick, BareAssocHash, Begin, Binary, BlockArg, BlockNode, BlockVar, BodyStmt, Break, CHAR, CVar, CallNode, Case, ClassDeclaration, Comma, Command, CommandCall, Comment, Const, ConstPathField, ConstPathRef, ConstRef, DefNode, Defined, DynaSymbol, ENDBlock, Else, Elsif, EmbDoc, EmbExprBeg, EmbExprEnd, EmbVar, EndContent, Ensure, ExcessedComma, Field, FloatLiteral, FndPtn, For, GVar, HashLiteral, Heredoc, HeredocBeg, HeredocEnd, HshPtn, IVar, Ident, IfNode, IfOp, Imaginary, In, Int, Kw, KwRestParam, LBrace, LBracket, LParen, Label, LabelEnd, Lambda, LambdaVar, MAssign, MLHS, MLHSParen, MRHS, MethodAddBlock, ModuleDeclaration, Next, Not, Op, OpAssign, Params, Paren, Period, PinnedBegin, PinnedVarRef, Program, QSymbols, QSymbolsBeg, QWords, QWordsBeg, RAssign, RBrace, RBracket, RParen, RangeNode, RationalLiteral, Redo, RegexpBeg, RegexpContent, RegexpEnd, RegexpLiteral, Rescue, RescueEx, RescueMod, RestParam, Retry, ReturnNode, SClass, Statements, StringConcat, StringContent, StringDVar, StringEmbExpr, StringLiteral, Super, SymBeg, SymbolContent, SymbolLiteral, Symbols, SymbolsBeg, TLamBeg, TLambda, TStringBeg, TStringContent, TStringEnd, TopConstField, TopConstRef, Unary, Undef, UnlessNode, UntilNode, VCall, VarField, VarRef, VoidStmt, When, WhileNode, Word, Words, WordsBeg, XString, XStringLiteral, YieldNode, ZSuper

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#locationObject (readonly)

Location

the location of this node



107
108
109
# File 'lib/syntax_tree/node.rb', line 107

def location
  @location
end

Instance Method Details

#accept(visitor) ⇒ Object

Raises:

  • (NotImplementedError)


109
110
111
# File 'lib/syntax_tree/node.rb', line 109

def accept(visitor)
  raise NotImplementedError
end

#child_nodesObject

Raises:

  • (NotImplementedError)


113
114
115
# File 'lib/syntax_tree/node.rb', line 113

def child_nodes
  raise NotImplementedError
end

#construct_keysObject



149
150
151
# File 'lib/syntax_tree/node.rb', line 149

def construct_keys
  PrettierPrint.format(+"") { |q| accept(MatchVisitor.new(q)) }
end

#deconstructObject

Raises:

  • (NotImplementedError)


117
118
119
# File 'lib/syntax_tree/node.rb', line 117

def deconstruct
  raise NotImplementedError
end

#deconstruct_keys(keys) ⇒ Object

Raises:

  • (NotImplementedError)


121
122
123
# File 'lib/syntax_tree/node.rb', line 121

def deconstruct_keys(keys)
  raise NotImplementedError
end

#end_charObject



133
134
135
# File 'lib/syntax_tree/node.rb', line 133

def end_char
  location.end_char
end

#format(q) ⇒ Object

Raises:

  • (NotImplementedError)


125
126
127
# File 'lib/syntax_tree/node.rb', line 125

def format(q)
  raise NotImplementedError
end

#pretty_print(q) ⇒ Object



137
138
139
# File 'lib/syntax_tree/node.rb', line 137

def pretty_print(q)
  accept(PrettyPrintVisitor.new(q))
end

#start_charObject



129
130
131
# File 'lib/syntax_tree/node.rb', line 129

def start_char
  location.start_char
end

#to_json(*opts) ⇒ Object



141
142
143
# File 'lib/syntax_tree/node.rb', line 141

def to_json(*opts)
  accept(JSONVisitor.new).to_json(*opts)
end

#to_mermaidObject



145
146
147
# File 'lib/syntax_tree/node.rb', line 145

def to_mermaid
  accept(MermaidVisitor.new)
end