class SheepAst::AnalyzerCore
Aggregates User interface of sheep_ast library
@api public
Attributes
Public Class Methods
SheepAst::FactoryBase::new
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 59 def initialize @data_store = DataStore.new @tokenizer = Tokenizer.new @stage_manager = StageManager.new(@data_store) @file_manager = FileManager.new(@stage_manager, @tokenizer, @data_store) @fof = FoF.new(self, @data_store) @eol_validation = false super() end
Public Instance Methods
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 151 def <<(expr) analyze_expr(expr) end
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 158 def analyze_expr(expr) @file_manager.register_next_expr(expr) do_analyze end
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 134 def analyze_file(files) @files = files @file_manager.register_files(files) do_analyze end
To configure AST objects. Allow user to add AST analze
@example
core.config_ast do |ast, syn| syn.within { #.. } end
@note Please see Example page for further usage
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 108 def config_ast(name, klass = AstManager, &blk) if !name_defined?(name) ast = klass.new(name, @data_store, @fof.match_factory) create_id(ast, name) syn = SheepAst::Syntax.new(ast, @fof.match_factory, @fof.action_factory) blk.call(ast, syn, @fof.match_factory, @fof.action_factory) @stage_manager.add_stage(ast) else ast = from_name(name) syn = SheepAst::Syntax.new(ast, @fof.match_factory, @fof.action_factory) blk.call(ast, syn, @fof.match_factory, @fof.action_factory) end return ast end
To configure tokenizer
@example
core.config_tok do |tok| tok.some_ethod end
@note Please see Example page for further usage
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 92 def config_tok(&blk) blk.call(@tokenizer) end
disable eol validation
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 281 def disable_eol_validation @eol_validation = false end
disable last word check
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 270 def disable_last_word_check @file_manager.last_word_check = nil end
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 171 def dump(logs = :pfatal) logf = method(logs) @tokenizer.dump(logs) @stage_manager.dump_tree(logs) logf.call '## Resume Info ##' logf.call @file_manager.resume_data.inspect logf.call '' end
If an action is called when it is not end of line The action is ignored. This is useful for console application
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 276 def enable_eol_validation @eol_validation = true end
To check last word, and if it is not matched, ignore the word This is useful when console application's auto completion
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 265 def enable_last_word_check(word = ' ') @file_manager.last_word_check = word end
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 79 def let Let end
API to raise exception when Lazy Abort
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 259 def not_raise_when_all_ast_not_found @data_store.assign(:_sheep_not_raise_when_lazy_abort, true) end
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 194 def report(logs = :pfatal, **options) yield return true rescue => e bt = e.backtrace arr = [] bt.each do |elem| test = elem.split(':') arr << "#{test[0].split('/')[-1]}:#{test[-2]}" end logf = method(logs) logf.call '' logf.call '---------------------------' logf.call '## report Got exception ##' logf.call '--------------------------' logf.call '' logf.call '## Exception Info' logf.call 'Message' logf.call "#{e.inspect}", :red logf.call 'BackTrace:' logf.call "#{arr.inspect}", :blue logf.call '' dump(logs) logf.call 'Exception was occured at analyzer core' if !ENV['SHEEP_DEBUG_PRY'].nil? logf.call 'Entering pry debug session' binding.pry # rubocop: disable all else logf.call 'Not entering pry debug session.' logf.call 'Please define SHEEP_DEBUG_PRY for entering pry debug session' end logf.call '' logf.call 'End of Report' logf.call '--------------------------' logf.call '' if options[:raise] raise end return false end
API to set search path to include files by {SheepAst::LetInclude} module
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 238 def sheep_dir_path_set(arr) @data_store.assign(:_sheep_dir_path, arr) end
API to set exclude path to skip analysis by {SheepAst::LetInclude} module
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 243 def sheep_exclude_dir_path_set(arr) @data_store.assign(:_sheep_exclude_dir_path, arr) end
API to set output directory for {SheepAst::LetCompile} module
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 249 def sheep_outdir_set(path) @data_store.assign(:_sheep_outdir, path) end
API to set output directory for {SheepAst::LetCompile} module
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 254 def sheep_template_dir_path_set(arr) @data_store.assign(:_sheep_template_dir, arr) end
Private Instance Methods
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 345 def disable_eof_validation @stage_manager.disable_eof_validation end
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 295 def do_analyze if !ENV['SHEEP_RSPEC'] process_option else @option = {} end dump(:pwarn) and return if @option[:d] count = 0 is_eol = true ret = MatchResult::NotFound @file_manager.analyze do |data| count += 1 ret = @stage_manager.analyze_stages(data) if ret == @eol_validation && MatchResult::Finish && !data.is_eol ldebug? and ldebug "Action called but it is not eol" is_eol = false break end if ret == MatchResult::NotFound ldebug? and ldebug "Expression not found." break end end res = AnalyzerCoreReturn.new res.result = ret.dup res.eol = is_eol res.next_command = next_command return res end
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 350 def process_option if !@option option_on option_parse(ARGV) end @option[:D]&.each do |item| if item.include?('=') key = item.split('=').first data = item.split('=').last @envdb[key] = data else @envdb[item] = '1' end end sheep_dir_path_set(@option[:I]) if @option[:I] sheep_exclude_dir_path_set(@option[:E]) if @option[:E] sheep_outdir_set(@option[:o]) if @option[:o] sheep_template_dir_path_set(@option[:t]) if @option[:t] end
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 288 def stage(name) return @stage_manager.stage_get(name) end
# File lib/sheep_ast/analyzer_core/analyzer_core.rb, line 334 def tokenize(file) tokenized = @tokenizer.feed_file(file) ldebug? and ldebug "start #{File.expand_path(file)}", :red return tokenized end