fw-06 step 01 — Lexer, parser, and source locations
Goal
Build the front end — and record source ranges from the start, because you cannot recover them later.
Tasks
-
Lexer for a small template language: text, interpolation
{{ }}, elements, attributes, directives. You have written a state machine over markup before (bi-03); it will be faster this time. -
Parser producing an AST, with a source range on every node. Not most nodes — every node.
-
Transforms: interpolation, attribute binding, event binding, conditionals, loops.
-
Codegen producing a render function that returns
fw-05VNodes. -
Error reporting. Produce a caret-and-line message for an unclosed element:
error: unclosed element <div> --> Card.tmpl:12:3 | 12 | <div class="card"> | ^^^^ opened here, never closed -
Deliberately drop source locations and try to act on a compile error. Note the difference.
Done when
- Every AST node carries a range
- At least three error classes produce caret-and-line messages
- The no-locations experience recorded — it is the argument for step 2