ast

package
v0.0.0-...-2292f9e Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

This package contains the Abstract Syntax Tree (AST) elements used by gocc to generate a target lexer and parser.

The top-level node is Grammar in grammar.go

The EBNF accepted by gocc consists of two parts:

1. The lexical part, containing the definition of tokens.

2. The grammar or syntax part, containing the grammar or syntax of the language. Files containing grammar objects are prefixed with "g", e.g.: galts.go

Index

Constants

This section is empty.

Variables

View Source
var LexDOT = &LexDot{}

Functions

This section is empty.

Types

type FileHeader

type FileHeader struct {
	SDTLit string
	// contains filtered or unexported fields
}

func NewFileHeader

func NewFileHeader(sdtLit interface{}) (*FileHeader, error)

func (*FileHeader) String

func (this *FileHeader) String() string

type Grammar

type Grammar struct {
	*LexPart
	*SyntaxPart
}

func NewGrammar

func NewGrammar(lexPart, syntaxPart interface{}) (*Grammar, error)

type LexAlt

type LexAlt struct {
	Terms []LexTerm
}

func AppendLexTerm

func AppendLexTerm(lexAlt, lexTerm interface{}) (*LexAlt, error)

func NewLexAlt

func NewLexAlt(lexTerm interface{}) (*LexAlt, error)

func (*LexAlt) Contain

func (this *LexAlt) Contain(term LexTerm) bool

func (*LexAlt) Element

func (this *LexAlt) Element(i int) LexNode

func (*LexAlt) Len

func (this *LexAlt) Len() int

func (LexAlt) LexTerminal

func (LexAlt) LexTerminal() bool

func (*LexAlt) String

func (this *LexAlt) String() string

func (*LexAlt) Walk

func (this *LexAlt) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexCharLit

type LexCharLit struct {
	Val rune
	Lit []byte
	// contains filtered or unexported fields
}

func NewLexCharLit

func NewLexCharLit(tok interface{}) (*LexCharLit, error)

func (*LexCharLit) IsTerminal

func (this *LexCharLit) IsTerminal() bool

func (*LexCharLit) LexTerminal

func (*LexCharLit) LexTerminal() bool

func (*LexCharLit) String

func (this *LexCharLit) String() string

func (*LexCharLit) Walk

func (this *LexCharLit) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexCharRange

type LexCharRange struct {
	From *LexCharLit
	To   *LexCharLit
	// contains filtered or unexported fields
}

func NewLexCharRange

func NewLexCharRange(from, to interface{}) (*LexCharRange, error)

func (*LexCharRange) IsTerminal

func (this *LexCharRange) IsTerminal() bool

func (*LexCharRange) LexTerminal

func (*LexCharRange) LexTerminal() bool

func (*LexCharRange) String

func (this *LexCharRange) String() string

func (*LexCharRange) Walk

func (this *LexCharRange) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexDot

type LexDot struct{}

func (*LexDot) IsTerminal

func (this *LexDot) IsTerminal() bool

func (LexDot) LexTerminal

func (LexDot) LexTerminal() bool

func (*LexDot) String

func (this *LexDot) String() string

func (*LexDot) Walk

func (this *LexDot) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexGroupPattern

type LexGroupPattern struct {
	*LexPattern
}

func NewLexGroupPattern

func NewLexGroupPattern(pattern interface{}) (*LexGroupPattern, error)

func (*LexGroupPattern) Element

func (this *LexGroupPattern) Element(i int) LexNode

func (*LexGroupPattern) IsTerminal

func (this *LexGroupPattern) IsTerminal() bool

func (*LexGroupPattern) Len

func (this *LexGroupPattern) Len() int

func (LexGroupPattern) LexTerminal

func (LexGroupPattern) LexTerminal() bool

func (*LexGroupPattern) String

func (this *LexGroupPattern) String() string

func (*LexGroupPattern) Walk

func (this *LexGroupPattern) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexIgnoredTokDef

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

func NewLexIgnoredTokDef

func NewLexIgnoredTokDef(tokId, lexPattern interface{}) (*LexIgnoredTokDef, error)

func (*LexIgnoredTokDef) Id

func (this *LexIgnoredTokDef) Id() string

func (*LexIgnoredTokDef) LexPattern

func (this *LexIgnoredTokDef) LexPattern() *LexPattern

func (*LexIgnoredTokDef) LexTerminal

func (*LexIgnoredTokDef) LexTerminal() bool

func (*LexIgnoredTokDef) RegDef

func (*LexIgnoredTokDef) RegDef() bool

func (*LexIgnoredTokDef) String

func (this *LexIgnoredTokDef) String() string

func (*LexIgnoredTokDef) Walk

func (this *LexIgnoredTokDef) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexImport

type LexImport struct {
	Id      string
	ExtFunc string
}

func NewLexImport

func NewLexImport(regDefId, extFunc interface{}) (*LexImport, error)

func (*LexImport) IsTerminal

func (this *LexImport) IsTerminal() bool

func (*LexImport) String

func (this *LexImport) String() string

type LexImports

type LexImports struct {
	Imports map[string]*LexImport
}

func AddLexImport

func AddLexImport(imports, lexImport interface{}) (*LexImports, error)

func NewLexImports

func NewLexImports(lexImport interface{}) (*LexImports, error)

func (*LexImports) Add

func (this *LexImports) Add(lexImport *LexImport) (*LexImports, error)

Add will return true if a new lex import has been added, otherwise false.

func (LexImports) LexTerminal

func (LexImports) LexTerminal() bool

func (*LexImports) String

func (this *LexImports) String() string

func (*LexImports) Walk

func (this *LexImports) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexNTNode

type LexNTNode interface {
	LexNode
	Element(int) LexNode
	Len() int
	Walk(LexNodeVisitor) LexNodeVisitor
}

type LexNode

type LexNode interface {
	LexTerminal() bool
	String() string
}

type LexNodeVisitor

type LexNodeVisitor interface {
	Visit(LexNode) LexNodeVisitor
}

type LexOptPattern

type LexOptPattern struct {
	*LexPattern
}

func NewLexOptPattern

func NewLexOptPattern(pattern interface{}) (*LexOptPattern, error)

func (*LexOptPattern) Element

func (this *LexOptPattern) Element(i int) LexNode

func (*LexOptPattern) IsTerminal

func (this *LexOptPattern) IsTerminal() bool

func (*LexOptPattern) Len

func (this *LexOptPattern) Len() int

func (LexOptPattern) LexTerminal

func (LexOptPattern) LexTerminal() bool

func (*LexOptPattern) String

func (this *LexOptPattern) String() string

func (*LexOptPattern) Walk

func (this *LexOptPattern) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexPart

type LexPart struct {
	Header *FileHeader
	*LexImports
	TokDefsList []*LexTokDef
	TokDefs     map[string]*LexTokDef

	RegDefsList        []*LexRegDef
	RegDefs            map[string]*LexRegDef
	IgnoredTokDefsList []*LexIgnoredTokDef
	IgnoredTokDefs     map[string]*LexIgnoredTokDef
	ProdList           *LexProductions
	ProdMap            *LexProdMap
	// contains filtered or unexported fields
}

All maps are indexed by production id

func NewLexPart

func NewLexPart(header, imports, prodList interface{}) (*LexPart, error)

func (*LexPart) ProdIndex

func (this *LexPart) ProdIndex(id string) LexProdIndex

func (*LexPart) Production

func (this *LexPart) Production(id string) LexProduction

func (*LexPart) String

func (this *LexPart) String() string

func (*LexPart) StringLitTokDef

func (this *LexPart) StringLitTokDef(id string) *LexTokDef

func (*LexPart) TokenIds

func (this *LexPart) TokenIds() []string

func (*LexPart) UpdateStringLitTokens

func (this *LexPart) UpdateStringLitTokens(tokens []string)

type LexPattern

type LexPattern struct {
	Alternatives []*LexAlt
}

func AppendLexAlt

func AppendLexAlt(lexPattern, lexAlt interface{}) (*LexPattern, error)

func NewLexPattern

func NewLexPattern(lexAlt interface{}) (*LexPattern, error)

func (*LexPattern) Element

func (this *LexPattern) Element(i int) LexNode

func (*LexPattern) Len

func (this *LexPattern) Len() int

func (LexPattern) LexTerminal

func (LexPattern) LexTerminal() bool

func (*LexPattern) String

func (this *LexPattern) String() string

func (*LexPattern) Walk

func (this *LexPattern) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexProdIndex

type LexProdIndex int

type LexProdMap

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

func NewLexProdMap

func NewLexProdMap(prodList *LexProductions) *LexProdMap

func (*LexProdMap) Add

func (this *LexProdMap) Add(prods ...LexProduction)

func (*LexProdMap) Id

func (this *LexProdMap) Id(index LexProdIndex) string

func (*LexProdMap) Index

func (this *LexProdMap) Index(id string) LexProdIndex

type LexProduction

type LexProduction interface {
	LexNode
	Id() string
	LexPattern() *LexPattern
	RegDef() bool
}

type LexProductions

type LexProductions struct {
	Productions []LexProduction
}

func AppendLexProduction

func AppendLexProduction(lexProds, prod interface{}) (*LexProductions, error)

func NewLexProductions

func NewLexProductions(lexProd interface{}) (*LexProductions, error)

func (LexProductions) LexTerminal

func (LexProductions) LexTerminal() bool

func (*LexProductions) String

func (this *LexProductions) String() string

func (*LexProductions) Walk

func (this *LexProductions) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexRegDef

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

func NewLexRegDef

func NewLexRegDef(regDefId, lexPattern interface{}) (*LexRegDef, error)

func (*LexRegDef) Id

func (this *LexRegDef) Id() string

func (*LexRegDef) LexPattern

func (this *LexRegDef) LexPattern() *LexPattern

func (*LexRegDef) LexTerminal

func (*LexRegDef) LexTerminal() bool

func (*LexRegDef) RegDef

func (*LexRegDef) RegDef() bool

func (*LexRegDef) String

func (this *LexRegDef) String() string

func (*LexRegDef) Walk

func (this *LexRegDef) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexRegDefId

type LexRegDefId struct {
	Id string
}

func NewLexRegDefId

func NewLexRegDefId(regDefId interface{}) (*LexRegDefId, error)

func (*LexRegDefId) IsTerminal

func (this *LexRegDefId) IsTerminal() bool

func (LexRegDefId) LexTerminal

func (LexRegDefId) LexTerminal() bool

func (*LexRegDefId) String

func (this *LexRegDefId) String() string

func (*LexRegDefId) Walk

func (this *LexRegDefId) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexRepPattern

type LexRepPattern struct {
	*LexPattern
}

func NewLexRepPattern

func NewLexRepPattern(pattern interface{}) (*LexRepPattern, error)

func (*LexRepPattern) Element

func (this *LexRepPattern) Element(i int) LexNode

func (*LexRepPattern) IsTerminal

func (this *LexRepPattern) IsTerminal() bool

func (*LexRepPattern) Len

func (this *LexRepPattern) Len() int

func (LexRepPattern) LexTerminal

func (LexRepPattern) LexTerminal() bool

func (*LexRepPattern) String

func (this *LexRepPattern) String() string

func (*LexRepPattern) Walk

func (this *LexRepPattern) Walk(visitor LexNodeVisitor) LexNodeVisitor

type LexTNode

type LexTNode interface {
	LexNode
	// contains filtered or unexported methods
}

type LexTerm

type LexTerm interface {
	LexNode
	// contains filtered or unexported methods
}

type LexTokDef

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

func NewLexStringLitTokDef

func NewLexStringLitTokDef(tokId string) *LexTokDef

func NewLexTokDef

func NewLexTokDef(tokId, lexPattern interface{}) (*LexTokDef, error)

func (*LexTokDef) Id

func (this *LexTokDef) Id() string

func (*LexTokDef) LexPattern

func (this *LexTokDef) LexPattern() *LexPattern

func (*LexTokDef) LexTerminal

func (*LexTokDef) LexTerminal() bool

func (*LexTokDef) RegDef

func (*LexTokDef) RegDef() bool

func (*LexTokDef) String

func (this *LexTokDef) String() string

func (*LexTokDef) Walk

func (this *LexTokDef) Walk(visitor LexNodeVisitor) LexNodeVisitor

type SyntaxAlts

type SyntaxAlts []*SyntaxBody

func AddSyntaxAlt

func AddSyntaxAlt(alts, body interface{}) (SyntaxAlts, error)

func NewSyntaxAlts

func NewSyntaxAlts(body interface{}) (SyntaxAlts, error)

type SyntaxBody

type SyntaxBody struct {
	Error   bool
	Symbols SyntaxSymbols
	SDT     string
}

func NewEmptyBody

func NewEmptyBody() (*SyntaxBody, error)

func NewErrorBody

func NewErrorBody(symbols, sdtLit interface{}) (*SyntaxBody, error)

func NewSyntaxBody

func NewSyntaxBody(symbols, sdtLit interface{}) (*SyntaxBody, error)

func (*SyntaxBody) Empty

func (this *SyntaxBody) Empty() bool

func (*SyntaxBody) String

func (this *SyntaxBody) String() string

type SyntaxEmpty

type SyntaxEmpty int
const EMPTY SyntaxEmpty = 0

func (SyntaxEmpty) String

func (SyntaxEmpty) String() string

func (SyntaxEmpty) SymbolString

func (SyntaxEmpty) SymbolString() string

type SyntaxEof

type SyntaxEof int
var EOF SyntaxEof = 0

func (SyntaxEof) String

func (SyntaxEof) String() string

func (SyntaxEof) SymbolsString

func (SyntaxEof) SymbolsString() string

type SyntaxError

type SyntaxError int

func (SyntaxError) String

func (SyntaxError) String() string

func (SyntaxError) SymbolString

func (SyntaxError) SymbolString() string

type SyntaxPart

type SyntaxPart struct {
	Header   *FileHeader
	ProdList SyntaxProdList
}

func NewSyntaxPart

func NewSyntaxPart(header, prodList interface{}) (*SyntaxPart, error)

type SyntaxProd

type SyntaxProd struct {
	Id   string
	Body *SyntaxBody
}

func NewSyntaxProd

func NewSyntaxProd(prodId, alts interface{}) ([]*SyntaxProd, error)

func (*SyntaxProd) String

func (this *SyntaxProd) String() string

type SyntaxProdId

type SyntaxProdId string

Id or name of a grammar(syntax) production

func NewSyntaxProdId

func NewSyntaxProdId(tok interface{}) (SyntaxProdId, error)

func (SyntaxProdId) String

func (this SyntaxProdId) String() string

func (SyntaxProdId) SymbolString

func (this SyntaxProdId) SymbolString() string

type SyntaxProdList

type SyntaxProdList []*SyntaxProd

func AddSyntaxProds

func AddSyntaxProds(prodList, prods interface{}) (SyntaxProdList, error)

func NewSyntaxProdList

func NewSyntaxProdList(prods interface{}) (SyntaxProdList, error)

type SyntaxStringLit

type SyntaxStringLit string

func NewStringLit

func NewStringLit(tok interface{}) (SyntaxStringLit, error)

func (SyntaxStringLit) Bytes

func (this SyntaxStringLit) Bytes() []byte

func (SyntaxStringLit) String

func (this SyntaxStringLit) String() string

func (SyntaxStringLit) SymbolString

func (this SyntaxStringLit) SymbolString() string

type SyntaxSymbol

type SyntaxSymbol interface {
	SymbolString() string
	String() string
	// contains filtered or unexported methods
}

All syntax symbols are types of string.

type SyntaxSymbols

type SyntaxSymbols []SyntaxSymbol

func AddSyntaxSymbol

func AddSyntaxSymbol(symbols, symbol interface{}) (SyntaxSymbols, error)

func NewSyntaxSymbols

func NewSyntaxSymbols(sym interface{}) (SyntaxSymbols, error)

func (SyntaxSymbols) String

func (this SyntaxSymbols) String() string

type SyntaxTokId

type SyntaxTokId string

func NewTokId

func NewTokId(tokId interface{}) (SyntaxTokId, error)

func (SyntaxTokId) String

func (this SyntaxTokId) String() string

func (SyntaxTokId) SymbolString

func (this SyntaxTokId) SymbolString() string

Jump to

Keyboard shortcuts

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