Documentation
¶
Index ¶
Constants ¶
const ( LOWEST precedence LOR // || LAND // && EQUALS // == LESSGREATER // > or < SUM // + PRODUCT // * PREFIX // -X or !X CALL // function(X) )
const ( CURRENT peekNumber = iota NEXT )
Variables ¶
var TokenTypeMap = map[TokenType]string{ Illegal: "ILLEGAL", Ident: "IDENT", Int: "INT", String: "STRING", Function: "FUNCTION", Contract: "CONTRACT", IntType: "INT_TYPE", StringType: "STRING_TYPE", BoolType: "BOOL_TYPE", Assign: "ASSIGN", Plus: "PLUS", Minus: "MINUS", Bang: "BANG", Asterisk: "ASTERISK", Slash: "SLASH", Mod: "MOD", PlusAssign: "PLUS_ASSIGN", MinusAssign: "MINUS_ASSIGN", AsteriskAssign: "ASTERISK_ASSIGN", SlashAssign: "SLASH_ASSIGN", ModAssign: "MOD_ASSIGN", Land: "LAND", Lor: "LOR", Inc: "INC", Dec: "DEC", LT: "LT", GT: "GT", LTE: "LTE", GTE: "GTE", EQ: "EQ", NOT_EQ: "NOT_EQ", Comma: "COMMA", Lparen: "LPAREN", Rparen: "RPAREN", Lbrace: "LBRACE", Rbrace: "RBRACE", True: "TRUE", False: "FALSE", If: "IF", Else: "ELSE", Return: "RETURN", Eof: "EOF", Eol: "EOL", Semicolon: "SEMICOLON", }
TokenTypeMap mapping TokenType with its string, this helps debugging
Functions ¶
Types ¶
type DefaultTokenBuffer ¶
type DefaultTokenBuffer struct {
// contains filtered or unexported fields
}
DefaultTokenBuffer is implementation for TokenBuffer interface providing buffers to the client.
cur, next work as buffer. Each store token as below
----------------------------------------------
client <- | cur | next | <- lexer ====== <- | token | token | <- =====
----------------------------------------------
func NewTokenBuffer ¶
func NewTokenBuffer(l *Lexer) *DefaultTokenBuffer
func (*DefaultTokenBuffer) Peek ¶
func (b *DefaultTokenBuffer) Peek(n peekNumber) Token
Peek returns token based on the peekNumber, this doesn't change token value
func (*DefaultTokenBuffer) Read ¶
func (b *DefaultTokenBuffer) Read() Token
Read returns current token, then read from lexer then change the cur, next token value
type DupSymError ¶
type DupSymError struct {
Source Token
}
dupSymError occur when there is duplicated symbol
func (DupSymError) Error ¶
func (e DupSymError) Error() string
type ExpectError ¶
ExpectError happens during parsing expectNext
func (ExpectError) Error ¶
func (e ExpectError) Error() string
type NotExistSymError ¶
type NotExistSymError struct {
Source Token
}
NotExistSymError occur when there is no target symbol
func (NotExistSymError) Error ¶
func (e NotExistSymError) Error() string
type Pos ¶
type Pos int
Pos represents a byte position in the original input text from which this template was parsed.
type PrefixError ¶
type PrefixError struct { Source Token Right ast.Expression }
prefixError occur when there is invalid prefix type
func (PrefixError) Error ¶
func (e PrefixError) Error() string
type TokenBuffer ¶
type TokenBuffer interface { // Read retrieve token from buffer. and change the // buffer states Read() Token // Peek take token as many as n from buffer but not change the // buffer states Peek(n peekNumber) Token }
TokenBuffer provide tokenized token, we can read from this buffer or just peek the token
type TokenType ¶
type TokenType int
const ( // ILLEGAL Token Illegal TokenType = iota // Identifiers + literals Ident // add, foobar, x, y, ... Int // 1343456 String // "hello world" Function // func Contract // contract IntType StringType BoolType VoidType Assign // = Plus // + Minus // - Bang // ! Asterisk // * Slash // / Mod // % PlusAssign // += MinusAssign // -= AsteriskAssign // *= SlashAssign // /= ModAssign // %= Land // && Lor // || Inc // ++ Dec //-- LT // < GT // > LTE // <= GTE // >= EQ // == NOT_EQ // != Comma // , Lparen // ( Rparen // ) Lbrace // { Rbrace // } True // true False // false If // if Else // else Return // return Eof // end of file Eol // end of line Semicolon )