js2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/meta/replace.rb ADDED
@@ -0,0 +1,126 @@
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 start (type, start_idx = nil)
11
+ return <<-END
12
+ in_#{type} = 1;
13
+ start_#{type} = #{start_idx || 'curr'};
14
+ line_#{type} = line_number;
15
+ cb_lvl_#{type} = cb_count;
16
+ br_lvl_#{type} = br_count;
17
+ END
18
+ end
19
+
20
+ # directly in
21
+ def directly_in? (type)
22
+ return "(cb_lvl_#{type} == (cb_count - 1) && in_#{type} == 1)"
23
+ end
24
+
25
+ def set_static
26
+ return "rb_funcall2(self, set_static_sym, set_static_argc, set_static_argv);"
27
+ end
28
+
29
+ def def_literals
30
+ ret = []
31
+ LITERALS.each do |literal|
32
+ ret << "'#{literal}' whitespacecharacter* regexpliteral => { };"
33
+ end
34
+ ret.join("\n") + "\n"
35
+ end
36
+
37
+ def is? (type)
38
+ return "strcmp(word, \"#{type.to_s.downcase}\") == 0"
39
+ end
40
+
41
+ def handle_stops (types)
42
+ ret = ''
43
+ types.each do |type|
44
+ ret += <<-END
45
+ if (in_#{type} && cb_lvl_#{type} == cb_count) {
46
+ #{self.stop type}
47
+ }
48
+ END
49
+ end
50
+
51
+ return ret
52
+ end
53
+
54
+ def handle_semicolon_stops (types)
55
+ ret = ''
56
+ types.each do |type|
57
+ ret += <<-END
58
+ if (in_#{type} == 1) {
59
+ #{self.stop type}
60
+ }
61
+ END
62
+ end
63
+ return ret
64
+ end
65
+
66
+ def declare_vars (types)
67
+ ret = ''
68
+ types.each do |type|
69
+ ret += self.declare(type)
70
+ end
71
+
72
+ return ret
73
+ end
74
+
75
+ def do_next (type, start, stop)
76
+ return <<-END
77
+ do_next_argv[0] = sym_#{type};
78
+ do_next_argv[1] = INT2FIX(#{start});
79
+ do_next_argv[2] = INT2FIX(#{stop});
80
+ do_next_argv[3] = INT2FIX(0);
81
+ rb_funcall2(self, do_next_sym, do_next_argc, do_next_argv);
82
+ END
83
+ end
84
+
85
+ def stop (type, stop = nil)
86
+ return <<-END
87
+ in_#{type} = 0;
88
+ cb_lvl_#{type} = -1;
89
+ do_next_argv[0] = sym_#{type};
90
+ do_next_argv[1] = INT2FIX(start_#{type});
91
+ do_next_argv[2] = INT2FIX(#{stop || 'curr'});
92
+ do_next_argv[3] = INT2FIX(0);
93
+ rb_funcall2(self, do_next_sym, do_next_argc, do_next_argv);
94
+ END
95
+ end
96
+
97
+
98
+ def declare (type)
99
+ return <<-END
100
+ // #{type}
101
+ int in_#{type} = 0;
102
+ int start_#{type} = -1;
103
+ int line_#{type} = 0;
104
+ int cb_lvl_#{type} = -1;
105
+ int br_lvl_#{type} = 0;
106
+ ID sym_#{type} = ID2SYM(rb_intern("#{type}"));
107
+ END
108
+ end
109
+
110
+ def set_keyword
111
+ <<-END
112
+ for (j=0, i=ts-data; i<te-data; i++) {
113
+ word[j] = data[i];
114
+ ++j;
115
+ }
116
+ word[j] = 0;
117
+ END
118
+ end
119
+ end
120
+
121
+ replacer = Replacer.new
122
+ template = ERB.new(File.read('c_tokenizer.rl.erb'), 0, "%<>")
123
+
124
+ File.open('final_tokenizer.rl', 'w') do |f|
125
+ f << template.result(binding)
126
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: js2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Su
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-23 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.3
24
+ version:
25
+ description: FIX (describe your package)
26
+ email:
27
+ - me@jeffsu.com
28
+ executables:
29
+ - js2
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - PostInstall.txt
36
+ files:
37
+ - Changelog
38
+ - History.txt
39
+ - LICENSE
40
+ - Manifest.txt
41
+ - PostInstall.txt
42
+ - README
43
+ - README.rdoc
44
+ - Rakefile
45
+ - examples/js2.yml
46
+ - examples/test.yml
47
+ - lib/javascript/sel_marker.js2
48
+ - lib/javascript/test.js2
49
+ - lib/js2.rb
50
+ - lib/js2/ast/class_node.rb
51
+ - lib/js2/ast/comment_node.rb
52
+ - lib/js2/ast/haml_node.rb
53
+ - lib/js2/ast/include_node.rb
54
+ - lib/js2/ast/inherited_node.rb
55
+ - lib/js2/ast/member_node.rb
56
+ - lib/js2/ast/method_node.rb
57
+ - lib/js2/ast/module_node.rb
58
+ - lib/js2/ast/node.rb
59
+ - lib/js2/ast/nodes.rb
60
+ - lib/js2/ast/stuff_node.rb
61
+ - lib/js2/config.rb
62
+ - lib/js2/daemon.rb
63
+ - lib/js2/decorator/app.rb
64
+ - lib/js2/decorator/cleanser.rb
65
+ - lib/js2/decorator/standard.rb
66
+ - lib/js2/decorator/test.rb
67
+ - lib/js2/parser/fast.rb
68
+ - lib/js2/parser/haml.rb
69
+ - lib/js2/process/file_handler.rb
70
+ - lib/js2/process/haml_engine.rb
71
+ - lib/js2/process/universe.rb
72
+ - lib/js2/processor.rb
73
+ - lib/js2/test/selenium.rb
74
+ - lib/js2/test/selenium_element.rb
75
+ - lib/js2/test/selenium_helper.rb
76
+ - lib/tasks/js2.rake
77
+ - meta/c_tokenizer.rl.erb
78
+ - meta/replace.rb
79
+ - bin/js2
80
+ has_rdoc: true
81
+ homepage: http://github.com/#{github_username}/#{project_name}
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --main
87
+ - README.rdoc
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ requirements: []
103
+
104
+ rubyforge_project: js2
105
+ rubygems_version: 1.3.5
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: FIX (describe your package)
109
+ test_files: []
110
+