<commit_before><commit_msg>Initial<commit_after>
from pyang import plugin, statements

def pyang_plugin_init():
    plugin.register_plugin(IndexerPlugin())

class IndexerPlugin(plugin.PyangPlugin):
    def add_output_format(self, fmts):
        self.multiple_modules = True
        fmts['yang-catalog-index'] = self

    def setup_fmt(self, ctx):
        ctx.implicit_errors = False

    def emit(self, ctx, modules, fd):
        emit_index(ctx, modules, fd)

def emit_index(ctx, modules, fd):
	print "create table yindex(module, path, statement, argument);"
	for module in modules:
		for child in module.i_children:
			statements.iterate_i_children(child, printer)

def printer(stmt):
	module = stmt.main_module()
	path = statements.mk_path_str(stmt)
	print "insert into yindex values('%s', '%s', '%s', '%s');" % (module.arg, path, stmt.keyword, stmt.arg)
	# print "###", module.arg, path, stmt.keyword, stmt.arg
{'fraction_non_alphanumeric': 0.13253012048192772, 'fraction_numerical': 0.0, 'mean_word_length': 4.573170731707317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5357626', 'n_tokens_mistral': 309, 'n_tokens_neox': 298, 'n_words': 75}