コード例 #1
0
ファイル: rules.py プロジェクト: wtimme/ocstyle
 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)
コード例 #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)
コード例 #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")
コード例 #4
0
ファイル: binary.py プロジェクト: BrenBarn/parcon
 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()))
コード例 #5
0
ファイル: binary.py プロジェクト: dvogel/Parcon
 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()))