lex

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package lex implements lexing for the CTM data format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorInfo

type ErrorInfo struct {
	Message    string
	Inner      error
	Start, End lex.Position
}

ErrorInfo desribes an lexical error along with the position in a source where the error occurred.

func (ErrorInfo) Error

func (e ErrorInfo) Error() string

type Lexeme

type Lexeme struct {
	Type       Type
	Value      string
	Start, End lex.Position
	// ErrMessage is set only when Type==Error.
	ErrMessage string
	// ErrInner is set only when Type==Error.
	ErrInner error
}

Lexeme describes a lexical CTM atom, including its position in a source text.

func (Lexeme) Match

func (l Lexeme) Match(t Type, v string) bool

func (Lexeme) String

func (l Lexeme) String() string

type Lexer

type Lexer struct {
	*lex.RuneScanner
	// contains filtered or unexported fields
}

Lexer supports lexing a CTM source into lexical atoms.

func NewLexer

func NewLexer(r io.Reader) *Lexer

NewLexer creates a lexer that can read lexical CTM atoms from r.

func (*Lexer) Lexeme

func (lx *Lexer) Lexeme() *Lexeme

Lexeme returns the next lexical CTM atom, and never returns nil.

At the end of available input, Lexeme returns a Lexeme with Type==EOF. If an error is encountered, a Lexeme is returned with Type==Error.

type Type

type Type int

Type identifies the type of lexemes read from a CTM source.

const (
	Error Type = iota
	Break
	Comment
	Delimiter
	EOF
	IRI
	Name
	Number
	Space
	String
)

func (Type) String

func (t Type) String() string

func (Type) Terminal

func (t Type) Terminal() bool

Terminal returns true if t indicates that reading should stop.

Jump to

Keyboard shortcuts

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