# FEATURE: Generator Evaluation Core

| Field | Value |
|-------|-------|
| Version | 20261028 V1 |
| Description | Evaluates basic jq filters as ordered, lazy streams of values. |
| Depends On | FEATURE-Parser.md |
| Provides | jq generator evaluation |
| Consumes | jq abstract syntax tree |

## Behavior

`jq_interpreter.evaluator.evaluate(ast, value, environment=None)` yields an ordered stream.
Identity yields its input, literals yield their values, and `empty` yields no values. A comma
evaluates both branches against the same input and concatenates their streams in order. A pipe
evaluates its right side once for each value yielded by its left side. Nested generators preserve
multiplicity and backtracking; evaluation must remain lazy so a consumer can stop without
evaluating later results. Outputs already yielded remain observable if evaluation later raises
a runtime error. Combining operands use the same original input.

Provide the minimal root executable needed to run this story's scoped conformance cases:
`./jq -c '<program>'` reads JSON from standard input and writes one compact JSON value per
output line. Distinguish compilation failure from runtime failure with exit statuses 3 and 5;
successful completion exits 0. Later stories complete the command and language surface.

## Programmatic Acceptance

=== AC core-stream ===
Intent: Identity, comma, and pipe preserve input, ordering, and multiplicity through the evaluator.

from jq_interpreter.evaluator import evaluate
from jq_interpreter.parser import parse

value = {"item": [1, 2]}
assert list(evaluate(parse("."), value)) == [value]
assert list(evaluate(parse("., . | ."), value)) == [value, value]
assert list(evaluate(parse("empty"), value)) == []
=== END AC core-stream ===

=== AC core-lazy ===
Intent: A consumer can take the first generated result without evaluating a later runtime error.

from jq_interpreter.evaluator import evaluate
from jq_interpreter.parser import parse

value = 7
stream = iter(evaluate(parse("., error"), value))
assert next(stream) == value
=== END AC core-lazy ===

=== AC core-corpus ===
Intent: The basic literal and identity corpus cases execute successfully through the command interface.
Suite: scoped
Requires: executable=python3; scope=test
Probe: --list
Probe Count: summary

import json
import os
import subprocess
import sys

SELECT = r"^(true|false|null|1|-1|\.|1,1|1,\.)$"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", SELECT, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": os.path.abspath("jq")},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
tally = report["summary"]
print(f"{tally['pass']} passed, {tally['fail']} failed, {tally['error']} errored")
assert sum(tally.values()) > 0, f"selector matched no case: {SELECT}"
assert tally["fail"] == 0 and tally["error"] == 0, tally
assert result.returncode == 0, result.returncode
=== END AC core-corpus ===

## User Acceptance

- None.

## Guardrails

- Preserve stream order, multiplicity, laziness, and partial output on runtime failure.
- Use only the Python standard library; do not invoke another jq implementation.
- Do not modify the staged conformance assets.
