├── .gitignore
├── .travis.yml
├── Gruntfile.coffee
├── LICENSE-MIT
├── README.md
├── component.json
├── lib
├── compiler.js
└── parser.js
├── package.json
├── spec
├── compiler.coffee
└── runner.html
└── src
├── compiler.coffee
└── grammar.peg
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules/
2 | /components/
3 | npm-debug.log
4 | .DS_Store
5 | /browser/
6 | /spec/*.js
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "0.10"
4 | before_script:
5 | - npm install -g grunt-cli
6 |
--------------------------------------------------------------------------------
/Gruntfile.coffee:
--------------------------------------------------------------------------------
1 | module.exports = ->
2 | # Project configuration
3 | @initConfig
4 | pkg: @file.readJSON 'package.json'
5 |
6 | # Generate library from Peg grammar
7 | peg:
8 | parser:
9 | src: 'src/grammar.peg'
10 | dest: 'lib/parser.js'
11 |
12 | # Build the browser Component
13 | componentbuild:
14 | 'vfl-compiler':
15 | options:
16 | name: 'vfl-compiler'
17 | src: '.'
18 | dest: 'browser'
19 | scripts: true
20 | styles: false
21 |
22 | # JavaScript minification for the browser
23 | uglify:
24 | options:
25 | report: 'min'
26 | 'vfl-compiler':
27 | files:
28 | './browser/vfl-compiler.min.js': ['./browser/vfl-compiler.js']
29 |
30 | # Automated recompilation and testing when developing
31 | watch:
32 | files: ['spec/**/*.coffee', 'src/**/*.{coffee,peg}']
33 | tasks: ['test']
34 |
35 | # BDD tests on Node.js
36 | cafemocha:
37 | nodejs:
38 | src: ['spec/**/*.coffee']
39 | options:
40 | reporter: 'spec'
41 |
42 | # CoffeeScript compilation
43 | coffee:
44 | src:
45 | options:
46 | bare: true
47 | expand: true
48 | cwd: 'src'
49 | src: ['**/*.coffee']
50 | dest: 'lib'
51 | ext: '.js'
52 | spec:
53 | options:
54 | bare: true
55 | expand: true
56 | cwd: 'spec'
57 | src: ['**/*.coffee']
58 | dest: 'spec'
59 | ext: '.js'
60 |
61 | # BDD tests on browser
62 | mocha_phantomjs:
63 | all: ['spec/runner.html']
64 |
65 | # Grunt plugins used for building
66 | @loadNpmTasks 'grunt-peg'
67 | @loadNpmTasks 'grunt-component-build'
68 | @loadNpmTasks 'grunt-contrib-uglify'
69 |
70 | # Grunt plugins used for testing
71 | @loadNpmTasks 'grunt-cafe-mocha'
72 | @loadNpmTasks 'grunt-contrib-coffee'
73 | @loadNpmTasks 'grunt-mocha-phantomjs'
74 | @loadNpmTasks 'grunt-contrib-watch'
75 |
76 | @registerTask 'build', ['coffee:src', 'peg', 'componentbuild', 'uglify']
77 | @registerTask 'test', ['build', 'coffee:spec', 'cafemocha', 'mocha_phantomjs']
78 | @registerTask 'default', ['build']
79 |
--------------------------------------------------------------------------------
/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 The Grid
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | VFL to CCSS Compiler [](https://travis-ci.org/gss/vfl-compiler)
2 | =============
3 |
4 | This library compiles [GSS-flavored VFL](http://gridstylesheets.org/guides/vfl/) statements into [GSS-flavored CCSS](http://gridstylesheets.org/guides/ccss/) statements.
5 |
6 | ## Background
7 |
8 | Language specs inspired by Apple's [Visual Format Language](https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html) (VFL) and Greg Badros's [Constraint CSS](http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.101.4819) (CCSS).
9 |
10 |
11 | ## Documentation
12 |
13 | Please refer to .
14 |
--------------------------------------------------------------------------------
/component.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vfl-compiler",
3 | "description": "Visual Format Language compiler",
4 | "version": "1.1.3",
5 | "scripts": [
6 | "lib/compiler.js",
7 | "lib/parser.js"
8 | ],
9 | "dependencies": {
10 | "gss/error-reporter": "~0.1.0"
11 | },
12 | "main": "lib/compiler.js"
13 | }
14 |
--------------------------------------------------------------------------------
/lib/compiler.js:
--------------------------------------------------------------------------------
1 | var ErrorReporter, parse;
2 |
3 | if (typeof window !== "undefined" && window !== null) {
4 | parse = require('./parser').parse;
5 | } else {
6 | parse = require('../lib/parser').parse;
7 | }
8 |
9 | ErrorReporter = require('error-reporter');
10 |
11 | module.exports = {
12 | parse: function(source) {
13 | var columnNumber, error, errorReporter, lineNumber, message, results;
14 | results = null;
15 | try {
16 | results = parse(source);
17 | } catch (_error) {
18 | error = _error;
19 | errorReporter = new ErrorReporter(source);
20 | message = error.message, lineNumber = error.line, columnNumber = error.column;
21 | errorReporter.reportError(message, lineNumber, columnNumber);
22 | }
23 | return results;
24 | }
25 | };
26 |
--------------------------------------------------------------------------------
/lib/parser.js:
--------------------------------------------------------------------------------
1 | module.exports = (function() {
2 | /*
3 | * Generated by PEG.js 0.8.0.
4 | *
5 | * http://pegjs.majda.cz/
6 | */
7 |
8 | function peg$subclass(child, parent) {
9 | function ctor() { this.constructor = child; }
10 | ctor.prototype = parent.prototype;
11 | child.prototype = new ctor();
12 | }
13 |
14 | function SyntaxError(message, expected, found, offset, line, column) {
15 | this.message = message;
16 | this.expected = expected;
17 | this.found = found;
18 | this.offset = offset;
19 | this.line = line;
20 | this.column = column;
21 |
22 | this.name = "SyntaxError";
23 | }
24 |
25 | peg$subclass(SyntaxError, Error);
26 |
27 | function parse(input) {
28 | var options = arguments.length > 1 ? arguments[1] : {},
29 |
30 | peg$FAILED = {},
31 |
32 | peg$startRuleFunctions = { start: peg$parsestart },
33 | peg$startRuleFunction = peg$parsestart,
34 |
35 | peg$c0 = peg$FAILED,
36 | peg$c1 = [],
37 | peg$c2 = function() { return p.getResults(); },
38 | peg$c3 = function(vfl) { return p.getResults().concat(vfl); },
39 | peg$c4 = function(exp) { return exp; },
40 | peg$c5 = null,
41 | peg$c6 = function(d, head, tail, o) {
42 | var connection, result, ccss, chainedViews, withContainer,
43 | tailView, tailViewObj, headView, headViewObj;
44 | p.addSplatIfNeeded(head, d, o);
45 | result = head;
46 | headViewObj = head;
47 | headView = headViewObj.view;
48 | chainedViews = [];
49 | if (headView !== "|") {chainedViews.push(headView);}
50 | p.addPreds(headView,head.preds,d);
51 | for (var i = 0; i < tail.length; i++) {
52 | connection = tail[i][1];
53 | tailViewObj = tail[i][3];
54 | p.addSplatIfNeeded(tailViewObj, d, o);
55 | tailView = tailViewObj.view;
56 | if (tailView !== "|") {chainedViews.push(tailView);}
57 | p.addPreds(tailView,tail[i][3].preds,d);
58 | result = [
59 | //"c",
60 | connection,
61 | result,
62 | tailView
63 | ];
64 | if (!(headViewObj.isPoint && tailViewObj.isPoint)) {
65 | withContainer = ( headView =="|" || tailView === "|") && !(headViewObj.isPoint || tailViewObj.isPoint);
66 | ccss = p.getLeftVar(headView, d, o, headViewObj) + " "
67 | + p.getConnectionString(connection, d, o, withContainer) + " "
68 | + p.getRightVar(tailView, d, o, tailViewObj)
69 | + p.getTrailingOptions(o)
70 | + p.getSW(o);
71 | p.addC(
72 | ccss.trim()
73 | );}
74 | headViewObj = tailViewObj;
75 | headView = tailView;
76 | }
77 | p.addChains(chainedViews,o);
78 | return {'vfl':d, o:o};
79 | },
80 | peg$c7 = "@horizontal",
81 | peg$c8 = { type: "literal", value: "@horizontal", description: "\"@horizontal\"" },
82 | peg$c9 = "@-gss-horizontal",
83 | peg$c10 = { type: "literal", value: "@-gss-horizontal", description: "\"@-gss-horizontal\"" },
84 | peg$c11 = "@-gss-h",
85 | peg$c12 = { type: "literal", value: "@-gss-h", description: "\"@-gss-h\"" },
86 | peg$c13 = "@h",
87 | peg$c14 = { type: "literal", value: "@h", description: "\"@h\"" },
88 | peg$c15 = function() {return 0;},
89 | peg$c16 = "@vertical",
90 | peg$c17 = { type: "literal", value: "@vertical", description: "\"@vertical\"" },
91 | peg$c18 = "@-gss-vertical",
92 | peg$c19 = { type: "literal", value: "@-gss-vertical", description: "\"@-gss-vertical\"" },
93 | peg$c20 = "@-gss-v",
94 | peg$c21 = { type: "literal", value: "@-gss-v", description: "\"@-gss-v\"" },
95 | peg$c22 = "@v",
96 | peg$c23 = { type: "literal", value: "@v", description: "\"@v\"" },
97 | peg$c24 = function() {return 1;},
98 | peg$c25 = function(os) {
99 | var obj = {};
100 | obj.chains = [];
101 | for (var i = 0; i < os.length; i++) {
102 | // proccess chains
103 | if (!!os[i].chain) {
104 | obj.chains.push(os[i].chain);
105 | }
106 | // or just add option
107 | else {
108 | obj[os[i].key] = os[i].value;
109 | }
110 | }
111 | return obj;
112 | },
113 | peg$c26 = { type: "other", description: "Option" },
114 | peg$c27 = function(chain) { return chain; },
115 | peg$c28 = "in",
116 | peg$c29 = { type: "literal", value: "in", description: "\"in\"" },
117 | peg$c30 = "(",
118 | peg$c31 = { type: "literal", value: "(", description: "\"(\"" },
119 | peg$c32 = /^[^) ]/,
120 | peg$c33 = { type: "class", value: "[^) ]", description: "[^) ]" },
121 | peg$c34 = ")",
122 | peg$c35 = { type: "literal", value: ")", description: "\")\"" },
123 | peg$c36 = function(simple) {
124 | return {key:"in", value:simple.join('')};
125 | },
126 | peg$c37 = /^[^)]/,
127 | peg$c38 = { type: "class", value: "[^)]", description: "[^)]" },
128 | peg$c39 = function(complex) {
129 | return {key:"in", value:"(" + complex.join('') + ")"};
130 | },
131 | peg$c40 = function(key, value) {
132 | return {key:key.join(''), value:value.join('')};
133 | },
134 | peg$c41 = function(sw) {return {key:"sw",value:sw}; },
135 | peg$c42 = /^[^>=========]/,
191 | peg$c78 = { type: "class", value: "[^>]", description: "[^>]" },
192 | peg$c79 = ">",
193 | peg$c80 = { type: "literal", value: ">", description: "\">\"" },
194 | peg$c81 = function(position) {
195 | return p.stringify(position);
196 | },
197 | peg$c82 = { type: "other", description: "Predicate" },
198 | peg$c83 = function(preds) {return preds;},
199 | peg$c84 = { type: "other", description: "Predicate Expression" },
200 | peg$c85 = "==",
201 | peg$c86 = { type: "literal", value: "==", description: "\"==\"" },
202 | peg$c87 = "<=",
203 | peg$c88 = { type: "literal", value: "<=", description: "\"<=\"" },
204 | peg$c89 = ">=",
205 | peg$c90 = { type: "literal", value: ">=", description: "\">=\"" },
206 | peg$c91 = "=<",
207 | peg$c92 = { type: "literal", value: "=<", description: "\"=<\"" },
208 | peg$c93 = function() {return "<=";},
209 | peg$c94 = "=>",
210 | peg$c95 = { type: "literal", value: "=>", description: "\"=>\"" },
211 | peg$c96 = function() {return ">=";},
212 | peg$c97 = function(eq) {return eq;},
213 | peg$c98 = /^[+\-\/*]/,
214 | peg$c99 = { type: "class", value: "[+\\-\\/*]", description: "[+\\-\\/*]" },
215 | peg$c100 = function(op) {return op;},
216 | peg$c101 = function(name) {return ["view",name.join("")];},
217 | peg$c102 = function(n) {return n.join("");},
218 | peg$c103 = "[",
219 | peg$c104 = { type: "literal", value: "[", description: "\"[\"" },
220 | peg$c105 = "]",
221 | peg$c106 = { type: "literal", value: "]", description: "\"]\"" },
222 | peg$c107 = function(name) {return "[" + name.join("") + "]";},
223 | peg$c108 = function(view, prop) {return view.join("") + "[" + prop.join("") + "]";},
224 | peg$c109 = function() {return "";},
225 | peg$c110 = { type: "other", description: "VFL Connection" },
226 | peg$c111 = "-",
227 | peg$c112 = { type: "literal", value: "-", description: "\"-\"" },
228 | peg$c113 = function(gap) {return {op:"==",gap:gap};},
229 | peg$c114 = function() {return {op:"==",gap:"__STANDARD__"};},
230 | peg$c115 = "~",
231 | peg$c116 = { type: "literal", value: "~", description: "\"~\"" },
232 | peg$c117 = function(gap) {return {op:"<=",gap:gap};},
233 | peg$c118 = function() {return {op:"<=",gap:"__STANDARD__"};},
234 | peg$c119 = function() {return {op:"<="};},
235 | peg$c120 = "",
236 | peg$c121 = function() {return {op:"=="};},
237 | peg$c122 = "&",
238 | peg$c123 = { type: "literal", value: "&", description: "\"&\"" },
239 | peg$c124 = function(local) {
240 | if (local.length > 1) {
241 | throw new SyntaxError('Invalid local variable scope', null, null, null, line(), column());
242 | }
243 | return local.join("");
244 | },
245 | peg$c125 = "^",
246 | peg$c126 = { type: "literal", value: "^", description: "\"^\"" },
247 | peg$c127 = function(parent) {return parent.join("");},
248 | peg$c128 = "$",
249 | peg$c129 = { type: "literal", value: "$", description: "\"$\"" },
250 | peg$c130 = function(global) {
251 | if (global.length > 1) {
252 | throw new SyntaxError('Invalid global variable scope', null, null, null, line(), column());
253 | }
254 | return global.join("");
255 | },
256 | peg$c131 = { type: "other", description: "VFL Connection Gap" },
257 | peg$c132 = /^[a-zA-Z0-9_]/,
258 | peg$c133 = { type: "class", value: "[a-zA-Z0-9_]", description: "[a-zA-Z0-9_]" },
259 | peg$c134 = function(scope, gap) {return scope + gap.join("");},
260 | peg$c135 = function(gap) {return gap.join("");},
261 | peg$c136 = /^[^[]/,
262 | peg$c137 = { type: "class", value: "[^[]", description: "[^[]" },
263 | peg$c138 = /^[^\]]/,
264 | peg$c139 = { type: "class", value: "[^\\]]", description: "[^\\]]" },
265 | peg$c140 = function(gap, varr) {return gap.join("") + "[" + varr.join("") + "]";},
266 | peg$c141 = { type: "other", description: "Strength / Weight" },
267 | peg$c142 = "!",
268 | peg$c143 = { type: "literal", value: "!", description: "\"!\"" },
269 | peg$c144 = /^[a-zA-Z]/,
270 | peg$c145 = { type: "class", value: "[a-zA-Z]", description: "[a-zA-Z]" },
271 | peg$c146 = /^[0-9]/,
272 | peg$c147 = { type: "class", value: "[0-9]", description: "[0-9]" },
273 | peg$c148 = function(s, w) {
274 | var val;
275 | val = "!" + p.join(s) + p.join(w);
276 | return val.trim();
277 | },
278 | peg$c149 = { type: "any", description: "any character" },
279 | peg$c150 = function() {
280 | throw new SyntaxError('Invalid Strength or Weight', null, null, null, line(), column());
281 | },
282 | peg$c151 = /^[a-zA-Z0-9#.\-_$:""&]/,
283 | peg$c152 = { type: "class", value: "[a-zA-Z0-9#.\\-_$:\"\"&]", description: "[a-zA-Z0-9#.\\-_$:\"\"&]" },
284 | peg$c153 = " ",
285 | peg$c154 = { type: "literal", value: " ", description: "\" \"" },
286 | peg$c155 = function(val) {
287 | return [ "number",
288 | val
289 | ];
290 | },
291 | peg$c156 = function(digits) {
292 | return parseInt(digits.join(""), 10);
293 | },
294 | peg$c157 = ".",
295 | peg$c158 = { type: "literal", value: ".", description: "\".\"" },
296 | peg$c159 = function(digits) {
297 | return parseFloat(digits.join(""));
298 | },
299 | peg$c160 = /^[\-+]/,
300 | peg$c161 = { type: "class", value: "[\\-+]", description: "[\\-+]" },
301 | peg$c162 = { type: "other", description: "whitespace" },
302 | peg$c163 = /^[\t\x0B\f \xA0\uFEFF]/,
303 | peg$c164 = { type: "class", value: "[\\t\\x0B\\f \\xA0\\uFEFF]", description: "[\\t\\x0B\\f \\xA0\\uFEFF]" },
304 | peg$c165 = /^[\n\r\u2028\u2029]/,
305 | peg$c166 = { type: "class", value: "[\\n\\r\\u2028\\u2029]", description: "[\\n\\r\\u2028\\u2029]" },
306 | peg$c167 = { type: "other", description: "end of line" },
307 | peg$c168 = "\n",
308 | peg$c169 = { type: "literal", value: "\n", description: "\"\\n\"" },
309 | peg$c170 = "\r\n",
310 | peg$c171 = { type: "literal", value: "\r\n", description: "\"\\r\\n\"" },
311 | peg$c172 = "\r",
312 | peg$c173 = { type: "literal", value: "\r", description: "\"\\r\"" },
313 | peg$c174 = "\u2028",
314 | peg$c175 = { type: "literal", value: "\u2028", description: "\"\\u2028\"" },
315 | peg$c176 = "\u2029",
316 | peg$c177 = { type: "literal", value: "\u2029", description: "\"\\u2029\"" },
317 | peg$c178 = ";",
318 | peg$c179 = { type: "literal", value: ";", description: "\";\"" },
319 | peg$c180 = void 0,
320 | peg$c181 = { type: "other", description: "comment" },
321 | peg$c182 = "/*",
322 | peg$c183 = { type: "literal", value: "/*", description: "\"/*\"" },
323 | peg$c184 = "*/",
324 | peg$c185 = { type: "literal", value: "*/", description: "\"*/\"" },
325 | peg$c186 = "//",
326 | peg$c187 = { type: "literal", value: "//", description: "\"//\"" },
327 |
328 | peg$currPos = 0,
329 | peg$reportedPos = 0,
330 | peg$cachedPos = 0,
331 | peg$cachedPosDetails = { line: 1, column: 1, seenCR: false },
332 | peg$maxFailPos = 0,
333 | peg$maxFailExpected = [],
334 | peg$silentFails = 0,
335 |
336 | peg$result;
337 |
338 | if ("startRule" in options) {
339 | if (!(options.startRule in peg$startRuleFunctions)) {
340 | throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
341 | }
342 |
343 | peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
344 | }
345 |
346 | function text() {
347 | return input.substring(peg$reportedPos, peg$currPos);
348 | }
349 |
350 | function offset() {
351 | return peg$reportedPos;
352 | }
353 |
354 | function line() {
355 | return peg$computePosDetails(peg$reportedPos).line;
356 | }
357 |
358 | function column() {
359 | return peg$computePosDetails(peg$reportedPos).column;
360 | }
361 |
362 | function expected(description) {
363 | throw peg$buildException(
364 | null,
365 | [{ type: "other", description: description }],
366 | peg$reportedPos
367 | );
368 | }
369 |
370 | function error(message) {
371 | throw peg$buildException(message, null, peg$reportedPos);
372 | }
373 |
374 | function peg$computePosDetails(pos) {
375 | function advance(details, startPos, endPos) {
376 | var p, ch;
377 |
378 | for (p = startPos; p < endPos; p++) {
379 | ch = input.charAt(p);
380 | if (ch === "\n") {
381 | if (!details.seenCR) { details.line++; }
382 | details.column = 1;
383 | details.seenCR = false;
384 | } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
385 | details.line++;
386 | details.column = 1;
387 | details.seenCR = true;
388 | } else {
389 | details.column++;
390 | details.seenCR = false;
391 | }
392 | }
393 | }
394 |
395 | if (peg$cachedPos !== pos) {
396 | if (peg$cachedPos > pos) {
397 | peg$cachedPos = 0;
398 | peg$cachedPosDetails = { line: 1, column: 1, seenCR: false };
399 | }
400 | advance(peg$cachedPosDetails, peg$cachedPos, pos);
401 | peg$cachedPos = pos;
402 | }
403 |
404 | return peg$cachedPosDetails;
405 | }
406 |
407 | function peg$fail(expected) {
408 | if (peg$currPos < peg$maxFailPos) { return; }
409 |
410 | if (peg$currPos > peg$maxFailPos) {
411 | peg$maxFailPos = peg$currPos;
412 | peg$maxFailExpected = [];
413 | }
414 |
415 | peg$maxFailExpected.push(expected);
416 | }
417 |
418 | function peg$buildException(message, expected, pos) {
419 | function cleanupExpected(expected) {
420 | var i = 1;
421 |
422 | expected.sort(function(a, b) {
423 | if (a.description < b.description) {
424 | return -1;
425 | } else if (a.description > b.description) {
426 | return 1;
427 | } else {
428 | return 0;
429 | }
430 | });
431 |
432 | while (i < expected.length) {
433 | if (expected[i - 1] === expected[i]) {
434 | expected.splice(i, 1);
435 | } else {
436 | i++;
437 | }
438 | }
439 | }
440 |
441 | function buildMessage(expected, found) {
442 | function stringEscape(s) {
443 | function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
444 |
445 | return s
446 | .replace(/\\/g, '\\\\')
447 | .replace(/"/g, '\\"')
448 | .replace(/\x08/g, '\\b')
449 | .replace(/\t/g, '\\t')
450 | .replace(/\n/g, '\\n')
451 | .replace(/\f/g, '\\f')
452 | .replace(/\r/g, '\\r')
453 | .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
454 | .replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); })
455 | .replace(/[\u0180-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); })
456 | .replace(/[\u1080-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); });
457 | }
458 |
459 | var expectedDescs = new Array(expected.length),
460 | expectedDesc, foundDesc, i;
461 |
462 | for (i = 0; i < expected.length; i++) {
463 | expectedDescs[i] = expected[i].description;
464 | }
465 |
466 | expectedDesc = expected.length > 1
467 | ? expectedDescs.slice(0, -1).join(", ")
468 | + " or "
469 | + expectedDescs[expected.length - 1]
470 | : expectedDescs[0];
471 |
472 | foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
473 |
474 | return "Expected " + expectedDesc + " but " + foundDesc + " found.";
475 | }
476 |
477 | var posDetails = peg$computePosDetails(pos),
478 | found = pos < input.length ? input.charAt(pos) : null;
479 |
480 | if (expected !== null) {
481 | cleanupExpected(expected);
482 | }
483 |
484 | return new SyntaxError(
485 | message !== null ? message : buildMessage(expected, found),
486 | expected,
487 | found,
488 | pos,
489 | posDetails.line,
490 | posDetails.column
491 | );
492 | }
493 |
494 | function peg$parsestart() {
495 | var s0, s1, s2, s3;
496 |
497 | s0 = peg$currPos;
498 | s1 = peg$parse__();
499 | if (s1 !== peg$FAILED) {
500 | s2 = [];
501 | s3 = peg$parseStatement();
502 | while (s3 !== peg$FAILED) {
503 | s2.push(s3);
504 | s3 = peg$parseStatement();
505 | }
506 | if (s2 !== peg$FAILED) {
507 | s3 = peg$parse__();
508 | if (s3 !== peg$FAILED) {
509 | peg$reportedPos = s0;
510 | s1 = peg$c2();
511 | s0 = s1;
512 | } else {
513 | peg$currPos = s0;
514 | s0 = peg$c0;
515 | }
516 | } else {
517 | peg$currPos = s0;
518 | s0 = peg$c0;
519 | }
520 | } else {
521 | peg$currPos = s0;
522 | s0 = peg$c0;
523 | }
524 |
525 | return s0;
526 | }
527 |
528 | function peg$parsedebug() {
529 | var s0, s1, s2, s3;
530 |
531 | s0 = peg$currPos;
532 | s1 = peg$parse__();
533 | if (s1 !== peg$FAILED) {
534 | s2 = [];
535 | s3 = peg$parseStatement();
536 | while (s3 !== peg$FAILED) {
537 | s2.push(s3);
538 | s3 = peg$parseStatement();
539 | }
540 | if (s2 !== peg$FAILED) {
541 | s3 = peg$parse__();
542 | if (s3 !== peg$FAILED) {
543 | peg$reportedPos = s0;
544 | s1 = peg$c3(s2);
545 | s0 = s1;
546 | } else {
547 | peg$currPos = s0;
548 | s0 = peg$c0;
549 | }
550 | } else {
551 | peg$currPos = s0;
552 | s0 = peg$c0;
553 | }
554 | } else {
555 | peg$currPos = s0;
556 | s0 = peg$c0;
557 | }
558 |
559 | return s0;
560 | }
561 |
562 | function peg$parseStatement() {
563 | var s0, s1, s2, s3;
564 |
565 | s0 = peg$currPos;
566 | s1 = peg$parseVFLStatement();
567 | if (s1 !== peg$FAILED) {
568 | s2 = peg$parseEOS();
569 | if (s2 !== peg$FAILED) {
570 | s3 = peg$parse__();
571 | if (s3 !== peg$FAILED) {
572 | peg$reportedPos = s0;
573 | s1 = peg$c4(s1);
574 | s0 = s1;
575 | } else {
576 | peg$currPos = s0;
577 | s0 = peg$c0;
578 | }
579 | } else {
580 | peg$currPos = s0;
581 | s0 = peg$c0;
582 | }
583 | } else {
584 | peg$currPos = s0;
585 | s0 = peg$c0;
586 | }
587 |
588 | return s0;
589 | }
590 |
591 | function peg$parseVFLStatement() {
592 | var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
593 |
594 | s0 = peg$currPos;
595 | s1 = peg$parseDimension();
596 | if (s1 !== peg$FAILED) {
597 | s2 = peg$parse__();
598 | if (s2 !== peg$FAILED) {
599 | s3 = peg$parseView();
600 | if (s3 !== peg$FAILED) {
601 | s4 = [];
602 | s5 = peg$currPos;
603 | s6 = peg$parse__();
604 | if (s6 !== peg$FAILED) {
605 | s7 = peg$parseConnection();
606 | if (s7 === peg$FAILED) {
607 | s7 = peg$c5;
608 | }
609 | if (s7 !== peg$FAILED) {
610 | s8 = peg$parse__();
611 | if (s8 !== peg$FAILED) {
612 | s9 = peg$parseView();
613 | if (s9 !== peg$FAILED) {
614 | s6 = [s6, s7, s8, s9];
615 | s5 = s6;
616 | } else {
617 | peg$currPos = s5;
618 | s5 = peg$c0;
619 | }
620 | } else {
621 | peg$currPos = s5;
622 | s5 = peg$c0;
623 | }
624 | } else {
625 | peg$currPos = s5;
626 | s5 = peg$c0;
627 | }
628 | } else {
629 | peg$currPos = s5;
630 | s5 = peg$c0;
631 | }
632 | while (s5 !== peg$FAILED) {
633 | s4.push(s5);
634 | s5 = peg$currPos;
635 | s6 = peg$parse__();
636 | if (s6 !== peg$FAILED) {
637 | s7 = peg$parseConnection();
638 | if (s7 === peg$FAILED) {
639 | s7 = peg$c5;
640 | }
641 | if (s7 !== peg$FAILED) {
642 | s8 = peg$parse__();
643 | if (s8 !== peg$FAILED) {
644 | s9 = peg$parseView();
645 | if (s9 !== peg$FAILED) {
646 | s6 = [s6, s7, s8, s9];
647 | s5 = s6;
648 | } else {
649 | peg$currPos = s5;
650 | s5 = peg$c0;
651 | }
652 | } else {
653 | peg$currPos = s5;
654 | s5 = peg$c0;
655 | }
656 | } else {
657 | peg$currPos = s5;
658 | s5 = peg$c0;
659 | }
660 | } else {
661 | peg$currPos = s5;
662 | s5 = peg$c0;
663 | }
664 | }
665 | if (s4 !== peg$FAILED) {
666 | s5 = peg$parse__();
667 | if (s5 !== peg$FAILED) {
668 | s6 = peg$parseOptions();
669 | if (s6 !== peg$FAILED) {
670 | peg$reportedPos = s0;
671 | s1 = peg$c6(s1, s3, s4, s6);
672 | s0 = s1;
673 | } else {
674 | peg$currPos = s0;
675 | s0 = peg$c0;
676 | }
677 | } else {
678 | peg$currPos = s0;
679 | s0 = peg$c0;
680 | }
681 | } else {
682 | peg$currPos = s0;
683 | s0 = peg$c0;
684 | }
685 | } else {
686 | peg$currPos = s0;
687 | s0 = peg$c0;
688 | }
689 | } else {
690 | peg$currPos = s0;
691 | s0 = peg$c0;
692 | }
693 | } else {
694 | peg$currPos = s0;
695 | s0 = peg$c0;
696 | }
697 |
698 | return s0;
699 | }
700 |
701 | function peg$parseDimension() {
702 | var s0, s1;
703 |
704 | s0 = peg$currPos;
705 | if (input.substr(peg$currPos, 11) === peg$c7) {
706 | s1 = peg$c7;
707 | peg$currPos += 11;
708 | } else {
709 | s1 = peg$FAILED;
710 | if (peg$silentFails === 0) { peg$fail(peg$c8); }
711 | }
712 | if (s1 === peg$FAILED) {
713 | if (input.substr(peg$currPos, 16) === peg$c9) {
714 | s1 = peg$c9;
715 | peg$currPos += 16;
716 | } else {
717 | s1 = peg$FAILED;
718 | if (peg$silentFails === 0) { peg$fail(peg$c10); }
719 | }
720 | if (s1 === peg$FAILED) {
721 | if (input.substr(peg$currPos, 7) === peg$c11) {
722 | s1 = peg$c11;
723 | peg$currPos += 7;
724 | } else {
725 | s1 = peg$FAILED;
726 | if (peg$silentFails === 0) { peg$fail(peg$c12); }
727 | }
728 | if (s1 === peg$FAILED) {
729 | if (input.substr(peg$currPos, 2) === peg$c13) {
730 | s1 = peg$c13;
731 | peg$currPos += 2;
732 | } else {
733 | s1 = peg$FAILED;
734 | if (peg$silentFails === 0) { peg$fail(peg$c14); }
735 | }
736 | }
737 | }
738 | }
739 | if (s1 !== peg$FAILED) {
740 | peg$reportedPos = s0;
741 | s1 = peg$c15();
742 | }
743 | s0 = s1;
744 | if (s0 === peg$FAILED) {
745 | s0 = peg$currPos;
746 | if (input.substr(peg$currPos, 9) === peg$c16) {
747 | s1 = peg$c16;
748 | peg$currPos += 9;
749 | } else {
750 | s1 = peg$FAILED;
751 | if (peg$silentFails === 0) { peg$fail(peg$c17); }
752 | }
753 | if (s1 === peg$FAILED) {
754 | if (input.substr(peg$currPos, 14) === peg$c18) {
755 | s1 = peg$c18;
756 | peg$currPos += 14;
757 | } else {
758 | s1 = peg$FAILED;
759 | if (peg$silentFails === 0) { peg$fail(peg$c19); }
760 | }
761 | if (s1 === peg$FAILED) {
762 | if (input.substr(peg$currPos, 7) === peg$c20) {
763 | s1 = peg$c20;
764 | peg$currPos += 7;
765 | } else {
766 | s1 = peg$FAILED;
767 | if (peg$silentFails === 0) { peg$fail(peg$c21); }
768 | }
769 | if (s1 === peg$FAILED) {
770 | if (input.substr(peg$currPos, 2) === peg$c22) {
771 | s1 = peg$c22;
772 | peg$currPos += 2;
773 | } else {
774 | s1 = peg$FAILED;
775 | if (peg$silentFails === 0) { peg$fail(peg$c23); }
776 | }
777 | }
778 | }
779 | }
780 | if (s1 !== peg$FAILED) {
781 | peg$reportedPos = s0;
782 | s1 = peg$c24();
783 | }
784 | s0 = s1;
785 | }
786 |
787 | return s0;
788 | }
789 |
790 | function peg$parseOptions() {
791 | var s0, s1, s2;
792 |
793 | s0 = peg$currPos;
794 | s1 = [];
795 | s2 = peg$parseOption();
796 | while (s2 !== peg$FAILED) {
797 | s1.push(s2);
798 | s2 = peg$parseOption();
799 | }
800 | if (s1 !== peg$FAILED) {
801 | peg$reportedPos = s0;
802 | s1 = peg$c25(s1);
803 | }
804 | s0 = s1;
805 |
806 | return s0;
807 | }
808 |
809 | function peg$parseOption() {
810 | var s0, s1, s2, s3, s4, s5;
811 |
812 | peg$silentFails++;
813 | s0 = peg$currPos;
814 | s1 = peg$parse__();
815 | if (s1 !== peg$FAILED) {
816 | s2 = peg$parseChain();
817 | if (s2 !== peg$FAILED) {
818 | peg$reportedPos = s0;
819 | s1 = peg$c27(s2);
820 | s0 = s1;
821 | } else {
822 | peg$currPos = s0;
823 | s0 = peg$c0;
824 | }
825 | } else {
826 | peg$currPos = s0;
827 | s0 = peg$c0;
828 | }
829 | if (s0 === peg$FAILED) {
830 | s0 = peg$currPos;
831 | s1 = peg$parse__();
832 | if (s1 !== peg$FAILED) {
833 | if (input.substr(peg$currPos, 2) === peg$c28) {
834 | s2 = peg$c28;
835 | peg$currPos += 2;
836 | } else {
837 | s2 = peg$FAILED;
838 | if (peg$silentFails === 0) { peg$fail(peg$c29); }
839 | }
840 | if (s2 !== peg$FAILED) {
841 | if (input.charCodeAt(peg$currPos) === 40) {
842 | s3 = peg$c30;
843 | peg$currPos++;
844 | } else {
845 | s3 = peg$FAILED;
846 | if (peg$silentFails === 0) { peg$fail(peg$c31); }
847 | }
848 | if (s3 !== peg$FAILED) {
849 | s4 = [];
850 | if (peg$c32.test(input.charAt(peg$currPos))) {
851 | s5 = input.charAt(peg$currPos);
852 | peg$currPos++;
853 | } else {
854 | s5 = peg$FAILED;
855 | if (peg$silentFails === 0) { peg$fail(peg$c33); }
856 | }
857 | if (s5 !== peg$FAILED) {
858 | while (s5 !== peg$FAILED) {
859 | s4.push(s5);
860 | if (peg$c32.test(input.charAt(peg$currPos))) {
861 | s5 = input.charAt(peg$currPos);
862 | peg$currPos++;
863 | } else {
864 | s5 = peg$FAILED;
865 | if (peg$silentFails === 0) { peg$fail(peg$c33); }
866 | }
867 | }
868 | } else {
869 | s4 = peg$c0;
870 | }
871 | if (s4 !== peg$FAILED) {
872 | if (input.charCodeAt(peg$currPos) === 41) {
873 | s5 = peg$c34;
874 | peg$currPos++;
875 | } else {
876 | s5 = peg$FAILED;
877 | if (peg$silentFails === 0) { peg$fail(peg$c35); }
878 | }
879 | if (s5 !== peg$FAILED) {
880 | peg$reportedPos = s0;
881 | s1 = peg$c36(s4);
882 | s0 = s1;
883 | } else {
884 | peg$currPos = s0;
885 | s0 = peg$c0;
886 | }
887 | } else {
888 | peg$currPos = s0;
889 | s0 = peg$c0;
890 | }
891 | } else {
892 | peg$currPos = s0;
893 | s0 = peg$c0;
894 | }
895 | } else {
896 | peg$currPos = s0;
897 | s0 = peg$c0;
898 | }
899 | } else {
900 | peg$currPos = s0;
901 | s0 = peg$c0;
902 | }
903 | if (s0 === peg$FAILED) {
904 | s0 = peg$currPos;
905 | s1 = peg$parse__();
906 | if (s1 !== peg$FAILED) {
907 | if (input.substr(peg$currPos, 2) === peg$c28) {
908 | s2 = peg$c28;
909 | peg$currPos += 2;
910 | } else {
911 | s2 = peg$FAILED;
912 | if (peg$silentFails === 0) { peg$fail(peg$c29); }
913 | }
914 | if (s2 !== peg$FAILED) {
915 | if (input.charCodeAt(peg$currPos) === 40) {
916 | s3 = peg$c30;
917 | peg$currPos++;
918 | } else {
919 | s3 = peg$FAILED;
920 | if (peg$silentFails === 0) { peg$fail(peg$c31); }
921 | }
922 | if (s3 !== peg$FAILED) {
923 | s4 = [];
924 | if (peg$c37.test(input.charAt(peg$currPos))) {
925 | s5 = input.charAt(peg$currPos);
926 | peg$currPos++;
927 | } else {
928 | s5 = peg$FAILED;
929 | if (peg$silentFails === 0) { peg$fail(peg$c38); }
930 | }
931 | if (s5 !== peg$FAILED) {
932 | while (s5 !== peg$FAILED) {
933 | s4.push(s5);
934 | if (peg$c37.test(input.charAt(peg$currPos))) {
935 | s5 = input.charAt(peg$currPos);
936 | peg$currPos++;
937 | } else {
938 | s5 = peg$FAILED;
939 | if (peg$silentFails === 0) { peg$fail(peg$c38); }
940 | }
941 | }
942 | } else {
943 | s4 = peg$c0;
944 | }
945 | if (s4 !== peg$FAILED) {
946 | if (input.charCodeAt(peg$currPos) === 41) {
947 | s5 = peg$c34;
948 | peg$currPos++;
949 | } else {
950 | s5 = peg$FAILED;
951 | if (peg$silentFails === 0) { peg$fail(peg$c35); }
952 | }
953 | if (s5 !== peg$FAILED) {
954 | peg$reportedPos = s0;
955 | s1 = peg$c39(s4);
956 | s0 = s1;
957 | } else {
958 | peg$currPos = s0;
959 | s0 = peg$c0;
960 | }
961 | } else {
962 | peg$currPos = s0;
963 | s0 = peg$c0;
964 | }
965 | } else {
966 | peg$currPos = s0;
967 | s0 = peg$c0;
968 | }
969 | } else {
970 | peg$currPos = s0;
971 | s0 = peg$c0;
972 | }
973 | } else {
974 | peg$currPos = s0;
975 | s0 = peg$c0;
976 | }
977 | if (s0 === peg$FAILED) {
978 | s0 = peg$currPos;
979 | s1 = peg$parse__();
980 | if (s1 !== peg$FAILED) {
981 | s2 = [];
982 | s3 = peg$parseNameChars();
983 | if (s3 !== peg$FAILED) {
984 | while (s3 !== peg$FAILED) {
985 | s2.push(s3);
986 | s3 = peg$parseNameChars();
987 | }
988 | } else {
989 | s2 = peg$c0;
990 | }
991 | if (s2 !== peg$FAILED) {
992 | if (input.charCodeAt(peg$currPos) === 40) {
993 | s3 = peg$c30;
994 | peg$currPos++;
995 | } else {
996 | s3 = peg$FAILED;
997 | if (peg$silentFails === 0) { peg$fail(peg$c31); }
998 | }
999 | if (s3 !== peg$FAILED) {
1000 | s4 = [];
1001 | s5 = peg$parseOpionValueChars();
1002 | if (s5 !== peg$FAILED) {
1003 | while (s5 !== peg$FAILED) {
1004 | s4.push(s5);
1005 | s5 = peg$parseOpionValueChars();
1006 | }
1007 | } else {
1008 | s4 = peg$c0;
1009 | }
1010 | if (s4 !== peg$FAILED) {
1011 | if (input.charCodeAt(peg$currPos) === 41) {
1012 | s5 = peg$c34;
1013 | peg$currPos++;
1014 | } else {
1015 | s5 = peg$FAILED;
1016 | if (peg$silentFails === 0) { peg$fail(peg$c35); }
1017 | }
1018 | if (s5 !== peg$FAILED) {
1019 | peg$reportedPos = s0;
1020 | s1 = peg$c40(s2, s4);
1021 | s0 = s1;
1022 | } else {
1023 | peg$currPos = s0;
1024 | s0 = peg$c0;
1025 | }
1026 | } else {
1027 | peg$currPos = s0;
1028 | s0 = peg$c0;
1029 | }
1030 | } else {
1031 | peg$currPos = s0;
1032 | s0 = peg$c0;
1033 | }
1034 | } else {
1035 | peg$currPos = s0;
1036 | s0 = peg$c0;
1037 | }
1038 | } else {
1039 | peg$currPos = s0;
1040 | s0 = peg$c0;
1041 | }
1042 | if (s0 === peg$FAILED) {
1043 | s0 = peg$currPos;
1044 | s1 = peg$parse__();
1045 | if (s1 !== peg$FAILED) {
1046 | s2 = peg$parseStrengthAndWeight();
1047 | if (s2 !== peg$FAILED) {
1048 | peg$reportedPos = s0;
1049 | s1 = peg$c41(s2);
1050 | s0 = s1;
1051 | } else {
1052 | peg$currPos = s0;
1053 | s0 = peg$c0;
1054 | }
1055 | } else {
1056 | peg$currPos = s0;
1057 | s0 = peg$c0;
1058 | }
1059 | }
1060 | }
1061 | }
1062 | }
1063 | peg$silentFails--;
1064 | if (s0 === peg$FAILED) {
1065 | s1 = peg$FAILED;
1066 | if (peg$silentFails === 0) { peg$fail(peg$c26); }
1067 | }
1068 |
1069 | return s0;
1070 | }
1071 |
1072 | function peg$parseOpionValueChars() {
1073 | var s0, s1;
1074 |
1075 | if (peg$c42.test(input.charAt(peg$currPos))) {
1076 | s0 = input.charAt(peg$currPos);
1077 | peg$currPos++;
1078 | } else {
1079 | s0 = peg$FAILED;
1080 | if (peg$silentFails === 0) { peg$fail(peg$c43); }
1081 | }
1082 | if (s0 === peg$FAILED) {
1083 | s0 = peg$currPos;
1084 | if (peg$c44.test(input.charAt(peg$currPos))) {
1085 | s1 = input.charAt(peg$currPos);
1086 | peg$currPos++;
1087 | } else {
1088 | s1 = peg$FAILED;
1089 | if (peg$silentFails === 0) { peg$fail(peg$c45); }
1090 | }
1091 | if (s1 !== peg$FAILED) {
1092 | peg$reportedPos = s0;
1093 | s1 = peg$c46();
1094 | }
1095 | s0 = s1;
1096 | }
1097 |
1098 | return s0;
1099 | }
1100 |
1101 | function peg$parseChain() {
1102 | var s0, s1, s2, s3;
1103 |
1104 | peg$silentFails++;
1105 | s0 = peg$currPos;
1106 | if (input.substr(peg$currPos, 6) === peg$c48) {
1107 | s1 = peg$c48;
1108 | peg$currPos += 6;
1109 | } else {
1110 | s1 = peg$FAILED;
1111 | if (peg$silentFails === 0) { peg$fail(peg$c49); }
1112 | }
1113 | if (s1 !== peg$FAILED) {
1114 | s2 = [];
1115 | s3 = peg$parseNameChars();
1116 | if (s3 !== peg$FAILED) {
1117 | while (s3 !== peg$FAILED) {
1118 | s2.push(s3);
1119 | s3 = peg$parseNameChars();
1120 | }
1121 | } else {
1122 | s2 = peg$c0;
1123 | }
1124 | if (s2 !== peg$FAILED) {
1125 | s3 = peg$parseChainPredicate();
1126 | if (s3 === peg$FAILED) {
1127 | s3 = peg$c5;
1128 | }
1129 | if (s3 !== peg$FAILED) {
1130 | peg$reportedPos = s0;
1131 | s1 = peg$c50(s2, s3);
1132 | s0 = s1;
1133 | } else {
1134 | peg$currPos = s0;
1135 | s0 = peg$c0;
1136 | }
1137 | } else {
1138 | peg$currPos = s0;
1139 | s0 = peg$c0;
1140 | }
1141 | } else {
1142 | peg$currPos = s0;
1143 | s0 = peg$c0;
1144 | }
1145 | peg$silentFails--;
1146 | if (s0 === peg$FAILED) {
1147 | s1 = peg$FAILED;
1148 | if (peg$silentFails === 0) { peg$fail(peg$c47); }
1149 | }
1150 |
1151 | return s0;
1152 | }
1153 |
1154 | function peg$parseChainPredicate() {
1155 | var s0, s1, s2, s3;
1156 |
1157 | peg$silentFails++;
1158 | s0 = peg$currPos;
1159 | if (input.charCodeAt(peg$currPos) === 40) {
1160 | s1 = peg$c30;
1161 | peg$currPos++;
1162 | } else {
1163 | s1 = peg$FAILED;
1164 | if (peg$silentFails === 0) { peg$fail(peg$c31); }
1165 | }
1166 | if (s1 !== peg$FAILED) {
1167 | s2 = [];
1168 | s3 = peg$parseChainPredicateItems();
1169 | if (s3 !== peg$FAILED) {
1170 | while (s3 !== peg$FAILED) {
1171 | s2.push(s3);
1172 | s3 = peg$parseChainPredicateItems();
1173 | }
1174 | } else {
1175 | s2 = peg$c0;
1176 | }
1177 | if (s2 !== peg$FAILED) {
1178 | if (input.charCodeAt(peg$currPos) === 41) {
1179 | s3 = peg$c34;
1180 | peg$currPos++;
1181 | } else {
1182 | s3 = peg$FAILED;
1183 | if (peg$silentFails === 0) { peg$fail(peg$c35); }
1184 | }
1185 | if (s3 !== peg$FAILED) {
1186 | peg$reportedPos = s0;
1187 | s1 = peg$c52(s2);
1188 | s0 = s1;
1189 | } else {
1190 | peg$currPos = s0;
1191 | s0 = peg$c0;
1192 | }
1193 | } else {
1194 | peg$currPos = s0;
1195 | s0 = peg$c0;
1196 | }
1197 | } else {
1198 | peg$currPos = s0;
1199 | s0 = peg$c0;
1200 | }
1201 | if (s0 === peg$FAILED) {
1202 | s0 = peg$currPos;
1203 | if (input.substr(peg$currPos, 2) === peg$c53) {
1204 | s1 = peg$c53;
1205 | peg$currPos += 2;
1206 | } else {
1207 | s1 = peg$FAILED;
1208 | if (peg$silentFails === 0) { peg$fail(peg$c54); }
1209 | }
1210 | if (s1 !== peg$FAILED) {
1211 | peg$reportedPos = s0;
1212 | s1 = peg$c55();
1213 | }
1214 | s0 = s1;
1215 | }
1216 | peg$silentFails--;
1217 | if (s0 === peg$FAILED) {
1218 | s1 = peg$FAILED;
1219 | if (peg$silentFails === 0) { peg$fail(peg$c51); }
1220 | }
1221 |
1222 | return s0;
1223 | }
1224 |
1225 | function peg$parseChainPredicateItems() {
1226 | var s0, s1, s2, s3;
1227 |
1228 | s0 = peg$currPos;
1229 | s1 = peg$parseChainPredicateItem();
1230 | if (s1 !== peg$FAILED) {
1231 | s2 = peg$parse_();
1232 | if (s2 === peg$FAILED) {
1233 | s2 = peg$c5;
1234 | }
1235 | if (s2 !== peg$FAILED) {
1236 | if (input.charCodeAt(peg$currPos) === 44) {
1237 | s3 = peg$c56;
1238 | peg$currPos++;
1239 | } else {
1240 | s3 = peg$FAILED;
1241 | if (peg$silentFails === 0) { peg$fail(peg$c57); }
1242 | }
1243 | if (s3 === peg$FAILED) {
1244 | s3 = peg$c5;
1245 | }
1246 | if (s3 !== peg$FAILED) {
1247 | peg$reportedPos = s0;
1248 | s1 = peg$c58(s1);
1249 | s0 = s1;
1250 | } else {
1251 | peg$currPos = s0;
1252 | s0 = peg$c0;
1253 | }
1254 | } else {
1255 | peg$currPos = s0;
1256 | s0 = peg$c0;
1257 | }
1258 | } else {
1259 | peg$currPos = s0;
1260 | s0 = peg$c0;
1261 | }
1262 |
1263 | return s0;
1264 | }
1265 |
1266 | function peg$parseChainPredicateItem() {
1267 | var s0, s1, s2, s3, s4, s5, s6, s7;
1268 |
1269 | s0 = peg$currPos;
1270 | s1 = peg$parsePredEq();
1271 | if (s1 !== peg$FAILED) {
1272 | s2 = peg$parse_();
1273 | if (s2 !== peg$FAILED) {
1274 | s3 = peg$parseChainPredVal();
1275 | if (s3 === peg$FAILED) {
1276 | s3 = peg$c5;
1277 | }
1278 | if (s3 !== peg$FAILED) {
1279 | s4 = peg$parse_();
1280 | if (s4 === peg$FAILED) {
1281 | s4 = peg$c5;
1282 | }
1283 | if (s4 !== peg$FAILED) {
1284 | s5 = peg$parsePredEq();
1285 | if (s5 === peg$FAILED) {
1286 | s5 = peg$c5;
1287 | }
1288 | if (s5 !== peg$FAILED) {
1289 | s6 = peg$parse_();
1290 | if (s6 === peg$FAILED) {
1291 | s6 = peg$c5;
1292 | }
1293 | if (s6 !== peg$FAILED) {
1294 | s7 = peg$parseStrengthAndWeight();
1295 | if (s7 === peg$FAILED) {
1296 | s7 = peg$c5;
1297 | }
1298 | if (s7 !== peg$FAILED) {
1299 | peg$reportedPos = s0;
1300 | s1 = peg$c59(s1, s3, s5, s7);
1301 | s0 = s1;
1302 | } else {
1303 | peg$currPos = s0;
1304 | s0 = peg$c0;
1305 | }
1306 | } else {
1307 | peg$currPos = s0;
1308 | s0 = peg$c0;
1309 | }
1310 | } else {
1311 | peg$currPos = s0;
1312 | s0 = peg$c0;
1313 | }
1314 | } else {
1315 | peg$currPos = s0;
1316 | s0 = peg$c0;
1317 | }
1318 | } else {
1319 | peg$currPos = s0;
1320 | s0 = peg$c0;
1321 | }
1322 | } else {
1323 | peg$currPos = s0;
1324 | s0 = peg$c0;
1325 | }
1326 | } else {
1327 | peg$currPos = s0;
1328 | s0 = peg$c0;
1329 | }
1330 | if (s0 === peg$FAILED) {
1331 | s0 = peg$currPos;
1332 | s1 = peg$parsePredEq();
1333 | if (s1 === peg$FAILED) {
1334 | s1 = peg$c5;
1335 | }
1336 | if (s1 !== peg$FAILED) {
1337 | s2 = peg$parse_();
1338 | if (s2 === peg$FAILED) {
1339 | s2 = peg$c5;
1340 | }
1341 | if (s2 !== peg$FAILED) {
1342 | s3 = peg$parseChainPredVal();
1343 | if (s3 !== peg$FAILED) {
1344 | s4 = peg$parse_();
1345 | if (s4 === peg$FAILED) {
1346 | s4 = peg$c5;
1347 | }
1348 | if (s4 !== peg$FAILED) {
1349 | s5 = peg$parsePredEq();
1350 | if (s5 === peg$FAILED) {
1351 | s5 = peg$c5;
1352 | }
1353 | if (s5 !== peg$FAILED) {
1354 | s6 = peg$parse_();
1355 | if (s6 === peg$FAILED) {
1356 | s6 = peg$c5;
1357 | }
1358 | if (s6 !== peg$FAILED) {
1359 | s7 = peg$parseStrengthAndWeight();
1360 | if (s7 === peg$FAILED) {
1361 | s7 = peg$c5;
1362 | }
1363 | if (s7 !== peg$FAILED) {
1364 | peg$reportedPos = s0;
1365 | s1 = peg$c59(s1, s3, s5, s7);
1366 | s0 = s1;
1367 | } else {
1368 | peg$currPos = s0;
1369 | s0 = peg$c0;
1370 | }
1371 | } else {
1372 | peg$currPos = s0;
1373 | s0 = peg$c0;
1374 | }
1375 | } else {
1376 | peg$currPos = s0;
1377 | s0 = peg$c0;
1378 | }
1379 | } else {
1380 | peg$currPos = s0;
1381 | s0 = peg$c0;
1382 | }
1383 | } else {
1384 | peg$currPos = s0;
1385 | s0 = peg$c0;
1386 | }
1387 | } else {
1388 | peg$currPos = s0;
1389 | s0 = peg$c0;
1390 | }
1391 | } else {
1392 | peg$currPos = s0;
1393 | s0 = peg$c0;
1394 | }
1395 | if (s0 === peg$FAILED) {
1396 | s0 = peg$currPos;
1397 | s1 = peg$parsePredEq();
1398 | if (s1 === peg$FAILED) {
1399 | s1 = peg$c5;
1400 | }
1401 | if (s1 !== peg$FAILED) {
1402 | s2 = peg$parse_();
1403 | if (s2 === peg$FAILED) {
1404 | s2 = peg$c5;
1405 | }
1406 | if (s2 !== peg$FAILED) {
1407 | s3 = peg$parseChainPredVal();
1408 | if (s3 === peg$FAILED) {
1409 | s3 = peg$c5;
1410 | }
1411 | if (s3 !== peg$FAILED) {
1412 | s4 = peg$parse_();
1413 | if (s4 === peg$FAILED) {
1414 | s4 = peg$c5;
1415 | }
1416 | if (s4 !== peg$FAILED) {
1417 | s5 = peg$parsePredEq();
1418 | if (s5 === peg$FAILED) {
1419 | s5 = peg$c5;
1420 | }
1421 | if (s5 !== peg$FAILED) {
1422 | s6 = peg$parse_();
1423 | if (s6 === peg$FAILED) {
1424 | s6 = peg$c5;
1425 | }
1426 | if (s6 !== peg$FAILED) {
1427 | s7 = peg$parseStrengthAndWeight();
1428 | if (s7 !== peg$FAILED) {
1429 | peg$reportedPos = s0;
1430 | s1 = peg$c59(s1, s3, s5, s7);
1431 | s0 = s1;
1432 | } else {
1433 | peg$currPos = s0;
1434 | s0 = peg$c0;
1435 | }
1436 | } else {
1437 | peg$currPos = s0;
1438 | s0 = peg$c0;
1439 | }
1440 | } else {
1441 | peg$currPos = s0;
1442 | s0 = peg$c0;
1443 | }
1444 | } else {
1445 | peg$currPos = s0;
1446 | s0 = peg$c0;
1447 | }
1448 | } else {
1449 | peg$currPos = s0;
1450 | s0 = peg$c0;
1451 | }
1452 | } else {
1453 | peg$currPos = s0;
1454 | s0 = peg$c0;
1455 | }
1456 | } else {
1457 | peg$currPos = s0;
1458 | s0 = peg$c0;
1459 | }
1460 | }
1461 | }
1462 |
1463 | return s0;
1464 | }
1465 |
1466 | function peg$parseChainPredVal() {
1467 | var s0, s1;
1468 |
1469 | s0 = [];
1470 | if (peg$c60.test(input.charAt(peg$currPos))) {
1471 | s1 = input.charAt(peg$currPos);
1472 | peg$currPos++;
1473 | } else {
1474 | s1 = peg$FAILED;
1475 | if (peg$silentFails === 0) { peg$fail(peg$c61); }
1476 | }
1477 | if (s1 !== peg$FAILED) {
1478 | while (s1 !== peg$FAILED) {
1479 | s0.push(s1);
1480 | if (peg$c60.test(input.charAt(peg$currPos))) {
1481 | s1 = input.charAt(peg$currPos);
1482 | peg$currPos++;
1483 | } else {
1484 | s1 = peg$FAILED;
1485 | if (peg$silentFails === 0) { peg$fail(peg$c61); }
1486 | }
1487 | }
1488 | } else {
1489 | s0 = peg$c0;
1490 | }
1491 |
1492 | return s0;
1493 | }
1494 |
1495 | function peg$parseView() {
1496 | var s0, s1;
1497 |
1498 | peg$silentFails++;
1499 | s0 = peg$parseSplat();
1500 | if (s0 === peg$FAILED) {
1501 | s0 = peg$parseViewSelector();
1502 | if (s0 === peg$FAILED) {
1503 | s0 = peg$currPos;
1504 | s1 = peg$parsePoint();
1505 | if (s1 !== peg$FAILED) {
1506 | peg$reportedPos = s0;
1507 | s1 = peg$c63(s1);
1508 | }
1509 | s0 = s1;
1510 | if (s0 === peg$FAILED) {
1511 | s0 = peg$currPos;
1512 | if (input.charCodeAt(peg$currPos) === 124) {
1513 | s1 = peg$c64;
1514 | peg$currPos++;
1515 | } else {
1516 | s1 = peg$FAILED;
1517 | if (peg$silentFails === 0) { peg$fail(peg$c65); }
1518 | }
1519 | if (s1 !== peg$FAILED) {
1520 | peg$reportedPos = s0;
1521 | s1 = peg$c66();
1522 | }
1523 | s0 = s1;
1524 | }
1525 | }
1526 | }
1527 | peg$silentFails--;
1528 | if (s0 === peg$FAILED) {
1529 | s1 = peg$FAILED;
1530 | if (peg$silentFails === 0) { peg$fail(peg$c62); }
1531 | }
1532 |
1533 | return s0;
1534 | }
1535 |
1536 | function peg$parseViewSelector() {
1537 | var s0, s1, s2, s3, s4, s5, s6, s7;
1538 |
1539 | s0 = peg$currPos;
1540 | if (input.charCodeAt(peg$currPos) === 40) {
1541 | s1 = peg$c30;
1542 | peg$currPos++;
1543 | } else {
1544 | s1 = peg$FAILED;
1545 | if (peg$silentFails === 0) { peg$fail(peg$c31); }
1546 | }
1547 | if (s1 !== peg$FAILED) {
1548 | s2 = peg$parse_();
1549 | if (s2 !== peg$FAILED) {
1550 | s3 = [];
1551 | s4 = peg$parseNameChars();
1552 | if (s4 !== peg$FAILED) {
1553 | while (s4 !== peg$FAILED) {
1554 | s3.push(s4);
1555 | s4 = peg$parseNameChars();
1556 | }
1557 | } else {
1558 | s3 = peg$c0;
1559 | }
1560 | if (s3 !== peg$FAILED) {
1561 | s4 = peg$parse_();
1562 | if (s4 !== peg$FAILED) {
1563 | s5 = peg$parsePredicate();
1564 | if (s5 === peg$FAILED) {
1565 | s5 = peg$c5;
1566 | }
1567 | if (s5 !== peg$FAILED) {
1568 | s6 = peg$parse_();
1569 | if (s6 !== peg$FAILED) {
1570 | if (input.charCodeAt(peg$currPos) === 41) {
1571 | s7 = peg$c34;
1572 | peg$currPos++;
1573 | } else {
1574 | s7 = peg$FAILED;
1575 | if (peg$silentFails === 0) { peg$fail(peg$c35); }
1576 | }
1577 | if (s7 !== peg$FAILED) {
1578 | peg$reportedPos = s0;
1579 | s1 = peg$c67(s3, s5);
1580 | s0 = s1;
1581 | } else {
1582 | peg$currPos = s0;
1583 | s0 = peg$c0;
1584 | }
1585 | } else {
1586 | peg$currPos = s0;
1587 | s0 = peg$c0;
1588 | }
1589 | } else {
1590 | peg$currPos = s0;
1591 | s0 = peg$c0;
1592 | }
1593 | } else {
1594 | peg$currPos = s0;
1595 | s0 = peg$c0;
1596 | }
1597 | } else {
1598 | peg$currPos = s0;
1599 | s0 = peg$c0;
1600 | }
1601 | } else {
1602 | peg$currPos = s0;
1603 | s0 = peg$c0;
1604 | }
1605 | } else {
1606 | peg$currPos = s0;
1607 | s0 = peg$c0;
1608 | }
1609 | if (s0 === peg$FAILED) {
1610 | s0 = peg$parseComplexViewSelector();
1611 | }
1612 |
1613 | return s0;
1614 | }
1615 |
1616 | function peg$parseComplexViewSelector() {
1617 | var s0, s1, s2, s3, s4, s5, s6, s7;
1618 |
1619 | s0 = peg$currPos;
1620 | if (input.charCodeAt(peg$currPos) === 40) {
1621 | s1 = peg$c30;
1622 | peg$currPos++;
1623 | } else {
1624 | s1 = peg$FAILED;
1625 | if (peg$silentFails === 0) { peg$fail(peg$c31); }
1626 | }
1627 | if (s1 !== peg$FAILED) {
1628 | s2 = peg$parse_();
1629 | if (s2 !== peg$FAILED) {
1630 | s3 = [];
1631 | if (peg$c68.test(input.charAt(peg$currPos))) {
1632 | s4 = input.charAt(peg$currPos);
1633 | peg$currPos++;
1634 | } else {
1635 | s4 = peg$FAILED;
1636 | if (peg$silentFails === 0) { peg$fail(peg$c69); }
1637 | }
1638 | while (s4 !== peg$FAILED) {
1639 | s3.push(s4);
1640 | if (peg$c68.test(input.charAt(peg$currPos))) {
1641 | s4 = input.charAt(peg$currPos);
1642 | peg$currPos++;
1643 | } else {
1644 | s4 = peg$FAILED;
1645 | if (peg$silentFails === 0) { peg$fail(peg$c69); }
1646 | }
1647 | }
1648 | if (s3 !== peg$FAILED) {
1649 | s4 = peg$parse_();
1650 | if (s4 !== peg$FAILED) {
1651 | s5 = peg$parsePredicate();
1652 | if (s5 === peg$FAILED) {
1653 | s5 = peg$c5;
1654 | }
1655 | if (s5 !== peg$FAILED) {
1656 | s6 = peg$parse_();
1657 | if (s6 !== peg$FAILED) {
1658 | if (input.charCodeAt(peg$currPos) === 41) {
1659 | s7 = peg$c34;
1660 | peg$currPos++;
1661 | } else {
1662 | s7 = peg$FAILED;
1663 | if (peg$silentFails === 0) { peg$fail(peg$c35); }
1664 | }
1665 | if (s7 !== peg$FAILED) {
1666 | peg$reportedPos = s0;
1667 | s1 = peg$c70(s3, s5);
1668 | s0 = s1;
1669 | } else {
1670 | peg$currPos = s0;
1671 | s0 = peg$c0;
1672 | }
1673 | } else {
1674 | peg$currPos = s0;
1675 | s0 = peg$c0;
1676 | }
1677 | } else {
1678 | peg$currPos = s0;
1679 | s0 = peg$c0;
1680 | }
1681 | } else {
1682 | peg$currPos = s0;
1683 | s0 = peg$c0;
1684 | }
1685 | } else {
1686 | peg$currPos = s0;
1687 | s0 = peg$c0;
1688 | }
1689 | } else {
1690 | peg$currPos = s0;
1691 | s0 = peg$c0;
1692 | }
1693 | } else {
1694 | peg$currPos = s0;
1695 | s0 = peg$c0;
1696 | }
1697 |
1698 | return s0;
1699 | }
1700 |
1701 | function peg$parseSplat() {
1702 | var s0, s1, s2, s3, s4, s5;
1703 |
1704 | s0 = peg$currPos;
1705 | s1 = peg$parseViewSelector();
1706 | if (s1 !== peg$FAILED) {
1707 | s2 = peg$parse__();
1708 | if (s2 !== peg$FAILED) {
1709 | s3 = peg$parseConnection();
1710 | if (s3 === peg$FAILED) {
1711 | s3 = peg$c5;
1712 | }
1713 | if (s3 !== peg$FAILED) {
1714 | s4 = peg$parse__();
1715 | if (s4 !== peg$FAILED) {
1716 | if (input.substr(peg$currPos, 3) === peg$c71) {
1717 | s5 = peg$c71;
1718 | peg$currPos += 3;
1719 | } else {
1720 | s5 = peg$FAILED;
1721 | if (peg$silentFails === 0) { peg$fail(peg$c72); }
1722 | }
1723 | if (s5 !== peg$FAILED) {
1724 | peg$reportedPos = s0;
1725 | s1 = peg$c73(s1, s3);
1726 | s0 = s1;
1727 | } else {
1728 | peg$currPos = s0;
1729 | s0 = peg$c0;
1730 | }
1731 | } else {
1732 | peg$currPos = s0;
1733 | s0 = peg$c0;
1734 | }
1735 | } else {
1736 | peg$currPos = s0;
1737 | s0 = peg$c0;
1738 | }
1739 | } else {
1740 | peg$currPos = s0;
1741 | s0 = peg$c0;
1742 | }
1743 | } else {
1744 | peg$currPos = s0;
1745 | s0 = peg$c0;
1746 | }
1747 |
1748 | return s0;
1749 | }
1750 |
1751 | function peg$parsePoint() {
1752 | var s0, s1, s2, s3, s4, s5;
1753 |
1754 | peg$silentFails++;
1755 | s0 = peg$currPos;
1756 | if (input.charCodeAt(peg$currPos) === 60) {
1757 | s1 = peg$c75;
1758 | peg$currPos++;
1759 | } else {
1760 | s1 = peg$FAILED;
1761 | if (peg$silentFails === 0) { peg$fail(peg$c76); }
1762 | }
1763 | if (s1 !== peg$FAILED) {
1764 | s2 = peg$parse_();
1765 | if (s2 === peg$FAILED) {
1766 | s2 = peg$c5;
1767 | }
1768 | if (s2 !== peg$FAILED) {
1769 | s3 = [];
1770 | if (peg$c77.test(input.charAt(peg$currPos))) {
1771 | s4 = input.charAt(peg$currPos);
1772 | peg$currPos++;
1773 | } else {
1774 | s4 = peg$FAILED;
1775 | if (peg$silentFails === 0) { peg$fail(peg$c78); }
1776 | }
1777 | if (s4 !== peg$FAILED) {
1778 | while (s4 !== peg$FAILED) {
1779 | s3.push(s4);
1780 | if (peg$c77.test(input.charAt(peg$currPos))) {
1781 | s4 = input.charAt(peg$currPos);
1782 | peg$currPos++;
1783 | } else {
1784 | s4 = peg$FAILED;
1785 | if (peg$silentFails === 0) { peg$fail(peg$c78); }
1786 | }
1787 | }
1788 | } else {
1789 | s3 = peg$c0;
1790 | }
1791 | if (s3 !== peg$FAILED) {
1792 | s4 = peg$parse_();
1793 | if (s4 === peg$FAILED) {
1794 | s4 = peg$c5;
1795 | }
1796 | if (s4 !== peg$FAILED) {
1797 | if (input.charCodeAt(peg$currPos) === 62) {
1798 | s5 = peg$c79;
1799 | peg$currPos++;
1800 | } else {
1801 | s5 = peg$FAILED;
1802 | if (peg$silentFails === 0) { peg$fail(peg$c80); }
1803 | }
1804 | if (s5 !== peg$FAILED) {
1805 | peg$reportedPos = s0;
1806 | s1 = peg$c81(s3);
1807 | s0 = s1;
1808 | } else {
1809 | peg$currPos = s0;
1810 | s0 = peg$c0;
1811 | }
1812 | } else {
1813 | peg$currPos = s0;
1814 | s0 = peg$c0;
1815 | }
1816 | } else {
1817 | peg$currPos = s0;
1818 | s0 = peg$c0;
1819 | }
1820 | } else {
1821 | peg$currPos = s0;
1822 | s0 = peg$c0;
1823 | }
1824 | } else {
1825 | peg$currPos = s0;
1826 | s0 = peg$c0;
1827 | }
1828 | peg$silentFails--;
1829 | if (s0 === peg$FAILED) {
1830 | s1 = peg$FAILED;
1831 | if (peg$silentFails === 0) { peg$fail(peg$c74); }
1832 | }
1833 |
1834 | return s0;
1835 | }
1836 |
1837 | function peg$parsePredicate() {
1838 | var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
1839 |
1840 | peg$silentFails++;
1841 | s0 = peg$currPos;
1842 | if (input.charCodeAt(peg$currPos) === 40) {
1843 | s1 = peg$c30;
1844 | peg$currPos++;
1845 | } else {
1846 | s1 = peg$FAILED;
1847 | if (peg$silentFails === 0) { peg$fail(peg$c31); }
1848 | }
1849 | if (s1 !== peg$FAILED) {
1850 | s2 = [];
1851 | s3 = peg$currPos;
1852 | s4 = peg$parsePredEq();
1853 | if (s4 !== peg$FAILED) {
1854 | s5 = peg$parsePredExpression();
1855 | if (s5 !== peg$FAILED) {
1856 | s6 = peg$parseStrengthAndWeight();
1857 | if (s6 === peg$FAILED) {
1858 | s6 = peg$c5;
1859 | }
1860 | if (s6 !== peg$FAILED) {
1861 | s7 = peg$parse_();
1862 | if (s7 === peg$FAILED) {
1863 | s7 = peg$c5;
1864 | }
1865 | if (s7 !== peg$FAILED) {
1866 | s8 = peg$parsePredSeperator();
1867 | if (s8 !== peg$FAILED) {
1868 | s9 = peg$parse_();
1869 | if (s9 === peg$FAILED) {
1870 | s9 = peg$c5;
1871 | }
1872 | if (s9 !== peg$FAILED) {
1873 | s4 = [s4, s5, s6, s7, s8, s9];
1874 | s3 = s4;
1875 | } else {
1876 | peg$currPos = s3;
1877 | s3 = peg$c0;
1878 | }
1879 | } else {
1880 | peg$currPos = s3;
1881 | s3 = peg$c0;
1882 | }
1883 | } else {
1884 | peg$currPos = s3;
1885 | s3 = peg$c0;
1886 | }
1887 | } else {
1888 | peg$currPos = s3;
1889 | s3 = peg$c0;
1890 | }
1891 | } else {
1892 | peg$currPos = s3;
1893 | s3 = peg$c0;
1894 | }
1895 | } else {
1896 | peg$currPos = s3;
1897 | s3 = peg$c0;
1898 | }
1899 | if (s3 !== peg$FAILED) {
1900 | while (s3 !== peg$FAILED) {
1901 | s2.push(s3);
1902 | s3 = peg$currPos;
1903 | s4 = peg$parsePredEq();
1904 | if (s4 !== peg$FAILED) {
1905 | s5 = peg$parsePredExpression();
1906 | if (s5 !== peg$FAILED) {
1907 | s6 = peg$parseStrengthAndWeight();
1908 | if (s6 === peg$FAILED) {
1909 | s6 = peg$c5;
1910 | }
1911 | if (s6 !== peg$FAILED) {
1912 | s7 = peg$parse_();
1913 | if (s7 === peg$FAILED) {
1914 | s7 = peg$c5;
1915 | }
1916 | if (s7 !== peg$FAILED) {
1917 | s8 = peg$parsePredSeperator();
1918 | if (s8 !== peg$FAILED) {
1919 | s9 = peg$parse_();
1920 | if (s9 === peg$FAILED) {
1921 | s9 = peg$c5;
1922 | }
1923 | if (s9 !== peg$FAILED) {
1924 | s4 = [s4, s5, s6, s7, s8, s9];
1925 | s3 = s4;
1926 | } else {
1927 | peg$currPos = s3;
1928 | s3 = peg$c0;
1929 | }
1930 | } else {
1931 | peg$currPos = s3;
1932 | s3 = peg$c0;
1933 | }
1934 | } else {
1935 | peg$currPos = s3;
1936 | s3 = peg$c0;
1937 | }
1938 | } else {
1939 | peg$currPos = s3;
1940 | s3 = peg$c0;
1941 | }
1942 | } else {
1943 | peg$currPos = s3;
1944 | s3 = peg$c0;
1945 | }
1946 | } else {
1947 | peg$currPos = s3;
1948 | s3 = peg$c0;
1949 | }
1950 | }
1951 | } else {
1952 | s2 = peg$c0;
1953 | }
1954 | if (s2 !== peg$FAILED) {
1955 | if (input.charCodeAt(peg$currPos) === 41) {
1956 | s3 = peg$c34;
1957 | peg$currPos++;
1958 | } else {
1959 | s3 = peg$FAILED;
1960 | if (peg$silentFails === 0) { peg$fail(peg$c35); }
1961 | }
1962 | if (s3 !== peg$FAILED) {
1963 | peg$reportedPos = s0;
1964 | s1 = peg$c83(s2);
1965 | s0 = s1;
1966 | } else {
1967 | peg$currPos = s0;
1968 | s0 = peg$c0;
1969 | }
1970 | } else {
1971 | peg$currPos = s0;
1972 | s0 = peg$c0;
1973 | }
1974 | } else {
1975 | peg$currPos = s0;
1976 | s0 = peg$c0;
1977 | }
1978 | peg$silentFails--;
1979 | if (s0 === peg$FAILED) {
1980 | s1 = peg$FAILED;
1981 | if (peg$silentFails === 0) { peg$fail(peg$c82); }
1982 | }
1983 |
1984 | return s0;
1985 | }
1986 |
1987 | function peg$parsePredExpression() {
1988 | var s0, s1;
1989 |
1990 | peg$silentFails++;
1991 | s0 = [];
1992 | s1 = peg$parsePredOp();
1993 | if (s1 === peg$FAILED) {
1994 | s1 = peg$parsePredLiteral();
1995 | if (s1 === peg$FAILED) {
1996 | s1 = peg$parsePredVariable();
1997 | if (s1 === peg$FAILED) {
1998 | s1 = peg$parsePredViewVariable();
1999 | if (s1 === peg$FAILED) {
2000 | s1 = peg$parsePredView();
2001 | }
2002 | }
2003 | }
2004 | }
2005 | if (s1 !== peg$FAILED) {
2006 | while (s1 !== peg$FAILED) {
2007 | s0.push(s1);
2008 | s1 = peg$parsePredOp();
2009 | if (s1 === peg$FAILED) {
2010 | s1 = peg$parsePredLiteral();
2011 | if (s1 === peg$FAILED) {
2012 | s1 = peg$parsePredVariable();
2013 | if (s1 === peg$FAILED) {
2014 | s1 = peg$parsePredViewVariable();
2015 | if (s1 === peg$FAILED) {
2016 | s1 = peg$parsePredView();
2017 | }
2018 | }
2019 | }
2020 | }
2021 | }
2022 | } else {
2023 | s0 = peg$c0;
2024 | }
2025 | peg$silentFails--;
2026 | if (s0 === peg$FAILED) {
2027 | s1 = peg$FAILED;
2028 | if (peg$silentFails === 0) { peg$fail(peg$c84); }
2029 | }
2030 |
2031 | return s0;
2032 | }
2033 |
2034 | function peg$parsePredEq() {
2035 | var s0, s1, s2, s3;
2036 |
2037 | s0 = peg$currPos;
2038 | s1 = peg$parse_();
2039 | if (s1 === peg$FAILED) {
2040 | s1 = peg$c5;
2041 | }
2042 | if (s1 !== peg$FAILED) {
2043 | if (input.substr(peg$currPos, 2) === peg$c85) {
2044 | s2 = peg$c85;
2045 | peg$currPos += 2;
2046 | } else {
2047 | s2 = peg$FAILED;
2048 | if (peg$silentFails === 0) { peg$fail(peg$c86); }
2049 | }
2050 | if (s2 === peg$FAILED) {
2051 | if (input.substr(peg$currPos, 2) === peg$c87) {
2052 | s2 = peg$c87;
2053 | peg$currPos += 2;
2054 | } else {
2055 | s2 = peg$FAILED;
2056 | if (peg$silentFails === 0) { peg$fail(peg$c88); }
2057 | }
2058 | if (s2 === peg$FAILED) {
2059 | if (input.charCodeAt(peg$currPos) === 60) {
2060 | s2 = peg$c75;
2061 | peg$currPos++;
2062 | } else {
2063 | s2 = peg$FAILED;
2064 | if (peg$silentFails === 0) { peg$fail(peg$c76); }
2065 | }
2066 | if (s2 === peg$FAILED) {
2067 | if (input.substr(peg$currPos, 2) === peg$c89) {
2068 | s2 = peg$c89;
2069 | peg$currPos += 2;
2070 | } else {
2071 | s2 = peg$FAILED;
2072 | if (peg$silentFails === 0) { peg$fail(peg$c90); }
2073 | }
2074 | if (s2 === peg$FAILED) {
2075 | if (input.charCodeAt(peg$currPos) === 62) {
2076 | s2 = peg$c79;
2077 | peg$currPos++;
2078 | } else {
2079 | s2 = peg$FAILED;
2080 | if (peg$silentFails === 0) { peg$fail(peg$c80); }
2081 | }
2082 | if (s2 === peg$FAILED) {
2083 | s2 = peg$currPos;
2084 | if (input.substr(peg$currPos, 2) === peg$c91) {
2085 | s3 = peg$c91;
2086 | peg$currPos += 2;
2087 | } else {
2088 | s3 = peg$FAILED;
2089 | if (peg$silentFails === 0) { peg$fail(peg$c92); }
2090 | }
2091 | if (s3 !== peg$FAILED) {
2092 | peg$reportedPos = s2;
2093 | s3 = peg$c93();
2094 | }
2095 | s2 = s3;
2096 | if (s2 === peg$FAILED) {
2097 | s2 = peg$currPos;
2098 | if (input.substr(peg$currPos, 2) === peg$c94) {
2099 | s3 = peg$c94;
2100 | peg$currPos += 2;
2101 | } else {
2102 | s3 = peg$FAILED;
2103 | if (peg$silentFails === 0) { peg$fail(peg$c95); }
2104 | }
2105 | if (s3 !== peg$FAILED) {
2106 | peg$reportedPos = s2;
2107 | s3 = peg$c96();
2108 | }
2109 | s2 = s3;
2110 | }
2111 | }
2112 | }
2113 | }
2114 | }
2115 | }
2116 | if (s2 !== peg$FAILED) {
2117 | s3 = peg$parse_();
2118 | if (s3 === peg$FAILED) {
2119 | s3 = peg$c5;
2120 | }
2121 | if (s3 !== peg$FAILED) {
2122 | peg$reportedPos = s0;
2123 | s1 = peg$c97(s2);
2124 | s0 = s1;
2125 | } else {
2126 | peg$currPos = s0;
2127 | s0 = peg$c0;
2128 | }
2129 | } else {
2130 | peg$currPos = s0;
2131 | s0 = peg$c0;
2132 | }
2133 | } else {
2134 | peg$currPos = s0;
2135 | s0 = peg$c0;
2136 | }
2137 |
2138 | return s0;
2139 | }
2140 |
2141 | function peg$parsePredOp() {
2142 | var s0, s1, s2;
2143 |
2144 | s0 = peg$currPos;
2145 | if (peg$c98.test(input.charAt(peg$currPos))) {
2146 | s1 = input.charAt(peg$currPos);
2147 | peg$currPos++;
2148 | } else {
2149 | s1 = peg$FAILED;
2150 | if (peg$silentFails === 0) { peg$fail(peg$c99); }
2151 | }
2152 | if (s1 !== peg$FAILED) {
2153 | s2 = peg$parse_();
2154 | if (s2 === peg$FAILED) {
2155 | s2 = peg$c5;
2156 | }
2157 | if (s2 !== peg$FAILED) {
2158 | peg$reportedPos = s0;
2159 | s1 = peg$c100(s1);
2160 | s0 = s1;
2161 | } else {
2162 | peg$currPos = s0;
2163 | s0 = peg$c0;
2164 | }
2165 | } else {
2166 | peg$currPos = s0;
2167 | s0 = peg$c0;
2168 | }
2169 |
2170 | return s0;
2171 | }
2172 |
2173 | function peg$parsePredView() {
2174 | var s0, s1, s2;
2175 |
2176 | s0 = peg$currPos;
2177 | s1 = [];
2178 | s2 = peg$parseNameChars();
2179 | if (s2 !== peg$FAILED) {
2180 | while (s2 !== peg$FAILED) {
2181 | s1.push(s2);
2182 | s2 = peg$parseNameChars();
2183 | }
2184 | } else {
2185 | s1 = peg$c0;
2186 | }
2187 | if (s1 !== peg$FAILED) {
2188 | s2 = peg$parse_();
2189 | if (s2 === peg$FAILED) {
2190 | s2 = peg$c5;
2191 | }
2192 | if (s2 !== peg$FAILED) {
2193 | peg$reportedPos = s0;
2194 | s1 = peg$c101(s1);
2195 | s0 = s1;
2196 | } else {
2197 | peg$currPos = s0;
2198 | s0 = peg$c0;
2199 | }
2200 | } else {
2201 | peg$currPos = s0;
2202 | s0 = peg$c0;
2203 | }
2204 |
2205 | return s0;
2206 | }
2207 |
2208 | function peg$parsePredLiteral() {
2209 | var s0, s1, s2;
2210 |
2211 | s0 = peg$currPos;
2212 | s1 = [];
2213 | s2 = peg$parseNumber();
2214 | if (s2 !== peg$FAILED) {
2215 | while (s2 !== peg$FAILED) {
2216 | s1.push(s2);
2217 | s2 = peg$parseNumber();
2218 | }
2219 | } else {
2220 | s1 = peg$c0;
2221 | }
2222 | if (s1 !== peg$FAILED) {
2223 | s2 = peg$parse_();
2224 | if (s2 === peg$FAILED) {
2225 | s2 = peg$c5;
2226 | }
2227 | if (s2 !== peg$FAILED) {
2228 | peg$reportedPos = s0;
2229 | s1 = peg$c102(s1);
2230 | s0 = s1;
2231 | } else {
2232 | peg$currPos = s0;
2233 | s0 = peg$c0;
2234 | }
2235 | } else {
2236 | peg$currPos = s0;
2237 | s0 = peg$c0;
2238 | }
2239 |
2240 | return s0;
2241 | }
2242 |
2243 | function peg$parsePredVariable() {
2244 | var s0, s1, s2, s3, s4;
2245 |
2246 | s0 = peg$currPos;
2247 | if (input.charCodeAt(peg$currPos) === 91) {
2248 | s1 = peg$c103;
2249 | peg$currPos++;
2250 | } else {
2251 | s1 = peg$FAILED;
2252 | if (peg$silentFails === 0) { peg$fail(peg$c104); }
2253 | }
2254 | if (s1 !== peg$FAILED) {
2255 | s2 = [];
2256 | s3 = peg$parseNameChars();
2257 | if (s3 !== peg$FAILED) {
2258 | while (s3 !== peg$FAILED) {
2259 | s2.push(s3);
2260 | s3 = peg$parseNameChars();
2261 | }
2262 | } else {
2263 | s2 = peg$c0;
2264 | }
2265 | if (s2 !== peg$FAILED) {
2266 | if (input.charCodeAt(peg$currPos) === 93) {
2267 | s3 = peg$c105;
2268 | peg$currPos++;
2269 | } else {
2270 | s3 = peg$FAILED;
2271 | if (peg$silentFails === 0) { peg$fail(peg$c106); }
2272 | }
2273 | if (s3 !== peg$FAILED) {
2274 | s4 = peg$parse_();
2275 | if (s4 === peg$FAILED) {
2276 | s4 = peg$c5;
2277 | }
2278 | if (s4 !== peg$FAILED) {
2279 | peg$reportedPos = s0;
2280 | s1 = peg$c107(s2);
2281 | s0 = s1;
2282 | } else {
2283 | peg$currPos = s0;
2284 | s0 = peg$c0;
2285 | }
2286 | } else {
2287 | peg$currPos = s0;
2288 | s0 = peg$c0;
2289 | }
2290 | } else {
2291 | peg$currPos = s0;
2292 | s0 = peg$c0;
2293 | }
2294 | } else {
2295 | peg$currPos = s0;
2296 | s0 = peg$c0;
2297 | }
2298 |
2299 | return s0;
2300 | }
2301 |
2302 | function peg$parsePredViewVariable() {
2303 | var s0, s1, s2, s3, s4, s5;
2304 |
2305 | s0 = peg$currPos;
2306 | s1 = [];
2307 | s2 = peg$parseNameChars();
2308 | if (s2 !== peg$FAILED) {
2309 | while (s2 !== peg$FAILED) {
2310 | s1.push(s2);
2311 | s2 = peg$parseNameChars();
2312 | }
2313 | } else {
2314 | s1 = peg$c0;
2315 | }
2316 | if (s1 !== peg$FAILED) {
2317 | if (input.charCodeAt(peg$currPos) === 91) {
2318 | s2 = peg$c103;
2319 | peg$currPos++;
2320 | } else {
2321 | s2 = peg$FAILED;
2322 | if (peg$silentFails === 0) { peg$fail(peg$c104); }
2323 | }
2324 | if (s2 !== peg$FAILED) {
2325 | s3 = [];
2326 | s4 = peg$parseNameChars();
2327 | if (s4 !== peg$FAILED) {
2328 | while (s4 !== peg$FAILED) {
2329 | s3.push(s4);
2330 | s4 = peg$parseNameChars();
2331 | }
2332 | } else {
2333 | s3 = peg$c0;
2334 | }
2335 | if (s3 !== peg$FAILED) {
2336 | if (input.charCodeAt(peg$currPos) === 93) {
2337 | s4 = peg$c105;
2338 | peg$currPos++;
2339 | } else {
2340 | s4 = peg$FAILED;
2341 | if (peg$silentFails === 0) { peg$fail(peg$c106); }
2342 | }
2343 | if (s4 !== peg$FAILED) {
2344 | s5 = peg$parse_();
2345 | if (s5 === peg$FAILED) {
2346 | s5 = peg$c5;
2347 | }
2348 | if (s5 !== peg$FAILED) {
2349 | peg$reportedPos = s0;
2350 | s1 = peg$c108(s1, s3);
2351 | s0 = s1;
2352 | } else {
2353 | peg$currPos = s0;
2354 | s0 = peg$c0;
2355 | }
2356 | } else {
2357 | peg$currPos = s0;
2358 | s0 = peg$c0;
2359 | }
2360 | } else {
2361 | peg$currPos = s0;
2362 | s0 = peg$c0;
2363 | }
2364 | } else {
2365 | peg$currPos = s0;
2366 | s0 = peg$c0;
2367 | }
2368 | } else {
2369 | peg$currPos = s0;
2370 | s0 = peg$c0;
2371 | }
2372 |
2373 | return s0;
2374 | }
2375 |
2376 | function peg$parsePredSeperator() {
2377 | var s0, s1;
2378 |
2379 | s0 = peg$currPos;
2380 | if (input.charCodeAt(peg$currPos) === 44) {
2381 | s1 = peg$c56;
2382 | peg$currPos++;
2383 | } else {
2384 | s1 = peg$FAILED;
2385 | if (peg$silentFails === 0) { peg$fail(peg$c57); }
2386 | }
2387 | if (s1 === peg$FAILED) {
2388 | s1 = peg$c5;
2389 | }
2390 | if (s1 !== peg$FAILED) {
2391 | peg$reportedPos = s0;
2392 | s1 = peg$c109();
2393 | }
2394 | s0 = s1;
2395 |
2396 | return s0;
2397 | }
2398 |
2399 | function peg$parseConnection() {
2400 | var s0, s1, s2, s3, s4, s5;
2401 |
2402 | peg$silentFails++;
2403 | s0 = peg$currPos;
2404 | if (input.charCodeAt(peg$currPos) === 45) {
2405 | s1 = peg$c111;
2406 | peg$currPos++;
2407 | } else {
2408 | s1 = peg$FAILED;
2409 | if (peg$silentFails === 0) { peg$fail(peg$c112); }
2410 | }
2411 | if (s1 !== peg$FAILED) {
2412 | s2 = peg$parse_();
2413 | if (s2 !== peg$FAILED) {
2414 | s3 = peg$parseExplicitGap();
2415 | if (s3 !== peg$FAILED) {
2416 | s4 = peg$parse_();
2417 | if (s4 !== peg$FAILED) {
2418 | if (input.charCodeAt(peg$currPos) === 45) {
2419 | s5 = peg$c111;
2420 | peg$currPos++;
2421 | } else {
2422 | s5 = peg$FAILED;
2423 | if (peg$silentFails === 0) { peg$fail(peg$c112); }
2424 | }
2425 | if (s5 !== peg$FAILED) {
2426 | peg$reportedPos = s0;
2427 | s1 = peg$c113(s3);
2428 | s0 = s1;
2429 | } else {
2430 | peg$currPos = s0;
2431 | s0 = peg$c0;
2432 | }
2433 | } else {
2434 | peg$currPos = s0;
2435 | s0 = peg$c0;
2436 | }
2437 | } else {
2438 | peg$currPos = s0;
2439 | s0 = peg$c0;
2440 | }
2441 | } else {
2442 | peg$currPos = s0;
2443 | s0 = peg$c0;
2444 | }
2445 | } else {
2446 | peg$currPos = s0;
2447 | s0 = peg$c0;
2448 | }
2449 | if (s0 === peg$FAILED) {
2450 | s0 = peg$currPos;
2451 | if (input.charCodeAt(peg$currPos) === 45) {
2452 | s1 = peg$c111;
2453 | peg$currPos++;
2454 | } else {
2455 | s1 = peg$FAILED;
2456 | if (peg$silentFails === 0) { peg$fail(peg$c112); }
2457 | }
2458 | if (s1 !== peg$FAILED) {
2459 | peg$reportedPos = s0;
2460 | s1 = peg$c114();
2461 | }
2462 | s0 = s1;
2463 | if (s0 === peg$FAILED) {
2464 | s0 = peg$currPos;
2465 | if (input.charCodeAt(peg$currPos) === 126) {
2466 | s1 = peg$c115;
2467 | peg$currPos++;
2468 | } else {
2469 | s1 = peg$FAILED;
2470 | if (peg$silentFails === 0) { peg$fail(peg$c116); }
2471 | }
2472 | if (s1 !== peg$FAILED) {
2473 | s2 = peg$parse_();
2474 | if (s2 !== peg$FAILED) {
2475 | s3 = peg$parseExplicitGap();
2476 | if (s3 !== peg$FAILED) {
2477 | s4 = peg$parse_();
2478 | if (s4 !== peg$FAILED) {
2479 | if (input.charCodeAt(peg$currPos) === 126) {
2480 | s5 = peg$c115;
2481 | peg$currPos++;
2482 | } else {
2483 | s5 = peg$FAILED;
2484 | if (peg$silentFails === 0) { peg$fail(peg$c116); }
2485 | }
2486 | if (s5 !== peg$FAILED) {
2487 | peg$reportedPos = s0;
2488 | s1 = peg$c117(s3);
2489 | s0 = s1;
2490 | } else {
2491 | peg$currPos = s0;
2492 | s0 = peg$c0;
2493 | }
2494 | } else {
2495 | peg$currPos = s0;
2496 | s0 = peg$c0;
2497 | }
2498 | } else {
2499 | peg$currPos = s0;
2500 | s0 = peg$c0;
2501 | }
2502 | } else {
2503 | peg$currPos = s0;
2504 | s0 = peg$c0;
2505 | }
2506 | } else {
2507 | peg$currPos = s0;
2508 | s0 = peg$c0;
2509 | }
2510 | if (s0 === peg$FAILED) {
2511 | s0 = peg$currPos;
2512 | if (input.charCodeAt(peg$currPos) === 126) {
2513 | s1 = peg$c115;
2514 | peg$currPos++;
2515 | } else {
2516 | s1 = peg$FAILED;
2517 | if (peg$silentFails === 0) { peg$fail(peg$c116); }
2518 | }
2519 | if (s1 !== peg$FAILED) {
2520 | if (input.charCodeAt(peg$currPos) === 45) {
2521 | s2 = peg$c111;
2522 | peg$currPos++;
2523 | } else {
2524 | s2 = peg$FAILED;
2525 | if (peg$silentFails === 0) { peg$fail(peg$c112); }
2526 | }
2527 | if (s2 !== peg$FAILED) {
2528 | if (input.charCodeAt(peg$currPos) === 126) {
2529 | s3 = peg$c115;
2530 | peg$currPos++;
2531 | } else {
2532 | s3 = peg$FAILED;
2533 | if (peg$silentFails === 0) { peg$fail(peg$c116); }
2534 | }
2535 | if (s3 !== peg$FAILED) {
2536 | peg$reportedPos = s0;
2537 | s1 = peg$c118();
2538 | s0 = s1;
2539 | } else {
2540 | peg$currPos = s0;
2541 | s0 = peg$c0;
2542 | }
2543 | } else {
2544 | peg$currPos = s0;
2545 | s0 = peg$c0;
2546 | }
2547 | } else {
2548 | peg$currPos = s0;
2549 | s0 = peg$c0;
2550 | }
2551 | if (s0 === peg$FAILED) {
2552 | s0 = peg$currPos;
2553 | if (input.charCodeAt(peg$currPos) === 126) {
2554 | s1 = peg$c115;
2555 | peg$currPos++;
2556 | } else {
2557 | s1 = peg$FAILED;
2558 | if (peg$silentFails === 0) { peg$fail(peg$c116); }
2559 | }
2560 | if (s1 !== peg$FAILED) {
2561 | peg$reportedPos = s0;
2562 | s1 = peg$c119();
2563 | }
2564 | s0 = s1;
2565 | if (s0 === peg$FAILED) {
2566 | s0 = peg$currPos;
2567 | s1 = peg$c120;
2568 | if (s1 !== peg$FAILED) {
2569 | peg$reportedPos = s0;
2570 | s1 = peg$c121();
2571 | }
2572 | s0 = s1;
2573 | }
2574 | }
2575 | }
2576 | }
2577 | }
2578 | peg$silentFails--;
2579 | if (s0 === peg$FAILED) {
2580 | s1 = peg$FAILED;
2581 | if (peg$silentFails === 0) { peg$fail(peg$c110); }
2582 | }
2583 |
2584 | return s0;
2585 | }
2586 |
2587 | function peg$parseScope() {
2588 | var s0, s1, s2;
2589 |
2590 | s0 = peg$currPos;
2591 | s1 = [];
2592 | if (input.charCodeAt(peg$currPos) === 38) {
2593 | s2 = peg$c122;
2594 | peg$currPos++;
2595 | } else {
2596 | s2 = peg$FAILED;
2597 | if (peg$silentFails === 0) { peg$fail(peg$c123); }
2598 | }
2599 | if (s2 !== peg$FAILED) {
2600 | while (s2 !== peg$FAILED) {
2601 | s1.push(s2);
2602 | if (input.charCodeAt(peg$currPos) === 38) {
2603 | s2 = peg$c122;
2604 | peg$currPos++;
2605 | } else {
2606 | s2 = peg$FAILED;
2607 | if (peg$silentFails === 0) { peg$fail(peg$c123); }
2608 | }
2609 | }
2610 | } else {
2611 | s1 = peg$c0;
2612 | }
2613 | if (s1 !== peg$FAILED) {
2614 | peg$reportedPos = s0;
2615 | s1 = peg$c124(s1);
2616 | }
2617 | s0 = s1;
2618 | if (s0 === peg$FAILED) {
2619 | s0 = peg$currPos;
2620 | s1 = [];
2621 | if (input.charCodeAt(peg$currPos) === 94) {
2622 | s2 = peg$c125;
2623 | peg$currPos++;
2624 | } else {
2625 | s2 = peg$FAILED;
2626 | if (peg$silentFails === 0) { peg$fail(peg$c126); }
2627 | }
2628 | if (s2 !== peg$FAILED) {
2629 | while (s2 !== peg$FAILED) {
2630 | s1.push(s2);
2631 | if (input.charCodeAt(peg$currPos) === 94) {
2632 | s2 = peg$c125;
2633 | peg$currPos++;
2634 | } else {
2635 | s2 = peg$FAILED;
2636 | if (peg$silentFails === 0) { peg$fail(peg$c126); }
2637 | }
2638 | }
2639 | } else {
2640 | s1 = peg$c0;
2641 | }
2642 | if (s1 !== peg$FAILED) {
2643 | peg$reportedPos = s0;
2644 | s1 = peg$c127(s1);
2645 | }
2646 | s0 = s1;
2647 | if (s0 === peg$FAILED) {
2648 | s0 = peg$currPos;
2649 | s1 = [];
2650 | if (input.charCodeAt(peg$currPos) === 36) {
2651 | s2 = peg$c128;
2652 | peg$currPos++;
2653 | } else {
2654 | s2 = peg$FAILED;
2655 | if (peg$silentFails === 0) { peg$fail(peg$c129); }
2656 | }
2657 | if (s2 !== peg$FAILED) {
2658 | while (s2 !== peg$FAILED) {
2659 | s1.push(s2);
2660 | if (input.charCodeAt(peg$currPos) === 36) {
2661 | s2 = peg$c128;
2662 | peg$currPos++;
2663 | } else {
2664 | s2 = peg$FAILED;
2665 | if (peg$silentFails === 0) { peg$fail(peg$c129); }
2666 | }
2667 | }
2668 | } else {
2669 | s1 = peg$c0;
2670 | }
2671 | if (s1 !== peg$FAILED) {
2672 | peg$reportedPos = s0;
2673 | s1 = peg$c130(s1);
2674 | }
2675 | s0 = s1;
2676 | }
2677 | }
2678 |
2679 | return s0;
2680 | }
2681 |
2682 | function peg$parseExplicitGap() {
2683 | var s0, s1, s2, s3, s4;
2684 |
2685 | peg$silentFails++;
2686 | s0 = peg$currPos;
2687 | s1 = peg$parseScope();
2688 | if (s1 !== peg$FAILED) {
2689 | s2 = [];
2690 | if (peg$c132.test(input.charAt(peg$currPos))) {
2691 | s3 = input.charAt(peg$currPos);
2692 | peg$currPos++;
2693 | } else {
2694 | s3 = peg$FAILED;
2695 | if (peg$silentFails === 0) { peg$fail(peg$c133); }
2696 | }
2697 | if (s3 !== peg$FAILED) {
2698 | while (s3 !== peg$FAILED) {
2699 | s2.push(s3);
2700 | if (peg$c132.test(input.charAt(peg$currPos))) {
2701 | s3 = input.charAt(peg$currPos);
2702 | peg$currPos++;
2703 | } else {
2704 | s3 = peg$FAILED;
2705 | if (peg$silentFails === 0) { peg$fail(peg$c133); }
2706 | }
2707 | }
2708 | } else {
2709 | s2 = peg$c0;
2710 | }
2711 | if (s2 !== peg$FAILED) {
2712 | peg$reportedPos = s0;
2713 | s1 = peg$c134(s1, s2);
2714 | s0 = s1;
2715 | } else {
2716 | peg$currPos = s0;
2717 | s0 = peg$c0;
2718 | }
2719 | } else {
2720 | peg$currPos = s0;
2721 | s0 = peg$c0;
2722 | }
2723 | if (s0 === peg$FAILED) {
2724 | s0 = peg$currPos;
2725 | s1 = [];
2726 | if (peg$c132.test(input.charAt(peg$currPos))) {
2727 | s2 = input.charAt(peg$currPos);
2728 | peg$currPos++;
2729 | } else {
2730 | s2 = peg$FAILED;
2731 | if (peg$silentFails === 0) { peg$fail(peg$c133); }
2732 | }
2733 | if (s2 !== peg$FAILED) {
2734 | while (s2 !== peg$FAILED) {
2735 | s1.push(s2);
2736 | if (peg$c132.test(input.charAt(peg$currPos))) {
2737 | s2 = input.charAt(peg$currPos);
2738 | peg$currPos++;
2739 | } else {
2740 | s2 = peg$FAILED;
2741 | if (peg$silentFails === 0) { peg$fail(peg$c133); }
2742 | }
2743 | }
2744 | } else {
2745 | s1 = peg$c0;
2746 | }
2747 | if (s1 !== peg$FAILED) {
2748 | peg$reportedPos = s0;
2749 | s1 = peg$c135(s1);
2750 | }
2751 | s0 = s1;
2752 | if (s0 === peg$FAILED) {
2753 | s0 = peg$currPos;
2754 | s1 = [];
2755 | if (peg$c136.test(input.charAt(peg$currPos))) {
2756 | s2 = input.charAt(peg$currPos);
2757 | peg$currPos++;
2758 | } else {
2759 | s2 = peg$FAILED;
2760 | if (peg$silentFails === 0) { peg$fail(peg$c137); }
2761 | }
2762 | while (s2 !== peg$FAILED) {
2763 | s1.push(s2);
2764 | if (peg$c136.test(input.charAt(peg$currPos))) {
2765 | s2 = input.charAt(peg$currPos);
2766 | peg$currPos++;
2767 | } else {
2768 | s2 = peg$FAILED;
2769 | if (peg$silentFails === 0) { peg$fail(peg$c137); }
2770 | }
2771 | }
2772 | if (s1 !== peg$FAILED) {
2773 | if (input.charCodeAt(peg$currPos) === 91) {
2774 | s2 = peg$c103;
2775 | peg$currPos++;
2776 | } else {
2777 | s2 = peg$FAILED;
2778 | if (peg$silentFails === 0) { peg$fail(peg$c104); }
2779 | }
2780 | if (s2 !== peg$FAILED) {
2781 | s3 = [];
2782 | if (peg$c138.test(input.charAt(peg$currPos))) {
2783 | s4 = input.charAt(peg$currPos);
2784 | peg$currPos++;
2785 | } else {
2786 | s4 = peg$FAILED;
2787 | if (peg$silentFails === 0) { peg$fail(peg$c139); }
2788 | }
2789 | if (s4 !== peg$FAILED) {
2790 | while (s4 !== peg$FAILED) {
2791 | s3.push(s4);
2792 | if (peg$c138.test(input.charAt(peg$currPos))) {
2793 | s4 = input.charAt(peg$currPos);
2794 | peg$currPos++;
2795 | } else {
2796 | s4 = peg$FAILED;
2797 | if (peg$silentFails === 0) { peg$fail(peg$c139); }
2798 | }
2799 | }
2800 | } else {
2801 | s3 = peg$c0;
2802 | }
2803 | if (s3 !== peg$FAILED) {
2804 | if (input.charCodeAt(peg$currPos) === 93) {
2805 | s4 = peg$c105;
2806 | peg$currPos++;
2807 | } else {
2808 | s4 = peg$FAILED;
2809 | if (peg$silentFails === 0) { peg$fail(peg$c106); }
2810 | }
2811 | if (s4 !== peg$FAILED) {
2812 | peg$reportedPos = s0;
2813 | s1 = peg$c140(s1, s3);
2814 | s0 = s1;
2815 | } else {
2816 | peg$currPos = s0;
2817 | s0 = peg$c0;
2818 | }
2819 | } else {
2820 | peg$currPos = s0;
2821 | s0 = peg$c0;
2822 | }
2823 | } else {
2824 | peg$currPos = s0;
2825 | s0 = peg$c0;
2826 | }
2827 | } else {
2828 | peg$currPos = s0;
2829 | s0 = peg$c0;
2830 | }
2831 | }
2832 | }
2833 | peg$silentFails--;
2834 | if (s0 === peg$FAILED) {
2835 | s1 = peg$FAILED;
2836 | if (peg$silentFails === 0) { peg$fail(peg$c131); }
2837 | }
2838 |
2839 | return s0;
2840 | }
2841 |
2842 | function peg$parseStrengthAndWeight() {
2843 | var s0, s1, s2, s3, s4;
2844 |
2845 | peg$silentFails++;
2846 | s0 = peg$currPos;
2847 | if (input.charCodeAt(peg$currPos) === 33) {
2848 | s1 = peg$c142;
2849 | peg$currPos++;
2850 | } else {
2851 | s1 = peg$FAILED;
2852 | if (peg$silentFails === 0) { peg$fail(peg$c143); }
2853 | }
2854 | if (s1 !== peg$FAILED) {
2855 | s2 = [];
2856 | if (peg$c144.test(input.charAt(peg$currPos))) {
2857 | s3 = input.charAt(peg$currPos);
2858 | peg$currPos++;
2859 | } else {
2860 | s3 = peg$FAILED;
2861 | if (peg$silentFails === 0) { peg$fail(peg$c145); }
2862 | }
2863 | if (s3 !== peg$FAILED) {
2864 | while (s3 !== peg$FAILED) {
2865 | s2.push(s3);
2866 | if (peg$c144.test(input.charAt(peg$currPos))) {
2867 | s3 = input.charAt(peg$currPos);
2868 | peg$currPos++;
2869 | } else {
2870 | s3 = peg$FAILED;
2871 | if (peg$silentFails === 0) { peg$fail(peg$c145); }
2872 | }
2873 | }
2874 | } else {
2875 | s2 = peg$c0;
2876 | }
2877 | if (s2 === peg$FAILED) {
2878 | s2 = peg$c5;
2879 | }
2880 | if (s2 !== peg$FAILED) {
2881 | s3 = [];
2882 | if (peg$c146.test(input.charAt(peg$currPos))) {
2883 | s4 = input.charAt(peg$currPos);
2884 | peg$currPos++;
2885 | } else {
2886 | s4 = peg$FAILED;
2887 | if (peg$silentFails === 0) { peg$fail(peg$c147); }
2888 | }
2889 | if (s4 !== peg$FAILED) {
2890 | while (s4 !== peg$FAILED) {
2891 | s3.push(s4);
2892 | if (peg$c146.test(input.charAt(peg$currPos))) {
2893 | s4 = input.charAt(peg$currPos);
2894 | peg$currPos++;
2895 | } else {
2896 | s4 = peg$FAILED;
2897 | if (peg$silentFails === 0) { peg$fail(peg$c147); }
2898 | }
2899 | }
2900 | } else {
2901 | s3 = peg$c0;
2902 | }
2903 | if (s3 === peg$FAILED) {
2904 | s3 = peg$c5;
2905 | }
2906 | if (s3 !== peg$FAILED) {
2907 | peg$reportedPos = s0;
2908 | s1 = peg$c148(s2, s3);
2909 | s0 = s1;
2910 | } else {
2911 | peg$currPos = s0;
2912 | s0 = peg$c0;
2913 | }
2914 | } else {
2915 | peg$currPos = s0;
2916 | s0 = peg$c0;
2917 | }
2918 | } else {
2919 | peg$currPos = s0;
2920 | s0 = peg$c0;
2921 | }
2922 | if (s0 === peg$FAILED) {
2923 | s0 = peg$currPos;
2924 | if (input.charCodeAt(peg$currPos) === 33) {
2925 | s1 = peg$c142;
2926 | peg$currPos++;
2927 | } else {
2928 | s1 = peg$FAILED;
2929 | if (peg$silentFails === 0) { peg$fail(peg$c143); }
2930 | }
2931 | if (s1 !== peg$FAILED) {
2932 | if (input.length > peg$currPos) {
2933 | s2 = input.charAt(peg$currPos);
2934 | peg$currPos++;
2935 | } else {
2936 | s2 = peg$FAILED;
2937 | if (peg$silentFails === 0) { peg$fail(peg$c149); }
2938 | }
2939 | if (s2 === peg$FAILED) {
2940 | s2 = peg$c5;
2941 | }
2942 | if (s2 !== peg$FAILED) {
2943 | peg$reportedPos = s0;
2944 | s1 = peg$c150();
2945 | s0 = s1;
2946 | } else {
2947 | peg$currPos = s0;
2948 | s0 = peg$c0;
2949 | }
2950 | } else {
2951 | peg$currPos = s0;
2952 | s0 = peg$c0;
2953 | }
2954 | }
2955 | peg$silentFails--;
2956 | if (s0 === peg$FAILED) {
2957 | s1 = peg$FAILED;
2958 | if (peg$silentFails === 0) { peg$fail(peg$c141); }
2959 | }
2960 |
2961 | return s0;
2962 | }
2963 |
2964 | function peg$parseNameChars() {
2965 | var s0;
2966 |
2967 | if (peg$c151.test(input.charAt(peg$currPos))) {
2968 | s0 = input.charAt(peg$currPos);
2969 | peg$currPos++;
2970 | } else {
2971 | s0 = peg$FAILED;
2972 | if (peg$silentFails === 0) { peg$fail(peg$c152); }
2973 | }
2974 |
2975 | return s0;
2976 | }
2977 |
2978 | function peg$parseNameCharsWithSpace() {
2979 | var s0;
2980 |
2981 | s0 = peg$parseNameChars();
2982 | if (s0 === peg$FAILED) {
2983 | if (input.charCodeAt(peg$currPos) === 32) {
2984 | s0 = peg$c153;
2985 | peg$currPos++;
2986 | } else {
2987 | s0 = peg$FAILED;
2988 | if (peg$silentFails === 0) { peg$fail(peg$c154); }
2989 | }
2990 | }
2991 |
2992 | return s0;
2993 | }
2994 |
2995 | function peg$parseLiteral() {
2996 | var s0, s1;
2997 |
2998 | s0 = peg$currPos;
2999 | s1 = peg$parseNumber();
3000 | if (s1 !== peg$FAILED) {
3001 | peg$reportedPos = s0;
3002 | s1 = peg$c155(s1);
3003 | }
3004 | s0 = s1;
3005 |
3006 | return s0;
3007 | }
3008 |
3009 | function peg$parseNumber() {
3010 | var s0;
3011 |
3012 | s0 = peg$parseReal();
3013 | if (s0 === peg$FAILED) {
3014 | s0 = peg$parseInteger();
3015 | }
3016 |
3017 | return s0;
3018 | }
3019 |
3020 | function peg$parseInteger() {
3021 | var s0, s1, s2;
3022 |
3023 | s0 = peg$currPos;
3024 | s1 = [];
3025 | if (peg$c146.test(input.charAt(peg$currPos))) {
3026 | s2 = input.charAt(peg$currPos);
3027 | peg$currPos++;
3028 | } else {
3029 | s2 = peg$FAILED;
3030 | if (peg$silentFails === 0) { peg$fail(peg$c147); }
3031 | }
3032 | if (s2 !== peg$FAILED) {
3033 | while (s2 !== peg$FAILED) {
3034 | s1.push(s2);
3035 | if (peg$c146.test(input.charAt(peg$currPos))) {
3036 | s2 = input.charAt(peg$currPos);
3037 | peg$currPos++;
3038 | } else {
3039 | s2 = peg$FAILED;
3040 | if (peg$silentFails === 0) { peg$fail(peg$c147); }
3041 | }
3042 | }
3043 | } else {
3044 | s1 = peg$c0;
3045 | }
3046 | if (s1 !== peg$FAILED) {
3047 | peg$reportedPos = s0;
3048 | s1 = peg$c156(s1);
3049 | }
3050 | s0 = s1;
3051 |
3052 | return s0;
3053 | }
3054 |
3055 | function peg$parseReal() {
3056 | var s0, s1, s2, s3, s4;
3057 |
3058 | s0 = peg$currPos;
3059 | s1 = peg$currPos;
3060 | s2 = peg$parseInteger();
3061 | if (s2 !== peg$FAILED) {
3062 | if (input.charCodeAt(peg$currPos) === 46) {
3063 | s3 = peg$c157;
3064 | peg$currPos++;
3065 | } else {
3066 | s3 = peg$FAILED;
3067 | if (peg$silentFails === 0) { peg$fail(peg$c158); }
3068 | }
3069 | if (s3 !== peg$FAILED) {
3070 | s4 = peg$parseInteger();
3071 | if (s4 !== peg$FAILED) {
3072 | s2 = [s2, s3, s4];
3073 | s1 = s2;
3074 | } else {
3075 | peg$currPos = s1;
3076 | s1 = peg$c0;
3077 | }
3078 | } else {
3079 | peg$currPos = s1;
3080 | s1 = peg$c0;
3081 | }
3082 | } else {
3083 | peg$currPos = s1;
3084 | s1 = peg$c0;
3085 | }
3086 | if (s1 !== peg$FAILED) {
3087 | peg$reportedPos = s0;
3088 | s1 = peg$c159(s1);
3089 | }
3090 | s0 = s1;
3091 |
3092 | return s0;
3093 | }
3094 |
3095 | function peg$parseSignedInteger() {
3096 | var s0, s1, s2, s3;
3097 |
3098 | s0 = peg$currPos;
3099 | if (peg$c160.test(input.charAt(peg$currPos))) {
3100 | s1 = input.charAt(peg$currPos);
3101 | peg$currPos++;
3102 | } else {
3103 | s1 = peg$FAILED;
3104 | if (peg$silentFails === 0) { peg$fail(peg$c161); }
3105 | }
3106 | if (s1 === peg$FAILED) {
3107 | s1 = peg$c5;
3108 | }
3109 | if (s1 !== peg$FAILED) {
3110 | s2 = [];
3111 | if (peg$c146.test(input.charAt(peg$currPos))) {
3112 | s3 = input.charAt(peg$currPos);
3113 | peg$currPos++;
3114 | } else {
3115 | s3 = peg$FAILED;
3116 | if (peg$silentFails === 0) { peg$fail(peg$c147); }
3117 | }
3118 | if (s3 !== peg$FAILED) {
3119 | while (s3 !== peg$FAILED) {
3120 | s2.push(s3);
3121 | if (peg$c146.test(input.charAt(peg$currPos))) {
3122 | s3 = input.charAt(peg$currPos);
3123 | peg$currPos++;
3124 | } else {
3125 | s3 = peg$FAILED;
3126 | if (peg$silentFails === 0) { peg$fail(peg$c147); }
3127 | }
3128 | }
3129 | } else {
3130 | s2 = peg$c0;
3131 | }
3132 | if (s2 !== peg$FAILED) {
3133 | s1 = [s1, s2];
3134 | s0 = s1;
3135 | } else {
3136 | peg$currPos = s0;
3137 | s0 = peg$c0;
3138 | }
3139 | } else {
3140 | peg$currPos = s0;
3141 | s0 = peg$c0;
3142 | }
3143 |
3144 | return s0;
3145 | }
3146 |
3147 | function peg$parseSourceCharacter() {
3148 | var s0;
3149 |
3150 | if (input.length > peg$currPos) {
3151 | s0 = input.charAt(peg$currPos);
3152 | peg$currPos++;
3153 | } else {
3154 | s0 = peg$FAILED;
3155 | if (peg$silentFails === 0) { peg$fail(peg$c149); }
3156 | }
3157 |
3158 | return s0;
3159 | }
3160 |
3161 | function peg$parseWhiteSpace() {
3162 | var s0, s1;
3163 |
3164 | peg$silentFails++;
3165 | if (peg$c163.test(input.charAt(peg$currPos))) {
3166 | s0 = input.charAt(peg$currPos);
3167 | peg$currPos++;
3168 | } else {
3169 | s0 = peg$FAILED;
3170 | if (peg$silentFails === 0) { peg$fail(peg$c164); }
3171 | }
3172 | peg$silentFails--;
3173 | if (s0 === peg$FAILED) {
3174 | s1 = peg$FAILED;
3175 | if (peg$silentFails === 0) { peg$fail(peg$c162); }
3176 | }
3177 |
3178 | return s0;
3179 | }
3180 |
3181 | function peg$parseLineTerminator() {
3182 | var s0;
3183 |
3184 | if (peg$c165.test(input.charAt(peg$currPos))) {
3185 | s0 = input.charAt(peg$currPos);
3186 | peg$currPos++;
3187 | } else {
3188 | s0 = peg$FAILED;
3189 | if (peg$silentFails === 0) { peg$fail(peg$c166); }
3190 | }
3191 |
3192 | return s0;
3193 | }
3194 |
3195 | function peg$parseLineTerminatorSequence() {
3196 | var s0, s1;
3197 |
3198 | peg$silentFails++;
3199 | if (input.charCodeAt(peg$currPos) === 10) {
3200 | s0 = peg$c168;
3201 | peg$currPos++;
3202 | } else {
3203 | s0 = peg$FAILED;
3204 | if (peg$silentFails === 0) { peg$fail(peg$c169); }
3205 | }
3206 | if (s0 === peg$FAILED) {
3207 | if (input.substr(peg$currPos, 2) === peg$c170) {
3208 | s0 = peg$c170;
3209 | peg$currPos += 2;
3210 | } else {
3211 | s0 = peg$FAILED;
3212 | if (peg$silentFails === 0) { peg$fail(peg$c171); }
3213 | }
3214 | if (s0 === peg$FAILED) {
3215 | if (input.charCodeAt(peg$currPos) === 13) {
3216 | s0 = peg$c172;
3217 | peg$currPos++;
3218 | } else {
3219 | s0 = peg$FAILED;
3220 | if (peg$silentFails === 0) { peg$fail(peg$c173); }
3221 | }
3222 | if (s0 === peg$FAILED) {
3223 | if (input.charCodeAt(peg$currPos) === 8232) {
3224 | s0 = peg$c174;
3225 | peg$currPos++;
3226 | } else {
3227 | s0 = peg$FAILED;
3228 | if (peg$silentFails === 0) { peg$fail(peg$c175); }
3229 | }
3230 | if (s0 === peg$FAILED) {
3231 | if (input.charCodeAt(peg$currPos) === 8233) {
3232 | s0 = peg$c176;
3233 | peg$currPos++;
3234 | } else {
3235 | s0 = peg$FAILED;
3236 | if (peg$silentFails === 0) { peg$fail(peg$c177); }
3237 | }
3238 | }
3239 | }
3240 | }
3241 | }
3242 | peg$silentFails--;
3243 | if (s0 === peg$FAILED) {
3244 | s1 = peg$FAILED;
3245 | if (peg$silentFails === 0) { peg$fail(peg$c167); }
3246 | }
3247 |
3248 | return s0;
3249 | }
3250 |
3251 | function peg$parseEOS() {
3252 | var s0, s1, s2;
3253 |
3254 | s0 = peg$currPos;
3255 | s1 = peg$parse__();
3256 | if (s1 !== peg$FAILED) {
3257 | if (input.charCodeAt(peg$currPos) === 59) {
3258 | s2 = peg$c178;
3259 | peg$currPos++;
3260 | } else {
3261 | s2 = peg$FAILED;
3262 | if (peg$silentFails === 0) { peg$fail(peg$c179); }
3263 | }
3264 | if (s2 !== peg$FAILED) {
3265 | s1 = [s1, s2];
3266 | s0 = s1;
3267 | } else {
3268 | peg$currPos = s0;
3269 | s0 = peg$c0;
3270 | }
3271 | } else {
3272 | peg$currPos = s0;
3273 | s0 = peg$c0;
3274 | }
3275 | if (s0 === peg$FAILED) {
3276 | s0 = peg$currPos;
3277 | s1 = peg$parse_();
3278 | if (s1 !== peg$FAILED) {
3279 | s2 = peg$parseLineTerminatorSequence();
3280 | if (s2 !== peg$FAILED) {
3281 | s1 = [s1, s2];
3282 | s0 = s1;
3283 | } else {
3284 | peg$currPos = s0;
3285 | s0 = peg$c0;
3286 | }
3287 | } else {
3288 | peg$currPos = s0;
3289 | s0 = peg$c0;
3290 | }
3291 | if (s0 === peg$FAILED) {
3292 | s0 = peg$currPos;
3293 | s1 = peg$parse__();
3294 | if (s1 !== peg$FAILED) {
3295 | s2 = peg$parseEOF();
3296 | if (s2 !== peg$FAILED) {
3297 | s1 = [s1, s2];
3298 | s0 = s1;
3299 | } else {
3300 | peg$currPos = s0;
3301 | s0 = peg$c0;
3302 | }
3303 | } else {
3304 | peg$currPos = s0;
3305 | s0 = peg$c0;
3306 | }
3307 | }
3308 | }
3309 |
3310 | return s0;
3311 | }
3312 |
3313 | function peg$parseEOF() {
3314 | var s0, s1;
3315 |
3316 | s0 = peg$currPos;
3317 | peg$silentFails++;
3318 | if (input.length > peg$currPos) {
3319 | s1 = input.charAt(peg$currPos);
3320 | peg$currPos++;
3321 | } else {
3322 | s1 = peg$FAILED;
3323 | if (peg$silentFails === 0) { peg$fail(peg$c149); }
3324 | }
3325 | peg$silentFails--;
3326 | if (s1 === peg$FAILED) {
3327 | s0 = peg$c180;
3328 | } else {
3329 | peg$currPos = s0;
3330 | s0 = peg$c0;
3331 | }
3332 |
3333 | return s0;
3334 | }
3335 |
3336 | function peg$parseComment() {
3337 | var s0, s1;
3338 |
3339 | peg$silentFails++;
3340 | s0 = peg$parseMultiLineComment();
3341 | if (s0 === peg$FAILED) {
3342 | s0 = peg$parseSingleLineComment();
3343 | }
3344 | peg$silentFails--;
3345 | if (s0 === peg$FAILED) {
3346 | s1 = peg$FAILED;
3347 | if (peg$silentFails === 0) { peg$fail(peg$c181); }
3348 | }
3349 |
3350 | return s0;
3351 | }
3352 |
3353 | function peg$parseMultiLineComment() {
3354 | var s0, s1, s2, s3, s4, s5;
3355 |
3356 | s0 = peg$currPos;
3357 | if (input.substr(peg$currPos, 2) === peg$c182) {
3358 | s1 = peg$c182;
3359 | peg$currPos += 2;
3360 | } else {
3361 | s1 = peg$FAILED;
3362 | if (peg$silentFails === 0) { peg$fail(peg$c183); }
3363 | }
3364 | if (s1 !== peg$FAILED) {
3365 | s2 = [];
3366 | s3 = peg$currPos;
3367 | s4 = peg$currPos;
3368 | peg$silentFails++;
3369 | if (input.substr(peg$currPos, 2) === peg$c184) {
3370 | s5 = peg$c184;
3371 | peg$currPos += 2;
3372 | } else {
3373 | s5 = peg$FAILED;
3374 | if (peg$silentFails === 0) { peg$fail(peg$c185); }
3375 | }
3376 | peg$silentFails--;
3377 | if (s5 === peg$FAILED) {
3378 | s4 = peg$c180;
3379 | } else {
3380 | peg$currPos = s4;
3381 | s4 = peg$c0;
3382 | }
3383 | if (s4 !== peg$FAILED) {
3384 | s5 = peg$parseSourceCharacter();
3385 | if (s5 !== peg$FAILED) {
3386 | s4 = [s4, s5];
3387 | s3 = s4;
3388 | } else {
3389 | peg$currPos = s3;
3390 | s3 = peg$c0;
3391 | }
3392 | } else {
3393 | peg$currPos = s3;
3394 | s3 = peg$c0;
3395 | }
3396 | while (s3 !== peg$FAILED) {
3397 | s2.push(s3);
3398 | s3 = peg$currPos;
3399 | s4 = peg$currPos;
3400 | peg$silentFails++;
3401 | if (input.substr(peg$currPos, 2) === peg$c184) {
3402 | s5 = peg$c184;
3403 | peg$currPos += 2;
3404 | } else {
3405 | s5 = peg$FAILED;
3406 | if (peg$silentFails === 0) { peg$fail(peg$c185); }
3407 | }
3408 | peg$silentFails--;
3409 | if (s5 === peg$FAILED) {
3410 | s4 = peg$c180;
3411 | } else {
3412 | peg$currPos = s4;
3413 | s4 = peg$c0;
3414 | }
3415 | if (s4 !== peg$FAILED) {
3416 | s5 = peg$parseSourceCharacter();
3417 | if (s5 !== peg$FAILED) {
3418 | s4 = [s4, s5];
3419 | s3 = s4;
3420 | } else {
3421 | peg$currPos = s3;
3422 | s3 = peg$c0;
3423 | }
3424 | } else {
3425 | peg$currPos = s3;
3426 | s3 = peg$c0;
3427 | }
3428 | }
3429 | if (s2 !== peg$FAILED) {
3430 | if (input.substr(peg$currPos, 2) === peg$c184) {
3431 | s3 = peg$c184;
3432 | peg$currPos += 2;
3433 | } else {
3434 | s3 = peg$FAILED;
3435 | if (peg$silentFails === 0) { peg$fail(peg$c185); }
3436 | }
3437 | if (s3 !== peg$FAILED) {
3438 | s1 = [s1, s2, s3];
3439 | s0 = s1;
3440 | } else {
3441 | peg$currPos = s0;
3442 | s0 = peg$c0;
3443 | }
3444 | } else {
3445 | peg$currPos = s0;
3446 | s0 = peg$c0;
3447 | }
3448 | } else {
3449 | peg$currPos = s0;
3450 | s0 = peg$c0;
3451 | }
3452 |
3453 | return s0;
3454 | }
3455 |
3456 | function peg$parseMultiLineCommentNoLineTerminator() {
3457 | var s0, s1, s2, s3, s4, s5;
3458 |
3459 | s0 = peg$currPos;
3460 | if (input.substr(peg$currPos, 2) === peg$c182) {
3461 | s1 = peg$c182;
3462 | peg$currPos += 2;
3463 | } else {
3464 | s1 = peg$FAILED;
3465 | if (peg$silentFails === 0) { peg$fail(peg$c183); }
3466 | }
3467 | if (s1 !== peg$FAILED) {
3468 | s2 = [];
3469 | s3 = peg$currPos;
3470 | s4 = peg$currPos;
3471 | peg$silentFails++;
3472 | if (input.substr(peg$currPos, 2) === peg$c184) {
3473 | s5 = peg$c184;
3474 | peg$currPos += 2;
3475 | } else {
3476 | s5 = peg$FAILED;
3477 | if (peg$silentFails === 0) { peg$fail(peg$c185); }
3478 | }
3479 | if (s5 === peg$FAILED) {
3480 | s5 = peg$parseLineTerminator();
3481 | }
3482 | peg$silentFails--;
3483 | if (s5 === peg$FAILED) {
3484 | s4 = peg$c180;
3485 | } else {
3486 | peg$currPos = s4;
3487 | s4 = peg$c0;
3488 | }
3489 | if (s4 !== peg$FAILED) {
3490 | s5 = peg$parseSourceCharacter();
3491 | if (s5 !== peg$FAILED) {
3492 | s4 = [s4, s5];
3493 | s3 = s4;
3494 | } else {
3495 | peg$currPos = s3;
3496 | s3 = peg$c0;
3497 | }
3498 | } else {
3499 | peg$currPos = s3;
3500 | s3 = peg$c0;
3501 | }
3502 | while (s3 !== peg$FAILED) {
3503 | s2.push(s3);
3504 | s3 = peg$currPos;
3505 | s4 = peg$currPos;
3506 | peg$silentFails++;
3507 | if (input.substr(peg$currPos, 2) === peg$c184) {
3508 | s5 = peg$c184;
3509 | peg$currPos += 2;
3510 | } else {
3511 | s5 = peg$FAILED;
3512 | if (peg$silentFails === 0) { peg$fail(peg$c185); }
3513 | }
3514 | if (s5 === peg$FAILED) {
3515 | s5 = peg$parseLineTerminator();
3516 | }
3517 | peg$silentFails--;
3518 | if (s5 === peg$FAILED) {
3519 | s4 = peg$c180;
3520 | } else {
3521 | peg$currPos = s4;
3522 | s4 = peg$c0;
3523 | }
3524 | if (s4 !== peg$FAILED) {
3525 | s5 = peg$parseSourceCharacter();
3526 | if (s5 !== peg$FAILED) {
3527 | s4 = [s4, s5];
3528 | s3 = s4;
3529 | } else {
3530 | peg$currPos = s3;
3531 | s3 = peg$c0;
3532 | }
3533 | } else {
3534 | peg$currPos = s3;
3535 | s3 = peg$c0;
3536 | }
3537 | }
3538 | if (s2 !== peg$FAILED) {
3539 | if (input.substr(peg$currPos, 2) === peg$c184) {
3540 | s3 = peg$c184;
3541 | peg$currPos += 2;
3542 | } else {
3543 | s3 = peg$FAILED;
3544 | if (peg$silentFails === 0) { peg$fail(peg$c185); }
3545 | }
3546 | if (s3 !== peg$FAILED) {
3547 | s1 = [s1, s2, s3];
3548 | s0 = s1;
3549 | } else {
3550 | peg$currPos = s0;
3551 | s0 = peg$c0;
3552 | }
3553 | } else {
3554 | peg$currPos = s0;
3555 | s0 = peg$c0;
3556 | }
3557 | } else {
3558 | peg$currPos = s0;
3559 | s0 = peg$c0;
3560 | }
3561 |
3562 | return s0;
3563 | }
3564 |
3565 | function peg$parseSingleLineComment() {
3566 | var s0, s1, s2, s3, s4, s5;
3567 |
3568 | s0 = peg$currPos;
3569 | if (input.substr(peg$currPos, 2) === peg$c186) {
3570 | s1 = peg$c186;
3571 | peg$currPos += 2;
3572 | } else {
3573 | s1 = peg$FAILED;
3574 | if (peg$silentFails === 0) { peg$fail(peg$c187); }
3575 | }
3576 | if (s1 !== peg$FAILED) {
3577 | s2 = [];
3578 | s3 = peg$currPos;
3579 | s4 = peg$currPos;
3580 | peg$silentFails++;
3581 | s5 = peg$parseLineTerminator();
3582 | peg$silentFails--;
3583 | if (s5 === peg$FAILED) {
3584 | s4 = peg$c180;
3585 | } else {
3586 | peg$currPos = s4;
3587 | s4 = peg$c0;
3588 | }
3589 | if (s4 !== peg$FAILED) {
3590 | s5 = peg$parseSourceCharacter();
3591 | if (s5 !== peg$FAILED) {
3592 | s4 = [s4, s5];
3593 | s3 = s4;
3594 | } else {
3595 | peg$currPos = s3;
3596 | s3 = peg$c0;
3597 | }
3598 | } else {
3599 | peg$currPos = s3;
3600 | s3 = peg$c0;
3601 | }
3602 | while (s3 !== peg$FAILED) {
3603 | s2.push(s3);
3604 | s3 = peg$currPos;
3605 | s4 = peg$currPos;
3606 | peg$silentFails++;
3607 | s5 = peg$parseLineTerminator();
3608 | peg$silentFails--;
3609 | if (s5 === peg$FAILED) {
3610 | s4 = peg$c180;
3611 | } else {
3612 | peg$currPos = s4;
3613 | s4 = peg$c0;
3614 | }
3615 | if (s4 !== peg$FAILED) {
3616 | s5 = peg$parseSourceCharacter();
3617 | if (s5 !== peg$FAILED) {
3618 | s4 = [s4, s5];
3619 | s3 = s4;
3620 | } else {
3621 | peg$currPos = s3;
3622 | s3 = peg$c0;
3623 | }
3624 | } else {
3625 | peg$currPos = s3;
3626 | s3 = peg$c0;
3627 | }
3628 | }
3629 | if (s2 !== peg$FAILED) {
3630 | s3 = peg$parseLineTerminator();
3631 | if (s3 === peg$FAILED) {
3632 | s3 = peg$parseEOF();
3633 | }
3634 | if (s3 !== peg$FAILED) {
3635 | s1 = [s1, s2, s3];
3636 | s0 = s1;
3637 | } else {
3638 | peg$currPos = s0;
3639 | s0 = peg$c0;
3640 | }
3641 | } else {
3642 | peg$currPos = s0;
3643 | s0 = peg$c0;
3644 | }
3645 | } else {
3646 | peg$currPos = s0;
3647 | s0 = peg$c0;
3648 | }
3649 |
3650 | return s0;
3651 | }
3652 |
3653 | function peg$parse_() {
3654 | var s0, s1;
3655 |
3656 | s0 = [];
3657 | s1 = peg$parseWhiteSpace();
3658 | if (s1 === peg$FAILED) {
3659 | s1 = peg$parseMultiLineCommentNoLineTerminator();
3660 | if (s1 === peg$FAILED) {
3661 | s1 = peg$parseSingleLineComment();
3662 | }
3663 | }
3664 | while (s1 !== peg$FAILED) {
3665 | s0.push(s1);
3666 | s1 = peg$parseWhiteSpace();
3667 | if (s1 === peg$FAILED) {
3668 | s1 = peg$parseMultiLineCommentNoLineTerminator();
3669 | if (s1 === peg$FAILED) {
3670 | s1 = peg$parseSingleLineComment();
3671 | }
3672 | }
3673 | }
3674 |
3675 | return s0;
3676 | }
3677 |
3678 | function peg$parse__() {
3679 | var s0, s1;
3680 |
3681 | s0 = [];
3682 | s1 = peg$parseWhiteSpace();
3683 | if (s1 === peg$FAILED) {
3684 | s1 = peg$parseLineTerminatorSequence();
3685 | if (s1 === peg$FAILED) {
3686 | s1 = peg$parseComment();
3687 | }
3688 | }
3689 | while (s1 !== peg$FAILED) {
3690 | s0.push(s1);
3691 | s1 = peg$parseWhiteSpace();
3692 | if (s1 === peg$FAILED) {
3693 | s1 = peg$parseLineTerminatorSequence();
3694 | if (s1 === peg$FAILED) {
3695 | s1 = peg$parseComment();
3696 | }
3697 | }
3698 | }
3699 |
3700 | return s0;
3701 | }
3702 |
3703 |
3704 | var p, parser, cs, leftVarNames, superLeftVarNames, rightVarNames, superRightVarNames, standardGapNames, getSuperViewName, getGapString, sizeVarNames;
3705 |
3706 | p = parser = this;
3707 |
3708 | p.trickleDownOptions = ["name"];
3709 | sizeVarNames = p.sizeVarNames = ["width", "height"];
3710 | leftVarNames = p.leftVarNames = ["right", "bottom"];
3711 | superLeftVarNames = p.superLeftVarNames = ["left", "top"];
3712 | rightVarNames = p.rightVarNames = ["left", "top"];
3713 | superRightVarNames = p.superRightVarNames = ["right", "bottom"];
3714 |
3715 | cs = p.cs = [];
3716 |
3717 | p.addC = function (c) {
3718 | cs.push(c);
3719 | };
3720 |
3721 |
3722 | p.selectors = [];
3723 | p.addSelector = function (sel) {
3724 | if (p.selectors.indexOf(sel) === -1) {
3725 | p.selectors.push(sel);
3726 | }
3727 | }
3728 |
3729 | p.addSplatIfNeeded = function (v, d, o) { // viewObj, dimension, options
3730 | var statement, op, gap;
3731 | if (v.connection) {
3732 | op = v.connection.op;
3733 | gap = v.connection.gap;
3734 | }
3735 | else {
3736 | op = "==";
3737 | gap = 0;
3738 | }
3739 | if (v.isSplat) {
3740 | statement = v.view + " { " +
3741 | "&[" + leftVarNames[d] + "] ";
3742 | statement += p.getConnectionString(v.connection, d, o, false) + " ";
3743 | statement += "&:next[" + rightVarNames[d] + "];" +
3744 | " }";
3745 |
3746 | p.addC(statement);
3747 | }
3748 | }
3749 | p.addPreds = function (view,preds,d) {
3750 | var pred, ccss, eq, exps, exp;
3751 | if (preds) {
3752 | for (var i = 0; i < preds.length; i++) {
3753 | pred = preds[i];
3754 | eq = pred[0];
3755 | ccss = view + "[" + sizeVarNames[d] + "] " + eq + " ";
3756 | exps = pred[1];
3757 | for (var j = 0; j < exps.length; j++) {
3758 | exp = exps[j];
3759 | if (exp[0] === "view") {
3760 | exp = exp[1] + "[" + sizeVarNames[d] + "]";
3761 | }
3762 | ccss += exp + " ";
3763 | }
3764 | if (pred[2]) {
3765 | ccss += pred[2];
3766 | } // strength & weight
3767 | cs.push(ccss.trim());
3768 | }
3769 | }
3770 | };
3771 |
3772 | p.defaultChainObject = {
3773 | headEq: "==",
3774 | value: "",
3775 | tailEq: "",
3776 | s: ""
3777 | };
3778 |
3779 | p.chainTailEqMap = {
3780 | "<=": ">=",
3781 | ">=": "<=",
3782 | "==": "==",
3783 | "<" : ">",
3784 | ">" : "<"
3785 | };
3786 |
3787 | p.addChains = function (views,o) {
3788 | var chains, chain, prop, preds, connector, ccss, view, pred;
3789 | chains = o.chains;
3790 | if (chains) {
3791 | for (var i = 0; i < chains.length; i++) {
3792 | chain = chains[i];
3793 | prop = chain[0];
3794 | preds = chain[1];
3795 | if (preds === "" || !preds) {
3796 | // load default chain predicate
3797 | preds = [p.defaultChainObject];
3798 | }
3799 | for (var j = 0; j < preds.length; j++) {
3800 | pred = preds[j];
3801 | ccss = "";
3802 | for (var k = 0; k < views.length - 1; k++) {
3803 | view = views[k];
3804 | if (pred.headEq === "") {
3805 | pred.headEq = p.defaultChainObject.headEq;
3806 | }
3807 | ccss += " " + view + "[" + prop + "] " + pred.headEq;
3808 | if (pred.value !== "") {
3809 | ccss += " " + pred.value;
3810 | if (views.length > 1) {
3811 | if (pred.tailEq === "") {
3812 | pred.tailEq = p.chainTailEqMap[pred.headEq];
3813 | }
3814 | ccss += " " + pred.tailEq;
3815 | }
3816 | else {
3817 | ccss += " " + pred.s;
3818 | cs.push(ccss.trim());
3819 | }
3820 | }
3821 | }
3822 | if (views.length > 1) {
3823 | ccss += " " + views[views.length-1] + "[" + prop + "]";
3824 | ccss += p.getTrailingOptions(o);
3825 | ccss += " " + pred.s;
3826 | cs.push(ccss.trim());
3827 | }
3828 | }
3829 | }
3830 | }
3831 | };
3832 |
3833 | getSuperViewName = function (o) {
3834 | if (o.in === undefined) {
3835 | return "::this";
3836 | }
3837 | return o.in;
3838 | };
3839 |
3840 | p.getLeftVar = function (view, dimension, o, viewObj) {
3841 | var varName;
3842 | if (viewObj.isPoint) {
3843 | return viewObj.pos;
3844 | }
3845 | else if (view === "|") {
3846 | view = getSuperViewName(o);
3847 | varName = superLeftVarNames[dimension];
3848 | }
3849 | else {
3850 | if (viewObj.isSplat) {
3851 | view += ":last";
3852 | if (view[0] === "(") {
3853 | view = "(" + view + ")";
3854 | }
3855 | }
3856 | varName = leftVarNames[dimension];
3857 | }
3858 | return view + "[" + varName + "]";
3859 | };
3860 |
3861 | p.getRightVar = function (view, dimension, o, viewObj) {
3862 | var varName;
3863 | if (viewObj.isPoint) {
3864 | return viewObj.pos;
3865 | }
3866 | else if (view === "|") {
3867 | view = getSuperViewName(o);
3868 | varName = superRightVarNames[dimension];
3869 | }
3870 | else {
3871 | if (viewObj.isSplat) {
3872 | view += ":first";
3873 | if (view[0] === "(") {
3874 | view = "(" + view + ")";
3875 | }
3876 | }
3877 | varName = rightVarNames[dimension];
3878 | }
3879 | return view + "[" + varName + "]";
3880 | };
3881 |
3882 | standardGapNames = ["[hgap]", "[vgap]"];
3883 |
3884 | getGapString = function (g,d,o,withContainer) {
3885 | if (g === undefined) {return "";}
3886 | if (g === "__STANDARD__") {
3887 | // use gap if given with `gap()` or `outer-gap`
3888 | if (withContainer && o['outer-gap']) {
3889 | g = o['outer-gap'];
3890 | } else if (o.gap) {
3891 | g = o.gap;
3892 | // else use standard var
3893 | } else {
3894 | g = standardGapNames[d];
3895 | }
3896 | }
3897 | return "+ " + g;
3898 | };
3899 |
3900 | p.getConnectionString = function (c, d, o, withContainer) {
3901 |
3902 | return (getGapString(c.gap,d,o,withContainer) + " " + c.op).trim();
3903 | };
3904 |
3905 | p.getTrailingOptions = function (o) {
3906 | var string = "";
3907 | if (o) {
3908 | p.trickleDownOptions.forEach(function(key){
3909 | if (o[key] != null) {
3910 | string = string + " " + key + "(" + o[key] + ")";
3911 | }
3912 | });
3913 | }
3914 | return string;
3915 | };
3916 |
3917 | p.getSW = function (o) {
3918 | if (o.sw) {
3919 | return " " + o.sw.trim();
3920 | }
3921 | return "";
3922 | };
3923 |
3924 |
3925 | p.getResults = function () {
3926 | return { statements:this.cs, selectors:p.selectors};
3927 | };
3928 |
3929 | p.flatten = function (array, isShallow) {
3930 |
3931 | if (typeof array === "string") {return array;}
3932 |
3933 | var index = -1,
3934 | length = array ? array.length : 0,
3935 | result = [];
3936 |
3937 | while (++index < length) {
3938 | var value = array[index];
3939 |
3940 | if (value instanceof Array) {
3941 | Array.prototype.push.apply(result, isShallow ? value : p.flatten(value));
3942 | }
3943 | else {
3944 | result.push(value);
3945 | }
3946 | }
3947 | return result;
3948 | }
3949 |
3950 | p.trim = function (x) {
3951 | if (typeof x === "string") {return x.trim();}
3952 | if (x instanceof Array) {return x.join("").trim();}
3953 | return ""
3954 | };
3955 |
3956 | p.join = function (a) {
3957 | if (!a) {return "";}
3958 | if (a.join){return a.join("");}
3959 | return a;
3960 | };
3961 |
3962 | p.stringify = function (array) {
3963 | if (!array) {return "";}
3964 | return p.trim(p.join(p.flatten(array)));
3965 | };
3966 |
3967 |
3968 |
3969 | peg$result = peg$startRuleFunction();
3970 |
3971 | if (peg$result !== peg$FAILED && peg$currPos === input.length) {
3972 | return peg$result;
3973 | } else {
3974 | if (peg$result !== peg$FAILED && peg$currPos < input.length) {
3975 | peg$fail({ type: "end", description: "end of input" });
3976 | }
3977 |
3978 | throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos);
3979 | }
3980 | }
3981 |
3982 | return {
3983 | SyntaxError: SyntaxError,
3984 | parse: parse
3985 | };
3986 | })();
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vfl-compiler",
3 | "description": "Visual Format Language compiler",
4 | "version": "1.1.3",
5 | "repository": {
6 | "type": "git",
7 | "url": "git://github.com/gss/vfl-compiler.git"
8 | },
9 | "licenses": [
10 | {
11 | "type": "MIT",
12 | "url": "https://github.com/gss/vfl-compiler/blob/master/LICENSE-MIT"
13 | }
14 | ],
15 | "dependencies": {
16 | "error-reporter": "~0.1.0"
17 | },
18 | "devDependencies": {
19 | "grunt": "~0.4.1",
20 | "grunt-cafe-mocha": "~0.1.2",
21 | "chai": "~1.8.0",
22 | "mocha": "~1.9.0",
23 | "grunt-contrib-watch": "~0.3.1",
24 | "grunt-peg": "~1.3.1",
25 | "grunt-component-build": "~0.5.0",
26 | "grunt-mocha-phantomjs": "~0.2.8",
27 | "grunt-contrib-uglify": "~0.2.1",
28 | "grunt-contrib-coffee": "~0.7.0",
29 | "grunt-cli": "~0.1.13"
30 | },
31 | "keywords": [],
32 | "scripts": {
33 | "test": "node_modules/.bin/grunt test"
34 | },
35 | "main": "./lib/compiler"
36 | }
37 |
--------------------------------------------------------------------------------
/spec/compiler.coffee:
--------------------------------------------------------------------------------
1 | if window?
2 | parser = require 'vfl-compiler'
3 | else
4 | chai = require 'chai' unless chai
5 | parser = require '../lib/compiler'
6 |
7 | {expect} = chai
8 |
9 |
10 | parse = (sources, expectation, pending) ->
11 | itFn = if pending then xit else it
12 |
13 |
14 | if !(sources instanceof Array)
15 | sources = [sources]
16 | for source in sources
17 |
18 | describe source, ->
19 | result = null
20 |
21 | itFn 'should do something', ->
22 | result = parser.parse source
23 | expect(result.statements).to.be.an 'array'
24 | expect(result.selectors).to.be.an 'array'
25 | itFn 'should match expected', ->
26 | if expectation instanceof Array
27 | expect(result.statements).to.eql expectation
28 | else
29 | expect(result).to.eql expectation
30 |
31 |
32 | # Helper function for expecting errors to be thrown when parsing.
33 | #
34 | # @param source [String] VFL statements.
35 | # @param message [String] This should be provided when a rule exists to catch
36 | # invalid syntax, and omitted when an error is expected to be thrown by the PEG
37 | # parser.
38 | # @param pending [Boolean] Whether the spec should be treated as pending.
39 | #
40 | expectError = (source, message, pending) ->
41 | itFn = if pending then xit else it
42 |
43 | describe source, ->
44 | predicate = 'should throw an error'
45 | predicate = "#{predicate} with message: #{message}" if message?
46 |
47 | itFn predicate, ->
48 | exercise = -> parser.parse source
49 | expect(exercise).to.throw Error, message
50 |
51 |
52 | describe 'VFL-to-CCSS Compiler', ->
53 |
54 | it 'should provide a parse method', ->
55 | expect(parser.parse).to.be.a 'function'
56 |
57 | # Basics
58 | # --------------------------------------------------
59 |
60 | describe '/* Basics */', ->
61 |
62 | parse """
63 | @horizontal (#b1)(#b2); // simple connection
64 | """
65 | ,
66 | [
67 | "#b1[right] == #b2[left]"
68 | ]
69 |
70 | parse """
71 | @h (#b1)(#b2); // shorthand
72 | """
73 | ,
74 | [
75 | "#b1[right] == #b2[left]"
76 | ]
77 |
78 | parse """
79 | @vertical (#b1)(#b2); // shorthand
80 | """
81 | ,
82 | [
83 | "#b1[bottom] == #b2[top]"
84 | ]
85 |
86 | parse """
87 | @v (#b1)-(#b2) - (#b3)- (#b4) -(#b5); // implicit standard gaps
88 | """
89 | ,
90 | [
91 | "#b1[bottom] + [vgap] == #b2[top]"
92 | "#b2[bottom] + [vgap] == #b3[top]"
93 | "#b3[bottom] + [vgap] == #b4[top]"
94 | "#b4[bottom] + [vgap] == #b5[top]"
95 | ]
96 |
97 | parse [
98 | """
99 | @v (#b1)-(#b2)-(#b3)-(#b4)-(#b5) gap(20); // explicit standard gaps
100 | """,
101 | """
102 | @v (#b1)
103 | -
104 | (#b2)
105 | -20-
106 | (#b3)
107 | -20-
108 | (#b4)
109 | -
110 | (#b5)
111 |
112 | gap(20);
113 | """
114 | ]
115 | ,
116 | [
117 | "#b1[bottom] + 20 == #b2[top]"
118 | "#b2[bottom] + 20 == #b3[top]"
119 | "#b3[bottom] + 20 == #b4[top]"
120 | "#b4[bottom] + 20 == #b5[top]"
121 | ]
122 |
123 | parse [
124 | "@h (#b1)-100-(#b2)-8-(#b3); // explicit gaps",
125 | "@h (#b1) - 100 - (#b2) - 8 - (#b3); // explicit gaps"
126 | ],
127 |
128 | [
129 | "#b1[right] + 100 == #b2[left]"
130 | "#b2[right] + 8 == #b3[left]"
131 | ]
132 |
133 | parse """
134 | @h (#b1)-[my-gap]-(#b2)-[my-other-gap]-(#b3); // explicit var gaps
135 | """
136 | ,
137 | [
138 | "#b1[right] + [my-gap] == #b2[left]"
139 | "#b2[right] + [my-other-gap] == #b3[left]"
140 | ]
141 |
142 | parse """
143 | @v (#b1)
144 | -#box1.class1[width]-
145 | (#b2)
146 | -"virtual"[-my-custom-prop]-
147 | (#b3); // explicit view var gaps
148 | """
149 | ,
150 | [
151 | "#b1[bottom] + #box1.class1[width] == #b2[top]"
152 | """#b2[bottom] + "virtual"[-my-custom-prop] == #b3[top]"""
153 | ]
154 |
155 | parse """
156 | @h (#b1)(#b2)-(#b3)-100-(#b4) gap(20); // mix gaps
157 | """
158 | ,
159 | [
160 | "#b1[right] == #b2[left]"
161 | "#b2[right] + 20 == #b3[left]"
162 | "#b3[right] + 100 == #b4[left]"
163 | ]
164 |
165 | parse """
166 | @h (#b1)-100-(#b2)-(#b3)-(#b4) gap([col-width]); // variable standard gap
167 | """
168 | ,
169 | [
170 | "#b1[right] + 100 == #b2[left]"
171 | "#b2[right] + [col-width] == #b3[left]"
172 | "#b3[right] + [col-width] == #b4[left]"
173 | ]
174 |
175 | parse """
176 | @h (#b1)-100-(#b2)-(#b3)-(#b4) gap(#box1[width]); // view variable standard gap
177 | """
178 | ,
179 | [
180 | "#b1[right] + 100 == #b2[left]"
181 | "#b2[right] + #box1[width] == #b3[left]"
182 | "#b3[right] + #box1[width] == #b4[left]"
183 | ]
184 |
185 | parse """
186 | @v ("Zone")-("1")-("a")-("q-1")-("_fallout"); // virtuals
187 | """
188 | ,
189 | [
190 | '"Zone"[bottom] + [vgap] == "1"[top]'
191 | '"1"[bottom] + [vgap] == "a"[top]'
192 | '"a"[bottom] + [vgap] == "q-1"[top]'
193 | '"q-1"[bottom] + [vgap] == "_fallout"[top]'
194 | ]
195 |
196 | expectError '@h (#b1(#b2);'
197 |
198 |
199 | # Variable scope
200 | # --------------------------------------------------
201 |
202 | # Global
203 |
204 | parse """
205 | @h (#b1)-$[md]-(#b2)
206 | """
207 | ,
208 | [
209 | "#b1[right] + $[md] == #b2[left]"
210 | ]
211 |
212 | parse """
213 | @h (#b1)-$md-(#b2)
214 | """
215 | ,
216 | [
217 | "#b1[right] + $md == #b2[left]"
218 | ]
219 |
220 | expectError '@h (#b1)-$$md-(#b2)'
221 |
222 |
223 | # Parent
224 |
225 | parse """
226 | @h (#b1)-^[md]-(#b2)
227 | """
228 | ,
229 | [
230 | "#b1[right] + ^[md] == #b2[left]"
231 | ]
232 |
233 | parse """
234 | @h (#b1)-^md-(#b2)
235 | """
236 | ,
237 | [
238 | "#b1[right] + ^md == #b2[left]"
239 | ]
240 |
241 | parse """
242 | @h (#b1)-^^md-(#b2)
243 | """
244 | ,
245 | [
246 | "#b1[right] + ^^md == #b2[left]"
247 | ]
248 |
249 |
250 | # Local
251 |
252 | parse """
253 | @h (#b1)-&[md]-(#b2)
254 | """
255 | ,
256 | [
257 | "#b1[right] + &[md] == #b2[left]"
258 | ]
259 |
260 | parse """
261 | @h (#b1)-&md-(#b2)
262 | """
263 | ,
264 | [
265 | "#b1[right] + &md == #b2[left]"
266 | ]
267 |
268 | expectError '@h (#b1)-&&md-(#b2)'
269 |
270 |
271 |
272 |
273 |
274 |
275 | # Element Containment
276 | # --------------------------------------------------
277 |
278 | describe '/* Element Containment */', ->
279 |
280 | parse """
281 | @v |(#sub)| in(#parent); // flush with super view
282 | """
283 | ,
284 | [
285 | '#parent[top] == #sub[top]'
286 | '#sub[bottom] == #parent[bottom]'
287 | ]
288 |
289 | parse """
290 | @v |("sub")| in("parent"); // virtuals
291 | """
292 | ,
293 | [
294 | '"parent"[top] == "sub"[top]'
295 | '"sub"[bottom] == "parent"[bottom]'
296 | ]
297 |
298 |
299 | parse """
300 | @v |(#sub)|; // super view defaults to ::this
301 | """
302 | ,
303 | [
304 | '::this[top] == #sub[top]'
305 | '#sub[bottom] == ::this[bottom]'
306 | ]
307 |
308 | parse """
309 | @h |-(#sub1)-(#sub2)-| in(#parent); // super view with standard gaps
310 | """
311 | ,
312 | [
313 | '#parent[left] + [hgap] == #sub1[left]'
314 | '#sub1[right] + [hgap] == #sub2[left]'
315 | '#sub2[right] + [hgap] == #parent[right]'
316 | ]
317 |
318 | parse """
319 | @h |-1-(#sub)-2-| in(#parent); // super view with explicit gaps
320 | """
321 | ,
322 | [
323 | '#parent[left] + 1 == #sub[left]'
324 | '#sub[right] + 2 == #parent[right]'
325 | ]
326 |
327 | parse """
328 | @v |
329 | -
330 | (#sub)
331 | -
332 | |
333 | in(#parent) gap(100); // super view with explicit standard gaps
334 | """
335 | ,
336 | [
337 | '#parent[top] + 100 == #sub[top]'
338 | '#sub[bottom] + 100 == #parent[bottom]'
339 | ]
340 |
341 | parse """
342 | @h |-(#sub1)-(#sub2)-| in(#parent) outer-gap(10); // outer-gap
343 | """
344 | ,
345 | [
346 | '#parent[left] + 10 == #sub1[left]'
347 | '#sub1[right] + [hgap] == #sub2[left]'
348 | '#sub2[right] + 10 == #parent[right]'
349 | ]
350 |
351 | parse """
352 | @h |-(#sub1)-(#sub2)-| in(#parent) gap(8) outer-gap([baseline]); // outer-gap
353 | """
354 | ,
355 | [
356 | '#parent[left] + [baseline] == #sub1[left]'
357 | '#sub1[right] + 8 == #sub2[left]'
358 | '#sub2[right] + [baseline] == #parent[right]'
359 | ]
360 |
361 | expectError '@h |-(#box]-;'
362 |
363 |
364 |
365 |
366 |
367 |
368 | # Points
369 | # --------------------------------------------------
370 |
371 | describe '/* Points */', ->
372 |
373 | parse """
374 | @v <100>(#sub)<300>; // point containment
375 | """
376 | ,
377 | [
378 | '100 == #sub[top]'
379 | '#sub[bottom] == 300'
380 | ]
381 |
382 | parse """
383 | @h < "col1"[center-x] + 20 >-(#box1)-< ::window[center-x] >; // point containment
384 | """
385 | ,
386 | [
387 | '"col1"[center-x] + 20 + [hgap] == #box1[left]'
388 | '#box1[right] + [hgap] == ::window[center-x]'
389 | ]
390 |
391 | parse """
392 | @h < [line] >-(#box1)-(#box2); // point containment
393 | """
394 | ,
395 | [
396 | '[line] + [hgap] == #box1[left]'
397 | '#box1[right] + [hgap] == #box2[left]'
398 | ]
399 |
400 | parse """
401 | @h (#btn1)-<::window[center-x]>-(#btn2) gap(8); // point in alignment
402 | """
403 | ,
404 | [
405 | '#btn1[right] + 8 == ::window[center-x]'
406 | '::window[center-x] + 8 == #btn2[left]'
407 | ]
408 |
409 | parse """
410 | @h (#btn1)-<::window[center-x]>-(#btn2) gap(8) chain-top chain-width(==); // chains ignore points
411 | """
412 | ,
413 | [
414 | '#btn1[right] + 8 == ::window[center-x]'
415 | '::window[center-x] + 8 == #btn2[left]'
416 | '#btn1[top] == #btn2[top]'
417 | '#btn1[width] == #btn2[width]'
418 | ]
419 |
420 | parse """
421 | @h (#btn1)-<"col3"[left]>
422 | <"col4"[right]>-(#btn2)
423 | gap(8);
424 | // consecutive points are not equalized
425 | """
426 | ,
427 | [
428 | '#btn1[right] + 8 == "col3"[left]'
429 | '"col4"[right] + 8 == #btn2[left]'
430 | ]
431 |
432 |
433 |
434 |
435 | parse """
436 | @h (#btn1)-<&[-other-place]>
437 | < &[center-x] >-(#btn2)
438 | gap(&[gap]);
439 | // this scoped
440 | """
441 | ,
442 | [
443 | '#btn1[right] + &[gap] == &[-other-place]'
444 | '&[center-x] + &[gap] == #btn2[left]'
445 | ]
446 |
447 | parse """
448 | @h (#btn1)-< (.box .foo:bar:next .black)[center-x] >
449 | < (.box ! .foo:bar:next .black)[left] >-(#btn2)
450 | gap(&[gap]);
451 | // complex selectors
452 | """
453 | ,
454 | [
455 | '#btn1[right] + &[gap] == (.box .foo:bar:next .black)[center-x]'
456 | '(.box ! .foo:bar:next .black)[left] + &[gap] == #btn2[left]'
457 | ]
458 |
459 | parse """
460 | @h | - (#btn1) - <&[right]>
461 | < &[right] > - (#btn2) - |
462 | gap(&[gap])
463 | outer-gap(&[outer-gap])
464 | in(&);
465 | // this scoped
466 | """
467 | ,
468 | [
469 | '&[left] + &[outer-gap] == #btn1[left]'
470 | '#btn1[right] + &[gap] == &[right]'
471 | '&[right] + &[gap] == #btn2[left]'
472 | '#btn2[right] + &[outer-gap] == &[right]'
473 | ]
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 | # Cushions
484 | # --------------------------------------------------
485 |
486 | describe '/* Cushions */', ->
487 |
488 | parse """
489 | @h (#b1)~(#b2); // simple cushion
490 | """
491 | ,
492 | [
493 | "#b1[right] <= #b2[left]"
494 | ]
495 |
496 | parse """
497 | @h (#b1)~-~(#b2)~100~(#b3); // cushions w/ gaps
498 | """
499 | ,
500 | [
501 | "#b1[right] + [hgap] <= #b2[left]"
502 | "#b2[right] + 100 <= #b3[left]"
503 | ]
504 |
505 | parse """
506 | @h |~(#sub)~2~| in(#parent); // super view with cushions
507 | """
508 | ,
509 | [
510 | '#parent[left] <= #sub[left]'
511 | '#sub[right] + 2 <= #parent[right]'
512 | ]
513 |
514 |
515 | # Predicates
516 | # --------------------------------------------------
517 |
518 | describe '/* Predicates */', ->
519 |
520 | parse """
521 | @v (#sub(==100)); // single predicate
522 | """
523 | ,
524 | [
525 | '#sub[height] == 100'
526 | ]
527 |
528 | parse """
529 | @v (#box(<=100!required,>=30!strong100)); // multiple predicates w/ strength & weight
530 | """
531 | ,
532 | [
533 | '#box[height] <= 100 !required'
534 | '#box[height] >= 30 !strong100'
535 | ]
536 |
537 | parse """
538 | @h (#b1(<=100))(#b2(==#b1)); // connected predicates
539 | """
540 | ,
541 | [
542 | '#b1[width] <= 100'
543 | '#b2[width] == #b1[width]'
544 | '#b1[right] == #b2[left]'
545 | ]
546 |
547 | parse """
548 | @h ("b1"(<=100)) ("b2"(=="b1")); // virtuals
549 | """
550 | ,
551 | [
552 | '"b1"[width] <= 100'
553 | '"b2"[width] == "b1"[width]'
554 | '"b1"[right] == "b2"[left]'
555 | ]
556 |
557 | parse """
558 | @h (#b1( <=100 , ==#b99 !99 ))(#b2(>= #b1 *2 !weak10, <=3!required))-100-(.b3(==200)) !medium200; // multiple, connected predicates w/ strength & weight
559 | """
560 | ,
561 | [
562 | '#b1[width] <= 100'
563 | '#b1[width] == #b99[width] !99'
564 | '#b2[width] >= #b1[width] * 2 !weak10'
565 | '#b2[width] <= 3 !required'
566 | '#b1[right] == #b2[left] !medium200'
567 | '.b3[width] == 200'
568 | '#b2[right] + 100 == .b3[left] !medium200'
569 | ]
570 |
571 | parse """
572 | @h (#b1(==[colwidth])); // predicate with constraint variable
573 | """
574 | ,
575 | [
576 | '#b1[width] == [colwidth]'
577 | ]
578 |
579 | parse """
580 | @h (#b1(==#b2[height])); // predicate with explicit view variable
581 | """
582 | ,
583 | [
584 | '#b1[width] == #b2[height]'
585 | ]
586 |
587 |
588 | # Chains
589 | # --------------------------------------------------
590 |
591 | describe '/* Chains */', ->
592 |
593 | parse """
594 | @h (#b1)(#b2) chain-height chain-width(250); // basic equality chains
595 | """
596 | ,
597 | [
598 | '#b1[right] == #b2[left]'
599 | '#b1[height] == #b2[height]'
600 | '#b1[width] == 250 == #b2[width]'
601 | ]
602 |
603 | parse """
604 | @h (#b1)(#b2)(#b3) chain-width(==[colwidth]!strong,<=500!required); // mutliple chain predicates
605 | """
606 | ,
607 | [
608 | '#b1[right] == #b2[left]'
609 | '#b2[right] == #b3[left]'
610 | '#b1[width] == [colwidth] == #b2[width] == [colwidth] == #b3[width] !strong'
611 | '#b1[width] <= 500 >= #b2[width] <= 500 >= #b3[width] !required'
612 | ]
613 |
614 | parse """
615 | @v (#b1)(#b2)(#b3)(#b4) chain-width(==!weak10) chain-height(<=150>=!required) !medium; // explicit equality & inequality chains
616 | """
617 | ,
618 | [
619 | '#b1[bottom] == #b2[top] !medium'
620 | '#b2[bottom] == #b3[top] !medium'
621 | '#b3[bottom] == #b4[top] !medium'
622 | '#b1[width] == #b2[width] == #b3[width] == #b4[width] !weak10'
623 | '#b1[height] <= 150 >= #b2[height] <= 150 >= #b3[height] <= 150 >= #b4[height] !required'
624 | ]
625 |
626 | parse """
627 | @v (#b1(==100!strong)) chain-centerX chain-width( 50 !weak10); // single view w/ equality chains
628 | """
629 | ,
630 | [
631 | '#b1[height] == 100 !strong'
632 | ]
633 |
634 | parse """
635 | @v |-8-(#b1(==100!strong))(#b2)-8-| in(#panel) chain-centerX( #panel[centerX] !required) chain-width(>=50== 50 <= #b2[width] !weak10'
645 | ]
646 |
647 | parse """
648 | @v |-(#b1)-(#b2)-| in("panel") gap("zone"[col-size]) outer-gap("outer-zone"[row-size]) chain-centerX( "panel"[centerX] !required); // adv w/ virtuals
649 | """
650 | ,
651 | [
652 | '"panel"[top] + "outer-zone"[row-size] == #b1[top]'
653 | '#b1[bottom] + "zone"[col-size] == #b2[top]'
654 | '#b2[bottom] + "outer-zone"[row-size] == "panel"[bottom]'
655 | '#b1[centerX] == "panel"[centerX] == #b2[centerX] !required'
656 | ]
657 |
658 |
659 | # Names
660 | # --------------------------------------------------
661 |
662 | describe '/* Names */', ->
663 |
664 | parse """
665 | @h (#b1)-100-(#b2)-(#b3)-(#b4) gap(#box1[width]) name(button-layout) !strong; // view variable standard gap
666 | """
667 | ,
668 | [
669 | "#b1[right] + 100 == #b2[left] name(button-layout) !strong"
670 | "#b2[right] + #box1[width] == #b3[left] name(button-layout) !strong"
671 | "#b3[right] + #box1[width] == #b4[left] name(button-layout) !strong"
672 | ]
673 |
674 | parse """
675 | @h (#b1)-100-(#b2)-(#b3)-(#b4) gap(#box1[width]) !strong name(button-layout); // view variable standard gap
676 | """
677 | ,
678 | [
679 | "#b1[right] + 100 == #b2[left] name(button-layout) !strong"
680 | "#b2[right] + #box1[width] == #b3[left] name(button-layout) !strong"
681 | "#b3[right] + #box1[width] == #b4[left] name(button-layout) !strong"
682 | ]
683 |
684 | parse """
685 | @v (#b1)(#b2)(#b3)(#b4) chain-width(==) chain-height(<=150>=!required) name(bob) !medium; // explicit equality & inequality chains
686 | """
687 | ,
688 | [
689 | '#b1[bottom] == #b2[top] name(bob) !medium'
690 | '#b2[bottom] == #b3[top] name(bob) !medium'
691 | '#b3[bottom] == #b4[top] name(bob) !medium'
692 | '#b1[width] == #b2[width] == #b3[width] == #b4[width] name(bob)'
693 | '#b1[height] <= 150 >= #b2[height] <= 150 >= #b3[height] <= 150 >= #b4[height] name(bob) !required'
694 | ]
695 |
696 |
697 | # Splat
698 | # --------------------------------------------------
699 |
700 | describe '/* Splats */', ->
701 |
702 | # @h Just splats + gaps
703 | # -----------------------------
704 |
705 | parse """
706 | @h (.box)...;
707 | """
708 | ,
709 | {
710 | statements: [
711 | ".box { &[right] == &:next[left]; }"
712 | ]
713 | selectors: ['.box']
714 | }
715 |
716 | parse [
717 | """
718 | @h (.box)-10-...;
719 | """,
720 | """
721 | @h (.box)-... gap(10);
722 | """
723 | ]
724 | ,
725 | {
726 | statements: [
727 | ".box { &[right] + 10 == &:next[left]; }"
728 | ]
729 | selectors: ['.box']
730 | }
731 |
732 | parse [
733 | """
734 | @h (.box)-... gap("col-1"[width]);
735 | """,
736 | """
737 | @h (.box)-"col-1"[width]-...;
738 | """
739 | ]
740 | ,
741 | {
742 | statements: [
743 | """.box { &[right] + "col-1"[width] == &:next[left]; }"""
744 | ]
745 | selectors: ['.box']
746 | }
747 |
748 | # @v Just splats + cushions
749 | # -----------------------------
750 |
751 | parse """
752 | @v (.box)~...;
753 | """
754 | ,
755 | {
756 | statements: [
757 | ".box { &[bottom] <= &:next[top]; }"
758 | ]
759 | selectors: ['.box']
760 | }
761 |
762 | parse [
763 | """
764 | @v (.box)
765 | ~10~...;
766 | """,
767 | """
768 | @v (.box) ~-~ ... gap(10);
769 | """
770 | ]
771 | ,
772 | {
773 | statements: [
774 | ".box { &[bottom] + 10 <= &:next[top]; }"
775 | ]
776 | selectors: ['.box']
777 | }
778 |
779 | parse [
780 | """
781 | @v
782 | ( .box )
783 | ~-~
784 | ...
785 |
786 | gap("col-1"[width]);
787 | """,
788 | """
789 | @v
790 | ( .box )
791 | ~ "col-1"[width] ~
792 | ...;
793 | """
794 | ]
795 | ,
796 | {
797 | statements: [
798 | """.box { &[bottom] + "col-1"[width] <= &:next[top]; }"""
799 | ]
800 | selectors: ['.box']
801 | }
802 |
803 | # Splats + other layout items
804 | # -----------------------------
805 |
806 | parse """ // :first & :last injection w/ parans
807 | @h (& .nav) (& .box)... (& .aside)
808 | """
809 | ,
810 | {
811 | statements: [
812 | "(& .box) { &[right] == &:next[left]; }"
813 | "(& .nav)[right] == ((& .box):first)[left]"
814 | "((& .box):last)[right] == (& .aside)[left]"
815 | ]
816 | selectors: ['(& .nav)','(& .box)','(& .aside)']
817 | }
818 |
819 | parse """
820 | @h (#nav) (.box)... (#aside)
821 | """
822 | ,
823 | {
824 | statements: [
825 | ".box { &[right] == &:next[left]; }"
826 | "#nav[right] == .box:first[left]"
827 | ".box:last[right] == #aside[left]"
828 | ]
829 | selectors: ['#nav','.box','#aside']
830 | }
831 |
832 | parse """
833 | @h | ~ (.box:even)... -16- (.box:odd)... ~ | in(&)
834 | """
835 | ,
836 | {
837 | statements: [
838 | ".box:even { &[right] == &:next[left]; }"
839 | "&[left] <= .box:even:first[left]"
840 | ".box:odd { &[right] == &:next[left]; }"
841 | ".box:even:last[right] + 16 == .box:odd:first[left]"
842 | ".box:odd:last[right] <= &[right]"
843 | ]
844 | selectors: ['.box:even','.box:odd']
845 | }
846 |
847 | parse """
848 | @v |
849 | (.box)...
850 | |
851 | in(::window)
852 | """
853 | ,
854 | {
855 | statements: [
856 | ".box { &[bottom] == &:next[top]; }"
857 | "::window[top] == .box:first[top]"
858 | ".box:last[bottom] == ::window[bottom]"
859 | ]
860 | selectors: ['.box']
861 | }
862 |
863 | parse """
864 | @v |
865 | (#nav)
866 | ~20~
867 | (.box)
868 | -[post-gap]-
869 | ...
870 | ~20~
871 | (#footer)
872 | |
873 | in(::window)
874 | """
875 | ,
876 | {
877 | statements: [
878 | "::window[top] == #nav[top]"
879 | ".box { &[bottom] + [post-gap] == &:next[top]; }"
880 | "#nav[bottom] + 20 <= .box:first[top]"
881 | ".box:last[bottom] + 20 <= #footer[top]"
882 | "#footer[bottom] == ::window[bottom]"
883 | ]
884 | selectors: ['#nav','.box','#footer']
885 | }
886 |
887 |
888 |
889 |
890 |
891 |
892 | # Selectors
893 | # --------------------------------------------------
894 |
895 | describe '/* Selectors */', ->
896 |
897 | parse """
898 | @h | (button.selected:first) (button.selected:last) | in(header.test:boob)
899 | """
900 | ,
901 | {
902 | statements: [
903 | "header.test:boob[left] == button.selected:first[left]",
904 | "button.selected:first[right] == button.selected:last[left]",
905 | "button.selected:last[right] == header.test:boob[right]"
906 | ]
907 | selectors: ['button.selected:first', 'button.selected:last']
908 | }
909 |
910 | parse """
911 | @v | (&) | in(::window)
912 | """
913 | ,
914 | {
915 | statements: [
916 | "::window[top] == &[top]",
917 | "&[bottom] == ::window[bottom]"
918 | ]
919 | selectors: ['&']
920 | }
921 |
922 | parse """ // complex selectors
923 | @v (& "Zone")-(#box "1")-(.class"a")-(&.class"q-1")-(& > .class .class2"_fallout");
924 | """
925 | ,
926 | {
927 | statements: [
928 | '(& "Zone")[bottom] + [vgap] == (#box "1")[top]'
929 | '(#box "1")[bottom] + [vgap] == .class"a"[top]'
930 | '.class"a"[bottom] + [vgap] == &.class"q-1"[top]'
931 | '&.class"q-1"[bottom] + [vgap] == (& > .class .class2"_fallout")[top]'
932 | ]
933 | selectors: ['(& "Zone")', '(#box "1")', '.class"a"', '&.class"q-1"', '(& > .class .class2"_fallout")']
934 | }
935 |
936 | parse """
937 | @v | (&:next .featured article .title"zone") | in(& > .class .class2"_fallout")
938 | """
939 | ,
940 | {
941 | statements: [
942 | '(& > .class .class2"_fallout")[top] == (&:next .featured article .title"zone")[top]'
943 | '(&:next .featured article .title"zone")[bottom] == (& > .class .class2"_fallout")[bottom]'
944 | ]
945 | selectors: [
946 | '(&:next .featured article .title"zone")'
947 | ]
948 | }
949 |
950 | parse """ // comma seperated scoped zones
951 | @v |(&"zone2", &"zone1")| in(&)
952 | """
953 | ,
954 | {
955 | statements: [
956 | '&[top] == (&"zone2", &"zone1")[top]'
957 | '(&"zone2", &"zone1")[bottom] == &[bottom]'
958 | ]
959 | selectors: [
960 | '(&"zone2", &"zone1")'
961 | ]
962 | }
963 |
--------------------------------------------------------------------------------
/spec/runner.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | VFL compiler in browser
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/compiler.coffee:
--------------------------------------------------------------------------------
1 | if window?
2 | {parse} = require './parser'
3 | else
4 | {parse} = require '../lib/parser'
5 |
6 | ErrorReporter = require 'error-reporter'
7 |
8 |
9 | # A wrapper module for the parser generated by PEG.
10 | #
11 | # @note Provides a way to handle errors consistently regardless of if the error
12 | # originated from PEG or was thrown manually as part the parsing expression for
13 | # a rule.
14 | #
15 | module.exports =
16 |
17 | # Parse VFL to produce CCSS.
18 | #
19 | # @param source [String] A VFL expression.
20 | # @return [Array] The CCSS expressions equivalent to `source`.
21 | #
22 | parse: (source) ->
23 | results = null
24 |
25 | try
26 | results = parse source
27 | catch error
28 | errorReporter = new ErrorReporter source
29 | {message, line:lineNumber, column:columnNumber} = error
30 | errorReporter.reportError message, lineNumber, columnNumber
31 |
32 | return results
33 |
--------------------------------------------------------------------------------
/src/grammar.peg:
--------------------------------------------------------------------------------
1 | {
2 | var p, parser, cs, leftVarNames, superLeftVarNames, rightVarNames, superRightVarNames, standardGapNames, getSuperViewName, getGapString, sizeVarNames;
3 |
4 | p = parser = this;
5 |
6 | p.trickleDownOptions = ["name"];
7 | sizeVarNames = p.sizeVarNames = ["width", "height"];
8 | leftVarNames = p.leftVarNames = ["right", "bottom"];
9 | superLeftVarNames = p.superLeftVarNames = ["left", "top"];
10 | rightVarNames = p.rightVarNames = ["left", "top"];
11 | superRightVarNames = p.superRightVarNames = ["right", "bottom"];
12 |
13 | cs = p.cs = [];
14 |
15 | p.addC = function (c) {
16 | cs.push(c);
17 | };
18 |
19 |
20 | p.selectors = [];
21 | p.addSelector = function (sel) {
22 | if (p.selectors.indexOf(sel) === -1) {
23 | p.selectors.push(sel);
24 | }
25 | }
26 |
27 | p.addSplatIfNeeded = function (v, d, o) { // viewObj, dimension, options
28 | var statement, op, gap;
29 | if (v.connection) {
30 | op = v.connection.op;
31 | gap = v.connection.gap;
32 | }
33 | else {
34 | op = "==";
35 | gap = 0;
36 | }
37 | if (v.isSplat) {
38 | statement = v.view + " { " +
39 | "&[" + leftVarNames[d] + "] ";
40 | statement += p.getConnectionString(v.connection, d, o, false) + " ";
41 | statement += "&:next[" + rightVarNames[d] + "];" +
42 | " }";
43 |
44 | p.addC(statement);
45 | }
46 | }
47 | p.addPreds = function (view,preds,d) {
48 | var pred, ccss, eq, exps, exp;
49 | if (preds) {
50 | for (var i = 0; i < preds.length; i++) {
51 | pred = preds[i];
52 | eq = pred[0];
53 | ccss = view + "[" + sizeVarNames[d] + "] " + eq + " ";
54 | exps = pred[1];
55 | for (var j = 0; j < exps.length; j++) {
56 | exp = exps[j];
57 | if (exp[0] === "view") {
58 | exp = exp[1] + "[" + sizeVarNames[d] + "]";
59 | }
60 | ccss += exp + " ";
61 | }
62 | if (pred[2]) {
63 | ccss += pred[2];
64 | } // strength & weight
65 | cs.push(ccss.trim());
66 | }
67 | }
68 | };
69 |
70 | p.defaultChainObject = {
71 | headEq: "==",
72 | value: "",
73 | tailEq: "",
74 | s: ""
75 | };
76 |
77 | p.chainTailEqMap = {
78 | "<=": ">=",
79 | ">=": "<=",
80 | "==": "==",
81 | "<" : ">",
82 | ">" : "<"
83 | };
84 |
85 | p.addChains = function (views,o) {
86 | var chains, chain, prop, preds, connector, ccss, view, pred;
87 | chains = o.chains;
88 | if (chains) {
89 | for (var i = 0; i < chains.length; i++) {
90 | chain = chains[i];
91 | prop = chain[0];
92 | preds = chain[1];
93 | if (preds === "" || !preds) {
94 | // load default chain predicate
95 | preds = [p.defaultChainObject];
96 | }
97 | for (var j = 0; j < preds.length; j++) {
98 | pred = preds[j];
99 | ccss = "";
100 | for (var k = 0; k < views.length - 1; k++) {
101 | view = views[k];
102 | if (pred.headEq === "") {
103 | pred.headEq = p.defaultChainObject.headEq;
104 | }
105 | ccss += " " + view + "[" + prop + "] " + pred.headEq;
106 | if (pred.value !== "") {
107 | ccss += " " + pred.value;
108 | if (views.length > 1) {
109 | if (pred.tailEq === "") {
110 | pred.tailEq = p.chainTailEqMap[pred.headEq];
111 | }
112 | ccss += " " + pred.tailEq;
113 | }
114 | else {
115 | ccss += " " + pred.s;
116 | cs.push(ccss.trim());
117 | }
118 | }
119 | }
120 | if (views.length > 1) {
121 | ccss += " " + views[views.length-1] + "[" + prop + "]";
122 | ccss += p.getTrailingOptions(o);
123 | ccss += " " + pred.s;
124 | cs.push(ccss.trim());
125 | }
126 | }
127 | }
128 | }
129 | };
130 |
131 | getSuperViewName = function (o) {
132 | if (o.in === undefined) {
133 | return "::this";
134 | }
135 | return o.in;
136 | };
137 |
138 | p.getLeftVar = function (view, dimension, o, viewObj) {
139 | var varName;
140 | if (viewObj.isPoint) {
141 | return viewObj.pos;
142 | }
143 | else if (view === "|") {
144 | view = getSuperViewName(o);
145 | varName = superLeftVarNames[dimension];
146 | }
147 | else {
148 | if (viewObj.isSplat) {
149 | view += ":last";
150 | if (view[0] === "(") {
151 | view = "(" + view + ")";
152 | }
153 | }
154 | varName = leftVarNames[dimension];
155 | }
156 | return view + "[" + varName + "]";
157 | };
158 |
159 | p.getRightVar = function (view, dimension, o, viewObj) {
160 | var varName;
161 | if (viewObj.isPoint) {
162 | return viewObj.pos;
163 | }
164 | else if (view === "|") {
165 | view = getSuperViewName(o);
166 | varName = superRightVarNames[dimension];
167 | }
168 | else {
169 | if (viewObj.isSplat) {
170 | view += ":first";
171 | if (view[0] === "(") {
172 | view = "(" + view + ")";
173 | }
174 | }
175 | varName = rightVarNames[dimension];
176 | }
177 | return view + "[" + varName + "]";
178 | };
179 |
180 | standardGapNames = ["[hgap]", "[vgap]"];
181 |
182 | getGapString = function (g,d,o,withContainer) {
183 | if (g === undefined) {return "";}
184 | if (g === "__STANDARD__") {
185 | // use gap if given with `gap()` or `outer-gap`
186 | if (withContainer && o['outer-gap']) {
187 | g = o['outer-gap'];
188 | } else if (o.gap) {
189 | g = o.gap;
190 | // else use standard var
191 | } else {
192 | g = standardGapNames[d];
193 | }
194 | }
195 | return "+ " + g;
196 | };
197 |
198 | p.getConnectionString = function (c, d, o, withContainer) {
199 |
200 | return (getGapString(c.gap,d,o,withContainer) + " " + c.op).trim();
201 | };
202 |
203 | p.getTrailingOptions = function (o) {
204 | var string = "";
205 | if (o) {
206 | p.trickleDownOptions.forEach(function(key){
207 | if (o[key] != null) {
208 | string = string + " " + key + "(" + o[key] + ")";
209 | }
210 | });
211 | }
212 | return string;
213 | };
214 |
215 | p.getSW = function (o) {
216 | if (o.sw) {
217 | return " " + o.sw.trim();
218 | }
219 | return "";
220 | };
221 |
222 |
223 | p.getResults = function () {
224 | return { statements:this.cs, selectors:p.selectors};
225 | };
226 |
227 | p.flatten = function (array, isShallow) {
228 |
229 | if (typeof array === "string") {return array;}
230 |
231 | var index = -1,
232 | length = array ? array.length : 0,
233 | result = [];
234 |
235 | while (++index < length) {
236 | var value = array[index];
237 |
238 | if (value instanceof Array) {
239 | Array.prototype.push.apply(result, isShallow ? value : p.flatten(value));
240 | }
241 | else {
242 | result.push(value);
243 | }
244 | }
245 | return result;
246 | }
247 |
248 | p.trim = function (x) {
249 | if (typeof x === "string") {return x.trim();}
250 | if (x instanceof Array) {return x.join("").trim();}
251 | return ""
252 | };
253 |
254 | p.join = function (a) {
255 | if (!a) {return "";}
256 | if (a.join){return a.join("");}
257 | return a;
258 | };
259 |
260 | p.stringify = function (array) {
261 | if (!array) {return "";}
262 | return p.trim(p.join(p.flatten(array)));
263 | };
264 |
265 | }
266 |
267 | start
268 | = __ Statement* __ { return p.getResults(); }
269 |
270 | debug
271 | = __ vfl:Statement* __ { return p.getResults().concat(vfl); }
272 |
273 | Statement
274 | = exp:VFLStatement EOS __ { return exp; }
275 |
276 | VFLStatement
277 | = d:Dimension __ head:View
278 | tail:(__ Connection? __ View)* __ o:Options {
279 | var connection, result, ccss, chainedViews, withContainer,
280 | tailView, tailViewObj, headView, headViewObj;
281 | p.addSplatIfNeeded(head, d, o);
282 | result = head;
283 | headViewObj = head;
284 | headView = headViewObj.view;
285 | chainedViews = [];
286 | if (headView !== "|") {chainedViews.push(headView);}
287 | p.addPreds(headView,head.preds,d);
288 | for (var i = 0; i < tail.length; i++) {
289 | connection = tail[i][1];
290 | tailViewObj = tail[i][3];
291 | p.addSplatIfNeeded(tailViewObj, d, o);
292 | tailView = tailViewObj.view;
293 | if (tailView !== "|") {chainedViews.push(tailView);}
294 | p.addPreds(tailView,tail[i][3].preds,d);
295 | result = [
296 | //"c",
297 | connection,
298 | result,
299 | tailView
300 | ];
301 | if (!(headViewObj.isPoint && tailViewObj.isPoint)) {
302 | withContainer = ( headView =="|" || tailView === "|") && !(headViewObj.isPoint || tailViewObj.isPoint);
303 | ccss = p.getLeftVar(headView, d, o, headViewObj) + " "
304 | + p.getConnectionString(connection, d, o, withContainer) + " "
305 | + p.getRightVar(tailView, d, o, tailViewObj)
306 | + p.getTrailingOptions(o)
307 | + p.getSW(o);
308 | p.addC(
309 | ccss.trim()
310 | );}
311 | headViewObj = tailViewObj;
312 | headView = tailView;
313 | }
314 | p.addChains(chainedViews,o);
315 | return {'vfl':d, o:o};
316 | }
317 |
318 | Dimension
319 | = ("@horizontal" / "@-gss-horizontal" / "@-gss-h" / "@h") {return 0;}
320 | / ("@vertical" / "@-gss-vertical" / "@-gss-v" / "@v") {return 1;}
321 |
322 |
323 | Options
324 | = os:Option* {
325 | var obj = {};
326 | obj.chains = [];
327 | for (var i = 0; i < os.length; i++) {
328 | // proccess chains
329 | if (!!os[i].chain) {
330 | obj.chains.push(os[i].chain);
331 | }
332 | // or just add option
333 | else {
334 | obj[os[i].key] = os[i].value;
335 | }
336 | }
337 | return obj;
338 | }
339 |
340 | Option 'Option'
341 | = __ chain:Chain { return chain; }
342 | / __ "in" "(" simple:[^) ]+ ")"
343 | {
344 | return {key:"in", value:simple.join('')};
345 | }
346 | / __ "in" "(" complex:[^)]+ ")"
347 | {
348 | return {key:"in", value:"(" + complex.join('') + ")"};
349 | }
350 | / __ key:NameChars+ "(" value:OpionValueChars+ ")"
351 | {
352 | return {key:key.join(''), value:value.join('')};
353 | }
354 | / __ sw:StrengthAndWeight {return {key:"sw",value:sw}; }
355 |
356 | OpionValueChars
357 | = [^>===]+ _? ">" {
428 | return p.stringify(position);
429 | }
430 |
431 | Predicate 'Predicate'
432 | = "(" preds:(PredEq PredExpression StrengthAndWeight? _? PredSeperator _?)+ ")" {return preds;}
433 |
434 | PredExpression "Predicate Expression"
435 | = (PredOp / PredLiteral / PredVariable / PredViewVariable / PredView )+
436 |
437 | PredEq
438 | = _? eq:("==" / "<=" / "<" / ">=" / ">" / "=<"{return "<=";} / "=>"{return ">=";}) _? {return eq;}
439 |
440 | PredOp
441 | = op:[+\-/*] _? {return op;}
442 |
443 | PredView
444 | = name:NameChars+ _? {return ["view",name.join("")];}
445 |
446 | PredLiteral
447 | = n:Number+ _? {return n.join("");}
448 |
449 | PredVariable
450 | = "[" name:NameChars+ "]" _? {return "[" + name.join("") + "]";}
451 |
452 | PredViewVariable
453 | = view:NameChars+ "[" prop:NameChars+ "]" _? {return view.join("") + "[" + prop.join("") + "]";}
454 |
455 | PredSeperator
456 | = ","? {return "";}
457 |
458 | Connection "VFL Connection"
459 | = "-" _ gap:ExplicitGap _ "-" {return {op:"==",gap:gap};}
460 | / "-" {return {op:"==",gap:"__STANDARD__"};}
461 | / "~" _ gap:ExplicitGap _ "~" {return {op:"<=",gap:gap};}
462 | / "~" "-" "~" {return {op:"<=",gap:"__STANDARD__"};}
463 | / "~" {return {op:"<="};}
464 | / "" {return {op:"=="};}
465 |
466 | Scope
467 | = local:"&"+ {
468 | if (local.length > 1) {
469 | throw new SyntaxError('Invalid local variable scope', null, null, null, line(), column());
470 | }
471 | return local.join("");
472 | }
473 | / parent:"^"+ {return parent.join("");}
474 | / global:"$"+ {
475 | if (global.length > 1) {
476 | throw new SyntaxError('Invalid global variable scope', null, null, null, line(), column());
477 | }
478 | return global.join("");
479 | }
480 |
481 | ExplicitGap "VFL Connection Gap"
482 | = scope:Scope gap:[a-zA-Z0-9_]+ {return scope + gap.join("");}
483 | / gap:[a-zA-Z0-9_]+ {return gap.join("");}
484 | / gap:[^\[]* "[" varr:[^\]]+ "]" {return gap.join("") + "[" + varr.join("") + "]";}
485 |
486 |
487 | StrengthAndWeight "Strength / Weight"
488 | = "!" s:([a-zA-Z]+)? w:([0-9]+)? {
489 | var val;
490 | val = "!" + p.join(s) + p.join(w);
491 | return val.trim();
492 | }
493 | / "!" .? {
494 | throw new SyntaxError('Invalid Strength or Weight', null, null, null, line(), column());
495 | }
496 |
497 | NameChars
498 | = [a-zA-Z0-9#.\-_$:""&]
499 |
500 | NameCharsWithSpace
501 | = NameChars / " "
502 |
503 | Literal
504 | = val:Number {
505 | return [ "number",
506 | val
507 | ];
508 | }
509 |
510 | Number
511 | = Real / Integer
512 |
513 | Integer
514 | = digits:[0-9]+ {
515 | return parseInt(digits.join(""), 10);
516 | }
517 |
518 | Real
519 | = digits:(Integer "." Integer) {
520 | return parseFloat(digits.join(""));
521 | }
522 |
523 | SignedInteger
524 | = [-+]? [0-9]+
525 |
526 | SourceCharacter
527 | = .
528 |
529 | WhiteSpace "whitespace"
530 | = [\t\v\f \u00A0\uFEFF]
531 |
532 | LineTerminator
533 | = [\n\r\u2028\u2029]
534 |
535 | LineTerminatorSequence "end of line"
536 | = "\n"
537 | / "\r\n"
538 | / "\r"
539 | / "\u2028" // line separator
540 | / "\u2029" // paragraph separator
541 |
542 | EOS
543 | = __ ";"
544 | / _ LineTerminatorSequence
545 | / __ EOF
546 |
547 | EOF
548 | = !.
549 |
550 | Comment "comment"
551 | = MultiLineComment
552 | / SingleLineComment
553 |
554 | MultiLineComment
555 | = "/*" (!"*/" SourceCharacter)* "*/"
556 |
557 | MultiLineCommentNoLineTerminator
558 | = "/*" (!("*/" / LineTerminator) SourceCharacter)* "*/"
559 |
560 | SingleLineComment
561 | = "//" (!LineTerminator SourceCharacter)* (LineTerminator / EOF)
562 | _
563 | = (WhiteSpace / MultiLineCommentNoLineTerminator / SingleLineComment)*
564 |
565 | __
566 | = (WhiteSpace / LineTerminatorSequence / Comment)*
567 |
--------------------------------------------------------------------------------