MCPcopy Index your code
hub / github.com/Vanderhoof/PyDBML / PyDBMLParser

Class PyDBMLParser

pydbml/parser/parser.py:112–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110
111
112class PyDBMLParser:
113 def __init__(
114 self,
115 source: str,
116 allow_properties: bool = False,
117 sql_renderer: Type[BaseRenderer] = DefaultSQLRenderer,
118 dbml_renderer: Type[BaseRenderer] = DefaultDBMLRenderer,
119 ):
120 self.database = None
121
122 self.ref_blueprints: List[ReferenceBlueprint] = []
123 self.table_groups: List[TableGroupBlueprint] = []
124 self.source = source
125 self.tables: List[TableBlueprint] = []
126 self.refs: List[ReferenceBlueprint] = []
127 self.enums: List[EnumBlueprint] = []
128 self.project: Optional[ProjectBlueprint] = None
129 self.sticky_notes: List[StickyNoteBlueprint] = []
130 self._allow_properties = allow_properties
131 self._sql_renderer = sql_renderer
132 self._dbml_renderer = dbml_renderer
133
134 def parse(self):
135 self._set_syntax()
136 self._syntax.parse_string(self.source, parseAll=True)
137 self.build_database()
138 return self.database
139
140 def __repr__(self):
141 return "<PyDBMLParser>"
142
143 def _set_syntax(self):
144 table_expr = (
145 table_with_properties.copy() if self._allow_properties else table.copy()
146 )
147 ref_expr = ref.copy()
148 enum_expr = enum.copy()
149 table_group_expr = table_group.copy()
150 project_expr = project.copy()
151 note_expr = sticky_note.copy()
152
153 table_expr.addParseAction(self.parse_blueprint)
154 ref_expr.addParseAction(self.parse_blueprint)
155 enum_expr.addParseAction(self.parse_blueprint)
156 table_group_expr.addParseAction(self.parse_blueprint)
157 project_expr.addParseAction(self.parse_blueprint)
158 note_expr.addParseAction(self.parse_blueprint)
159
160 expr = (
161 table_expr
162 | ref_expr
163 | enum_expr
164 | table_group_expr
165 | project_expr
166 | note_expr
167 )
168 self._syntax = expr[...] + ("\n" | comment)[...] + pp.StringEnd()
169

Callers 5

test_edgeMethod · 0.90
test_repr_pydbml_parserFunction · 0.90
parseMethod · 0.85
parse_fileMethod · 0.85

Calls

no outgoing calls

Tested by 3

test_edgeMethod · 0.72
test_repr_pydbml_parserFunction · 0.72