diff options
author | Valerio Virgillito | 2012-05-16 15:23:48 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-05-16 15:23:48 -0700 |
commit | 13ae16997d4bbca14e255d5989d1c44a76eac72c (patch) | |
tree | d9ebb1dcc6bebee4cb910b950ecb67c1a2d593cd /node_modules/montage/core/selector/parser.js | |
parent | 99f16ae08fbb0a6dfe6008c9833f2253b18c19e5 (diff) | |
download | ninja-13ae16997d4bbca14e255d5989d1c44a76eac72c.tar.gz |
montage v.0.10 integration
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'node_modules/montage/core/selector/parser.js')
-rw-r--r-- | node_modules/montage/core/selector/parser.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/node_modules/montage/core/selector/parser.js b/node_modules/montage/core/selector/parser.js new file mode 100644 index 00000000..b674218c --- /dev/null +++ b/node_modules/montage/core/selector/parser.js | |||
@@ -0,0 +1,62 @@ | |||
1 | |||
2 | var Montage = require("montage").Montage; | ||
3 | |||
4 | var Parser = exports.Parser = Montage.create(Montage, { | ||
5 | |||
6 | newWithLanguage: { | ||
7 | value: function (language, callback) { | ||
8 | var self = Montage.create(this); | ||
9 | self.tokens = []; | ||
10 | self.state = language.parsePrevious(function (syntax) { | ||
11 | callback && callback(syntax); | ||
12 | return language.parseEof(); | ||
13 | }); | ||
14 | return self; | ||
15 | } | ||
16 | }, | ||
17 | |||
18 | state: { | ||
19 | value: null, | ||
20 | writable: true | ||
21 | }, | ||
22 | |||
23 | emit: { | ||
24 | value: function (token) { | ||
25 | try { | ||
26 | this.tokens.push(token); | ||
27 | this.state = this.state(token); | ||
28 | return this; | ||
29 | } catch (exception) { | ||
30 | if (exception instanceof SyntaxError) { | ||
31 | throw new SyntaxError(exception.message + ' at ' + this.format()); | ||
32 | } else { | ||
33 | throw exception; | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | }, | ||
38 | |||
39 | state: { | ||
40 | value: null, | ||
41 | writable: true | ||
42 | }, | ||
43 | |||
44 | syntax: { | ||
45 | value: null, | ||
46 | writable: true, | ||
47 | serializable: true | ||
48 | }, | ||
49 | |||
50 | format: { | ||
51 | value: function () { | ||
52 | return this.tokens.reduce(function (hither, token) { | ||
53 | if (token.type === 'literal') { | ||
54 | return hither + '(' + JSON.stringify(token.value) + ')'; | ||
55 | } else { | ||
56 | return hither + '.' + token.type; | ||
57 | } | ||
58 | }, 'Selector'); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | }); | ||