Documentation ¶
Overview ¶
Package pmmpost implements an interpreter for "Poor Man's MetaPost".
This is the implementation of an interpreter for "Poor Man's MetaPost", my variant of the MetaPost graphical language. There is an accompanying ANTLR grammar file, which describes the features and limitations of PMMPost. I will sometimes refer to MetaFont, the original language underlying MetaPost, as the grammar definitions are taken from Don Knuth's grammar description in "The METAFONTBook".
The intent of PMMPost is to produce scalable drawings. To accomplish this, users write a PMMPost program. A typical PMMPost looks like this (statements for drawing a triangle):
beginfig("triangle", 1cm, 1cm); pair A, B, C; A:=(0,0); B:=(1cm,0); C:=(0.5cm,1cm); draw A--B--C--cycle; endfig;
PMMPost will, depending on the backend configuration, output a picture for each "beginfig() ... endfig"-statement in the program. For more information, please refer to https://www.tug.org/docs/metapost/mpman.pdf.
BSD License ¶
Copyright (c) 2017–18, 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 Norbert Pillmayer 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 ¶
var T tracing.Trace
We will trace to the InterpreterTracer
Functions ¶
This section is empty.
Types ¶
type PMMPostInterpreter ¶
type PMMPostInterpreter struct {
// contains filtered or unexported fields
}
This is an umbrella object to hold together the various tools needed to parse and execute PMMPost statements. It will orchestrate and instrument the tools and execute them in the correct order. Also, this object will hold and respect parameters we pass to the interpreter, so we can alter the behaviour in certain aspects.
func NewPMMPostInterpreter ¶
func NewPMMPostInterpreter(loadBuiltins bool, callback func(*gfx.Picture)) *PMMPostInterpreter
Create a new Interpreter for the "Poor Man's MetaPost". This is the top-level object for this package.
The interpreter manages an AST listener, a scope tree, a memory frame stack, and stacks for numeric/pair and path expressions.
Loads builtin symbols (variables and types) if argument is true.
func (*PMMPostInterpreter) ParseStatements ¶
func (intp *PMMPostInterpreter) ParseStatements(input []byte) []error
Parse and interpret a statement list.
func (*PMMPostInterpreter) ValueOf ¶
func (intp *PMMPostInterpreter) ValueOf(variable string) (VarValue, error)
Value returns the current value of a variable. Return values are: canonical name of the variable & value of the variable as string.
func (*PMMPostInterpreter) ValueString ¶
func (intp *PMMPostInterpreter) ValueString(variable string) (string, string)
ValueString returns the current value of a variable. Return values are: canonical name of the variable & value of the variable as string.
type VarValue ¶
type VarValue struct { VariableFullName string // full name of the variable this value is from // contains filtered or unexported fields }
VarValue is a wrapper type for variable values. It hides the complexities of the various types of variables from clients.
This is part of an API for the interpreter. The PMMPost interpreter can be used as a standalone batch drawing CLI, but its foremost purpose is to be integrated in applications.
func (VarValue) AsPair ¶
func (vval VarValue) AsPair() arithmetic.Pair
func (VarValue) Type ¶
func (vval VarValue) Type() variables.VariableType
Type returns the type of a variable's value.
Directories ¶
Path | Synopsis |
---|---|
Package grammar contains generated Go code produced by ANTLR V4.
|
Package grammar contains generated Go code produced by ANTLR V4. |
Package listener exposes listener function implementations for ANTLR V4.
|
Package listener exposes listener function implementations for ANTLR V4. |