parser: add internal []Token queue to the Parser

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-30 20:08:29 +00:00
parent d081fe7d1c
commit c1d3f61b73
2 changed files with 46 additions and 1 deletions
+44
View File
@@ -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
View File
@@ -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.