Skip to content

Commit 2595be0

Browse files
committed
first pass at grammar
doesn't work with Objects as values right now
1 parent 3fce2a9 commit 2595be0

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

examples/simple.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
objectVersion = 45;
5+
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
6+
}

pbxproj.pegjs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
function merge(hash, secondHash) {
3+
secondHash = secondHash[0]
4+
for(var i in secondHash)
5+
hash[i] = secondHash[i]
6+
7+
return hash;
8+
}
9+
}
10+
11+
Project
12+
= headComment:SingleLineComment? obj:Object NewLine
13+
{
14+
var proj = Object.create(null)
15+
proj.project = obj
16+
17+
if (headComment) {
18+
proj.headComment = headComment
19+
}
20+
21+
return proj;
22+
}
23+
24+
Anything
25+
= Char / EOF
26+
27+
Object
28+
= "{" obj:Definition "}"
29+
{ return obj }
30+
31+
Definition
32+
= _ head:Assignment _ tail:((Definition)*) _
33+
{
34+
if (tail) return merge(head,tail)
35+
else return head
36+
}
37+
38+
Assignment
39+
= id:Identifier _ "=" _ val:Value ";"
40+
{
41+
var result = Object.create(null);
42+
result[id.join('')] = val.join('')
43+
return result
44+
}
45+
46+
Identifier
47+
= [A-Za-z0-9]+
48+
49+
Value
50+
= [^;\n]+ / Object
51+
52+
SingleLineComment
53+
= "//" _ contents:OneLineString NewLine
54+
{ return contents }
55+
56+
Terminator
57+
= NewLine? EOF
58+
59+
OneLineString
60+
= contents:NonLine*
61+
{ return contents.join('') }
62+
63+
_ "whitespace"
64+
= whitespace*
65+
66+
whitespace
67+
= NewLine / [\t ]
68+
69+
NonLine
70+
= !NewLine char:Char
71+
{ return char }
72+
73+
NewLine
74+
= [\n\r]
75+
76+
EOF
77+
= !.
78+
79+
String
80+
= str:Char*
81+
{ return str.join('') }
82+
83+
Char
84+
= .

0 commit comments

Comments
 (0)