Пример #1
0
// New returns a new Parser object
func New(startState StateFn, lex lexer.Lexer, channelCap int) Parser {
	p := &parser{
		lex:      lex,
		tokens:   queue.New(4), // 4 is just a nice number that seems appropriate
		pos:      0,
		sequence: 0,
		eofToken: nil,
		eof:      false,
		state:    startState,
		chn:      make(chan interface{}, channelCap),
	}
	return p
}
Пример #2
0
// New returns a new Lexer object
func New(startState StateFn, reader io.Reader, readerBufLen int, channelCap int) Lexer {
	r := bufio.NewReaderSize(reader, readerBufLen)
	l := &lexer{
		reader:   r,
		bufLen:   readerBufLen,
		runes:    queue.New(4), // 4 is just a nice number that seems appropriate
		state:    startState,
		tokens:   make(chan *Token, channelCap),
		line:     1,
		column:   0,
		eofToken: nil,
		eof:      false,
	}
	l.updatePeekBytes()
	return l
}