parsejoy

package
v0.0.0-...-64d5393 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LinkTokens

func LinkTokens(token *Token)

func PrintASTNode

func PrintASTNode(node *ASTNode, level int) int

func PrintASTTree

func PrintASTTree(node interface{}, level int) int

func PrintL2ParseTree

func PrintL2ParseTree(token *L2Token, level int) int

func PrintParseTree

func PrintParseTree(token *Token, grammar *set.BitGrammar, level int)

Types

type ASTNode

type ASTNode struct {
	//represents an AST node
	Type       string
	Attributes map[string]interface{}
}

func (*ASTNode) Initialize

func (node *ASTNode) Initialize(nodeType string, properties map[interface{}]interface{})

type ASTProperty

type ASTProperty struct {
	//represents an AST property
	Name  string
	List  bool
	Value interface{}
}

type BaseToken

type BaseToken interface {
	SetNext(token BaseToken)
	GetValue(state State) string
}

type CompilerError

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

func (*CompilerError) Error

func (e *CompilerError) Error() string

type L2Token

type L2Token struct {
	Type     string
	Ignore   bool
	From     *Token
	To       *Token
	Children *L2Token
	Parent   *L2Token
	Next     *L2Token
	Last     *L2Token
	First    *L2Token
}

func (*L2Token) Copy

func (self *L2Token) Copy() *L2Token

func (*L2Token) GetValue

func (self *L2Token) GetValue(state State) (s string)

func (*L2Token) SetNext

func (self *L2Token) SetNext(token BaseToken)

type Outcome

type Outcome struct {
	State       State
	Fingerprint uint
	Token       BaseToken
	Error       error
}

type OutcomeMixin

type OutcomeMixin struct {
	Outcome    [][]Outcome
	OutcomeMap []uint
}

func (*OutcomeMixin) Initialize

func (om *OutcomeMixin) Initialize(N uint, M uint)

type Parser

type Parser func(State) (State, BaseToken, error)

type ParserError

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

func (*ParserError) Error

func (e *ParserError) Error() string

type ParserGenerator

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

func (*ParserGenerator) Compile

func (pg *ParserGenerator) Compile(grammar map[string]interface{}) (Parser, error)

func (*ParserGenerator) GetFingerprint

func (pg *ParserGenerator) GetFingerprint(rule interface{}) string

func (*ParserGenerator) SetPlugin

func (pg *ParserGenerator) SetPlugin(plugin ParserPlugin)

type ParserMap

type ParserMap map[string]Parser

type ParserPlugin

type ParserPlugin interface {
	PrepareGrammar(grammar map[string]interface{})

	SetGenerator(generator *ParserGenerator)
	// contains filtered or unexported methods
}

type ParserPluginMixin

type ParserPluginMixin struct {
	RulePrefixes map[string]interface{}
	// contains filtered or unexported fields
}

func (*ParserPluginMixin) Initialize

func (pg *ParserPluginMixin) Initialize()

func (*ParserPluginMixin) SetGenerator

func (pg *ParserPluginMixin) SetGenerator(generator *ParserGenerator)

type Position

type Position struct {
	Position int
	Column   int
	Row      int
}

type Prefix

type Prefix struct {
	Parent *Prefix
	Value  []byte
	Id     uint
	Next   []*Prefix
}

type PrefixSet

type PrefixSet struct {
	Set *set.BitSet
	Pos int
}

type State

type State interface {
	Copy() State
	//Pushes a new AST node onto the AST stack
	PushASTNode(node *ASTNode, state State) error
	//Pushes an AST property onto the AST stack
	PushASTProperty(property *ASTProperty, state State) error
}

type StringContext

type StringContext struct {
	TokenNumber   uint
	TokenIds      *set.BitGrammar
	TokenId       uint
	Errors        uint
	Calls         uint
	S             []byte
	CurrentRow    int
	LineBreaks    []int
	NumberOfLines int
}

func (*StringContext) Initialize

func (s *StringContext) Initialize(N uint, tokenIds *set.BitGrammar)

type StringParserPlugin

type StringParserPlugin struct {
	ParserPluginMixin
	PrefixGrammar   *set.BitGrammar //contains all possible prefixes
	PrefixList      [][]byte
	PrefixIds       []uint
	TokenIds        *set.BitGrammar
	PrefixTree      *Prefix
	MaxPrefixLength int
}

func (*StringParserPlugin) Initialize

func (pg *StringParserPlugin) Initialize()

func (*StringParserPlugin) PrepareGrammar

func (pg *StringParserPlugin) PrepareGrammar(grammar map[string]interface{})

type StringState

type StringState struct {
	Pos              int
	N                int
	Level            int
	Debug            bool
	CurrentPrefixSet *PrefixSet
	Indents          [][]byte
	Context          *StringContext
}

func (*StringState) Advance

func (s *StringState) Advance(n int) bool

func (*StringState) Copy

func (s *StringState) Copy() State

func (*StringState) CreateToken

func (s *StringState) CreateToken(tokenId uint, from int, to int, ignore bool) (*Token, bool)

func (*StringState) GetPosition

func (s *StringState) GetPosition(position int) Position

func (*StringState) HasPrefix

func (s *StringState) HasPrefix(prefix []byte) bool

func (*StringState) Initialize

func (s *StringState) Initialize(code []byte, tokenIds *set.BitGrammar)

func (*StringState) PushASTNode

func (s *StringState) PushASTNode(node *ASTNode, state State) error

func (*StringState) PushASTProperty

func (s *StringState) PushASTProperty(node *ASTProperty, state State) error

func (*StringState) Value

func (s *StringState) Value() []byte

func (*StringState) ValueN

func (s *StringState) ValueN(n int) []byte

type Token

type Token struct {
	Id       uint
	Number   uint
	Ignore   bool
	From     Position
	To       Position
	Next     *Token
	Last     *Token
	Children *Token
	Parent   *Token
	Outcomes []Outcome
}

func (*Token) GetValue

func (self *Token) GetValue(state State) (s string)

func (*Token) SetNext

func (self *Token) SetNext(token BaseToken)

type TokenContext

type TokenContext struct {
	Errors      uint
	Calls       uint
	StringState *StringState
}

type TokenParserPlugin

type TokenParserPlugin struct {
	ParserPluginMixin
	// contains filtered or unexported fields
}

func (*TokenParserPlugin) Initialize

func (pg *TokenParserPlugin) Initialize(tokenIds *set.BitGrammar)

func (*TokenParserPlugin) PrepareGrammar

func (pg *TokenParserPlugin) PrepareGrammar(grammar map[string]interface{})

type TokenState

type TokenState struct {
	CurrentToken *Token
	Context      *TokenContext
	//The AST stack
	ASTStack []interface{}

	Level int
	Debug bool
}

func (*TokenState) Advance

func (self *TokenState) Advance(token *Token)

func (*TokenState) Copy

func (self *TokenState) Copy() State

func (*TokenState) CreateToken

func (s *TokenState) CreateToken(_type string, from *Token, to *Token) *L2Token

func (*TokenState) Get

func (self *TokenState) Get(tokenId uint, leavesOnly bool) *Token

func (*TokenState) Initialize

func (s *TokenState) Initialize(token *Token, stringState *StringState)

func (*TokenState) PushASTNode

func (s *TokenState) PushASTNode(node *ASTNode, oldState State) error

func (*TokenState) PushASTProperty

func (s *TokenState) PushASTProperty(property *ASTProperty, oldState State) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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