Grammalecte  Diff

Differences From Artifact [4e3eba14a0]:

To Artifact [ffaec91e64]:


259
260
261
262
263
264
265




































266
267
268
269
270
271
272
        dFUNCTIONS["_g_d_"+sActionId] = sAction
        sAction = "_g_d_"+sActionId
        return [sOption, sCondition, cAction, sAction]
    else:
        print("# Unknown action at line " + sActionId)
        return None






































def make (lRule, dDef, sLang, bJavaScript):
    "compile rules, returns a dictionary of values"
    # for clarity purpose, don’t create any file here

    # removing comments, zeroing empty lines, creating definitions, storing tests, merging rule lines
    print("  parsing rules...")







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
        dFUNCTIONS["_g_d_"+sActionId] = sAction
        sAction = "_g_d_"+sActionId
        return [sOption, sCondition, cAction, sAction]
    else:
        print("# Unknown action at line " + sActionId)
        return None


def checkRegexes (dAllGraph):
    "check validity of regexes"
    print("  checking regexes...")
    for sGraphName, dGraph in dAllGraph.items():
        for nKey, dVal in dGraph.items():
            if "<re_value>" in dVal:
                for sRegex in dVal["<re_value>"]:
                    _checkRegex(sRegex)
            if "<re_morph>" in dVal:
                for sRegex in dVal["<re_morph>"]:
                    _checkRegex(sRegex)

def _checkRegex (sRegex):
    #print(sRegex)
    if "¬" in sRegex:
        sPattern, sNegPattern = sRegex.split("¬")
        try:
            if not sNegPattern:
                print("# Warning! Empty negpattern:", sRegex)
            re.compile(sPattern)
            re.compile(sNegPattern)
        except:
            print("# Error. Wrong regex:", sRegex)
            traceback.print_exc()
            exit()
    else:
        try:
            if not sRegex:
                print("# Warning! Empty pattern:", sRegex)
            re.compile(sRegex)
        except:
            print("# Error. Wrong regex:", sRegex)
            traceback.print_exc()
            exit()


def make (lRule, dDef, sLang, bJavaScript):
    "compile rules, returns a dictionary of values"
    # for clarity purpose, don’t create any file here

    # removing comments, zeroing empty lines, creating definitions, storing tests, merging rule lines
    print("  parsing rules...")
376
377
378
379
380
381
382


383
384
385
386
387
388
389
    # Debugging
    if False:
        print("\nActions:")
        for sActionName, aAction in dACTIONS.items():
            print(sActionName, aAction)
        print("\nFunctions:")
        print(sPyCallables)



    # Result
    return {
        "graph_callables": sPyCallables,
        "rules_graphs": dAllGraph,
        "rules_actions": dACTIONS
    }







>
>







412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
    # Debugging
    if False:
        print("\nActions:")
        for sActionName, aAction in dACTIONS.items():
            print(sActionName, aAction)
        print("\nFunctions:")
        print(sPyCallables)

    checkRegexes(dAllGraph)

    # Result
    return {
        "graph_callables": sPyCallables,
        "rules_graphs": dAllGraph,
        "rules_actions": dACTIONS
    }