Example #1
0
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))
Example #2
0
def Main(source):
    """Main function."""
    
    tree = parser._parse(source)
    transforme = parser.Transformer()
    ourTree = transforme.visitRCFAE(tree)
    answer = Interpret(ourTree)
    print answer.__str__()
Example #3
0
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
Example #4
0
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
Example #5
0
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))
Example #6
0
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))
Example #7
0
 def coerce_to_rule(rule):
   if isinstance(rule, basestring):
     return _parse(rule)
   else:
     return (rule, )
Example #8
0
def parse(url, check_domain=True):
    return GitUrlParsed(_parse(url, check_domain))
Example #9
0
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]
Example #10
0
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]