Skip to content

Commit d00b983

Browse files
committed
[parser] support comments before the proj obj
1 parent aab13d6 commit d00b983

File tree

5 files changed

+76
-7
lines changed

5 files changed

+76
-7
lines changed

lib/parser/pbxproj.js

Lines changed: 25 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/parser/pbxproj.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Project: point of entry from pbxproj file
1313
*/
1414
Project
15-
= headComment:SingleLineComment? obj:Object NewLine
15+
= headComment:SingleLineComment? InlineComment? _ obj:Object NewLine _
1616
{
1717
var proj = Object.create(null)
1818
proj.project = obj

test/parser/comments.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var PEG = require('pegjs'),
2+
fs = require('fs'),
3+
pbx = fs.readFileSync('test/parser/projects/comments.pbxproj', 'utf-8'),
4+
grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'),
5+
parser = PEG.buildParser(grammar);
6+
7+
// Cordova 1.8 has the Apache headers as comments in the pbxproj file
8+
// I DON'T KNOW WHY
9+
exports['should ignore comments outside the main object'] = function (test) {
10+
parser.parse(pbx);
11+
test.done();
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// !$*UTF8*$!
2+
/*
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one
5+
# or more contributor license agreements. See the NOTICE file
6+
# distributed with this work for additional information
7+
# regarding copyright ownership. The ASF licenses this file
8+
# to you under the Apache License, Version 2.0 (the
9+
# "License"); you may not use this file except in compliance
10+
# with the License. You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing,
15+
# software distributed under the License is distributed on an
16+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
# KIND, either express or implied. See the License for the
18+
# specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
*/
22+
{
23+
archiveVersion = 1;
24+
classes = {
25+
};
26+
objectVersion = 45;
27+
nonObject = 29B97313FDCFA39411CA2CEF;
28+
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
29+
}
30+

test/pbxProject.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ exports['parse function'] = {
4848
test.done();
4949
})
5050
},
51+
'should handle projects with comments in the header': function (test) {
52+
var myProj = new pbx('test/parser/projects/comments.pbxproj');
53+
54+
myProj.parse(function (err, projHash) {
55+
test.ok(projHash);
56+
test.done();
57+
})
58+
},
5159
'should attach the hash object to the pbx object': function (test) {
5260
var myProj = new pbx('test/parser/projects/hash.pbxproj');
5361

0 commit comments

Comments
 (0)