strparse

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package strparse provides facilities for parsing strings, intended for use in tests and debug input.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

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

Parser is a helper used to implement parsing of strings, like manifest.ParseFileMetadataDebug.

It takes a string and splits it into tokens. Tokens are separated by whitespace; in addition user-specified separators are also always separate tokens. For example, when passed the separators `:-[]();` the string `000001:[a - b]` results in tokens `000001`, `:`, `[`, `a`, `-`, `b`, `]`, .

All Parser methods throw panics instead of returning errors. The code that uses a Parser can recover them and convert them to errors.

func MakeParser

func MakeParser(separators string, input string) Parser

MakeParser constructs a new Parser that converts any instance of the runes contained in [separators] into separate tokens, and consumes the provided input string.

func (*Parser) BlobFileID

func (p *Parser) BlobFileID() base.BlobFileID

BlobFileID parses the next token as a BlobFileID.

func (*Parser) DiskFileNum

func (p *Parser) DiskFileNum() base.DiskFileNum

DiskFileNum parses the next token as a DiskFileNum.

func (*Parser) Done

func (p *Parser) Done() bool

Done returns true if there are no more tokens.

func (*Parser) Errf

func (p *Parser) Errf(format string, args ...any)

Errf panics with an error which includes the original string and the last token.

func (*Parser) Expect

func (p *Parser) Expect(tokens ...string)

Expect consumes the next tokens, verifying that they exactly match the arguments.

func (*Parser) FileNum

func (p *Parser) FileNum() base.FileNum

FileNum parses the next token as a FileNum.

func (*Parser) Int

func (p *Parser) Int() int

Int parses the next token as an integer.

func (*Parser) InternalKey

func (p *Parser) InternalKey() base.InternalKey

InternalKey parses the next token as an internal key.

func (*Parser) Level

func (p *Parser) Level() int

Level parses the next token as a level.

func (*Parser) Next

func (p *Parser) Next() string

Next returns the next token, or "" if there are no more tokens.

func (*Parser) Peek

func (p *Parser) Peek() string

Peek returns the next token, without consuming the token. Returns "" if there are no more tokens.

func (*Parser) Remaining

func (p *Parser) Remaining() string

Remaining returns all the remaining tokens, separated by spaces.

func (*Parser) SeqNum

func (p *Parser) SeqNum() base.SeqNum

Uint64 parses the next token as a sequence number.

func (*Parser) TryLevel

func (p *Parser) TryLevel() (level int, ok bool)

TryLevel tries to parse a token as a level (e.g. L1, L0.2). If successful, the token is consumed.

func (*Parser) Uint32

func (p *Parser) Uint32() uint32

Uint32 parses the next token as an uint32.

func (*Parser) Uint64

func (p *Parser) Uint64() uint64

Uint64 parses the next token as an uint64.

Jump to

Keyboard shortcuts

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