11
12
13
14
15
16
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/sql_beautifier/in_list.rb', line 11
def format_in_text(text, base_indent: 0)
output = +""
scanner = Scanner.new(text)
while scanner.position < text.length
consumed = scanner.scan_quoted_or_sentinel!
if consumed
output << consumed
next
end
if scanner.current_char == Constants::OPEN_PARENTHESIS
scanner.increment_depth!
output << scanner.current_char
scanner.advance!
next
end
if scanner.current_char == Constants::CLOSE_PARENTHESIS
scanner.decrement_depth!
output << scanner.current_char
scanner.advance!
next
end
if scanner.parenthesis_depth.zero? && in_keyword_at?(scanner)
keyword_length = in_keyword_length_at(scanner)
parenthesis_position = find_opening_parenthesis(text, scanner.position + keyword_length)
if parenthesis_position
expansion = format_in_list(text, keyword_position: scanner.position, parenthesis_position: parenthesis_position, base_indent: base_indent)
if expansion
output << expansion[:text]
scanner.advance!(expansion[:consumed] - scanner.position)
next
end
end
end
output << scanner.current_char
scanner.advance!
end
output
end
|