Documentation ¶
Index ¶
- Constants
- func Logln(v ...interface{})
- func MapOnList(f func(value interface{}) interface{}, lst *list.List) *list.List
- type CCommentCharEvent
- type CCommentEvent
- type CCommentHSM
- func (self *CCommentHSM) CurrentStateID() string
- func (self *CCommentHSM) Dispatch(event hsm.Event)
- func (self *CCommentHSM) Init()
- func (self *CCommentHSM) ProcessCodeChar(c byte)
- func (self *CCommentHSM) QTran(targetStateID string)
- func (self *CCommentHSM) QTranOnEvent(targetStateID string, event hsm.Event)
- func (self *CCommentHSM) TraverseCode(f func(value interface{}) interface{})
- type CCommentSlashEvent
- type CCommentStarEvent
- type CodeState
- func (self *CodeState) Entry(sm hsm.HSM, event hsm.Event) hsm.State
- func (self *CodeState) Exit(sm hsm.HSM, event hsm.Event) hsm.State
- func (self *CodeState) Handle(sm hsm.HSM, event hsm.Event) hsm.State
- func (_ *CodeState) ID() string
- func (self *CodeState) Init(sm hsm.HSM, event hsm.Event) hsm.State
- type CommentState
- type SlashState
- type StarState
Constants ¶
const ( // EventSlash represents a slash character as input EventSlash hsm.EventType = hsm.EventUser + iota // EventStar represents a star character is meet EventStar // EventChar represents a character which is neither a slash nor a star EventChar )
According to the state chart, there are three types of different events representing the input of our state machine.
const ( StateCodeID = "code" StateSlashID = "slash" StateStarID = "star" StateCommentID = "comment" )
Four states are defined according to the state chart. Define their IDs first since go-hsm use ID(of type string in Golang) as the target of state transfer.
const (
HSMTypeCComment = hsm.HSMTypeStd + 1 + iota
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CCommentCharEvent ¶
CCommentCharEvent wraps everything for a event of EventChar type. For the simplicity of this example, it contains only a single character.
func NewCCommentCharEvent ¶
func NewCCommentCharEvent(c byte) *CCommentCharEvent
func (*CCommentCharEvent) Char ¶
func (self *CCommentCharEvent) Char() byte
Char() is part of CCommentEvent interface.
type CCommentEvent ¶
CCommentEvent is the general event we use in this example to drive out state machine.
type CCommentHSM ¶
CCommentHSM represent the Hierarchical State Machine for C Comment Parsing. This example demonstrate how to parse C code, recording the code chars and ignore those chars in /* */ comments, working the similar way as a C code Parser reads in the source code and does token scanning.
func NewCCommentHSM ¶
func NewCCommentHSM(top, initial hsm.State) *CCommentHSM
func NewWorld ¶
func NewWorld() *CCommentHSM
NewWorld() setup HSM and all states for this C Comment Parsing example.
func (*CCommentHSM) CurrentStateID ¶
func (self *CCommentHSM) CurrentStateID() string
CurrentStateID() is a abstract leaking method to get current state. Just for example demonstration.
func (*CCommentHSM) Dispatch ¶
func (self *CCommentHSM) Dispatch(event hsm.Event)
Dispatch() is part of HSM interface.
func (*CCommentHSM) ProcessCodeChar ¶
func (self *CCommentHSM) ProcessCodeChar(c byte)
ProcessCodeChar() is to record all chars of the code.
func (*CCommentHSM) QTran ¶
func (self *CCommentHSM) QTran(targetStateID string)
func (*CCommentHSM) QTranOnEvent ¶
func (self *CCommentHSM) QTranOnEvent(targetStateID string, event hsm.Event)
func (*CCommentHSM) TraverseCode ¶
func (self *CCommentHSM) TraverseCode(f func(value interface{}) interface{})
TraverseCode() is the interface of traversing all chars of the code.
type CCommentSlashEvent ¶
CCommentSlashEvent wraps everything for a event of EventSlash type. For the simplicity of this example, it is left empty. An event struct may contain any datas and methods needed in real project.
func NewCCommentSlashEvent ¶
func NewCCommentSlashEvent() *CCommentSlashEvent
func (*CCommentSlashEvent) Char ¶
func (_ *CCommentSlashEvent) Char() byte
Char() is part of CCommentEvent interface.
type CCommentStarEvent ¶
CCommentStarEvent wraps everything for a event of EventStar type. For the simplicity of this example, it is left empty.
func NewCCommentStarEvent ¶
func NewCCommentStarEvent() *CCommentStarEvent
func (*CCommentStarEvent) Char ¶
func (_ *CCommentStarEvent) Char() byte
Char() is part of CCommentEvent interface.
type CodeState ¶
type CodeState struct { // the embedded StateHead implements most methods of the interface State( // without the method ID and Handle). // We use a feature in Golang called 'anonymous field' to achieve the // goal of providing interfaces and implementations heritance, just like // heritance from non-pure abstract class in C++ or // heritance from abstract parent class(not interface) in Java. *hsm.StateHead // contains filtered or unexported fields }
CodeState represent the code state in state chart.
func NewCodeState ¶
func (*CodeState) Entry ¶
Entry() is part of the interface State. It would be called on state entry.
type CommentState ¶
CommentState represents the comment state in state chart.
func NewCommentState ¶
func NewCommentState(super hsm.State) *CommentState
func (*CommentState) ID ¶
func (self *CommentState) ID() string
type SlashState ¶
SlashState represents the slash state in state chart.
func NewSlashState ¶
func NewSlashState(super hsm.State) *SlashState
func (*SlashState) ID ¶
func (self *SlashState) ID() string