package parser
import "github.com/moby/buildkit/frontend/dockerfile/parser"
Package parser implements a parser and parse tree dumper for Dockerfiles.
Index ¶
- Constants
- func ChompHeredocContent(src string) string
- func WithLocation(err error, location []Range) error
- type ErrorLocation
- type Heredoc
- type Node
- func (node *Node) AddChild(child *Node, startLine, endLine int)
- func (node *Node) Dump() string
- func (node *Node) Location() []Range
- type Position
- type Range
- type Result
- type Warning
Constants ¶
const DefaultEscapeToken = '\\'
DefaultEscapeToken is the default escape token
Functions ¶
func ChompHeredocContent ¶
func WithLocation ¶
WithLocation extends an error with a source code location
Types ¶
type ErrorLocation ¶
type ErrorLocation struct { Location []Range // contains filtered or unexported fields }
ErrorLocation gives a location in source code that caused the error
func (*ErrorLocation) Unwrap ¶
func (e *ErrorLocation) Unwrap() error
Unwrap unwraps to the next error
type Heredoc ¶
func MustParseHeredoc ¶
func ParseHeredoc ¶
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 Heredocs []Heredoc // extra heredoc content attachments 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 PrevComment []string }
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 ¶
AddChild adds a new child node, and updates line information
func (*Node) Dump ¶
Dump dumps the AST defined by `node` as a list of sexps. Returns a string suitable for printing.
func (*Node) Location ¶
Location return the location of node in source code
type Position ¶
Position is a point in source code
type Range ¶
Range is a code section between two positions
type Result ¶
Result is the result of parsing a Dockerfile
func Parse ¶
Parse reads lines from a Reader, parses the lines into an AST and returns the AST and escape token
func (*Result) PrintWarnings ¶
PrintWarnings to the writer
type Warning ¶
Source Files ¶
errors.go line_parsers.go parser.go split_command.go
Directories ¶
Path | Synopsis |
---|---|
frontend/dockerfile/parser/dumper |
- Version
- v0.10.6
- Published
- Nov 10, 2022
- Platform
- js/wasm
- Imports
- 14 packages
- Last checked
- 12 hours ago –
Tools for package owners.