parser

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2015 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

A parser for the DOT grammar.

Index

Constants

View Source
const INITIAL_STACK_SIZE = 100

Variables

View Source
var ProductionsTable = ProdTab{

	ProdTabEntry{
		"S! : DotGraph ;",
		"S!",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"DotGraph : Graph { } << ast.NewGraph(ast.GRAPH, ast.FALSE, nil, nil) >> ;",
		"DotGraph",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.GRAPH, ast.FALSE, nil, nil)
		},
	},

	ProdTabEntry{
		"DotGraph : Strict Graph { } << ast.NewGraph(ast.GRAPH, ast.TRUE, nil, nil) >> ;",
		"DotGraph",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.GRAPH, ast.TRUE, nil, nil)
		},
	},

	ProdTabEntry{
		"DotGraph : Graph Id { } << ast.NewGraph(ast.GRAPH, ast.FALSE, X[1], nil) >> ;",
		"DotGraph",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.GRAPH, ast.FALSE, X[1], nil)
		},
	},

	ProdTabEntry{
		"DotGraph : Strict Graph Id { } << ast.NewGraph(ast.GRAPH, ast.TRUE, X[2], nil) >> ;",
		"DotGraph",
		5,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.GRAPH, ast.TRUE, X[2], nil)
		},
	},

	ProdTabEntry{
		"DotGraph : Graph { StmtList } << ast.NewGraph(ast.GRAPH, ast.FALSE, nil, X[2]) >> ;",
		"DotGraph",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.GRAPH, ast.FALSE, nil, X[2])
		},
	},

	ProdTabEntry{
		"DotGraph : Graph Id { StmtList } << ast.NewGraph(ast.GRAPH, ast.FALSE, X[1], X[3]) >> ;",
		"DotGraph",
		5,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.GRAPH, ast.FALSE, X[1], X[3])
		},
	},

	ProdTabEntry{
		"DotGraph : Strict Graph { StmtList } << ast.NewGraph(ast.GRAPH, ast.TRUE, nil, X[3]) >> ;",
		"DotGraph",
		5,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.GRAPH, ast.TRUE, nil, X[3])
		},
	},

	ProdTabEntry{
		"DotGraph : Strict Graph Id { StmtList } << ast.NewGraph(ast.GRAPH, ast.TRUE, X[2], X[4]) >> ;",
		"DotGraph",
		6,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.GRAPH, ast.TRUE, X[2], X[4])
		},
	},

	ProdTabEntry{
		"DotGraph : Digraph { } << ast.NewGraph(ast.DIGRAPH, ast.FALSE, nil, nil) >> ;",
		"DotGraph",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.DIGRAPH, ast.FALSE, nil, nil)
		},
	},

	ProdTabEntry{
		"DotGraph : Strict Digraph { } << ast.NewGraph(ast.DIGRAPH, ast.TRUE, nil, nil) >> ;",
		"DotGraph",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.DIGRAPH, ast.TRUE, nil, nil)
		},
	},

	ProdTabEntry{
		"DotGraph : Digraph Id { } << ast.NewGraph(ast.DIGRAPH, ast.FALSE, X[1], nil) >> ;",
		"DotGraph",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.DIGRAPH, ast.FALSE, X[1], nil)
		},
	},

	ProdTabEntry{
		"DotGraph : Strict Digraph Id { } << ast.NewGraph(ast.DIGRAPH, ast.TRUE, X[2], nil) >> ;",
		"DotGraph",
		5,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.DIGRAPH, ast.TRUE, X[2], nil)
		},
	},

	ProdTabEntry{
		"DotGraph : Digraph { StmtList } << ast.NewGraph(ast.DIGRAPH, ast.FALSE, nil, X[2]) >> ;",
		"DotGraph",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.DIGRAPH, ast.FALSE, nil, X[2])
		},
	},

	ProdTabEntry{
		"DotGraph : Digraph Id { StmtList } << ast.NewGraph(ast.DIGRAPH, ast.FALSE, X[1], X[3]) >> ;",
		"DotGraph",
		5,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.DIGRAPH, ast.FALSE, X[1], X[3])
		},
	},

	ProdTabEntry{
		"DotGraph : Strict Digraph { StmtList } << ast.NewGraph(ast.DIGRAPH, ast.TRUE, nil, X[3]) >> ;",
		"DotGraph",
		5,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.DIGRAPH, ast.TRUE, nil, X[3])
		},
	},

	ProdTabEntry{
		"DotGraph : Strict Digraph Id { StmtList } << ast.NewGraph(ast.DIGRAPH, ast.TRUE, X[2], X[4]) >> ;",
		"DotGraph",
		6,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraph(ast.DIGRAPH, ast.TRUE, X[2], X[4])
		},
	},

	ProdTabEntry{
		"StmtList : Stmt1 << ast.NewStmtList(X[0]) >> ;",
		"StmtList",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewStmtList(X[0])
		},
	},

	ProdTabEntry{
		"StmtList : StmtList Stmt1 << ast.AppendStmtList(X[0], X[1]) >> ;",
		"StmtList",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.AppendStmtList(X[0], X[1])
		},
	},

	ProdTabEntry{
		"Stmt1 : Stmt << X[0], nil >> ;",
		"Stmt1",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Stmt1 : Stmt ; << X[0], nil >> ;",
		"Stmt1",
		2,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Stmt : Id = Id << ast.NewAttr(X[0], X[2]) >> ;",
		"Stmt",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewAttr(X[0], X[2])
		},
	},

	ProdTabEntry{
		"Stmt : NodeStmt << X[0], nil >> ;",
		"Stmt",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Stmt : EdgeStmt << X[0], nil >> ;",
		"Stmt",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Stmt : AttrStmt << X[0], nil >> ;",
		"Stmt",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Stmt : SubGraphStmt << X[0], nil >> ;",
		"Stmt",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"AttrStmt : Graph AttrList << ast.NewGraphAttrs(X[1]) >> ;",
		"AttrStmt",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewGraphAttrs(X[1])
		},
	},

	ProdTabEntry{
		"AttrStmt : Node AttrList << ast.NewNodeAttrs(X[1]) >> ;",
		"AttrStmt",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewNodeAttrs(X[1])
		},
	},

	ProdTabEntry{
		"AttrStmt : Edge AttrList << ast.NewEdgeAttrs(X[1]) >> ;",
		"AttrStmt",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewEdgeAttrs(X[1])
		},
	},

	ProdTabEntry{
		"AttrList : [ ] << ast.NewAttrList(nil) >> ;",
		"AttrList",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewAttrList(nil)
		},
	},

	ProdTabEntry{
		"AttrList : [ AList ] << ast.NewAttrList(X[1]) >> ;",
		"AttrList",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewAttrList(X[1])
		},
	},

	ProdTabEntry{
		"AttrList : AttrList [ ] << ast.AppendAttrList(X[0], nil) >> ;",
		"AttrList",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.AppendAttrList(X[0], nil)
		},
	},

	ProdTabEntry{
		"AttrList : AttrList [ AList ] << ast.AppendAttrList(X[0], X[2]) >> ;",
		"AttrList",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.AppendAttrList(X[0], X[2])
		},
	},

	ProdTabEntry{
		"AList : Attr << ast.NewAList(X[0]) >> ;",
		"AList",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewAList(X[0])
		},
	},

	ProdTabEntry{
		"AList : AList Attr << ast.AppendAList(X[0], X[1]) >> ;",
		"AList",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.AppendAList(X[0], X[1])
		},
	},

	ProdTabEntry{
		"AList : AList , Attr << ast.AppendAList(X[0], X[2]) >> ;",
		"AList",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.AppendAList(X[0], X[2])
		},
	},

	ProdTabEntry{
		"Attr : Id << ast.NewAttr(X[0], nil) >> ;",
		"Attr",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewAttr(X[0], nil)
		},
	},

	ProdTabEntry{
		"Attr : Id = Id << ast.NewAttr(X[0], X[2]) >> ;",
		"Attr",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewAttr(X[0], X[2])
		},
	},

	ProdTabEntry{
		"EdgeStmt : NodeId EdgeRHS << ast.NewEdgeStmt(X[0], X[1], nil) >> ;",
		"EdgeStmt",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewEdgeStmt(X[0], X[1], nil)
		},
	},

	ProdTabEntry{
		"EdgeStmt : NodeId EdgeRHS AttrList << ast.NewEdgeStmt(X[0], X[1], X[2]) >> ;",
		"EdgeStmt",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewEdgeStmt(X[0], X[1], X[2])
		},
	},

	ProdTabEntry{
		"EdgeStmt : SubGraphStmt EdgeRHS << ast.NewEdgeStmt(X[0], X[1], nil) >> ;",
		"EdgeStmt",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewEdgeStmt(X[0], X[1], nil)
		},
	},

	ProdTabEntry{
		"EdgeStmt : SubGraphStmt EdgeRHS AttrList << ast.NewEdgeStmt(X[0], X[1], X[2]) >> ;",
		"EdgeStmt",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewEdgeStmt(X[0], X[1], X[2])
		},
	},

	ProdTabEntry{
		"EdgeRHS : EdgeOp NodeId << ast.NewEdgeRHS(X[0], X[1]) >> ;",
		"EdgeRHS",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewEdgeRHS(X[0], X[1])
		},
	},

	ProdTabEntry{
		"EdgeRHS : EdgeOp SubGraphStmt << ast.NewEdgeRHS(X[0], X[1]) >> ;",
		"EdgeRHS",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewEdgeRHS(X[0], X[1])
		},
	},

	ProdTabEntry{
		"EdgeRHS : EdgeRHS EdgeOp NodeId << ast.AppendEdgeRHS(X[0], X[1], X[2]) >> ;",
		"EdgeRHS",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.AppendEdgeRHS(X[0], X[1], X[2])
		},
	},

	ProdTabEntry{
		"EdgeRHS : EdgeRHS EdgeOp SubGraphStmt << ast.AppendEdgeRHS(X[0], X[1], X[2]) >> ;",
		"EdgeRHS",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.AppendEdgeRHS(X[0], X[1], X[2])
		},
	},

	ProdTabEntry{
		"NodeStmt : NodeId << ast.NewNodeStmt(X[0], nil) >> ;",
		"NodeStmt",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewNodeStmt(X[0], nil)
		},
	},

	ProdTabEntry{
		"NodeStmt : NodeId AttrList << ast.NewNodeStmt(X[0], X[1]) >> ;",
		"NodeStmt",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewNodeStmt(X[0], X[1])
		},
	},

	ProdTabEntry{
		"NodeId : Id << ast.NewNodeId(X[0], nil) >> ;",
		"NodeId",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewNodeId(X[0], nil)
		},
	},

	ProdTabEntry{
		"NodeId : Id Port << ast.NewNodeId(X[0], X[1]) >> ;",
		"NodeId",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewNodeId(X[0], X[1])
		},
	},

	ProdTabEntry{
		"Port : : Id << ast.NewPort(X[1], nil) >> ;",
		"Port",
		2,
		func(X []Attrib) (Attrib, error) {
			return ast.NewPort(X[1], nil)
		},
	},

	ProdTabEntry{
		"Port : : Id : Id << ast.NewPort(X[1], X[3]) >> ;",
		"Port",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewPort(X[1], X[3])
		},
	},

	ProdTabEntry{
		"SubGraphStmt : { StmtList } << ast.NewSubGraph(nil, X[1]) >> ;",
		"SubGraphStmt",
		3,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSubGraph(nil, X[1])
		},
	},

	ProdTabEntry{
		"SubGraphStmt : Subgraph { StmtList } << ast.NewSubGraph(nil, X[2]) >> ;",
		"SubGraphStmt",
		4,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSubGraph(nil, X[2])
		},
	},

	ProdTabEntry{
		"SubGraphStmt : Subgraph Id { StmtList } << ast.NewSubGraph(X[1], X[3]) >> ;",
		"SubGraphStmt",
		5,
		func(X []Attrib) (Attrib, error) {
			return ast.NewSubGraph(X[1], X[3])
		},
	},

	ProdTabEntry{
		"EdgeOp : -> << ast.DIRECTED, nil >> ;",
		"EdgeOp",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.DIRECTED, nil
		},
	},

	ProdTabEntry{
		"EdgeOp : -- << ast.UNDIRECTED, nil >> ;",
		"EdgeOp",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.UNDIRECTED, nil
		},
	},

	ProdTabEntry{
		"Graph : graph << X[0], nil >> ;",
		"Graph",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Graph : Graph << X[0], nil >> ;",
		"Graph",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Graph : GRAPH << X[0], nil >> ;",
		"Graph",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Strict : strict << X[0], nil >> ;",
		"Strict",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Strict : Strict << X[0], nil >> ;",
		"Strict",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Strict : STRICT << X[0], nil >> ;",
		"Strict",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Digraph : digraph << X[0], nil >> ;",
		"Digraph",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Digraph : Digraph << X[0], nil >> ;",
		"Digraph",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Digraph : DiGraph << X[0], nil >> ;",
		"Digraph",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Digraph : DIGRAPH << X[0], nil >> ;",
		"Digraph",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Node : node << X[0], nil >> ;",
		"Node",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Node : Node << X[0], nil >> ;",
		"Node",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Node : NODE << X[0], nil >> ;",
		"Node",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Edge : edge << X[0], nil >> ;",
		"Edge",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Edge : Edge << X[0], nil >> ;",
		"Edge",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Edge : EDGE << X[0], nil >> ;",
		"Edge",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Subgraph : subgraph << X[0], nil >> ;",
		"Subgraph",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Subgraph : Subgraph << X[0], nil >> ;",
		"Subgraph",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Subgraph : SubGraph << X[0], nil >> ;",
		"Subgraph",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Subgraph : SUBGRAPH << X[0], nil >> ;",
		"Subgraph",
		1,
		func(X []Attrib) (Attrib, error) {
			return X[0], nil
		},
	},

	ProdTabEntry{
		"Id : id << ast.NewId(X[0]) >> ;",
		"Id",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewId(X[0])
		},
	},

	ProdTabEntry{
		"Id : string_lit << ast.NewId(X[0]) >> ;",
		"Id",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewId(X[0])
		},
	},

	ProdTabEntry{
		"Id : int_lit << ast.NewId(X[0]) >> ;",
		"Id",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewId(X[0])
		},
	},

	ProdTabEntry{
		"Id : float_lit << ast.NewId(X[0]) >> ;",
		"Id",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewId(X[0])
		},
	},

	ProdTabEntry{
		"Id : html_lit << ast.NewId(X[0]) >> ;",
		"Id",
		1,
		func(X []Attrib) (Attrib, error) {
			return ast.NewId(X[0])
		},
	},
}

Functions

func NewStack

func NewStack() *stack

func Parse

func Parse(r io.Reader) (*ast.Graph, error)

Parses a reader which contains a DOT string and outputs the abstract syntax tree representing the graph.

func ParseBytes

func ParseBytes(dotBytes []byte) (*ast.Graph, error)

Parses the bytes representing a DOT string and outputs the abstract syntax tree representing the graph.

func ParseFile

func ParseFile(filename string) (*ast.Graph, error)

Parses a file which contains a DOT string and outputs the abstract syntax tree representing the graph.

func ParseString

func ParseString(dotString string) (*ast.Graph, error)

Parses a DOT string and outputs the abstract syntax tree representing the graph.

Types

type Accept

type Accept int

func (Accept) Act

func (this Accept) Act()

func (Accept) String

func (this Accept) String() string

type Action

type Action interface {
	Act()
	String() string
}

type ActionRow

type ActionRow map[token.Type]Action

func (ActionRow) String

func (R ActionRow) String() string

type ActionTab

type ActionTab []ActionRow
var ActionTable ActionTab = ActionTab{}/* 175 elements not displayed */

type Attrib

type Attrib interface {
	String() string
}

type GotoRow

type GotoRow map[NT]State

type GotoTab

type GotoTab []GotoRow
var GotoTable GotoTab = GotoTab{}/* 175 elements not displayed */

type NT

type NT string

type Parser

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

func NewParser

func NewParser(act ActionTab, gto GotoTab, prod ProdTab, tm *token.TokenMap) *Parser

func (*Parser) Error

func (P *Parser) Error(err error) error

func (*Parser) Parse

func (this *Parser) Parse(scanner Scanner) (res interface{}, err error)

func (*Parser) TokString

func (P *Parser) TokString(tok *token.Token) string

type ProdTab

type ProdTab []ProdTabEntry

type ProdTabEntry

type ProdTabEntry struct {
	String     string
	Head       NT
	NumSymbols int
	ReduceFunc func([]Attrib) (Attrib, error)
}

type Reduce

type Reduce int

func (Reduce) Act

func (this Reduce) Act()

func (Reduce) String

func (this Reduce) String() string

type Scanner

type Scanner interface {
	Scan() (*token.Token, token.Position)
}

type Shift

type Shift State

func (Shift) Act

func (this Shift) Act()

func (Shift) String

func (this Shift) String() string

type State

type State int

Jump to

Keyboard shortcuts

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