Permalink
Browse files

.

  • Loading branch information...
richard-lyman committed Nov 14, 2016
1 parent 4c016fe commit 1daaa0babade014fe0fab12ac23a72c16468d310
Showing with 44 additions and 5 deletions.
  1. +12 −5 amotoen.go
  2. +4 −0 node.go
  3. +20 −0 state.go
  4. +8 −0 string.go
View
@@ -22,12 +22,18 @@ func Manual(root State, input Input, mustConsumeAll bool) Tree {
return result
}
-type PostHandler func(Tree) (Tree, error)
+type PostResult struct {
+ Content interface{}
+ Err error
+}
+
+type PostHandler func(Tree) PostResult
type State interface {
Handle(Input) (Tree, error)
Label(string) State
Post(PostHandler) State
+ PostHandle(Tree) PostResult
Stringer
}
@@ -50,10 +56,11 @@ type Tree interface {
type DeferredState struct{ inner State }
-func (s *DeferredState) Post(ph PostHandler) State { s.inner.Post(ph); return s }
-func (s *DeferredState) Label(label string) State { return s }
-func (s *DeferredState) String() string { return s.inner.String() }
-func (s *DeferredState) Set(newState State) { s.inner = newState }
+func (s *DeferredState) PostHandle(t Tree) PostResult { return s.inner.PostHandle(t) }
+func (s *DeferredState) Post(ph PostHandler) State { s.inner.Post(ph); return s }
+func (s *DeferredState) Label(label string) State { return s }
+func (s *DeferredState) String() string { return s.inner.String() }
+func (s *DeferredState) Set(newState State) { s.inner = newState }
func (s *DeferredState) Handle(input Input) (Tree, error) {
t, err := s.inner.Handle(input)
return t, err
View
@@ -19,6 +19,10 @@ func (n *node) Source() State {
}
func (n *node) Append(t Tree) Tree {
+ // It's expected that when a Tree is provided to append
+ // ... it is finished - it's ready to be post-processed...
+ // We can access the post-processor through the state which is in the
+ // ... source attribute
n.children = append(n.children, t)
return t
}
View
@@ -6,6 +6,10 @@ type oState struct {
postHandler PostHandler
}
+func (s *oState) PostHandle(t Tree) PostResult {
+ return s.postHandler(t)
+}
+
func (s *oState) Post(f PostHandler) State {
s.postHandler = f
return s
@@ -52,6 +56,10 @@ type zState struct {
postHandler PostHandler
}
+func (s *zState) PostHandle(t Tree) PostResult {
+ return s.postHandler(t)
+}
+
func (s *zState) Post(f PostHandler) State {
s.postHandler = f
return s
@@ -91,6 +99,10 @@ type sState struct {
postHandler PostHandler
}
+func (s *sState) PostHandle(t Tree) PostResult {
+ return s.postHandler(t)
+}
+
func (s *sState) Post(f PostHandler) State {
s.postHandler = f
return s
@@ -130,6 +142,10 @@ type nState struct {
postHandler PostHandler
}
+func (s *nState) PostHandle(t Tree) PostResult {
+ return s.postHandler(t)
+}
+
func (s *nState) Post(f PostHandler) State {
s.postHandler = f
return s
@@ -172,6 +188,10 @@ type eState struct {
postHandler PostHandler
}
+func (s *eState) PostHandle(t Tree) PostResult {
+ return s.postHandler(t)
+}
+
func (s *eState) Post(f PostHandler) State {
s.postHandler = f
return s
View
@@ -94,6 +94,10 @@ type esState struct {
postHandler PostHandler
}
+func (s *esState) PostHandle(t Tree) PostResult {
+ return s.postHandler(t)
+}
+
func (s *esState) Post(f PostHandler) State {
s.postHandler = f
return s
@@ -136,6 +140,10 @@ type rState struct {
postHandler PostHandler
}
+func (s *rState) PostHandle(t Tree) PostResult {
+ return s.postHandler(t)
+}
+
func (s *rState) Post(f PostHandler) State {
s.postHandler = f
return s

0 comments on commit 1daaa0b

Please sign in to comment.