Class: MotionBlender::Analyzer::Parser
- Inherits:
-
Object
- Object
- MotionBlender::Analyzer::Parser
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/motion_blender/analyzer/parser.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#evaluators ⇒ Object
readonly
Returns the value of attribute evaluators.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #evaluate(source) ⇒ Object
-
#initialize(file) ⇒ Parser
constructor
A new instance of Parser.
- #last_trace ⇒ Object
- #parse ⇒ Object
- #raketime_block?(source) ⇒ Boolean
- #require_command?(source) ⇒ Boolean
- #requires ⇒ Object
- #traverse(source) ⇒ Object
Constructor Details
#initialize(file) ⇒ Parser
Returns a new instance of Parser.
17 18 19 20 |
# File 'lib/motion_blender/analyzer/parser.rb', line 17 def initialize file @file = file.to_s @evaluators = [] end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
15 16 17 |
# File 'lib/motion_blender/analyzer/parser.rb', line 15 def cache @cache end |
#evaluators ⇒ Object (readonly)
Returns the value of attribute evaluators.
15 16 17 |
# File 'lib/motion_blender/analyzer/parser.rb', line 15 def evaluators @evaluators end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
15 16 17 |
# File 'lib/motion_blender/analyzer/parser.rb', line 15 def file @file end |
Instance Method Details
#evaluate(source) ⇒ Object
50 51 52 53 |
# File 'lib/motion_blender/analyzer/parser.rb', line 50 def evaluate source @evaluators << Evaluator.new(source) @evaluators.last.run end |
#last_trace ⇒ Object
59 60 61 |
# File 'lib/motion_blender/analyzer/parser.rb', line 59 def last_trace @evaluators.last.try :trace end |
#parse ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/motion_blender/analyzer/parser.rb', line 22 def parse srcs = cache.fetch do run_callbacks :parse do ast = ::Parser::CurrentRuby.parse_file(@file) ast && traverse(Source.new(ast: ast)) @evaluators.map(&:source).map(&:attributes) end end if srcs && cache.hit? srcs.each do |attrs| evaluate Source.new(attrs) end end self end |
#raketime_block?(source) ⇒ Boolean
67 68 69 70 |
# File 'lib/motion_blender/analyzer/parser.rb', line 67 def raketime_block? source source.type.block? && (source.children.first.code == 'MotionBlender.raketime') end |
#require_command?(source) ⇒ Boolean
63 64 65 |
# File 'lib/motion_blender/analyzer/parser.rb', line 63 def require_command? source source.type.send? && Require.acceptable?(source.method) end |
#requires ⇒ Object
55 56 57 |
# File 'lib/motion_blender/analyzer/parser.rb', line 55 def requires @evaluators.map(&:requires).flatten end |
#traverse(source) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/motion_blender/analyzer/parser.rb', line 42 def traverse source if require_command?(source) evaluate source elsif !raketime_block?(source) source.children.each { |src| traverse src } end end |