mar

package
v0.0.0-...-5d0d25f Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FormatVersions = []string{"20150701", "20150702"}

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func Format

func Format(name, version string) []byte

Format returns the contents of the named embedded MAR file. If the verison is not specified then latest version is returned. Returns nil if the format does not exist.

func Formats

func Formats() []string

Formats returns a list of available built-in formats. Excludes formats that are only to be spawned by other formats.

func GenerateUUID

func GenerateUUID(data []byte) int

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func ReadFormat

func ReadFormat(name string) ([]byte, error)

ReadFormat returns a built-in format, if it exists, or reads from a file.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func SplitFormat

func SplitFormat(s string) (name, version string)

SplitFormat splits a fully qualified format name into it's name and version parts.

func StripFormatVersion

func StripFormatVersion(format string) string

StripFormatVersion removes any version specified on a format.

func TransitionsDestinations

func TransitionsDestinations(a []*Transition) []string

TransitionsDestinations returns the destination state names from the transitions.

func TransitionsErrorState

func TransitionsErrorState(a []*Transition) string

TransitionsErrorState returns the first error state in a list of transitions.

func Walk

func Walk(v Visitor, node Node)

Walk traverses an AST in depth-first order.

Types

type Action

type Action struct {
	Party     string
	PartyPos  Pos
	Module    string
	ModulePos Pos
	Dot       Pos
	Method    string
	MethodPos Pos
	Lparen    Pos
	Args      []*Arg
	Rparen    Pos
	If        Pos

	RegexMatchIncoming       Pos
	RegexMatchIncomingLparen Pos
	Regex                    string
	RegexPos                 Pos
	RegexMatchIncomingRparen Pos
}

func FilterActionsByParty

func FilterActionsByParty(actions []*Action, party string) []*Action

FilterActionsByParty returns a slice of actions matching party.

func (*Action) ArgValues

func (a *Action) ArgValues() []interface{}

func (*Action) Name

func (a *Action) Name() string

Name returns the concatenation of the module & method.

func (*Action) Transform

func (a *Action) Transform(party string)

Transform converts the action to its complement depending on the party.

type ActionBlock

type ActionBlock struct {
	Action  Pos
	Name    string
	NamePos Pos
	Colon   Pos
	Actions []*Action
}

type Arg

type Arg struct {
	Value  interface{}
	Pos    Pos
	EndPos Pos
}

type Document

type Document struct {
	UUID   int
	Format string

	Connection   Pos
	Lparen       Pos
	Transport    string
	TransportPos Pos
	Comma        Pos
	Port         string
	PortPos      Pos
	Rparen       Pos
	Colon        Pos
	Transitions  []*Transition
	ActionBlocks []*ActionBlock
}

func MustParse

func MustParse(party string, data []byte) *Document

MustParse parses data in to a MAR document. Panic on error.

func Parse

func Parse(party string, data []byte) (*Document, error)

Parse parses data in to a MAR document.

func (*Document) ActionBlock

func (doc *Document) ActionBlock(name string) *ActionBlock

ActionBlock returns an action block by name.

func (*Document) FirstSender

func (doc *Document) FirstSender() string

FirstSender returns the party that initiates the protocol.

func (*Document) HasTransition

func (doc *Document) HasTransition(src, dst string) bool

HasTransition returns true if there is a transition between src and dst.

func (*Document) Normalize

func (doc *Document) Normalize() error

Normalize ensures document conforms to expected state.

type Node

type Node interface {
	// contains filtered or unexported methods
}

Node represents a node within the AST.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser represents a Marionette DSL parser.

The parser will automatically convert certain actions to their complement depending on the party that is parsing the document. No transformation is performed if the party is blank.

func NewParser

func NewParser(party string) *Parser

NewParser returns a new instance of Parser.

func (*Parser) Parse

func (p *Parser) Parse(data []byte) (*Document, error)

Parse parses s into an AST.

type Pos

type Pos struct {
	Char int
	Line int
}

Pos specifies the line and character position of a token. The Char and Line are both zero-based indexes.

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner is a marionette DSL tokenizer.

func NewScanner

func NewScanner(data []byte) *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Peek

func (s *Scanner) Peek() (tok Token, lit string, pos Pos)

Peek returns the next token without moving the scanner forward.

func (*Scanner) PeekIgnoreWhitespace

func (s *Scanner) PeekIgnoreWhitespace() (tok Token, lit string, pos Pos)

PeekIgnoreWhitespace returns the next non-whitespace, non-comment token without moving the scanner forward.

func (*Scanner) Scan

func (s *Scanner) Scan() (tok Token, lit string, pos Pos)

Scan returns the next token from the reader.

func (*Scanner) ScanIgnoreWhitespace

func (s *Scanner) ScanIgnoreWhitespace() (tok Token, lit string, pos Pos)

ScanIgnoreWhitespace returns the next non-whitespace, non-comment token.

type SyntaxError

type SyntaxError struct {
	Message string
	Pos     Pos
}

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

type Token

type Token int

Token represents a lexical token type.

const (
	ILLEGAL Token = iota
	EOF
	COMMENT
	WS

	IDENT   // connection
	NULL    // NULL
	STRING  // "foo"
	INTEGER // 12345
	FLOAT   // 123.45

	LPAREN // (
	RPAREN // )
	DOT    // .
	COMMA  // ,
	COLON  // :
	HASH   // #

	// keywords
	ACTION
	CLIENT
	IF
	END
	REGEX_MATCH_INCOMING
	SERVER
	START
)

func (Token) String

func (tok Token) String() string

type Transition

type Transition struct {
	Source            string
	SourcePos         Pos
	Destination       string
	DestinationPos    Pos
	ActionBlock       string
	ActionBlockPos    Pos
	Probability       float64
	ProbabilityPos    Pos
	IsErrorTransition bool
}

func ChooseTransitions

func ChooseTransitions(a []*Transition, rand *rand.Rand) []*Transition

func FilterErrorTransitions

func FilterErrorTransitions(a []*Transition) []*Transition

func FilterNonErrorTransitions

func FilterNonErrorTransitions(a []*Transition) []*Transition

func FilterProbableTransitions

func FilterProbableTransitions(a []*Transition) []*Transition

func FilterTransitionsByDestination

func FilterTransitionsByDestination(a []*Transition, name string) []*Transition

func FilterTransitionsBySource

func FilterTransitionsBySource(a []*Transition, name string) []*Transition

type Visitor

type Visitor interface {
	Visit(node Node) (w Visitor)
}

Visitor represents an object for iterating over nodes using Walk().

type VisitorFunc

type VisitorFunc func(node Node)

VisitorFunc implements a type to use a function as a Visitor.

func (VisitorFunc) Visit

func (fn VisitorFunc) Visit(node Node) Visitor

Jump to

Keyboard shortcuts

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