Overview
Comment: | [build] graph builder: function creator |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | build | rg |
Files: | files | file ages | folders |
SHA3-256: |
a8d90dbabbd3f7c51b314d4695e58573 |
User & Date: | olr on 2018-08-11 10:50:29 |
Other Links: | branch diff | manifest | tags |
Context
2018-08-11
| ||
14:00 | [build][bug] graph builder: action identifier must be more specific to avoid rules confusion check-in: 709b969c75 user: olr tags: build, rg | |
10:50 | [build] graph builder: function creator check-in: a8d90dbabb user: olr tags: build, rg | |
10:49 | [fr] conversion: regex rules -> graph rules check-in: 2c954b6dbd user: olr tags: fr, rg | |
Changes
Modified compile_rules_graph.py from [550d738494] to [f91ed363c6].
︙ | |||
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | + + + + + + + + + + + + + + + | import json import darg dACTIONS = {} dFUNCTIONS = {} dFUNCNAME = {} def createFunction (sType, sActionId, sCode, bStartWithEqual=False): "create a function (stored in dFUNCTIONS) and return function name" sCode = prepareFunction(sCode) if sActionId not in dFUNCNAME: dFUNCNAME[sActionId] = {} if sCode not in dFUNCNAME[sActionId]: dFUNCNAME[sActionId][sCode] = len(dFUNCNAME[sActionId])+1 sFuncName = "_g_" + sType + "_" + sActionId + "_" + str(dFUNCNAME[sActionId][sCode]) dFUNCTIONS[sFuncName] = sCode return sFuncName if not bStartWithEqual else "="+sFuncName def prepareFunction (s): "convert simple rule syntax to a string of Python code" if s[0:1] == "=": s = s[1:] s = s.replace("__also__", "bCondMemo") s = s.replace("__else__", "not bCondMemo") s = s.replace("sContext", "_sAppContext") s = re.sub(r"(morph|morphVC|analyse|value|displayInfo)[(]\\(\d+)", 'g_\\1(lToken[nTokenOffset+\\2]', s) s = re.sub(r"(morph|morphVC|analyse|value|displayInfo)[(]\\-(\d+)", 'g_\\1(lToken[nLastToken-\\2+1]', s) s = re.sub(r"(select|exclude|define|define_from)[(][\\](\d+)", 'g_\\1(lToken[nTokenOffset+\\2]', s) s = re.sub(r"(select|exclude|define|define_from)[(][\\]-(\d+)", 'g_\\1(lToken[nLastToken-\\2+1]', s) |
︙ | |||
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | + + - - - + + + | sOption = False m = re.match("/(\\w+)/", sAction) if m: sOption = m.group(1) sAction = sAction[m.end():].strip() if nPriority == -1: nPriority = dOptPriority.get(sOption, 4) # valid action? m = re.search(r"(?P<action>[-~=/%>])(?P<start>-?\d+\.?|)(?P<end>:\.?-?\d+|)(?P<casing>:|)>>", sAction) if not m: print(" # Error. No action found at: ", sActionId) return None # Condition sCondition = sAction[:m.start()].strip() if sCondition: sCondition = changeReferenceToken(sCondition, dPos) |
︙ | |||
232 233 234 235 236 237 238 | 249 250 251 252 253 254 255 256 257 258 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 | - + - - - - - + - - - + - - - - - + | sURL = "" mURL = re.search("[|] *(https?://.*)", sMsg) if mURL: sURL = mURL.group(1).strip() sMsg = sMsg[:mURL.start(0)].strip() checkTokenNumbers(sMsg, sActionId, nToken) if sMsg[0:1] == "=": |
︙ | |||
387 388 389 390 391 392 393 | 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | - + - + - + - + - + | 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" for sFuncName, sReturn in dFUNCTIONS.items(): |
︙ |