예제 #1
0
 def unapply(self,value):
     if type(value) == list and len(value) > 0:
         iterator = iter(value)
         return self.head.unapply(iterator.next()) |bind| \
                (lambda rhead:self.tail.unapply(list(iterator)) |bind| \
                (lambda rtail:option(MatchResult(value,[]) << rhead << rtail)))
     else:
         return option()
예제 #2
0
 def unapply(self, value):
     if type(value) == list and len(value) > 0:
         iterator = iter(value)
         return self.head.unapply(iterator.next()) |bind| \
                (lambda rhead:self.tail.unapply(list(iterator)) |bind| \
                (lambda rtail:option(MatchResult(value,[]) << rhead << rtail)))
     else:
         return option()
예제 #3
0
 def unapply(self, value):
     return self.value.unapply(value) | bind | (
         lambda res: option(MatchResult(value, [res.value]) << res))
예제 #4
0
 def unapply(self, value):
     return option(MatchResult(value, []))
예제 #5
0
 def unapply(self, value):
     try:
         return option(MatchResult(self.match(value), []))
     except:
         return option()
예제 #6
0
 def compareWith(self, value):
     return option(True if isinstance(value, self.value) else None)
예제 #7
0
 def unapply(self, value):
     return option(re.match(self.value, value)) | bind | (
         lambda res: option(MatchResult(res.groups(), [])))
예제 #8
0
 def __call__(self, stream):
     return option(re.match(self.regex, stream.value())) | bind | (
         lambda result: option(stream.offset(len(result.group()))) | bind |
         (lambda _: option(
             self.kind(result.groups()[len(result.groups()) - 1]))))
예제 #9
0
 def compareWith(self,value):
     return option(True if self.value == value else None)
예제 #10
0
 def unapply(self,value):
     return self.value.unapply(value) |bind| (lambda res:option(MatchResult(value,[res.value]) << res))
예제 #11
0
 def unapply(self,value):
     return option(MatchResult(value,[]))
예제 #12
0
 def unapply(self,value):
     try:
         return option(MatchResult(self.match(value),[]))
     except:
         return option()
예제 #13
0
 def compareWith(self,value):
     return option(True if isinstance(value,self.value) else None)
예제 #14
0
 def __call__(self,stream):
     return option(re.match(self.regex,stream.value())) |bind| (
            lambda result: option(stream.offset(len(result.group()))) |bind| (
            lambda _: option(self.kind(result.groups()[len(result.groups())-1]))))
예제 #15
0
def test(a, expected):
    return (a | bind | (lambda _: option(True))).join() == expected
예제 #16
0
 def unapply(self,value):
     return option(MatchResult(value,[]) if set(value) == set([]) else None)
예제 #17
0
 def unapply(self,value):
     return self.compareWith(value) |bind| (lambda _:option(MatchResult(value,[])))
예제 #18
0
 def compareWith(self, value):
     return option(True if self.value == value else None)
예제 #19
0
 def unapply(self, value):
     return option(
         MatchResult(value, []) if set(value) == set([]) else None)
예제 #20
0
 def unapply(self, value):
     return self.compareWith(value) | bind | (
         lambda _: option(MatchResult(value, [])))
예제 #21
0
 def unapply(self,value):
     return option(re.match(self.value,value)) |bind| (lambda res:option(MatchResult(res.groups(),[])))
예제 #22
0
def test(a,expected):
    return (a |bind| (lambda _:option(True))).join() == expected