opal 0.3.2 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +85 -127
- data/bin/opal +3 -3
- data/lib/core.rb +114 -0
- data/{gems/core/lib → lib}/core/array.rb +68 -187
- data/{gems/core/lib → lib}/core/basic_object.rb +22 -5
- data/lib/core/class.rb +38 -0
- data/{gems/core/lib → lib}/core/dir.rb +1 -1
- data/lib/core/enumerable.rb +33 -0
- data/{gems/core/lib → lib}/core/error.rb +1 -4
- data/{gems/core/lib → lib}/core/false_class.rb +0 -0
- data/{gems/core/lib → lib}/core/file.rb +11 -3
- data/{gems/core/lib → lib}/core/hash.rb +12 -0
- data/{gems/core/lib → lib}/core/kernel.rb +114 -86
- data/lib/core/match_data.rb +33 -0
- data/lib/core/module.rb +97 -0
- data/{gems/core/lib → lib}/core/nil_class.rb +0 -0
- data/{gems/core/lib → lib}/core/numeric.rb +5 -0
- data/{gems/core/lib → lib}/core/object.rb +0 -0
- data/{gems/core/lib → lib}/core/proc.rb +13 -3
- data/{gems/core/lib → lib}/core/range.rb +10 -0
- data/{gems/core/lib → lib}/core/regexp.rb +33 -1
- data/{gems/core/lib → lib}/core/string.rb +25 -10
- data/{gems/core/lib → lib}/core/symbol.rb +3 -3
- data/{gems/core/lib → lib}/core/top_self.rb +0 -0
- data/{gems/core/lib → lib}/core/true_class.rb +0 -0
- data/lib/dev.rb +169 -0
- data/{gems/ospec/lib → lib}/ospec.rb +1 -0
- data/lib/ospec/autorun.rb +8 -0
- data/{gems/ospec/lib → lib}/ospec/dsl.rb +2 -2
- data/{gems/ospec/lib → lib}/ospec/example.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/before_and_after_hooks.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/errors.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/example_group.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/example_group_factory.rb +0 -3
- data/{gems/ospec/lib → lib}/ospec/example/example_group_hierarchy.rb +4 -3
- data/{gems/ospec/lib → lib}/ospec/example/example_group_methods.rb +1 -1
- data/{gems/ospec/lib → lib}/ospec/example/example_group_proxy.rb +3 -2
- data/{gems/ospec/lib → lib}/ospec/example/example_methods.rb +1 -1
- data/{gems/ospec/lib → lib}/ospec/example/example_proxy.rb +7 -7
- data/{gems/ospec/lib → lib}/ospec/expectations.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/expectations/errors.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/expectations/fail_with.rb +4 -3
- data/{gems/ospec/lib → lib}/ospec/expectations/handler.rb +6 -0
- data/lib/ospec/helpers/scratch.rb +18 -0
- data/{gems/ospec/lib → lib}/ospec/matchers.rb +2 -2
- data/{gems/ospec/lib → lib}/ospec/matchers/be.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/matchers/generated_descriptions.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/matchers/operator_matcher.rb +2 -0
- data/lib/ospec/matchers/raise_error.rb +38 -0
- data/lib/ospec/runner.rb +90 -0
- data/{gems/ospec/lib → lib}/ospec/runner/example_group_runner.rb +10 -13
- data/lib/ospec/runner/formatter/html_formatter.rb +139 -0
- data/{gems/ospec/lib → lib}/ospec/runner/formatter/terminal_formatter.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/runner/options.rb +1 -3
- data/{gems/ospec/lib → lib}/ospec/runner/reporter.rb +0 -9
- data/lib/racc/parser.rb +165 -0
- data/lib/strscan.rb +52 -0
- data/{lib → opal_lib}/opal.rb +2 -0
- data/opal_lib/opal/build_methods.rb +51 -0
- data/opal_lib/opal/builder.rb +164 -0
- data/opal_lib/opal/bundle.rb +70 -0
- data/opal_lib/opal/command.rb +68 -0
- data/{lib → opal_lib}/opal/context.rb +21 -9
- data/{lib → opal_lib}/opal/context/console.rb +0 -2
- data/opal_lib/opal/context/file_system.rb +34 -0
- data/{lib → opal_lib}/opal/context/loader.rb +26 -8
- data/opal_lib/opal/gem.rb +84 -0
- data/{lib → opal_lib}/opal/rake/builder_task.rb +2 -2
- data/opal_lib/opal/rake/spec_task.rb +32 -0
- data/{lib → opal_lib}/opal/ruby/nodes.rb +730 -109
- data/{lib → opal_lib}/opal/ruby/parser.rb +90 -23
- data/opal_lib/opal/ruby/ruby_parser.rb +4862 -0
- data/opal_lib/opal/ruby/ruby_parser.y +1454 -0
- data/opal_lib/opal/version.rb +4 -0
- data/runtime/class.js +359 -0
- data/runtime/debug.js +84 -0
- data/runtime/fs.js +199 -0
- data/runtime/init.js +558 -0
- data/runtime/loader.js +351 -0
- data/runtime/module.js +109 -0
- data/runtime/post.js +10 -0
- data/runtime/pre.js +7 -0
- data/runtime/runtime.js +351 -0
- metadata +88 -175
- data/.gitignore +0 -7
- data/Changelog +0 -31
- data/LICENSE +0 -75
- data/Rakefile +0 -86
- data/gems/core/README.md +0 -14
- data/gems/core/Rakefile +0 -8
- data/gems/core/core.gemspec +0 -13
- data/gems/core/lib/core.rb +0 -34
- data/gems/core/lib/core/class.rb +0 -31
- data/gems/core/lib/core/module.rb +0 -100
- data/gems/core/lib/core/vm.rb +0 -16
- data/gems/core/spec/core/array/append_spec.rb +0 -30
- data/gems/core/spec/core/array/assoc_spec.rb +0 -29
- data/gems/core/spec/core/array/at_spec.rb +0 -37
- data/gems/core/spec/core/array/clear_spec.rb +0 -22
- data/gems/core/spec/core/array/collect_bang_spec.rb +0 -27
- data/gems/core/spec/core/array/collect_spec.rb +0 -27
- data/gems/core/spec/core/array/compact_spec.rb +0 -41
- data/gems/core/spec/core/array/concat_spec.rb +0 -15
- data/gems/core/spec/core/array/constructor_spec.rb +0 -14
- data/gems/core/spec/core/array/each_spec.rb +0 -9
- data/gems/core/spec/core/array/element_reference_spec.rb +0 -4
- data/gems/core/spec/core/array/first_spec.rb +0 -35
- data/gems/core/spec/core/array/include_spec.rb +0 -9
- data/gems/core/spec/core/array/join_spec.rb +0 -6
- data/gems/core/spec/core/array/last_spec.rb +0 -51
- data/gems/core/spec/core/array/length_spec.rb +0 -6
- data/gems/core/spec/core/array/map_spec.rb +0 -33
- data/gems/core/spec/core/array/reverse_spec.rb +0 -6
- data/gems/core/spec/core/builtin_constants/builtin_constants_spec.rb +0 -7
- data/gems/core/spec/core/false/and_spec.rb +0 -10
- data/gems/core/spec/core/false/inspect_spec.rb +0 -6
- data/gems/core/spec/core/false/or_spec.rb +0 -10
- data/gems/core/spec/core/false/to_s_spec.rb +0 -6
- data/gems/core/spec/core/false/xor_spec.rb +0 -10
- data/gems/core/spec/core/file/join_spec.rb +0 -19
- data/gems/core/spec/core/hash/assoc_spec.rb +0 -32
- data/gems/core/spec/core/kernel/instance_eval_spec.rb +0 -0
- data/gems/core/spec/core/kernel/loop_spec.rb +0 -24
- data/gems/core/spec/core/kernel/raise_spec.rb +0 -0
- data/gems/core/spec/core/module/attr_accessor_spec.rb +0 -28
- data/gems/core/spec/core/number/lt_spec.rb +0 -12
- data/gems/core/spec/core/string/sub_spec.rb +0 -24
- data/gems/core/spec/core/true/and_spec.rb +0 -10
- data/gems/core/spec/core/true/inspect_spec.rb +0 -6
- data/gems/core/spec/core/true/or_spec.rb +0 -10
- data/gems/core/spec/core/true/to_s_spec.rb +0 -6
- data/gems/core/spec/core/true/xor_spec.rb +0 -10
- data/gems/core/spec/language/and_spec.rb +0 -61
- data/gems/core/spec/language/array_spec.rb +0 -68
- data/gems/core/spec/language/block_spec.rb +0 -38
- data/gems/core/spec/language/break_spec.rb +0 -36
- data/gems/core/spec/language/case_spec.rb +0 -103
- data/gems/core/spec/language/def_spec.rb +0 -21
- data/gems/core/spec/language/eigenclass_spec.rb +0 -60
- data/gems/core/spec/language/file_spec.rb +0 -13
- data/gems/core/spec/language/fixtures/block.rb +0 -21
- data/gems/core/spec/language/fixtures/super.rb +0 -293
- data/gems/core/spec/language/hash_spec.rb +0 -29
- data/gems/core/spec/language/if_spec.rb +0 -54
- data/gems/core/spec/language/loop_spec.rb +0 -11
- data/gems/core/spec/language/metaclass_spec.rb +0 -21
- data/gems/core/spec/language/method_spec.rb +0 -124
- data/gems/core/spec/language/next_spec.rb +0 -25
- data/gems/core/spec/language/or_spec.rb +0 -34
- data/gems/core/spec/language/redo_spec.rb +0 -24
- data/gems/core/spec/language/regexp_spec.rb +0 -26
- data/gems/core/spec/language/rescue_spec.rb +0 -20
- data/gems/core/spec/language/return_spec.rb +0 -47
- data/gems/core/spec/language/string_spec.rb +0 -25
- data/gems/core/spec/language/super_spec.rb +0 -32
- data/gems/core/spec/language/until_spec.rb +0 -157
- data/gems/core/spec/language/variables_spec.rb +0 -155
- data/gems/core/spec/language/while_spec.rb +0 -163
- data/gems/core/spec/spec_helper.rb +0 -5
- data/gems/core_fs/README.md +0 -19
- data/gems/dev/Rakefile +0 -5
- data/gems/dev/lib/dev.js +0 -99
- data/gems/dev/lib/dev/generator.js +0 -1264
- data/gems/dev/lib/dev/parser.js +0 -979
- data/gems/dev/lib/dev/ruby_parser.js +0 -1088
- data/gems/dev/lib/dev/ruby_parser.y +0 -1267
- data/gems/dev/lib/dev/string_scanner.js +0 -38
- data/gems/dev/tools/racc2js/README.md +0 -39
- data/gems/dev/tools/racc2js/math_parser.js +0 -222
- data/gems/dev/tools/racc2js/math_parser.rb +0 -133
- data/gems/dev/tools/racc2js/math_parser.y +0 -28
- data/gems/dev/tools/racc2js/parser.js +0 -218
- data/gems/dev/tools/racc2js/racc2js.rb +0 -153
- data/gems/json/README.md +0 -4
- data/gems/json/json.gemspec +0 -14
- data/gems/json/lib/json.rb +0 -64
- data/gems/json/lib/json/ext.rb +0 -51
- data/gems/json/lib/json/json2.js +0 -481
- data/gems/ospec/README.md +0 -0
- data/gems/ospec/lib/ospec/autorun.rb +0 -3
- data/gems/ospec/lib/ospec/runner.rb +0 -40
- data/gems/ospec/lib/ospec/runner/formatter/html_formatter.rb +0 -91
- data/gems/ospec/ospec.gemspec +0 -0
- data/gems/rquery/README.md +0 -9
- data/gems/rquery/lib/rquery.rb +0 -10
- data/gems/rquery/lib/rquery/ajax.rb +0 -4
- data/gems/rquery/lib/rquery/css.rb +0 -96
- data/gems/rquery/lib/rquery/document.rb +0 -25
- data/gems/rquery/lib/rquery/element.rb +0 -292
- data/gems/rquery/lib/rquery/event.rb +0 -108
- data/gems/rquery/lib/rquery/jquery.js +0 -8177
- data/gems/rquery/lib/rquery/request.rb +0 -138
- data/gems/rquery/lib/rquery/response.rb +0 -49
- data/gems/rquery/rquery.gemspec +0 -16
- data/lib/opal.js +0 -1597
- data/lib/opal/builder.rb +0 -117
- data/lib/opal/bundle.rb +0 -131
- data/lib/opal/command.rb +0 -11
- data/lib/opal/context/file_system.rb +0 -19
- data/lib/opal/gem.rb +0 -153
- data/lib/opal/ruby/ruby_parser.rb +0 -5170
- data/lib/opal/ruby/ruby_parser.y +0 -1298
- data/opal.gemspec +0 -15
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
var parser = function() {
|
|
2
|
-
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
parser.prototype.do_parse = function() {
|
|
6
|
-
return this.do_parse_js(parser.Racc_arg, false);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
parser.prototype.do_parse_js = function(arg, in_debug) {
|
|
10
|
-
var action_table = arg[0],
|
|
11
|
-
action_check = arg[1],
|
|
12
|
-
action_default = arg[2],
|
|
13
|
-
action_pointer = arg[3],
|
|
14
|
-
|
|
15
|
-
goto_table = arg[4],
|
|
16
|
-
goto_check = arg[5],
|
|
17
|
-
goto_default = arg[6],
|
|
18
|
-
goto_pointer = arg[7],
|
|
19
|
-
|
|
20
|
-
nt_base = arg[8],
|
|
21
|
-
reduce_table = arg[9],
|
|
22
|
-
token_table = arg[10],
|
|
23
|
-
shift_n = arg[11],
|
|
24
|
-
reduce_n = arg[12],
|
|
25
|
-
|
|
26
|
-
use_result = arg[13];
|
|
27
|
-
|
|
28
|
-
// racc sys vars
|
|
29
|
-
var racc_state = [0],
|
|
30
|
-
racc_tstack = [],
|
|
31
|
-
racc_vstack = [],
|
|
32
|
-
|
|
33
|
-
racc_t = null,
|
|
34
|
-
racc_tok = null,
|
|
35
|
-
racc_val = null,
|
|
36
|
-
racc_read_next = true,
|
|
37
|
-
|
|
38
|
-
racc_user_yyerror = false,
|
|
39
|
-
racc_error_status = 0;
|
|
40
|
-
|
|
41
|
-
var token = null, act = null, i = null, nerr = 0, curstate = null;
|
|
42
|
-
|
|
43
|
-
while (true) {
|
|
44
|
-
// console.log('looping');
|
|
45
|
-
if ((i = action_pointer[racc_state[racc_state.length - 1]]) !== null) {
|
|
46
|
-
// console.log('yeap');
|
|
47
|
-
if (racc_read_next) {
|
|
48
|
-
if (racc_t !== 0) { // not EOF
|
|
49
|
-
token = this.next_token();
|
|
50
|
-
racc_tok = token[0];
|
|
51
|
-
racc_val = token[1];
|
|
52
|
-
|
|
53
|
-
// console.log('token is: ' + token.join(','));
|
|
54
|
-
|
|
55
|
-
if (!racc_tok) { // EOF
|
|
56
|
-
racc_t = 0;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
racc_t = token_table[racc_tok];
|
|
60
|
-
if (racc_t === undefined) racc_t = 1;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// console.log('racc_t: ' + racc_t);
|
|
64
|
-
|
|
65
|
-
racc_read_next = false;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
i += racc_t;
|
|
70
|
-
|
|
71
|
-
// console.log('i is now ' + i);
|
|
72
|
-
|
|
73
|
-
if ((i < 0) || ((act = action_table[i]) === null) || (action_check[i] !== racc_state[racc_state.length - 1])) {
|
|
74
|
-
act = action_default[racc_state[racc_state.length - 1]];
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
act = action_default[racc_state[racc_state.length - 1]];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// console.log('act is: ' + act);
|
|
82
|
-
|
|
83
|
-
// ================
|
|
84
|
-
// = racc_evalact =
|
|
85
|
-
// ================
|
|
86
|
-
|
|
87
|
-
if (act > 0 && act < shift_n) {
|
|
88
|
-
// console.log('shift on ' + act);
|
|
89
|
-
//
|
|
90
|
-
// shift
|
|
91
|
-
//
|
|
92
|
-
if (racc_error_status > 0) {
|
|
93
|
-
// error token
|
|
94
|
-
// console.log('err part 1');
|
|
95
|
-
if (racc_t !== 1) {
|
|
96
|
-
// console.log('err part 2');
|
|
97
|
-
racc_error_status -= 1;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
racc_vstack.push(racc_val);
|
|
102
|
-
curstate = act;
|
|
103
|
-
racc_state.push(act);
|
|
104
|
-
racc_read_next = true;
|
|
105
|
-
}
|
|
106
|
-
else if (act < 0 && act > -reduce_n) {
|
|
107
|
-
// console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ reduce on ' + act);
|
|
108
|
-
//
|
|
109
|
-
// reduce
|
|
110
|
-
//
|
|
111
|
-
var reduce_i = act * -3,
|
|
112
|
-
reduce_len = reduce_table[reduce_i],
|
|
113
|
-
reduce_to = reduce_table[reduce_i + 1],
|
|
114
|
-
method_id = reduce_table[reduce_i + 2];
|
|
115
|
-
|
|
116
|
-
var tmp_v = racc_vstack.slice(racc_vstack.length - reduce_len);
|
|
117
|
-
// console.log('reduce len is: ' + reduce_len);
|
|
118
|
-
// console.log('tmp_v is: ' + tmp_v.join(', '));
|
|
119
|
-
|
|
120
|
-
// pop for number of reductions
|
|
121
|
-
while(reduce_len--) {
|
|
122
|
-
// console.log('popping: ' + reduce_len);
|
|
123
|
-
racc_state.pop();
|
|
124
|
-
racc_vstack.pop();
|
|
125
|
-
racc_tstack.pop();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (use_result) {
|
|
129
|
-
// msgsend..we push on result of method call..?
|
|
130
|
-
// console.log('reducing: ' + method_id);
|
|
131
|
-
// console.log('['+tmp_v.join(', ')+']');
|
|
132
|
-
// console.log('[' + racc_vstack.join(', ') + ']');
|
|
133
|
-
// racc_vstack.push(method_id);
|
|
134
|
-
// console.log("NEED TO EXECUTE: [" + tmp_v.join(',') + ']');
|
|
135
|
-
// console.log(this[method_id]);
|
|
136
|
-
var reduce_call_result = this[method_id](tmp_v, tmp_v[0]);
|
|
137
|
-
// console.log(reduce_call_result);
|
|
138
|
-
racc_vstack.push(reduce_call_result);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
throw "not using result?!?!?!?!?!";
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
racc_tstack.push(reduce_to);
|
|
145
|
-
|
|
146
|
-
// console.log('VSTACK: [' + racc_vstack.join(', ') + ']');
|
|
147
|
-
|
|
148
|
-
var k1 = reduce_to - nt_base;
|
|
149
|
-
// console.log('k1 is ' +k1);
|
|
150
|
-
// console.log("goto pointer is: " + goto_pointer[k1]);
|
|
151
|
-
if ((reduce_i = goto_pointer[k1]) !== null) {
|
|
152
|
-
|
|
153
|
-
reduce_i += racc_state[racc_state.length - 1];
|
|
154
|
-
// console.log("reduce_i is now: " + reduce_i);
|
|
155
|
-
// console.log("-- potential curstate is: " + goto_table[reduce_i]);
|
|
156
|
-
if ((reduce_i >= 0) && ((curstate = goto_table[reduce_i]) !== null) &&
|
|
157
|
-
(curstate !== undefined) && (goto_check[reduce_i] === k1)) {
|
|
158
|
-
// curstate = curstate; ..?
|
|
159
|
-
// console.log('========== return current state: ' + curstate);
|
|
160
|
-
racc_state.push(curstate);
|
|
161
|
-
}
|
|
162
|
-
else {//
|
|
163
|
-
// console.log("dont do this??");
|
|
164
|
-
// curstate = k1;
|
|
165
|
-
// console.log("=========== PUSHING curstate " + curstate);
|
|
166
|
-
// console.log('=========== goto default is: ' + goto_default[k1]);
|
|
167
|
-
racc_state.push(goto_default[k1]);
|
|
168
|
-
}
|
|
169
|
-
// tmp_v is return value from stack
|
|
170
|
-
// racc_vstack.push(tmp_v[0]);
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
// console.log('GOTO default down here init!!!!!!!!!!!');
|
|
175
|
-
racc_state.push(goto_default[k1]);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// return;
|
|
179
|
-
}
|
|
180
|
-
else if (act === shift_n) {
|
|
181
|
-
// console.log('accept on ' + act);
|
|
182
|
-
//
|
|
183
|
-
// accept
|
|
184
|
-
//
|
|
185
|
-
// console.log('accepting!!!!');
|
|
186
|
-
// console.log(racc_vstack[0]);
|
|
187
|
-
return racc_vstack[0];
|
|
188
|
-
}
|
|
189
|
-
else if (act === -reduce_n) {
|
|
190
|
-
// console.log('error on ' + act);
|
|
191
|
-
//
|
|
192
|
-
// error
|
|
193
|
-
//
|
|
194
|
-
// console.log('racc error status: ' + racc_error_status);
|
|
195
|
-
// console.log(racc_tok + ", " + racc_val);
|
|
196
|
-
throw new Error('syntax error, unexpected ' + racc_tok);
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
throw "Racc - unknown action: " + act;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// return;
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
// default next token implementation
|
|
208
|
-
parser.prototype.next_token = function() {
|
|
209
|
-
throw "next_token is not defined for parser."
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
parser.prototype.yyerror = function(err) {
|
|
213
|
-
throw "yyerror: " + err;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
parser.prototype._reduce_none = function(val, result) {
|
|
217
|
-
return result;
|
|
218
|
-
};
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby -wKU
|
|
2
|
-
|
|
3
|
-
class Racc2JS
|
|
4
|
-
|
|
5
|
-
def initialize(source, output = nil)
|
|
6
|
-
@source = source
|
|
7
|
-
@output = output ||
|
|
8
|
-
File.join(File.dirname(source), File.basename(source, '.*') + '.js')
|
|
9
|
-
|
|
10
|
-
@racc_output = File.join(
|
|
11
|
-
File.dirname(source), File.basename(source, '.*') + '.rb')
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def generate
|
|
15
|
-
puts "generating racc parser..."
|
|
16
|
-
`racc --output-file=#@racc_output #@source`
|
|
17
|
-
puts "loading generated parser.."
|
|
18
|
-
self.class.module_eval File.read(File.expand_path(@racc_output))
|
|
19
|
-
# we rely on only constant under our class being our new generated parser..
|
|
20
|
-
parser = self.class.constants[0]
|
|
21
|
-
raise "no suitable parser found in #@racc_output" unless parser
|
|
22
|
-
puts "using parser: #{parser}"
|
|
23
|
-
@parser_name = parser.to_s
|
|
24
|
-
@parser = self.class.const_get(parser)
|
|
25
|
-
|
|
26
|
-
@parser_output = []
|
|
27
|
-
handle_parser_runtime
|
|
28
|
-
handle_racc_arg
|
|
29
|
-
handle_racc_actions
|
|
30
|
-
|
|
31
|
-
# write output to our destination
|
|
32
|
-
File.open(@output, 'w') { |o| o.puts pre + @parser_output.join('') + post }
|
|
33
|
-
|
|
34
|
-
# remove temp ruby file
|
|
35
|
-
File.delete @racc_output
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# pre code
|
|
39
|
-
def pre
|
|
40
|
-
%Q[var #@parser_name = (function() {\n]
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# post code
|
|
44
|
-
def post
|
|
45
|
-
%Q[\n return parser;
|
|
46
|
-
})();
|
|
47
|
-
|
|
48
|
-
if (typeof require !== 'undefined' && typeof module !== 'undefined') {
|
|
49
|
-
exports.#@parser_name = #@parser_name;
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# add parser runtime to @parser_output
|
|
55
|
-
def handle_parser_runtime
|
|
56
|
-
source = File.read(File.join(File.dirname(__FILE__), 'parser.js'))
|
|
57
|
-
@parser_output << source
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# handle racc table
|
|
61
|
-
def handle_racc_arg
|
|
62
|
-
racc_arg = @parser::Racc_arg
|
|
63
|
-
|
|
64
|
-
@parser_output << "parser.Racc_arg = [\n"
|
|
65
|
-
|
|
66
|
-
# puts racc_arg
|
|
67
|
-
racc_arg.each_with_index do |arg, idx|
|
|
68
|
-
@parser_output.push "," if idx > 0
|
|
69
|
-
|
|
70
|
-
case arg
|
|
71
|
-
when Array
|
|
72
|
-
@parser_output << "["
|
|
73
|
-
|
|
74
|
-
arg.each_with_index do |ary_item, ary_idx|
|
|
75
|
-
@parser_output.push "," if ary_idx > 0
|
|
76
|
-
@parser_output.push ruby_to_javascript ary_item
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
@parser_output << "]"
|
|
80
|
-
when Hash
|
|
81
|
-
@parser_output << "{"
|
|
82
|
-
done = false
|
|
83
|
-
arg.each do |key, value|
|
|
84
|
-
@parser_output.push "," if done
|
|
85
|
-
done = true
|
|
86
|
-
|
|
87
|
-
@parser_output.push key.to_s.inspect
|
|
88
|
-
@parser_output.push ": "
|
|
89
|
-
@parser_output.push ruby_to_javascript(value)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
@parser_output << "}"
|
|
93
|
-
else
|
|
94
|
-
@parser_output << ruby_to_javascript(arg)
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
@parser_output << "];"
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
# output ruby values' javascript equivalent
|
|
102
|
-
def ruby_to_javascript(literal)
|
|
103
|
-
case literal
|
|
104
|
-
when Numeric
|
|
105
|
-
literal.to_s
|
|
106
|
-
when NilClass
|
|
107
|
-
# see parser.js - saves space once minimized. - removed.
|
|
108
|
-
'null'
|
|
109
|
-
when String, Symbol
|
|
110
|
-
literal.to_s.inspect
|
|
111
|
-
when true, false
|
|
112
|
-
literal.to_s
|
|
113
|
-
else
|
|
114
|
-
raise "Error: bad native: #{literal}"
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
# get all method from racc. we get all impl methods, and then output their
|
|
119
|
-
# code to js. we (for now) rely on all methods basically being:
|
|
120
|
-
#
|
|
121
|
-
# result = "val[0] + .."
|
|
122
|
-
#
|
|
123
|
-
# so we assign result a string, which we can then use to output js..hacky, but
|
|
124
|
-
# only way (for now).
|
|
125
|
-
def handle_racc_actions
|
|
126
|
-
# get all methods and unique them.
|
|
127
|
-
reduce_table = @parser::Racc_arg[9].select { |a| Symbol === a }.uniq!
|
|
128
|
-
# remove racc_error and _reduce_none
|
|
129
|
-
reduce_table.delete(:racc_error)
|
|
130
|
-
reduce_table.delete(:_reduce_none)
|
|
131
|
-
# we need a parser to use
|
|
132
|
-
parser = @parser.new
|
|
133
|
-
reduce_table.each do |reduction|
|
|
134
|
-
code = parser.send(reduction, nil, nil, nil)
|
|
135
|
-
@parser_output << %Q[
|
|
136
|
-
parser.prototype.#{reduction} = function(val, result) {
|
|
137
|
-
#{code}
|
|
138
|
-
return result;
|
|
139
|
-
};]
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
#
|
|
145
|
-
# bin
|
|
146
|
-
#
|
|
147
|
-
if ARGV.empty?
|
|
148
|
-
raise "no filename given"
|
|
149
|
-
elsif ARGV.length == 1
|
|
150
|
-
Racc2JS.new(ARGV[0]).generate
|
|
151
|
-
else
|
|
152
|
-
Racc2JS.new(ARGV[0], ARGV[1]).generate
|
|
153
|
-
end
|
data/gems/json/README.md
DELETED
data/gems/json/json.gemspec
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
|
|
3
|
-
Gem::Specification.new do |s|
|
|
4
|
-
s.name = "json"
|
|
5
|
-
s.version = "0.0.1"
|
|
6
|
-
s.authors = ["Adam Beynon"]
|
|
7
|
-
s.email = ["adam@adambeynon.com"]
|
|
8
|
-
s.homepage = "http://github.com/adambeynon/opal"
|
|
9
|
-
s.summary = "JSON implementation for opal"
|
|
10
|
-
|
|
11
|
-
s.files = Dir.glob("{bin,lib}/**/*") + %w[README.md]
|
|
12
|
-
s.require_path = "lib"
|
|
13
|
-
end
|
|
14
|
-
|
data/gems/json/lib/json.rb
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
require 'json/ext'
|
|
2
|
-
require 'json/json2'
|
|
3
|
-
|
|
4
|
-
module JSON
|
|
5
|
-
|
|
6
|
-
class JSONError < StandardError; end
|
|
7
|
-
|
|
8
|
-
class ParseError < JSONError; end
|
|
9
|
-
|
|
10
|
-
def self.parse(source, opts = nil)
|
|
11
|
-
`var json = JSON.parse(source);
|
|
12
|
-
|
|
13
|
-
var to_opal = function(value) {
|
|
14
|
-
|
|
15
|
-
switch (typeof value) {
|
|
16
|
-
case 'string':
|
|
17
|
-
return value;
|
|
18
|
-
|
|
19
|
-
case 'number':
|
|
20
|
-
return value;
|
|
21
|
-
|
|
22
|
-
case 'boolean':
|
|
23
|
-
return value ? Qtrue : Qfalse;
|
|
24
|
-
|
|
25
|
-
case 'null':
|
|
26
|
-
return nil;
|
|
27
|
-
|
|
28
|
-
case 'object':
|
|
29
|
-
if (!value) return nil;
|
|
30
|
-
|
|
31
|
-
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
|
32
|
-
var arr = [];
|
|
33
|
-
|
|
34
|
-
for (var i = 0, ii = value.length; i < ii; i++) {
|
|
35
|
-
arr.push(to_opal(value[i]));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return arr;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
var hash = VM.H(), v, assoc;
|
|
42
|
-
|
|
43
|
-
for (var k in value) {
|
|
44
|
-
if (Object.hasOwnProperty.call(value, k)) {
|
|
45
|
-
v = to_opal(value[k]);
|
|
46
|
-
assoc = k.$hash();
|
|
47
|
-
hash.$keys.push(k);
|
|
48
|
-
hash.$assocs[assoc] = v;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return hash;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return to_opal(json);`
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def self.generate(obj, opts = nil)
|
|
61
|
-
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|