pegn

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: MPL-2.0 Imports: 17 Imported by: 0

README

PEGN Parser Generator

At this stage of the project, my goal is NOT to provide readable code with a good interface. This is entirely experimental.

How to (re-)generate the pegn sub-module?

It is as easy as running the following command.

go generate

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateFromFiles

func GenerateFromFiles(outputDir string, config Config, grammar []byte, dependencies ...[]byte) error

GenerateFromFiles generates Go code to the given outputDir based on the given configuration an files.

func GenerateFromURLs

func GenerateFromURLs(outputDir string, config Config, urls ...string) error

GenerateFromURLs generates Go code to the given outputDir based on the given configuration an urls.

Types

type Config

type Config struct {
	// ModulePath is the path to the module. REQUIRED!
	ModulePath string
	// MuduleName is the name of the module. Uses the meta.language field by default.
	ModuleName string

	// GrammarLocations are aliases to the grammar locations.
	// e.g. 'spec.pegn.dev': 'https://raw.githubusercontent.com/pegn/spec/master/grammar.pegn'
	GrammarLocations map[string]string

	// IgnoreReserved makes sure the generator does not return a error when it
	// tries to generate a reserved class/token. False by default, you should
	// not overwrite reserved classes or tokens.
	IgnoreReserved bool

	// TokenPrefix represents the prefix before a token name. No prefix is added
	// when the value is an empty string.
	// e.g. 'SP' with prefix 'Token' results in 'TokenSP'.
	TokenPrefix string
	// TokenSubPackage is the name of the sub-package for tokens. It left empty
	// the tokens will get added to the main file.
	TokenSubPackage string

	// TypeSuffix represent the pre- or suffix before a class name.
	// Recommended. Type names are the same as there corresponding parse
	// functions. e.g. 'Grammar' with suffix 'Type' results in 'GrammarType'.
	TypeSuffix string
	// TypeSubPackage is the name of the sub-package for types. It left empty
	// the types will get added to the main file.
	TypeSubPackage string

	// ClassAliases is a map of original class names to an alias.
	// e.g. map[alphanum: AlphaNum]
	ClassAliases map[string]string
	// ClassSubPackage is the name of the sub-package for classes. It left empty
	// the classes will get added to the main file.
	ClassSubPackage string

	// NodeAliases is a map of original node names to an alias.
	// e.g. map[Hexadec: Hexadecimal]
	NodeAliases map[string]string
}

Config that offers additional configuration options to the generator.

type InMemoryParser

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

InMemoryParser is the in-memory equivalent of generated code of generator.

func ParserFromFiles

func ParserFromFiles(config Config, grammar []byte, dependencies ...[]byte) (InMemoryParser, error)

ParserFromFiles creates an in-memory parser based on the given configuration and files.

func ParserFromURLs

func ParserFromURLs(config Config, urls ...string) (InMemoryParser, error)

ParserFromURLs creates an in-memory parser based on the given configuration and urls.

func (*InMemoryParser) GetClassDef

func (i *InMemoryParser) GetClassDef(id string) (interface{}, error)

GetClassDef returns a class definition.

func (*InMemoryParser) GetNodeDef

func (i *InMemoryParser) GetNodeDef(id string) (interface{}, error)

GetNodeDef returns a node definition.

func (*InMemoryParser) GetTokenDef

func (i *InMemoryParser) GetTokenDef(id string) (interface{}, error)

GetTokenDef returns a token definition.

type ReservedIdentifierError

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

ReservedIdentifierError indicates that the grammar overwrites one of the predefined/reserved (default) PEGN classes or tokens.

func (*ReservedIdentifierError) Error

func (r *ReservedIdentifierError) Error() string

Directories

Path Synopsis
is
nd
tk

Jump to

Keyboard shortcuts

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