Example #1
0
	def parse(self, text, dt, pos=0, debug=-9999):
		first = True
		d = adatetime()
		seen = [False] * len(self.elements)

		while True:
			newpos = pos
			print_debug(debug, "Bag %s text=%r", self.name, text[pos:])
			if not first:
				print_debug(debug, "Bag %s looking for sep", self.name)
				m = self.sep_expr.match(text, pos)
				if m:
					newpos = m.end()
				else:
					print_debug(debug, "Bag %s didn't find sep", self.name)
					break

			for i, e in enumerate(self.elements):
				print_debug(debug, "Bag %s trying=%r", self.name, e)

				try:
					at, xpos = e.parse(text, dt, newpos, debug + 1)
				except TimeError:
					at, xpos = None, None

				print_debug(debug, "Bag %s result=%r", self.name, at)
				if at:
					if self.onceper and seen[i]:
						return (None, None)

					d = fill_in(d, at)
					newpos = xpos
					seen[i] = True
					break
			else:
				break

			pos = newpos
			if self.onceper and all(seen):
				break

			first = False

		if (not any(seen)
			or (self.allof and not all(seen[pos] for pos in self.allof))
			or (self.anyof and not any(seen[pos] for pos in self.anyof))
			or (self.requireall and not all(seen))):
			return (None, None)

		print_debug(debug, "Bag %s final=%r", self.name, d)
		return (d, pos)
Example #2
0
    def parse(self, text, dt, pos=0, debug=-9999):
        first = True
        d = adatetime()
        seen = [False] * len(self.elements)

        while True:
            newpos = pos
            print_debug(debug, "Bag %s text=%r", self.name, text[pos:])
            if not first:
                print_debug(debug, "Bag %s looking for sep", self.name)
                m = self.sep_expr.match(text, pos)
                if m:
                    newpos = m.end()
                else:
                    print_debug(debug, "Bag %s didn't find sep", self.name)
                    break

            for i, e in enumerate(self.elements):
                print_debug(debug, "Bag %s trying=%r", self.name, e)

                try:
                    at, xpos = e.parse(text, dt, newpos, debug + 1)
                except TimeError:
                    at, xpos = None, None

                print_debug(debug, "Bag %s result=%r", self.name, at)
                if at:
                    if self.onceper and seen[i]:
                        return (None, None)

                    d = fill_in(d, at)
                    newpos = xpos
                    seen[i] = True
                    break
            else:
                break

            pos = newpos
            if self.onceper and all(seen):
                break

            first = False

        if (not any(seen) or (self.allof and not all(seen[pos]
                                                     for pos in self.allof))
                or (self.anyof and not any(seen[pos] for pos in self.anyof))
                or (self.requireall and not all(seen))):
            return (None, None)

        print_debug(debug, "Bag %s final=%r", self.name, d)
        return (d, pos)
Example #3
0
	def parse(self, text, dt, pos=0, debug=-9999):
		d = adatetime()
		first = True
		foundall = False
		failed = False

		print_debug(debug, "Seq %s sep=%r text=%r", self.name,
					self.sep_pattern, text[pos:])
		for e in self.elements:
			print_debug(debug, "Seq %s text=%r", self.name, text[pos:])
			if self.sep_expr and not first:
				print_debug(debug, "Seq %s looking for sep", self.name)
				m = self.sep_expr.match(text, pos)
				if m:
					pos = m.end()
				else:
					print_debug(debug, "Seq %s didn't find sep", self.name)
					break

			print_debug(debug, "Seq %s trying=%r at=%s", self.name, e, pos)

			try:
				at, newpos = e.parse(text, dt, pos=pos, debug=debug + 1)
			except TimeError:
				failed = True
				break

			print_debug(debug, "Seq %s result=%r", self.name, at)
			if not at:
				break
			pos = newpos

			print_debug(debug, "Seq %s adding=%r to=%r", self.name, at, d)
			try:
				d = fill_in(d, at)
			except TimeError:
				print_debug(debug, "Seq %s Error in fill_in", self.name)
				failed = True
				break
			print_debug(debug, "Seq %s filled date=%r", self.name, d)

			first = False
		else:
			foundall = True

		if not failed and (foundall or (not first and self.progressive)):
			print_debug(debug, "Seq %s final=%r", self.name, d)
			return (d, pos)
		else:
			print_debug(debug, "Seq %s failed", self.name)
			return (None, None)
Example #4
0
    def parse(self, text, dt, pos=0, debug=-9999):
        d = adatetime()
        first = True
        foundall = False
        failed = False

        print_debug(debug, "Seq %s sep=%r text=%r", self.name,
                    self.sep_pattern, text[pos:])
        for e in self.elements:
            print_debug(debug, "Seq %s text=%r", self.name, text[pos:])
            if self.sep_expr and not first:
                print_debug(debug, "Seq %s looking for sep", self.name)
                m = self.sep_expr.match(text, pos)
                if m:
                    pos = m.end()
                else:
                    print_debug(debug, "Seq %s didn't find sep", self.name)
                    break

            print_debug(debug, "Seq %s trying=%r at=%s", self.name, e, pos)

            try:
                at, newpos = e.parse(text, dt, pos=pos, debug=debug + 1)
            except TimeError:
                failed = True
                break

            print_debug(debug, "Seq %s result=%r", self.name, at)
            if not at:
                break
            pos = newpos

            print_debug(debug, "Seq %s adding=%r to=%r", self.name, at, d)
            try:
                d = fill_in(d, at)
            except TimeError:
                print_debug(debug, "Seq %s Error in fill_in", self.name)
                failed = True
                break
            print_debug(debug, "Seq %s filled date=%r", self.name, d)

            first = False
        else:
            foundall = True

        if not failed and (foundall or (not first and self.progressive)):
            print_debug(debug, "Seq %s final=%r", self.name, d)
            return (d, pos)
        else:
            print_debug(debug, "Seq %s failed", self.name)
            return (None, None)