Documentation ¶
Overview ¶
Package lualex provides a scanner to split a byte stream into Lua lexical elements.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseInt ¶
ParseInt converts the given string to a 64-bit signed integer according to the lexical rules of Lua. Surrounding whitespace is permitted, and any error returned will be of type *strconv.NumError.
func ParseNumber ¶
ParseNumber converts the given string to a 64-bit floating-point number according to the lexical rules of Lua. Surrounding whitespace is permitted, and any error returned will be of type *strconv.NumError.
Types ¶
type Position ¶
type Position struct { // Line is the 1-based line number. Line int // Column is the 1-based column number. // Columns are based in bytes. // Zero indicates that the position only has line number information. Column int }
Position represents a position in a textual source file.
func Pos ¶
Pos returns a new position with the given line number and column. It panics if the resulting Position would not be valid (as reported by Position.IsValid).
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
A Scanner parses Lua tokens from a byte stream.
func NewScanner ¶
func NewScanner(r io.ByteScanner) *Scanner
NewScanner returns a Scanner that reads from r. NewScanner does not buffer r.
func (*Scanner) Scan ¶
Scan reads the next Token from the stream. If Scan returns an error, then the returned token will be an ErrorToken with the Position field set to the approximate position of the error. If an ErrorToken does not have a valid Position, then it indicates an error returned from the underlying reader or an otherwise unrecoverable error.
type Token ¶
type Token struct { Kind TokenKind Position Position // Value holds information for // an [IdentifierToken], a [StringToken], or a [NumeralToken]. Value string }
Token represents a single lexical element in a Lua source file.
func (Token) String ¶
String formats the token as it would appear in Lua source. String returns "<eof>" for ErrorToken.
type TokenKind ¶
type TokenKind int
TokenKind is an enumeration of valid Token types. The zero value is ErrorToken.
const ( // ErrorToken indicates an invalid token. ErrorToken TokenKind = iota // IdentifierToken indicates a name. // The Value field of [Token] will contain the identifier. IdentifierToken // StringToken indicates a literal string. // The Value field of [Token] will contain the parsed value of the string. StringToken // NumeralToken indicates a numeric constant. // The Value field of [Token] will contain the constant as written. NumeralToken AndToken // and BreakToken // break DoToken // do ElseToken // else ElseifToken // elseif EndToken // end FalseToken // false ForToken // for FunctionToken // function GotoToken // goto IfToken // if InToken // in LocalToken // local NilToken // nil NotToken // not OrToken // or RepeatToken // repeat ReturnToken // return ThenToken // then TrueToken // true UntilToken // until WhileToken // while AddToken // + SubToken // - MulToken // * DivToken // / ModToken // % PowToken // ^ LenToken // # BitAndToken // & BitXorToken // ~ BitOrToken // | LShiftToken // << RShiftToken // >> IntDivToken // // EqualToken // == NotEqualToken // ~= LessEqualToken // <= GreaterEqualToken // >= LessToken // < GreaterToken // > AssignToken // = LParenToken // ( RParenToken // ) LBraceToken // { RBraceToken // } LBracketToken // [ RBracketToken // ] LabelToken // :: SemiToken // ; ColonToken // : CommaToken // , DotToken // . ConcatToken // .. VarargToken // ... )
TokenKind values.