terexlang

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package terexlang provides a parser for TeREx (term rewriting).

BSD License

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of this software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AST

func AST(parsetree *sppf.Forest, tokRetr termr.TokenRetriever) (*terex.GCons,
	*terex.Environment, error)

AST creates an abstract syntax tree from a parse tree/forest.

Returns a homogenous AST, a TeREx-environment and an error status.

func ErrorPacker

func ErrorPacker(emsg string, env *terex.Environment) terex.Element

func Lexer

func Lexer() (*scanner.LMAdapter, error)

Lexer creates a new lexmachine lexer.

func LoadStandardLanguage

func LoadStandardLanguage() *terex.Environment

LoadStandardLanguage returns an environment with all the standard symbols and operators loaded.

func Parse

func Parse(input string) (*sppf.Forest, termr.TokenRetriever, error)

Parse parses an input string, given in TeREx language format. It returns the parse forest and a TokenReceiver, or an error in case of failure.

Clients may use a terex.ASTBuilder to create an abstract syntax tree from the parse forest.

func QuoteAST

func QuoteAST(ast terex.Element, env *terex.Environment) (terex.Element, error)

QuoteAST returns an AST, which should be the result of parsing an s-expr, as pure data.

If the environment contains any symbol's value, quoting will replace the symbol by its value. For example, if the s-expr contains a symbol 'str' with a value of "this is a string", the resulting data structure will contain the string, not the name of the symbol. If you do not have use for this kind of substitution, simply call Quote(…) for the global environment.

func T

func T() tracing.Trace

T traces to the global syntax tracer

func Token

func Token(t string) (string, int)

Token returns a token name and its value.

Types

type Dict

type Dict map[string]terex.Atom

type Rewriter

type Rewriter struct {
	Op terex.Operator
	// contains filtered or unexported fields
}

func NewRewriter

func NewRewriter(symname string) *Rewriter

func (Rewriter) Descend

func (rew Rewriter) Descend(sppf.RuleCtxt) bool

func (*Rewriter) Match

func (rew *Rewriter) Match(e terex.Element, env *terex.Environment) terex.Element

func (Rewriter) Operator

func (rew Rewriter) Operator() terex.Operator

func (*Rewriter) Rewrite

func (rew *Rewriter) Rewrite(l *terex.GCons, env *terex.Environment) terex.Element

func (*Rewriter) SetRewriters

func (rew *Rewriter) SetRewriters(rlist *terex.GCons)

func (Rewriter) String

func (rew Rewriter) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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