Documentation ¶
Index ¶
- Variables
- type Token
- func (t *Token) AnsiStyling() []color.Attribute
- func (t *Token) BackgroundColor() prompt.Color
- func (t *Token) Color() prompt.Color
- func (t *Token) DisplayAttributes() []prompt.DisplayAttribute
- func (t *Token) FirstByteIndex() pstrings.ByteNumber
- func (t *Token) InspectValue() string
- func (t *Token) LastByteIndex() pstrings.ByteNumber
- func (t *Token) SetSpan(span *position.Span)
- func (t *Token) Span() *position.Span
- func (t *Token) String() string
- func (t *Token) StringValue() string
- type Type
- func (t Type) IsAssignmentOperator() bool
- func (t Type) IsCollectionLiteralBeg() bool
- func (t Type) IsComparisonOperator() bool
- func (t Type) IsEndOfFile() bool
- func (t Type) IsEqualityOperator() bool
- func (t Type) IsFloatLiteral() bool
- func (t Type) IsIdentifier() bool
- func (t Type) IsIntLiteral() bool
- func (t Type) IsKeyword() bool
- func (t Type) IsLiteral() bool
- func (t Type) IsNonOverridableOperator() bool
- func (t Type) IsOperator() bool
- func (t Type) IsOverridableOperator() bool
- func (t Type) IsRegexFlag() bool
- func (t Type) IsSpecialCollectionLiteral() bool
- func (t Type) IsSpecialCollectionLiteralBeg() bool
- func (t Type) IsStatementSeparator() bool
- func (t Type) IsValidAsArgumentToNoParenFunctionCall() bool
- func (t Type) IsValidAsEndInRangeLiteral() bool
- func (t Type) IsValidAsEndInRangePattern() bool
- func (t Type) IsValidMethodName() bool
- func (t Type) IsValidPublicMethodName() bool
- func (t Type) IsValidRegularMethodName() bool
- func (t Type) IsValidSimpleSymbolContent() bool
- func (t Type) String() string
Constants ¶
This section is empty.
Variables ¶
var Keywords = map[string]Type{ "nil": NIL, "false": FALSE, "true": TRUE, "if": IF, "else": ELSE, "elsif": ELSIF, "unless": UNLESS, "while": WHILE, "until": UNTIL, "loop": LOOP, "for": FOR, "fornum": FORNUM, "in": IN, "halt": HALT, "break": BREAK, "continue": CONTINUE, "return": RETURN, "yield": YIELD, "async": ASYNC, "await": AWAIT, "go": GO, "def": DEF, "sig": SIG, "end": END, "then": THEN, "init": INIT, "class": CLASS, "struct": STRUCT, "module": MODULE, "mixin": MIXIN, "interface": INTERFACE, "include": INCLUDE, "extend": EXTEND, "enhance": ENHANCE, "enum": ENUM, "type": TYPE, "typedef": TYPEDEF, "var": VAR, "val": VAL, "const": CONST, "throw": THROW, "try": TRY, "catch": CATCH, "do": DO, "ensure": ENSURE, "finally": FINALLY, "alias": ALIAS, "as": AS, "is": IS, "self": SELF, "super": SUPER, "switch": SWITCH, "case": CASE, "match": MATCH, "with": WITH, "using": USING, "breakpoint": BREAKPOINT, "getter": GETTER, "setter": SETTER, "accessor": ACCESSOR, "must": MUST, "singleton": SINGLETON, "abstract": ABSTRACT, "sealed": SEALED, }
Maps keywords to their Token Type.
Functions ¶
This section is empty.
Types ¶
type Token ¶
type Token struct { Type Value string // Literal value of the token, will be empty for tokens with non-dynamic lexemes // contains filtered or unexported fields }
Represents a single token produced by the lexer.
func NewWithValue ¶
Creates a new token with the specified value.
func (*Token) AnsiStyling ¶
Returns the ANSI font styling for the github.com/fatih/color package.
func (*Token) BackgroundColor ¶
func (t *Token) BackgroundColor() prompt.Color
Background color for go-prompt.
func (*Token) DisplayAttributes ¶
func (t *Token) DisplayAttributes() []prompt.DisplayAttribute
Display attributes for go-prompt eg. bold, italic, underline.
func (*Token) FirstByteIndex ¶
func (t *Token) FirstByteIndex() pstrings.ByteNumber
Index of the first byte of the lexeme. Used by go-prompt.
func (*Token) InspectValue ¶
Returns a shortened version of the value which resembles source code.
func (*Token) LastByteIndex ¶
func (t *Token) LastByteIndex() pstrings.ByteNumber
Index of the last byte of the lexeme. Used by go-prompt.
func (*Token) StringValue ¶
When the Value field of the token is empty, the string will be fetched from a global map.
type Type ¶
type Type uint8
Represents the type of token
const ( ZERO_VALUE Type = iota // Zero value for Type ERROR // ERROR Token with a message END_OF_FILE // End Of File has been reached NEWLINE // Newline `\n`, `\r\n` SEMICOLON // SEMICOLON `;` LPAREN // Left parenthesis `(` RPAREN // Right parenthesis `)` LBRACE // Left brace `{` RBRACE // Right brace `}` LBRACKET // Left bracket `[` QUESTION_LBRACKET // Safe access `?[` RBRACKET // Right bracket `]` COMMA // Comma `,` DOT // Dot `.` QUESTION_DOT // Safe method call operator `?.` COLON // Colon `:` QUESTION // Question mark `?` // Operators start here LABEL_OP_BEG THIN_ARROW // Thin arrow `->` (function arrow) WIGGLY_ARROW // Wiggly arrow `~>` (lambda arrow) THICK_ARROW // Thick arrow `=>` // Assignment operators start here LABEL_ASSIGN_OP_BEG EQUAL_OP // Equal (assignment) `=` MINUS_EQUAL // Minus equal `-=` PLUS_EQUAL // Plus equal `+=` STAR_EQUAL // Star equal `*=` SLASH_EQUAL // Slash equal `/=` STAR_STAR_EQUAL // Two stars equal `**=` TILDE_EQUAL // Tilde equal `~=` AND_AND_EQUAL // Logical and equal `&&=` AND_EQUAL // Bitwise and equal `&=` OR_OR_EQUAL // Logical or `||=` OR_EQUAL // Bitwise or equal `|=` XOR_EQUAL // Bitwise xor equal `^=` QUESTION_QUESTION_EQUAL // Nil coalescing equal operator `??=` LBITSHIFT_EQUAL // Left bitwise shift equal `<<=` LTRIPLE_BITSHIFT_EQUAL // Triple left bitwise shift equal `<<<=` RBITSHIFT_EQUAL // Right bitwise shift equal `>>=` RTRIPLE_BITSHIFT_EQUAL // Triple right bitwise shift equal `>>>=` PERCENT_EQUAL // Percent equal `%=` COLON_EQUAL // Colon equal `:=` LABEL_ASSIGN_OP_END // Assignment operators end here SCOPE_RES_OP // Scope resolution operator `::` CLOSED_RANGE_OP // Closed range operator `...` OPEN_RANGE_OP // Open range operator `<.<` RIGHT_OPEN_RANGE_OP // Right open range operator `..<` LEFT_OPEN_RANGE_OP // Left open range operator `<..` PIPE_OP // Pipe operator `|>` AND_AND // Logical and `&&` AND_BANG // Logical expression sequencing operator `&!` with the precedence of `&&` OR_OR // Logical or `||` OR_BANG // Logical expression sequencing operator `|!` with the precedence of `||` NOT_EQUAL // Not equal `!=` LAX_NOT_EQUAL // Lax not equal operator `!~` STRICT_EQUAL // Strict equal `===` STRICT_NOT_EQUAL // Strict not equal `!==` // Overridable operators start here LABEL_OVERRIDABLE_OP_BEG PLUS_PLUS // Increment operator `++` MINUS_MINUS // Decrement operator `--` PLUS_AT // Negate `+@` MINUS_AT // Negate `-@` MINUS // Minus `-` PLUS // Plus `+` STAR // Star `*` SLASH // Slash `/` STAR_STAR // Two stars `**` LESS // Less than `<` LESS_EQUAL // Less than or equal `<=` GREATER // Greater than `>` GREATER_EQUAL // Greater than or equal `>=` SPACESHIP_OP // Spaceship operator `<=>` EQUAL_EQUAL // Equal (comparison) `==` LAX_EQUAL // Lax equality operator `=~` TILDE // Tilde `~` AND // Bitwise and `&` AND_TILDE // Bitwise and not `&~` OR // Bitwise or `|` XOR // Bitwise xor `^` QUESTION_QUESTION // Nil coalescing operator `??` BANG // Logical not `!` ISA_OP // "is a" operator `<:` REVERSE_ISA_OP // Reverse "is a" operator `:>` INSTANCE_OF_OP // Instance of operator `<<:` REVERSE_INSTANCE_OF_OP // Reverse instance of operator `:>>` LBITSHIFT // Left bitwise shift `<<` LTRIPLE_BITSHIFT // Triple left bitwise shift `<<<` RBITSHIFT // Right bitwise shift `>>` RTRIPLE_BITSHIFT // Triple right bitwise shift `>>>` PERCENT // Percent `%` LABEL_OP_END // Operators end here // Identifiers start here LABEL_IDENTIFIER_BEG PUBLIC_IDENTIFIER // Identifier PRIVATE_IDENTIFIER // Identifier with a initial underscore PUBLIC_CONSTANT // Constant (identifier with an initial capital letter) PRIVATE_CONSTANT // Constant with an initial underscore LABEL_IDENTIFIER_END // Identifiers end here INSTANCE_VARIABLE // Instance variable token eg. `@foo` SPECIAL_IDENTIFIER // Special identifier token eg. `$foo` // Literals start here LABEL_LITERAL_BEG // Special collection literals start here LABEL_SPECIAL_COLLECTION_LITERAL_BEG WORD_ARRAY_LIST_BEG // Word array literal beginning `\w[` WORD_ARRAY_LIST_END // Word array literal end `]` SYMBOL_ARRAY_LIST_BEG // Symbol array literal beginning `\s[` SYMBOL_ARRAY_LIST_END // Symbol array literal end `]` HEX_ARRAY_LIST_BEG // Hexadecimal integer array literal beginning `\x[` HEX_ARRAY_LIST_END // Hexadecimal integer array literal end `]` BIN_ARRAY_LIST_BEG // Binary integer array literal beginning `\b[` BIN_ARRAY_LIST_END // Binary integer array literal end `]` WORD_HASH_SET_BEG // Word set literal beginning `^w[` WORD_HASH_SET_END // Word set literal end `]` SYMBOL_HASH_SET_BEG // Symbol set literal beginning `^s[` SYMBOL_HASH_SET_END // Symbol set literal end `]` HEX_HASH_SET_BEG // Hexadecimal integer set literal beginning `^x[` HEX_HASH_SET_END // Hexadecimal integer set literal end `]` BIN_HASH_SET_BEG // Binary integer set literal beginning `^b[` BIN_HASH_SET_END // Binary integer set literal end `]` WORD_ARRAY_TUPLE_BEG // Word arrayTuple literal beginning `%w[` WORD_ARRAY_TUPLE_END // Word arrayTuple literal end `]` SYMBOL_ARRAY_TUPLE_BEG // Symbol arrayTuple literal beginning `%s[` SYMBOL_ARRAY_TUPLE_END // Symbol arrayTuple literal end `]` HEX_ARRAY_TUPLE_BEG // Hexadecimal integer arrayTuple literal beginning `%x[` HEX_ARRAY_TUPLE_END // Hexadecimal integer arrayTuple literal end `]` BIN_ARRAY_TUPLE_BEG // Binary integer arrayTuple literal beginning `%b[` BIN_ARRAY_TUPLE_END // Binary integer arrayTuple literal end `]` LABEL_SPECIAL_COLLECTION_LITERAL_END // Special collection literals end here HASH_SET_LITERAL_BEG // HashHashSet literal beginning `^[` TUPLE_LITERAL_BEG // ArrayTuple literal beginning `%[` RECORD_LITERAL_BEG // Record literal beginning `%{` DOC_COMMENT // Documentation comment `##[` ... `]##` RAW_STRING // Raw String literal delimited by single quotes `'` ... `'` CHAR_LITERAL // Character literal delimited by backticks eg. `f` RAW_CHAR_LITERAL // Raw Character literal delimited by r` eg. r`f` REGEX_BEG // Beginning delimiter of Regex literals `%/` REGEX_CONTENT // Regex literal content REGEX_INTERP_BEG // Beginning of regex interpolation `${` REGEX_INTERP_END // End of regex interpolation `}` REGEX_END // Ending delimiter of Regex literals `/` // Regex flags start here LABEL_REGEX_FLAG_BEG REGEX_FLAG_i // Regex flag i REGEX_FLAG_m // Regex flag m REGEX_FLAG_U // Regex flag U REGEX_FLAG_a // Regex flag a REGEX_FLAG_x // Regex flag x REGEX_FLAG_s // Regex flag s LABEL_REGEX_FLAG_END // Regex flags end here STRING_BEG // Beginning delimiter of String literals `"` STRING_CONTENT // String literal content STRING_INTERP_LOCAL // A local embedded in string interpolation eg. `$foo` STRING_INTERP_CONSTANT // A constant embedded in string interpolation eg. `$Foo` STRING_INTERP_BEG // Beginning of string interpolation `${` STRING_INSPECT_INTERP_BEG // Beginning of string inspect interpolation `#{` STRING_INSPECT_INTERP_CONSTANT // A constant embedded in inspect string interpolation eg. `#Foo` STRING_INSPECT_INTERP_LOCAL // A local embedded in inspect string interpolation eg. `#foo` STRING_INTERP_END // End of string interpolation `}` STRING_END // Ending delimiter of String literals `"` // Int literals start here LABEL_INT_LITERAL_BEG INT // Int literal eg. `23` INT64 // Int64 literal eg. `23i64` UINT64 // UInt64 literal eg. `23u64` INT32 // Int32 literal eg. `23i32` UINT32 // UInt32 literal eg. `23u32` INT16 // Int16 literal eg. `23i16` UINT16 // UInt16 literal eg. `23u16` INT8 // Int8 literal eg. `23i8` UINT8 // UInt8 literal eg. `23u8` LABEL_INT_LITERAL_END // Int literals end here // Float literals start here LABEL_FLOAT_LITERAL_BEG FLOAT // Float literal eg. `2.5` BIG_FLOAT // BigFloat literal eg. `2.5bf` FLOAT64 // Float64 literal eg. `2.5f64` FLOAT32 // Float32 literal eg. `2.5f32` LABEL_FLOAT_LITERAL_END // Float literals end here LABEL_LITERAL_END // Literals end here // Keywords start here LABEL_KEYWORD_BEG NIL // Keyword `nil` FALSE // Keyword `false` TRUE // Keyword `true` IF // Keyword `if` ELSE // Keyword `else` ELSIF // Keyword `elsif` UNLESS // Keyword `unless` WHILE // Keyword `while` UNTIL // Keyword `until` LOOP // Keyword `loop` FOR // Keyword `for` FORNUM // Keyword `fornum` IN // Keyword `in` HALT // Keyword `halt` BREAK // Keyword `break` CONTINUE // Keyword `continue` RETURN // Keyword `return` YIELD // Keyword `yield` ASYNC // Keyword `async` AWAIT // Keyword `await` GO // Keyword `go` DEF // Keyword `def` SIG // Keyword `sig` END // Keyword `end` THEN // Keyword `then` INIT // Keyword `init` CLASS // Keyword `class` STRUCT // Keyword `struct` MODULE // Keyword `module` MIXIN // Keyword `mixin` INTERFACE // Keyword `interface` INCLUDE // Keyword `include` EXTEND // Keyword `extend` ENHANCE // Keyword `enhance` ENUM // Keyword `enum` TYPE // Keyword `type` TYPEDEF // Keyword `typedef` VAR // Keyword `var` VAL // Keyword `val` CONST // Keyword `const` THROW // Keyword `throw` TRY // Keyword `try` CATCH // Keyword `catch` DO // Keyword `do` ENSURE // Keyword `ensure` FINALLY // Keyword `finally` ALIAS // Keyword `alias` AS // Keyword `as` IS // Keyword `is` SELF // Keyword `self` SUPER // Keyword `super` SWITCH // Keyword `switch` CASE // Keyword `case` MATCH // Keyword `match` WITH // Keyword `with` USING // Keyword `using` BREAKPOINT // Keyword `breakpoint` GETTER // Keyword `getter` SETTER // Keyword `setter` ACCESSOR // Keyword `accessor` MUST // Keyword `must` SINGLETON // Keyword `singleton` ABSTRACT // Keyword `abstract` SEALED // Keyword `sealed` LABEL_KEYWORD_END // Keywords end here )
func (Type) IsAssignmentOperator ¶
Check whether the token is an assignment operator.
func (Type) IsCollectionLiteralBeg ¶
func (Type) IsComparisonOperator ¶
Check whether the token is a comparison operator.
func (Type) IsEndOfFile ¶
Check whether the token marks the end of the file.
func (Type) IsEqualityOperator ¶
Check whether the token is an equality operator.
func (Type) IsFloatLiteral ¶
Check whether the token is a float literal.
func (Type) IsIdentifier ¶
Check whether the token is an identifier.
func (Type) IsIntLiteral ¶
Check whether the token is an int literal.
func (Type) IsNonOverridableOperator ¶
Check whether the token is a non overridable operator.
func (Type) IsOverridableOperator ¶
Check whether the token is an overridable operator. Overridable operators can be used as method names.
func (Type) IsRegexFlag ¶
Check whether the token represents a regex flag
func (Type) IsSpecialCollectionLiteral ¶
Check whether the token represents a special collection literal like `%w[]`
func (Type) IsSpecialCollectionLiteralBeg ¶
return `true` if the token is the beginning of a special collection literal
func (Type) IsStatementSeparator ¶
Check whether the token can separate statements.
func (Type) IsValidAsArgumentToNoParenFunctionCall ¶
Returns `true` if the token can be a beginning of an argument to a function call without parentheses eg. `foo 2`
func (Type) IsValidAsEndInRangeLiteral ¶
Returns `true` if the token can be an end of a range value eg. `..2`
func (Type) IsValidAsEndInRangePattern ¶
Returns `true` if the token can be an end of a range pattern eg. `..2`
func (Type) IsValidMethodName ¶
Check whether the token is a valid method name (including operators).
func (Type) IsValidPublicMethodName ¶
Check whether the token is a valid method name in method call expressions.
func (Type) IsValidRegularMethodName ¶
Check whether the token is a valid method name (without operators).
func (Type) IsValidSimpleSymbolContent ¶
Check whether the token is a valid simple symbol content.