parser

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package parser is the recursive-descent GQL parser (SPEC-04 §3 EBNF).

M6 (landed): the grammar-complete parser. Precedence `!` > `&&` > `||` (parseOr → parseAnd → parseNot → parsePrimary); sugar (`=` → `==`, AND/OR/NOT in any casing → the symbolic nodes); `field!="value"` as its own OpNeq comparison; IN lists capped at 256 elements; the quantified blocks ANY(f){ … } (accepted) and ALL(f){ … } (parses — the M7 validator rejects it in v0.0.1); the functional exists(field) form AND the bare-field presence test; positions from the source tokens on every node. Parse-time K-13 enforcement: node count ≤ 1024, depth ≤ 32 (constants at the top of parser.go — the normative spec values are not vendored in-repo; these bounds are the tuning point). Grammar failures abort with GQL_E_PARSE at the offending token plus a did-you-mean keyword hint when the text is within edit distance 1 of a keyword (errors.go); the error points at the misspelled FIELD when the field is the misspelling.

Consumes internal/gql/lexer, produces internal/gql/ast; never imports any collector or egress package (ADR-0010; AC-3.1).

Index

Constants

View Source
const CodeParse = "GQL_E_PARSE"

CodeParse is the stable GQL grammar-error code (SPEC-04 §3).

Variables

This section is empty.

Functions

func Parse

func Parse(src string) (ast.Node, error)

Parse tokenizes src and parses it to an ast.Node tree. Lexical errors surface as *lexer.Error (GQL_E_LEX); grammatical errors as *Error (GQL_E_PARSE) — both carry the 1-based position.

Types

type Error

type Error struct {
	Detail string // what failed, including "line L, column C"
	Why    string // likely why
	Next   string // concrete Try: hint (may carry did-you-mean)
	Line   int    // 1-based line the error points at
	Col    int    // 1-based (rune) column the error points at
}

Error is a GQL parse error with its source position.

func (*Error) Code

func (e *Error) Code() string

Code is the stable error code (uniform access across the GQL chain).

func (*Error) Error

func (e *Error) Error() string

Error renders per the SPEC-03 §7 style guide.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL