Module: Fdlint::Parser::JS::Stat::Stat

Includes:
If, Iter, Switch, Try, Var
Included in:
JsParser
Defined in:
lib/fdlint/parser/js/stat/stat.rb

Overview

Stat : Statement node.

Instance Method Summary collapse

Methods included from Var

#parse_stat_var, #parse_stat_var_declaration, #parse_stat_var_declarationlist

Methods included from If

#parse_stat_if

Methods included from Switch

#parse_stat_caseblock, #parse_stat_caseclause, #parse_stat_caseclauses, #parse_stat_defaultclause, #parse_stat_switch

Methods included from Iter

#parse_stat_dowhile, #parse_stat_for, #parse_stat_while

Methods included from Try

#parse_stat_try

Instance Method Details

#after_parse_statement(stat) ⇒ Object



95
96
97
98
99
100
101
102
# File 'lib/fdlint/parser/js/stat/stat.rb', line 95

def after_parse_statement(stat)
  skip /[ \t]*/, true
  colon = !!check(/;/, true)
  stat.end_with_semicolon = colon
  colon ? skip(/;/, true) :
      (eos? || check(/\}/)) ? nil : skip(/\n/, true)
  stat
end

#parse_stat_blockObject



43
44
45
46
47
48
49
50
51
# File 'lib/fdlint/parser/js/stat/stat.rb', line 43

def parse_stat_block
  log 'parse stat block'
  
  pos = skip /\{/
  stats = batch(:parse_statement, /\}/)
  skip /\}/ 

  create_element BlockStatement, Elements.new(stats), pos
end

#parse_stat_breakObject



75
76
77
78
# File 'lib/fdlint/parser/js/stat/stat.rb', line 75

def parse_stat_break
  log 'parse stat break'
  parse_stat_simple /break/, :parse_expr_identifier
end

#parse_stat_continueObject



70
71
72
73
# File 'lib/fdlint/parser/js/stat/stat.rb', line 70

def parse_stat_continue
  log 'parse stat continue'
  parse_stat_simple /continue/, :parse_expr_identifier
end

#parse_stat_emptyObject



53
54
55
56
57
58
59
60
# File 'lib/fdlint/parser/js/stat/stat.rb', line 53

def parse_stat_empty
  log 'parse stat empty'
  pos = skip /;/
  
  stat = create_element Statement, 'empty'
  stat.end_with_semicolon = true
  stat
end

#parse_stat_expressionObject



62
63
64
65
66
67
68
# File 'lib/fdlint/parser/js/stat/stat.rb', line 62

def parse_stat_expression
  log 'parse stat expression'

  expr = parse_expression
  stat = create_element ExpressionStatement, expr
  after_parse_statement stat
end

#parse_stat_labelObject



90
91
92
93
# File 'lib/fdlint/parser/js/stat/stat.rb', line 90

def parse_stat_label
  log 'parse stat label'
  raise 'not impelments'
end

#parse_stat_returnObject



80
81
82
83
# File 'lib/fdlint/parser/js/stat/stat.rb', line 80

def parse_stat_return
  log 'parse stat return'
  parse_stat_simple /return/, :parse_expression
end

#parse_stat_throwObject



85
86
87
88
# File 'lib/fdlint/parser/js/stat/stat.rb', line 85

def parse_stat_throw
  log 'parse stat throw'
  parse_stat_simple /throw/, :parse_expression
end

#parse_statementObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fdlint/parser/js/stat/stat.rb', line 17

def parse_statement
  # 在ruby-1.8下map是无序的,所以这里只能用数组来实现
  map = [
    /\{/,         'block',
    /\;/,         'empty',
    /var\b/,      'var',
    /if\b/,       'if',
    /switch\b/,   'switch',
    /do\b/,       'dowhile',
    /while\b/,    'while',
    /for\b/,      'for',
    /continue\b/, 'continue',
    /break\b/,    'break',
    /return\b/,   'return',
    /throw\b/,    'throw',
    /try\b/,      'try',
    /./,          'expression'
  ] 

  0.upto(map.size / 2 - 1) do |i|
    if check(map[i * 2])
      return self.send('parse_stat_' + map[i * 2 + 1])
    end
  end
end