Run artifact

workspace/targets/jq/blueprint/FEATURE-Lexer.md

FEATURE: jq Lexer

FieldValue
Version20261028 V1
DescriptionConverts jq source text into located tokens and rejects lexical errors.
Depends OnARCHITECTURE.md, FEATURE-CorpusStaging.md
Providesjq token stream
ConsumesPython application foundation, staged conformance assets

Behavior

jq_interpreter.lexer.tokenize(source) returns tokens in source order, with kind, value, line, and column attributes. Use one-based source locations. Follow sources/lexer.l for operators, keywords, identifiers, bindings, numbers, punctuation, formats, and delimiter nesting. Recognize quoted strings, JSON escapes, and embedded jq expressions introduced by interpolation; retain enough structure for the parser to distinguish literal text from interpolated expressions. Ignore whitespace and comments, including the specified backslash continuation of comments. Invalid characters, invalid string escapes, unterminated strings, and mismatched delimiters raise jq_interpreter.errors.CompileError.

The parser consumes this interface. Corpus cases that combine lexical behavior with evaluation are executed by later scoped integration after their required capabilities exist.

Programmatic Acceptance

=== AC lexer-locations ===
Intent: The lexer ignores comments and retains the source locations of successive literal tokens.

from jq_interpreter.lexer import tokenize

tokens = list(tokenize("1 # comment\n2")) numbers = [token for token in tokens if token.value in (1, 2) and not isinstance(token.value, bool)] assert [token.value for token in numbers] == [1, 2] assert [(token.line, token.column) for token in numbers] == [(1, 1), (2, 1)] === END AC lexer-locations ===

=== AC lexer-invalid ===
Intent: Invalid string escapes and unmatched delimiters are compile failures.

from jq_interpreter.errors import CompileError from jq_interpreter.lexer import tokenize

for source in (r'"\v"', "(", "]"): try: list(tokenize(source)) except CompileError: pass else: raise AssertionError(f"accepted invalid source: {source!r}") === END AC lexer-invalid ===

User Acceptance

Guardrails