martine/ninja — Issue #183: Indented comments in rule and build blocks cause silent errors
Author: evanj
Created: 2012-01-04 17:12:01+00:00
State: open

I was debugging a build.ninja file, so I commented a variable:

rule echo
command = echo in $in out $out
#restat = true
build example: echo

This causes ninja to exit without an error message. The same problem occurs if you comment a variable in a build block. This should either:

1. Report a useful error message (eg. unexpected comment? Unexpected indent?)
2. Ignore the commented line

It seems to me like #2 is more like what people would expect, and is more generally useful. I did some debugging to see if I could fix this, but it is going to require some lexer / parser changes. I'm happy to make a patch, but thought I should discuss it first.

The problem:

In ParseRule(), it sees the intent token before the comment, so it calls ParseLet(). This fails to parse an identifier, so it fails to parse. However, it also doesn't set any error message.

Proposed solution:

Add a PeekComment() method to Lexer. We will try this before calling ParseLet(). If it succeeds, we will ignore the line and continue. This will need to be done in both ParseBuild() and ParseRule()