<commit_before>package dockerpatch

import (
	"bytes"
	"fmt"
	"io"
	"strings"

	"github.com/docker/docker/builder/dockerfile/command"
	"github.com/docker/docker/builder/dockerfile/parser"
)

type Dockerfile struct {
	root *parser.Node
}

// DockerfileNew returns an empty Dockerfile
func DockerfileNew() *Dockerfile {
	dockerfile, _ := DockerfileFromString("")
	return dockerfile
}

// DockerfileFromString reads a Dockerfiler as string
func DockerfileFromString(input string) (*Dockerfile, error) {
	payload := new(bytes.Buffer)
	payload.Write([]byte(input))
	return DockerfileRead(payload)
}

// DockerfileRead reads a Dockerfile as io.Reader
func DockerfileRead(input io.Reader) (*Dockerfile, error) {
	dockerfile := Dockerfile{}

	root, err := parser.Parse(input)
	if err != nil {
		return nil, err
	}
	dockerfile.root = root

	return &dockerfile, nil
}

func (d *Dockerfile) RemoveAt(i int) error {
	if i >= 0 && i < d.Length() {
		d.root.Children = append(d.root.Children[:i], d.root.Children[i+1:]...)
		return nil
	}
	return fmt.Errorf("Cannot remove %d: index error", i)
}

// String returns a docker-readable Dockerfile
func (d *Dockerfile) String() string {
	lines := []string{}
	for _, child := range d.root.Children {<commit_msg>Update to work with Docker v1.13.0 parser API<commit_after>package dockerpatch

import (
	"bytes"
	"fmt"
	"io"
	"strings"

	"github.com/docker/docker/builder/dockerfile/command"
	"github.com/docker/docker/builder/dockerfile/parser"
)

type Dockerfile struct {
	root *parser.Node
}

// DockerfileNew returns an empty Dockerfile
func DockerfileNew() *Dockerfile {
	dockerfile, _ := DockerfileFromString("")
	return dockerfile
}

// DockerfileFromString reads a Dockerfiler as string
func DockerfileFromString(input string) (*Dockerfile, error) {
	payload := new(bytes.Buffer)
	payload.Write([]byte(input))
	return DockerfileRead(payload)
}

// DockerfileRead reads a Dockerfile as io.Reader
func DockerfileRead(input io.Reader) (*Dockerfile, error) {
	dockerfile := Dockerfile{}

	d := parser.Directive{LookingForDirectives: true}
	parser.SetEscapeToken(parser.DefaultEscapeToken, &d)
	root, err := parser.Parse(input, &d)
	if err != nil {
		return nil, err
	}
	dockerfile.root = root

	return &dockerfile, nil
}

func (d *Dockerfile) RemoveAt(i int) error {
	if i >= 0 && i < d.Length() {
		d.root.Children = append(d.root.Children[:i], d.root.Children[i+1:]...)
		return nil
	}
	return fmt.Errorf("Cannot remove %d: index error", i)
}

// String returns a docker-readable Dockerfile
func (d *Dockerfile) String() string {
	lines := []string{}
	for _, child := range d.root.Children {
{'fraction_non_alphanumeric': 0.1340952380952381, 'fraction_numerical': 0.0030476190476190477, 'mean_word_length': 4.611111111111111, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '54944', 'n_tokens_mistral': 948, 'n_tokens_neox': 868, 'n_words': 229}