33Parses Scala case class definitions suitable for Doobie, Quill,
44or Slick into the internal schema representation.
55"""
6+
67from __future__ import annotations
78
89import re
1213
1314# Regex: extract case class
1415_CASE_CLASS_RE = re .compile (
15- r' (?:@(?:Entity|Table|Mapped)\s*(?:\([^)]*\))?\s*)?'
16- r' (?:case\s+)?class\s+(\w+)'
17- r' (?:\s*\(((?:[^()]|\([^()]*\))*)\))' ,
16+ r" (?:@(?:Entity|Table|Mapped)\s*(?:\([^)]*\))?\s*)?"
17+ r" (?:case\s+)?class\s+(\w+)"
18+ r" (?:\s*\(((?:[^()]|\([^()]*\))*)\))" ,
1819 re .MULTILINE ,
1920)
2021
2122# Regex: extract field from case class parameter list
22- _FIELD_RE = re .compile (
23- r'\s*(\w+)\s*:\s*([^=,]+)(?:\s*=\s*([^,]+))?\s*,?\s*'
24- )
23+ _FIELD_RE = re .compile (r"\s*(\w+)\s*:\s*([^=,]+)(?:\s*=\s*([^,]+))?\s*,?\s*" )
2524
2625# Map Scala types to ColumnType
2726_SCALA_TYPE_MAP : dict [str , ColumnType ] = {
@@ -92,8 +91,9 @@ def _parse_default(value_str: str) -> Any:
9291 return None
9392
9493 # Quoted strings
95- if (val .startswith ('"' ) and val .endswith ('"' )) or \
96- (val .startswith ('"""' ) and val .endswith ('"""' )):
94+ if (val .startswith ('"' ) and val .endswith ('"' )) or (
95+ val .startswith ('"""' ) and val .endswith ('"""' )
96+ ):
9797 inner = val .strip ('"' )
9898 # Handle interpolation: s"..."
9999 idx = inner .find ("$" )
@@ -143,7 +143,9 @@ def parse(self, text: str) -> Schema:
143143 fields = _FIELD_RE .findall (params_str )
144144
145145 for field_name , field_type , default_str in fields :
146- col = self ._field_to_column (field_name , field_type .strip (), default_str .strip ())
146+ col = self ._field_to_column (
147+ field_name , field_type .strip (), default_str .strip ()
148+ )
147149 if col :
148150 table .columns .append (col )
149151
@@ -152,7 +154,9 @@ def parse(self, text: str) -> Schema:
152154
153155 return schema
154156
155- def _field_to_column (self , name : str , raw_type : str , default_str : str ) -> Column | None :
157+ def _field_to_column (
158+ self , name : str , raw_type : str , default_str : str
159+ ) -> Column | None :
156160 """Convert a Scala field to a Column IR."""
157161 clean_type , is_optional = _clean_scala_type (raw_type )
158162
0 commit comments