Class: Noraneko::Processor
- Inherits:
-
Parser::AST::Processor
- Object
- Parser::AST::Processor
- Noraneko::Processor
- Includes:
- NodeUtility
- Defined in:
- lib/noraneko/processor.rb
Constant Summary collapse
- ParseError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#context_stack ⇒ Object
writeonly
Sets the attribute context_stack.
-
#filepath ⇒ Object
writeonly
Sets the attribute filepath.
-
#registry ⇒ Object
writeonly
Sets the attribute registry.
Class Method Summary collapse
Instance Method Summary collapse
Methods included from NodeUtility
#convert_to_hash, #extract_consts, #extract_syms, #singleton_class?
Instance Attribute Details
#context_stack=(value) ⇒ Object (writeonly)
Sets the attribute context_stack
13 14 15 |
# File 'lib/noraneko/processor.rb', line 13 def context_stack=(value) @context_stack = value end |
#filepath=(value) ⇒ Object (writeonly)
Sets the attribute filepath
13 14 15 |
# File 'lib/noraneko/processor.rb', line 13 def filepath=(value) @filepath = value end |
#registry=(value) ⇒ Object (writeonly)
Sets the attribute registry
13 14 15 |
# File 'lib/noraneko/processor.rb', line 13 def registry=(value) @registry = value end |
Class Method Details
.init_with(registry:, filepath: nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/noraneko/processor.rb', line 17 def self.init_with(registry:, filepath: nil) new.tap do |instance| instance.registry = registry instance.filepath = filepath instance.context_stack = [] end end |
Instance Method Details
#process(node) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/noraneko/processor.rb', line 25 def process(node) return nil unless node context_generated = false begin case node.type when :class, :sclass nclass = process_class(node) context_generated = true when :module nmodule = process_module(node) context_generated = true when :def process_def(node) context_generated = true when :defs process_defs(node) context_generated = true when :send process_send(node) when :block_pass process_block_pass(node) end rescue StandardError line = node.loc.line = "Fail to parse. location: #{@filepath}:#{line}" raise ParseError.new() end super if node.type == :sclass @registry.find(nclass.parent_name).merge_singleton(nclass) @registry.delete(nclass) end if context_generated @public_scope = true unless sent_in_method? @context_stack.pop end end |