Fix comments with continuation

Backgound: aog/919954 tried to handle
```
   second line
```

but did it incorrectly. The parser works correctly (so this change
reverts aog/919954), it returns multiline comment, but the serializer
converting the internal representation to Blueprint was not emitting
'//' on the lines after the first.

Test: treehugger
Bug: 127521510
Change-Id: I0257a8b3cc4ffcaa6bea44113ceba66bb99d7e43
This commit is contained in:
Sasha Smundak 2020-11-19 02:20:40 -08:00
parent b479459ac9
commit 7890211d58
3 changed files with 10 additions and 9 deletions

View File

@ -137,7 +137,14 @@ func ConvertFile(filename string, buffer *bytes.Buffer) (string, []error) {
switch x := node.(type) { switch x := node.(type) {
case *mkparser.Comment: case *mkparser.Comment:
file.insertComment("//" + x.Comment) // Split the comment on escaped newlines and then
// add each chunk separately.
chunks := strings.Split(x.Comment, "\\\n")
file.insertComment("//" + chunks[0])
for i := 1; i < len(chunks); i++ {
file.bpPos.Line++
file.insertComment("//" + chunks[i])
}
case *mkparser.Assignment: case *mkparser.Assignment:
handleAssignment(file, x, assignmentCond) handleAssignment(file, x, assignmentCond)
case *mkparser.Directive: case *mkparser.Directive:

View File

@ -1260,10 +1260,10 @@ prebuilt_firmware {
desc: "comment with ESC", desc: "comment with ESC",
in: ` in: `
# Comment line 1 \ # Comment line 1 \
# Comment line 2 Comment line 2
`, `,
expected: ` expected: `
// Comment line 1 \ // Comment line 1
// Comment line 2 // Comment line 2
`, `,
}, },

View File

@ -497,12 +497,6 @@ loop:
switch p.tok { switch p.tok {
case '\\': case '\\':
p.parseEscape() p.parseEscape()
if p.tok == '\n' {
// Special case: '\' does not "escape" newline in comment (b/127521510)
comment += "\\"
p.accept(p.tok)
break loop
}
comment += "\\" + p.scanner.TokenText() comment += "\\" + p.scanner.TokenText()
p.accept(p.tok) p.accept(p.tok)
case '\n': case '\n':