diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-03-10 00:47:58 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-03-10 00:47:58 +0300 |
commit | ff198abd8fc9e2019c2f3ef9b7e74206ecdb99b7 (patch) | |
tree | 3ea7c05e54d00bf2d70cec7c88442402f9916a55 /statefunc.go | |
parent | 521e6da1f6c9c964abca5bac22ce62823c276c1f (diff) |
Push/pop state, full json examplev0.0.2
Diffstat (limited to 'statefunc.go')
-rw-r--r-- | statefunc.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/statefunc.go b/statefunc.go index 5980ecc..734fe57 100644 --- a/statefunc.go +++ b/statefunc.go @@ -2,3 +2,17 @@ package unilex // StateFunc represents function that scans lexems and returns new state function or nil if lexing completed. 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 +} |