Beispiel #1
0
 def parse(self, text, position, endPosition, space):
   result = self.parser.parse(text, position, endPosition, space)
   if not result:
     return failure(result.expected)
   if self._passPosition:
     translated = self.function(result.value, result.end)
   else:
     translated = self.function(result.value)
   return match(result.end, translated, result.expected)
Beispiel #2
0
 def parse(self, text, position, endPosition, space):
   result = self.parser.parse(text, position, endPosition, space)
   if not result:
     return failure(result.expected)
   if self._passPosition:
     translated = self.function(result.value, result.end)
   else:
     translated = self.function(result.value)
   return match(result.end, translated, result.expected)
Beispiel #3
0
 def parse(self, text, position, end, space):
     position = start = space.consume(text, position, end)
     regex_match = self.regex.search(text, position, end)
     if regex_match:
         # print regex_match.start()
         position = regex_match.start()
         return parcon.match(position, text[start:position].strip(), [(position, parcon.EUnsatisfiable())])
     else:
         return parcon.failure("regex not found")
Beispiel #4
0
 def parse(self, text, position, end, space):
     position = space.consume(text, position, end)
     if position + self.length > end:
         return parcon.failure([(position, parcon.ECustomExpectation("struct.unpack format " + repr(self.format)))])
     result =  struct.unpack(self.format, text[position:position+self.length])
     if len(result) == 1:
         result = result[0]
     else:
         result = list(result)
     return parcon.match(position + self.length, result, (position + self.length, parcon.EUnsatisfiable()))
Beispiel #5
0
 def parse(self, text, position, end, space):
     position = space.consume(text, position, end)
     if position + self.length > end:
         return parcon.failure([
             (position,
              parcon.ECustomExpectation("struct.unpack format " +
                                        repr(self.format)))
         ])
     result = struct.unpack(self.format,
                            text[position:position + self.length])
     if len(result) == 1:
         result = result[0]
     else:
         result = list(result)
     return parcon.match(position + self.length, result,
                         (position + self.length, parcon.EUnsatisfiable()))