js2 0.0.8 → 0.0.9

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.
Files changed (43) hide show
  1. data/Changelog +3 -0
  2. data/Manifest.txt +13 -28
  3. data/Rakefile +19 -19
  4. data/bin/js2 +48 -41
  5. data/lib/javascript/sel_marker.js2 +3 -3
  6. data/lib/js2/config.rb +6 -1
  7. data/lib/js2/{process/file_handler.rb → file_handler.rb} +15 -19
  8. data/lib/js2/foo.js2.haml +3 -0
  9. data/lib/js2/{process/haml_engine.rb → haml_engine.rb} +1 -1
  10. data/lib/js2/{parser/haml.rb → haml_parser.rb} +20 -7
  11. data/lib/js2/js2.js +108 -0
  12. data/lib/js2/js2bootstrap.js2 +455 -0
  13. data/lib/js2/parser.rb +3542 -0
  14. data/lib/js2/processor.rb +14 -65
  15. data/lib/js2/replace.rb +106 -0
  16. data/lib/js2/{decorator/test.rb → sel_decorator.rb} +11 -14
  17. data/{meta/c_tokenizer.rl.erb → lib/js2/tokenizer.rl.erb} +155 -123
  18. data/lib/js2/tree.rb +340 -0
  19. data/lib/js2/universe.rb +101 -0
  20. data/lib/js2.rb +31 -77
  21. data/lib/tasks/js2.rake +1 -1
  22. metadata +15 -29
  23. data/lib/js2/ast/class_node.rb +0 -105
  24. data/lib/js2/ast/comment_node.rb +0 -2
  25. data/lib/js2/ast/haml_node.rb +0 -22
  26. data/lib/js2/ast/include_node.rb +0 -11
  27. data/lib/js2/ast/inherited_node.rb +0 -7
  28. data/lib/js2/ast/member_node.rb +0 -18
  29. data/lib/js2/ast/method_node.rb +0 -29
  30. data/lib/js2/ast/module_node.rb +0 -6
  31. data/lib/js2/ast/node.rb +0 -14
  32. data/lib/js2/ast/nodes.rb +0 -123
  33. data/lib/js2/ast/stuff_node.rb +0 -6
  34. data/lib/js2/decorator/app.rb +0 -7
  35. data/lib/js2/decorator/cleanser.rb +0 -54
  36. data/lib/js2/decorator/standard.rb +0 -103
  37. data/lib/js2/parser/fast.rb +0 -3959
  38. data/lib/js2/process/universe.rb +0 -89
  39. data/lib/js2/test/selenium.rb +0 -109
  40. data/lib/js2/test/selenium_element.rb +0 -234
  41. data/lib/js2/test/selenium_helper.rb +0 -27
  42. data/lib/js2bootstrap.js2 +0 -274
  43. data/meta/replace.rb +0 -126
data/lib/js2/processor.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'yaml'
2
2
 
3
3
  class JS2::Processor
4
- attr_accessor :fh, :haml_engine, :decorator
4
+ attr_accessor :fh, :haml_engine
5
5
 
6
6
  # ----------------------------------------------------------------------------
7
7
  # Rails support
@@ -20,13 +20,16 @@ class JS2::Processor
20
20
  # ----------------------------------------------------------------------------
21
21
  # yaml support
22
22
  # ----------------------------------------------------------------------------
23
- def self.from_yaml(file)
24
- config = JS2::Config.new(YAML.load_file(file))
23
+ def self.from_yaml(file, env = nil)
24
+ hash = YAML.load_file(file)
25
+ hash = hash[env] if env
26
+
27
+ config = JS2::Config.new(hash)
25
28
  return self.get(config)
26
29
  end
27
30
 
28
- def self.daemon_from_yaml(file)
29
- p = self.from_yaml(file)
31
+ def self.daemon_from_yaml(file, env = nil)
32
+ p = self.from_yaml(file, env)
30
33
  return JS2::Daemon.new(p)
31
34
  end
32
35
 
