ast

package
v0.0.0-...-1bc8c79 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ast implements a (low level) parser and parse tree dumper for Dockerfiles.

Index

Constants

View Source
const DefaultEscapeToken = '\\'

DefaultEscapeToken is the default escape token

View Source
const (
	UnknownInstMsg = "unknown instruction"
)

Variables

View Source
var (
	ErrDockerfileNotStringArray = errors.New("when using JSON array syntax, arrays must be comprised of strings only")
)
View Source
var (
	ErrDockerfileUnknownInst = errors.New(UnknownInstMsg)
)

Functions

This section is empty.

Types

type Directive

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

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

func NewDefaultDirective

func NewDefaultDirective() *Directive

NewDefaultDirective returns a new Directive with the default escapeToken token

type NameValError

type NameValError struct {
	ParseError
}

type NewFormatNameValError

type NewFormatNameValError struct {
	NameValError
}

type Node

type Node struct {
	IsValid    bool
	Errors     []string
	Value      string // actual content
	ArgsRaw    string
	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 (*Node) AddChild

func (node *Node) AddChild(child *Node, startLine, endLine int)

AddChild adds a new child node, and updates line information

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.

type OldFormatNameValError

type OldFormatNameValError struct {
	NameValError
}

type ParseError

type ParseError struct {
	Context string
	Data    string
	Message string
}

func (ParseError) Error

func (e ParseError) Error() string

type Result

type Result struct {
	Lines       []string
	AST         *Node
	EscapeToken rune
	Warnings    []string
}

Result is the result of parsing a Dockerfile

func Parse

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

Parse reads lines from a Reader, parses the lines into an AST and returns the AST and escape token

func (*Result) PrintWarnings

func (r *Result) PrintWarnings(out io.Writer)

PrintWarnings to the writer

Jump to

Keyboard shortcuts

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