c_comment

package
v0.0.0-...-b8628b5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2015 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
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.

View Source
const (
	HSMTypeCComment = hsm.HSMTypeStd + 1 + iota
)

Variables

This section is empty.

Functions

func Logln

func Logln(v ...interface{})

func MapOnList

func MapOnList(
	f func(value interface{}) interface{},
	lst *list.List) *list.List

Call func f on every element of list lst. Like a map() style function on lisp, func f must get the type of element right. To achieve generalization, interface{}(void pointer) is used in Golang.

Types

type CCommentCharEvent

type CCommentCharEvent struct {
	*hsm.StdEvent
	// contains filtered or unexported fields
}

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

type CCommentEvent interface {
	hsm.Event
	Char() byte
}

CCommentEvent is the general event we use in this example to drive out state machine.

type CCommentHSM

type CCommentHSM struct {
	*hsm.StdHSM
	// contains filtered or unexported fields
}

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) Init

func (self *CCommentHSM) Init()

Init() 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

type CCommentSlashEvent struct {
	*hsm.StdEvent
}

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

type CCommentStarEvent struct {
	*hsm.StdEvent
}

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 NewCodeState(super hsm.State) *CodeState

func (*CodeState) Entry

func (self *CodeState) Entry(sm hsm.HSM, event hsm.Event) hsm.State

Entry() is part of the interface State. It would be called on state entry.

func (*CodeState) Exit

func (self *CodeState) Exit(sm hsm.HSM, event hsm.Event) hsm.State

Exit() is part of the interface State. It would be called on state exit.

func (*CodeState) Handle

func (self *CodeState) Handle(sm hsm.HSM, event hsm.Event) hsm.State

Handle() is part of the interface State. It would be called with input events. Please refer to the state chart for all state transfers and actions round them.

func (*CodeState) ID

func (_ *CodeState) ID() string

ID() is part of the interface State.

func (*CodeState) Init

func (self *CodeState) Init(sm hsm.HSM, event hsm.Event) hsm.State

Init() is part of the interface State. It would be called on state initialization.

type CommentState

type CommentState struct {
	*hsm.StateHead
}

CommentState represents the comment state in state chart.

func NewCommentState

func NewCommentState(super hsm.State) *CommentState

func (*CommentState) Entry

func (self *CommentState) Entry(sm hsm.HSM, event hsm.Event) hsm.State

func (*CommentState) Exit

func (self *CommentState) Exit(sm hsm.HSM, event hsm.Event) hsm.State

func (*CommentState) Handle

func (self *CommentState) Handle(sm hsm.HSM, event hsm.Event) hsm.State

func (*CommentState) ID

func (self *CommentState) ID() string

type SlashState

type SlashState struct {
	*hsm.StateHead
}

SlashState represents the slash state in state chart.

func NewSlashState

func NewSlashState(super hsm.State) *SlashState

func (*SlashState) Entry

func (self *SlashState) Entry(sm hsm.HSM, event hsm.Event) hsm.State

func (*SlashState) Exit

func (self *SlashState) Exit(sm hsm.HSM, event hsm.Event) hsm.State

func (*SlashState) Handle

func (self *SlashState) Handle(sm hsm.HSM, event hsm.Event) hsm.State

func (*SlashState) ID

func (self *SlashState) ID() string

type StarState

type StarState struct {
	*hsm.StateHead
}

StarState represents the star state in state chart.

func NewStarState

func NewStarState(super hsm.State) *StarState

func (*StarState) Entry

func (self *StarState) Entry(sm hsm.HSM, event hsm.Event) hsm.State

func (*StarState) Exit

func (self *StarState) Exit(sm hsm.HSM, event hsm.Event) hsm.State

func (*StarState) Handle

func (self *StarState) Handle(sm hsm.HSM, event hsm.Event) hsm.State

func (*StarState) ID

func (self *StarState) ID() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL