Repositorio del curso CCOM4030 el semestre B91 del proyecto kilometro0

pbxproj.pegjs 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /**
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. 'License'); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. {
  18. function merge_obj(obj, secondObj) {
  19. if (!obj)
  20. return secondObj;
  21. for(var i in secondObj)
  22. obj[i] = merge_obj(obj[i], secondObj[i]);
  23. return obj;
  24. }
  25. }
  26. /*
  27. * Project: point of entry from pbxproj file
  28. */
  29. Project
  30. = headComment:SingleLineComment? InlineComment? _ obj:Object NewLine _
  31. {
  32. var proj = Object.create(null)
  33. proj.project = obj
  34. if (headComment) {
  35. proj.headComment = headComment
  36. }
  37. return proj;
  38. }
  39. /*
  40. * Object: basic hash data structure with Assignments
  41. */
  42. Object
  43. = "{" obj:(AssignmentList / EmptyBody) "}"
  44. { return obj }
  45. EmptyBody
  46. = _
  47. { return Object.create(null) }
  48. AssignmentList
  49. = _ list:((a:Assignment / d:DelimitedSection) _)+
  50. {
  51. var returnObject = list[0][0];
  52. for(var i = 1; i < list.length; i++){
  53. var another = list[i][0];
  54. returnObject = merge_obj(returnObject, another);
  55. }
  56. return returnObject;
  57. }
  58. /*
  59. * Assignments
  60. * can be simple "key = value"
  61. * or commented "key /* real key * / = value"
  62. */
  63. Assignment
  64. = SimpleAssignment / CommentedAssignment
  65. SimpleAssignment
  66. = id:Identifier _ "=" _ val:Value ";"
  67. {
  68. var result = Object.create(null);
  69. result[id] = val
  70. return result
  71. }
  72. CommentedAssignment
  73. = commentedId:CommentedIdentifier _ "=" _ val:Value ";"
  74. {
  75. var result = Object.create(null),
  76. commentKey = commentedId.id + '_comment';
  77. result[commentedId.id] = val;
  78. result[commentKey] = commentedId[commentKey];
  79. return result;
  80. }
  81. /
  82. id:Identifier _ "=" _ commentedVal:CommentedValue ";"
  83. {
  84. var result = Object.create(null);
  85. result[id] = commentedVal.value;
  86. result[id + "_comment"] = commentedVal.comment;
  87. return result;
  88. }
  89. CommentedIdentifier
  90. = id:Identifier _ comment:InlineComment
  91. {
  92. var result = Object.create(null);
  93. result.id = id;
  94. result[id + "_comment"] = comment.trim();
  95. return result
  96. }
  97. CommentedValue
  98. = literal:Value _ comment:InlineComment
  99. {
  100. var result = Object.create(null)
  101. result.comment = comment.trim();
  102. result.value = literal.trim();
  103. return result;
  104. }
  105. InlineComment
  106. = InlineCommentOpen body:[^*]+ InlineCommentClose
  107. { return body.join('') }
  108. InlineCommentOpen
  109. = "/*"
  110. InlineCommentClose
  111. = "*/"
  112. /*
  113. * DelimitedSection - ad hoc project structure pbxproj files use
  114. */
  115. DelimitedSection
  116. = begin:DelimitedSectionBegin _ fields:(AssignmentList / EmptyBody) _ DelimitedSectionEnd
  117. {
  118. var section = Object.create(null);
  119. section[begin.name] = fields
  120. return section
  121. }
  122. DelimitedSectionBegin
  123. = "/* Begin " sectionName:Identifier " section */" NewLine
  124. { return { name: sectionName } }
  125. DelimitedSectionEnd
  126. = "/* End " sectionName:Identifier " section */" NewLine
  127. { return { name: sectionName } }
  128. /*
  129. * Arrays: lists of values, possible wth comments
  130. */
  131. Array
  132. = "(" arr:(ArrayBody / EmptyArray ) ")" { return arr }
  133. EmptyArray
  134. = _ { return [] }
  135. ArrayBody
  136. = _ head:ArrayEntry _ tail:ArrayBody? _
  137. {
  138. if (tail) {
  139. tail.unshift(head);
  140. return tail;
  141. } else {
  142. return [head];
  143. }
  144. }
  145. ArrayEntry
  146. = SimpleArrayEntry / CommentedArrayEntry
  147. SimpleArrayEntry
  148. = val:Value EndArrayEntry { return val }
  149. CommentedArrayEntry
  150. = val:Value _ comment:InlineComment EndArrayEntry
  151. {
  152. var result = Object.create(null);
  153. result.value = val.trim();
  154. result.comment = comment.trim();
  155. return result;
  156. }
  157. EndArrayEntry
  158. = "," / _ &")"
  159. /*
  160. * Identifiers and Values
  161. */
  162. Identifier
  163. = id:[A-Za-z0-9_.]+ { return id.join('') }
  164. / QuotedString
  165. Value
  166. = Object / Array / NumberValue / StringValue
  167. NumberValue
  168. = DecimalValue / IntegerValue
  169. DecimalValue
  170. = decimal:(IntegerValue "." IntegerValue)
  171. {
  172. // store decimals as strings
  173. // as JS doesn't differentiate bw strings and numbers
  174. return decimal.join('')
  175. }
  176. IntegerValue
  177. = !Alpha number:Digit+ !NonTerminator
  178. { return parseInt(number.join(''), 10) }
  179. StringValue
  180. = QuotedString / LiteralString
  181. QuotedString
  182. = DoubleQuote str:QuotedBody DoubleQuote { return '"' + str + '"' }
  183. QuotedBody
  184. = str:NonQuote+ { return str.join('') }
  185. NonQuote
  186. = EscapedQuote / !DoubleQuote char:. { return char }
  187. EscapedQuote
  188. = "\\" DoubleQuote { return '\\"' }
  189. LiteralString
  190. = literal:LiteralChar+ { return literal.join('') }
  191. LiteralChar
  192. = !InlineCommentOpen !LineTerminator char:NonTerminator
  193. { return char }
  194. NonTerminator
  195. = [^;,\n]
  196. /*
  197. * SingleLineComment - used for the encoding comment
  198. */
  199. SingleLineComment
  200. = "//" _ contents:OneLineString NewLine
  201. { return contents }
  202. OneLineString
  203. = contents:NonLine*
  204. { return contents.join('') }
  205. /*
  206. * Simple character checking rules
  207. */
  208. Digit
  209. = [0-9]
  210. Alpha
  211. = [A-Za-z]
  212. DoubleQuote
  213. = '"'
  214. _ "whitespace"
  215. = whitespace*
  216. whitespace
  217. = NewLine / [\t ]
  218. NonLine
  219. = !NewLine char:Char
  220. { return char }
  221. LineTerminator
  222. = NewLine / ";"
  223. NewLine
  224. = [\n\r]
  225. Char
  226. = .