Documentation
¶
Index ¶
Constants ¶
const ( LowestPrec = 0 // non-operators UnaryPrec = 6 HighestPrec = 7 )
A set of constants for precedence-based expression parsing. Non-operators have lowest precedence, followed by operators starting with precedence 1 up to unary operators. The highest precedence serves as "catch-all" precedence for selector, indexing, and other operator and delimiter tokens.
Variables ¶
This section is empty.
Functions ¶
func IsIdentifier ¶
IsIdentifier reports whether name is a Go identifier, that is, a non-empty string made up of letters, digits, and underscores, where the first character is not a digit. Keywords are not identifiers.
Types ¶
type Token ¶
type Token int
const ( Illegal Token = iota EOF Comment Identifier // main Integer // 12345 Float // 123.45 Imaginary // 123.45i Character // 'abc' String // "abc" Assign // = Add // + Substract // - Multiply // * Quotient // / Remainder // % AddAssign // += SubstractAssign // -= MultiplyAssign // *= QuotientAssign // /= RemainderAssign // %= And // & Or // | Xor // ^ ShiftLeft // << ShiftRight // >> AndAssign // &= OrAssign // |= XorAssign // ^= ShiftLeftAssign // <<= ShiftRightAssign // >>= LogicAnd // && LogicOr // || Increment // ++ Decrement // -- Equal // == Less // < Greater // > Not // ! NotEqual // != LessEqual // <= GreaterEqual // >= // Delimiters Comma // , Period // . Ellipsis // ... SemiColon // ; Colon // : LeftParenthesis // ( RightParenthesis // ) LeftBrace // { RightBrace // } LeftBracket // [ RightBracket // ] Function // fn Let Switch Case Default Continue Fallthrough Break If Else Defer Goto Return )
func (Token) IsKeyword ¶
IsKeyword returns true for tokens corresponding to keywords; it returns false otherwise.
func (Token) IsLiteral ¶
IsLiteral returns true for tokens corresponding to identifiers and basic type literals; it returns false otherwise.
func (Token) IsOperator ¶
IsOperator returns true for tokens corresponding to operators and delimiters; it returns false otherwise.
func (Token) Precedence ¶
Precedence returns the operator precedence of the binary operator op. If op is not a binary operator, the result is LowestPrecedence.
func (Token) String ¶
String returns the string corresponding to the token tok. For operators, delimiters, and keywords the string is the actual token character sequence (e.g., for the token Add, the string is "+"). For all other tokens the string corresponds to the token constant name (e.g. for the token Ident, the string is "IDENT").