template-ruby-parser 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/code-ruby-parser.gemspec +3 -1
- data/lib/code-ruby-parser.rb +1 -7
- data/lib/template-ruby-parser.rb +1 -7
- data/template-ruby-parser.gemspec +3 -1
- metadata +18 -137
- data/.overcommit.yml +0 -4
- data/CHANGELOG.md +0 -31
- data/Gemfile +0 -5
- data/Gemfile.lock +0 -32
- data/bin/code-parser +0 -27
- data/bin/deploy +0 -16
- data/bin/format +0 -3
- data/bin/parse-docs +0 -6
- data/bin/template-parser +0 -27
- data/docs/class.code +0 -9
- data/docs/meetup.code +0 -14
- data/docs/precedence.code +0 -1
- data/docs/precedence.template +0 -35
- data/docs/rain.code +0 -23
- data/docs/slack.code +0 -17
- data/docs/stripe.code +0 -7
- data/docs/twitter.code +0 -7
- data/lib/code/parser/addition.rb +0 -13
- data/lib/code/parser/and_operator.rb +0 -13
- data/lib/code/parser/bitwise_and.rb +0 -13
- data/lib/code/parser/bitwise_or.rb +0 -13
- data/lib/code/parser/boolean.rb +0 -13
- data/lib/code/parser/call.rb +0 -183
- data/lib/code/parser/chained_call.rb +0 -41
- data/lib/code/parser/class.rb +0 -55
- data/lib/code/parser/code.rb +0 -20
- data/lib/code/parser/comments.rb +0 -46
- data/lib/code/parser/dictionnary.rb +0 -52
- data/lib/code/parser/equal.rb +0 -68
- data/lib/code/parser/equality.rb +0 -20
- data/lib/code/parser/error/syntax_error.rb +0 -36
- data/lib/code/parser/error.rb +0 -6
- data/lib/code/parser/function.rb +0 -118
- data/lib/code/parser/greater_than.rb +0 -13
- data/lib/code/parser/group.rb +0 -15
- data/lib/code/parser/if.rb +0 -81
- data/lib/code/parser/if_modifier.rb +0 -39
- data/lib/code/parser/list.rb +0 -20
- data/lib/code/parser/multiplication.rb +0 -13
- data/lib/code/parser/name.rb +0 -14
- data/lib/code/parser/negation.rb +0 -18
- data/lib/code/parser/not_keyword.rb +0 -26
- data/lib/code/parser/nothing.rb +0 -13
- data/lib/code/parser/number.rb +0 -39
- data/lib/code/parser/operation.rb +0 -65
- data/lib/code/parser/or_keyword.rb +0 -13
- data/lib/code/parser/or_operator.rb +0 -13
- data/lib/code/parser/power.rb +0 -33
- data/lib/code/parser/range.rb +0 -13
- data/lib/code/parser/rescue.rb +0 -38
- data/lib/code/parser/shift.rb +0 -13
- data/lib/code/parser/splat.rb +0 -35
- data/lib/code/parser/statement.rb +0 -9
- data/lib/code/parser/string.rb +0 -62
- data/lib/code/parser/ternary.rb +0 -73
- data/lib/code/parser/unary_minus.rb +0 -23
- data/lib/code/parser/while.rb +0 -36
- data/lib/code/parser.rb +0 -237
- data/lib/code.rb +0 -2
- data/lib/template/parser.rb +0 -32
- data/lib/template.rb +0 -2
- data/spec/code/parser/addition_spec.rb +0 -26
- data/spec/code/parser/and_operator_spec.rb +0 -26
- data/spec/code/parser/bitwise_and_spec.rb +0 -26
- data/spec/code/parser/bitwise_or_spec.rb +0 -26
- data/spec/code/parser/boolean_spec.rb +0 -13
- data/spec/code/parser/call_spec.rb +0 -52
- data/spec/code/parser/chained_call_spec.rb +0 -33
- data/spec/code/parser/class_spec.rb +0 -32
- data/spec/code/parser/code_spec.rb +0 -13
- data/spec/code/parser/dictionnary_spec.rb +0 -40
- data/spec/code/parser/equal_spec.rb +0 -42
- data/spec/code/parser/equality_spec.rb +0 -26
- data/spec/code/parser/function_spec.rb +0 -43
- data/spec/code/parser/greater_than_spec.rb +0 -26
- data/spec/code/parser/group_spec.rb +0 -13
- data/spec/code/parser/if_modifier_spec.rb +0 -26
- data/spec/code/parser/if_spec.rb +0 -39
- data/spec/code/parser/list_spec.rb +0 -27
- data/spec/code/parser/multiplication_spec.rb +0 -26
- data/spec/code/parser/negation_spec.rb +0 -13
- data/spec/code/parser/not_keyword_spec.rb +0 -21
- data/spec/code/parser/nothing_spec.rb +0 -20
- data/spec/code/parser/number_spec.rb +0 -24
- data/spec/code/parser/or_keyword_spec.rb +0 -26
- data/spec/code/parser/or_operator_spec.rb +0 -26
- data/spec/code/parser/power_spec.rb +0 -21
- data/spec/code/parser/range_spec.rb +0 -21
- data/spec/code/parser/rescue_spec.rb +0 -26
- data/spec/code/parser/shift_spec.rb +0 -26
- data/spec/code/parser/string_spec.rb +0 -28
- data/spec/code/parser/ternary_spec.rb +0 -26
- data/spec/code/parser/unary_minus_spec.rb +0 -21
- data/spec/code/parser/while_spec.rb +0 -32
- data/spec/code/parser_spec.rb +0 -13
- data/spec/spec_helper.rb +0 -6
- data/spec/template/parser_spec.rb +0 -13
data/lib/code/parser/while.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
class Code
|
2
|
-
class Parser
|
3
|
-
class While < ::Code::Parser
|
4
|
-
def parse
|
5
|
-
if operator = match([WHILE_KEYWORD, UNTIL_KEYWORD])
|
6
|
-
previous_cursor = cursor
|
7
|
-
|
8
|
-
comments = parse_comments
|
9
|
-
|
10
|
-
condition = parse_subclass(::Code::Parser::While)
|
11
|
-
|
12
|
-
if condition
|
13
|
-
body = parse_code
|
14
|
-
|
15
|
-
match(END_KEYWORD)
|
16
|
-
|
17
|
-
{
|
18
|
-
while: {
|
19
|
-
operator: operator,
|
20
|
-
comments: comments,
|
21
|
-
condition: condition,
|
22
|
-
body: body
|
23
|
-
}.compact
|
24
|
-
}
|
25
|
-
else
|
26
|
-
@cursor = previous_cursor
|
27
|
-
buffer!
|
28
|
-
parse_subclass(::Code::Parser::If)
|
29
|
-
end
|
30
|
-
else
|
31
|
-
parse_subclass(::Code::Parser::If)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/code/parser.rb
DELETED
@@ -1,237 +0,0 @@
|
|
1
|
-
class Code
|
2
|
-
class Parser
|
3
|
-
attr_accessor :input, :cursor, :buffer
|
4
|
-
|
5
|
-
EMPTY_STRING = ""
|
6
|
-
|
7
|
-
DIGITS = %w[0 1 2 3 4 5 6 7 8 9]
|
8
|
-
NON_ZERO_DIGITS = %w[1 2 3 4 5 6 7 8 9]
|
9
|
-
|
10
|
-
X = "x"
|
11
|
-
O = "o"
|
12
|
-
B = "b"
|
13
|
-
|
14
|
-
SINGLE_QUOTE = "'"
|
15
|
-
DOUBLE_QUOTE = '"'
|
16
|
-
OPENING_CURLY_BRACKET = "{"
|
17
|
-
CLOSING_CURLY_BRACKET = "}"
|
18
|
-
OPENING_SQUARE_BRACKET = "["
|
19
|
-
CLOSING_SQUARE_BRACKET = "]"
|
20
|
-
OPENING_PARENTHESIS = "("
|
21
|
-
CLOSING_PARENTHESIS = ")"
|
22
|
-
DOT = "."
|
23
|
-
BACKSLASH = "\\"
|
24
|
-
COMMA = ","
|
25
|
-
SPACE = " "
|
26
|
-
SLASH = "/"
|
27
|
-
ASTERISK = "*"
|
28
|
-
NEWLINE = "\n"
|
29
|
-
HASH = "#"
|
30
|
-
COLON = ":"
|
31
|
-
EQUAL = "="
|
32
|
-
GREATER = ">"
|
33
|
-
LESSER = "<"
|
34
|
-
AMPERSAND = "&"
|
35
|
-
PIPE = "|"
|
36
|
-
UNDERSCORE = "_"
|
37
|
-
EXCLAMATION_POINT = "!"
|
38
|
-
QUESTION_MARK = "?"
|
39
|
-
MINUS = "-"
|
40
|
-
PLUS = "+"
|
41
|
-
PERCENT = "%"
|
42
|
-
CARET = "^"
|
43
|
-
TILDE = "~"
|
44
|
-
|
45
|
-
EQUALS = [
|
46
|
-
EQUAL,
|
47
|
-
PLUS + EQUAL,
|
48
|
-
MINUS + EQUAL,
|
49
|
-
ASTERISK + EQUAL,
|
50
|
-
SLASH + EQUAL,
|
51
|
-
PERCENT + EQUAL,
|
52
|
-
GREATER + GREATER + EQUAL,
|
53
|
-
LESSER + LESSER + EQUAL,
|
54
|
-
AMPERSAND + EQUAL,
|
55
|
-
PIPE + EQUAL,
|
56
|
-
CARET + EQUAL,
|
57
|
-
PIPE + PIPE + EQUAL,
|
58
|
-
AMPERSAND + AMPERSAND + EQUAL
|
59
|
-
]
|
60
|
-
|
61
|
-
WHITESPACE = [SPACE, NEWLINE]
|
62
|
-
|
63
|
-
SPECIAL_NEWLINE = "\\n"
|
64
|
-
SPECIAL_NEWLINE_ESCAPED = "\n"
|
65
|
-
|
66
|
-
NOTHING_KEYWORD = "nothing"
|
67
|
-
NULL_KEYWORD = "null"
|
68
|
-
NIL_KEYWORD = "nil"
|
69
|
-
TRUE_KEYWORD = "true"
|
70
|
-
FALSE_KEYWORD = "false"
|
71
|
-
DO_KEYWORD = "do"
|
72
|
-
END_KEYWORD = "end"
|
73
|
-
RESCUE_KEYWORD = "rescue"
|
74
|
-
NOT_KEYWORD = "not"
|
75
|
-
OR_KEYWORD = "or"
|
76
|
-
AND_KEYWORD = "and"
|
77
|
-
IF_KEYWORD = "if"
|
78
|
-
UNLESS_KEYWORD = "unless"
|
79
|
-
ELSE_KEYWORD = "else"
|
80
|
-
ELSIF_KEYWORD = "elsif"
|
81
|
-
ELSUNLESS_KEYWORD = "elsunless"
|
82
|
-
WHILE_KEYWORD = "while"
|
83
|
-
UNTIL_KEYWORD = "until"
|
84
|
-
CLASS_KEYWORD = "class"
|
85
|
-
|
86
|
-
NOTHING_KEYWORDS = [NOTHING_KEYWORD, NULL_KEYWORD, NIL_KEYWORD]
|
87
|
-
BOOLEAN_KEYWORDS = [TRUE_KEYWORD, FALSE_KEYWORD]
|
88
|
-
KEYWORDS =
|
89
|
-
NOTHING_KEYWORDS + BOOLEAN_KEYWORDS +
|
90
|
-
[
|
91
|
-
DO_KEYWORD, END_KEYWORD, RESCUE_KEYWORD, NOT_KEYWORD, OR_KEYWORD,
|
92
|
-
AND_KEYWORD, IF_KEYWORD, UNLESS_KEYWORD, ELSE_KEYWORD, ELSIF_KEYWORD,
|
93
|
-
ELSUNLESS_KEYWORD, WHILE_KEYWORD, UNTIL_KEYWORD, CLASS_KEYWORD
|
94
|
-
]
|
95
|
-
|
96
|
-
SPECIAL = [
|
97
|
-
SINGLE_QUOTE, DOUBLE_QUOTE, OPENING_CURLY_BRACKET, CLOSING_CURLY_BRACKET,
|
98
|
-
OPENING_SQUARE_BRACKET, CLOSING_SQUARE_BRACKET, BACKSLASH, DOT, COMMA,
|
99
|
-
SPACE, SLASH, ASTERISK, NEWLINE, HASH, COLON, EQUAL, GREATER, LESSER,
|
100
|
-
OPENING_PARENTHESIS, CLOSING_PARENTHESIS, AMPERSAND, PIPE,
|
101
|
-
EXCLAMATION_POINT, QUESTION_MARK, MINUS, PLUS, TILDE
|
102
|
-
]
|
103
|
-
|
104
|
-
def initialize(
|
105
|
-
input,
|
106
|
-
cursor: 0,
|
107
|
-
buffer: EMPTY_STRING,
|
108
|
-
check_end_of_input: true
|
109
|
-
)
|
110
|
-
@input = input
|
111
|
-
@cursor = cursor
|
112
|
-
@buffer = buffer
|
113
|
-
@check_end_of_input = check_end_of_input
|
114
|
-
end
|
115
|
-
|
116
|
-
def self.parse(input)
|
117
|
-
new(input).parse
|
118
|
-
end
|
119
|
-
|
120
|
-
def parse
|
121
|
-
output = parse_subclass(::Code::Parser::Code)
|
122
|
-
|
123
|
-
if check_end_of_input && cursor != input.size
|
124
|
-
syntax_error("Unexpected end of input")
|
125
|
-
end
|
126
|
-
|
127
|
-
output
|
128
|
-
end
|
129
|
-
|
130
|
-
private
|
131
|
-
|
132
|
-
attr_reader :check_end_of_input
|
133
|
-
|
134
|
-
def syntax_error(message)
|
135
|
-
raise(
|
136
|
-
::Code::Parser::Error::SyntaxError.new(
|
137
|
-
message,
|
138
|
-
input: input,
|
139
|
-
line: line,
|
140
|
-
column: column,
|
141
|
-
offset_lines: offset_lines,
|
142
|
-
offset_columns: offset_columns
|
143
|
-
)
|
144
|
-
)
|
145
|
-
end
|
146
|
-
|
147
|
-
def line
|
148
|
-
input[0...cursor].count("\n")
|
149
|
-
end
|
150
|
-
|
151
|
-
def column
|
152
|
-
cursor - input.lines[0...line].map(&:size).sum
|
153
|
-
end
|
154
|
-
|
155
|
-
def offset_lines
|
156
|
-
buffer.count("\n")
|
157
|
-
end
|
158
|
-
|
159
|
-
def offset_columns
|
160
|
-
buffer.size + 1
|
161
|
-
end
|
162
|
-
|
163
|
-
def consume(n = 1)
|
164
|
-
if cursor + n <= input.size
|
165
|
-
consumed = input[cursor, n]
|
166
|
-
@buffer += input[cursor, n]
|
167
|
-
@cursor += n
|
168
|
-
consumed
|
169
|
-
else
|
170
|
-
syntax_error("Unexpected end of input")
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def add(output)
|
175
|
-
@output << output if output
|
176
|
-
output
|
177
|
-
end
|
178
|
-
|
179
|
-
def next?(expected)
|
180
|
-
if expected.is_a?(Array)
|
181
|
-
expected.any? { |e| input[cursor, e.size] == e }
|
182
|
-
else
|
183
|
-
input[cursor, expected.size] == expected
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
def next_next?(expected)
|
188
|
-
if expected.is_a?(Array)
|
189
|
-
expected.any? { |e| next_next?(e) }
|
190
|
-
else
|
191
|
-
input[cursor + 1, expected.size] == expected
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
def match(expected)
|
196
|
-
if expected.is_a?(Array)
|
197
|
-
expected.detect { |e| match(e) }
|
198
|
-
else
|
199
|
-
if input[cursor, expected.size] == expected
|
200
|
-
@buffer += expected
|
201
|
-
@cursor += expected.size
|
202
|
-
expected
|
203
|
-
else
|
204
|
-
false
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
def parse_subclass(subclass, **kargs)
|
210
|
-
parser =
|
211
|
-
subclass.new(input, cursor: cursor, check_end_of_input: false, **kargs)
|
212
|
-
output = parser.parse
|
213
|
-
@cursor = parser.cursor
|
214
|
-
output
|
215
|
-
end
|
216
|
-
|
217
|
-
def parse_code
|
218
|
-
parse_subclass(::Code::Parser::Code)
|
219
|
-
end
|
220
|
-
|
221
|
-
def parse_comments(whitespace: WHITESPACE)
|
222
|
-
parse_subclass(::Code::Parser::Comments, whitespace: whitespace)
|
223
|
-
end
|
224
|
-
|
225
|
-
def end_of_input?
|
226
|
-
cursor >= input.size
|
227
|
-
end
|
228
|
-
|
229
|
-
def buffer?
|
230
|
-
buffer != EMPTY_STRING
|
231
|
-
end
|
232
|
-
|
233
|
-
def buffer!
|
234
|
-
buffer.tap { @buffer = EMPTY_STRING }
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
data/lib/code.rb
DELETED
data/lib/template/parser.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
class Template
|
2
|
-
class Parser < ::Code::Parser
|
3
|
-
Version = Gem::Version.new("0.1.7")
|
4
|
-
|
5
|
-
def parse
|
6
|
-
parts = []
|
7
|
-
|
8
|
-
while !end_of_input?
|
9
|
-
c = consume
|
10
|
-
|
11
|
-
if c == OPENING_CURLY_BRACKET
|
12
|
-
parts << { text: escape(buffer!) } if buffer?
|
13
|
-
parts << { code: parse_code }
|
14
|
-
match(CLOSING_CURLY_BRACKET)
|
15
|
-
buffer!
|
16
|
-
elsif c == BACKSLASH
|
17
|
-
match(OPENING_CURLY_BRACKET)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
parts << { text: escape(buffer!) } if buffer?
|
22
|
-
|
23
|
-
parts
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def escape(text)
|
29
|
-
text.gsub(BACKSLASH + OPENING_CURLY_BRACKET, OPENING_CURLY_BRACKET)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/template.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe ::Code::Parser do
|
4
|
-
subject { ::Code::Parser.parse(input) }
|
5
|
-
|
6
|
-
["a + b", "a - b", "(a - b) + c", "a - (b + c)"].each do |input|
|
7
|
-
context input do
|
8
|
-
let!(:input) { input }
|
9
|
-
|
10
|
-
it { subject }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
[
|
15
|
-
"a /* cool */ * b",
|
16
|
-
"a + /* cool */ b",
|
17
|
-
"a + b - c /* cool */",
|
18
|
-
"a + b - /* cool */ c"
|
19
|
-
].each do |input|
|
20
|
-
context input do
|
21
|
-
let!(:input) { input }
|
22
|
-
|
23
|
-
it { expect(subject.to_json).to include("cool") }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe ::Code::Parser do
|
4
|
-
subject { ::Code::Parser.parse(input) }
|
5
|
-
|
6
|
-
["a && b", "a && b && c"].each do |input|
|
7
|
-
context input do
|
8
|
-
let!(:input) { input }
|
9
|
-
|
10
|
-
it { subject }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
[
|
15
|
-
"a /* cool */ && b",
|
16
|
-
"a && /* cool */ b",
|
17
|
-
"a && b && c /* cool */",
|
18
|
-
"a && b && /* cool */ c"
|
19
|
-
].each do |input|
|
20
|
-
context input do
|
21
|
-
let!(:input) { input }
|
22
|
-
|
23
|
-
it { expect(subject.to_json).to include("cool") }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe ::Code::Parser do
|
4
|
-
subject { ::Code::Parser.parse(input) }
|
5
|
-
|
6
|
-
["a & b", "a & b & c"].each do |input|
|
7
|
-
context input do
|
8
|
-
let!(:input) { input }
|
9
|
-
|
10
|
-
it { subject }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
[
|
15
|
-
"a /* cool */ & b",
|
16
|
-
"a & /* cool */ b",
|
17
|
-
"a & b & c /* cool */",
|
18
|
-
"a & b & /* cool */ c"
|
19
|
-
].each do |input|
|
20
|
-
context input do
|
21
|
-
let!(:input) { input }
|
22
|
-
|
23
|
-
it { expect(subject.to_json).to include("cool") }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe ::Code::Parser do
|
4
|
-
subject { ::Code::Parser.parse(input) }
|
5
|
-
|
6
|
-
["a | b", "a | b | c"].each do |input|
|
7
|
-
context input do
|
8
|
-
let!(:input) { input }
|
9
|
-
|
10
|
-
it { subject }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
[
|
15
|
-
"a /* cool */ | b",
|
16
|
-
"a | /* cool */ b",
|
17
|
-
"a | b | c /* cool */",
|
18
|
-
"a | b | /* cool */ c"
|
19
|
-
].each do |input|
|
20
|
-
context input do
|
21
|
-
let!(:input) { input }
|
22
|
-
|
23
|
-
it { expect(subject.to_json).to include("cool") }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe ::Code::Parser do
|
4
|
-
subject { ::Code::Parser.parse(input) }
|
5
|
-
|
6
|
-
[
|
7
|
-
"a",
|
8
|
-
"admin?",
|
9
|
-
"update!",
|
10
|
-
"*args",
|
11
|
-
"**kargs",
|
12
|
-
"&block",
|
13
|
-
"update!(user)",
|
14
|
-
"puts(1)",
|
15
|
-
"print(1)",
|
16
|
-
"defined?(a)",
|
17
|
-
"each{}",
|
18
|
-
"each do end",
|
19
|
-
"render(a, *b, **c, &d) { |e, *f, **g, &h| puts(e) }",
|
20
|
-
"&render {}"
|
21
|
-
].each do |input|
|
22
|
-
context input do
|
23
|
-
let!(:input) { input }
|
24
|
-
|
25
|
-
it { subject }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
[
|
30
|
-
"update! /* cool */ { }",
|
31
|
-
"each{/* cool */}",
|
32
|
-
"render(/* cool */ a)",
|
33
|
-
"render(a /* cool */)",
|
34
|
-
"render(a, /* cool */ b)",
|
35
|
-
"render(a, b /* cool */)",
|
36
|
-
"render(/* cool */ a: 1)",
|
37
|
-
"render(a: 1 /* cool */)",
|
38
|
-
"render(a: 1, /* cool */ b: 2)",
|
39
|
-
"render(a: 1, b: 2 /* cool */)",
|
40
|
-
"render { /* cool */ |a, b| }",
|
41
|
-
"render { |/* cool */ a, b| }",
|
42
|
-
"render { |a /* cool */, b| }",
|
43
|
-
"render { |a: 1, /* cool */ b: 2| }",
|
44
|
-
"render { |a: 1, b: 2 /* cool */| }"
|
45
|
-
].each do |input|
|
46
|
-
context input do
|
47
|
-
let!(:input) { input }
|
48
|
-
|
49
|
-
it { expect(subject.to_json).to include("cool") }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe ::Code::Parser do
|
4
|
-
subject { ::Code::Parser.parse(input) }
|
5
|
-
|
6
|
-
[
|
7
|
-
"a.b",
|
8
|
-
"a.b.c",
|
9
|
-
"a(1).b.c(2)",
|
10
|
-
"user.first_name",
|
11
|
-
"User.all",
|
12
|
-
"User::Email.first",
|
13
|
-
"User.each do |user| user.update(created_at: Time.now) end"
|
14
|
-
].each do |input|
|
15
|
-
context input do
|
16
|
-
let!(:input) { input }
|
17
|
-
|
18
|
-
it { subject }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
[
|
23
|
-
"a /* cool */ . b",
|
24
|
-
"a . /* cool */ b",
|
25
|
-
"a . # cool\n /* cool */ b"
|
26
|
-
].each do |input|
|
27
|
-
context input do
|
28
|
-
let!(:input) { input }
|
29
|
-
|
30
|
-
it { expect(subject.to_json).to include("cool") }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe ::Code::Parser do
|
4
|
-
subject { ::Code::Parser.parse(input) }
|
5
|
-
|
6
|
-
[
|
7
|
-
"class A",
|
8
|
-
"class A self.b = 1",
|
9
|
-
"class A < B",
|
10
|
-
"class A end",
|
11
|
-
"class A self.b = 1 end",
|
12
|
-
"class A < B end"
|
13
|
-
].each do |input|
|
14
|
-
context input do
|
15
|
-
let!(:input) { input }
|
16
|
-
|
17
|
-
it { subject }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
[
|
22
|
-
"class /* cool */ A",
|
23
|
-
"class A /* cool */ < B",
|
24
|
-
"class A </* cool */ B"
|
25
|
-
].each do |input|
|
26
|
-
context input do
|
27
|
-
let!(:input) { input }
|
28
|
-
|
29
|
-
it { expect(subject.to_json).to include("cool") }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe ::Code::Parser do
|
4
|
-
subject { ::Code::Parser.parse(input) }
|
5
|
-
|
6
|
-
[
|
7
|
-
"{}",
|
8
|
-
"{a:1}",
|
9
|
-
"{ a: 1 }",
|
10
|
-
"{ :a => 1 }",
|
11
|
-
"{ :a => 1, b: 2 }",
|
12
|
-
"{ :a => 1, b: { c: 2 } }"
|
13
|
-
].each do |input|
|
14
|
-
context input do
|
15
|
-
let!(:input) { input }
|
16
|
-
|
17
|
-
it { subject }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
[
|
22
|
-
"{ /* cool */ }",
|
23
|
-
"{ a /* cool */ : 1",
|
24
|
-
"{ a /* cool */ => 1",
|
25
|
-
"{ a: 1 /* cool */ }",
|
26
|
-
"{ a: 1, /* cool */ b: 2 }",
|
27
|
-
"{ a: 1, b /* cool */ : 2 }",
|
28
|
-
"{ a: 1, b /* cool */ => 2 }",
|
29
|
-
"{ a: 1, b => /* cool */ 2 }",
|
30
|
-
"{ a: 1, b => 2 /* cool */ }",
|
31
|
-
"{ /* cool */ **kargs }",
|
32
|
-
"{ **kargs /* cool */ }"
|
33
|
-
].each do |input|
|
34
|
-
context input do
|
35
|
-
let!(:input) { input }
|
36
|
-
|
37
|
-
it { expect(subject.to_json).to include("cool") }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe ::Code::Parser do
|
4
|
-
subject { ::Code::Parser.parse(input) }
|
5
|
-
|
6
|
-
[
|
7
|
-
"a = 1",
|
8
|
-
"a += 1",
|
9
|
-
"a -= 1",
|
10
|
-
"a *= 1",
|
11
|
-
"a /= 1",
|
12
|
-
"a <<= 1",
|
13
|
-
"a >>= 1",
|
14
|
-
"a &= 1",
|
15
|
-
"a |= 1",
|
16
|
-
"a ^= 1",
|
17
|
-
"a %= 1",
|
18
|
-
"a ||= 1",
|
19
|
-
"a &&= 1",
|
20
|
-
"a = b = 1",
|
21
|
-
"a = b += c"
|
22
|
-
].each do |input|
|
23
|
-
context input do
|
24
|
-
let!(:input) { input }
|
25
|
-
|
26
|
-
it { subject }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
[
|
31
|
-
"a /* cool */ = 1",
|
32
|
-
"a += /* cool */ 1",
|
33
|
-
"a = b -= /* cool */ 1",
|
34
|
-
"a = b /* cool */ *= 1"
|
35
|
-
].each do |input|
|
36
|
-
context input do
|
37
|
-
let!(:input) { input }
|
38
|
-
|
39
|
-
it { expect(subject.to_json).to include("cool") }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe ::Code::Parser do
|
4
|
-
subject { ::Code::Parser.parse(input) }
|
5
|
-
|
6
|
-
["a == b", "a != b", "a > 1 == true", "a == b == c"].each do |input|
|
7
|
-
context input do
|
8
|
-
let!(:input) { input }
|
9
|
-
|
10
|
-
it { subject }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
[
|
15
|
-
"a /* cool */ == b",
|
16
|
-
"a == /* cool */ b",
|
17
|
-
"a == b /* cool */ == c",
|
18
|
-
"a == b == /* cool */ c"
|
19
|
-
].each do |input|
|
20
|
-
context input do
|
21
|
-
let!(:input) { input }
|
22
|
-
|
23
|
-
it { expect(subject.to_json).to include("cool") }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|