1 """
2 A (quite trivial) grammar that iterates over lists of dicts.
3 """
4
5
6
7
8
9
10
11 from gavo import base
12 from gavo.grammars.common import Grammar, RowIterator
13
14
17 RowIterator.__init__(self, *args, **kwargs)
18 self.recNo = 0
19 if self.grammar.asPars:
20 self.sourceRow = self.sourceToken[0]
21
23 if self.grammar.asPars:
24 return
25 self.recNo = 1
26 for rec in self.sourceToken:
27 res = rec.copy()
28 yield res
29 self.recNo += 1
30
32 return "List, index=%d"%self.recNo
33
34
36 """A grammar that "parses" from lists of dicts.
37
38 Actually, it will just return the dicts as they are passed. This is
39 mostly useful internally, though it might come in handy in custom code.
40 """
41 name_ = "dictlistGrammar"
42 rowIterator = ListIterator
43
44 _asPars = base.BooleanAttribute("asPars", default=False, description=
45 "Just return the first item of the list as parameters row and exit?")
46