Asama 0.1 — Implement SourceFile and SourceLocation classes #36

Open
opened 2026-05-26 19:51:33 +03:00 by saqut · 0 comments
Owner

Goal: Create the foundational metadata system so every token and AST node knows its exact origin (file, line, column, offset).

Files to create/modify:

  • src/core/location.hpp (new)
  • src/core/sourcefile.hpp (new)

Requirements:

  • SourceLocation struct with fields: filePath (string), line (int), column (int), offset (int).
  • SourceFile class that stores full source text and precomputed vector of line-start offsets. Provides offsetToLocation(int offset) using binary search (O(log n)).
  • SourceFile constructor takes file path and source text; computes line offsets in one pass (O(n)).

Success criteria:

  • Given source string and offset, offsetToLocation returns correct line and column.
  • Binary search is used, not linear scan.
**Goal:** Create the foundational metadata system so every token and AST node knows its exact origin (file, line, column, offset). **Files to create/modify:** - src/core/location.hpp (new) - src/core/sourcefile.hpp (new) **Requirements:** - SourceLocation struct with fields: filePath (string), line (int), column (int), offset (int). - SourceFile class that stores full source text and precomputed vector of line-start offsets. Provides offsetToLocation(int offset) using binary search (O(log n)). - SourceFile constructor takes file path and source text; computes line offsets in one pass (O(n)). **Success criteria:** - Given source string and offset, offsetToLocation returns correct line and column. - Binary search is used, not linear scan.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: saqut/saqut-compiler#36
No description provided.