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/abstract-semantics.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/abstract-semantics.js')
-rw-r--r-- | node_modules/montage/core/selector/abstract-semantics.js | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/node_modules/montage/core/selector/abstract-semantics.js b/node_modules/montage/core/selector/abstract-semantics.js new file mode 100644 index 00000000..9a55ecca --- /dev/null +++ b/node_modules/montage/core/selector/abstract-semantics.js | |||
@@ -0,0 +1,100 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage").Montage; | ||
8 | |||
9 | var AbstractSemantics = exports.AbstractSemantics = Montage.create(Montage, { | ||
10 | |||
11 | create: { | ||
12 | value: function (prototype, descriptor) { | ||
13 | var self = Montage.create(prototype, descriptor); | ||
14 | |||
15 | var operators = self.operators; | ||
16 | self.evaluatorArgumentLengths = {}; | ||
17 | |||
18 | // convert the declared operators into evaluators | ||
19 | Object.keys(operators).forEach(function (name) { | ||
20 | var operate = operators[name]; | ||
21 | self.evaluators[name] = function () { // ...args | ||
22 | var args = Array.prototype.slice.call( | ||
23 | arguments, | ||
24 | 0, | ||
25 | operate.length | ||
26 | ); | ||
27 | return function (value, parameters, visitor) { | ||
28 | return operate.apply( | ||
29 | operators, | ||
30 | args.map(function (argument) { | ||
31 | return argument(value, parameters, visitor); | ||
32 | }) | ||
33 | ); | ||
34 | }; | ||
35 | }; | ||
36 | self.evaluatorArgumentLengths[name] = operate.length; | ||
37 | }); | ||
38 | |||
39 | return self; | ||
40 | } | ||
41 | }, | ||
42 | |||
43 | evaluatorArgumentLengths: { | ||
44 | value: null | ||
45 | }, | ||
46 | |||
47 | compile: { | ||
48 | value: function (syntax, parents) { | ||
49 | var self = this; | ||
50 | parents = { | ||
51 | syntax: syntax, | ||
52 | parents: parents | ||
53 | }; | ||
54 | if (syntax.type === 'value') { | ||
55 | return function (value) { | ||
56 | return value; | ||
57 | }; | ||
58 | } else if (syntax.type === 'parameters') { | ||
59 | return function (value, parameters) { | ||
60 | return parameters; | ||
61 | }; | ||
62 | } else if (syntax.type === 'literal') { | ||
63 | return function () { | ||
64 | return syntax.value; | ||
65 | }; | ||
66 | } else if (self.evaluators[syntax.type]) { | ||
67 | var evaluator = self.evaluators[syntax.type]; | ||
68 | var length = | ||
69 | self.evaluatorArgumentLengths[syntax.type] || | ||
70 | evaluator.length; | ||
71 | var args = syntax.args.map(function (child) { | ||
72 | return self.compile(child, parents); | ||
73 | }); | ||
74 | if (syntax.insensitive) { | ||
75 | args = args.map(function (evaluate) { | ||
76 | return function (value, parameters, visitor) { | ||
77 | return evaluate.call( | ||
78 | self, | ||
79 | value, | ||
80 | parameters, | ||
81 | visitor | ||
82 | ).toLowerCase(); | ||
83 | }; | ||
84 | }) | ||
85 | } | ||
86 | return evaluator.apply(self, args.concat([parents])); | ||
87 | } else { | ||
88 | throw new Error("Unknown evaluator " + syntax.type); | ||
89 | } | ||
90 | } | ||
91 | }, | ||
92 | |||
93 | evaluate: { | ||
94 | value: function (syntax, value, parameters, visitor) { | ||
95 | return this.compile(syntax)(value, parameters, visitor); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | }); | ||
100 | |||