Documentation ¶
Overview ¶
String lexer package
Derived from template/parse/lex.go Copyright 2011 The Go Authors.
Index ¶
- Variables
- func IsAlphaNumeric(char rune) bool
- func IsSpace(char rune) bool
- type Item
- type ItemType
- type Lexer
- func (self *Lexer) Accept(valid string) (ok bool, err error)
- func (self *Lexer) AcceptNot(invalid string) (ok bool, err error)
- func (self *Lexer) AcceptRun(valid string) (err error)
- func (self *Lexer) AcceptRunNot(invalid string) (err error)
- func (self *Lexer) Backup() (err error)
- func (self *Lexer) Emit(t ItemType) Item
- func (self *Lexer) Errorf(format string, args ...interface{}) (StateFn, Item)
- func (self *Lexer) Ignore()
- func (self *Lexer) LineNumber() int
- func (self *Lexer) LinePosition() int
- func (self *Lexer) Next() (char rune, err error)
- func (self *Lexer) NextItem() Item
- func (self *Lexer) Peek() (char rune, err error)
- func (self *Lexer) Rewind(state StateFn)
- func (self *Lexer) ScanNumber() (ok bool, err error)
- type StateFn
Constants ¶
This section is empty.
Variables ¶
var ItemName = map[ItemType]string{ Incomplete: "incomplete", ItemError: "error", ItemChar: "char", ItemEOF: "EOF", ItemEnd: "end", ItemField: "field", ItemNumber: "number", ItemText: "text", ItemID: "id", ItemSeq: "seq", ItemQual: "qual", }
Make the types prettyprint.
Functions ¶
func IsAlphaNumeric ¶
IsAlphaNumeric reports whether char is an alphabetic, digit, or underscore.
Types ¶
type Lexer ¶
type Lexer struct { Buffer []rune // buffer to store tokens being built. // contains filtered or unexported fields }
Lexer holds the state of the scanner.
func (*Lexer) AcceptRunNot ¶
AcceptRunNot consumes a run of bytes not from the invalid set.
func (*Lexer) Errorf ¶
Error returns an error token and terminates the scan by passing back a nil pointer that will be the next state, terminating self.run.
func (*Lexer) Ignore ¶
func (self *Lexer) Ignore()
Ignore skips over the pending input before this point.
func (*Lexer) LineNumber ¶
LineNumber reports which line we're on.
func (*Lexer) LinePosition ¶
LinePosition reports where we are in the line we're on.
func (*Lexer) ScanNumber ¶
ScanNumber scans a number: decimal, octal, hex, or float. This isn't a perfect number scanner - for instance it accepts "." and "0x0.2" and "089" - but when it's wrong the input is invalid and the parser (via strconv) will notice.
func LexNumber(self *Lexer) { if !self.ScanNumber() { return self.Errorf("bad number syntax: %q", self.input[self.start:self.pos]) } self.Emit(ItemNumber) return <nextStateFn> }