123456789101112131415161718192021222324252627282930313233343536 |
- var $builtinmodule = function(name)
- {
- var mod = {};
-
- var parses = {};
-
- mod.count_components = new Sk.builtin.func(function(source, component) {
- Sk.builtin.pyCheckArgs("parse", arguments, 2, 2);
- Sk.builtin.pyCheckType("source", "string", Sk.builtin.checkString(source));
- Sk.builtin.pyCheckType("component", "string", Sk.builtin.checkString(component));
-
- source = source.v;
- component = component.v;
-
- if (!(source in parses)) {
- var parse = Sk.parse("__main__", source);
- parses[source] = Sk.astFromParse(parse.cst, "__main__", parse.flags);
- }
- var ast = parses[source];
-
- ast_list = (new NodeVisitor()).recursive_walk(ast);
-
- var count = 0;
- for (var i = 0, len = ast_list.length; i < len; i = i+1) {
- if (ast_list[i]._astname == component) {
- count = count+1;
- }
- }
-
- return Sk.ffi.remapToPy(count);
- });
-
-
- return mod;
- }
|