Grammalecte  Check-in [9094ac6082]

Overview
Comment:[build] code simplification
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | build
Files: files | file ages | folders
SHA3-256: 9094ac60823b5ed03c011827de60fc226bf8bbd3745f88d07eb9ca17b91ae59a
User & Date: olr on 2020-04-22 16:56:58
Other Links: manifest | tags
Context
2020-04-23
08:36
[fr] ajustements check-in: 5ab43f5063 user: olr tags: fr, trunk
2020-04-22
16:56
[build] code simplification check-in: 9094ac6082 user: olr tags: build, trunk
14:59
[build] make data more readable check-in: e17a78cf83 user: olr tags: build, trunk
Changes

Modified compile_rules.py from [c6e75ae902] to [d8be0874f6].

   146    146       if s.startswith("@@@@"):
   147    147           if bParagraph:
   148    148               print("Error. Graph call can be made only after the first pass (sentence by sentence)")
   149    149               exit()
   150    150           return ["@@@@", s[4:], sLineId]
   151    151   
   152    152       #### OPTIONS
   153         -    sOption = False         # False or [a-z0-9]+ name
          153  +    sOption = ""            # empty string or [a-z0-9]+ name
   154    154       nPriority = 4           # Default is 4, value must be between 0 and 9
   155    155       tGroups = None          # code for groups positioning (only useful for JavaScript)
   156    156       cCaseMode = 'i'         # i: case insensitive,  s: case sensitive,  u: uppercasing allowed
   157    157       cWordLimitLeft = '['    # [: word limit, <: no specific limit
   158    158       cWordLimitRight = ']'   # ]: word limit, >: no specific limit
   159    159       m = re.match("^__(?P<borders_and_case>[\\[<]\\w[\\]>])(?P<option>/[a-zA-Z0-9]+|)(?P<ruleid>\\(\\w+\\))(?P<priority>![0-9]|)__ *", s)
   160    160       if m:
   161    161           cWordLimitLeft = m.group('borders_and_case')[0]
   162    162           cCaseMode = m.group('borders_and_case')[1]
   163    163           cWordLimitRight = m.group('borders_and_case')[2]
   164         -        sOption = m.group('option')[1:]  if m.group('option')  else False
          164  +        sOption = m.group('option')[1:]  if m.group('option')  else ""
   165    165           sRuleId =  m.group('ruleid')[1:-1]
   166    166           if sRuleId in aRULESET:
   167    167               print(f"# Error. Several rules have the same id: {sRuleId}")
   168    168               exit()
   169    169           aRULESET.add(sRuleId)
   170    170           nPriority = dOptPriority.get(sOption, 4)
   171    171           if m.group('priority'):
................................................................................
   408    408       return lFinal
   409    409   
   410    410   
   411    411   def createRulesAsString (lRules):
   412    412       "create rules as a string of arrays (to be bundled in a JSON string)"
   413    413       sArray = "[\n"
   414    414       for sOption, aRuleGroup in lRules:
   415         -        sOption = "False"  if not sOption  else  f'"{sOption}"'
   416         -        sArray += f'  [{sOption}, [\n'
          415  +        sArray += f'  ["{sOption}", [\n'
   417    416           for aRule in aRuleGroup:
   418    417               sArray += f'    {aRule},\n'
   419    418           sArray += "  ]],\n"
   420    419       sArray += "]"
   421    420       return sArray
   422    421   
   423    422   

Modified compile_rules_js_convert.py from [37ece1a88a] to [b4c7f14ca9].

   132    132       return lRuleJS
   133    133   
   134    134   
   135    135   def writeRulesToJSArray (lRules):
   136    136       "create rules as a string of arrays (to be bundled in a JSON string)"
   137    137       sArray = "[\n"
   138    138       for sOption, aRuleGroup in lRules:
          139  +        sArray += f'  ["{sOption}", [\n'
   139    140           if sOption != "@@@@":
   140         -            sOption = "false"  if not sOption  else  f'"{sOption}"'
   141         -            sArray += f'  [{sOption}, [\n'
   142    141               for sRegex, bCaseInsensitive, sLineId, sRuleId, nPriority, lActions, aGroups, aNegLookBehindRegex in aRuleGroup:
   143    142                   sCaseSensitive = "true" if bCaseInsensitive  else "false"
   144    143                   sActions = json.dumps(lActions, ensure_ascii=False)
   145    144                   sGroups = json.dumps(aGroups, ensure_ascii=False)
   146    145                   sNLBRegex = json.dumps(aNegLookBehindRegex, ensure_ascii=False)
   147    146                   sArray += f'    [{sRegex}, {sCaseSensitive}, "{sLineId}", "{sRuleId}", {nPriority}, {sActions}, {sGroups}, {sNLBRegex}],\n'
   148         -            sArray += "  ]],\n"
   149    147           else:
   150         -            sArray += f'  ["{sOption}", [\n'
   151         -            for sGraphName, sLineId in aRuleGroup:
   152         -                sArray += f'    ["{sGraphName}", "{sLineId}"],\n'
   153         -            sArray += "  ]],\n"
          148  +            for aRule in aRuleGroup:
          149  +                sArray += f'    {aRule},\n'
          150  +        sArray += "  ]],\n"
   154    151       sArray += "]"
   155    152       return sArray
   156    153   
   157    154   
   158    155   def groupsPositioningCodeToList (sGroupsPositioningCode):
   159    156       "convert <sGroupsPositioningCode> to a list of codes (numbers or strings)"
   160    157       if not sGroupsPositioningCode: