Version: v2.1.0 Latest Latest

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

Go to latest
Published: Apr 18, 2020 License: Apache-2.0 Imports: 7 Imported by: 0



Package grammars parses XML GEP grammar representations for a particular output language. It can then be used to generate code from Karva expressions for that language.



This section is empty.


This section is empty.


This section is empty.


type BasicFunctions

type BasicFunctions struct {
	Count          int      `xml:"count,attr"`
	BasicFunctions []Helper `xml:"basicFunction"`

BasicFunctions are simple functions used by GEP for the target language.

type Categories

type Categories struct {
	Functioncall      Functioncall      `xml:"functioncall"`
	TransformFunction TransformFunction `xml:"transformfunction"`
	Switch            Switch            `xml:"switch"`
	Case              Format            `xml:"case"`
	Equality          Format            `xml:"equality"`

Categories lists the types of grammar available.

type Constant

type Constant struct {
	Type       string `xml:"type,attr"`
	Replace    string `xml:"replace,attr"`
	Labelindex int    `xml:"labelindex,attr"`
	Chardata   string `xml:",chardata"`

Constant represents a constant.

type Format

type Format struct {
	Format string `xml:"format,attr"`

Format represents how an item is formatted.

type Function

type Function struct {
	// Idx is the index of the function in the XML grammar.
	Idx int `xml:"idx,attr"`
	// SymbolName is the Karva symbol used to represent the function.
	SymbolName string `xml:"symbol,attr"`
	// TerminalCount specifies the number of input terminals to the function.
	TerminalCount int `xml:"terminals,attr"`
	// Uniontype (optional) determines how the diadic function is rendered.
	Uniontype string `xml:"uniontype,attr"`
	// Chardata is the action function rendering for the given language.
	Chardata string `xml:",chardata"`

Function represents a single function.

func (*Function) BoolFunction

func (f *Function) BoolFunction([]bool) bool

BoolFunction allows FuncMap to implement interace functions.FuncMap.

func (*Function) Float64Function

func (f *Function) Float64Function([]float64) float64

Float64Function allows FuncMap to implement interace functions.FuncMap.

func (*Function) IntFunction added in v2.1.0

func (f *Function) IntFunction([]int) int

IntFunction allows FuncMap to implement interace functions.FuncMap.

func (*Function) Symbol

func (f *Function) Symbol() string

Symbol returns the symbol name of the function.

func (*Function) Terminals

func (f *Function) Terminals() int

Terminals returns the terminal count of the function.

func (*Function) VectorIntFunction added in v2.1.0

func (f *Function) VectorIntFunction([]functions.VectorInt) functions.VectorInt

VectorIntFunction allows FuncMap to implement interace functions.FuncMap.

type Functioncall

type Functioncall struct {
	Call string `xml:"call,attr"`

Functioncall represents a function call.

type Functions

type Functions struct {
	Count     int        `xml:"count,attr"`
	Functions []Function `xml:"function"`

	// Lookup table of function symbol name to function definition
	FuncMap functions.FuncMap `xml:"-"`

Functions is a collection of Functions available in the language grammar.

type Grammar

type Grammar struct {
	XMLName  xml.Name `xml:"grammar"`
	Comments string   `xml:",comment"`
	Name     string   `xml:"name,attr"`
	Version  string   `xml:"version,attr"`
	Ext      string   `xml:"ext,attr"`
	Type     string   `xml:"type,attr"`
	// Functions lists all possible functions available in the language grammar.
	Functions Functions `xml:"functions"`
	// Order specifies the order structure of the program.
	Order []OrderItem `xml:"order>item"`
	// Open contains the text for the start of the generated source code file.
	Open string `xml:"open"`
	// Close contains the text for the end of the generated source code file.
	Close string `xml:"close"`
	// Headers/Subheaders contains any required headers such as imports needed near the top of the generated source code file.
	Headers    []Replacement `xml:"headers>header"`
	Subheaders []Replacement `xml:"subheaders>subheader"`
	// RandomConstants defines the syntax for a random constant.
	RandomConstants []Replacement `xml:"randomconstants>randomconst"`
	// Categories defines the special features of the target language.
	Categories Categories `xml:"categories"`
	// Transformations/ReverseTransformations lists any special transformations for the target language.
	Transformations        []Transformation `xml:"transformations>transformation"`
	ReverseTransformations []Transformation `xml:"reversetransformations>transformation"`
	// Constants defines the syntax for constants for the target language.
	Constants []Constant `xml:"constants>constant"`
	// Tempvars defines the syntax for temporary variables for the target language.
	Tempvars []Tempvar `xml:"tempvars>tempvar"`
	// Endline specifies how the end of a line is rendered for the target language.
	Endline string `xml:"endline"`
	// Indent is the number of tab characters to add to each line in the code block.
	Indent int `xml:"indent"`
	// Parenstype specifies the type of parentheses to use for arrays in the target language.
	// 0=(), 1=[]
	Parenstype int `xml:"parenstype"`
	// Footers defines special code structures for the target language.
	Footers []Replacement `xml:"footers>footer"`
	// Helpers defines the complete set of helper functions used in the Functions above.
	Helpers Helpers `xml:"helpers"`
	// Keywords lists the keywords for the target language.
	Keywords []Keyword `xml:"keywords>keyword"`
	// Commentmark defines how a comment is rendered in the target language.
	Commentmark string `xml:"commentmark"`
	// LinkingFunctions lists special linking functions used by GEP for the target language.
	LinkingFunctions LinkingFunctions `xml:"linkingFunctions"`
	// BasicFunctions lists basic functions used by GEP for the target language.
	BasicFunctions BasicFunctions `xml:"basicFunctions"`
	Ddfcomment     string         `xml:"ddfcomment"`
	Udfcomment     string         `xml:"udfcomment"`
	// Testing defines a function used for testing a method for the target language.
	Testing Testing `xml:"testing"`

Grammar represents the complete XML specification for rendering a Karva string for the given target language.

func LoadGoBooleanAllGatesGrammar

func LoadGoBooleanAllGatesGrammar() (*Grammar, error)

LoadGoBooleanAllGatesGrammar loads the general boolean grammer for Go as the target language.

func LoadGoBooleanMuxSystemGrammar

func LoadGoBooleanMuxSystemGrammar() (*Grammar, error)

LoadGoBooleanMuxSystemGrammar loads the specialized boolean grammer for Go as the target language.

func LoadGoBooleanNandGatesGrammar

func LoadGoBooleanNandGatesGrammar() (*Grammar, error)

LoadGoBooleanNandGatesGrammar loads the specialized boolean grammer for Go as the target language.

func LoadGoBooleanNorGatesGrammar

func LoadGoBooleanNorGatesGrammar() (*Grammar, error)

LoadGoBooleanNorGatesGrammar loads the specialized boolean grammer for Go as the target language.

func LoadGoBooleanNotAndOrGatesGrammar

func LoadGoBooleanNotAndOrGatesGrammar() (*Grammar, error)

LoadGoBooleanNotAndOrGatesGrammar loads the specialized boolean grammer for Go as the target language.

func LoadGoMathGrammar

func LoadGoMathGrammar() (*Grammar, error)

LoadGoMathGrammar loads the floating-point math grammer for Go as the target language.

func LoadGoReedMullerSystemGrammar

func LoadGoReedMullerSystemGrammar() (*Grammar, error)

LoadGoReedMullerSystemGrammar loads the specialized boolean grammer for Go as the target language.

type Helper

type Helper struct {
	Replaces  string `xml:"replaces,attr"`
	Prototype string `xml:"prototype,attr"`
	Chardata  string `xml:",chardata"`

Helper represents a helper function.

type HelperMap

type HelperMap map[string]string

HelperMap maps helper replacement functions to their definitions.

type Helpers

type Helpers struct {
	Count       int      `xml:"count,attr"`
	Declaration string   `xml:"declaration,attr"`
	Assignment  string   `xml:"assignment,attr"`
	Helpers     []Helper `xml:"helper"`

	// Lookup table of helper symbol name to helper definition
	HelperMap HelperMap `xml:"-"`

Helpers represents helper functions for the target language.

type Keyword

type Keyword struct {
	Chardata string `xml:",chardata"`

Keyword is a reserved keyword in the target language.

type LinkingFunctions

type LinkingFunctions struct {
	Count            int      `xml:"count,attr"`
	LinkingFunctions []Helper `xml:"linkingFunction"`

LinkingFunctions are special functions used by GEP for the target language.

type Method

type Method struct {
	Callformat string `xml:"callformat,attr"`
	Listformat string `xml:"listformat,attr"`
	Chardata   string `xml:",chardata"`

Method represents a method.

type OrderItem

type OrderItem struct {
	Name string `xml:"name,attr"`

OrderItem is a single element of the code structure.

type Prototype

type Prototype struct {
	Paramsformat string `xml:"paramsformat,attr"`
	Chardata     string `xml:",chardata"`

Prototype is a function signature.

type Replacement

type Replacement struct {
	Type      string `xml:"type,attr"`
	Replace   string `xml:"replace,attr"`
	Indexzero bool   `xml:"indexzero,attr"`
	Indexone  bool   `xml:"indexone,attr"`
	Chardata  string `xml:",chardata"`

Replacement determines how a function can be replaced.

type Switch

type Switch struct {
	Special            string `xml:"special,attr"`
	Top                string `xml:"top,attr"`
	Bottom             string `xml:"bottom,attr"`
	Categoricaldefault string `xml:"categoricaldefault,attr"`
	Numericaldefault   string `xml:"numericaldefault,attr"`

Switch represents the grammar for a switch call.

type Tempvar

type Tempvar struct {
	Type     string `xml:"type,attr"`
	Typename string `xml:"typename,attr"`
	Varname  string `xml:"varname,attr"`
	Chardata string `xml:",chardata"`

Tempvar represents a temporary variable.

type Testing

type Testing struct {
	Prototype Prototype `xml:"prototype"`
	Method    Method    `xml:"method"`

Testing represents a testing function.

type TransformFunction

type TransformFunction struct {
	Header    string `xml:"header,attr"`
	Footer    string `xml:"footer,attr"`
	Prototype string `xml:"prototype,attr"`

TransformFunction represents the transformation of a function.

type Transformation

type Transformation struct {
	Name         string `xml:"name,attr"`
	Call         string `xml:"call,attr"`
	Itemformat   string `xml:"itemformat,attr"`
	Prototype    string `xml:"prototype,attr"`
	Declarations string `xml:"declarations,attr"`
	Chardata     string `xml:",chardata"`

Transformation represents a function transformation.

Source Files

Jump to

Keyboard shortcuts

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