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
data/lib/js/stat/iter.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
module XRay
|
2
|
-
module JS
|
3
|
-
module Stat
|
4
|
-
|
5
|
-
module Iter
|
6
|
-
|
7
|
-
def parse_stat_dowhile
|
8
|
-
log 'parse stat dowhile'
|
9
|
-
|
10
|
-
pos = skip /do/
|
11
|
-
body = parse_statement
|
12
|
-
|
13
|
-
skip /while\s*\(/
|
14
|
-
condition = parse_expression
|
15
|
-
skip /\)/
|
16
|
-
|
17
|
-
create_element DowhileStatement, body, condition, pos
|
18
|
-
end
|
19
|
-
|
20
|
-
def parse_stat_while
|
21
|
-
log 'parse stat while'
|
22
|
-
|
23
|
-
pos = skip /while\s*\(/
|
24
|
-
condition = parse_expression
|
25
|
-
skip /\)/
|
26
|
-
body = parse_statement
|
27
|
-
|
28
|
-
create_element WhileStatement, condition, body, pos
|
29
|
-
end
|
30
|
-
|
31
|
-
def parse_stat_for
|
32
|
-
log 'parse stat for'
|
33
|
-
|
34
|
-
pos = skip /for/
|
35
|
-
|
36
|
-
con_pos = skip /\(/
|
37
|
-
first, is_var = parse_stat_for_con_first
|
38
|
-
type, second, third = parse_stat_for_con_other(first, is_var)
|
39
|
-
skip /\)/
|
40
|
-
|
41
|
-
condition = create_element ForConditionElement, type, first, second, third, con_pos
|
42
|
-
body = parse_statement
|
43
|
-
create_element ForStatement, condition, body, pos
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def parse_stat_for_con_first
|
49
|
-
self.expr_operate_not_in = true
|
50
|
-
first = if check /var\b/
|
51
|
-
skip /var/
|
52
|
-
is_var = true
|
53
|
-
parse_stat_var_declarationlist
|
54
|
-
elsif !check(/;/)
|
55
|
-
parse_expression
|
56
|
-
end
|
57
|
-
self.expr_operate_not_in = false
|
58
|
-
[first, is_var]
|
59
|
-
end
|
60
|
-
|
61
|
-
def parse_stat_for_con_other(first, is_var)
|
62
|
-
if check /in\b/
|
63
|
-
if is_var && first.length != 1 || !is_var && !first.left_hand?
|
64
|
-
parse_error('first expression of for-condtion error')
|
65
|
-
end
|
66
|
-
|
67
|
-
skip /in/
|
68
|
-
type = is_var ? 'forvarin' : 'forin'
|
69
|
-
second = parse_expression
|
70
|
-
else
|
71
|
-
skip /;/
|
72
|
-
type = is_var ? 'forvar' : 'fordefault'
|
73
|
-
second = check(/;/) ? nil : parse_expression
|
74
|
-
skip /;/
|
75
|
-
|
76
|
-
third = check(/\)/) ? nil : parse_expression
|
77
|
-
end
|
78
|
-
[type, second, third]
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
data/lib/js/stat/stat.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
require_relative 'var'
|
2
|
-
require_relative 'if'
|
3
|
-
require_relative 'switch'
|
4
|
-
require_relative 'iter'
|
5
|
-
require_relative 'try'
|
6
|
-
|
7
|
-
module XRay
|
8
|
-
module JS
|
9
|
-
module Stat
|
10
|
-
|
11
|
-
module Stat
|
12
|
-
|
13
|
-
include Var, If, Switch, Iter, Try
|
14
|
-
|
15
|
-
def parse_statement
|
16
|
-
# 在1.8下map是无序的,所以这里只能用数组来实现
|
17
|
-
map = [
|
18
|
-
/\{/, 'block',
|
19
|
-
/\;/, 'empty',
|
20
|
-
/var\b/, 'var',
|
21
|
-
/if\b/, 'if',
|
22
|
-
/switch\b/, 'switch',
|
23
|
-
/do\b/, 'dowhile',
|
24
|
-
/while\b/, 'while',
|
25
|
-
/for\b/, 'for',
|
26
|
-
/continue\b/, 'continue',
|
27
|
-
/break\b/, 'break',
|
28
|
-
/return\b/, 'return',
|
29
|
-
/throw\b/, 'throw',
|
30
|
-
/try\b/, 'try',
|
31
|
-
/./, 'expression'
|
32
|
-
]
|
33
|
-
|
34
|
-
0.upto(map.size / 2 - 1) do |i|
|
35
|
-
if check(map[i * 2])
|
36
|
-
return self.send('parse_stat_' + map[i * 2 + 1])
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def parse_stat_block
|
42
|
-
log 'parse stat block'
|
43
|
-
|
44
|
-
pos = skip /\{/
|
45
|
-
stats = batch(:parse_statement, /\}/)
|
46
|
-
skip /\}/
|
47
|
-
|
48
|
-
create_element BlockStatement, Elements.new(stats), pos
|
49
|
-
end
|
50
|
-
|
51
|
-
def parse_stat_empty
|
52
|
-
log 'parse stat empty'
|
53
|
-
pos = skip /;/
|
54
|
-
|
55
|
-
stat = create_element Statement, 'empty'
|
56
|
-
stat.end_with_semicolon = true
|
57
|
-
stat
|
58
|
-
end
|
59
|
-
|
60
|
-
def parse_stat_expression
|
61
|
-
log 'parse stat expression'
|
62
|
-
|
63
|
-
expr = parse_expression
|
64
|
-
stat = create_element ExpressionStatement, expr
|
65
|
-
after_parse_statement stat
|
66
|
-
end
|
67
|
-
|
68
|
-
def parse_stat_continue
|
69
|
-
log 'parse stat continue'
|
70
|
-
parse_stat_simple /continue/, :parse_expr_identifier
|
71
|
-
end
|
72
|
-
|
73
|
-
def parse_stat_break
|
74
|
-
log 'parse stat break'
|
75
|
-
parse_stat_simple /break/, :parse_expr_identifier
|
76
|
-
end
|
77
|
-
|
78
|
-
def parse_stat_return
|
79
|
-
log 'parse stat return'
|
80
|
-
parse_stat_simple /return/, :parse_expression
|
81
|
-
end
|
82
|
-
|
83
|
-
def parse_stat_throw
|
84
|
-
log 'parse stat throw'
|
85
|
-
parse_stat_simple /throw/, :parse_expression
|
86
|
-
end
|
87
|
-
|
88
|
-
def parse_stat_label
|
89
|
-
log 'parse stat label'
|
90
|
-
raise 'not impelments'
|
91
|
-
end
|
92
|
-
|
93
|
-
def after_parse_statement(stat)
|
94
|
-
skip /[ \t]*/, true
|
95
|
-
colon = !!check(/;/, true)
|
96
|
-
stat.end_with_semicolon = colon
|
97
|
-
colon ? skip(/;/, true) :
|
98
|
-
(eos? || check(/\}/)) ? nil : skip(/\n/, true)
|
99
|
-
stat
|
100
|
-
end
|
101
|
-
|
102
|
-
private
|
103
|
-
|
104
|
-
def parse_stat_simple(pattern, action)
|
105
|
-
type = scan pattern
|
106
|
-
skip /[ \t]*/, true
|
107
|
-
left = (eos? || check(/[;\n}]/, true)) ? nil : self.send(action)
|
108
|
-
|
109
|
-
stat = create_element Statement, type.text, left, nil, type.position
|
110
|
-
after_parse_statement stat
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
data/lib/js/stat/switch.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
module XRay
|
2
|
-
module JS
|
3
|
-
module Stat
|
4
|
-
|
5
|
-
module Switch
|
6
|
-
def parse_stat_switch
|
7
|
-
log 'parse stat switch'
|
8
|
-
|
9
|
-
pos = skip /switch\s*\(/
|
10
|
-
expression = parse_expression
|
11
|
-
skip /\)/
|
12
|
-
block = parse_stat_caseblock
|
13
|
-
|
14
|
-
create_element SwitchStatement, expression, block, pos
|
15
|
-
end
|
16
|
-
|
17
|
-
def parse_stat_caseblock
|
18
|
-
log 'parse stat caseblock'
|
19
|
-
|
20
|
-
pos = skip /\{/
|
21
|
-
case_clauses = check(/case\b/) ? parse_stat_caseclauses : nil
|
22
|
-
default_clause = check(/default\b/) ? parse_stat_defaultclause : nil
|
23
|
-
bottom_case_clauses = check(/case\b/) ? parse_stat_caseclauses : nil
|
24
|
-
skip /\}/
|
25
|
-
|
26
|
-
create_element CaseBlockStatement, case_clauses, default_clause,
|
27
|
-
bottom_case_clauses, pos
|
28
|
-
end
|
29
|
-
|
30
|
-
def parse_stat_caseclauses
|
31
|
-
log 'parse stat caseclauses'
|
32
|
-
stats = batch(:parse_stat_caseclause, /default\b|\}/)
|
33
|
-
create_element Elements, stats
|
34
|
-
end
|
35
|
-
|
36
|
-
def parse_stat_caseclause
|
37
|
-
log 'parse stat caseclause'
|
38
|
-
|
39
|
-
pos = skip /case/
|
40
|
-
expr = parse_expression
|
41
|
-
skip /:/
|
42
|
-
stats = parse_statement_list
|
43
|
-
create_element Statement, 'caseclause', expr, stats, pos
|
44
|
-
end
|
45
|
-
|
46
|
-
def parse_stat_defaultclause
|
47
|
-
log 'parse stat defaultclause'
|
48
|
-
|
49
|
-
pos = skip /default\s*:/
|
50
|
-
stats = parse_statement_list
|
51
|
-
create_element Statement, 'defaultclause', stats, nil, pos
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def parse_statement_list
|
57
|
-
elms = batch(:parse_statement, /case\b|default\b|\}/)
|
58
|
-
Elements.new elms
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/lib/js/stat/try.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module XRay
|
2
|
-
module JS
|
3
|
-
module Stat
|
4
|
-
|
5
|
-
module Try
|
6
|
-
def parse_stat_try
|
7
|
-
pos = skip /try/
|
8
|
-
try_part = parse_stat_block
|
9
|
-
|
10
|
-
catch_part = if check /catch\b/
|
11
|
-
catch_pos = skip /catch\s*\(/
|
12
|
-
id = parse_expr_identifier
|
13
|
-
skip /\)/
|
14
|
-
create_element Statement, 'catch', id, parse_stat_block, catch_pos
|
15
|
-
end
|
16
|
-
|
17
|
-
finally_part = if check /finally\b/
|
18
|
-
skip /finally/
|
19
|
-
parse_stat_block
|
20
|
-
end
|
21
|
-
|
22
|
-
create_element TryStatement, try_part, catch_part, finally_part, pos
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/lib/js/stat/var.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module XRay
|
2
|
-
module JS
|
3
|
-
module Stat
|
4
|
-
|
5
|
-
module Var
|
6
|
-
def parse_stat_var
|
7
|
-
log 'parse stat var'
|
8
|
-
|
9
|
-
pos = skip /var/
|
10
|
-
|
11
|
-
decs = parse_stat_var_declarationlist
|
12
|
-
stat = create_element VarStatement, decs, pos
|
13
|
-
after_parse_statement stat
|
14
|
-
end
|
15
|
-
|
16
|
-
def parse_stat_var_declarationlist
|
17
|
-
log 'parse stat var declarationlist'
|
18
|
-
decs = []
|
19
|
-
decs << parse_stat_var_declaration
|
20
|
-
while check /,/
|
21
|
-
skip /,/
|
22
|
-
decs << parse_stat_var_declaration
|
23
|
-
end
|
24
|
-
create_element Elements, decs
|
25
|
-
end
|
26
|
-
|
27
|
-
def parse_stat_var_declaration
|
28
|
-
log 'parse stat var declaration'
|
29
|
-
name = parse_expr_identifier
|
30
|
-
expr = if check(/\=/)
|
31
|
-
skip /\=/
|
32
|
-
parse_expr_assignment
|
33
|
-
end
|
34
|
-
create_element Statement, 'var=', name, expr
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/js/struct.rb
DELETED
@@ -1,248 +0,0 @@
|
|
1
|
-
require_relative '../node'
|
2
|
-
|
3
|
-
module XRay
|
4
|
-
module JS
|
5
|
-
Node = XRay::Node
|
6
|
-
|
7
|
-
class Element < Node
|
8
|
-
attr_reader :type, :left, :right
|
9
|
-
|
10
|
-
def initialize(type, left = nil, right = nil, position = nil)
|
11
|
-
@type, @left, @right, @position = type, left, right, position
|
12
|
-
end
|
13
|
-
|
14
|
-
def text
|
15
|
-
"(#{type},#{left},#{right})"
|
16
|
-
end
|
17
|
-
|
18
|
-
def position
|
19
|
-
@position ? @position :
|
20
|
-
left ? left.position :
|
21
|
-
right ? right.position : nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def contains?(target)
|
25
|
-
return true if target == @type
|
26
|
-
left && left.respond_to?(:contains?) && left.contains?(target) or
|
27
|
-
right && right.respond_to?(:contains?) && right.contains?(target)
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
class Elements < Node
|
33
|
-
attr_reader :elements, :type
|
34
|
-
|
35
|
-
def initialize(elements, position = nil)
|
36
|
-
@elements, @position = elements, position
|
37
|
-
@type = 'elements'
|
38
|
-
end
|
39
|
-
|
40
|
-
def text
|
41
|
-
"[#{elements.collect(&:text).join(',')}]"
|
42
|
-
end
|
43
|
-
|
44
|
-
def position
|
45
|
-
@position ? @position :
|
46
|
-
elements.empty? ? nil : elements[0].position
|
47
|
-
end
|
48
|
-
|
49
|
-
def method_missing(m, *args, &block)
|
50
|
-
@elements.send m, *args, &block
|
51
|
-
end
|
52
|
-
|
53
|
-
def contains?( target )
|
54
|
-
@elements.any? {|elm| elm.contains? target }
|
55
|
-
end
|
56
|
-
|
57
|
-
alias :contain? :contains?
|
58
|
-
end
|
59
|
-
|
60
|
-
class Program < Element
|
61
|
-
alias :elements :left
|
62
|
-
|
63
|
-
def initialize(elements)
|
64
|
-
super 'program', elements
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
class FunctionDeclaraion < Element
|
70
|
-
attr_reader :body
|
71
|
-
alias :name :left
|
72
|
-
alias :parameters :right
|
73
|
-
|
74
|
-
def initialize(name, parameters, body, pos)
|
75
|
-
super 'function', name, parameters, pos
|
76
|
-
@body = body
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class Statement < Element
|
81
|
-
|
82
|
-
def end_with_semicolon=(end_with_semicolon)
|
83
|
-
@end_with_semicolon = !!end_with_semicolon
|
84
|
-
end
|
85
|
-
|
86
|
-
def end_with_semicolon?
|
87
|
-
@end_with_semicolon || false
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
class VarStatement < Statement
|
93
|
-
alias :declarations :left
|
94
|
-
|
95
|
-
def initialize(declarations, position)
|
96
|
-
super 'var', declarations, nil, position
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
class BlockStatement < Statement
|
101
|
-
alias :elements :left
|
102
|
-
|
103
|
-
def initialize(elements, pos)
|
104
|
-
super 'block', elements, nil, pos
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class IfStatement < Statement
|
109
|
-
attr_reader :false_part
|
110
|
-
alias :condition :left
|
111
|
-
alias :true_part :right
|
112
|
-
|
113
|
-
def initialize(condition, true_part, false_part, position)
|
114
|
-
super 'if', condition, true_part, position
|
115
|
-
@false_part = false_part
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
class SwitchStatement < Statement
|
120
|
-
alias :expression :left
|
121
|
-
alias :case_block :right
|
122
|
-
|
123
|
-
def initialize(expression, case_block, position)
|
124
|
-
super 'switch', expression, case_block, position
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
class CaseBlockStatement < Statement
|
129
|
-
attr_reader :bottom_case_clauses
|
130
|
-
alias :case_clauses :left
|
131
|
-
alias :default_clause :right
|
132
|
-
|
133
|
-
def initialize(case_clauses, default_clause, bottom_case_clauses, position)
|
134
|
-
super 'caseblock', case_clauses, default_clause, position
|
135
|
-
@bottom_case_clauses = bottom_case_clauses
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
class DowhileStatement < Statement
|
140
|
-
alias :body :left
|
141
|
-
alias :condition :right
|
142
|
-
|
143
|
-
def initialize(body, condition, pos)
|
144
|
-
super 'dowhile', body, condition, pos
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
class WhileStatement < Statement
|
149
|
-
alias :condition :left
|
150
|
-
alias :body :right
|
151
|
-
|
152
|
-
def initialize(condition, body, pos)
|
153
|
-
super 'while', condition, body, pos
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
class ForStatement < Statement
|
158
|
-
alias :condition :left
|
159
|
-
alias :body :right
|
160
|
-
|
161
|
-
def initialize(condition, body, pos)
|
162
|
-
super 'for', condition, body, pos
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
class ForConditionElement < Element
|
167
|
-
attr_reader :third
|
168
|
-
alias :first :left
|
169
|
-
alias :second :right
|
170
|
-
|
171
|
-
def initialize(type, first, second, third, pos)
|
172
|
-
super type, first, second
|
173
|
-
@third = third
|
174
|
-
end
|
175
|
-
|
176
|
-
end
|
177
|
-
|
178
|
-
class TryStatement < Statement
|
179
|
-
attr_reader :finally_part
|
180
|
-
alias :try_part :left
|
181
|
-
alias :catch_part :right
|
182
|
-
|
183
|
-
def initialize(try_part, catch_part, finally_part, pos)
|
184
|
-
super 'try', try_part, catch_part, pos
|
185
|
-
@finally_part = finally_part
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
class ExpressionStatement < Statement
|
190
|
-
alias :expression :left
|
191
|
-
|
192
|
-
def initialize(expression)
|
193
|
-
super 'expression', expression
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
class Expression < Element
|
198
|
-
def left_hand?
|
199
|
-
@left_hand || false
|
200
|
-
end
|
201
|
-
|
202
|
-
def left_hand=(left_hand)
|
203
|
-
@left_hand = left_hand
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
class PrimaryExpression < Expression
|
208
|
-
|
209
|
-
def initialize(type, expr, position = nil)
|
210
|
-
super type, expr, nil, position
|
211
|
-
end
|
212
|
-
|
213
|
-
def text
|
214
|
-
node.text
|
215
|
-
end
|
216
|
-
|
217
|
-
def node
|
218
|
-
left
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
class ConditionExpression < Expression
|
223
|
-
attr_reader :condition
|
224
|
-
|
225
|
-
def initialize(condition, left, right)
|
226
|
-
super '?:', left, right, condition.position
|
227
|
-
@condition = condition
|
228
|
-
end
|
229
|
-
|
230
|
-
def text
|
231
|
-
"(#{type},#{condition},#{left},#{right})"
|
232
|
-
end
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
|
-
class FunctionExpression < Expression
|
237
|
-
attr_reader :body
|
238
|
-
alias :name :left
|
239
|
-
alias :parameters :right
|
240
|
-
|
241
|
-
def initialize(func)
|
242
|
-
super 'function', func.name, func.parameters, func.position
|
243
|
-
@body = func.body
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
end
|
248
|
-
end
|
data/lib/log_entry.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require_relative 'helper/color_string'
|
2
|
-
|
3
|
-
module XRay
|
4
|
-
|
5
|
-
LogEntry = Struct.new(:message, :level, :row, :column)
|
6
|
-
|
7
|
-
class LogEntry
|
8
|
-
|
9
|
-
def initialize(message, level, row = 0, colmn = 0)
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_s
|
14
|
-
pos = row.nil? ? "" : "[#{row},#{column}]"
|
15
|
-
"[#{level.to_s.upcase}] #{pos} #{message}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_color_s
|
19
|
-
t = self.to_s
|
20
|
-
if warn?
|
21
|
-
t.yellow
|
22
|
-
elsif fatal?
|
23
|
-
t.white.red_bg
|
24
|
-
elsif error?
|
25
|
-
t.red
|
26
|
-
else
|
27
|
-
t
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def error?
|
32
|
-
level == :error
|
33
|
-
end
|
34
|
-
|
35
|
-
def warn?
|
36
|
-
level == :warn
|
37
|
-
end
|
38
|
-
|
39
|
-
def fatal?
|
40
|
-
level == :fatal
|
41
|
-
end
|
42
|
-
|
43
|
-
def info?
|
44
|
-
level == :info
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
data/lib/node.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require_relative 'context'
|
2
|
-
|
3
|
-
module XRay
|
4
|
-
|
5
|
-
class Node
|
6
|
-
|
7
|
-
attr_accessor :text, :position
|
8
|
-
|
9
|
-
def initialize(text = '', position = nil)
|
10
|
-
|
11
|
-
if text.is_a? Node
|
12
|
-
@text, @position = text.text, text.position
|
13
|
-
else
|
14
|
-
@text, @position = (text || '').strip, position
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def =~(other)
|
19
|
-
text =~ other
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_s
|
23
|
-
text
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|