parser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package parser implements the ClassAd lexer and parser.

Package parser provides the ClassAd parser implementation. The parser is generated from classad.y using goyacc.

Index

Constants

View Source
const AND = 57356
View Source
const BOOLEAN_LITERAL = 57350
View Source
const ELVIS = 57354
View Source
const EQ = 57357
View Source
const ERROR = 57352
View Source
const GE = 57362
View Source
const IDENTIFIER = 57346
View Source
const INT64_MIN_MAGNITUDE = 57353
View Source
const INTEGER_LITERAL = 57348
View Source
const IS = 57359
View Source
const ISNT = 57360
View Source
const LE = 57361
View Source
const LSHIFT = 57363
View Source
const NE = 57358
View Source
const OR = 57355
View Source
const REAL_LITERAL = 57349
View Source
const RSHIFT = 57364
View Source
const STRING_LITERAL = 57347
View Source
const UNARY = 57366
View Source
const UNDEFINED = 57351
View Source
const URSHIFT = 57365

Variables

This section is empty.

Functions

func Parse

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

Parse parses a ClassAd string (a bracketed record, "[ a = 1; ... ]") and returns its AST. It does not accept a bare expression; to parse a standalone expression such as "a + 1" or "{1, 2}", use ParseExpr.

func ParseClassAd

func ParseClassAd(input string) (*ast.ClassAd, error)

ParseClassAd parses a ClassAd and returns a ClassAd AST node. It returns an error if the input is not a ClassAd (for example a bare expression).

func ParseExpr added in v0.1.0

func ParseExpr(input string) (ast.Expr, error)

ParseExpr parses a standalone ClassAd expression (for example "a + 1", `strcat("x", "y")`, or "{1, 2, 3}") and returns its expression AST. It returns an error if the input is not a single well-formed expression.

The grammar's top-level production is a ClassAd, so the expression is parsed inside a throwaway single-attribute wrapper and the attribute's value is returned. This keeps Parse ClassAd-only -- avoiding grammar ambiguity between a record literal and a bare expression -- while still giving callers direct expression access.

func ParseOldClassAd

func ParseOldClassAd(input string) (*ast.ClassAd, error)

ParseOldClassAd parses a ClassAd in the "old" HTCondor format. Old ClassAds have attributes separated by newlines without surrounding brackets. Example:

Foo = 3
Bar = "hello"
Moo = Foo =!= Undefined

This implementation converts the old format to new format and reuses the existing parser.

func ParseScopedIdentifier

func ParseScopedIdentifier(identifier string) (string, ast.AttributeScope)

ParseScopedIdentifier parses an identifier that may have a scope prefix. Returns the attribute name and scope.

Types

type Lexer

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

Lexer wraps the streaming lexer for string inputs while retaining the input and position fields used in existing tests.

func NewLexer

func NewLexer(input string) *Lexer

NewLexer creates a new lexer for the given input.

func (*Lexer) Error

func (l *Lexer) Error(s string)

Error implements the goyacc Lexer interface.

func (*Lexer) Lex

func (l *Lexer) Lex(lval *yySymType) int

Lex implements the goyacc Lexer interface.

func (*Lexer) Result

func (l *Lexer) Result() (ast.Node, error)

Result returns the parsed result and any error. It must surface an error recorded on the underlying streaming lexer even when the parser produced a (partial) result -- e.g. trailing input that triggers a lexer error after a complete ClassAd, which the reference parser rejects.

func (*Lexer) SetResult

func (l *Lexer) SetResult(node ast.Node)

SetResult sets the parse result.

type ReaderParser

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

ReaderParser parses consecutive ClassAds from a buffered reader without requiring delimiters between ads. It reuses a single streaming lexer instance for efficiency.

func NewReaderParser

func NewReaderParser(r io.Reader) *ReaderParser

NewReaderParser creates a reusable parser that pulls consecutive ClassAds from the provided reader without requiring delimiters. Non-buffered readers are wrapped internally for efficiency.

func (*ReaderParser) ParseClassAd

func (p *ReaderParser) ParseClassAd() (*ast.ClassAd, error)

ParseClassAd parses the next ClassAd from the underlying reader. It reuses the same streaming lexer instance to avoid per-call allocations. It returns io.EOF when there is no more data to parse.

type StreamingLexer

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

StreamingLexer tokenizes ClassAds directly from an io.Reader. It stops producing tokens after the first complete ClassAd so the caller can parse multiple ads from a single stream.

func NewStreamingLexer

func NewStreamingLexer(r io.Reader) *StreamingLexer

NewStreamingLexer creates a lexer that consumes tokens directly from a reader. It wraps non-buffered readers in a bufio.Reader for efficiency.

func (*StreamingLexer) Error

func (l *StreamingLexer) Error(s string)

Error implements the goyacc Lexer interface.

func (*StreamingLexer) Lex

func (l *StreamingLexer) Lex(lval *yySymType) int

Lex implements the goyacc Lexer interface.

func (*StreamingLexer) Result

func (l *StreamingLexer) Result() (ast.Node, error)

Result returns the parsed result and any error.

func (*StreamingLexer) SetResult

func (l *StreamingLexer) SetResult(node ast.Node)

SetResult sets the parse result.

type Token

type Token struct {
	Type int
	Text string
	Pos  int
}

Token represents a lexical token.

Jump to

Keyboard shortcuts

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