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

  1. 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.

  2. Parser producing an AST, with a source range on every node. Not most nodes — every node.

  3. Transforms: interpolation, attribute binding, event binding, conditionals, loops.

  4. Codegen producing a render function that returns fw-05 VNodes.

  5. 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
    
  6. 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