-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathproject.py
More file actions
47 lines (37 loc) · 1.21 KB
/
project.py
File metadata and controls
47 lines (37 loc) · 1.21 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
import pyparsing as pp
from .common import _, _c, c, n, note, note_object
from .generic import name, string_literal
from pydbml.parser.blueprints import NoteBlueprint, ProjectBlueprint
pp.ParserElement.set_default_whitespace_chars(' \t\r')
project_field = pp.Group(name + _ + pp.Suppress(':') + _ - string_literal)
project_element = _ + (note | note_object | project_field) + _
project_body = project_element[...]
project = _c + (
pp.CaselessLiteral('project') + _
- name('name') + _
+ '{' + _
- project_body('items') + _
- '}'
) + (n | pp.StringEnd())
def parse_project(s, loc, tok):
'''
Project project_name {
database_type: 'PostgreSQL'
Note: 'Description of the project'
}
'''
init_dict = {'name': tok['name']}
items = {}
for item in tok.get('items', []):
if isinstance(item, NoteBlueprint):
init_dict['note'] = item
else:
k, v = item
items[k] = v
if items:
init_dict['items'] = items
if 'comment_before' in tok:
comment = '\n'.join(c[0] for c in tok['comment_before'])
init_dict['comment'] = comment
return ProjectBlueprint(**init_dict)
project.set_parse_action(parse_project)