diff options
Diffstat (limited to 'internal/lexer/statefunc.go')
-rw-r--r-- | internal/lexer/statefunc.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/lexer/statefunc.go b/internal/lexer/statefunc.go new file mode 100644 index 0000000..8d0e42a --- /dev/null +++ b/internal/lexer/statefunc.go @@ -0,0 +1,17 @@ +package lexer + +type stateFunc func(*Lexer) stateFunc + +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 +} |