Overview
Comment: | [build] check regexes: memorize checked regexes |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | build | rg |
Files: | files | file ages | folders |
SHA3-256: |
6f12ea6825fc2208af81dca900503a86 |
User & Date: | olr on 2018-06-27 23:36:45 |
Other Links: | branch diff | manifest | tags |
Context
2018-06-27
| ||
23:39 | [build][fix] check regexes: memorize checked regexes check-in: 74d9c8e099 user: olr tags: build, rg | |
23:36 | [build] check regexes: memorize checked regexes check-in: 6f12ea6825 user: olr tags: build, rg | |
23:30 | [build] check regexes: memorize checked regexes check-in: ffacab70c5 user: olr tags: build, rg | |
Changes
Modified compile_rules_graph.py from [9a2e2f9a01] to [f859281899].
︙ | ︙ | |||
259 260 261 262 263 264 265 | dFUNCTIONS["_g_d_"+sActionId] = sAction sAction = "_g_d_"+sActionId return [sOption, sCondition, cAction, sAction] else: print("# Unknown action at line " + sActionId) return None | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 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...") |
︙ | ︙ |
Modified darg.py from [5064c8e027] to [e3a97a1f63].
︙ | ︙ | |||
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | sHashId = oNode.__hash__() if sHashId not in dGraph: dGraph[sHashId] = oNode.getNodeAsDict() else: print("Error. Double node… same id: ", sHashId) print(str(oNode.getNodeAsDict())) dGraph = self._rewriteKeysOfDARG(dGraph) return dGraph def _rewriteKeysOfDARG (self, dGraph): "keys of DARG are long numbers (hashes): this function replace these hashes with smaller numbers (to reduce storing size)" # create translation dictionary dKeyTrans = {} for i, nKey in enumerate(dGraph): dKeyTrans[nKey] = i # replace keys dNewGraph = {} for nKey, dVal in dGraph.items(): dNewGraph[dKeyTrans[nKey]] = dVal for nKey, dVal in dGraph.items(): for sArc, val in dVal.items(): if type(val) is int: dVal[sArc] = dKeyTrans[val] else: for sArc, nKey in val.items(): val[sArc] = dKeyTrans[nKey] return dNewGraph class Node: """Node of the rule graph""" NextId = 0 | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | sHashId = oNode.__hash__() if sHashId not in dGraph: dGraph[sHashId] = oNode.getNodeAsDict() else: print("Error. Double node… same id: ", sHashId) print(str(oNode.getNodeAsDict())) dGraph = self._rewriteKeysOfDARG(dGraph) self._checkRegexes(dGraph) return dGraph def _rewriteKeysOfDARG (self, dGraph): "keys of DARG are long numbers (hashes): this function replace these hashes with smaller numbers (to reduce storing size)" # create translation dictionary dKeyTrans = {} for i, nKey in enumerate(dGraph): dKeyTrans[nKey] = i # replace keys dNewGraph = {} for nKey, dVal in dGraph.items(): dNewGraph[dKeyTrans[nKey]] = dVal for nKey, dVal in dGraph.items(): for sArc, val in dVal.items(): if type(val) is int: dVal[sArc] = dKeyTrans[val] else: for sArc, nKey in val.items(): val[sArc] = dKeyTrans[nKey] return dNewGraph def _checkRegexes (dGraph): "check validity of regexes" aRegex = set() for nKey, dVal in dGraph.items(): if "<re_value>" in dVal: for sRegex in dVal["<re_value>"]: if sRegex not in aRegex: _checkRegex(sRegex) aRegex.add(sRegex) if "<re_morph>" in dVal: for sRegex in dVal["<re_morph>"]: if sRegex not in aRegex: _checkRegex(sRegex) aRegex.add(sRegex) aRegex.clear() 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() class Node: """Node of the rule graph""" NextId = 0 |
︙ | ︙ |