token

package
v3.8.2-oya+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ILLEGAL = "ILLEGAL"
	EOF     = "EOF"

	// Identifiers + literals
	IDENT    = "IDENT"    // add, foobar, x, y, ...
	INT      = "INT"      // 1343456
	FLOAT    = "FLOAT"    // 12.34
	STRING   = "STRING"   // "foobar"
	B_STRING = "B_STRING" // `foobar`
	HTML     = "HTML"     // <p>adf</p>
	DOT      = "DOT"      // .23

	// Operators
	ASSIGN   = "="
	PLUS     = "+"
	MINUS    = "-"
	BANG     = "!"
	ASTERISK = "*"
	SLASH    = "/"
	PERCENT  = "%"

	LT   = "<"
	LTEQ = "<="
	GT   = ">"
	GTEQ = ">="

	EQ      = "=="
	NOT_EQ  = "!="
	AND     = "&&"
	OR      = "||"
	MATCHES = "~="

	S_START = "<%"
	C_START = S_START + "#"
	E_START = S_START + "="
	E_END   = "%>"

	COMMA     = ","
	SEMICOLON = ";"
	COLON     = ":"

	LPAREN   = "("
	RPAREN   = ")"
	LBRACE   = "{"
	RBRACE   = "}"
	LBRACKET = "["
	RBRACKET = "]"

	// Keywords
	FUNCTION = "FUNCTION"
	LET      = "LET"
	TRUE     = "TRUE"
	FALSE    = "FALSE"
	IF       = "IF"
	ELSE     = "ELSE"
	RETURN   = "RETURN"
	FOR      = "FOR"
	IN       = "IN"
)

Variables

This section is empty.

Functions

func MatchAhead

func MatchAhead(token Type, firstChar, lastChar byte) bool

MatchAhead returns true if token matches firstChar and nextChar

func SetTemplatingDelimiters

func SetTemplatingDelimiters(start, end string) error

SetTemplatingDelimiters to start and end, or return delimitersLengthError if delimiters length is incorrect

Types

type Token

type Token struct {
	Type       Type
	Literal    string
	LineNumber int
}

Token of a section of input source.

type Type

type Type string

Type represents each type of token.

func LookupIdent

func LookupIdent(ident string) Type

LookupIdent an ident and return a keyword type, or a plain ident

func Resolve

func Resolve(token Type) Type

Resolve token.Type, return dynamic replacement if found or default Type

func (*Type) BeginsWith

func (t *Type) BeginsWith(ch byte) bool

BeginsWith returns true if first char of type matches input

Jump to

Keyboard shortcuts

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