Exemple #1
0
 def rewrite_atom(self,atom,always=False):
     if not (self.pref and (always or self.to_pref == None or split_name(atom.rep)[0] in self.to_pref)):
         return atom
     the_pref = self.pref
     if self.static != None and atom.rep in self.static:
         the_pref = Atom(the_pref.rep)
     return compose_atoms(the_pref,atom)
Exemple #2
0
def str_subst(s, subst):
    names = split_name(s)
    it = subst.get(names[0], names[0])
    if isinstance(it, This):
        if len(names) > 1:
            return compose_names(*names[1:])
        return it
    return compose_names(it, *names[1:])
Exemple #3
0
def str_subst(s,subst):
    names = split_name(s)
    it = subst.get(names[0],names[0])
    if isinstance(it,This):
        if len(names) > 1:
            return compose_names(*names[1:])
        return it
    return compose_names(it,*names[1:])
Exemple #4
0
 def rewrite_atom(self,atom,always=False):
     if not (self.pref and (always or self.to_pref == None or isinstance(atom.rep,This) or 
             split_name(atom.rep)[0] in self.to_pref)):
         return atom
     the_pref = self.pref
     if self.static != None and atom.rep in self.static:
         the_pref = Atom(the_pref.rep)
     return compose_atoms(the_pref,atom)
 def rewrite_atom(self,atom,always=False):
     if not(isinstance(atom.rep,This) or atom.rep.startswith('"')):
         g = name_parser.findall(atom.rep)
         if len(g) > 1:
             n = g[0] + ''.join(('[' + self.prefix_str(x[1:-1],always) + ']' if x.startswith('[') else x) for x in g[1:])
             atom = atom.rename(n)
     if not (self.pref and (always or self.to_pref == None or isinstance(atom.rep,This) or 
             split_name(atom.rep)[0] in self.to_pref)):
         return atom
     the_pref = self.pref
     if self.static != None and atom.rep in self.static:
         the_pref = Atom(the_pref.rep)
     return compose_atoms(the_pref,atom)
def substitute_constants_ast2(ast,subs):
    """
    Substitute terms for variables in an ast. Here, subs is
    a dict from string names of variables to terms.
    """
    if (isinstance(ast, Atom) or isinstance(ast,App)) and not ast.args:
        if ast.rep in subs:
            return subs[ast.rep]
        names = split_name(ast.rep)
        if names[0] in subs:
            thing = type(ast)(compose_names(*names[1:]),ast.args)
            thing.lineno = ast.lineno
            res = MethodCall(subs[names[0]],thing)
            res.lineno = ast.lineno
            return res
        return ast
    else:
        if isinstance(ast,str):
            return ast
        new_args = [substitute_constants_ast2(x,subs) for x in ast.args]
        res = ast.clone(new_args)
        copy_attributes_ast(ast,res)
        return res
Exemple #7
0
def subst_subscripts(s,subst):
    return compose_names(*[subst_subscripts_comp(t,subst) for t in split_name(s)])
 def prefix_str(self,name,always):
     if not (self.pref and (always or self.to_pref == None or split_name(name)[0] in self.to_pref)):
         return name
     return iu.compose_names(self.pref.rep,name)
Exemple #9
0
def str_subst(s,subst):
    names = split_name(s)
    return compose_names(subst.get(names[0],names[0]),*names[1:])
Exemple #10
0
def subst_subscripts(s, subst):
    return compose_names(
        *[subst_subscripts_comp(t, subst) for t in split_name(s)])
Exemple #11
0
def str_subst(s,subst):
    names = split_name(s)
    return compose_names(subst.get(names[0],names[0]),*names[1:])