mirror of https://github.com/docker/docs.git
Merge pull request #8370 from duglin/ParserIndent
Fix builder/parser so it keeps some whitespace on split lines.
This commit is contained in:
commit
7bd482d570
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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")
|
Loading…
Reference in New Issue