Grammalecte  Check-in [da8c5de7df]

Overview
Comment:[build][core] rules graph: definitions and multiple tokens
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | build | rg
Files: files | file ages | folders
SHA3-256: da8c5de7dfa98ccb745eb92a8e910af8c4dcadf31fac8de78ad631273941fb2c
User & Date: olr on 2018-05-24 11:14:16
Other Links: branch diff | manifest | tags
Context
2018-05-25
10:07
[build][core] multiple tokens and groups check-in: e83552ea6d user: olr tags: build, core, rg
2018-05-24
11:14
[build][core] rules graph: definitions and multiple tokens check-in: da8c5de7df user: olr tags: build, core, rg
11:13
[build][bug] darg: wrong statement check-in: c4ce706a6b user: olr tags: build, rg
Changes

Modified compile_rules_graph.py from [a8ad098a64] to [b56c5bc314].

    42     42   
    43     43   
    44     44   def changeReferenceToken (s, dPos):
    45     45       for i in range(len(dPos), 0, -1):
    46     46           s = s.replace("\\"+str(i), "\\"+dPos[i])
    47     47       return s
    48     48   
           49  +
           50  +def genTokenRules (sTokenLine):
           51  +    lToken = sTokenLine.split()
           52  +    lTokenRules = None
           53  +    for i, sToken in enumerate(lToken):
           54  +        if sToken.startswith("{") and sToken.endswith("}") and sToken in dDEF:
           55  +            lToken[i] = dDEF[sToken]
           56  +        if sToken.startswith("[") and sToken.endswith("]"):
           57  +            # multiple token
           58  +            if not lTokenRules:
           59  +                lTokenRules = [ sToken[1:-1].split("|") ]
           60  +            else:
           61  +                lNewTemp = []
           62  +                for aRule in lTokenRules:
           63  +                    lElem = sToken[1:-1].split("|")
           64  +                    sElem1 = lElem.pop(0)
           65  +                    for sElem in lElem:
           66  +                        aNew = list(aRule)
           67  +                        aNew.append(sElem)
           68  +                        lNewTemp.append(aNew)
           69  +                    aRule.append(sElem1)
           70  +                lTokenRules.extend(lNewTemp)
           71  +        else:
           72  +            # simple token
           73  +            if not lTokenRules:
           74  +                lTokenRules = [[sToken]]
           75  +            else:
           76  +                for aRule in lTokenRules:
           77  +                    aRule.append(sToken)
           78  +    for aRule in lTokenRules:
           79  +        print("Rule\n", aRule)
           80  +        yield aRule
           81  +
    49     82   
    50     83   def createRule (iLine, sRuleName, sTokenLine, sActions, nPriority):
    51     84       # print(iLine, "//", sRuleName, "//", sTokenLine, "//", sActions, "//", nPriority)
    52         -    lToken = sTokenLine.split()
    53         -
    54         -    # Calculate positions
    55         -    dPos = {}
    56         -    nGroup = 0
    57         -    for i, sToken in enumerate(lToken):
    58         -        if sToken.startswith("(") and sToken.endswith(")"):
    59         -            lToken[i] = sToken[1:-1]
    60         -            nGroup += 1
    61         -            dPos[nGroup] = i
    62         -
    63         -    # Parse actions
    64         -    for nAction, sAction in enumerate(sActions.split(" <<- ")):
    65         -        if sAction.strip():
    66         -            sActionId = sRuleName + "_a" + str(nAction)
    67         -            aAction = createAction(sActionId, sAction, nGroup, nPriority, dPos)
    68         -            if aAction:
    69         -                dACTIONS[sActionId] = aAction
    70         -                lResult = list(lToken)
    71         -                lResult.extend(["##"+str(iLine), sActionId])
    72         -                yield lResult
           85  +    for lToken in genTokenRules(sTokenLine):
           86  +        # Calculate positions
           87  +        dPos = {}
           88  +        nGroup = 0
           89  +        for i, sToken in enumerate(lToken):
           90  +            if sToken.startswith("(") and sToken.endswith(")"):
           91  +                lToken[i] = sToken[1:-1]
           92  +                nGroup += 1
           93  +                dPos[nGroup] = i
           94  +
           95  +        # Parse actions
           96  +        for nAction, sAction in enumerate(sActions.split(" <<- ")):
           97  +            if sAction.strip():
           98  +                sActionId = sRuleName + "_a" + str(nAction)
           99  +                aAction = createAction(sActionId, sAction, nGroup, nPriority, dPos)
          100  +                if aAction:
          101  +                    dACTIONS[sActionId] = aAction
          102  +                    lResult = list(lToken)
          103  +                    lResult.extend(["##"+str(iLine), sActionId])
          104  +                    yield lResult
    73    105   
    74    106   
    75    107   def createAction (sIdAction, sAction, nGroup, nPriority, dPos):
    76    108       m = re.search("([-~=])(\\d+|)(:\\d+|)>> ", sAction)
    77    109       if not m:
    78    110           print(" # Error. No action found at: ", sIdAction)
    79    111           print("   ==", sAction, "==")

Modified gc_lang/fr/rules_graph.grx from [afffaf61f2] to [25632727ec].

    48     48   __rule2__
    49     49       ci important que soi
    50     50       ci vraiment il y a
    51     51       ci pour ça
    52     52           <<- morph(\2, ":[WAR]", False) -1>> si   # Message1|http://test.grammalecte.net
    53     53   
    54     54   __rule3__
    55         -    contre nature
    56         -    contre pétrie
    57         -    contre action
           55  +    contre [nature|pétrie|action]
    58     56           <<- morph(\1, "xxxx") -1:2>> =\1+\2     # Message2|http://test.grammalecte.org
    59     57           <<-  ~>> hyper|fonction
    60     58