Documentation ¶
Overview ¶
Package terexlang provides a parser for TeREx (term rewriting).
BSD License ¶
Copyright (c) 2019–20, Norbert Pillmayer ¶
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 ¶
- func AST(parsetree *sppf.Forest, tokRetr termr.TokenRetriever) (*terex.GCons, *terex.Environment, error)
- func ErrorPacker(emsg string, env *terex.Environment) terex.Element
- func Lexer() (*scanner.LMAdapter, error)
- func LoadStandardLanguage() *terex.Environment
- func Parse(input string) (*sppf.Forest, termr.TokenRetriever, error)
- func QuoteAST(ast terex.Element, env *terex.Environment) (terex.Element, error)
- func T() tracing.Trace
- func Token(t string) (string, int)
- type Dict
- type Rewriter
- func (rew Rewriter) Descend(sppf.RuleCtxt) bool
- func (rew *Rewriter) Match(e terex.Element, env *terex.Environment) terex.Element
- func (rew Rewriter) Operator() terex.Operator
- func (rew *Rewriter) Rewrite(l *terex.GCons, env *terex.Environment) terex.Element
- func (rew *Rewriter) SetRewriters(rlist *terex.GCons)
- func (rew Rewriter) String() string
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 LoadStandardLanguage ¶
func LoadStandardLanguage() *terex.Environment
LoadStandardLanguage returns an environment with all the standard symbols and operators loaded.
func Parse ¶
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 ¶
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.