pdl

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseIntLiteral

func ParseIntLiteral(s string) (int64, error)

ParseIntLiteral parses a decimal or hexadecimal integer literal string.

func ParseTransportPSL

func ParseTransportPSL(source string) (*schema.TransportDef, error)

ParseTransportPSL parses a transport PSL source into a TransportDef. The expected format is:

message <Name> version "<ver>" {
  <messageType> {
    field <name>: <type> [optional] [default <value>|auto];
    [response { ... }]
  }
}

func ResolveVersion

func ResolveVersion(basePath string, requested *string) (string, error)

ResolveVersion finds the best matching version directory under basePath. If requested is non-nil, it looks for an exact match. If requested is nil, it returns the latest version by semver ordering. If no version subdirectories exist, it returns basePath as-is (flat fallback).

Types

type DynamicKeywordRegistry

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

DynamicKeywordRegistry holds transport-derived keywords for a parsing session. It indexes MessageTypeDef names from a TransportDef for O(1) lookup.

func NewDynamicKeywordRegistry

func NewDynamicKeywordRegistry(td *schema.TransportDef) *DynamicKeywordRegistry

NewDynamicKeywordRegistry creates a registry from a TransportDef, indexing all MessageTypeDef names in a map for O(1) lookup.

func (*DynamicKeywordRegistry) GetFieldDef

func (r *DynamicKeywordRegistry) GetFieldDef(messageType, fieldName string) (*schema.TransportFieldDef, bool)

GetFieldDef returns the TransportFieldDef for a field within a message type.

func (*DynamicKeywordRegistry) GetMessageType

func (r *DynamicKeywordRegistry) GetMessageType(name string) (*schema.MessageTypeDef, bool)

GetMessageType returns the MessageTypeDef for a message type name.

func (*DynamicKeywordRegistry) IsMessageType

func (r *DynamicKeywordRegistry) IsMessageType(name string) bool

IsMessageType checks if a token is a transport-defined message type.

func (*DynamicKeywordRegistry) MessageTypeNames

func (r *DynamicKeywordRegistry) MessageTypeNames() []string

MessageTypeNames returns all registered message type names.

type Lexer

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

Lexer performs lexical analysis on PDL source text, producing tokens one at a time.

func NewLexer

func NewLexer(source string) *Lexer

NewLexer creates a new Lexer for the given PDL source text.

func (*Lexer) NextToken

func (l *Lexer) NextToken() (Token, error)

NextToken returns the next token from the source. Returns TokenEOF at end of input, or a PDLSyntaxError for illegal characters.

type PDLParser

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

PDLParser parses PDL source text into a ProtocolSchema using recursive descent.

func NewPDLParser

func NewPDLParser(checksumReg *checksum.ChecksumRegistry, formatReg *format.FormatRegistry) *PDLParser

NewPDLParser creates a new PDLParser with optional registries for semantic validation.

func (*PDLParser) Parse

func (p *PDLParser) Parse(source string) (*schema.ProtocolSchema, error)

Parse parses PDL source text and returns a ProtocolSchema.

func (*PDLParser) ParseMessage

func (p *PDLParser) ParseMessage(source string) (*schema.MessageSchema, error)

ParseMessage parses a message PSL source and returns a MessageSchema.

func (*PDLParser) SetTransportLoader

func (p *PDLParser) SetTransportLoader(loader *TransportLoader)

SetTransportLoader sets the transport loader for dynamic keyword support.

type PDLPrinter

type PDLPrinter struct{}

PDLPrinter formats a ProtocolSchema back into valid PDL text.

func (*PDLPrinter) Print

func (p *PDLPrinter) Print(s *schema.ProtocolSchema) string

Print formats a ProtocolSchema as PDL text that can be re-parsed by PDLParser.

func (*PDLPrinter) PrintMessage

func (p *PDLPrinter) PrintMessage(ms *schema.MessageSchema) string

PrintMessage formats a MessageSchema back into valid PSL text.

func (*PDLPrinter) PrintTransport

func (p *PDLPrinter) PrintTransport(td *schema.TransportDef) string

PrintTransport formats a TransportDef back into valid transport PSL text.

type Token

type Token struct {
	Type   TokenType // The token type.
	Value  string    // The literal text of the token.
	Line   int       // 1-based line number where the token starts.
	Column int       // 1-based column number where the token starts.
}

Token represents a single lexical token produced by the PDL lexer.

type TokenType

type TokenType int

TokenType represents the type of a lexical token in PDL.

const (
	// Special tokens
	TokenEOF TokenType = iota

	// Literals
	TokenIdent  // identifier
	TokenString // string literal (e.g. "1.0")
	TokenInt    // integer literal (e.g. 42)

	// Keywords
	TokenProtocol  // protocol
	TokenVersion   // version
	TokenByteOrder // byte_order
	TokenField     // field
	TokenBitfield  // bitfield
	TokenChecksum  // checksum
	TokenCovers    // covers
	TokenWhen      // when
	TokenDisplay   // display
	TokenEnum      // enum
	TokenLengthRef // length_ref
	TokenScale     // scale
	TokenOffset    // offset
	TokenConst     // const
	TokenRange     // range
	TokenDefault   // = (default value, context-dependent)
	TokenMessage   // message
	TokenRequest   // request
	TokenResponse  // response
	TokenNotify    // notification
	TokenTransport // transport
	TokenOptional  // optional
	TokenObject    // object
	TokenArray     // array
	TokenImport    // import
	TokenEmbed     // embed
	TokenExtends   // extends
	TokenTypeAlias // type (alias)

	// Byte order values (treated as keywords)
	TokenBigEndian    // big-endian
	TokenLittleEndian // little-endian

	// Punctuation
	TokenLBrace       // {
	TokenRBrace       // }
	TokenLBracket     // [
	TokenRBracket     // ]
	TokenColon        // :
	TokenSemicolon    // ;
	TokenComma        // ,
	TokenEquals       // =
	TokenDotDot       // ..
	TokenGreater      // >
	TokenLess         // <
	TokenGreaterEqual // >=
	TokenLessEqual    // <=
	TokenNotEqual     // !=
	TokenEqualEqual   // ==
	TokenMinus        // -
)

func LookupKeyword

func LookupKeyword(ident string) TokenType

LookupKeyword returns the keyword TokenType for the given identifier, or TokenIdent if it is not a keyword.

func (TokenType) String

func (t TokenType) String() string

String returns a human-readable name for the token type.

type TransportLoader

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

TransportLoader loads and caches transport PSL definitions.

func NewTransportLoader

func NewTransportLoader(embedFS fs.FS, searchPaths []string) *TransportLoader

NewTransportLoader creates a new TransportLoader with the given embedded FS and search paths.

func (*TransportLoader) LoadTransport

func (tl *TransportLoader) LoadTransport(name string, version *string) (*schema.TransportDef, error)

LoadTransport loads a transport by name and optional version. Returns cached result if already loaded.

func (*TransportLoader) ResolveTransportPath

func (tl *TransportLoader) ResolveTransportPath(name string, version *string) (string, error)

ResolveTransportPath finds the PSL file path for a transport reference. Returns an error if the path contains directory traversal patterns.

type TransportRef

type TransportRef struct {
	Name    string
	Version *string // nil means "latest"
}

TransportRef represents a parsed transport reference.

func ParseTransportRef

func ParseTransportRef(ref string) TransportRef

ParseTransportRef parses "jsonrpc" or "jsonrpc@2.0" into a TransportRef.

Jump to

Keyboard shortcuts

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