rbelly 0.1.0 → 0.2.0

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/lib/rbelly/nodes.rb CHANGED
@@ -23,3 +23,6 @@ require 'rbelly/nodes/resolve_node'
23
23
  require 'rbelly/nodes/strict_equal_node'
24
24
  require 'rbelly/nodes/try_node'
25
25
  require 'rbelly/nodes/var_decl_node'
26
+
27
+ #Bellejs
28
+ require 'rbelly/nodes/bellejs/import_node'
@@ -10,6 +10,10 @@ module RBelly
10
10
  const true false null debugger
11
11
  }
12
12
 
13
+ BELLEJS_KEYWORDS = %w{
14
+ import
15
+ }
16
+
13
17
  RESERVED = %w{
14
18
  abstract boolean byte char class double enum export extends
15
19
  final float goto implements import int interface long native package
@@ -61,6 +65,9 @@ module RBelly
61
65
  token(:COMMENT, /\A\/(?:\*(?:.)*?\*\/|\/[^\n]*)/m)
62
66
  token(:STRING, /\A"(?:[^"\\]*(?:\\.[^"\\]*)*)"|\A'(?:[^'\\]*(?:\\.[^'\\]*)*)'/m)
63
67
 
68
+ # Combine Bellejs and regular javascript keywords
69
+ all_keywords = KEYWORDS + BELLEJS_KEYWORDS
70
+
64
71
  # A regexp to match floating point literals (but not integer literals).
65
72
  token(:NUMBER, /\A\d+\.\d*(?:[eE][-+]?\d+)?|\A\d+(?:\.\d*)?[eE][-+]?\d+|\A\.\d+(?:[eE][-+]?\d+)?/m) do |type, value|
66
73
  value.gsub!(/\.(\D)/, '.0\1') if value =~ /\.\w/
@@ -81,7 +88,7 @@ module RBelly
81
88
  end
82
89
 
83
90
  token(:RAW_IDENT, /\A([_\$A-Za-z][_\$0-9A-Za-z]*)/) do |type,value|
84
- if KEYWORDS.include?(value)
91
+ if all_keywords.include?(value)
85
92
  [value.upcase.to_sym, value]
86
93
  elsif RESERVED.include?(value)
87
94
  [:RESERVED, value]
@@ -46,7 +46,7 @@ module RBelly
46
46
  %w{
47
47
  AssignExprNode BitwiseNotNode BlockNode DeleteNode ElementNode
48
48
  ExpressionStatementNode FunctionBodyNode LogicalNotNode ReturnNode
49
- ThrowNode TypeOfNode UnaryMinusNode UnaryPlusNode VoidNode
49
+ ThrowNode TypeOfNode UnaryMinusNode UnaryPlusNode VoidNode ImportNode
50
50
  }.each do |type|
51
51
  define_method(:"visit_#{type}") do |o|
52
52
  node = Node.new(@node_index += 1, [type])
@@ -165,6 +165,10 @@ module RBelly
165
165
  "return" + (o.value ? " #{o.value.accept(self)}" : '') + ';'
166
166
  end
167
167
 
168
+ def visit_ImportNode(o)
169
+ "import #{o.value.accept(self)};"
170
+ end
171
+
168
172
  def visit_ThrowNode(o)
169
173
  "throw #{o.value.accept(self)};"
170
174
  end
@@ -202,6 +202,10 @@ module RBelly
202
202
  scope_chain.return = o.value.accept(self)
203
203
  end
204
204
 
205
+ def visit_ImportNode(o)
206
+ o.value.each { |x| x.accept(self) }
207
+ end
208
+
205
209
  def visit_BitwiseNotNode(o)
206
210
  orig = o.value.accept(self)
207
211
  number = to_int_32(orig)
@@ -36,7 +36,7 @@ module RBelly
36
36
  SetterPropertyNode StrictEqualNode StringNode
37
37
  SubtractNode SwitchNode ThisNode ThrowNode TrueNode TryNode TypeOfNode
38
38
  UnaryMinusNode UnaryPlusNode UnsignedRightShiftNode VarDeclNode
39
- VarStatementNode VoidNode WhileNode WithNode
39
+ VarStatementNode VoidNode WhileNode WithNode ImportNode
40
40
  }.each do |type|
41
41
  define_method(:"visit_#{type}") do |o|
42
42
  end
@@ -333,6 +333,10 @@ module RBelly
333
333
  o.value ? [:return, super] : [:return]
334
334
  end
335
335
 
336
+ def visit_ImportNode(o)
337
+ [:import, *super]
338
+ end
339
+
336
340
  def visit_FunctionExprNode(o)
337
341
  [ :func_expr, *super]
338
342
  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
10
+ FunctionBody 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
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.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: