Grammalecte  Check-in [cf5fbaf4dc]

Overview
Comment:[build] check regexes of DARGs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | build | rg
Files: files | file ages | folders
SHA3-256: cf5fbaf4dcb24e9c09296dfe7eea8b2a548ecc0a9599a6c3ab0b4dc7e7f6057f
User & Date: olr on 2018-06-27 23:26:28
Other Links: branch diff | manifest | tags
Context
2018-06-27
23:30
[build] check regexes: memorize checked regexes check-in: ffacab70c5 user: olr tags: build, rg
23:26
[build] check regexes of DARGs check-in: cf5fbaf4dc user: olr tags: build, rg
20:58
[core][bug] gc engine: missing parameter check-in: 6e8a6ca2ac user: olr tags: core, rg
Changes

Modified compile_rules_graph.py from [4e3eba14a0] to [ffaec91e64].

259
260
261
262
263
264
265




































266
267
268
269
270
271
272
...
376
377
378
379
380
381
382


383
384
385
386
387
388
389
        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...")
................................................................................
    # 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
    }







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







 







>
>







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
...
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
        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...")
................................................................................
    # 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
    }