1 | var ignore = 'ignore',
|
2 | missing = 'missing',
|
3 | only = 'only',
|
4 | attrs = ["id", "mode", "group", "for", "model"];
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | exports.compile = function(compiler, args) {
|
33 | var file = args.shift(),
|
34 | onlyIdx = args.indexOf(only),
|
35 | onlyCtx = onlyIdx !== -1 ? args.splice(onlyIdx, 1) : false,
|
36 | parentFile = (args.pop() || '').replace(/\\/g, '\\\\'),
|
37 | ignore = args[args.length - 1] === missing ? (args.pop()) : false,
|
38 | w = args.filter(function(o) {
|
39 | return !o.k;
|
40 | }).join(' '),
|
41 | w_args = {};
|
42 |
|
43 | args.map(function(w) {
|
44 | if (w.k) w_args[w.k] = w.v;
|
45 | });
|
46 |
|
47 | return (ignore ? ' try {\n' : '') +
|
48 | '_output += _swig._w(_ctx._yog, '+ file+',' + JSON.stringify(w_args) + ', {' +
|
49 | 'resolveFrom: "' + parentFile + '"' +
|
50 | '})(' +
|
51 | ((onlyCtx && w) ? w : (!w ? '_ctx' : '_utils.extend({}, _ctx, ' + w + ')')) +
|
52 | ');\n' +
|
53 | (ignore ? '} catch (e) {}\n' : '');
|
54 | };
|
55 |
|
56 | exports.parse = function(str, line, parser, types, stack, opts) {
|
57 | var file, w, k;
|
58 |
|
59 | parser.on(types.STRING, function(token) {
|
60 |
|
61 | if (!file) {
|
62 | file = token.match;
|
63 | this.out.push(file);
|
64 | return;
|
65 | }
|
66 |
|
67 | var out = {
|
68 | v: '',
|
69 | k: ''
|
70 | };
|
71 |
|
72 | if (~attrs.indexOf(k)) {
|
73 | out.v = token.match.replace(/^("|')?(.*)\1$/g, '$2');
|
74 | out.k = k;
|
75 | this.out.push(out);
|
76 | v = '';
|
77 | }
|
78 |
|
79 | });
|
80 |
|
81 | parser.on(types.VAR, function(token) {
|
82 | if (!file) {
|
83 | k = '';
|
84 | file = token.match;
|
85 | return true;
|
86 | }
|
87 |
|
88 | if (~attrs.indexOf(token.match)) {
|
89 | k = token.match;
|
90 | return false;
|
91 | }
|
92 |
|
93 | if (!w && token.match === 'with') {
|
94 | w = true;
|
95 | return;
|
96 | }
|
97 |
|
98 | if (w && token.match === only && this.prevToken.match !== 'with') {
|
99 | this.out.push(token.match);
|
100 | return;
|
101 | }
|
102 |
|
103 | if (token.match === ignore) {
|
104 | return false;
|
105 | }
|
106 |
|
107 | if (token.match === missing) {
|
108 | if (this.prevToken.match !== ignore) {
|
109 | throw new Error('Unexpected token "' + missing + '" on line ' + line + '.');
|
110 | }
|
111 | this.out.push(token.match);
|
112 | return false;
|
113 | }
|
114 |
|
115 | if (this.prevToken.match === ignore) {
|
116 | throw new Error('Expected "' + missing + '" on line ' + line + ' but found "' + token.match + '".');
|
117 | }
|
118 |
|
119 | return true;
|
120 | });
|
121 |
|
122 | parser.on('end', function() {
|
123 | this.out.push(opts.filename || null);
|
124 | });
|
125 |
|
126 | return true;
|
127 | };
|
128 |
|
129 | exports.ends = false; |
\ | No newline at end of file |