rbelly 0.2.1 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ module RBelly
2
+ module Nodes
3
+ class ClassNode < Node
4
+ attr_reader :class_body
5
+ def initialize(name, body)
6
+ super(name)
7
+ @class_body = body
8
+ end
9
+ end
10
+ end
11
+ end
@@ -78,7 +78,7 @@ edge [ ];
78
78
  end
79
79
 
80
80
  %w[EmptyStatement Parenthetical ExpressionStatement True Delete Return TypeOf
81
- SourceElements Number LogicalNot AssignExpr FunctionBody
81
+ SourceElements Number LogicalNot AssignExpr FunctionBody ClassBody
82
82
  ObjectLiteral UnaryMinus Throw This BitwiseNot Element String
83
83
  Array CaseBlock Null Break Parameter Block False Void Regexp
84
84
  Arguments Attr Continue ConstStatement UnaryPlus VarStatement].each do |node|
data/lib/rbelly/nodes.rb CHANGED
@@ -26,3 +26,4 @@ require 'rbelly/nodes/var_decl_node'
26
26
 
27
27
  #Bellejs
28
28
  require 'rbelly/nodes/bellejs/import_node'
29
+ require 'rbelly/nodes/bellejs/class_node'
@@ -11,7 +11,7 @@ module RBelly
11
11
  }
12
12
 
13
13
  BELLEJS_KEYWORDS = %w{
14
- import
14
+ import class
15
15
  }
16
16
 
