Exemple #1
0
 def parse2(s, rhs, level, lhs, c):  # parser of single rhs clause
     self._showDebug(
         clas="Parser",
         method="_parse",
         note=".parse.parse1.parse2 inputs",
         line=243,
         level=0,
         vars=[["s", s], ["rhs", rhs], ["level", level], ["lhs", lhs], ["c", c]],
     )
     smatch = bmatch = ""  #   prepare to get match and sub_binding
     bound1 = {}
     s1 = s
     if isinstance(rhs, basestring):  #   if string for matching
         rhs = rhs.strip()  #    strip it
         if rhs.startswith("<") and rhs.endswith(">"):  #    if a nested clause
             for s1, match, bound1 in parse(s, rhs, level=level + 1):  #     for each parsed rhs:
                 bound = bound1  #      temp sub_binding store
                 if lhs in bound1:  #      if rhs clause is recursive
                     del bound1[lhs]  #       remove it from temp binding
                     self._i_rules[lhs][c][1] -= 1  #       remove it from count of BNF clauses used
                 self._showDebug(
                     clas="Parser",
                     method="_parse",
                     note=".parse.parse1.parse2 yields",
                     line=255,
                     level=0,
                     vars=[["s1", s1], ["match", match], ["bound", bound], ["bound1", bound1]],
                 )
                 yield s1, match, bound, bound1  #      yield match data
         else:  #    if a simple text matching
             if s1.startswith(rhs):  #     if match
                 smatch = bmatch = rhs  #      record solving and binding matches
     elif isinstance(rhs, mtpexits.Test):
         tmp = rhs._eval(mtpexits.Element(s))
         if tmp:
             smatch = tmp[0]
             bmatch = tmp[1]
     elif rhs.match(s):  #   else if a regex match
         ep = self._i_rules[lhs][c][2]  #    get regex parts
         smatch, bmatch = mtutils._evalRegex(
             s, rhs, ep=ep
         )  #    get solving & binding matches from regex
     self._showDebug(
         clas="Parser",
         method="_parse",
         note=".parse.parse1.parse2 yields",
         line=268,
         level=1,
         vars=[["smatch", smatch], ["bmatch", bmatch]],
     )
     if bmatch:  #   if match recorded
         s1 = s[len(smatch) :]  #    remove solving match from the remaining sentence
         bound = match = bmatch  #    temp bound and match store
         self._showDebug(
             clas="Parser",
             method="_parse",
             note=".parse.parse1.parse2 yields",
             line=272,
             level=0,
             vars=[["s1", s1], ["match", match], ["bound", bound], ["bound1", bound1]],
         )
         yield s1, match, bound, bound1  #    yield match data