Class: Masamune::LexNode
- Inherits:
-
Object
- Object
- Masamune::LexNode
- Defined in:
- lib/masamune/lex_node.rb
Overview
docs.ruby-lang.org/en/3.0/Ripper.html#method-c-lex
@location: Line number and starting point on the line. i.e. - [4, 7]. @type: The type of token. i.e. - :kw (is a keyword). @token: The raw string which represents the actual ruby code. i.e. - “do”. @state: Ripper::Lexer::State. i.e. - CMDARG.
Instance Attribute Summary collapse
-
#ast_id ⇒ Object
Returns the value of attribute ast_id.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#location ⇒ Object
Returns the value of attribute location.
-
#state ⇒ Object
Returns the value of attribute state.
-
#token ⇒ Object
Returns the value of attribute token.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #ast ⇒ Object
-
#identifier? ⇒ Boolean
TODO: I’m not sure how I feel about checking @type against the symbol directly.
-
#initialize(index, raw_lex_node, ast_id) ⇒ LexNode
constructor
A new instance of LexNode.
- #method? ⇒ Boolean
- #method_call? ⇒ Boolean
- #method_definition? ⇒ Boolean
- #string? ⇒ Boolean
- #variable? ⇒ Boolean
Constructor Details
#initialize(index, raw_lex_node, ast_id) ⇒ LexNode
Returns a new instance of LexNode.
12 13 14 15 16 17 18 19 20 |
# File 'lib/masamune/lex_node.rb', line 12 def initialize(index, raw_lex_node, ast_id) @index = index @location, @type, @token, @state = raw_lex_node @type = @type.to_s.gsub(/^[a-z]*_/, "").to_sym # Since the Abstract Syntax Tree can get very large, # We just save the id and reference it with `ast` below. @ast_id = ast_id end |
Instance Attribute Details
#ast_id ⇒ Object
Returns the value of attribute ast_id.
9 10 11 |
# File 'lib/masamune/lex_node.rb', line 9 def ast_id @ast_id end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
10 11 12 |
# File 'lib/masamune/lex_node.rb', line 10 def index @index end |
#location ⇒ Object
Returns the value of attribute location.
9 10 11 |
# File 'lib/masamune/lex_node.rb', line 9 def location @location end |
#state ⇒ Object
Returns the value of attribute state.
9 10 11 |
# File 'lib/masamune/lex_node.rb', line 9 def state @state end |
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/masamune/lex_node.rb', line 9 def token @token end |
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'lib/masamune/lex_node.rb', line 9 def type @type end |
Instance Method Details
#ast ⇒ Object
22 23 24 |
# File 'lib/masamune/lex_node.rb', line 22 def ast ObjectSpace._id2ref(@ast_id) end |
#identifier? ⇒ Boolean
TODO: I’m not sure how I feel about checking @type against the symbol directly.
45 46 47 |
# File 'lib/masamune/lex_node.rb', line 45 def identifier? @type == :ident end |
#method? ⇒ Boolean
39 40 41 42 |
# File 'lib/masamune/lex_node.rb', line 39 def method? return false unless identifier? method_definition? || method_call? end |
#method_call? ⇒ Boolean
35 36 37 |
# File 'lib/masamune/lex_node.rb', line 35 def method_call? ast.method_calls(token_value: @token).any? end |
#method_definition? ⇒ Boolean
31 32 33 |
# File 'lib/masamune/lex_node.rb', line 31 def method_definition? ast.method_definitions(token_value: @token).any? end |
#string? ⇒ Boolean
49 50 51 |
# File 'lib/masamune/lex_node.rb', line 49 def string? @type == :tstring_content end |
#variable? ⇒ Boolean
26 27 28 29 |
# File 'lib/masamune/lex_node.rb', line 26 def variable? return false unless identifier? ast.variables(token_value: @token).any? end |