Esempio n. 1
0
// NewParser returns a new Parser object
func NewParser(startState StateFn, lex lexer.Lexer, channelCap int) Parser {
	p := &parser{
		lex:      lex,
		tokens:   queue.NewQueue(4),
		pos:      0,
		sequence: 0,
		eofToken: nil,
		eof:      false,
		state:    startState,
		chn:      make(chan interface{}, channelCap),
	}
	return p
}
Esempio n. 2
0
// NewLexer returns a new Lexer object
func NewLexer(startState StateFn, reader io.Reader, readerBufLen int, channelCap int) Lexer {
	r := bufio.NewReaderSize(reader, readerBufLen)
	l := &lexer{
		reader:   r,
		bufLen:   readerBufLen,
		runes:    queue.NewQueue(4),
		state:    startState,
		tokens:   make(chan *Token, channelCap),
		line:     1,
		column:   0,
		eofToken: nil,
		eof:      false,
	}
	l.updatePeekBytes()
	return l
}