unilex/statefunc.go

19 lines
401 B
Go
Raw Normal View History

2021-03-06 22:30:32 +03:00
package unilex
// StateFunc represents function that scans lexems and returns new state function or nil if lexing completed.
type StateFunc func(*Lexer) StateFunc
2021-03-10 00:47:58 +03:00
type stateStack []StateFunc
func (ss *stateStack) Push(s StateFunc) {
*ss = append(*ss, s)
}
func (ss *stateStack) Pop() (s StateFunc) {
if len(*ss) == 0 {
return nil
}
*ss, s = (*ss)[:len(*ss)-1], (*ss)[len(*ss)-1]
return s
}