|
|
@ -74,3 +74,29 @@ func (p *TextParser) StepLine() { |
|
|
|
func (p *TextParser) Position() lexer.Position { |
|
|
|
func (p *TextParser) Position() lexer.Position { |
|
|
|
return p.pos |
|
|
|
return p.pos |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// AcceptNewLine checks if next is a new line.
|
|
|
|
|
|
|
|
// It accepts "\n", "\n\r", "\r" and "\r\n".
|
|
|
|
|
|
|
|
func (p *TextParser) AcceptNewLine() bool { |
|
|
|
|
|
|
|
r1, _, err := p.ReadRune() |
|
|
|
|
|
|
|
switch { |
|
|
|
|
|
|
|
case err != nil: |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
case r1 == '\n': |
|
|
|
|
|
|
|
p.AcceptRune('\r') |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
case r1 == '\r': |
|
|
|
|
|
|
|
p.AcceptRune('\n') |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
p.UnreadRune() |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// AcceptRune checks if next is the specified rune
|
|
|
|
|
|
|
|
func (p *TextParser) AcceptRune(r rune) bool { |
|
|
|
|
|
|
|
return p.Accept(func(r2 rune) bool { |
|
|
|
|
|
|
|
return r == r2 |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|