0551eba5 by Gary Katsevman

abstract some functionality into a shared function

1 parent 4b1e49f1
1 /***** Start *****/ 1 /***** Start *****/
2 {
3 function reduce(rest, attr) {
4 return rest.reduce(function(prev, curr) {
5 var p,
6 currentItem = curr.pop();
7 for (p in currentItem) {
8 prev[p] = currentItem[p];
9 };
10 return prev;
11 }, attr);
12 }
13 }
14
2 start 15 start
3 = tags:lines+ .* { 16 = tags:lines+ .* {
4 var choices = { 17 var choices = {
...@@ -135,16 +148,7 @@ mediaURL ...@@ -135,16 +148,7 @@ mediaURL
135 / ! tag file:[ -~]+ { return file.join(''); } 148 / ! tag file:[ -~]+ { return file.join(''); }
136 149
137 keyAttributes 150 keyAttributes
138 = (attr:keyAttribute rest:(attrSeparator streamInfAttrs)*) { 151 = (attr:keyAttribute rest:(attrSeparator streamInfAttrs)*) { return reduce(rest, attr); }
139 return rest.reduce(function(prev, curr) {
140 var p,
141 currentItem = curr.pop();
142 for (p in currentItem) {
143 prev[p] = currentItem[p];
144 };
145 return prev;
146 }, attr);
147 }
148 / attr:keyAttribute? { return [attr]; } 152 / attr:keyAttribute? { return [attr]; }
149 153
150 keyAttribute 154 keyAttribute
...@@ -160,16 +164,7 @@ keyMethod ...@@ -160,16 +164,7 @@ keyMethod
160 / "SAMPLE-AES" 164 / "SAMPLE-AES"
161 165
162 mediaAttributes 166 mediaAttributes
163 = (attr:mediaAttribute rest:(attrSeparator mediaAttribute)*) { 167 = (attr:mediaAttribute rest:(attrSeparator mediaAttribute)*) { return reduce(rest, attr); }
164 return rest.reduce(function(prev, curr) {
165 var p,
166 currentItem = curr.pop();
167 for (p in currentItem) {
168 prev[p] = currentItem[p];
169 };
170 return prev;
171 }, attr);
172 }
173 / attr:mediaAttribute? { return [attr] } 168 / attr:mediaAttribute? { return [attr] }
174 169
175 mediaAttribute 170 mediaAttribute
...@@ -186,16 +181,7 @@ mediaAttribute ...@@ -186,16 +181,7 @@ mediaAttribute
186 / "CHARACTERISTICS" "=" characteristics:quotedString { return {characteristics: characteristics}; } 181 / "CHARACTERISTICS" "=" characteristics:quotedString { return {characteristics: characteristics}; }
187 182
188 streamInfAttrs 183 streamInfAttrs
189 = (attr:streamInfAttr rest:(attrSeparator streamInfAttr)*) { 184 = (attr:streamInfAttr rest:(attrSeparator streamInfAttr)*) { return reduce(rest, attr); }
190 return rest.reduce(function(prev, curr) {
191 var p,
192 currentItem = curr.pop();
193 for (p in currentItem) {
194 prev[p] = currentItem[p];
195 };
196 return prev;
197 }, attr);
198 }
199 / attr:streamInfAttr? 185 / attr:streamInfAttr?
200 186
201 streamInfAttr 187 streamInfAttr
...@@ -213,16 +199,7 @@ streamInfSharedAttr ...@@ -213,16 +199,7 @@ streamInfSharedAttr
213 / "VIDEO" "=" video:quotedString { return {video: video}; } 199 / "VIDEO" "=" video:quotedString { return {video: video}; }
214 200
215 mapAttributes 201 mapAttributes
216 = (attr:mapAttribute rest:(attrSeparator mapAttribute)*) { 202 = (attr:mapAttribute rest:(attrSeparator mapAttribute)*) { return reduce(rest, attr); }
217 return rest.reduce(function(prev, curr) {
218 var p,
219 currentItem = curr.pop();
220 for (p in currentItem) {
221 prev[p] = currentItem[p];
222 };
223 return prev;
224 }, attr);
225 }
226 / attr:mapAttribute? 203 / attr:mapAttribute?
227 204
228 mapAttribute 205 mapAttribute
...@@ -230,16 +207,7 @@ mapAttribute ...@@ -230,16 +207,7 @@ mapAttribute
230 / "BYTERANGE" "=" byteRange:quotedString { return {byterange: byterange}; } 207 / "BYTERANGE" "=" byteRange:quotedString { return {byterange: byterange}; }
231 208
232 iframeStreamAttrs 209 iframeStreamAttrs
233 = (attr:iframeStreamAttr rest:(attrSeparator iframeStreamAttr)*) { 210 = (attr:iframeStreamAttr rest:(attrSeparator iframeStreamAttr)*) { return reduce(rest, attr); }
234 return rest.reduce(function(prev, curr) {
235 var p,
236 currentItem = curr.pop();
237 for (p in currentItem) {
238 prev[p] = currentItem[p];
239 };
240 return prev;
241 }, attr);
242 }
243 / attr:iframeStreamAttr? 211 / attr:iframeStreamAttr?
244 212
245 iframeStreamAttr 213 iframeStreamAttr
...@@ -247,16 +215,7 @@ iframeStreamAttr ...@@ -247,16 +215,7 @@ iframeStreamAttr
247 / "URI" "=" uri:quotedString { return {uri: uri}; } 215 / "URI" "=" uri:quotedString { return {uri: uri}; }
248 216
249 startAttributes 217 startAttributes
250 = (attr:startAttribute rest:(attrSeparator startAttribute)*) { 218 = (attr:startAttribute rest:(attrSeparator startAttribute)*) { return reduce(rest, attr); }
251 return rest.reduce(function(prev, curr) {
252 var p,
253 currentItem = curr.pop();
254 for (p in currentItem) {
255 prev[p] = currentItem[p];
256 };
257 return prev;
258 }, attr);
259 }
260 / attr:startAttribute? 219 / attr:startAttribute?
261 220
262 startAttribute 221 startAttribute
......