Merge pull request #8370 from duglin/ParserIndent

Fix builder/parser so it keeps some whitespace on split lines.
This commit is contained in:
Victor Vieux 2014-10-06 10:32:02 -07:00
commit 7bd482d570
10 changed files with 53 additions and 15 deletions

View File

@ -6,6 +6,7 @@ import (
"io"
"regexp"
"strings"
"unicode"
)
// Node is a structure used to represent a parse tree.
@ -96,14 +97,14 @@ func Parse(rwc io.Reader) (*Node, error) {
scanner := bufio.NewScanner(rwc)
for scanner.Scan() {
line, child, err := parseLine(strings.TrimSpace(scanner.Text()))
line, child, err := parseLine(strings.TrimLeftFunc(scanner.Text(), unicode.IsSpace))
if err != nil {
return nil, err
}
if line != "" && child == nil {
for scanner.Scan() {
newline := strings.TrimSpace(scanner.Text())
newline := scanner.Text()
if newline == "" {
continue

View File

@ -71,8 +71,8 @@ func TestTestData(t *testing.T) {
}
if ast.Dump()+"\n" != string(content) {
fmt.Fprintln(os.Stderr, ast.Dump())
fmt.Fprintln(os.Stderr, string(content))
fmt.Fprintln(os.Stderr, "Result:\n"+ast.Dump())
fmt.Fprintln(os.Stderr, "Expected:\n"+string(content))
t.Fatalf("%s: AST dump of dockerfile does not match result", dir.Name())
}

View File

@ -0,0 +1,28 @@
FROM ubuntu:14.04
RUN echo hello\
world\
goodnight \
moon\
light\
ning
RUN echo hello \
world
RUN echo hello \
world
RUN echo hello \
goodbye\
frog
RUN echo hello \
RUN echo hi \
\
world \
\
good\
\
night
RUN echo goodbye\
frog
RUN echo good\
bye\
frog

View File

@ -0,0 +1,9 @@
(from "ubuntu:14.04")
(run "echo hello world goodnight moon lightning")
(run "echo hello world")
(run "echo hello world")
(run "echo hello goodbyefrog")
(run "echo hello \\")
(run "echo hi world goodnight")
(run "echo goodbyefrog")
(run "echo goodbyefrog")