Skip to content

Commit 333bdfd

Browse files
committed
feat: Add comments to pyproject.toml explaining how to build source and wheel distributions
1 parent 1e1b21e commit 333bdfd

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
requires = ["setuptools>=61.0", "wheel", "setuptools_scm[toml]>=6.2"]
33
build-backend = "setuptools.build_meta"
44

5+
# To build both source and wheel distributions:
6+
# python -m build --sdist --wheel
7+
# This creates both .tar.gz (source) and .whl (wheel) files in the 'dist' directory
8+
59
[project]
610
name = "cedarscript-ast-parser"
711
dynamic = ["version"]
@@ -22,7 +26,7 @@ classifiers = [
2226
]
2327
keywords = ["parser", "ast", "cedarscript", "code-editing", "refactoring", "code-analysis", "sql-like", "ai-assisted-development"]
2428
dependencies = [
25-
"cedarscript-grammar>=0.0.10",
29+
"cedarscript-grammar>=0.0.11",
2630
]
2731
requires-python = ">=3.8"
2832

src/cedarscript_ast_parser/cedarscript_ast_parser.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def as_marker(self) -> 'Marker':
5555
return self
5656

5757
def __str__(self):
58-
result = f"{self.type.value} '{self.value}'"
58+
result = f"{self.type.value} '{self.value.strip()}'"
5959
if self.offset is not None:
6060
result += f" at offset {self.offset}"
6161
return result
@@ -107,17 +107,20 @@ class SingleFileClause:
107107

108108
@dataclass
109109
class IdentifierFromFile(SingleFileClause, MarkerCompatible):
110-
where_clause: WhereClause
111110
identifier_type: MarkerType # VARIABLE, FUNCTION, CLASS (but not LINE)
111+
name: str
112+
where_clause: WhereClause
112113
offset: int | None = None
113114

114115
@property
115116
def as_marker(self) -> Marker:
116117
# TODO Handle different values for field and operator in where_clause
117-
return Marker(self.identifier_type, self.where_clause.value, self.offset)
118+
return Marker(self.identifier_type, self.name or self.where_clause.value, self.offset)
118119

119120
def __str__(self):
120-
result = f"{str(self.identifier_type).lower()} ({self.where_clause})"
121+
wc = self.where_clause
122+
if wc: wc = f' ({wc})'
123+
result = f"{str(self.identifier_type).lower()} {self.name}{wc}"
121124
if self.offset is not None:
122125
result += f" at offset {self.offset}"
123126
return f"{result} from file {self.file_path}"
@@ -402,22 +405,28 @@ def parse_update_target(self, node):
402405
raise ValueError(f"[parse_update_target] Invalid target: {invalid}")
403406

404407
def parse_identifier_from_file(self, node):
405-
identifier_type = MarkerType(node.children[0].type.casefold())
408+
identifier_marker = self.find_first_by_type(node.named_children, 'identifierMarker')
409+
identifier_type = MarkerType(identifier_marker.children[0].type.casefold())
410+
name = self.parse_string(identifier_marker.named_children[0])
411+
offset_clause = self.find_first_by_type(identifier_marker.named_children, 'offset_clause')
406412
file_clause = self.find_first_by_type(node.named_children, 'singlefile_clause')
407413
where_clause = self.find_first_by_type(node.named_children, 'where_clause')
408-
offset_clause = self.find_first_by_type(node.named_children, 'offset_clause')
409414

410-
if not file_clause or not where_clause:
415+
if not file_clause or not name:
411416
raise ValueError("Invalid identifier_from_file clause")
412417

413418
file_path = self.parse_singlefile_clause(file_clause).file_path
414-
where = self.parse_where_clause(where_clause)
415419
offset = self.parse_offset_clause(offset_clause) if offset_clause else None
420+
where = self.parse_where_clause(where_clause)
416421

417-
return IdentifierFromFile(identifier_type=identifier_type, file_path=file_path,
418-
where_clause=where, offset=offset)
422+
return IdentifierFromFile(file_path=file_path,
423+
identifier_type=identifier_type, name=name, offset=offset,
424+
where_clause=where
425+
)
419426

420427
def parse_where_clause(self, node):
428+
if not node:
429+
return None
421430
condition = self.find_first_by_type(node.children, 'condition')
422431
if not condition:
423432
raise ValueError("No condition found in where clause")
@@ -596,11 +605,18 @@ def parse_string(node):
596605
text = node.text.decode('utf8')
597606
match node.type.casefold():
598607
case 'raw_string':
599-
text = text.strip('"\'')
608+
match text:
609+
case x if x.startswith("r'''") or x.startswith('r"""'):
610+
text = text[4:-3]
611+
case x if x.startswith("r'") or x.startswith('r"'):
612+
text = text[3:-1]
613+
case _:
614+
raise ValueError(f"Invalid raw string: `{text}`")
600615
case 'single_quoted_string':
601-
text = text.replace("\\'", "'").replace('\\"', '"').strip('"\'')
616+
text = text[1:-1] # Remove surrounding quotes
617+
text = text.replace("\\'", "'").replace('\\"', '"').replace("\\t", '\t')
602618
case 'multi_line_string':
603-
text = text.removeprefix("'''").removeprefix('"""').removesuffix("'''").removesuffix('"""')
619+
text = text[3:-3]
604620

605621
return text
606622

0 commit comments

Comments
 (0)