fdlint 0.1.3 → 0.2.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -9
- data/Gemfile.lock +14 -4
- data/Rakefile +9 -85
- data/bin/fdlint +71 -8
- data/lib/fdlint/cli.rb +102 -0
- data/lib/{file_validator.rb → fdlint/file_validator.rb} +0 -0
- data/lib/fdlint/helper/code_type.rb +55 -0
- data/lib/fdlint/helper/file_reader.rb +19 -0
- data/lib/fdlint/helper/logger.rb +35 -0
- data/lib/fdlint/log_entry.rb +51 -0
- data/lib/fdlint/parser/base_parser.rb +151 -0
- data/lib/{css/parser.rb → fdlint/parser/css/css_parser.rb} +31 -28
- data/lib/{css → fdlint/parser/css}/struct.rb +5 -5
- data/lib/{encoding_error.rb → fdlint/parser/encoding_error.rb} +2 -2
- data/lib/{html/parser.rb → fdlint/parser/html/html_parser.rb} +26 -20
- data/lib/{html → fdlint/parser/html}/query.rb +0 -0
- data/lib/{html → fdlint/parser/html}/rule/check_tag_rule.rb +0 -0
- data/lib/{html → fdlint/parser/html}/struct.rb +82 -38
- data/lib/fdlint/parser/js/expr/expr.rb +71 -0
- data/lib/fdlint/parser/js/expr/left_hand.rb +65 -0
- data/lib/fdlint/parser/js/expr/operate.rb +94 -0
- data/lib/fdlint/parser/js/expr/primary.rb +168 -0
- data/lib/{js/parser.rb → fdlint/parser/js/js_parser.rb} +11 -9
- data/lib/fdlint/parser/js/stat/if.rb +27 -0
- data/lib/fdlint/parser/js/stat/iter.rb +88 -0
- data/lib/fdlint/parser/js/stat/stat.rb +120 -0
- data/lib/fdlint/parser/js/stat/switch.rb +67 -0
- data/lib/fdlint/parser/js/stat/try.rb +30 -0
- data/lib/fdlint/parser/js/stat/var.rb +42 -0
- data/lib/fdlint/parser/js/struct.rb +257 -0
- data/lib/fdlint/parser/node.rb +27 -0
- data/lib/fdlint/parser/parse_error.rb +10 -0
- data/lib/fdlint/parser/parser_visitable.rb +134 -0
- data/lib/{position_info.rb → fdlint/parser/position_info.rb} +12 -1
- data/lib/fdlint/parser.rb +3 -0
- data/lib/fdlint/printer/base_printer.rb +20 -0
- data/lib/fdlint/printer/console_printer.rb +80 -0
- data/lib/fdlint/printer/nocolor_printer.rb +29 -0
- data/lib/fdlint/printer/vim_printer.rb +21 -0
- data/lib/fdlint/printer.rb +1 -0
- data/lib/fdlint/rule/dsl.rb +83 -0
- data/lib/fdlint/rule/validation.rb +79 -0
- data/lib/fdlint/rule.rb +81 -0
- data/lib/fdlint/support/core/array.rb +5 -0
- data/lib/fdlint/support/core/file.rb +8 -0
- data/lib/fdlint/support/core/hash.rb +5 -0
- data/lib/fdlint/support/core/nil.rb +7 -0
- data/lib/fdlint/support/core/string.rb +7 -0
- data/lib/fdlint/support/core_ext.rb +5 -0
- data/lib/fdlint/validator.rb +102 -0
- data/lib/fdlint/version.rb +3 -0
- data/lib/fdlint.rb +5 -0
- data/rules.d/css.rule.rb +100 -0
- data/rules.d/filename.rule.rb +49 -0
- data/rules.d/html.rule.rb +169 -0
- data/rules.d/js.jquery.rule.rb +49 -0
- data/rules.d/js.rule.rb +205 -0
- data/test/default_test.rb +14 -0
- data/test/fixtures/js/scope-test.js +15 -2
- data/test/test_helper.rb +9 -0
- metadata +269 -221
- data/lib/base_parser.rb +0 -143
- data/lib/cmd_runner.rb +0 -145
- data/lib/context.rb +0 -31
- data/lib/css/reader.rb +0 -30
- data/lib/css/rule/check_compression_rule.rb +0 -48
- data/lib/css/rule/checklist.rb +0 -45
- data/lib/helper/code_type.rb +0 -50
- data/lib/helper/color_string.rb +0 -44
- data/lib/helper/file_reader.rb +0 -22
- data/lib/helper/strenc.rb +0 -65
- data/lib/js/expr/expr.rb +0 -66
- data/lib/js/expr/left_hand.rb +0 -63
- data/lib/js/expr/operate.rb +0 -92
- data/lib/js/expr/primary.rb +0 -166
- data/lib/js/rule/all.rb +0 -35
- data/lib/js/rule/checklist.rb +0 -41
- data/lib/js/rule/file_checker.rb +0 -42
- data/lib/js/rule/helper.rb +0 -96
- data/lib/js/rule/no_global.rb +0 -87
- data/lib/js/stat/if.rb +0 -25
- data/lib/js/stat/iter.rb +0 -85
- data/lib/js/stat/stat.rb +0 -117
- data/lib/js/stat/switch.rb +0 -65
- data/lib/js/stat/try.rb +0 -28
- data/lib/js/stat/var.rb +0 -40
- data/lib/js/struct.rb +0 -248
- data/lib/log_entry.rb +0 -49
- data/lib/node.rb +0 -28
- data/lib/parse_error.rb +0 -13
- data/lib/parser_visitable.rb +0 -138
- data/lib/printer/base_printer.rb +0 -24
- data/lib/printer/console_printer.rb +0 -66
- data/lib/printer/nocolor_printer.rb +0 -27
- data/lib/printer/vim_printer.rb +0 -19
- data/lib/rule.rb +0 -241
- data/lib/rule_helper.rb +0 -14
- data/lib/runner.rb +0 -225
- data/rules.d/css.rule +0 -127
- data/rules.d/html.dtd.rule +0 -22
- data/rules.d/html.prop.rule +0 -51
- data/rules.d/html.tag.rule +0 -136
- data/rules.d/js.file.rule +0 -13
- data/rules.d/js.jquery.rule +0 -56
- data/rules.d/js.mergefile.rule +0 -71
- data/rules.d/js.rule +0 -84
@@ -0,0 +1,94 @@
|
|
1
|
+
module Fdlint
|
2
|
+
module Parser
|
3
|
+
module JS
|
4
|
+
module Expr
|
5
|
+
|
6
|
+
module Operate
|
7
|
+
|
8
|
+
def parse_expr_postfix
|
9
|
+
log 'parse expr postfix'
|
10
|
+
expr = parse_expr_lefthand
|
11
|
+
if check(/[ \t]*(?:\+\+|--)/, true)
|
12
|
+
op = scan /\+\+|--/
|
13
|
+
expr = create_element Expression, op.text, expr
|
14
|
+
end
|
15
|
+
expr
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_expr_unary
|
19
|
+
log 'parse expr unary'
|
20
|
+
r = /delete|void|typeof|\+\+|--|\+|-|~|!/
|
21
|
+
if check r
|
22
|
+
op = scan r
|
23
|
+
create_element Expression, op.text, nil, parse_expr_unary, scanner_pos
|
24
|
+
else
|
25
|
+
parse_expr_postfix
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_expr_mul
|
30
|
+
log 'parse expr mul'
|
31
|
+
parse_expr_with_operate :parse_expr_unary, /(?:\*|\/|%)(?!=)/
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_expr_add
|
35
|
+
log 'parse expr add'
|
36
|
+
parse_expr_with_operate :parse_expr_mul, /(?:\+|-)(?!=)/
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_expr_shift
|
40
|
+
log 'parse expr shift'
|
41
|
+
parse_expr_with_operate :parse_expr_add, /(?:<<|>>>|>>)(?!=)/
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_expr_relation
|
45
|
+
not_in = expr_operate_not_in?
|
46
|
+
log "parse expr relational#{not_in ? '(notin)' : ''}"
|
47
|
+
pattern = not_in ? (/>=|<=|>|<|\binstanceof\b/) : (/>=|<=|>|<|\binstanceof\b|\bin\b/)
|
48
|
+
parse_expr_with_operate :parse_expr_shift, pattern
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse_expr_equal
|
52
|
+
log 'parse expr equal'
|
53
|
+
parse_expr_with_operate :parse_expr_relation, /===|!==|==|!=/
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse_expr_bit_and
|
57
|
+
log 'parse expr bit and'
|
58
|
+
parse_expr_with_operate :parse_expr_equal, /&(?![&=])/
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse_expr_bit_xor
|
62
|
+
log 'parse expr bit xor'
|
63
|
+
parse_expr_with_operate :parse_expr_bit_and, /\^(?!=)/
|
64
|
+
end
|
65
|
+
|
66
|
+
def parse_expr_bit_or
|
67
|
+
log 'parse expr bit or'
|
68
|
+
parse_expr_with_operate :parse_expr_bit_xor, /\|(?![|=])/
|
69
|
+
end
|
70
|
+
|
71
|
+
def parse_expr_logical_and
|
72
|
+
log 'parse expr logical and'
|
73
|
+
parse_expr_with_operate :parse_expr_bit_or, /&&/
|
74
|
+
end
|
75
|
+
|
76
|
+
def parse_expr_logical_or
|
77
|
+
log 'parse expr logical or'
|
78
|
+
parse_expr_with_operate :parse_expr_logical_and, /\|\|/
|
79
|
+
end
|
80
|
+
|
81
|
+
def expr_operate_not_in?
|
82
|
+
@operate_not_in || false
|
83
|
+
end
|
84
|
+
|
85
|
+
def expr_operate_not_in=(value)
|
86
|
+
@operate_not_in = !!value
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
module Fdlint
|
2
|
+
module Parser
|
3
|
+
module JS
|
4
|
+
module Expr
|
5
|
+
|
6
|
+
module Primary
|
7
|
+
|
8
|
+
R_IDENTIFY = /[a-zA-Z_$][\w$]*/
|
9
|
+
|
10
|
+
RESERVED_WORDS = %w(
|
11
|
+
break case catch continue debugger default delete do else
|
12
|
+
finally for function if in instanceof new return switch this
|
13
|
+
throw try typeof var void while with
|
14
|
+
class const enum export extends import super
|
15
|
+
implements interface let package private protected public static yield
|
16
|
+
null true false
|
17
|
+
)
|
18
|
+
|
19
|
+
R_THIS_NULL_BOOLEAN = /(?:this|null|true|false)\b/
|
20
|
+
R_HEX = /0[xX]/
|
21
|
+
R_NUMBERIC = /[+-]?(?:\d|(?:[.]\d))/
|
22
|
+
R_STRING = /['"]/
|
23
|
+
R_REGEXP = /\/[^\/]/
|
24
|
+
|
25
|
+
def parse_expr_primary
|
26
|
+
log "parse expr primary"
|
27
|
+
if check /\(/
|
28
|
+
parse_expr_parentheses
|
29
|
+
|
30
|
+
elsif check /\[/
|
31
|
+
parse_expr_array
|
32
|
+
|
33
|
+
elsif check /\{/
|
34
|
+
parse_expr_object
|
35
|
+
|
36
|
+
# literal
|
37
|
+
elsif check R_THIS_NULL_BOOLEAN
|
38
|
+
parse_expr_literal_this_null_boolean
|
39
|
+
|
40
|
+
elsif check R_HEX
|
41
|
+
parse_expr_literal_hex
|
42
|
+
|
43
|
+
elsif check R_NUMBERIC
|
44
|
+
parse_expr_literal_number
|
45
|
+
|
46
|
+
elsif check R_STRING
|
47
|
+
parse_expr_literal_string
|
48
|
+
|
49
|
+
elsif check R_REGEXP
|
50
|
+
parse_expr_literal_regexp
|
51
|
+
#~
|
52
|
+
|
53
|
+
else
|
54
|
+
parse_expr_identifier
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def parse_expr_parentheses
|
59
|
+
log 'parse expr parentheses'
|
60
|
+
|
61
|
+
pos = skip /\(/
|
62
|
+
expr = parse_expression
|
63
|
+
skip /\)/
|
64
|
+
|
65
|
+
create_expression 'parentheses', expr, pos
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_expr_array
|
69
|
+
log 'parse expr array'
|
70
|
+
|
71
|
+
pos = skip /\[/
|
72
|
+
elms = batch(:parse_expr_assignment, /\]/, /,/)
|
73
|
+
skip /\]/
|
74
|
+
|
75
|
+
create_expression 'array', Elements.new(elms), pos
|
76
|
+
end
|
77
|
+
|
78
|
+
def parse_expr_object
|
79
|
+
log 'parse expr object'
|
80
|
+
|
81
|
+
pos = skip /\{/
|
82
|
+
elms = batch(:parse_expr_object_item, /\}/, /,/)
|
83
|
+
skip /\}/
|
84
|
+
|
85
|
+
create_expression 'object', Elements.new(elms), pos
|
86
|
+
end
|
87
|
+
|
88
|
+
def parse_expr_object_item
|
89
|
+
log 'parse expr object item'
|
90
|
+
|
91
|
+
name = if check R_STRING
|
92
|
+
parse_expr_literal_string
|
93
|
+
elsif check R_NUMBERIC
|
94
|
+
parse_expr_literal_number
|
95
|
+
else
|
96
|
+
parse_expr_identifier
|
97
|
+
end
|
98
|
+
|
99
|
+
skip /:/
|
100
|
+
value = parse_expr_assignment
|
101
|
+
|
102
|
+
Expression.new ':', name, value
|
103
|
+
end
|
104
|
+
|
105
|
+
def parse_expr_identifier
|
106
|
+
log 'parse expr identifier'
|
107
|
+
|
108
|
+
id = scan(R_IDENTIFY)
|
109
|
+
RESERVED_WORDS.include?(id.text) ?
|
110
|
+
parse_error("identifier can not be reserved word: #{id}") : id
|
111
|
+
|
112
|
+
create_expression 'id', id
|
113
|
+
end
|
114
|
+
|
115
|
+
def parse_expr_literal_this_null_boolean
|
116
|
+
log 'parse expr literal this null boolean'
|
117
|
+
expr = scan /this|null|true|false/
|
118
|
+
type = expr.text.gsub(/true|false/, 'boolean')
|
119
|
+
|
120
|
+
create_expression type, expr
|
121
|
+
end
|
122
|
+
|
123
|
+
def parse_expr_literal_string
|
124
|
+
log 'parse expr literal string'
|
125
|
+
|
126
|
+
expr = if check /'/
|
127
|
+
scan /'(?:(?:\\')|(?:\\\n)|[^'\n])*'/
|
128
|
+
elsif check /"/
|
129
|
+
scan /"(?:(?:\\")|(?:\\\n)|[^"\n])*"/
|
130
|
+
else
|
131
|
+
raise 'assert false'
|
132
|
+
end
|
133
|
+
|
134
|
+
create_expression 'string', expr
|
135
|
+
end
|
136
|
+
|
137
|
+
def parse_expr_literal_hex
|
138
|
+
log 'parse expr literal hex'
|
139
|
+
expr = scan /0[xX][0-9a-fA-F]+/
|
140
|
+
create_expression 'number', expr
|
141
|
+
end
|
142
|
+
|
143
|
+
def parse_expr_literal_number
|
144
|
+
log 'parse expr literal number'
|
145
|
+
expr = scan /[+-]?(?:(?:\d*[.]\d+)|(?:\d+))(?:[eE][+-]?\d+)?/
|
146
|
+
create_expression 'number', expr
|
147
|
+
end
|
148
|
+
|
149
|
+
def parse_expr_literal_regexp
|
150
|
+
log 'parse expr literal regexp'
|
151
|
+
expr = scan %r{/(?:(?:\\.)|(?:\[(?:\\.|[^\[\]])+\])|[^/\\])+/[a-z]*}
|
152
|
+
create_expression 'regexp', expr
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
156
|
+
|
157
|
+
def create_expression(*args)
|
158
|
+
expr = PrimaryExpression.new *args
|
159
|
+
log " #{expr}"
|
160
|
+
expr
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -1,22 +1,23 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'fdlint/parser/base_parser'
|
2
|
+
require 'fdlint/parser/js/struct'
|
3
|
+
require 'fdlint/parser/js/expr/expr'
|
4
|
+
require 'fdlint/parser/js/stat/stat'
|
3
5
|
|
4
|
-
require_relative 'expr/expr'
|
5
|
-
require_relative 'stat/stat'
|
6
6
|
|
7
|
+
module Fdlint; module Parser
|
7
8
|
|
8
|
-
module XRay
|
9
9
|
module JS
|
10
10
|
|
11
|
-
class
|
11
|
+
class JsParser < Fdlint::Parser::BaseParser
|
12
12
|
|
13
13
|
include Expr::Expr
|
14
14
|
include Stat::Stat
|
15
|
+
include ::Fdlint::Parser::ParserVisitable
|
15
16
|
|
16
17
|
attr_reader :singleline_comments, :mutiline_comments
|
17
18
|
|
18
|
-
def initialize(js
|
19
|
-
super
|
19
|
+
def initialize(js)
|
20
|
+
super
|
20
21
|
@singleline_comments, @mutiline_comments = [], []
|
21
22
|
end
|
22
23
|
|
@@ -113,4 +114,5 @@ module XRay
|
|
113
114
|
end
|
114
115
|
|
115
116
|
end
|
116
|
-
|
117
|
+
|
118
|
+
end; end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Fdlint
|
2
|
+
module Parser
|
3
|
+
module JS
|
4
|
+
module Stat
|
5
|
+
|
6
|
+
module If
|
7
|
+
def parse_stat_if
|
8
|
+
log 'parse stat if'
|
9
|
+
|
10
|
+
pos = skip /if\s*\(/
|
11
|
+
condition = parse_expression
|
12
|
+
skip /\)/
|
13
|
+
|
14
|
+
true_part = parse_statement
|
15
|
+
false_part = if check /else\b/
|
16
|
+
skip /else/
|
17
|
+
parse_statement
|
18
|
+
end
|
19
|
+
|
20
|
+
create_element IfStatement, condition, true_part, false_part, pos
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Fdlint
|
2
|
+
module Parser
|
3
|
+
module JS
|
4
|
+
module Stat
|
5
|
+
|
6
|
+
# 循环语句
|
7
|
+
module Iter
|
8
|
+
|
9
|
+
def parse_stat_dowhile
|
10
|
+
log 'parse stat dowhile'
|
11
|
+
|
12
|
+
pos = skip /do/
|
13
|
+
body = parse_statement
|
14
|
+
|
15
|
+
skip /while\s*\(/
|
16
|
+
condition = parse_expression
|
17
|
+
skip /\)/
|
18
|
+
|
19
|
+
create_element DowhileStatement, body, condition, pos
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_stat_while
|
23
|
+
log 'parse stat while'
|
24
|
+
|
25
|
+
pos = skip /while\s*\(/
|
26
|
+
condition = parse_expression
|
27
|
+
skip /\)/
|
28
|
+
body = parse_statement
|
29
|
+
|
30
|
+
create_element WhileStatement, condition, body, pos
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_stat_for
|
34
|
+
log 'parse stat for'
|
35
|
+
|
36
|
+
pos = skip /for/
|
37
|
+
|
38
|
+
con_pos = skip /\(/
|
39
|
+
first, is_var = parse_stat_for_con_first
|
40
|
+
type, second, third = parse_stat_for_con_other(first, is_var)
|
41
|
+
skip /\)/
|
42
|
+
|
43
|
+
condition = create_element ForConditionElement, type, first, second, third, con_pos
|
44
|
+
body = parse_statement
|
45
|
+
create_element ForStatement, condition, body, pos
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def parse_stat_for_con_first
|
51
|
+
self.expr_operate_not_in = true
|
52
|
+
first = if check /var\b/
|
53
|
+
skip /var/
|
54
|
+
is_var = true
|
55
|
+
parse_stat_var_declarationlist
|
56
|
+
elsif !check(/;/)
|
57
|
+
parse_expression
|
58
|
+
end
|
59
|
+
self.expr_operate_not_in = false
|
60
|
+
[first, is_var]
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_stat_for_con_other(first, is_var)
|
64
|
+
if check /in\b/
|
65
|
+
if is_var && first.length != 1 || !is_var && !first.left_hand?
|
66
|
+
parse_error('first expression of for-condtion error')
|
67
|
+
end
|
68
|
+
|
69
|
+
skip /in/
|
70
|
+
type = is_var ? 'forvarin' : 'forin'
|
71
|
+
second = parse_expression
|
72
|
+
else
|
73
|
+
skip /;/
|
74
|
+
type = is_var ? 'forvar' : 'fordefault'
|
75
|
+
second = check(/;/) ? nil : parse_expression
|
76
|
+
skip /;/
|
77
|
+
|
78
|
+
third = check(/\)/) ? nil : parse_expression
|
79
|
+
end
|
80
|
+
[type, second, third]
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require_relative 'var'
|
2
|
+
require_relative 'if'
|
3
|
+
require_relative 'switch'
|
4
|
+
require_relative 'iter'
|
5
|
+
require_relative 'try'
|
6
|
+
|
7
|
+
module Fdlint
|
8
|
+
module Parser
|
9
|
+
module JS
|
10
|
+
module Stat
|
11
|
+
|
12
|
+
# Stat : Statement node.
|
13
|
+
module Stat
|
14
|
+
|
15
|
+
include Var, If, Switch, Iter, Try
|
16
|
+
|
17
|
+
def parse_statement
|
18
|
+
# 在ruby-1.8下map是无序的,所以这里只能用数组来实现
|
19
|
+
map = [
|
20
|
+
/\{/, 'block',
|
21
|
+
/\;/, 'empty',
|
22
|
+
/var\b/, 'var',
|
23
|
+
/if\b/, 'if',
|
24
|
+
/switch\b/, 'switch',
|
25
|
+
/do\b/, 'dowhile',
|
26
|
+
/while\b/, 'while',
|
27
|
+
/for\b/, 'for',
|
28
|
+
/continue\b/, 'continue',
|
29
|
+
/break\b/, 'break',
|
30
|
+
/return\b/, 'return',
|
31
|
+
/throw\b/, 'throw',
|
32
|
+
/try\b/, 'try',
|
33
|
+
/./, 'expression'
|
34
|
+
]
|
35
|
+
|
36
|
+
0.upto(map.size / 2 - 1) do |i|
|
37
|
+
if check(map[i * 2])
|
38
|
+
return self.send('parse_stat_' + map[i * 2 + 1])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse_stat_block
|
44
|
+
log 'parse stat block'
|
45
|
+
|
46
|
+
pos = skip /\{/
|
47
|
+
stats = batch(:parse_statement, /\}/)
|
48
|
+
skip /\}/
|
49
|
+
|
50
|
+
create_element BlockStatement, Elements.new(stats), pos
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_stat_empty
|
54
|
+
log 'parse stat empty'
|
55
|
+
pos = skip /;/
|
56
|
+
|
57
|
+
stat = create_element Statement, 'empty'
|
58
|
+
stat.end_with_semicolon = true
|
59
|
+
stat
|
60
|
+
end
|
61
|
+
|
62
|
+
def parse_stat_expression
|
63
|
+
log 'parse stat expression'
|
64
|
+
|
65
|
+
expr = parse_expression
|
66
|
+
stat = create_element ExpressionStatement, expr
|
67
|
+
after_parse_statement stat
|
68
|
+
end
|
69
|
+
|
70
|
+
def parse_stat_continue
|
71
|
+
log 'parse stat continue'
|
72
|
+
parse_stat_simple /continue/, :parse_expr_identifier
|
73
|
+
end
|
74
|
+
|
75
|
+
def parse_stat_break
|
76
|
+
log 'parse stat break'
|
77
|
+
parse_stat_simple /break/, :parse_expr_identifier
|
78
|
+
end
|
79
|
+
|
80
|
+
def parse_stat_return
|
81
|
+
log 'parse stat return'
|
82
|
+
parse_stat_simple /return/, :parse_expression
|
83
|
+
end
|
84
|
+
|
85
|
+
def parse_stat_throw
|
86
|
+
log 'parse stat throw'
|
87
|
+
parse_stat_simple /throw/, :parse_expression
|
88
|
+
end
|
89
|
+
|
90
|
+
def parse_stat_label
|
91
|
+
log 'parse stat label'
|
92
|
+
raise 'not impelments'
|
93
|
+
end
|
94
|
+
|
95
|
+
def after_parse_statement(stat)
|
96
|
+
skip /[ \t]*/, true
|
97
|
+
colon = !!check(/;/, true)
|
98
|
+
stat.end_with_semicolon = colon
|
99
|
+
colon ? skip(/;/, true) :
|
100
|
+
(eos? || check(/\}/)) ? nil : skip(/\n/, true)
|
101
|
+
stat
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def parse_stat_simple(pattern, action)
|
107
|
+
type = scan pattern
|
108
|
+
skip /[ \t]*/, true
|
109
|
+
left = (eos? || check(/[;\n}]/, true)) ? nil : self.send(action)
|
110
|
+
|
111
|
+
stat = create_element Statement, type.text, left, nil, type.position
|
112
|
+
after_parse_statement stat
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Fdlint
|
2
|
+
module Parser
|
3
|
+
module JS
|
4
|
+
module Stat
|
5
|
+
|
6
|
+
module Switch
|
7
|
+
def parse_stat_switch
|
8
|
+
log 'parse stat switch'
|
9
|
+
|
10
|
+
pos = skip /switch\s*\(/
|
11
|
+
expression = parse_expression
|
12
|
+
skip /\)/
|
13
|
+
block = parse_stat_caseblock
|
14
|
+
|
15
|
+
create_element SwitchStatement, expression, block, pos
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_stat_caseblock
|
19
|
+
log 'parse stat caseblock'
|
20
|
+
|
21
|
+
pos = skip /\{/
|
22
|
+
case_clauses = check(/case\b/) ? parse_stat_caseclauses : nil
|
23
|
+
default_clause = check(/default\b/) ? parse_stat_defaultclause : nil
|
24
|
+
bottom_case_clauses = check(/case\b/) ? parse_stat_caseclauses : nil
|
25
|
+
skip /\}/
|
26
|
+
|
27
|
+
create_element CaseBlockStatement, case_clauses, default_clause,
|
28
|
+
bottom_case_clauses, pos
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_stat_caseclauses
|
32
|
+
log 'parse stat caseclauses'
|
33
|
+
stats = batch(:parse_stat_caseclause, /default\b|\}/)
|
34
|
+
create_element Elements, stats
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_stat_caseclause
|
38
|
+
log 'parse stat caseclause'
|
39
|
+
|
40
|
+
pos = skip /case/
|
41
|
+
expr = parse_expression
|
42
|
+
skip /:/
|
43
|
+
stats = parse_statement_list
|
44
|
+
create_element Statement, 'caseclause', expr, stats, pos
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_stat_defaultclause
|
48
|
+
log 'parse stat defaultclause'
|
49
|
+
|
50
|
+
pos = skip /default\s*:/
|
51
|
+
stats = parse_statement_list
|
52
|
+
create_element Statement, 'defaultclause', stats, nil, pos
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def parse_statement_list
|
58
|
+
elms = batch(:parse_statement, /case\b|default\b|\}/)
|
59
|
+
Elements.new elms
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fdlint
|
2
|
+
module Parser
|
3
|
+
module JS
|
4
|
+
module Stat
|
5
|
+
|
6
|
+
module Try
|
7
|
+
def parse_stat_try
|
8
|
+
pos = skip /try/
|
9
|
+
try_part = parse_stat_block
|
10
|
+
|
11
|
+
catch_part = if check /catch\b/
|
12
|
+
catch_pos = skip /catch\s*\(/
|
13
|
+
id = parse_expr_identifier
|
14
|
+
skip /\)/
|
15
|
+
create_element Statement, 'catch', id, parse_stat_block, catch_pos
|
16
|
+
end
|
17
|
+
|
18
|
+
finally_part = if check /finally\b/
|
19
|
+
skip /finally/
|
20
|
+
parse_stat_block
|
21
|
+
end
|
22
|
+
|
23
|
+
create_element TryStatement, try_part, catch_part, finally_part, pos
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Fdlint
|
2
|
+
module Parser
|
3
|
+
module JS
|
4
|
+
module Stat
|
5
|
+
|
6
|
+
module Var
|
7
|
+
def parse_stat_var
|
8
|
+
log 'parse stat var'
|
9
|
+
|
10
|
+
pos = skip /var/
|
11
|
+
|
12
|
+
decs = parse_stat_var_declarationlist
|
13
|
+
stat = create_element VarStatement, decs, pos
|
14
|
+
after_parse_statement stat
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse_stat_var_declarationlist
|
18
|
+
log 'parse stat var declarationlist'
|
19
|
+
decs = []
|
20
|
+
decs << parse_stat_var_declaration
|
21
|
+
while check /,/
|
22
|
+
skip /,/
|
23
|
+
decs << parse_stat_var_declaration
|
24
|
+
end
|
25
|
+
create_element Elements, decs
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_stat_var_declaration
|
29
|
+
log 'parse stat var declaration'
|
30
|
+
name = parse_expr_identifier
|
31
|
+
expr = if check(/\=/)
|
32
|
+
skip /\=/
|
33
|
+
parse_expr_assignment
|
34
|
+
end
|
35
|
+
create_element Statement, 'var=', name, expr
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|