forked from fealebenpae/node-xcode
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpbxproj.pegjs
273 lines (218 loc) · 5.23 KB
/
pbxproj.pegjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
{
function merge(hash, secondHash) {
secondHash = secondHash[0]
for(var i in secondHash) {
hash[i] = merge_obj(hash[i], secondHash[i]);
}
return hash;
}
function merge_obj(obj, secondObj) {
if (!obj)
return secondObj;
for(var i in secondObj)
obj[i] = merge_obj(obj[i], secondObj[i]);
return obj;
}
}
/*
* Project: point of entry from pbxproj file
*/
Project
= headComment:SingleLineComment? InlineComment? _ obj:Object NewLine _
{
var proj = Object.create(null)
proj.project = obj
if (headComment) {
proj.headComment = headComment
}
return proj;
}
/*
* Object: basic hash data structure with Assignments
*/
Object
= "{" obj:(AssignmentList / EmptyBody) "}"
{ return obj }
EmptyBody
= _
{ return Object.create(null) }
AssignmentList
= _ head:Assignment _ tail:AssignmentList* _
{
if (tail) return merge(head,tail)
else return head
}
/ _ head:DelimitedSection _ tail:AssignmentList*
{
if (tail) return merge(head,tail)
else return head
}
/*
* Assignments
* can be simple "key = value"
* or commented "key /* real key * / = value"
*/
Assignment
= SimpleAssignment / CommentedAssignment
SimpleAssignment
= id:Identifier _ "=" _ val:Value ";"
{
var result = Object.create(null);
result[id] = val
return result
}
CommentedAssignment
= commentedId:CommentedIdentifier _ "=" _ val:Value ";"
{
var result = Object.create(null),
commentKey = commentedId.id + '_comment';
result[commentedId.id] = val;
result[commentKey] = commentedId[commentKey];
return result;
}
/
id:Identifier _ "=" _ commentedVal:CommentedValue ";"
{
var result = Object.create(null);
result[id] = commentedVal.value;
result[id + "_comment"] = commentedVal.comment;
return result;
}
CommentedIdentifier
= id:Identifier _ comment:InlineComment
{
var result = Object.create(null);
result.id = id;
result[id + "_comment"] = comment.trim();
return result
}
CommentedValue
= literal:Value _ comment:InlineComment
{
var result = Object.create(null)
result.comment = comment.trim();
result.value = literal.trim();
return result;
}
InlineComment
= InlineCommentOpen body:[^*]+ InlineCommentClose
{ return body.join('') }
InlineCommentOpen
= "/*"
InlineCommentClose
= "*/"
/*
* DelimitedSection - ad hoc project structure pbxproj files use
*/
DelimitedSection
= begin:DelimitedSectionBegin _ fields:(AssignmentList / EmptyBody) _ DelimitedSectionEnd
{
var section = Object.create(null);
section[begin.name] = fields
return section
}
DelimitedSectionBegin
= "/* Begin " sectionName:Identifier " section */" NewLine
{ return { name: sectionName } }
DelimitedSectionEnd
= "/* End " sectionName:Identifier " section */" NewLine
{ return { name: sectionName } }
/*
* Arrays: lists of values, possible wth comments
*/
Array
= "(" arr:(ArrayBody / EmptyArray ) ")" { return arr }
EmptyArray
= _ { return [] }
ArrayBody
= _ head:ArrayEntry _ tail:ArrayBody? _
{
if (tail) {
tail.unshift(head);
return tail;
} else {
return [head];
}
}
ArrayEntry
= SimpleArrayEntry / CommentedArrayEntry
SimpleArrayEntry
= val:Value EndArrayEntry { return val }
CommentedArrayEntry
= val:Value _ comment:InlineComment EndArrayEntry
{
var result = Object.create(null);
result.value = val.trim();
result.comment = comment.trim();
return result;
}
EndArrayEntry
= "," / _ &")"
/*
* Identifiers and Values
*/
Identifier
= id:[A-Za-z0-9_.]+ { return id.join('') }
/ QuotedString
Value
= Object / Array / NumberValue / StringValue
NumberValue
= DecimalValue / IntegerValue
DecimalValue
= decimal:(IntegerValue "." IntegerValue)
{
// store decimals as strings
// as JS doesn't differentiate bw strings and numbers
return decimal.join('')
}
IntegerValue
= !Alpha number:Digit+ !NonTerminator
{ return parseInt(number.join(''), 10) }
StringValue
= QuotedString / LiteralString
QuotedString
= DoubleQuote str:QuotedBody DoubleQuote { return '"' + str + '"' }
QuotedBody
= str:NonQuote+ { return str.join('') }
NonQuote
= EscapedQuote / !DoubleQuote char:. { return char }
EscapedQuote
= "\\" DoubleQuote { return '\\"' }
LiteralString
= literal:LiteralChar+ { return literal.join('') }
LiteralChar
= !InlineCommentOpen !LineTerminator char:NonTerminator
{ return char }
NonTerminator
= [^;,\n]
/*
* SingleLineComment - used for the encoding comment
*/
SingleLineComment
= "//" _ contents:OneLineString NewLine
{ return contents }
OneLineString
= contents:NonLine*
{ return contents.join('') }
/*
* Simple character checking rules
*/
Digit
= [0-9]
Alpha
= [A-Za-z]
DoubleQuote
= '"'
_ "whitespace"
= whitespace*
whitespace
= NewLine / [\t ]
NonLine
= !NewLine char:Char
{ return char }
LineTerminator
= NewLine / ";"
NewLine
= [\n\r]
Char
= .