CMake: pro2cmake.py: Handle for loops without block

Handle for loops with a single line of instructions and add a test
for that.

Change-Id: I041ae30f64abcbd3db7df29933647f047b92ede3
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Tobias Hunger 2019-02-27 15:31:29 +01:00
parent 33fe56c630
commit f2e968b245
3 changed files with 13 additions and 1 deletions

View File

@ -568,11 +568,13 @@ class QmakeParser:
+ pp.nestedExpr(opener='{', closer='}', ignoreExpr=pp.LineEnd())) # ignore the whole thing...
ForLoop = pp.Suppress(pp.Keyword('for') + CallArgs
+ pp.nestedExpr(opener='{', closer='}', ignoreExpr=pp.LineEnd())) # ignore the whole thing...
ForLoopSingleLine = pp.Suppress(pp.Keyword('for') + CallArgs
+ pp.Literal(':') + pp.SkipTo(EOL, ignore=LC)) # ignore the whole thing...
FunctionCall = pp.Suppress(Identifier + pp.nestedExpr())
Scope = pp.Forward()
Statement = pp.Group(Load | Include | Option | ForLoop \
Statement = pp.Group(Load | Include | Option | ForLoop | ForLoopSingleLine \
| DefineTestDefinition | FunctionCall | Operation)
StatementLine = Statement + (EOL | pp.FollowedBy('}'))
StatementGroup = pp.ZeroOrMore(StatementLine | Scope | pp.Suppress(EOL))

View File

@ -0,0 +1,4 @@
for(d, sd): \
exists($$d/$${d}.pro): \
SUBDIRS += $$d

View File

@ -180,6 +180,12 @@ def test_for():
assert result[1] == []
def test_single_line_for():
result = parse_file(_tests_path + '/data/single_line_for.pro')
assert len(result) == 1
assert result[0] == []
def test_unset():
result = parse_file(_tests_path + '/data/unset.pro')
assert len(result) == 1