ninja-build / ninja

a small build system with a focus on speed
https://ninja-build.org/
Apache License 2.0
11.25k stars 1.6k forks source link

ReadToken treats comments as line continuators #1519

Open rprichard opened 5 years ago

rprichard commented 5 years ago

I suppose it's harmless, but this seems unexpected?

myvar # Continue on the next line.
      # Keep going...
= foo

rule echo
  # We want to continue ignoring this line, though.
  # It's tested in ParserTest.IgnoreIndentedComments.
  command = echo $out

build $myvar : echo

Output:

$ ninja 
[1/1] echo foo
foo

A line-continuation comment isn't accepted in places where a path or binding value are parsed. AFAICT, a binding's = symbol is the only place where a comment can be used as a line-continuation.

rprichard commented 5 years ago

This issue also manifests when Ninja is trying to read a newline token. e.g. Ninja rejects this:

rule echo # end-of-line comment
  command = echo $out
build foo : echo

output:

$ ninja
ninja: error: build.ninja:2: expected newline, got indent

However, it accepts this:

rule echo # end-of-line comment

  command = echo $out
build foo : echo

output:

$ ninja
[1/1] echo foo
foo
rprichard commented 5 years ago

Ninja rejects this:

rule r
  command = r

  generator = 1

It's tested in manifest_parser_test.cc -- grep for input:4: unexpected indent.

Maybe this issue can be fixed by:

PeekIndent duplicates some of ReadToken, which is a bit unfortunate. It seems to work, though.