Version: v1.0.1 Latest Latest

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

Go to latest
Published: Jun 30, 2015 License: Apache-2.0 Imports: 10 Imported by: 0



This package implements a parser and parse tree dumper for Dockerfiles.



This section is empty.


View Source
var (
	TOKEN_WHITESPACE        = regexp.MustCompile(`[\t\v\f\r ]+`)
	TOKEN_LINE_CONTINUATION = regexp.MustCompile(`\\[ \t]*$`)
	TOKEN_COMMENT           = regexp.MustCompile(`^#.*$`)


This section is empty.


type Node

type Node struct {
	Value      string          // actual content
	Next       *Node           // the next item in the current sexp
	Children   []*Node         // the children of this sexp
	Attributes map[string]bool // special attributes for this node
	Original   string          // original line used before parsing

Node is a structure used to represent a parse tree.

In the node there are three fields, Value, Next, and Children. Value is the current token's string value. Next is always the next non-child token, and children contains all the children. Here's an example:

(value next (child child-next child-next-next) next-next)

This data structure is frankly pretty lousy for handling complex languages, but lucky for us the Dockerfile isn't very complicated. This structure works a little more effectively than a "proper" parse tree for our needs.

func Parse

func Parse(rwc io.Reader) (*Node, error)

The main parse routine. Handles an io.ReadWriteCloser and returns the root of the AST.

func (*Node) Dump

func (node *Node) Dump() string

dumps the AST defined by `node` as a list of sexps. Returns a string suitable for printing.


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL