<commit_before>meme central:memescript/compiler

requires ometa, ometa_tr, ometa_base, io
where
 ometa      = central:memescript/ometa
 ometa_tr   = central:memescript/ometa_tr
 ometa_base = central:memescript/ometa_base
 io         = central:stdlib/io


gen: fun(grammar_in_file_path, grammar_out_file_path, OMeta, OMetaTranslator) {
  io.print("=== processing " + grammar_in_file_path);
  var text = io.read_file(grammar_in_file_path);
  var maybe_ast = ometa_base.parse(text, OMeta, :mm_module);
  io.print(maybe_ast.toSource);
  if (maybe_ast[0]) {
    io.print("parse error: " + maybe_ast[0].toString);
  } else {
    io.print("\n\ntranslating...\n\n");
    maybe_ast = ometa_base.parse([maybe_ast[1]], OMetaTranslator, :mm_module);
    if (maybe_ast[0]) {
      io.print("translation error: " + maybe_ast[0].toString);
    } else {
      io.write_file(grammar_out_file_path, maybe_ast[1]);
      io.print("Wrote to " + grammar_out_file_path);
    }
  }
}

main: fun() {
  var name = argv()[1];
  gen("memescript/" + name + ".g", "memescript/" + name + ".me", ometa.OMeta, ometa_tr.OMetaTranslator);
}<commit_msg>build: Receive a path instead of a name in gen_parser argv<commit_after>meme central:memescript/compiler

requires ometa, ometa_tr, ometa_base, io
where
 ometa      = central:memescript/ometa
 ometa_tr   = central:memescript/ometa_tr
 ometa_base = central:memescript/ometa_base
 io         = central:stdlib/io


gen: fun(grammar_in_file_path, grammar_out_file_path, OMeta, OMetaTranslator) {
  io.print("=== processing " + grammar_in_file_path);
  var text = io.read_file(grammar_in_file_path);
  var maybe_ast = ometa_base.parse(text, OMeta, :mm_module);
  io.print(maybe_ast.toSource);
  if (maybe_ast[0]) {
    io.print("parse error: " + maybe_ast[0].toString);
  } else {
    io.print("\n\ntranslating...\n\n");
    maybe_ast = ometa_base.parse([maybe_ast[1]], OMetaTranslator, :mm_module);
    if (maybe_ast[0]) {
      io.print("translation error: " + maybe_ast[0].toString);
    } else {
      io.write_file(grammar_out_file_path, maybe_ast[1]);
      io.print("Wrote to " + grammar_out_file_path);
    }
  }
}

main: fun() {
  var path = argv()[1];
  gen(path, path.replace_all(".g", ".me"), ometa.OMeta, ometa_tr.OMetaTranslator);
}
{'fraction_non_alphanumeric': 0.14652501106684374, 'fraction_numerical': 0.00619743249225321, 'mean_word_length': 4.268065268065268, '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': '1188204', 'n_tokens_mistral': 871, 'n_tokens_neox': 855, 'n_words': 143}