parser

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const HelpText = `` /* 899-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",
		"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 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 DeleteEdge

type DeleteEdge struct {
	Tail string
	Head string
}

func DeleteEdgeParam

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

type DeleteVertex

type DeleteVertex struct {
	Key string
}

func DeleteVertexParam

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

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")
}

func IlluminateParam

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

IlluminateParam parses the modernised illuminate grammar (#410):

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

The three keyword arguments may appear in any order and any subset. Each defaults 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). Unknown keyword names, malformed `key=value` tokens, or values outside the canonical set above are rejected with a descriptive error so the REPL can surface a usage hint.

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
}

func PutVertexParam

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

type ScanEdges added in v0.9.0

type ScanEdges struct {
	TailPrefix string
	Limit      int
}

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
}

ScanVertices / ScanEdges back the `scan vertices` / `scan edges` REPL verbs that mirror the admin web CLI shape (#411). Limit is optional; 0 means "use the server default".

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 (*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