Index: compile_rules.py ================================================================== --- compile_rules.py +++ compile_rules.py @@ -565,11 +565,11 @@ lSentenceRulesJS.append(jsconv.pyRuleToJS(aRule, dJSREGEXES, sWORDLIMITLEFT)) # creating file with all functions callable by rules print(" creating callables...") sPyCallables = "# generated code, do not edit\n" - sJSCallables = "// generated code, do not edit\nconst oEvalFunc = {\n" + sJSCallables = "" for sFuncName, sReturn in lFUNCTIONS: if sFuncName.startswith("_c_"): # condition sParams = "s, sx, m, dTokenPos, sCountry, bCondMemo" elif sFuncName.startswith("_m_"): # message sParams = "s, m" @@ -580,16 +580,17 @@ elif sFuncName.startswith("_d_"): # disambiguator sParams = "s, m, dTokenPos" else: print("# Unknown function type in [" + sFuncName + "]") continue + # Python sPyCallables += "def {} ({}):\n".format(sFuncName, sParams) sPyCallables += " return " + sReturn + "\n" + # JavaScript sJSCallables += " {}: function ({})".format(sFuncName, sParams) + " {\n" sJSCallables += " return " + jsconv.py2js(sReturn) + ";\n" sJSCallables += " },\n" - sJSCallables += "}\n" displayStats(lParagraphRules, lSentenceRules) print("Unnamed rules: " + str(nRULEWITHOUTNAME)) Index: compile_rules_graph.py ================================================================== --- compile_rules_graph.py +++ compile_rules_graph.py @@ -6,10 +6,11 @@ import re import traceback import json import darg +import compile_rules_js_convert as jsconv dACTIONS = {} dFUNCTIONS = {} dFUNCNAME = {} @@ -416,11 +417,11 @@ print(k, "\t", v) # creating file with all functions callable by rules print(" creating callables...") sPyCallables = "# generated code, do not edit\n" - #sJSCallables = "// generated code, do not edit\nconst oEvalFunc = {\n" + sJSCallables = "" for sFuncName, sReturn in dFUNCTIONS.items(): if sFuncName.startswith("_g_cond_"): # condition sParams = "lToken, nTokenOffset, nLastToken, sCountry, bCondMemo, dTags, sSentence, sSentence0" elif sFuncName.startswith("g_msg_"): # message sParams = "lToken, nTokenOffset, nLastToken" @@ -431,16 +432,17 @@ elif sFuncName.startswith("_g_da_"): # disambiguator sParams = "lToken, nTokenOffset, nLastToken" else: print("# Unknown function type in [" + sFuncName + "]") continue + # Python sPyCallables += "def {} ({}):\n".format(sFuncName, sParams) sPyCallables += " return " + sReturn + "\n" - #sJSCallables += " {}: function ({})".format(sFuncName, sParams) + " {\n" - #sJSCallables += " return " + jsconv.py2js(sReturn) + ";\n" - #sJSCallables += " },\n" - #sJSCallables += "}\n" + # JavaScript + sJSCallables += " {}: function ({})".format(sFuncName, sParams) + " {\n" + sJSCallables += " return " + jsconv.py2js(sReturn) + ";\n" + sJSCallables += " },\n" # Debugging if False: print("\nActions:") for sActionName, aAction in dACTIONS.items(): @@ -449,8 +451,9 @@ print(sPyCallables) # Result return { "graph_callables": sPyCallables, + "graph_callablesJS": sJSCallables, "rules_graphs": dAllGraph, "rules_actions": dACTIONS }