⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parse.rb

📁 Harvestman-最新版本
💻 RB
字号:
require 'Parser'filename = ARGV[0]#filename = 'test.js'jsfile = File.open(filename).readjstree = parse(jsfile, filename)#puts 'finished parsing'def get_children (n)        children = []        attrs = [n.type, n.value, n.lineno, n.start, n.end, n.tokenizer, n.initializer,                n.name, n.params, n.funDecls, n.varDecls, n.body, n.functionForm,                n.assignOp, n.expression, n.condition, n.thenPart, n.elsePart,                n.readOnly, n.isLoop, n.setup, n.postfix, n.update, n.exception,                n.object, n.iterator, n.varDecl, n.label, n.target, n.tryBlock,                n.catchClauses, n.varName, n.guard, n.block, n.discriminant, n.cases,                n.defaultIndex, n.caseLabel, n.statements, n.statement]                n.length.times do |i|                children.push(n[i]) if n[i] != n and n[i].class == Node        end                attrs.length.times do |attr|                children.push(attrs[attr]) if attrs[attr].class == Node and attrs[attr] != n        end                return childrenenddef resolve_name (n)        name = ""                if n.type == $consts["DOT"]                name = resolve_name(n[0]) + "." + resolve_name(n[1])        else # INDENTIFIER                name = n.value        end                return name                enddef get_functions (n, functions = nil)        functions = {} unless functions        function = nil        name = nil        if n.type == $consts["FUNCTION"] and n.name                function = n                name = n.name        elsif n.type == $consts["ASSIGN"] && n[1].type == $consts["FUNCTION"] && !n[1].name                function = n[1]                name = resolve_name(n[0])        end        if function                functions[name] = function                #puts function.lineno.to_s + ": " + name        end                children = get_children(n)        children.length.times do |i|                get_functions(children[i], functions)        end        return functionsendfunctions = get_functions(jstree)if ARGV.length == 2        jsfile[functions[ARGV[1]].start..functions[ARGV[1]].end]else        functions.each_key {|name| puts "Function => " + name}end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -