nolol

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrExpectedStringConstant = "ErrExpectedStringConstant"
	ErrExpectedIdentifier     = "ErrExpectedIdentifier"
	ErrExpectedExistingMacro  = "ErrExpectedExistingMacro"
	ErrExpectedJumplabel      = "ErrExpectedJumplabel"
	ErrExpectedMacroType      = "ErrExpectedMacroType"
)

Constant definitions for parser.Error.Code

View Source
const MaxExpandedMacros = 100

MaxExpandedMacros is the maximum number of macros to expand, before aborting due to a loop

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalysisReport added in v0.0.28

type AnalysisReport struct {
	FileDocstring string
	Definitions   map[string]*nast.Definition
	Macros        map[string]*nast.MacroDefinition
	Variables     []string
	Labels        []string
	Docstrings    map[string]string
}

AnalysisReport contains collected information about a nolol-programm

func Analyse added in v0.0.28

func Analyse(prog *nast.Program) (*AnalysisReport, error)

Analyse returns an AnalysisReport for the given program All includes in the input-program must have been already resolved (use the converter for this) The input-programm is mutated. Do NOT use it after analysis

func (AnalysisReport) GetMacroLocalVars added in v0.0.28

func (a AnalysisReport) GetMacroLocalVars(mac *nast.MacroDefinition) []string

GetMacroLocalVars returns the local variables for the given macro

func (AnalysisReport) GetVarsAtLine added in v0.0.28

func (a AnalysisReport) GetVarsAtLine(line int) []string

GetVarsAtLine returns all variables that are in scope at the given line

type Converter

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

Converter can convert a nolol-ast to a yolol-ast

func (*Converter) Convert

func (c *Converter) Convert() (*ast.Program, error)

Convert converts the nolol-program to a yolol-program This is a shortcut to calling the ProcessXY-Methods in order

func (*Converter) Error added in v0.0.32

func (c *Converter) Error() error

func (*Converter) Get added in v0.0.32

func (c *Converter) Get() (*ast.Program, error)

Get returns the converted program and/or an error

func (*Converter) GetIntermediateProgram added in v0.0.32

func (c *Converter) GetIntermediateProgram() *nast.Program

GetIntermediateProgram returns the current intermediate nolol-ast. The state of it depends on what steps of the conversion have already been performed

func (*Converter) GetVariableTranslations added in v0.0.13

func (c *Converter) GetVariableTranslations() map[string]string

GetVariableTranslations returns a table that can be used to find the original names of the variables whos names where shortened during conversion

func (*Converter) Load added in v0.0.32

func (c *Converter) Load(prog *nast.Program, files FileSystem) ConverterIncludes

Load loades a nolol-ast to convert. Included files are retrieved using the given filesystem

func (*Converter) LoadFile added in v0.0.32

func (c *Converter) LoadFile(mainfile string) ConverterIncludes

LoadFile is a shortcut that loads a file to convert from the file-system mainfile is the path to the file on the disk. All included files are loaded relative to the mainfile.

func (*Converter) LoadFileEx added in v0.0.32

func (c *Converter) LoadFileEx(mainfile string, files FileSystem) ConverterIncludes

LoadFileEx acts like LoadFile, but allows the passing of a custom filesystem from which the source files are retrieved. This way, files that are not stored on disk can be converted

func (*Converter) ProcessCodeExpansion added in v0.0.32

func (c *Converter) ProcessCodeExpansion() ConverterNodes

ProcessCodeExpansion resolves all macro-definitions, macro-insertions and defines

func (*Converter) ProcessFinalize added in v0.0.32

func (c *Converter) ProcessFinalize() ConverterDone

ProcessFinalize takes the final steps in converting the program

func (*Converter) ProcessIncludes added in v0.0.32

func (c *Converter) ProcessIncludes() ConverterExpansions

ProcessIncludes resolves all Include-Directives in the given nolol-code

func (*Converter) ProcessLineNumbers added in v0.0.32

func (c *Converter) ProcessLineNumbers() ConverterFinal

ProcessLineNumbers handles gotos and line-labels

func (*Converter) ProcessNodes added in v0.0.32

func (c *Converter) ProcessNodes() ConverterLines

ProcessNodes converts most nolol ast-nodes to yolol ast.nodes

func (*Converter) RunConversion added in v0.0.32

func (c *Converter) RunConversion() ConverterDone

RunConversion jumps to the final phase of conversion

func (*Converter) SetChipType added in v0.1.5

func (c *Converter) SetChipType(chip string) ConverterEmpty

SetChipType sets the yolol chip-type for that the nolol-script should be compiled

func (*Converter) SetDebug added in v0.0.32

func (c *Converter) SetDebug(b bool) ConverterEmpty

SetDebug enables/disables debug logging

type ConverterDone added in v0.0.32

type ConverterDone interface {
	Get() (*ast.Program, error)
	GetVariableTranslations() map[string]string
	Error() error
	GetIntermediateProgram() *nast.Program
}

ConverterDone is part of the Sequenced-Builder-Pattern of the Converter

type ConverterEmpty added in v0.0.32

type ConverterEmpty interface {
	Load(prog *nast.Program, files FileSystem) ConverterIncludes
	LoadFile(mainfile string) ConverterIncludes
	LoadFileEx(mainfile string, files FileSystem) ConverterIncludes
	SetDebug(b bool) ConverterEmpty
	SetChipType(chip string) ConverterEmpty
}

ConverterEmpty is part of the Sequenced-Builder-Pattern of the Converter

func NewConverter

func NewConverter() ConverterEmpty

NewConverter creates a new converter

type ConverterExpansions added in v0.0.32

type ConverterExpansions interface {
	ProcessCodeExpansion() ConverterNodes
	Error() error
	GetIntermediateProgram() *nast.Program
}

ConverterExpansions is part of the Sequenced-Builder-Pattern of the Converter

type ConverterFinal added in v0.0.32

type ConverterFinal interface {
	ProcessFinalize() ConverterDone
	Error() error
	GetIntermediateProgram() *nast.Program
}

ConverterFinal is part of the Sequenced-Builder-Pattern of the Converter

type ConverterIncludes added in v0.0.32

type ConverterIncludes interface {
	ProcessIncludes() ConverterExpansions
	Convert() (*ast.Program, error)
	RunConversion() ConverterDone
	Error() error
	GetIntermediateProgram() *nast.Program
}

ConverterIncludes is part of the Sequenced-Builder-Pattern of the Converter

type ConverterLines added in v0.0.32

type ConverterLines interface {
	ProcessLineNumbers() ConverterFinal
	Error() error
	GetIntermediateProgram() *nast.Program
}

ConverterLines is part of the Sequenced-Builder-Pattern of the Converter

type ConverterNodes added in v0.0.32

type ConverterNodes interface {
	ProcessNodes() ConverterLines
	Error() error
	GetIntermediateProgram() *nast.Program
}

ConverterNodes is part of the Sequenced-Builder-Pattern of the Converter

type DiskFileSystem added in v0.0.10

type DiskFileSystem struct {
	Dir string
}

DiskFileSystem retrieves files from a directory on the disk

func (DiskFileSystem) Get added in v0.0.10

func (f DiskFileSystem) Get(name string) (string, error)

Get implements FileSystem

type FileSystem added in v0.0.10

type FileSystem interface {
	Get(name string) (string, error)
}

FileSystem defines an interface to get the content of files by name used so the converter can query for the content of files mentioned in include-directives

type InsertedMacro added in v0.0.32

type InsertedMacro struct {
	// Code to be inserted
	Code ast.Node
	// Type of the original macro
	MacroType string
	// The inseriton of the macro
	FuncCall *nast.FuncCall
	// The StatementLine the macro is inserted into (if any)
	ParentStatementLine *nast.StatementLine
	// Position inside ParentStatementLine
	ParentStatementLineIndex int
}

InsertedMacro is a pseudo-ast node that is used during the insertion of a macro IT bundles information about an (already expanded) macro and it's insetion

func (*InsertedMacro) Accept added in v0.0.32

func (e *InsertedMacro) Accept(v ast.Visitor) error

Accept is used to implement Acceptor

func (*InsertedMacro) El added in v0.0.32

func (e *InsertedMacro) El()

El implements the type-marker method

func (*InsertedMacro) End added in v0.0.32

func (e *InsertedMacro) End() ast.Position

End is needed to implement ast.Node

func (*InsertedMacro) Expr added in v0.0.32

func (e *InsertedMacro) Expr()

Expr implements the type-marker method

func (*InsertedMacro) NestEl added in v0.0.32

func (e *InsertedMacro) NestEl()

NestEl implements the type-marker method

func (*InsertedMacro) Start added in v0.0.32

func (e *InsertedMacro) Start() ast.Position

Start is needed to implement ast.Node

func (*InsertedMacro) Stmt added in v0.0.32

func (e *InsertedMacro) Stmt()

Stmt implements the type-marker method

type MemoryFileSystem added in v0.0.10

type MemoryFileSystem map[string]string

MemoryFileSystem serves files from Memory

func (MemoryFileSystem) Get added in v0.0.10

func (f MemoryFileSystem) Get(name string) (string, error)

Get implements FileSystem

type Parser

type Parser struct {
	*parser.Parser
}

Parser parses a nolol-program

func (*Parser) Debug added in v0.0.7

func (p *Parser) Debug(b bool)

Debug enables/disables debug logging

func (*Parser) Parse

func (p *Parser) Parse(prog string) (*nast.Program, error)

Parse is the entry point for parsing

func (*Parser) ParseBlock added in v0.0.9

func (p *Parser) ParseBlock(stop func() bool) *nast.Block

ParseBlock parse lines until stop() returns true

func (*Parser) ParseBreak added in v0.0.14

func (p *Parser) ParseBreak() ast.Statement

ParseBreak parses the break keyword

func (*Parser) ParseContinue added in v0.0.14

func (p *Parser) ParseContinue() ast.Statement

ParseContinue parses the continue keyword

func (*Parser) ParseDefinition added in v0.0.12

func (p *Parser) ParseDefinition() *nast.Definition

ParseDefinition parses a constant declaration

func (*Parser) ParseElement added in v0.0.10

func (p *Parser) ParseElement() nast.Element

ParseElement parses an element

func (*Parser) ParseFuncCall added in v0.0.6

func (p *Parser) ParseFuncCall() *nast.FuncCall

ParseFuncCall parse a function call

func (*Parser) ParseIf

func (p *Parser) ParseIf() ast.Statement

ParseIf parses an if-node. Copied nearly 1to1 from yolol-parser, but requires ; instead of " " between statements

func (*Parser) ParseInclude added in v0.0.10

func (p *Parser) ParseInclude() *nast.IncludeDirective

ParseInclude parses an include directive

func (*Parser) ParseMacroDefinition added in v0.0.11

func (p *Parser) ParseMacroDefinition() *nast.MacroDefinition

ParseMacroDefinition parses the definition of a macro

func (*Parser) ParseMultilineIf

func (p *Parser) ParseMultilineIf() nast.NestableElement

ParseMultilineIf parses a nolol-style multiline if

func (*Parser) ParseNestableElement added in v0.0.11

func (p *Parser) ParseNestableElement() nast.NestableElement

ParseNestableElement parses a NOLOL-Element which can appear inside a blocl

func (*Parser) ParseNestableElementFuncCall added in v0.0.32

func (p *Parser) ParseNestableElementFuncCall() *nast.FuncCall

ParseNestableElementFuncCall parses a funccall that is the only element on the line

func (*Parser) ParseProgram

func (p *Parser) ParseProgram() *nast.Program

ParseProgram parses the program

func (*Parser) ParseSingleExpression added in v0.0.14

func (p *Parser) ParseSingleExpression() ast.Expression

ParseSingleExpression wraps the method of the yolol-parser and adds parsing of func-calls

func (*Parser) ParseStatement added in v0.0.14

func (p *Parser) ParseStatement() ast.Statement

ParseStatement wraps the method of the yolol-parser to add new statement-types

func (*Parser) ParseStatementLine

func (p *Parser) ParseStatementLine() *nast.StatementLine

ParseStatementLine parses a statement line

func (*Parser) ParseWhile

func (p *Parser) ParseWhile() nast.NestableElement

ParseWhile pasres a nolol while

func (*Parser) SetFilename added in v0.0.10

func (p *Parser) SetFilename(name string)

SetFilename sets the filename that is included in the position of every returned ast.node Necessary when parsing an included file to differenciate between positions in different files

type Printer

type Printer struct {
	Indentation string
	// contains filtered or unexported fields
}

Printer can generate the nolol-code corresponding to a nolol ast

func NewPrinter

func NewPrinter() *Printer

NewPrinter creates a new Printer

func (*Printer) Print

func (np *Printer) Print(prog ast.Node) (string, error)

Print returns the nolol-code for the given ast

type PublicParser added in v0.0.32

type PublicParser interface {
	Parse(prog string) (*nast.Program, error)
	Debug(b bool)
}

PublicParser is an interface that hides all overridable-methods from normal users

func NewParser

func NewParser() PublicParser

NewParser creates and returns a nolol parser

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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