Skip to content

Commit

Permalink
statements: updated in_file to return ProgramStatements
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTimperley committed Jul 13, 2024
1 parent 4bfbaa3 commit bf168d7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/kaskara/statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def to_dict(self) -> dict[str, t.Any]:


@dataclass
class ProgramStatements:
class ProgramStatements(t.Iterable[Statement]):
_project_directory: str
_statements: t.Sequence[Statement]
_file_to_statements: t.Mapping[
Expand Down Expand Up @@ -131,13 +131,16 @@ def __len__(self) -> int:
def __iter__(self) -> Iterator[Statement]:
yield from self._statements

def in_file(self, filename: str) -> Iterator[Statement]:
"""Returns an iterator over the statements belonging to a file."""
def in_file(self, filename: str) -> ProgramStatements:
"""Returns the statements belonging to a file."""
if os.path.isabs(filename):
start = self._project_directory
filename = os.path.relpath(filename, start=start)

yield from self._file_to_statements.get(filename, [])
return self.build(
project_directory=self._project_directory,
statements=self._file_to_statements.get(filename, []),
)

def at_line(self, line: FileLine) -> Iterator[Statement]:
"""Returns an iterator over the statements located at a given line."""
Expand Down

0 comments on commit bf168d7

Please sign in to comment.