minjs 0.1.2
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/minjs +12 -0
- data/lib/minjs/compressor.rb +418 -0
- data/lib/minjs/ctype.rb +846 -0
- data/lib/minjs/ecma262/base.rb +128 -0
- data/lib/minjs/ecma262/env.rb +78 -0
- data/lib/minjs/ecma262/exp.rb +630 -0
- data/lib/minjs/ecma262/lit.rb +552 -0
- data/lib/minjs/ecma262/punc.rb +84 -0
- data/lib/minjs/ecma262/st.rb +808 -0
- data/lib/minjs/ecma262.rb +6 -0
- data/lib/minjs/exceptions.rb +15 -0
- data/lib/minjs/expression.rb +714 -0
- data/lib/minjs/func.rb +86 -0
- data/lib/minjs/lex.rb +745 -0
- data/lib/minjs/literal.rb +45 -0
- data/lib/minjs/minjs_compressor.rb +47 -0
- data/lib/minjs/program.rb +32 -0
- data/lib/minjs/statement.rb +438 -0
- data/lib/minjs/version.rb +3 -0
- data/lib/minjs.rb +16 -0
- data/minjs.gemspec +31 -0
- metadata +132 -0
data/lib/minjs/func.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module Minjs
|
2
|
+
module Func
|
3
|
+
#
|
4
|
+
#13
|
5
|
+
#
|
6
|
+
def func_declaration(lex, context)
|
7
|
+
return nil if lex.match_lit(ECMA262::ID_FUNCTION).nil?
|
8
|
+
lex.eval_lit {
|
9
|
+
new_env = context.lex_env.new_declarative_env()
|
10
|
+
new_context = ECMA262::Context.new
|
11
|
+
new_context.lex_env = new_env
|
12
|
+
new_context.var_env = new_env
|
13
|
+
|
14
|
+
if id=identifier(lex, context) and
|
15
|
+
lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and
|
16
|
+
args = formal_parameter_list(lex, new_context) and
|
17
|
+
lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and
|
18
|
+
lex.match_lit(ECMA262::PUNC_LCURLYBRAC) and
|
19
|
+
b=func_body(lex, new_context) and lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
|
20
|
+
f = ECMA262::StFunc.new(new_context, id, args, b, true)
|
21
|
+
|
22
|
+
context.var_env.record.create_mutable_binding(id, nil)
|
23
|
+
context.var_env.record.set_mutable_binding(id, f, nil)
|
24
|
+
f
|
25
|
+
else
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def func_exp(lex, context)
|
32
|
+
return nil if lex.match_lit(ECMA262::ID_FUNCTION).nil?
|
33
|
+
STDERR.puts "*** func_exp" if @debug
|
34
|
+
lex.debug_lit if @debug
|
35
|
+
|
36
|
+
lex.eval_lit {
|
37
|
+
id_opt = identifier(lex, context)
|
38
|
+
new_env = context.lex_env.new_declarative_env()
|
39
|
+
new_context = ECMA262::Context.new
|
40
|
+
new_context.lex_env = new_env
|
41
|
+
new_context.var_env = new_env
|
42
|
+
|
43
|
+
if lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and
|
44
|
+
args = formal_parameter_list(lex, new_context) and
|
45
|
+
lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and
|
46
|
+
lex.match_lit(ECMA262::PUNC_LCURLYBRAC) and
|
47
|
+
b = func_body(lex, new_context) and lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
|
48
|
+
f = ECMA262::StFunc.new(new_context, id_opt, args, b)
|
49
|
+
if id_opt
|
50
|
+
new_context.var_env.record.create_mutable_binding(id_opt, nil)
|
51
|
+
new_context.var_env.record.set_mutable_binding(id_opt, f, nil)
|
52
|
+
id_opt.context = new_context
|
53
|
+
end
|
54
|
+
f
|
55
|
+
else
|
56
|
+
lex.debug_lit
|
57
|
+
raise 'error'
|
58
|
+
end
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def formal_parameter_list(lex, context)
|
63
|
+
lex.eval_lit{
|
64
|
+
ret = []
|
65
|
+
while true
|
66
|
+
a = identifier(lex, context)
|
67
|
+
if a
|
68
|
+
ret.push(a)
|
69
|
+
break if lex.match_lit(ECMA262::PUNC_COMMA).nil?
|
70
|
+
else
|
71
|
+
break
|
72
|
+
end
|
73
|
+
end
|
74
|
+
ret.each do |argName|
|
75
|
+
context.var_env.record.create_mutable_binding(argName, nil)
|
76
|
+
context.var_env.record.set_mutable_binding(argName, :undefined, nil, {:_parameter_list => true})
|
77
|
+
end
|
78
|
+
ret
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
def func_body(lex, context)
|
83
|
+
source_elements(lex, context)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|