# FEATURE: jq Parser

| Field | Value |
|-------|-------|
| Version | 20261028 V1 |
| Description | Parses and statically validates jq programs into abstract syntax trees. |
| Depends On | FEATURE-Lexer.md |
| Provides | jq abstract syntax tree |
| Consumes | jq token stream |

## Behavior

`jq_interpreter.parser.parse(source)` uses the token stream to return an abstract syntax tree.
Implement the grammar, precedence, and associativity in `sources/parser.y`, including expression
composition, constructors, path expressions, assignments, control forms, bindings, functions,
patterns, interpolation, and module directives.

Perform static validation of lexical bindings, function references and arities, label visibility,
constant object keys, and module metadata and import paths. Reject invalid syntax and static
errors by raising `jq_interpreter.errors.CompileError`; never evaluate the program during parsing.
Module grammar rejection does not require loading files. Valid constructs are represented in the
AST even when a later story owns their evaluation.

The early gate calls the parser directly. Corpus programs requiring the executable or evaluator
are retained for executing scoped integration after those capabilities are available.

## Programmatic Acceptance

=== AC parser-valid ===
Intent: The parser accepts a composed expression and returns a syntax tree without evaluating it.

from jq_interpreter.parser import parse

tree = parse("(1, 2) | .")
assert tree is not None
=== END AC parser-valid ===

=== AC parser-invalid ===
Intent: Syntax and static scope errors are reported as compilation failures.

from jq_interpreter.errors import CompileError
from jq_interpreter.parser import parse

for source in ("{", ". as $x | $missing", "break $missing"):
    try:
        parse(source)
    except CompileError:
        pass
    else:
        raise AssertionError(f"accepted invalid program: {source!r}")
=== END AC parser-invalid ===

## User Acceptance

- None.

## Guardrails

- Use the staged grammar and lexer as the syntax authority and the manual for language behavior.
- Reject invalid module grammar without accessing the filesystem.
- Preserve the distinction between compile failures and runtime failures.
