Skip to content

Commit

Permalink
Add new dev tool for the scope plugin (#193)
Browse files Browse the repository at this point in the history
* Can show the result of scope analysis

* Better format
  • Loading branch information
Kuniwak authored Dec 22, 2016
1 parent 51ce7d3 commit 9ae019d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions dev_tool/show_scope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python

import sys
from argparse import ArgumentParser
from pathlib import Path
from pprint import pprint

vint_root = Path(__file__).resolve().parent.parent
sys.path.append(str(vint_root))

from vint.ast.node_type import NodeType
from vint.ast.traversing import traverse
from vint.ast.parsing import Parser
from vint.ast.plugin.scope_plugin import ScopePlugin


def prettify_node_type(node):
node['type'] = NodeType(node['type'])


if __name__ == '__main__':
arg_parser = ArgumentParser(prog='show_ast', description='Show AST')
arg_parser.add_argument('--enable-neovim', action='store_true', help='Enable Neovim syntax')
arg_parser.add_argument('files', nargs='*', help='File to parse')
namespace = vars(arg_parser.parse_args(sys.argv[1:]))

filepaths = map(Path, namespace['files'])
enable_neovim = namespace['enable_neovim']

scope_plugin = ScopePlugin()
parser = Parser(plugins={'scope': scope_plugin}, enable_neovim=enable_neovim)

for filepath in filepaths:
ast = parser.parse_file(filepath)
traverse(ast, on_enter=prettify_node_type)

print("////////// AST //////////\n")
pprint(ast)
print("\n\n")

print("////////// SCOPE TREE //////////\n")
pprint(scope_plugin._ref_tester._scope_tree)

0 comments on commit 9ae019d

Please sign in to comment.