17
17
  RESERVED = %w{
@@ -45,7 +45,7 @@ module RBelly
45
45
  # Single value nodes
46
46
  %w{
47
47
  AssignExprNode BitwiseNotNode BlockNode DeleteNode ElementNode
48
- ExpressionStatementNode FunctionBodyNode LogicalNotNode ReturnNode
48
+ ExpressionStatementNode FunctionBodyNode ClassBodyNode LogicalNotNode ReturnNode
49
49
  ThrowNode TypeOfNode UnaryMinusNode UnaryPlusNode VoidNode ImportNode
50
50
  }.each do |type|
51
51
  define_method(:"visit_#{type}") do |o|
@@ -207,6 +207,15 @@ module RBelly
207
207
  end
208
208
  end
209
209
 
210
+ def visit_ClassNode(o)
211
+ node = Node.new(@node_index += 1, [type, o.value || 'NULL'])
212
+ add_arrow_for(node)
213
+ @nodes << node
214
+ @stack.push(node)
215
+ o.class_body && o.class_body.accept(self)
216
+ @stack.pop
217
+ end
218
+
210
219
  def visit_DotAccessorNode(o)
211
220
  node = Node.new(@node_index += 1, ['DotAccessorNode', o.accessor])
212
221
  add_arrow_for(node)
@@ -92,6 +92,11 @@ module RBelly
92
92
  "#{o.function_body.accept(self)}"
93
93
  end
94
94
 
95
+ def visit_ClassNode(o)
96
+ "#{indent}class #{o.value}" +
97
+ "#{o.class_body.accept(self)}"
98
+ end
99
+
95
100
  def visit_ParameterNode(o)
96
101
  o.value
97
102
  end
@@ -101,6 +106,11 @@ module RBelly
101
106
  "{\n#{o.value.accept(self)}\n#{@indent -=1; indent}}"
102
107
  end
103
108
 
109
+ def visit_ClassBodyNode(o)
110
+ @indent += 1
111
+ "{\n#{o.value.accept(self)}\n#{@indent -=1; indent}}"
112
+ end
113
+
104
114
  def visit_BreakNode(o)
105
115
  "break" + (o.value ? " #{o.value}" : '') + ';'
106
116
  end
@@ -18,6 +18,9 @@ module RBelly
18
18
  def visit_FunctionDeclNode(o)
19
19
  end
20
20
 
21
+ def visit_ClassNode(o)
22
+ end
23
+
21
24
  def visit_VarStatementNode(o)
22
25
  o.value.each { |x| x.accept(self) }
23
26
  end
@@ -198,6 +201,11 @@ module RBelly
198
201
  scope_chain.return
199
202
  end
200
203
 
204
+ def visit_ClassBodyNode(o)
205
+ o.value.accept(self)
206
+ scope_chain.return
207
+ end
208
+
201
209
  def visit_ReturnNode(o)
202
210
  scope_chain.return = o.value.accept(self)
203
211
  end
@@ -17,13 +17,19 @@ module RBelly
17
17
  end
18
18
  end
19
19
 
20
+ def visit_ClassNode(o)
21
+ if o.value
22
+ scope_chain[o.value].value = RBelly::BELLEJS::Class.new(o.class_body)
23
+ end
24
+ end
25
+
20
26
  %w{
21
27
  AddNode ArgumentsNode ArrayNode AssignExprNode BitAndNode BitOrNode
22
28
  BitXOrNode BitwiseNotNode BlockNode BracketAccessorNode BreakNode
23
29
  CaseBlockNode CaseClauseNode CommaNode ConditionalNode
24
30
  ConstStatementNode ContinueNode DeleteNode DivideNode
25
31
  DoWhileNode DotAccessorNode ElementNode EmptyStatementNode EqualNode
26
- ExpressionStatementNode FalseNode ForInNode ForNode FunctionBodyNode
32
+ ExpressionStatementNode FalseNode ForInNode ForNode FunctionBodyNode ClassNode ClassBodyNode
27
33
  FunctionExprNode GetterPropertyNode GreaterNode GreaterOrEqualNode
28
34
  IfNode InNode InstanceOfNode LabelNode LeftShiftNode LessNode
29
35
  LessOrEqualNode LogicalAndNode LogicalNotNode LogicalOrNode ModulusNode
@@ -209,6 +209,10 @@ module RBelly
209
209
  [:func_body, super]
210
210
  end
211
211
 
212
+ def visit_ClassBodyNode(o)
213
+ [:class_body, super]
214
+ end
215
+
212
216
  def visit_ResolveNode(o)
213
217
  [:resolve, o.value]
214
218
  end
@@ -345,6 +349,10 @@ module RBelly
345
349
  [ :func_decl, *super]
346
350
  end
347
351
 
352
+ def visit_ClassNode(o)
353
+ [ :class, *super]
354
+ end
355
+
348
356
  def visit_ArgumentsNode(o)
349
357
  [:args, super]
350
358
  end
@@ -7,7 +7,7 @@ module RBelly
7
7
  }
8
8
  SINGLE_VALUE_NODES = %w{
9
9
  Parenthetical AssignExpr BitwiseNot Block Delete Element ExpressionStatement
10
- FunctionBody LogicalNot Return Throw TypeOf UnaryMinus UnaryPlus Void Import
10
+ FunctionBody ClassBody LogicalNot Return Throw TypeOf UnaryMinus UnaryPlus Void Import
11
11
  }
12
12
  BINARY_NODES = %w{
13
13
  Add BitAnd BitOr BitXOr CaseClause Comma Divide DoWhile Equal Greater
@@ -29,10 +29,11 @@ module RBelly
29
29
  CONDITIONAL_NODES = %w{ If Conditional }
30
30
  FUNC_CALL_NODES = %w{ NewExpr FunctionCall }
31
31
  FUNC_DECL_NODES = %w{ FunctionExpr FunctionDecl }
32
+ CLASS_NODES = %w{ Class }
32
33
  ALL_NODES = %w{ For ForIn Try BracketAccessor DotAccessor } +
33
34
  TERMINAL_NODES + SINGLE_VALUE_NODES + BINARY_NODES + ARRAY_VALUE_NODES +
34
35
  NAME_VALUE_NODES + PREFIX_POSTFIX_NODES + CONDITIONAL_NODES +
35
- FUNC_CALL_NODES + FUNC_DECL_NODES
36
+ FUNC_CALL_NODES + FUNC_DECL_NODES + CLASS_NODES
36
37
 
37
38
  def accept(target)
38
39
  target.accept(self)
@@ -95,6 +96,15 @@ module RBelly
95
96
  end
96
97
  end
97
98
 
99
+ CLASS_NODES.each do |type|
100
+ define_method(:"visit_#{type}Node") do |o|
101
+ [
102
+ o.value ? o.value : nil,
103
+ o.class_body.accept(self)
104
+ ]
105
+ end
106
+ end
107
+
98
108
  def visit_ForNode(o)
99
109
  [
100
110
  o.init ? o.init.accept(self) : nil,
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class BellejsTest < Test::Unit::TestCase
4
+
5
+ BELLEJS_IMPORT = "import 'fakeJSFileOne.bellejs';"
6
+ BELLEJS_CLASS = "class Dingo{
7
+
8
+ }"
9
+
10
+ def test_import_tokenizer
11
+ tokenizer = RBelly::Tokenizer.new
12
+ result = tokenizer.tokenize "import"
13
+ assert_equal result, [[:IMPORT, "import"]]
14
+ end
15
+
16
+ def test_import
17
+ parser = RBelly::Parser.new
18
+ result = parser.parse(BELLEJS_IMPORT)
19
+ assert_equal result.to_ecma, BELLEJS_IMPORT
20
+ end
21
+
22
+ def test_class_tokenizer
23
+ tokenizer = RBelly::Tokenizer.new
24
+ result = tokenizer.tokenize "class"
25
+ assert_equal result, [[:CLASS, "class"]]
26
+ end
27
+
28
+ def test_class
29
+ parser = RBelly::Parser.new
30
+ result = parser.parse(BELLEJS_CLASS)
31
+ assert_equal result.to_ecma, BELLEJS_CLASS
32
+ end
33
+
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbelly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 2.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-21 00:00:00.000000000 Z
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -63,6 +63,8 @@ files:
63
63
  - lib/rbelly/constants.rb
64
64
  - lib/rbelly/generated_parser.rb
65
65
  - lib/rbelly/js.rb
66
+ - lib/rbelly/bellejs.rb
67
+ - lib/rbelly/bellejs/class.rb
66
68
  - lib/rbelly/js/array.rb
67
69
  - lib/rbelly/js/base.rb
68
70
  - lib/rbelly/js/boolean.rb
@@ -104,6 +106,7 @@ files:
104
106
  - lib/rbelly/nodes/try_node.rb
105
107
  - lib/rbelly/nodes/var_decl_node.rb
106
108
  - lib/rbelly/nodes/bellejs/import_node.rb
109
+ - lib/rbelly/nodes/bellejs/class_node.rb
107
110
  - lib/rbelly/parser.rb
108
111
  - lib/rbelly/runtime.rb
109
112
  - lib/rbelly/runtime/ruby_function.rb
@@ -254,6 +257,7 @@ files:
254
257
  - test/test_void_node.rb
255
258
  - test/test_while_node.rb
256
259
  - test/test_with_node.rb
260
+ - test/test_bellejs.rb
257
261
  homepage: ''
258
262
  licenses: []
259
263
  post_install_message:
@@ -309,6 +313,7 @@ test_files:
309
313
  - test/test_array_node.rb
310
314
  - test/test_assign_expr_node.rb
311
315
  - test/test_automatic_semicolon_insertion.rb
316
+ - test/test_bellejs.rb
312
317
  - test/test_bit_and_node.rb
313
318
  - test/test_bit_or_node.rb
314
319
  - test/test_bit_x_or_node.rb
@@ -382,6 +387,7 @@ test_files:
382
387
  - test/test_postfix_node.rb
383
388
  - test/test_prefix_node.rb
384
389
  - test/test_property_node.rb
390
+ - test/test_rbelly.rb
385
391
  - test/test_regexp_node.rb
386
392
  - test/test_resolve_node.rb
387
393
  - test/test_return_node.rb