rbelly 0.2.1 → 2.0.3

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/Manifest.txt CHANGED
@@ -7,6 +7,8 @@ lib/rbelly.rb
7
7
  lib/rbelly/constants.rb
8
8
  lib/rbelly/generated_parser.rb
9
9
  lib/rbelly/js.rb
10
+ lib/rbelly/bellejs.rb
11
+ lib/rbelly/bellejs/class.rb
10
12
  lib/rbelly/js/array.rb
11
13
  lib/rbelly/js/base.rb
12
14
  lib/rbelly/js/boolean.rb
@@ -48,6 +50,7 @@ lib/rbelly/nodes/strict_equal_node.rb
48
50
  lib/rbelly/nodes/try_node.rb
49
51
  lib/rbelly/nodes/var_decl_node.rb
50
52
  lib/rbelly/nodes/bellejs/import_node.rb
53
+ lib/rbelly/nodes/bellejs/class_node.rb
51
54
  lib/rbelly/parser.rb
52
55
  lib/rbelly/runtime.rb
53
56
  lib/rbelly/runtime/ruby_function.rb
data/lib/parser.y CHANGED
@@ -11,7 +11,7 @@ token FINALLY FOR FUNCTION IF IN INSTANCEOF NEW RETURN SWITCH THIS THROW TRY
11
11
  token TYPEOF VAR VOID WHILE WITH
12
12
 
13
13
  /* Bellejs Keywords */
14
- token IMPORT
14
+ token IMPORT CLASS
15
15
 
16
16
  /* punctuators */
17
17
  token EQEQ NE /* == and != */
@@ -56,6 +56,11 @@ rule
56
56
  | Statement
57
57
  ;
58
58
 
59
+ SourceElement:
60
+ ClassDeclaration
61
+ | Statement
62
+ ;
63
+
59
64
  Statement:
60
65
  Block
61
66
  | VariableStatement
@@ -101,6 +106,11 @@ rule
101
106
  yyabort unless klass
102
107
  result = klass.new(val[1], FunctionExprNode.new(nil, val[6], val[3]))
103
108
  }
109
+ | IDENT IDENT '{' ClassBody '}' {
110
+ klass = property_class_for(val.first)
111
+ yyabort unless klass
112
+ result = klass.new(val[1], ClassNode.new(nil, val[3]))
113
+ }
104
114
  ;
105
115
 
106
116
  PropertyList:
@@ -813,6 +823,12 @@ rule
813
823
  }
814
824
  ;
815
825
 
826
+ ClassDeclaration:
827
+ CLASS IDENT '{' ClassBody '}' {
828
+ result = ClassNode.new(val[1], val[3])
829
+ debug(val[3])
830
+ }
831
+
816
832
  FunctionDeclaration:
817
833
  FUNCTION IDENT '(' ')' '{' FunctionBody '}' {
818
834
  result = FunctionDeclNode.new(val[1], val[5])
@@ -850,6 +866,10 @@ rule
850
866
  }
851
867
  ;
852
868
 
869
+ ClassBody:
870
+ SourceElements { result = ClassBodyNode.new(val[0]) }
871
+ ;
872
+
853
873
  FunctionBody:
854
874
  SourceElements { result = FunctionBodyNode.new(val[0]) }
855
875
  ;
@@ -0,0 +1,36 @@
1
+ module RBelly
2
+ module BELLEJS
3
+ class Class < Base
4
+ class << self
5
+ def create(*args)
6
+ if args.length > 0
7
+ parser = RBelly::Parser.new
8
+ body = args.pop
9
+ tree = parser.parse("class { #{body} }")
10
+ klass = tree.value.first
11
+ self.new(klass.class_body)
12
+ else
13
+ self.new
14
+ end
15
+ end
16
+ end
17
+
18
+ attr_reader :body
19
+ def initialize(body = nil)
20
+ super()
21
+ @body = body
22
+ self['toString'] = :undefined
23
+ end
24
+
25
+ #def js_call(scope_chain, *params)
26
+ # arguments.each_with_index { |name, i|
27
+ # scope_chain[name.value] = params[i] || RBelly::Runtime::UNDEFINED
28
+ # }
29
+ # function_visitor = RBelly::Visitors::FunctionVisitor.new(scope_chain)
30
+ # eval_visitor = RBelly::Visitors::EvaluationVisitor.new(scope_chain)
31
+ # body.accept(function_visitor) if body
32
+ # body.accept(eval_visitor) if body
33
+ #end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,2 @@
1
+ require 'rbelly/bellejs/import'
2
+ require 'rbelly/bellejs/class'
@@ -1,3 +1,3 @@
1
1
  module RBelly
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
3
3
  end