From ff198abd8fc9e2019c2f3ef9b7e74206ecdb99b7 Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Wed, 10 Mar 2021 00:47:58 +0300 Subject: Push/pop state, full json example --- statefunc.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'statefunc.go') 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 +} -- cgit v1.2.3