@@ -67,7 +70,7 @@ class JS2::Processor
67
70
  # haml engine
68
71
  haml_engine_class = config.haml_engine_class ?
69
72
  config.haml_engine_class.constantize :
70
- JS2::Process::HamlEngine
73
+ JS2::HamlEngine
71
74
 
72
75
  haml_engine = haml_engine_class.new
73
76
 
@@ -77,87 +80,33 @@ class JS2::Processor
77
80
  js2_haml_dir = config.js2_haml_dir
78
81
  haml_dir = config.haml_dir
79
82
 
80
- file_handler = JS2::Process::FileHandler.new(
83
+ file_handler = JS2::FileHandler.new(
81
84
  :read_dir => js2_dir,
82
85
  :write_dir => write_dir,
83
86
  :haml_dir => js2_haml_dir,
84
87
  :view_dir => haml_dir
85
88
  )
86
89
 
87
- decorator_klass = config.test_mode ?
88
- JS2::Decorator::Test :
89
- JS2::Decorator::Standard
90
-
91
90
  return self.new(
92
91
  :test_mode => config.test_mode,
93
92
  :reference_dir => config.reference_dir,
94
93
  :haml_engine => haml_engine,
95
94
  :file_handler => file_handler,
96
- :decorator_klass => decorator_klass
95
+ :vars => config.vars
97
96
  )
98
97
  end
99
98
 
100
99
  def initialize (params)
101
100
  @haml_engine = params[:haml_engine]
102
101
  @fh = params[:file_handler]
103
- @decorator_klass = params[:decorator_klass]
104
102
  @reference_dir = params[:reference_dir]
105
103
  @test_mode = params[:test_mode]
104
+ @vars = params[:vars]
106
105
  end
107
106
 
108
107
  def write_files
109
- parser ||= JS2::Parser::Fast.new()
110
- haml_parser ||= JS2::Parser::Haml.new(@haml_engine)
111
- universe = JS2::Process::Universe.new
112
-
113
- decorator = @decorator_klass.new
114
-
115
- bootstrap_file = File.dirname(__FILE__) + "/../js2bootstrap.js2"
116
- bootstrap_nodes = parser.parse(bootstrap_file)
117
- universe.add_nodes(bootstrap_nodes)
118
-
119
- @fh.get_files.each do |filename|
120
- nodes = parser.parse(filename)
121
- universe.add_nodes(nodes)
122
- end
123
-
124
- @fh.get_yml_files.each do |filename|
125
- begin
126
- yml = YAML.load_file(filename)
127
- universe.add_yml(yml, filename)
128
- rescue Exception => e
129
- puts "YAML Error in #{filename}:"
130
- puts e.to_s
131
- end
132
- end
133
-
134
- @fh.get_haml_files.each do |filename|
135
- hash = haml_parser.parse(filename)
136
- universe.add_haml_hash(hash)
137
- end
138
-
139
- universe.finalize!
140
-
141
- universe.node_containers.each do |nc|
142
- str = decorator.draw_nodes(nc)
143
- @fh.write_file(nc.filename, str)
144
- end
145
-
146
- if @test_mode
147
- decorator.write_references(@reference_dir)
148
- end
149
-
150
- @fh.get_view_files.each do |filename|
151
- js = haml_parser.parse_out_js(filename)
152
- nodes = parser.parse_string(js)
153
- decorator = @decorator_klass.new
154
- decorator.draw_nodes(nodes)
155
- decorator.write_references(@reference_dir)
156
- end
157
-
158
- universe.compilations.each_pair do |filename, hash|
159
- @fh.write_compilation(filename, hash)
160
- end
108
+ universe = JS2::Universe.new(@fh, @haml_engine)
109
+ universe.write
161
110
  end
162
111
 
163
112
  end
@@ -0,0 +1,106 @@
1
+ require 'erb'
2
+
3
+ LITERALS = [ '!=', '!==', '#', '%', '%=', '&&', '&&=', '&=', '*', '*=', '+', '+=', ',', '-', '-=', '->', '.', '/', '/=', ':', '::', '<', '<<', '<<=', '<=', '=', '==', '===', '>', '>=', '>>', '>>=', '>>>', '>>>=', '?', '@', '[', '^', '^=', '^^', '^^=', '|', '|=', '||', '||=', 'abstract', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'enum', 'export', 'extends', 'field', 'final', 'finally', 'for', 'function', 'goto', 'if', 'implements', 'import', 'in', 'instanceof', 'native', 'new', 'package', 'private', 'protected', 'public', 'return', 'static', 'switch', 'synchronized', 'throw', 'throws', 'transient', 'try', 'typeof', 'var', 'volatile', 'while', 'with', 'foreach', 'module', 'include' ]
4
+
5
+ class Replacer
6
+ def initialize
7
+ @types = []
8
+ end
9
+
10
+ def def_literals
11
+ ret = []
12
+ LITERALS.each do |literal|
13
+ ret << "'#{literal}' ws* regexpliteral => { };"
14
+ end
15
+ ret.join("\n") + "\n"
16
+ end
17
+
18
+ def warn_int (int)
19
+ return <<-END
20
+ rb_funcall2(self, warn_sym, 1, warn_intv);
21
+ END
22
+ end
23
+
24
+ def mark_node ()
25
+ return <<-END
26
+ mark_argv[0] = INT2FIX(ts-data+1);
27
+ rb_funcall2(self, mark_sym, 1, mark_argv);
28
+ END
29
+ end
30
+
31
+ def start_node (type, idx = nil, ignore_curly = false)
32
+ return <<-END
33
+ #{ignore_curly ? '' : 'curlies[++curly_idx] = cb_count;'};
34
+
35
+ start_argv[0] = sym_#{type};
36
+ start_argv[1] = INT2FIX(#{idx || 'ts-data'});
37
+ start_argv[2] = INT2FIX(is_static);
38
+ rb_funcall2(self, start_sym, 3, start_argv);
39
+ is_static = 0;
40
+ END
41
+ end
42
+
43
+ def start_member (type, idx = nil)
44
+ return <<-END
45
+ close_on_semi = 1;
46
+ start_argv[0] = sym_#{type};
47
+ start_argv[1] = INT2FIX(#{idx || 'ts-data'});
48
+ start_argv[2] = INT2FIX(is_static);
49
+ rb_funcall2(self, start_sym, 3, start_argv);
50
+ is_static = 0;
51
+ END
52
+ end
53
+
54
+
55
+ def stop_node (idx = nil)
56
+ return <<-END
57
+ if (curly_idx) curly_idx--;
58
+ stop_argv[0] = INT2FIX(#{idx || 'te-data'});
59
+ rb_funcall2(self, stop_sym, 1, stop_argv);
60
+ END
61
+ end
62
+
63
+ def stop_member (idx = nil)
64
+ return <<-END
65
+ close_on_semi = 0;
66
+ stop_argv[0] = INT2FIX(#{idx || 'te-data'});
67
+ rb_funcall2(self, stop_sym, 1, stop_argv);
68
+ END
69
+ end
70
+
71
+
72
+ def in_class
73
+ return "in_class == (cb_count + 1)"
74
+ end
75
+
76
+ def in_module
77
+ return "in_class == curly_idx || in_module == curly_idx"
78
+ end
79
+
80
+ def declare_vars (types)
81
+ ret = ''
82
+ types.each do |type|
83
+ ret += self.declare(type)
84
+ end
85
+
86
+ return ret
87
+ end
88
+
89
+ def declare (type)
90
+ return <<-END
91
+ // #{type}
92
+ ID sym_#{type} = ID2SYM(rb_intern("#{type}"));
93
+ END
94
+ end
95
+
96
+ end
97
+
98
+ module JS2
99
+ end
100
+
101
+ replacer = Replacer.new
102
+ template = ERB.new(File.read('tokenizer.rl.erb'), 0, "%<>")
103
+
104
+ File.open('tokenizer.rl', 'w') do |f|
105
+ f << template.result(binding)
106
+ end
@@ -1,27 +1,24 @@
1
1
  require 'json'
2
2
 
3
- class JS2::Decorator::Test < JS2::Decorator::Standard
3
+ class JS2::SelDecorator
4
4
 
5
5
  def initialize ()
6
- super()
7
6
  @references = Hash.new
8
7
  @in_class = false
9
8
  end
10
9
 
11
-
12
- def draw_class (node)
13
- str = super(node)
14
- @scope = node.name
15
- @in_class = true
16
- str = process_str(str)
10
+ def reset!
11
+ @references = Hash.new
17
12
  @in_class = false
18
- return str
19
13
  end
20
14
 
21
- def draw_stuff (node)
22
- str = super(node)
23
- @scope = nil
24
- return process_str(str)
15
+ def translate (str, scope = nil, in_class = false)
16
+ @scope = scope
17
+ @in_class = in_class
18
+ ret = process_str(str)
19
+ @in_class = false
20
+ @scope = nil
21
+ return ret
25
22
  end
26
23
 
27
24
  def write_references (dir)
@@ -120,7 +117,7 @@ class JS2::Decorator::Test < JS2::Decorator::Standard
120
117
  @scope.to_json
121
118
  end
122
119
 
123
- return padding + %{TMP_SEL_MARKER = this.SEL_MARKER || JS2.SEL_MARKER; TMP_SEL_MARKER.#{insert}(#{scope}, #{key.to_json}, #{lval}, #{finder});}
120
+ return padding + %{var TMP_SEL_MARKER = this.SEL_MARKER || JS2.SEL_MARKER; TMP_SEL_MARKER.#{insert}(#{scope}, #{key.to_json}, #{lval}, #{finder});}
124
121
  else
125
122
  return false
126
123
  end
@@ -24,6 +24,7 @@
24
24
  whitespacecharacter = [\t\v\f ];
25
25
  lineterminator = ('\r' | '\n');
26
26
  asciidigit = digit;
27
+ ws = (whitespacecharacter | lineterminator);
27
28
 
28
29
  literals = (
29
30
  '==' | '!=' | '===' | '!==' | '<=' | '>=' | '||' | '&&' | '++' | '--' | '<<' | '<<=' | '>>' | '>>=' | '>>>' | '>>>='| '&=' | '%=' | '^=' | '|=' | '+=' | '-=' | '*=' | '/='
@@ -101,83 +102,102 @@
101
102
  );
102
103
  single_char = any;
103
104
 
104
- arg_list = '(' . whitespacecharacter* . (identifier . whitespacecharacter* . ',' . whitespacecharacter*)* . identifier? . whitespacecharacter* . ')';
105
- curry_with = 'with' . whitespacecharacter* . arg_list;
106
- curry = 'curry' . whitespacecharacter* . arg_list? . whitespacecharacter* . curry_with? . whitespacecharacter* . '{';
105
+ var_list = (identifier . ws* . ',' . ws*)* . identifier?;
106
+ arg_list = '(' . ws* . var_list . ws* .')';
107
+
108
+ curry_with = 'with' . ws* . arg_list;
109
+ curry = 'curry' . ws* . arg_list? . ws* . curry_with? . ws*;
110
+
111
+ foreach = 'foreach' . ws* . '(' . ws* . 'var' . ws* . identifier . (ws* . ':' . ws* . identifier)? . ws*;
112
+
113
+ js2_include = 'include' . ws+ . identifier;
114
+ js2_class = 'class' . ws+ . identifier;
115
+ js2_module = 'module' . ws+ . identifier;
116
+
117
+ property = ws . 'property' . ws . var_list;
118
+ member = ws . ('static' . ws+)? . 'var' . ws+ . identifier;
119
+ method = ws . ('static' . ws+)? . 'function' . ws* . identifier;
120
+ private = ws . 'private' . ws;
121
+ accessor = ws . 'accessor' . ws;
122
+
123
+
124
+
107
125
 
108
126
  main := |*
109
127
 
110
128
  lineterminator => {
111
- line_number++;
129
+ //line_number++;
112
130
  };
113
131
 
114
- curry => {
115
- curr = ts-data;
116
- <%= replacer.start :CURRY %>
117
- cb_count++;
132
+ js2_class => {
133
+ if (in_class == 0) {
134
+ <%= replacer.start_node :CLASS %>
135
+ in_class = curly_idx;
136
+ }
118
137
  };
119
138
 
120
- whitespacecharacter => {};
121
- comment => {
122
- if (<%= replacer.directly_in? :CLASS %>) {
123
- <%= replacer.do_next(:COMMENT, 'ts-data', 'te-data-1') %>
139
+ private => {
140
+ if (in_class && in_class == curly_idx) {
141
+ <%= replacer.start_node :PRIVATE %>
142
+ <%= replacer.stop_node %>
124
143
  }
125
144
  };
126
145
 
127
- all_string => {};
128
- number => {};
129
- keywords => {
130
- curr = ts-data;
131
-
132
- <%= replacer.set_keyword %>
133
-
134
- if (<%= replacer.is? :CLASS %> || <%= replacer.is? :MODULE %>) {
135
- if (<%= replacer.is? :CLASS %>) {
136
- <%= replacer.start :CLASS %>
137
- } else {
138
- <%= replacer.start :MODULE %>
139
- }
146
+ js2_module => {
147
+ if (in_class == 0) {
148
+ <%= replacer.start_node :MODULE %>
149
+ in_class = curly_idx;
150
+ }
151
+ };
140
152
 
141
- // if "class" wasn't the first thing in the file
142
- // then submit the :STUFF
143
- if (curr > 0) {
144
- <%= replacer.stop :STUFF, 'curr-1' %>
145
- }
153
+ property => {
154
+ if (in_class && in_class == curly_idx) {
155
+ <%= replacer.start_member :PROPERTY %>
156
+ }
157
+ };
146
158
 
147
- } else if (<%= replacer.directly_in? :CLASS %> || <%= replacer.directly_in? :MODULE %>) {
148
- if (<%= replacer.is? :STATIC %>) {
149
- <%= replacer.set_static %>
150
- }
159
+ accessor => {
160
+ if (in_class && in_class == curly_idx) {
161
+ <%= replacer.start_member :ACCESSOR %>
162
+ }
163
+ };
151
164
 
152
- if (<%= replacer.is? :FUNCTION %>) {
153
- <%= replacer.start :METHOD %>
154
- }
155
165
 
156
- if (<%= replacer.is? :VAR %>) {
157
- <%= replacer.start :MEMBER %>
158
- }
166
+ member => {
167
+ if (in_class && in_class == curly_idx) {
168
+ <%= replacer.start_member :MEMBER %>
169
+ }
170
+ };
159
171
 
172
+ method => {
173
+ if (in_class && in_class == curly_idx) {
174
+ <%= replacer.start_node :METHOD %>
175
+ }
176
+ };
160
177
 
161
- if (<%= replacer.is? :ACCESSOR %>) {
162
- <%= replacer.start :MEMBER %>
163
- }
164
178
 
165
- if (<%= replacer.is? :PROPERTY %>) {
166
- <%= replacer.start :PROPERTY %>
167
- }
179
+ js2_include => {
180
+ if (in_class && in_class == curly_idx) {
181
+ <%= replacer.start_member :INCLUDE %>
182
+ }
183
+ };
168
184
 
185
+ foreach => {
186
+ <%= replacer.start_node :FOREACH %>
187
+ mark_on_br = br_count;
188
+ br_count++;
189
+ };
169
190
 
170
- if (<%= replacer.is? :INCLUDE %>) {
171
- <%= replacer.start :INCLUDE %>
172
- }
191
+ curry => {
192
+ <%= replacer.start_node :CURRY %>
193
+ };
173
194
 
174
- }
175
-
176
- if (<%= replacer.is? :FOREACH %>) {
177
- <%= replacer.start :FOREACH %>
178
- }
195
+ whitespacecharacter => {};
196
+ comment => { };
179
197
 
180
- };
198
+ all_string => {};
199
+ number => {};
200
+ keywords => { };
181
201
 
182
202
  literals => { };
183
203
  reserved => { };
@@ -185,38 +205,39 @@
185
205
 
186
206
  <%= replacer.def_literals %>
187
207
 
188
- single_char | (('(' | '{' | ';') whitespacecharacter* regexpliteral) => {
189
- curr = ts-data;
190
- single = data[ts-data];
191
-
192
- if (single == '(') {
193
- br_count++;
194
- } else if (single == ')') {
195
- br_count--;
196
-
197
- if (in_FOREACH && br_count == br_lvl_FOREACH) {
198
- <%= replacer.stop :FOREACH %>
199
- }
200
- }
208
+ single_char | (('(' | '{' | ';' | '}') ws* regexpliteral) => {
209
+ char single = data[ts-data];
201
210
 
202
211
  if (single == '{') {
212
+ in_foreach = 0;
203
213
  cb_count++;
204
214
  } else if (single == '}') {
205
- if (<%= replacer.directly_in? :CLASS %> || <%= replacer.directly_in? :MODULE %>) {
206
- <%= replacer.start :STUFF, 'curr+1' %>
207
- }
208
-
209
215
  cb_count--;
210
-
211
- // stuff that stops on }'s
212
- <%= replacer.handle_stops [ :METHOD, :CLASS, :FOREACH, :MODULE, :CURRY ] %>
216
+ if (curly_idx && curlies[curly_idx] == cb_count) {
217
+ in_foreach = 0;
218
+ <%= replacer.stop_node %>
219
+ if (curlies[in_class] == cb_count) {
220
+ in_class = 0;
221
+ }
222
+ }
223
+ } else if (single == ';' && close_on_semi == 1) {
224
+ <%= replacer.stop_member %>
213
225
  }
214
226
 
215
- if (single == ';') {
216
- <%= replacer.handle_semicolon_stops [ :MEMBER, :INCLUDE, :PROPERTY ] %>
227
+ if (single == ';' || single == '}') {
228
+ classable = 1;
217
229
  }
218
230
 
219
- };
231
+ if (single == '(') {
232
+ br_count++;
233
+ } else if (single == ')') {
234
+ br_count--;
235
+ if (mark_on_br == br_count) {
236
+ <%= replacer.stop_node %>
237
+ mark_on_br = -1;
238
+ }
239
+ }
240
+ };
220
241
 
221
242
  *|;
222
243
  }%%
@@ -224,7 +245,7 @@
224
245
  require 'rubygems'
225
246
  require 'inline'
226
247
 
227
- class JS2::Parser::Fast
248
+ class JS2::Parser
228
249
  attr_accessor :data
229
250
 
230
251
  inline do |builder|
@@ -236,33 +257,48 @@ class JS2::Parser::Fast
236
257
  int data_length = RSTRING(r_str)->len;
237
258
  char* data = STR2CSTR(r_str);
238
259
 
239
- VALUE ln_argv[1];
240
- int ln_argc = 1;
241
- int line_number = 1;
242
- ID ln_sym = rb_intern("set_line_number");
260
+ int in_class = 0;
261
+ int in_module = 0;
262
+ int close_on_semi = 0;
263
+ int classable = 1;
264
+ int in_foreach = 0;
265
+
266
+ // start vars
267
+ VALUE start_argv[3];
268
+ ID start_sym = rb_intern("start_node");
269
+
270
+ // stop vars
271
+ VALUE stop_argv[1];
272
+ ID stop_sym = rb_intern("stop_node");
243
273
 
244
- // do_next vars
245
- VALUE do_next_argv[4];
246
- int do_next_argc = 4;
247
- ID do_next_sym = rb_intern("do_next");
274
+ // mark vars
275
+ VALUE mark_argv[1];
276
+ ID mark_sym = rb_intern("mark_node");
277
+ int mark_on_br = -1;
278
+
279
+
280
+ VALUE warn_intv[1];
281
+ ID warn_sym = rb_intern("warn_int");
248
282
 
249
- VALUE set_static_argv[0];
250
- int set_static_argc = 0;
251
- ID set_static_sym = rb_intern("set_static");
252
283
 
253
284
  // state vars
254
285
  int i = 0; // iterator
255
286
  int j = 0; // iterator
256
- char word[100]; // keyword
257
- char single;
258
-
259
- int curr = 0;
260
- int prev = -1;
261
- int cb_count = 0;
262
- int br_count = 0;
263
287
 
264
- <%= replacer.declare_vars [ :CLASS, :METHOD, :MEMBER, :STUFF, :ACCESSOR, :COMMENT, :FOREACH, :MODULE, :INCLUDE, :CURRY, :PROPERTY ] %>
265
-
288
+ char keyword[100]; // keyword
289
+ char single;
290
+ int is_static = 0;
291
+ int is_private = 0;
292
+
293
+ // curly handling
294
+ int curlies[1000];
295
+ curlies[0] = 0;
296
+ int curly_idx = 0; // on purpose!
297
+ int cb_count = 0;
298
+ int br_count = 0;
299
+ int close_on_br = 0;
300
+
301
+ <%= replacer.declare_vars [ :CLASS, :METHOD, :MEMBER, :STUFF, :ACCESSOR, :COMMENT, :FOREACH, :MODULE, :INCLUDE, :CURRY, :PROPERTY, :PRIVATE, :STATIC ] %>
266
302
  // ragel variables
267
303
  int cs, act;
268
304
  char *ts = NULL;
@@ -272,51 +308,47 @@ class JS2::Parser::Fast
272
308
  char *eof = pe;
273
309
  char* regexp_start = NULL;
274
310
 
275
- <%= replacer.start :STUFF %>
311
+ <%= replacer.start_node :STUFF, 0, true %>
276
312
 
277
313
  %% write data;
278
314
  %% write init;
279
315
  %% write exec;
280
316
 
281
- if (in_STUFF == 1) {
282
- <%= replacer.stop :STUFF %>
283
- }
317
+ <%= replacer.stop_node('data_length-1') %>
284
318
  }
285
319
 
286
320
  END
287
321
  end
288
322
 
289
- def set_line_number (l)
290
- @line_number = l
323
+ def warn_int (int)
324
+ puts int.to_s
291
325
  end
292
326
 
293
- def set_static ()
294
- @nodes.set_static
327
+ def start_node (type, idx, is_static)
328
+ @ph.start_node(type, idx, is_static == 1)
295
329
  end
296
330
 
297
- def do_next (symbol, start_idx, end_idx, line)
298
- if end_idx == -1 then end_idx = start_idx end
299
- @nodes.do_next(symbol, start_idx, end_idx, line)
331
+ def stop_node (idx)
332
+ @ph.stop_node(idx)
300
333
  end
301
334
 
302
- def parse_string (str)
303
- self.data = str
304
- @nodes = JS2::AST::Nodes.new("string", str)
305
- self.do_parse(str)
306
- return @nodes
335
+ def mark_node (idx)
336
+ @ph.mark_node(idx)
307
337
  end
308
338
 
309
- def parse(filename)
310
- self.data = File.read(filename)
311
- @nodes = JS2::AST::Nodes.new(filename, data)
312
339
 
313
- #@cleanser ||= JS2::DecoCleanser.new
314
- #@cleanser.cleanse(data)
315
-
316
- eof = data.size
340
+ def parse (data)
341
+ @data = data
342
+ @ph = JS2::ParserHelper.new(data)
317
343
  self.do_parse(data)
344
+ return @ph
345
+ end
318
346
 
319
- return @nodes
347
+ def parse_file (filename)
348
+ data = File.read(filename)
349
+ ph = self.parse(data)
350
+ ph.filename = filename
351
+ return ph
320
352
  end
321
353
 
322
354
  end