tomlrb 2.0.3 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/tomlrb/parser.y DELETED
@@ -1,196 +0,0 @@
1
- class Tomlrb::GeneratedParser
2
- token IDENTIFIER STRING_MULTI STRING_BASIC STRING_LITERAL_MULTI STRING_LITERAL DATETIME LOCAL_TIME INTEGER NON_DEC_INTEGER FLOAT FLOAT_KEYWORD BOOLEAN NEWLINE EOS
3
- rule
4
- expressions
5
- | expressions expression
6
- | expressions EOS
7
- ;
8
- expression
9
- : table
10
- | assignment
11
- | inline_table
12
- | NEWLINE
13
- ;
14
- table
15
- : table_start table_continued NEWLINE
16
- | table_start table_continued EOS
17
- ;
18
- table_start
19
- : '[' '[' { @handler.start_(:array_of_tables) }
20
- | '[' { @handler.start_(:table) }
21
- ;
22
- table_continued
23
- : ']' ']' { array = @handler.end_(:array_of_tables); @handler.set_context(array, is_array_of_tables: true) }
24
- | ']' { array = @handler.end_(:table); @handler.set_context(array) }
25
- | table_identifier table_next
26
- ;
27
- table_next
28
- : ']' ']' { array = @handler.end_(:array_of_tables); @handler.set_context(array, is_array_of_tables: true) }
29
- | ']' { array = @handler.end_(:table); @handler.set_context(array) }
30
- | '.' table_continued
31
- ;
32
- table_identifier
33
- : table_identifier '.' table_identifier_component { @handler.push(val[2]) }
34
- | table_identifier '.' FLOAT { val[2].split('.').each { |k| @handler.push(k) } }
35
- | FLOAT {
36
- keys = val[0].split('.')
37
- @handler.start_(:table)
38
- keys.each { |key| @handler.push(key) }
39
- }
40
- | table_identifier_component { @handler.push(val[0]) }
41
- ;
42
- table_identifier_component
43
- : IDENTIFIER
44
- | STRING_BASIC { result = StringUtils.replace_escaped_chars(val[0]) }
45
- | STRING_LITERAL
46
- | INTEGER
47
- | NON_DEC_INTEGER
48
- | FLOAT_KEYWORD
49
- | BOOLEAN
50
- ;
51
- inline_table
52
- : inline_table_start inline_table_end
53
- | inline_table_start inline_continued inline_table_end
54
- ;
55
- inline_table_start
56
- : '{' { @handler.start_(:inline) }
57
- ;
58
- inline_table_end
59
- : '}' {
60
- array = @handler.end_(:inline)
61
- @handler.push_inline(array)
62
- }
63
- ;
64
- inline_continued
65
- : inline_assignment
66
- | inline_assignment inline_next
67
- ;
68
- inline_next
69
- : ',' inline_continued
70
- ;
71
- inline_assignment
72
- : inline_assignment_key '=' value {
73
- keys = @handler.end_(:inline_keys)
74
- @handler.push(keys)
75
- }
76
- ;
77
- inline_assignment_key
78
- : inline_assignment_key '.' assignment_key_component {
79
- @handler.push(val[2])
80
- }
81
- | inline_assignment_key '.' FLOAT { val[2].split('.').each { |k| @handler.push(k) } }
82
- | FLOAT {
83
- keys = val[0].split('.')
84
- @handler.start_(:inline_keys)
85
- keys.each { |key| @handler.push(key) }
86
- }
87
- | assignment_key_component {
88
- @handler.start_(:inline_keys)
89
- @handler.push(val[0])
90
- }
91
- ;
92
- assignment
93
- : assignment_key '=' value EOS {
94
- keys = @handler.end_(:keys)
95
- value = keys.pop
96
- @handler.validate_value(value)
97
- @handler.push(value)
98
- @handler.assign(keys)
99
- }
100
- | assignment_key '=' value NEWLINE {
101
- keys = @handler.end_(:keys)
102
- value = keys.pop
103
- @handler.validate_value(value)
104
- @handler.push(value)
105
- @handler.assign(keys)
106
- }
107
- ;
108
- assignment_key
109
- : assignment_key '.' assignment_key_component { @handler.push(val[2]) }
110
- | assignment_key '.' FLOAT { val[2].split('.').each { |k| @handler.push(k) } }
111
- | FLOAT {
112
- keys = val[0].split('.')
113
- @handler.start_(:keys)
114
- keys.each { |key| @handler.push(key) }
115
- }
116
- | assignment_key_component { @handler.start_(:keys); @handler.push(val[0]) }
117
- ;
118
- assignment_key_component
119
- : IDENTIFIER
120
- | STRING_BASIC { result = StringUtils.replace_escaped_chars(val[0]) }
121
- | STRING_LITERAL
122
- | INTEGER
123
- | NON_DEC_INTEGER
124
- | FLOAT_KEYWORD
125
- | BOOLEAN
126
- ;
127
- array
128
- : start_array array_continued
129
- ;
130
- array_continued
131
- : ']' { array = @handler.end_(:array); @handler.push(array.compact) }
132
- | value array_next
133
- | NEWLINE array_continued
134
- ;
135
- array_next
136
- : ']' { array = @handler.end_(:array); @handler.push(array.compact) }
137
- | ',' array_continued
138
- | NEWLINE array_continued
139
- ;
140
- start_array
141
- : '[' { @handler.start_(:array) }
142
- ;
143
- value
144
- : scalar { @handler.push(val[0]) }
145
- | array
146
- | inline_table
147
- ;
148
- scalar
149
- : string
150
- | literal
151
- ;
152
- literal
153
- | FLOAT { result = val[0].to_f }
154
- | FLOAT_KEYWORD {
155
- v = val[0]
156
- result = if v.end_with?('nan')
157
- Float::NAN
158
- else
159
- (v[0] == '-' ? -1 : 1) * Float::INFINITY
160
- end
161
- }
162
- | INTEGER { result = val[0].to_i }
163
- | NON_DEC_INTEGER {
164
- base = case val[0][1]
165
- when "x" then 16
166
- when "o" then 8
167
- when "b" then 2
168
- end
169
- result = val[0].to_i(base)
170
- }
171
- | BOOLEAN { result = val[0] == 'true' ? true : false }
172
- | DATETIME {
173
- v = val[0]
174
- result = if v[6].nil?
175
- if v[4].nil?
176
- LocalDate.new(v[0], v[1], v[2])
177
- else
178
- LocalDateTime.new(v[0], v[1], v[2], v[3] || 0, v[4] || 0, v[5].to_f)
179
- end
180
- else
181
- # Patch for 24:00:00 which Ruby parses
182
- if v[3].to_i == 24 && v[4].to_i == 0 && v[5].to_i == 0
183
- v[3] = (v[3].to_i + 1).to_s
184
- end
185
-
186
- Time.new(v[0], v[1], v[2], v[3] || 0, v[4] || 0, v[5].to_f, v[6])
187
- end
188
- }
189
- | LOCAL_TIME { result = LocalTime.new(*val[0]) }
190
- ;
191
- string
192
- : STRING_MULTI { result = StringUtils.replace_escaped_chars(StringUtils.multiline_replacements(val[0])) }
193
- | STRING_BASIC { result = StringUtils.replace_escaped_chars(val[0]) }
194
- | STRING_LITERAL_MULTI { result = StringUtils.strip_spaces(val[0]) }
195
- | STRING_LITERAL { result = val[0] }
196
- ;