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