minjs 0.1.3 → 0.1.5

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.
@@ -16,6 +16,8 @@ module Minjs
16
16
  a
17
17
  elsif a == ECMA262::LIT_LINE_FEED
18
18
  a
19
+ elsif a.nil?
20
+ ECMA262::LIT_LINE_FEED
19
21
  elsif a.lt?
20
22
  a
21
23
  else
@@ -28,7 +30,6 @@ module Minjs
28
30
  def statement(lex, context)
29
31
  [:block,
30
32
  :var_statement,
31
- :exp_statement,
32
33
  :if_statement,
33
34
  :iteration_statement,
34
35
  :continue_statement,
@@ -40,6 +41,7 @@ module Minjs
40
41
  :throw_statement,
41
42
  :try_statement,
42
43
  :debugger_statement,
44
+ :exp_statement,
43
45
  #
44
46
  # function declaration in statement(block) is not permitted by ECMA262.
45
47
  # however, almost all implementation permit it.
@@ -47,7 +49,6 @@ module Minjs
47
49
  :func_declaration,
48
50
  :empty_statement,
49
51
  ].each do |f|
50
- puts "* checking #{f.to_s}" if @debug
51
52
  t = lex.eval_lit {
52
53
  __send__(f, lex, context)
53
54
  }
@@ -62,7 +63,7 @@ module Minjs
62
63
  pos0 = lex.pos
63
64
  return nil unless lex.match_lit(ECMA262::PUNC_LCURLYBRAC)
64
65
  if lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
65
- return ECMA262::StBlock.new(ECMA262::StList.new([]))
66
+ return ECMA262::StBlock.new(ECMA262::StatementList.new([]))
66
67
  end
67
68
  lex.eval_lit {
68
69
  if s = statement_list(lex, context) and lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
@@ -83,7 +84,7 @@ module Minjs
83
84
  break
84
85
  end
85
86
  end
86
- ECMA262::StList.new(t)
87
+ ECMA262::StatementList.new(t)
87
88
  }
88
89
  end
89
90
  #
@@ -103,7 +104,6 @@ module Minjs
103
104
  end
104
105
  ECMA262::StVar.new(context, vl)
105
106
  else
106
- lex.debug_lit
107
107
  raise Minjs::ParseError.new("var_statement", lex)
108
108
  end
109
109
  }
@@ -170,7 +170,11 @@ module Minjs
170
170
  if a=exp(lex, context, {}) and semicolon(lex, context)
171
171
  ECMA262::StExp.new(a)
172
172
  else
173
- nil
173
+ if a
174
+ raise ParseError.new("no semicolon at end of expression statement", lex)
175
+ else
176
+ nil
177
+ end
174
178
  end
175
179
  }
176
180
  end
@@ -202,7 +206,6 @@ module Minjs
202
206
  if lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and e=exp(lex, context, {}) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and s=statement(lex, context)
203
207
  ECMA262::StWhile.new(e, s)
204
208
  else
205
- lex.debug_lit
206
209
  raise ParseError.new("while_statement", lex)
207
210
  end
208
211
  end
@@ -212,7 +215,6 @@ module Minjs
212
215
  if s=statement(lex, context) and lex.match_lit(ECMA262::ID_WHILE) and lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and e=exp(lex, context, {}) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and semicolon(lex, context)
213
216
  ECMA262::StDoWhile.new(e, s)
214
217
  else
215
- lex.debug_lit
216
218
  raise ParseError.new("do_while_statement", lex)
217
219
  end
218
220
  end
@@ -275,8 +277,14 @@ module Minjs
275
277
  lex.eval_lit {
276
278
  if semicolon(lex, context)
277
279
  ECMA262::StContinue.new
278
- elsif e=exp(lex, context, {}) and semicolon(lex, context)
280
+ elsif e=identifier(lex, context) and semicolon(lex, context)
279
281
  ECMA262::StContinue.new(e)
282
+ else
283
+ if e
284
+ raise ParseError.new("no semicolon at end of continue statement", lex)
285
+ else
286
+ raise ParseError.new("bad continue statement", lex)
287
+ end
280
288
  end
281
289
  }
282
290
  end
@@ -288,8 +296,14 @@ module Minjs
288
296
  lex.eval_lit {
289
297
  if semicolon(lex, context)
290
298
  ECMA262::StBreak.new
291
- elsif e=exp(lex, context, {}) and semicolon(lex, context)
299
+ elsif e=identifier(lex, context) and semicolon(lex, context)
292
300
  ECMA262::StBreak.new(e)
301
+ else
302
+ if e
303
+ raise ParseError.new("no semicolon at end of break statement", lex)
304
+ else
305
+ raise ParseError.new("bad break statement", lex)
306
+ end
293
307
  end
294
308
  }
295
309
  end
@@ -317,7 +331,6 @@ module Minjs
317
331
  if lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and e=exp(lex, context, {}) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and s=statement(lex, context)
318
332
  ECMA262::StWith.new(e, s)
319
333
  else
320
- lex.debug_lit
321
334
  raise ParseError.new("switch_statement", lex)
322
335
  end
323
336
  }
@@ -331,7 +344,6 @@ module Minjs
331
344
  if lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and e=exp(lex, context, {}) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and c = case_block(lex, context)
332
345
  ECMA262::StSwitch.new(e, c)
333
346
  else
334
- lex.debug_lit
335
347
  raise ParseError.new("switch_statement", lex)
336
348
  end
337
349
  }
@@ -374,11 +386,16 @@ module Minjs
374
386
  def throw_statement(lex, context)
375
387
  return nil unless lex.match_lit(ECMA262::ID_THROW)
376
388
  lex.eval_lit{
377
- if e=exp(lex, context, {}) and semicolon(lex, context)
389
+ if semicolon(lex, context)
390
+ raise ParseError.new("no line terminator here", lex)
391
+ elsif e=exp(lex, context, {}) and semi = semicolon(lex, context)
378
392
  ECMA262::StThrow.new(e)
379
393
  else
380
- lex.debug_lit
381
- raise ParseError.new("throw_statement", lex)
394
+ if e
395
+ raise ParseError.new("no semicolon at end of throw statement", lex)
396
+ else
397
+ raise ParseError.new("bad throw statement", lex)
398
+ end
382
399
  end
383
400
  }
384
401
  end
data/lib/minjs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Minjs
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Issei Numata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-13 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler