Ejemplo n.º 1
0
 def at(self, name, fn, options):
     index = self.__find(name)
     opt = options or {}
     if index == -1:
         return throwError('Parser rule not found:' + name)
     self.__rules[index]['fn'] = fn
     self.__rules[index]['alt'] = opt['alt'] or []
     self.__cache = None
Ejemplo n.º 2
0
 def after(self, afterName, ruleName, fn, options):
     index = self.__find(afterName)
     opt = options or {}
     if index == -1:
         return throwError('Parser rule not found: ' + afterName)
     self.__rules.insert(index + 1, {
         'name': ruleName,
         'enabled': True,
         'fn': fn,
         'alt': opt['alt'] or []
     })
     self.__cache = None
Ejemplo n.º 3
0
    def disable(self, array, ignoreInvalid=None):
        if not isinstance(array, list):
            array = [array]
        result = []
        for name in array:
            idx = self.__find(name)
            if idx < 0:
                if ignoreInvalid:
                    return
                return throwError('Rules manager: invalid rule name ' + name)
            self.__rules[idx]['enabled'] = False
            result.append(name)

        self.__cache = None
        return result