parser: add internal []Token queue to the Parser
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package parser
|
||||
|
||||
import "log"
|
||||
|
||||
func (p *Parser) push(tok Token) {
|
||||
n := len(p.queue)
|
||||
p.queue = append(p.queue, tok)
|
||||
|
||||
log.Printf("queue[%v]: %s", n, tok)
|
||||
}
|
||||
|
||||
func (p *Parser) pushString(typ TokenType) {
|
||||
s := p.src.Emit()
|
||||
|
||||
el := Token{
|
||||
Type: typ,
|
||||
Value: s,
|
||||
Position: p.pos,
|
||||
}
|
||||
|
||||
p.pos.StepN(len(s))
|
||||
|
||||
p.push(el)
|
||||
}
|
||||
|
||||
// stepLine discards the data and moves the position
|
||||
// to the next line
|
||||
func (p *Parser) stepLine() {
|
||||
p.src.Discard()
|
||||
p.pos.StepLine()
|
||||
}
|
||||
|
||||
// stepRune discards the data and moves the position
|
||||
// on rune forward on the same line
|
||||
func (p *Parser) stepRune() {
|
||||
p.src.Discard()
|
||||
p.pos.Step()
|
||||
}
|
||||
|
||||
func (p *Parser) stepString() string {
|
||||
s := p.src.Emit()
|
||||
p.pos.StepN(len(s))
|
||||
return s
|
||||
}
|
||||
+2
-1
@@ -11,7 +11,8 @@ import (
|
||||
type Parser struct {
|
||||
src *lexer.Reader
|
||||
|
||||
pos lexer.Position
|
||||
pos lexer.Position
|
||||
queue []Token
|
||||
|
||||
// OnSection is called after a [section] is parsed.
|
||||
// Returning an error will abort the process.
|
||||
|
||||
Reference in New Issue
Block a user