Return true on AcceptWhile and AcceptWhileNot functions
This commit is contained in:
parent
ff198abd8f
commit
d8d462d3f9
2 changed files with 11 additions and 4 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build example
|
||||||
// +build example
|
// +build example
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
@ -10,7 +11,7 @@ type lexemStack []unilex.Lexem
|
||||||
|
|
||||||
func (ls *lexemStack) Head() (l unilex.Lexem) {
|
func (ls *lexemStack) Head() (l unilex.Lexem) {
|
||||||
if len(*ls) == 0 {
|
if len(*ls) == 0 {
|
||||||
return unilex.Lexem{Type: unilex.LEOF}
|
return unilex.Lexem{Type: unilex.LexEOF}
|
||||||
}
|
}
|
||||||
return (*ls)[len(*ls)-1]
|
return (*ls)[len(*ls)-1]
|
||||||
}
|
}
|
||||||
|
@ -21,7 +22,7 @@ func (ls *lexemStack) Push(l unilex.Lexem) {
|
||||||
|
|
||||||
func (ls *lexemStack) Pop() (l unilex.Lexem) {
|
func (ls *lexemStack) Pop() (l unilex.Lexem) {
|
||||||
if len(*ls) == 0 {
|
if len(*ls) == 0 {
|
||||||
return unilex.Lexem{Type: unilex.LEOF}
|
return unilex.Lexem{Type: unilex.LexEOF}
|
||||||
}
|
}
|
||||||
*ls, l = (*ls)[:len(*ls)-1], (*ls)[len(*ls)-1]
|
*ls, l = (*ls)[:len(*ls)-1], (*ls)[len(*ls)-1]
|
||||||
return l
|
return l
|
||||||
|
|
10
lexer.go
10
lexer.go
|
@ -134,16 +134,22 @@ func (l *Lexer) AcceptAnyOf(s []string, caseInsentive bool) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptWhile passing symbols from input while they at `valid` string.
|
// AcceptWhile passing symbols from input while they at `valid` string.
|
||||||
func (l *Lexer) AcceptWhile(valid string) {
|
func (l *Lexer) AcceptWhile(valid string) bool {
|
||||||
|
isValid := false
|
||||||
for l.Accept(valid) {
|
for l.Accept(valid) {
|
||||||
|
isValid = true
|
||||||
}
|
}
|
||||||
|
return isValid
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptWhileNot passing symbols from input while they NOT in `invalid` string.
|
// AcceptWhileNot passing symbols from input while they NOT in `invalid` string.
|
||||||
func (l *Lexer) AcceptWhileNot(invalid string) {
|
func (l *Lexer) AcceptWhileNot(invalid string) bool {
|
||||||
|
isValid := false
|
||||||
for !strings.ContainsRune(invalid, l.Next()) {
|
for !strings.ContainsRune(invalid, l.Next()) {
|
||||||
|
isValid = true
|
||||||
}
|
}
|
||||||
l.Back()
|
l.Back()
|
||||||
|
return isValid
|
||||||
}
|
}
|
||||||
|
|
||||||
// AtStart returns true if current lexem not empty
|
// AtStart returns true if current lexem not empty
|
||||||
|
|
Loading…
Reference in a new issue