parser

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const HelpText = `` /* 1267-byte string literal not displayed */

HelpText is the per-verb grammar reference printed by the `help` verb (#436). Single source of truth for the Go REPL; the TypeScript port keeps a byte-equivalent copy at `admin/app/lib/cli/verbs.ts` `HELP_TEXT`, and the shared fixture `admin/test/cli-grammar/verbs.json` exercises both parsers against the bare `help` verb.

The kwarg enums and defaults below MUST stay in lockstep with `IlluminateParam`'s `IlluminateAlgorithms` / `IlluminateObjectives` / `IlluminateWeightings` sets and the corresponding TS parser.

Variables

View Source
var (
	Verbs = []string{
		"get",
		"put",
		"add",
		"delete",
		"scan",
		"count",
		"delete-prefix",
		"keys",
		"illuminate",
		"help",
		"exit",
	}

	Objectives = []string{
		"vertex",
		"edge",
	}

	// ScanObjectives are the plural-form objectives accepted by the
	// `scan` verb. They intentionally do NOT overlap with `Objectives`
	// (singular vertex/edge), which the get/put/delete/add verbs use, so
	// `get vertices` and `scan vertex` are both clean parse errors.
	ScanObjectives = []string{
		"vertices",
		"edges",
	}

	// IlluminateAlgorithms / IlluminateObjectives / IlluminateWeightings
	// are the canonical sets the REPL accepts for the keyword arguments of
	// the modernised illuminate verb (#410). The keyword form replaces the
	// legacy positional grammar (neighbor / spt_* / mst_*) entirely.
	IlluminateAlgorithms = []string{"none", "mst", "spt"}
	IlluminateObjectives = []string{"min", "max"}
	IlluminateWeightings = []string{"raw", "tfidf"}

	ErrNotFound = errors.New("not found")
	ErrNotEOF   = errors.New("not EOF")
)
View Source
var (
	ErrOutOfIndex = errors.New("out of index")
	// ErrUnterminatedString is returned by NewSource when the input
	// contains an unmatched single- or double-quote opener. See #438.
	ErrUnterminatedString = errors.New("unterminated string literal")
)
View Source
var ErrParse = errors.New("parse error")

Functions

func AnyOf

func AnyOf(s *Source, choices []string) (string, error)

AnyOf returns the canonical lowercase choice that matches the next token case-insensitively, or ErrNotFound. The returned value is always one of the entries in `choices` (not the raw token), so downstream switches can compare against the canonical form. This mirrors the Go REPL's existing ToLower-on-dispatch convention and keeps argument tokens (vertex keys, edge endpoints, illuminate seeds) free of case mangling \u2014 see #437.

func Bool

func Bool(s *Source) (bool, error)

func CoerceValue added in v0.18.0

func CoerceValue(raw, typ string) (any, error)

CoerceValue converts a raw CLI value token into a Go value for PutVertex, honouring the optional `type=` override (migrated from the noun-first `vertex put --value-type`). "" / "auto" auto-detects (int→float→bool→RFC3339→string); otherwise the named type is forced and a mismatch is an error. `json` parses the token and re-encodes objects / arrays as a compact JSON string (the wire has no nested value variant); json scalars pass through as their natural Go type.

func Datetime

func Datetime(s *Source) (time.Time, error)

func Duration

func Duration(s *Source) (time.Duration, error)

func EOF

func EOF(s *Source) error

func Float

func Float(s *Source) (float64, error)

func Float32

func Float32(s *Source) (float32, error)

func Integer

func Integer(s *Source) (int, error)

func Objective

func Objective(s *Source) (string, error)

func ScanObjective added in v0.9.0

func ScanObjective(s *Source) (string, error)

func String

func String(s *Source) (string, error)

func Validate

func Validate(input string) error

func Value

func Value(s *Source) (any, error)

func Verb

func Verb(s *Source) (string, error)

Types

type AddEdge

type AddEdge struct {
	Tail   string
	Head   string
	Weight float32
	TTL    time.Duration
}

func AddEdgeParam

func AddEdgeParam(s *Source) (*AddEdge, error)

type CountVertices added in v0.18.0

type CountVertices struct {
	Prefix string
}

CountVertices backs `count vertices <prefix>` — the prefix-cardinality verb migrated from the former `vertex count` subcommand.

func CountVerticesParam added in v0.18.0

func CountVerticesParam(s *Source) (*CountVertices, error)

CountVerticesParam parses `count vertices <prefix>` — exactly one prefix (migrated from the `vertex count` subcommand). The objective token ("vertices") has already been consumed by the caller.

type DeleteEdge

type DeleteEdge struct {
	Pairs []EdgePair
}

DeleteEdge backs `delete edge <tail> <head> [<tail> <head> …]`. Pairs holds one or more (tail, head) pairs (the token count must be even).

func DeleteEdgeParam

func DeleteEdgeParam(s *Source) (*DeleteEdge, error)

DeleteEdgeParam parses `delete edge <tail> <head> [<tail> <head> …]` — one or more (tail, head) pairs (an even, non-zero token count). A single pair deletes one edge; more than one routes to DeleteEdges.

type DeletePrefixVertices added in v0.18.0

type DeletePrefixVertices struct {
	Prefix  string
	Limit   int
	DryRun  bool
	Confirm bool
}

DeletePrefixVertices backs `delete-prefix vertices <prefix> [limit=<n>] [confirm=yes|dry_run=true]` — the destructive prefix delete migrated from `vertex delete-prefix`. Exactly one of Confirm / DryRun must be set (the safety gate); a bare `delete-prefix vertices p` is a usage error.

func DeletePrefixVerticesParam added in v0.18.0

func DeletePrefixVerticesParam(s *Source) (*DeletePrefixVertices, error)

DeletePrefixVerticesParam parses `delete-prefix vertices <prefix> [limit=<int>] [confirm=yes|dry_run=true]`. Exactly one of confirm=yes or dry_run=true is REQUIRED — the destructive-op safety gate; a bare `delete-prefix vertices p` is a usage error. The objective token ("vertices") has already been consumed by the caller.

type DeleteVertex

type DeleteVertex struct {
	Keys []string
}

DeleteVertex backs `delete vertex <key> [<key> …]`. Keys holds one or more keys; the dispatcher forwards a one-element batch to DeleteVertex and a multi-element batch to DeleteVertices.

func DeleteVertexParam

func DeleteVertexParam(s *Source) (*DeleteVertex, error)

DeleteVertexParam parses `delete vertex <key> [<key> …]` — one or more keys. A one-element batch deletes a single vertex; more than one routes to DeleteVertices in the dispatcher.

type EdgePair added in v0.18.0

type EdgePair struct {
	Tail string
	Head string
}

EdgePair is one (tail, head) pair in a batch edge delete.

type GetEdge

type GetEdge struct {
	Tail string
	Head string
}

func GetEdgeParam

func GetEdgeParam(s *Source) (*GetEdge, error)

type GetVertex

type GetVertex struct {
	Key string
}

func GetVertexParam

func GetVertexParam(s *Source) (*GetVertex, error)

type Illuminate

type Illuminate struct {
	Seed      string
	Step      int
	K         int
	Algorithm string // "none" | "mst" | "spt" (default: "none")
	Objective string // "min" | "max"           (default: "max")
	Weighting string // "raw" | "tfidf"         (default: "raw")
	Prefix    string // vertex-key prefix filter; "" (default) = no filter (#604)
}

func IlluminateParam

func IlluminateParam(s *Source) (*Illuminate, error)

IlluminateParam parses the modernised illuminate grammar (#410, #604):

illuminate <seed> <step> <k> [algorithm=none|mst|spt] [objective=min|max] [weighting=raw|tfidf] [prefix=<string>]

The keyword arguments may appear in any order and any subset. The three closed-set axes default to the strongest-edge behaviour (algorithm=none, objective=max, weighting=raw); objective defaults to max so a bare illuminate keeps the top-k strongest neighbours and the per-hop pruning matches the reduction direction (#560). prefix is free-text and defaults to empty (no frontier filter; #604). Unknown keyword names, malformed `key=value` tokens, closed-set values outside the canonical set above, or an empty prefix= value are rejected with a descriptive error so the REPL can surface a usage hint.

type Keys added in v0.17.0

type Keys struct {
	Prefix string
	Limit  int
}

Keys backs the `keys <prefix> [limit]` verb — the Redis-familiar key lister that lists vertex keys under a prefix (keys-only output). Lantern is a prefix-indexed store, so Prefix is a key PREFIX, not a glob. Limit is optional (0 = server default), mirroring ScanVertices.

func KeysParam added in v0.17.0

func KeysParam(s *Source) (*Keys, error)

KeysParam parses `keys <prefix> [limit]` — the Redis-familiar key lister. Lantern is a prefix-indexed store, so the argument is a key PREFIX (not a glob): `keys user:` lists every vertex key under "user:". A prefix is required; the optional trailing limit caps the page (0 = server default), mirroring ScanVerticesParam.

type PutEdge

type PutEdge struct {
	Tail   string
	Head   string
	Weight float32
	TTL    time.Duration
}

func PutEdgeParam

func PutEdgeParam(s *Source) (*PutEdge, error)

type PutVertex

type PutVertex struct {
	Key   string
	Value any
	TTL   time.Duration
	Type  string
}

PutVertex backs `put vertex <key> <value> [ttl_seconds] [type=…]`. Type is the optional value-type override migrated from `vertex put --value-type`: "" / "auto" auto-detects (int→float→bool→RFC3339→string); otherwise one of string|int|float|bool|datetime|duration|json.

func PutVertexParam

func PutVertexParam(s *Source) (*PutVertex, error)

type ScanEdges added in v0.9.0

type ScanEdges struct {
	TailPrefix string
	HeadPrefix string
	Limit      int
	All        bool
}

ScanEdges backs `scan edges <tail-prefix> [limit] [head=<prefix>] [all=true]`. HeadPrefix narrows the head dimension as a server-side index lookup; All iterates every page.

func ScanEdgesParam added in v0.9.0

func ScanEdgesParam(s *Source) (*ScanEdges, error)

ScanEdgesParam parses `scan edges <tail-prefix> [limit]`. The objective token ("edges") has already been consumed by the caller. An empty tail-prefix is permitted (scans every tail), matching the server's ScanEdges semantics where both prefixes default to empty.

type ScanVertices added in v0.9.0

type ScanVertices struct {
	Prefix string
	Limit  int
	All    bool
}

ScanVertices backs `scan vertices <prefix> [limit] [all=true]` (#411, extended in #679). Limit is optional (0 = server default); All iterates every page and renders the full result.

func ScanVerticesParam added in v0.9.0

func ScanVerticesParam(s *Source) (*ScanVertices, error)

ScanVerticesParam parses `scan vertices <prefix> [limit]`. The objective token ("vertices") has already been consumed by the caller; this function only reads the prefix and optional limit. An empty prefix is rejected because an unbounded vertex scan from the REPL is almost never what the operator meant.

type Source

type Source struct {
	// contains filtered or unexported fields
}

func NewSource

func NewSource(str string) (*Source, error)

NewSource tokenises the input into a Source. The grammar (#438):

token         = bareword | double-quoted | single-quoted
bareword      = first char ∉ {whitespace,'"',"'"}, continues until next whitespace.
                Quotes inside a bareword are kept verbatim.
double-quoted = "..." with C-style escapes \", \\, \n, \r, \t.
single-quoted = '...' verbatim (no escapes).

Quoting is only special at the start of a token. Unterminated quotes (or unknown backslash sequences inside a double-quoted token) return ErrUnterminatedString or a parse error. On any error the returned Source is still valid (empty token stream) so callers that ignore the error do not deref a nil pointer.

func NewSourceFromTokens added in v0.16.0

func NewSourceFromTokens(tokens []string) *Source

NewSourceFromTokens builds a Source directly from already-split tokens, skipping the quote-aware tokeniser entirely. It exists so the one-shot CLI verbs (`lantern-cli get vertex <key>`, etc.) can feed cobra's shell-split argv straight into the same grammar the REPL parses from a raw line — the shell already performed the word/quote splitting, so a second pass through tokenise() would be both redundant and lossy (a value containing spaces would be re-split). The verb token is expected to be the first element, mirroring `Verb(s)` on a NewSource stream.

func (*Source) HasNext

func (s *Source) HasNext() bool

func (*Source) Len

func (s *Source) Len() int

func (*Source) Next

func (s *Source) Next()

func (*Source) Peek

func (s *Source) Peek() (string, error)

func (*Source) Pos

func (s *Source) Pos() int

func (*Source) Reset

func (s *Source) Reset()

func (*Source) SetPos

func (s *Source) SetPos(pos int)

func (*Source) Slice

func (s *Source) Slice() []string

Jump to

Keyboard shortcuts

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