def parse(defn, fname = None): "Takes a docstring and returns a parsed ruleset." if not defn: if fname is not None: raise NoDocstringError("Function %s has no docstring" % fname) else: raise NoDocstringError("Provided function has no docstring") return _parse(defn.strip()) defn = [line.strip() for line in defn.split('\n') if line.strip()] return list(chain.from_iterable(_parse(line) for line in defn))
def Main(source): """Main function.""" tree = parser._parse(source) transforme = parser.Transformer() ourTree = transforme.visitRCFAE(tree) answer = Interpret(ourTree) print answer.__str__()
def create_wrapper(rule, fn): if isinstance(rule, basestring): rule = _parse(rule) # flattening rule = rule.select(()) def wrapper(p): kwargs = {} for i, term in enumerate(rule.terms): if isinstance(term, NamedTerm): kwargs[term.name] = p[i + 1] p[0] = fn(**kwargs) wrapper.__doc__ = rule.format() return wrapper
def expand_conditionals(rule, format=True): def all_subsets(set_): list_ = list(set_) for size in range(0, len(list_) + 1): for subset in combinations(list_, size): yield subset ret = [] if isinstance(rule, basestring): rule = _parse(rule) conditionals = rule.collect_conditionals() for subset in all_subsets(conditionals): # ensure that only terms in the subset are enabled if format: ret.append(rule.select(subset).format()) else: ret.append(rule.select(subset)) return sorted(set(ret))
def coerce_to_rule(rule): if isinstance(rule, basestring): return _parse(rule) else: return (rule, )
def parse(url, check_domain=True): return GitUrlParsed(_parse(url, check_domain))
def parse(defn, fname=None): if defn is None and fname is not None: raise NoDocstringError("Function %s has no docstring" % fname) defn = [line.strip() for line in defn.split("\n") if line.strip()] return [_parse(line) for line in defn]
def parse(defn, fname=None): if defn is None and fname is not None: raise NoDocstringError("Function %s has no docstring" % fname) defn = [line.strip() for line in defn.split('\n') if line.strip()] return [_parse(line) for line in defn]