Skip to content

[Compiler] Decide tokenizer + recursive-descent parser direction (ADR) #299

@cssbruno

Description

@cssbruno

Problem

The parser is line-oriented: it scans the source line by line with a
bufio.Scanner, matches patterns per trimmed line, and returns on the first
syntax error with no recovery. Spans are line-wide approximations and the
formatter is whitespace-only string manipulation. Most of the work deferred to
#250 — parser error recovery, an AST-backed formatter, exact token spans, and
granular per-construct diagnostic codes — is downstream of this single
foundation. Right now the line-oriented parser is effectively deferred by
omission rather than by an explicit decision.

Relevant code:

  • internal/parser/syntax.go: bufio.Scanner line loop, first-error return
  • internal/parser/patterns.go: per-line lexLine tokenizer
  • internal/parser/braces.go: stateful brace scanner (accepted JS-regex limit)
  • internal/lang/format.go: line-oriented formatter

Scope

This is a decision/ADR issue, not an implementation task. Decide whether M2
commits to a real tokenizer + recursive-descent parser with error recovery, or
explicitly keeps the line-oriented parser with documented limits for now.

If committing: outline the token-stream layer, the recovery strategy
(continue-after-error so one syntax error does not hide the rest of the file),
and the span model — which depends on byte offsets in SourcePosition.

If deferring: document the limitation explicitly and link the dependent issues so
it is a conscious choice rather than an omission.

Acceptance Criteria

  • An ADR (docs/engineering/decisions/) records the chosen direction and
    rationale.
  • If deferred, the line-oriented limitation is documented (not deferred by
    omission) and the dependent deferral ([Language] Track remaining parser/spec hardening follow-ups #250) references the decision.
  • If committed, a phased plan exists covering tokenizer, recovery, span model,
    and formatter, with byte-offset spans as a dependency.

Verification

  • ADR present under docs/engineering/decisions/.
  • docs/compiler/pipeline.md and docs/engineering/architecture.md updated to
    match the decision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerCompiler internals, pipeline, and generated metadataparser.gwdk parser and syntax handling

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions