parser

package
v1.1.3-0...-30d0c38 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package parser implements a parser and parse tree dumper for Dockerfiles.

Index

Constants

View Source
const DefaultEscapeToken = "\\"

DefaultEscapeToken is the default escape token

Variables

This section is empty.

Functions

func SetEscapeToken

func SetEscapeToken(s string, d *Directive) error

SetEscapeToken sets the default token for escaping characters in a Dockerfile.

Types

type Directive

type Directive struct {
	EscapeToken           rune           // Current escape token
	LineContinuationRegex *regexp.Regexp // Current line contination regex
	LookingForDirectives  bool           // Whether we are currently looking for directives
	EscapeSeen            bool           // Whether the escape directive has been seen
}

Directive is the structure used during a build run to hold the state of parsing directives.

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
	Flags      []string        // only top Node should have this set
	StartLine  int             // the line in the original dockerfile where the node begins
	EndLine    int             // the line in the original dockerfile where the node ends
}

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, d *Directive) (*Node, error)

Parse is the main parse routine. It handles an io.ReadWriteCloser and returns the root of the AST.

func ParseLine

func ParseLine(line string, d *Directive, ignoreCont bool) (string, *Node, error)

ParseLine parses a line and returns the remainder.

func (*Node) Dump

func (node *Node) Dump() string

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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