forked from Vanderhoof/PyDBML
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable_group.py
More file actions
58 lines (45 loc) · 1.46 KB
/
table_group.py
File metadata and controls
58 lines (45 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pyparsing as pp
from pydbml.parser.blueprints import TableGroupBlueprint, NoteBlueprint
from .common import _, _c, end, hex_color, note, note_object
from .generic import name
pp.ParserElement.set_default_whitespace_chars(' \t\r')
table_name = pp.Combine(name + '.' + name) | name
note_element = note | note_object
tg_element = _ + (note_element('note') | table_name.set_results_name('items', list_all_matches=True)) + _
tg_body = tg_element[...]
tg_color = (
pp.CaselessLiteral('color:').suppress() + _
- pp.Combine(hex_color)('color')
)
tg_setting = _ + (note('note') | tg_color) + _
tg_settings = '[' + tg_setting + (',' + tg_setting)[...] + ']'
table_group = _c + (
pp.CaselessLiteral('TableGroup')
- name('name') + _
+ tg_settings[0, 1] + _
- '{' + _
- tg_body + _
- '}'
) + end
def parse_table_group(s, loc, tok):
'''
TableGroup tablegroup_name {
table1
table2
table3
}
'''
init_dict = {
'name': tok['name'],
'items': list(tok.get('items', []))
}
if 'comment_before' in tok:
comment = '\n'.join(c[0] for c in tok['comment_before'])
init_dict['comment'] = comment
if 'note' in tok:
note = tok['note']
init_dict['note'] = note if isinstance(note, NoteBlueprint) else note[0]
if 'color' in tok:
init_dict['color'] = tok['color']
return TableGroupBlueprint(**init_dict)
table_group.set_parse_action(parse_table_group)