token

package
v1.8.17 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: GPL-3.0 Imports: 3 Imported by: 3

Documentation

Index

Constants

View Source
const (
	Syntax        = "syntax"
	Info          = "info"
	Service       = "service"
	Returns       = "returns"
	Any           = "any"
	TypeKeyword   = "type"
	MapKeyword    = "map"
	ImportKeyword = "import"
)

Variables

View Source
var EofToken = Token{Type: EOF}

EofToken is the end of file token.

View Source
var ErrorToken = Token{Type: error}

ErrorToken is the error token.

View Source
var HttpMethods = []interface{}{"get", "head", "post", "put", "patch", "delete", "connect", "options", "trace"}

HttpMethods returns the http methods.

View Source
var IllegalPosition = Position{}

IllegalPosition is a position that is not valid.

Functions

This section is empty.

Types

type Position

type Position struct {
	Filename string
	Line     int
	Column   int
}

Position represents a rune position in the source code.

func (Position) String

func (p Position) String() string

String returns a string representation of the position.

type Token

type Token struct {
	Type     Type
	Text     string
	Position Position
}

Token is the token of a rune.

func NewIllegalToken

func NewIllegalToken(b rune, pos Position) Token

NewIllegalToken returns a new illegal token.

func (Token) Fork

func (t Token) Fork(tp Type) Token

Fork forks token for a given Type.

func (Token) Is

func (t Token) Is(text ...string) bool

Is returns true if the token text is one of the given list.

func (Token) IsBaseType

func (t Token) IsBaseType() bool

IsBaseType returns true if the token is base type.

func (Token) IsComment

func (t Token) IsComment() bool

IsComment returns true if the token is comment.

func (Token) IsDocument

func (t Token) IsDocument() bool

IsDocument returns true if the token is document.

func (Token) IsEmptyString

func (t Token) IsEmptyString() bool

IsEmptyString returns true if the token is empty string.

func (Token) IsHttpMethod

func (t Token) IsHttpMethod() bool

IsHttpMethod returns true if the token is http method.

func (Token) IsKeyword

func (t Token) IsKeyword() bool

IsKeyword returns true if the token is keyword.

func (Token) IsType

func (t Token) IsType(tp Type) bool

IsType returns true if the token is the given type.

func (Token) Line

func (t Token) Line() int

Line returns the line number of the token.

func (Token) String

func (t Token) String() string

String returns the string of the token.

func (Token) Valid

func (t Token) Valid() bool

Valid returns true if the token is valid.

type Type

type Type int

Type is the type of token.

const (
	ILLEGAL Type
	EOF
	COMMENT
	DOCUMENT

	IDENT      // main
	INT        // 123
	DURATION   // 3s,3ms
	STRING     // "abc"
	RAW_STRING // `abc`
	PATH       // `abc`
	KEY        // `abc:`

	SUB    // -
	MUL    // *
	QUO    // /
	ASSIGN // =

	LPAREN // (
	LBRACK // [
	LBRACE // {
	COMMA  // ,
	DOT    // .

	RPAREN    // )
	RBRACE    // }
	RBRACK    // ]
	SEMICOLON // ;
	COLON     // :
	ELLIPSIS

	BREAK
	CASE
	CHAN
	CONST
	CONTINUE

	DEFAULT
	DEFER
	ELSE
	FALLTHROUGH
	FOR

	FUNC
	GO
	GOTO
	IF
	IMPORT

	INTERFACE
	MAP
	PACKAGE
	RANGE
	RETURN

	SELECT
	STRUCT
	SWITCH
	TYPE
	VAR

	AT_DOC
	AT_HANDLER
	AT_SERVER
	ANY
)

func LookupKeyword

func LookupKeyword(ident string) (Type, bool)

LookupKeyword returns the keyword type if the given ident is keyword.

func (Type) String

func (t Type) String() string

String returns the string of the token type.

Jump to

Keyboard shortcuts

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