mapast

package module
v0.0.0-...-863e8e2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: MIT Imports: 0 Imported by: 0

README

mapast

GoDoc

MapAST is an MIT-licensed Go abstract syntax tree for Golang

Getting started
  • API documentation is available via godoc.

Documentation

Overview

Package MapAST is an abstract syntax tree for the go language.

Index

Constants

View Source
const AssignStmtAdd byte = 3

AssignStmtAdd is an assignment with an add assignment operation.

View Source
const AssignStmtAnd byte = 8

AssignStmtAnd is an assignment with a bitwise and assignment operation.

View Source
const AssignStmtAndNot byte = 2

AssignStmtAndNot is an assignment with an and not assignment operation.

View Source
const AssignStmtColonEq byte = 1

AssignStmtColonEq is a short variable declaration

View Source
const AssignStmtEqual byte = 0

AssignStmtEqual is an assignment without an assignment operation.

View Source
const AssignStmtIotaIsLast byte = 13

AssignStmtIotaIsLast is used for constant declaration for lines that follow the iota row.

View Source
const AssignStmtMoreColonEq byte = 16

AssignStmtMoreColonEq is a short variable declaration with one expression on the right hand side.

View Source
const AssignStmtMoreColonEqRange byte = 18

AssignStmtMoreColonEqRange is a short variable declaration with one expression on the right hand side. Used within a range loop.

View Source
const AssignStmtMoreEqual byte = 15

AssignStmtMoreEqual is an assignment without an assignment operation. It has one expression on the right hand side.

View Source
const AssignStmtMoreEqualRange byte = 17

AssignStmtMoreEqualRange is an assignment without an assignment operation. It has one expression on the right hand side. Used within a range loop.

View Source
const AssignStmtMul byte = 5

AssignStmtMul is an assignment with a multiply assignment operation.

View Source
const AssignStmtOr byte = 9

AssignStmtOr is an assignment with a bitwise or assignment operation.

View Source
const AssignStmtQuo byte = 6

AssignStmtQuo is an assignment with a division assignment operation.

View Source
const AssignStmtRem byte = 7

AssignStmtRem is an assignment with a remainder assignment operation.

View Source
const AssignStmtShl byte = 11

AssignStmtShl is an assignment with a left shift assignment operation.

View Source
const AssignStmtShr byte = 12

AssignStmtShr is an assignment with a right shift assignment operation.

View Source
const AssignStmtSub byte = 4

AssignStmtSub is an assignment with a subtract assignment operation.

View Source
const AssignStmtTotalCount byte = 19

AssignStmtTotalCount is a total count sentinel. Do not use.

View Source
const AssignStmtTypeIsLast byte = 14

AssignStmtTypeIsLast is used in variable declaration giving the variables a type but no initial values are assigned.

View Source
const AssignStmtXor byte = 10

AssignStmtXor is an assignment with a bitwise xor assignment operation.

View Source
const BlocOfCodeCase byte = 8

BlocOfCodeCase contains Expression header elements that will appear comma separated.

View Source
const BlocOfCodeCommunicate byte = 11

BlocOfCodeCommunicate is a communicate clause. It has exactly one Expression or AssignStmt node in header. Child of BlocOfCodeSelect.

View Source
const BlocOfCodeCommunicateDefault byte = 12

BlocOfCodeCommunicateDefault is a communicate default clause. It has no header entries. Child of BlocOfCodeSelect.

View Source
const BlocOfCodeDefault byte = 9

BlocOfCodeDefault is a default clause, child of BlocOfCodeSwitch or a BlocOfCodeTypeSwitch. It has zero header elements.

View Source
const BlocOfCodeFor byte = 4

BlocOfCodeFor is "for" or "for something range something" loop. The range (if any) is part of AssignStmt child.

View Source
const BlocOfCodeForRange byte = 5

BlocOfCodeForRange is a for range loop. This loop code begins with "for range".

View Source
const BlocOfCodeIf byte = 1

BlocOfCodeIf is an if code block. It may occur right after BlocOfCodeIfElse, forming an if else if sequence of blocks. Has 1 or 3 header entries.

View Source
const BlocOfCodeIfElse byte = 2

BlocOfCodeIfElse. Must be followed by BlocOfCodePlain or BlocOfCodeIf node.

View Source
const BlocOfCodeNone byte = 10

BlocOfCodeNone is unused, but contains elements but no brackets.

View Source
const BlocOfCodePlain byte = 0

BlocOfCodePlain is a plain code block. Child of BlocOfCode, ToplevFunc or ClosureExp. Has zero header entries.

View Source
const BlocOfCodeSelect byte = 7

BlocOfCodeSelect contains no block header elements. The children are BlocOfCodeCommunicate or BlocOfCodeCommunicateDefault nodes.

View Source
const BlocOfCodeSwitch byte = 3

BlocOfCodeSwitch is a non-type switch. Can contain only BlocOfCodeCase and BlocOfCodeDefault nodes.

View Source
const BlocOfCodeTotalCount byte = 13

BlocOfCodeTotalCount is a total count sentinel. Do not use.

View Source
const BlocOfCodeTypeSwitch byte = 6

BlocOfCodeTypeSwitch switches using a .(type) header Expression.

View Source
const BranchStmtBreak byte = 1

BranchStmtSemi is a break statement. Child of a BlocOfCode node. Does not refer to a label.

View Source
const BranchStmtContinue byte = 2

BranchStmtContinue is a continue statement. Child of a BlocOfCode node. Does not refer to a label.

View Source
const BranchStmtFallthrough byte = 3

BranchStmtFallthrough is a fallthrough statement. Child of a BlocOfCode node.

View Source
const BranchStmtGoto byte = 4

BranchStmtGoto is a goto statement. Child of a BlocOfCode node. Does not refer to a label.

View Source
const BranchStmtSemi byte = 0

BranchStmtSemi is an explicit semicolon. Child of a BlocOfCode node.

View Source
const CommentRowEnder byte = 0

CommentRowEnder is a comment starting at the end of a previous element line.

View Source
const CommentRowNormal byte = 1

CommentRowNormal is a comment occupying it's own row.

View Source
const CommentRowSeparate byte = 2

CommentRowSeparate is a comment following an empty line(s).

View Source
const ExpressionAnd byte = 16

ExpressionAnd is a bitwise and operator.

View Source
const ExpressionAndAnd byte = 2

ExpressionAndAnd is a boolean and operator.

View Source
const ExpressionAndNot byte = 17

ExpressionAndNot is a bitwise and not operator.

View Source
const ExpressionArrayType byte = 26

ExpressionArrayType is an array type.

View Source
const ExpressionArrow byte = 25

ExpressionArrow is a send statement or an unary receive operation.

View Source
const ExpressionBrackets byte = 0

ExpressionBrackets has exactly one child that appears in a round brackets.

View Source
const ExpressionCall byte = 24

ExpressionCall is a call or method call expression, it is not variadic.

View Source
const ExpressionCallDotDotDot byte = 30

ExpressionCall is a variadic call or method call expression.

View Source
const ExpressionChan byte = 35

ExpressionChan is a channel type without a direction arrow operator.

View Source
const ExpressionComposed byte = 31

ExpressionComposed is a Literal Value nested in a composite literal.

View Source
const ExpressionComposite byte = 23

ExpressionComposite is a composite literal.

View Source
const ExpressionDiv byte = 14

ExpressionDiv is a numeric divide operator.

View Source
const ExpressionDot byte = 21

ExpressionDot is a dot separated selector expression or a qualified identifier.

View Source
const ExpressionEqual byte = 3

ExpressionEqual is an equality operator.

View Source
const ExpressionGrtEq byte = 7

ExpressionGrtEq is a numeric greater than or equal operator.

View Source
const ExpressionGrtThan byte = 8

ExpressionGrtThan is a numeric greater than operator.

View Source
const ExpressionIdentifier byte = 34

ExpressionIdentifier is a string wrapper. It has one string child node.

View Source
const ExpressionInChan byte = 36

ExpressionInChan is a channel type with a send direction arrow operator.

View Source
const ExpressionIndex byte = 32

ExpressionIndex is an index expression.

View Source
const ExpressionKeyVal byte = 28

ExpressionKeyVal is a key value expression.

View Source
const ExpressionLSh byte = 18

ExpressionLSh is a numeric left shift operator.

View Source
const ExpressionLessEq byte = 6

ExpressionLessEq is a numeric less than or equal operator.

View Source
const ExpressionLessThan byte = 5

ExpressionLessThan is a numeric less than operator.

View Source
const ExpressionMap byte = 33

ExpressionMap is a map type

View Source
const ExpressionMinus byte = 10

ExpressionMinus is a numeric minus operator.

View Source
const ExpressionMod byte = 15

ExpressionMod is a numeric remainder operator.

View Source
const ExpressionMul byte = 13

ExpressionMul is a numeric multiply operator.

View Source
const ExpressionNot byte = 20

ExpressionAndAnd is a boolean not operator.

View Source
const ExpressionNotEq byte = 4

ExpressionNotEq is an inequality operator.

View Source
const ExpressionOr byte = 11

ExpressionOr is a bitwise or operator.

View Source
const ExpressionOrOr byte = 1

ExpressionOrOr is a boolean or operator.

View Source
const ExpressionOutChan byte = 37

ExpressionOutChan is a channel type with a receive direction arrow operator.

View Source
const ExpressionPlus byte = 9

ExpressionPlus is a numeric plus operator.

View Source
const ExpressionRSh byte = 19

ExpressionRSh is a numeric right shift operator.

View Source
const ExpressionSlice byte = 22

ExpressionSlice is a slice expression.

View Source
const ExpressionSliceType byte = 27

ExpressionSliceType is a slice type.

View Source
const ExpressionTotalCount byte = 38

ExpressionTotalCount is a total count sentinel. Do not use.

View Source
const ExpressionType byte = 29

ExpressionType is a binary type assertion. If unary, it asserts the reserved word type.

View Source
const ExpressionXor byte = 12

ExpressionXor is a bitwise xor operator.

View Source
const GoDferStmtDefer byte = 1

GoDferStmtDefer is a defer statement used to invoke a call Expression using the go or defer keyword. It's only child is the Expression to be invoked.

View Source
const GoDferStmtGo byte = 0

GoDferStmtGo is a go statement used to invoke a call Expression using the go or defer keyword. It's only child is the Expression to be invoked.

View Source
const IncDecStmtMinusMinus byte = 1

IncDecStmtMinusMinus is an IncDec statement. It's the decrement -- statement.

View Source
const IncDecStmtPlusPlus byte = 0

IncDecStmtPlusPlus is an IncDec statement. It's the increment ++ statement.

View Source
const LblGotoCntBreak byte = 3

LblGotoCntBreak is a break followed by a label.

View Source
const LblGotoCntContinue byte = 2

LblGotoCntContinue is a continue followed by a label.

View Source
const LblGotoCntGoto byte = 1

LblGotoCntGoto is a goto followed by a label.

View Source
const LblGotoCntLabel byte = 0

LblGotoCntLabel is a labeled statement followed by a colon.

View Source
const MaxSubnodes = 1000000

MaxSubnodes - The current limit of how many certain type subnodes can some nodes have.

View Source
const PackageDefNormal byte = 0

PackageDefNormal is a package statement not following an empty line(s).

View Source
const PackageDefSeparate byte = 1

PackageDefSeparate is a package statement separated by an empty line(s).

View Source
const TypDefStmtAlias byte = 1

TypDefStmtAlias contains alias declaration.

View Source
const TypDefStmtNormal byte = 0

TypDefStmtNormal contains type definition.

View Source
const TypedIdentEllipsis byte = 2

TypedIdentEllipsis is the names followed by an ellipsis followed by a type.

View Source
const TypedIdentEquals byte = 1

TypedIdentEquals is the names followed by an equal sign followed by a type.

View Source
const TypedIdentNormal byte = 0

TypedIdentNormal is the names followed by type.

View Source
const TypedIdentTagged byte = 3

TypedIdentTagged is the names followed by type followed by a string tag.

View Source
const VarDefStmtConst byte = 1

VarDefStmtConst is a standalone or a multiple constant declaration.

View Source
const VarDefStmtTotalCount byte = 2

VarDefStmtTotalCount is a total count sentinel. Do not use.

View Source
const VarDefStmtVar byte = 0

VarDefStmtVar is a standalone or a multiple variable declaration.

Variables

View Source
var AssignStmt = storage[48:]

AssignStmt contains left hand side entries followed by an optional RootOfType and implicit equality kind operator, followed by a right hand side entries.

View Source
var BlocOfCode = storage[16:]

BlocOfCode node holds statements or other BlocOfCode nodes. Some BlocOfCode kinds have a header followed by the opening brace. Other BlocOfCode kinds lack braces altogether and use colon instead.

View Source
var BranchStmt = []byte("BranchStmt")

BranchStmt is a sole statement. One of semicolon, break, continue, fallthrough, goto. It has no children.

View Source
var ClosureExp = storage[64:]

ClosureExp is a function literal. The children are TypedIdent nodes.

View Source
var CommentRow = []byte("CommentRow")

CommentRow contains exactly one string, holding the comment verbatim, with optional leading or trailing newlines.

View Source
var Expression = storage[0:]

Expression node is one of the 38 differend kinds of Expression. It contains strings, IfceTypExps, ClosureExps, StructTypes or more Expressions.

View Source
var FileMatter = []byte("FileMatter")

FileMatter contains the file block elements. It represents a single go file. FileMatter node is a child of RootMatter node.

View Source
var GenericExp = []byte("GenericExp")

GenericExp is a generic type node. This node is reserved for future use.

View Source
var GoDferStmt = []byte("GoDferStmt")

GoDferStmt node is a statement node used to invoke a call Expression using the go or defer keyword. It's only child is the Expression to be invoked.

View Source
var IfceMethod = storage[80:]

IfceMethod node is a child of IfceTypExp. It's children are TypedIdent nodes. The name of interface method is stored in the first TypedIdent child, the one that would otherwise work as a receiver field.

View Source
var IfceTypExp = []byte("IfceTypExp")

IfceTypExp node contains one or several IfceMethod or RootOfType nodes.

View Source
var ImportStmt = []byte("ImportStmt")

ImportStmt holds a single import declaration. It is a child of ImportsDef or of a FileMatter. If the parent is FileMatter, it is a standalone import declaration. ImportStmt contains one or two strings.

View Source
var ImportsDef = []byte("ImportsDef")

ImportsDef is a bracketed container for multiple ImportStmt nodes. It is a child of FileMatter.

View Source
var IncDecStmt = []byte("IncDecStmt")

IncDecStmt is an increment++ or decrement-- statement. It's only child is a string identifier or a more complex Expression.

View Source
var LblGotoCnt = []byte("LblGotoCnt")

LblGotoCnt is a labeled statement, or a statement that uses label: break, continue or goto statement. It has one child, the string known as label name.

View Source
var PackageDef = []byte("PackageDef")

PackageDef is a child of FileMatter. Contains a string holding the file package name, and an optional CommentRow containing the import comment.

View Source
var ReturnStmt = []byte("ReturnStmt")

ReturnStmt node is a return statement followed by it's children. Strings are not allowed, a string child must be wrapped by ExpressionIdentifier.

View Source
var RootMatter = []byte("RootMatter")

RootMatter node is equivalent to a package block or an universe block containing all Go source text contained within the map. There is only one RootMatter located at key zero (0).

View Source
var RootOfType = []byte("RootOfType")

RootOfType marks the root of the type expression tree. It's only child is usually an Expression.

View Source
var StructType = []byte("StructType")

StructType is a sequence of named elements, called fields. Some fields can share their type, using a TypedIdent node.

View Source
var ToplevFunc = storage[32:]

ToplevFunc is a child function of FileMatter. The first child is a string. The rest of children can be TypedIdent nodes. The trailing child is an optional BlocOfCode.

View Source
var TypDefStmt = []byte("TypDefStmt")

TypDefStmt type declaration allows to declare an alias or a type. Bracketed form is currently not available.

View Source
var TypedIdent = []byte("TypedIdent")

TypedIdent field contains several string identifiers known as names, followed by a RootOfType node representing the type shared by the named identifiers. If contained within a StructType, it can be optionally tagged using the last string child (the tag).

View Source
var VarDefStmt = []byte("VarDefStmt")

VarDefStmt is a standalone or a multiple variable or constant declaration. It's children are single or multiple AssignStmt nodes, one for each row.

Functions

func AssignStmtNode

func AssignStmtNode(kind byte, elemscount uint64) []byte

Constructor for AssignStmt node. Elemscount is the number of elements including both side elements and the central type node (if any).

func BlocOfCodeNode

func BlocOfCodeNode(kind byte, headelemscount uint64) []byte

Constructor for BlocOfCode node. Headelemscount is the count of header elements including semicolons.

func BranchStmtNode

func BranchStmtNode(kind byte) []byte

Constructor for BranchStmt node.

func ClosureExpNode

func ClosureExpNode(paramscount uint64) []byte

Constructor for ClosureExp node. Paramscount is the number of parameters.

func Code

func Code(print func(string), ast map[uint64][]byte, iterator uint64, parent uint64)

Code generates go source code from an abstract syntax tree.

func Dump

func Dump(print func(string), ast map[uint64][]byte, iterator uint64, pad int) bool

Dump prints an ast dump. This is a xml like output that can be used to debug to see if the ast is correct. Only nested nodes under iterator position are printed.

func ExpressionNode

func ExpressionNode(kind byte, elemscount uint64) []byte

Constructor for Expression node. Elemscount is the number of children elements.

func GoDferStmtNode

func GoDferStmtNode(kind byte) []byte

Constructor for GoDferStmt node.

func IncDecStmtNode

func IncDecStmtNode(kind byte) []byte

Constructor for IncDecStmt node.

func LblGotoCntNode

func LblGotoCntNode(kind byte) []byte

Constructor for LblGotoCnt node.

func LookupComments

func LookupComments(file []byte, EnderSepar [2]map[int]struct{})

LookupComments fills EnderSepar with comment location information from file. This information is necessary to recognize comments of various types, like comments that span end of line only, or comments that follow an empty lines.

func O

func O(n uint64) uint64

O is an one way function. Given a node key it calculates the key of its first child node. The other keys of child nodes follow by adding 1, 2, 3... to the result.

func Poke

func Poke(ast map[uint64][]byte, iterator uint64) bool

The Poke function tests whether a given iterator key in an ast is occupied.

func PrintCode

func PrintCode(ast map[uint64][]byte, iterator uint64, parent uint64)

PrintCode prints go source code from an abstract syntax tree to a standard error.

func PrintDump

func PrintDump(ast map[uint64][]byte, iterator uint64, pad int) bool

PrintDump prints an ast dump. This a is xml like output that can be used to debug to see if the ast is correct. Only nested nodes under iterator position are printed.

func Printer

func Printer(s string)

Printer is used to print strings to standard error. Empty strings are printed as if they were newlines.

func ToplevFuncNode

func ToplevFuncNode(receiver bool, argc uint64) []byte

Constructor for ToplevFunc node. Argc is the count of proper arguments excluding results and receiver.

func TypDefStmtNode

func TypDefStmtNode(kind byte) []byte

Constructor for TypDefStmt node.

func VarDefStmtNode

func VarDefStmtNode(kind byte) []byte

Constructor for VarDefStmt node.

func Which

func Which(node []byte) []byte

Which determines which node a given byte slice represents. It resets capacity and the length to the maximum capacity and length. If node is a string, Which returns nil.

Types

This section is empty.

Directories

Path Synopsis
cmd
toyfmt
Toyfmt program demonstrates abstract syntax tree conversion and printing
Toyfmt program demonstrates abstract syntax tree conversion and printing
Package convert helps to convert go/ast to mapast
Package convert helps to convert go/ast to mapast

Jump to

Keyboard shortcuts

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