Example #1
0
 def apply(self, term, ctx):
     x = self.loperand.apply(term, ctx)
     y = self.roperand.apply(term, ctx)
     try:
         return self.func(term, x, y)
     except TypeError:
         raise exception.Failure('wrong term type', x, y)
Example #2
0
File: project.py Project: uxmal/idc
 def apply(self, trm, ctx):
     try:
         name = trm.name
     except AttributeError:
         raise exception.Failure("not an application term", trm)
     else:
         return trm.factory.makeStr(name)
Example #3
0
File: table.py Project: uxmal/idc
    def congruent(binding, trm, ctx):
        '''Lookups the key matching to the term in the table and return its
		associated value.
		'''
        tbl = _table(binding, ctx)
        try:
            return tbl[trm]
        except KeyError:
            raise exception.Failure("term not in table", trm)
Example #4
0
File: strings.py Project: uxmal/idc
 def apply(self, term, ctx):
     head = self.loperand.apply(term, ctx)
     tail = self.roperand.apply(term, ctx)
     try:
         head_value = aterm.convert.toStr(head)
         tail_value = aterm.convert.toStr(tail)
     except TypeError:
         raise exception.Failure('not string terms', head, tail)
     return term.factory.makeStr(head_value + tail_value)
Example #5
0
File: table.py Project: uxmal/idc
 def match(binding, trm, ctx):
     '''Lookups the key matching the term in the table.'''
     tbl = _table(binding, ctx)
     try:
         tbl[trm]
     except KeyError:
         raise exception.Failure("term not in table", trm)
     else:
         return trm
Example #6
0
File: table.py Project: uxmal/idc
    def unset(binding, trm, ctx):
        '''Setting a [key, value] list will add the pair to the table. Setting
		a [key] list will remove the key and its value from the table.'''
        # TODO: better exception handling
        tbl = _table(binding, ctx)
        try:
            return tbl.pop(trm)
        except KeyError:
            raise exception.Failure("term not in table", trm)
        return trm
Example #7
0
    def match(binding, trm, ctx):
        '''Match the term against this variable value, setting it,
		if it is undefined.'''
        old = binding.get(ctx)
        if old is None:
            binding.set(ctx, trm)
        elif old != trm:
            raise exception.Failure('variable mismatch', binding.name, trm,
                                    old)
        return trm
Example #8
0
 def apply(self, term, ctx):
     try:
         head = term.head
         tail = term.tail
     except AttributeError:
         raise exception.Failure('not a list construction term', term)
     else:
         self.tail.apply(tail, ctx)
         self.head.apply(head, ctx)
         return term
Example #9
0
 def apply(self, term, ctx):
     try:
         name = term.name
         args = term.args
     except AttributeError:
         raise exception.Failure('not an application term', term)
     else:
         factory = term.factory
         self.name.apply(factory.makeStr(name), ctx)
         self.args.apply(factory.makeList(args), ctx)
         return term
Example #10
0
    def apply(self, term, ctx):
        try:
            old_head = term.head
            old_tail = term.tail
        except AttributeError:
            raise exception.Failure('not a list cons term', term)

        new_tail = self.tail.apply(old_tail, ctx)
        new_head = self.head.apply(old_head, ctx)

        if new_head is not old_head or new_tail is not old_tail:
            return term.factory.makeCons(new_head, new_tail)
        else:
            return term
Example #11
0
    def apply(self, term, ctx):
        try:
            old_name = term.name
            old_args = term.args
        except AttributeError:
            raise exception.Failure('not an application term', term)

        factory = term.factory
        old_name = factory.makeStr(old_name)
        old_args = factory.makeList(old_args)
        new_name = self.name.apply(old_name, ctx)
        new_args = self.args.apply(old_args, ctx)

        if new_name is not old_name or new_args is not old_args:
            new_name = new_name.value
            new_args = tuple(new_args)
            return term.factory.makeAppl(new_name, new_args, term.annotations)
        else:
            return term
Example #12
0
    def apply(self, term, ctx):
        try:
            name = term.name
            old_args = term.args
        except AttributeError:
            raise exception.Failure('not an application term', term)

        if name != self.name:
            raise exception.Failure

        if len(self.args) != len(old_args):
            raise exception.Failure

        new_args = []
        modified = False
        for self_arg, old_arg in zip(self.args, old_args):
            new_arg = self_arg.apply(old_arg, ctx)
            new_args.append(new_arg)
            modified = modified or new_arg is not old_arg

        if modified:
            return term.factory.makeAppl(name, new_args, term.annotations)
        else:
            return term
Example #13
0
 def apply(self, term, ctx):
     if not aterm.types.isNil(term):
         raise exception.Failure('term is not an empty list', term)
     return term
Example #14
0
 def apply(self, term, ctx):
     if term in self.terms:
         return term
     else:
         raise exception.Failure('term not in set', term)
Example #15
0
 def apply(self, term, ctx):
     if self.term == term:
         return term
     else:
         raise exception.Failure('term mismatch', self.term, term)
Example #16
0
File: project.py Project: uxmal/idc
 def apply(self, trm, ctx):
     if not aterm.types.isAppl(trm):
         raise exception.Failure("not an application term", trm)
     return trm.factory.makeList(trm.args)
Example #17
0
 def build(binding, trm, ctx):
     '''Returns this variable term, if defined.'''
     trm = binding.get(ctx)
     if trm is None:
         raise exception.Failure('undefined variable', binding.name)
     return trm
Example #18
0
File: project.py Project: uxmal/idc
 def apply(self, trm, ctx):
     try:
         return trm.tail
     except AttributeError:
         raise exception.Failure("not a list construction term", trm)
Example #19
0
File: strings.py Project: uxmal/idc
 def apply(self, term, ctx):
     try:
         return term.factory.makeStr(str(term.value))
     except AttributeError:
         raise exception.Failure('not a literal term', term)