token

package
v0.0.0-...-2fb2b97 Latest Latest
Warning

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

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

Documentation

Overview

Package token defines constants representing the lexical tokens of the DOT language together with operations like printing, detecting Keywords or identifiers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind uint32

Kind represents the types of lexical tokens of the DOT language. Token kinds are powers of 2 and can be combined using bitwise OR to create token sets for efficient membership testing.

const (
	ERROR Kind = 1 << iota
	// EOF is not part of the DOT language and is used to indicate the end of the file or stream. No
	// language token should follow the EOF token.
	EOF

	ID      // like _A 12 "234"
	Comment // like C pre-processor ones '# 34'

	LeftBrace      // {
	RightBrace     // }
	LeftBracket    // [
	RightBracket   // ]
	Colon          // :
	Semicolon      // ;
	Equal          // =
	Comma          // ,
	DirectedEdge   // ->
	UndirectedEdge // --

	// Keywords
	Digraph  // digraph
	Edge     // edge
	Graph    // graph
	Node     // node
	Strict   // strict
	Subgraph // subgraph
)

func Lookup

func Lookup(identifier string) Kind

Lookup returns the token type associated with given identifier which is either a DOT keyword or a DOT ID. DOT keywords are case-insensitive. This function expects that the input is a valid DOT ID as specified in IDs.

func (Kind) IsTerminal

func (k Kind) IsTerminal() bool

IsTerminal reports whether the token type is a terminal symbol (punctuation or operator). Terminal symbols include braces, brackets, colon, semicolon, equal, and comma.

func (Kind) String

func (k Kind) String() string

String returns the string representation of the token type.

type Position

type Position struct {
	Line   uint32 // line number, starting at 1
	Column uint32 // column number, starting at 1 (byte offset)
}

Position describes a position in DOT source code. A Position is valid if the line number is > 0.

func (Position) After

func (p Position) After(o Position) bool

After reports whether the position p is after o.

func (Position) Before

func (p Position) Before(o Position) bool

Before reports whether the position p is before o.

func (Position) IsValid

func (p Position) IsValid() bool

IsValid reports whether the position is valid.

func (Position) String

func (p Position) String() string

String returns the position in line:column format.

type Token

type Token struct {
	Kind       Kind
	Literal    string
	Error      string // Error message for ERROR tokens, empty otherwise
	Start, End Position
}

Token represents a token of the DOT language.

func (Token) IsCompassPoint

func (t Token) IsCompassPoint() bool

func (Token) IsKeyword

func (t Token) IsKeyword() bool

func (Token) String

func (t Token) String() string

String returns the string representation of the token. For IDs, it returns the literal value. For other token types, it returns the token type's string representation.

Jump to

Keyboard shortcuts

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