BigSaltyMan/cuesmith/syntax does not have a README file

    Attribute

    pub(all) struct Attribute {
    name : String
    body : String
    span : Span
    } derive(Eq,
    Debug
    )

    A CUE attribute such as @protobuf(1,name=foo) or @if(debug).

    BinaryOp

    pub(all) enum BinaryOp {
    Or
    And
    Lor
    Land
    Eq
    Neq
    Lt
    Le
    Gt
    Ge
    Match
    NotMatch
    Add
    Sub
    Mul
    QuoSlash
    Div
    Mod
    Quo
    Rem
    } derive(Eq,
    Debug
    )

    Binary operators supported by CUE expressions.

    BytesInterpPart

    pub(all) enum BytesInterpPart {
    BytesChunk(Bytes)
    Expr(Expr)
    } derive(Eq,
    Debug
    )

    A segment of an interpolated bytes literal ('hello \(name)').

    Clause

    pub(all) enum Clause {
    For(String?, String, Expr, Span)
    If(Expr, Span)
    Let(String, Expr, Span)
    } derive(Eq,
    Debug
    )

    A comprehension clause (for, if, or let).

    Clause::span

    fn Clause::span(self : Clause) -> Span

    Returns the source span of a comprehension clause.

    Comment

    pub(all) struct Comment {
    text : String
    span : Span
    } derive(Eq,
    Debug
    )

    A lexed line comment (//...) without trailing CR/LF and its exact source span.

    Decl

    pub(all) enum Decl {
    Field(Array[FieldLabel], Expr, Array[Attribute], Span)
    Let(String, Expr, Span)
    Embed(Expr, Array[Attribute], Span)
    Ellipsis(Span)
    Comprehension(Array[Clause], Array[Decl], Span)
    Attribute(Attribute)
    } derive(Eq,
    Debug
    )

    A declaration inside a CUE file or struct body.

    Decl::span

    fn Decl::span(self : Decl) -> Span

    Returns the source span of a declaration node.

    Expr

    pub(all) enum Expr {
    Null(Span)
    Bool(Bool, Span)
    Int(String, Span)
    Float(String, Span)
    String(String, Span)
    Bytes(Bytes, Span)
    Bottom(Span)
    StringInterp(Array[StringInterpPart], Span)
    BytesInterp(Array[BytesInterpPart], Span)
    Ident(String, IdentKind, Span)
    Unary(UnaryOp, Expr, Span)
    Binary(BinaryOp, Expr, Expr, Span)
    Struct(Array[Decl], Span)
    List(Array[ListElem], Expr?, Bool, Span)
    Selector(Expr, SelectorLabel, Span)
    Index(Expr, Expr, Span)
    Slice(Expr, Expr?, Expr?, Span)
    Call(Expr, Array[Expr], Span)
    Paren(Expr, Span)
    Alias(String, Expr, Span)
    } derive(Eq,
    Debug
    )

    A CUE expression AST node.

    Expr::span

    fn Expr::span(self : Expr) -> Span

    Returns the source span of an expression node.

    FieldConstraint

    pub(all) enum FieldConstraint {
    Normal
    Optional
    Required
    } derive(Eq,
    Debug
    )

    Field presence constraint marker (? optional, ! required, or regular).

    FieldLabel

    pub(all) struct FieldLabel {
    alias_name : String?
    label : Label
    constraint : FieldConstraint
    span : Span
    } derive(Eq,
    Debug
    )

    A single label entry in a field declaration, including optional alias and ?/! constraint.

    File

    pub(all) struct File {
    pre_package_attrs : Array[Attribute]
    package_clause : PackageClause?
    imports : Array[ImportDecl]
    decls : Array[Decl]
    span : Span
    } derive(Eq,
    Debug
    )

    The root AST node of a parsed CUE source file.

    IdentKind

    pub(all) enum IdentKind {
    Regular
    Def
    Hidden
    HiddenDef
    } derive(Eq,
    Debug
    )

    Classification of a CUE identifier according to its prefix.

    Identifiers in the AST store their full source text as emitted by the lexer (for example "foo", "#Server", "_secret", "_#Private").

    ImportDecl

    pub(all) struct ImportDecl {
    grouped : Bool
    specs : Array[ImportSpec]
    span : Span
    } derive(Eq,
    Debug
    )

    An import declaration, either single (import "strings") or grouped (import ( ... )).

    ImportSpec

    pub(all) struct ImportSpec {
    alias_name : String?
    path : String
    span : Span
    } derive(Eq,
    Debug
    )

    A single import specification such as "strings" or str "strings".

    Label

    pub(all) enum Label {
    Ident(String, IdentKind, Span)
    StringLit(String, Span)
    DynamicExpr(Expr, Span)
    DynamicInterp(Array[StringInterpPart], Span)
    Pattern(String?, Expr, Span)
    } derive(Eq,
    Debug
    )

    A label identifying a field or pattern constraint in a struct declaration.

    Label::span

    fn Label::span(self : Label) -> Span

    Returns the source span of a label node.

    LexError

    pub(all) struct LexError {
    kind : LexErrorKind
    span : Span
    } derive(Eq,
    Debug
    )

    A lexical error with its exact source span.

    LexErrorKind

    pub(all) enum LexErrorKind {
    UnexpectedChar(Char)
    UnterminatedString
    UnterminatedBytes
    UnterminatedAttribute
    InvalidEscape(Char)
    InvalidEscapeSequence(String)
    InvalidMultilineString(String)
    InvalidNumber(String)
    } derive(Eq,
    Debug
    )

    Lexical diagnostic categories produced by tokenize.

    ListElem

    pub(all) enum ListElem {
    Expr(Expr)
    Comprehension(Array[Clause], Expr, Span)
    } derive(Eq,
    Debug
    )

    An element inside a CUE list literal: an expression or a list comprehension.

    PackageClause

    pub(all) struct PackageClause {
    name : String
    span : Span
    } derive(Eq,
    Debug
    )

    A package <name> clause at the top of a CUE file.

    ParseError

    pub(all) struct ParseError {
    kind : ParseErrorKind
    span : Span
    } derive(Eq,
    Debug
    )

    A parser diagnostic with its exact source span.

    ParseErrorKind

    pub(all) enum ParseErrorKind {
    UnexpectedToken(String, String)
    UnexpectedEof(String)
    MaxDepthExceeded(Int)
    InvalidLabel(String)
    InvalidSlice
    InvalidImport(String)
    InvalidPackage(String)
    InvalidExpr(String)
    } derive(Eq,
    Debug
    )

    Syntactic diagnostic categories produced by the parser.

    Position

    pub(all) struct Position {
    offset : Int
    line : Int
    column : Int
    } derive(Eq,
    Debug
    )

    A 0-based UTF-8 byte offset paired with 1-based line and column coordinates.

    SelectorLabel

    pub(all) enum SelectorLabel {
    Ident(String, IdentKind)
    StringLit(String)
    } derive(Eq,
    Debug
    )

    A selector label used in member access expressions (a.b or a."b-c").

    Span

    pub(all) struct Span {
    start : Position
    end : Position
    } derive(Eq,
    Debug
    )

    Half-open source span [start, end).

    StringInterpPart

    pub(all) enum StringInterpPart {
    Text(String)
    Expr(Expr)
    } derive(Eq,
    Debug
    )

    A segment of an interpolated string literal ("hello \(name)").

    SyntaxError

    pub(all) enum SyntaxError {
    Lex(LexError)
    Parse(ParseError)
    } derive(Eq,
    Debug
    )

    Unified lexical and syntactic diagnostic type for the syntax package.

    SyntaxError::message

    fn SyntaxError::message(self : SyntaxError) -> String

    Formats a SyntaxError as a human-readable diagnostic prefixed with line:column.

    SyntaxError::span

    fn SyntaxError::span(self : SyntaxError) -> Span

    Returns the source span associated with a SyntaxError.

    Token

    pub(all) struct Token {
    kind : TokenKind
    lexeme : String
    span : Span
    } derive(Eq,
    Debug
    )

    A lexed token carrying its kind, raw source lexeme, and source span.

    TokenKind

    pub(all) enum TokenKind {
    Ident(String)
    DefIdent(String)
    HiddenIdent(String)
    HiddenDefIdent(String)
    Bottom
    Null
    True
    False
    Package
    Import
    Let
    For
    In
    If
    IntLit(String)
    FloatLit(String)
    StringLit(String)
    BytesLit(Bytes)
    StringInterpStart(String)
    StringInterpMid(String)
    StringInterpEnd(String)
    BytesInterpStart(Bytes)
    BytesInterpMid(Bytes)
    BytesInterpEnd(Bytes)
    Attribute(String, String)
    LBrace
    RBrace
    LBracket
    RBracket
    LParen
    RParen
    Colon
    Comma
    Dot
    Ellipsis
    And
    Or
    Land
    Lor
    Star
    Question
    Bang
    Assign
    Eq
    Neq
    Lt
    Le
    Gt
    Ge
    Match
    NotMatch
    Plus
    Minus
    Slash
    Eof
    } derive(Eq,
    Debug
    )

    Token kinds supported by the CUE lexer.

    UnaryOp

    pub(all) enum UnaryOp {
    Plus
    Minus
    Not
    Default
    Lt
    Le
    Gt
    Ge
    Neq
    Match
    NotMatch
    } derive(Eq,
    Debug
    )

    Unary operators supported by CUE expressions, including bound and regex constraints.

    format

    fn format(source : String) -> Result[String, SyntaxError]

    Parses and formats a CUE source string into canonical cue fmt-style text, preserving line comments.

    format_expr

    fn format_expr(expr : Expr) -> String

    Formats a CUE expression AST node into canonical cue fmt-style source text.

    format_file

    fn format_file(file : File) -> String

    Formats a CUE file AST node into canonical cue fmt-style source text.

    Non-empty files always terminate with a single trailing newline (\n).

    format_file_with_comments

    fn format_file_with_comments(file : File, comments : Array[Comment]) -> String

    Formats a CUE file AST node together with its lexed line comments into canonical cue fmt-style source text.

    Non-empty files always terminate with a single trailing newline (\n). When comments is empty, output is byte-for-byte identical to format_file.

    format_file_with_comments_bounded

    fn format_file_with_comments_bounded(file : File, comments : Array[Comment], max_output_bytes : Int) -> Result[String, String]

    Formats a CUE file AST node together with its lexed line comments into canonical cue fmt-style source text while streaming UTF-8 byte count against max_output_bytes. Aborts immediately with Err(message) before writing any output that would exceed max_output_bytes.

    parse_expr

    fn parse_expr(source : String) -> Result[Expr, SyntaxError]

    Parses a standalone CUE expression, ensuring the entire input is consumed.

    parse_file

    fn parse_file(source : String) -> Result[File, SyntaxError]

    Parses a complete CUE source file into a File AST node.

    tokenize

    fn tokenize(source : String) -> Result[Array[Token], LexError]

    Tokenizes a CUE source string into a sequence of tokens ending with Eof.

    tokenize_with_comments

    fn tokenize_with_comments(source : String) -> Result[(Array[Token], Array[Comment]), LexError]

    Tokenizes a CUE source string into tokens (ending with Eof) and all line comments in source order.