rhcl 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rhcl/parse.tab.rb +39 -38
- data/lib/rhcl/parse.y +39 -38
- data/lib/rhcl/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c2dfad2b024f0251ae293e7f15b77690731bb82
|
4
|
+
data.tar.gz: 5836cb027e5aab9c42e51b9e7e1b547757397302
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66e61c3536485733c666deb6cb245d4e52fdac00f87b01fd645a7f2c5515e384e9b64061ab154265ac14eb5ebaf015a2e74f84170dc3f9740e95beff52f6848e
|
7
|
+
data.tar.gz: 9f8636fdf14f6be1f39d53a51e0f0f469b01db9dc5bfdce3a3ec2c9e8f5ad652c163be149ed3e03a4d83ceb7252dcf58f854fc154ee1c1710544265a3ee53c12
|
data/lib/rhcl/parse.tab.rb
CHANGED
@@ -21,81 +21,74 @@ end
|
|
21
21
|
|
22
22
|
def scan
|
23
23
|
tok = nil
|
24
|
-
@
|
24
|
+
@backup = []
|
25
25
|
|
26
26
|
until @ss.eos?
|
27
|
-
if (tok = @ss.scan /\s+/)
|
27
|
+
if (tok = backup { @ss.scan /\s+/ })
|
28
28
|
# nothing to do
|
29
|
-
elsif (tok = @ss.scan
|
30
|
-
@
|
31
|
-
|
32
|
-
tok =
|
33
|
-
elsif (tok = @ss.scan(%r|/|))
|
34
|
-
@prev_tokens << tok
|
35
|
-
|
36
|
-
case (tok = @ss.getch)
|
29
|
+
elsif (tok = backup { @ss.scan /#/ })
|
30
|
+
backup { @ss.scan_until /\n/ }
|
31
|
+
elsif (tok = backup { @ss.scan %r|/| })
|
32
|
+
case (tok = backup { @ss.getch })
|
37
33
|
when '/'
|
38
|
-
@
|
39
|
-
@prev_tokens << @ss.scan_until(/(\n|\z)/)
|
34
|
+
backup { @ss.scan_until /(\n|\z)/ }
|
40
35
|
when '*'
|
41
|
-
@prev_tokens << tok
|
42
36
|
nested = 1
|
43
37
|
|
44
38
|
until nested.zero?
|
45
|
-
case (tok = @ss.scan_until
|
39
|
+
case (tok = backup { @ss.scan_until %r{(/\*|\*/|\z)} })
|
46
40
|
when %r|/\*\z|
|
47
|
-
@prev_tokens << tok
|
48
41
|
nested += 1
|
49
42
|
when %r|\*/\z|
|
50
|
-
@prev_tokens << tok
|
51
43
|
nested -= 1
|
52
44
|
else
|
53
|
-
@prev_tokens << tok
|
54
45
|
break
|
55
46
|
end
|
56
47
|
end
|
57
48
|
else
|
58
|
-
raise "comment expected, got
|
49
|
+
raise "comment expected, got #{tok.inspect}"
|
59
50
|
end
|
60
|
-
|
61
|
-
tok = ''
|
62
|
-
elsif (tok = @ss.scan(/-?\d+\.\d+/))
|
51
|
+
elsif (tok = backup { @ss.scan /-?\d+\.\d+/ })
|
63
52
|
yield [:FLOAT, tok.to_f]
|
64
|
-
elsif (tok = @ss.scan
|
53
|
+
elsif (tok = backup { @ss.scan /-?\d+/ })
|
65
54
|
yield [:INTEGER, tok.to_i]
|
66
|
-
elsif (tok = @ss.scan
|
55
|
+
elsif (tok = backup { @ss.scan /,/ })
|
67
56
|
yield [:COMMA, tok]
|
68
|
-
elsif (tok = @ss.scan
|
57
|
+
elsif (tok = backup { @ss.scan /\=/ })
|
69
58
|
yield [:EQUAL, tok]
|
70
|
-
elsif (tok = @ss.scan
|
59
|
+
elsif (tok = backup { @ss.scan /\[/ })
|
71
60
|
yield [:LEFTBRACKET, tok]
|
72
|
-
elsif (tok = @ss.scan
|
61
|
+
elsif (tok = backup { @ss.scan /\]/ })
|
73
62
|
yield [:RIGHTBRACKET, tok]
|
74
|
-
elsif (tok = @ss.scan
|
63
|
+
elsif (tok = backup { @ss.scan /\{/ })
|
75
64
|
yield [:LEFTBRACE, tok]
|
76
|
-
elsif (tok = @ss.scan
|
65
|
+
elsif (tok = backup { @ss.scan /\}/ })
|
77
66
|
yield [:RIGHTBRACE, tok]
|
78
|
-
elsif (tok = @ss.scan
|
79
|
-
yield [:STRING, (@ss.scan_until
|
67
|
+
elsif (tok = backup { @ss.scan /"/ })
|
68
|
+
yield [:STRING, (backup { @ss.scan_until /("|\z)/ } || '').sub(/"\z/, '')]
|
80
69
|
else
|
81
|
-
|
70
|
+
identifier = (backup { @ss.scan_until /(\s|\z)/ } || '').sub(/\s\z/, '')
|
82
71
|
token_type = :IDENTIFIER
|
83
72
|
|
84
|
-
if ['true', 'false'].include?(
|
85
|
-
|
73
|
+
if ['true', 'false'].include?(identifier)
|
74
|
+
identifier = !!(identifier =~ /true/)
|
86
75
|
token_type = :BOOL
|
87
76
|
end
|
88
77
|
|
89
|
-
yield [token_type,
|
78
|
+
yield [token_type, identifier]
|
90
79
|
end
|
91
|
-
|
92
|
-
@prev_tokens << tok
|
93
80
|
end
|
94
81
|
|
95
82
|
yield [false, '$end']
|
96
83
|
end
|
97
84
|
private :scan
|
98
85
|
|
86
|
+
def backup
|
87
|
+
tok = yield
|
88
|
+
@backup << tok if tok
|
89
|
+
return tok
|
90
|
+
end
|
91
|
+
|
99
92
|
def parse
|
100
93
|
yyparse self, :scan
|
101
94
|
end
|
@@ -106,9 +99,17 @@ end
|
|
106
99
|
|
107
100
|
def raise_error(error_value)
|
108
101
|
header = "parse error on value: #{error_value}\n"
|
109
|
-
|
102
|
+
error_value = @backup.pop
|
103
|
+
|
104
|
+
if error_value =~ /\n\z/
|
105
|
+
error_value = '__' + error_value.chomp + "__\n"
|
106
|
+
else
|
107
|
+
error_value = '__' + error_value + '__'
|
108
|
+
end
|
109
|
+
|
110
|
+
prev = (@backup || [])
|
110
111
|
prev = prev.empty? ? '' : prev.join + ' '
|
111
|
-
errmsg = prev +
|
112
|
+
errmsg = prev + error_value
|
112
113
|
|
113
114
|
if @ss and @ss.rest?
|
114
115
|
errmsg << ' ' + @ss.rest
|
data/lib/rhcl/parse.y
CHANGED
@@ -112,81 +112,74 @@ end
|
|
112
112
|
|
113
113
|
def scan
|
114
114
|
tok = nil
|
115
|
-
@
|
115
|
+
@backup = []
|
116
116
|
|
117
117
|
until @ss.eos?
|
118
|
-
if (tok = @ss.scan /\s+/)
|
118
|
+
if (tok = backup { @ss.scan /\s+/ })
|
119
119
|
# nothing to do
|
120
|
-
elsif (tok = @ss.scan
|
121
|
-
@
|
122
|
-
|
123
|
-
tok =
|
124
|
-
elsif (tok = @ss.scan(%r|/|))
|
125
|
-
@prev_tokens << tok
|
126
|
-
|
127
|
-
case (tok = @ss.getch)
|
120
|
+
elsif (tok = backup { @ss.scan /#/ })
|
121
|
+
backup { @ss.scan_until /\n/ }
|
122
|
+
elsif (tok = backup { @ss.scan %r|/| })
|
123
|
+
case (tok = backup { @ss.getch })
|
128
124
|
when '/'
|
129
|
-
@
|
130
|
-
@prev_tokens << @ss.scan_until(/(\n|\z)/)
|
125
|
+
backup { @ss.scan_until /(\n|\z)/ }
|
131
126
|
when '*'
|
132
|
-
@prev_tokens << tok
|
133
127
|
nested = 1
|
134
128
|
|
135
129
|
until nested.zero?
|
136
|
-
case (tok = @ss.scan_until
|
130
|
+
case (tok = backup { @ss.scan_until %r{(/\*|\*/|\z)} })
|
137
131
|
when %r|/\*\z|
|
138
|
-
@prev_tokens << tok
|
139
132
|
nested += 1
|
140
133
|
when %r|\*/\z|
|
141
|
-
@prev_tokens << tok
|
142
134
|
nested -= 1
|
143
135
|
else
|
144
|
-
@prev_tokens << tok
|
145
136
|
break
|
146
137
|
end
|
147
138
|
end
|
148
139
|
else
|
149
|
-
raise "comment expected, got
|
140
|
+
raise "comment expected, got #{tok.inspect}"
|
150
141
|
end
|
151
|
-
|
152
|
-
tok = ''
|
153
|
-
elsif (tok = @ss.scan(/-?\d+\.\d+/))
|
142
|
+
elsif (tok = backup { @ss.scan /-?\d+\.\d+/ })
|
154
143
|
yield [:FLOAT, tok.to_f]
|
155
|
-
elsif (tok = @ss.scan
|
144
|
+
elsif (tok = backup { @ss.scan /-?\d+/ })
|
156
145
|
yield [:INTEGER, tok.to_i]
|
157
|
-
elsif (tok = @ss.scan
|
146
|
+
elsif (tok = backup { @ss.scan /,/ })
|
158
147
|
yield [:COMMA, tok]
|
159
|
-
elsif (tok = @ss.scan
|
148
|
+
elsif (tok = backup { @ss.scan /\=/ })
|
160
149
|
yield [:EQUAL, tok]
|
161
|
-
elsif (tok = @ss.scan
|
150
|
+
elsif (tok = backup { @ss.scan /\[/ })
|
162
151
|
yield [:LEFTBRACKET, tok]
|
163
|
-
elsif (tok = @ss.scan
|
152
|
+
elsif (tok = backup { @ss.scan /\]/ })
|
164
153
|
yield [:RIGHTBRACKET, tok]
|
165
|
-
elsif (tok = @ss.scan
|
154
|
+
elsif (tok = backup { @ss.scan /\{/ })
|
166
155
|
yield [:LEFTBRACE, tok]
|
167
|
-
elsif (tok = @ss.scan
|
156
|
+
elsif (tok = backup { @ss.scan /\}/ })
|
168
157
|
yield [:RIGHTBRACE, tok]
|
169
|
-
elsif (tok = @ss.scan
|
170
|
-
yield [:STRING, (@ss.scan_until
|
158
|
+
elsif (tok = backup { @ss.scan /"/ })
|
159
|
+
yield [:STRING, (backup { @ss.scan_until /("|\z)/ } || '').sub(/"\z/, '')]
|
171
160
|
else
|
172
|
-
|
161
|
+
identifier = (backup { @ss.scan_until /(\s|\z)/ } || '').sub(/\s\z/, '')
|
173
162
|
token_type = :IDENTIFIER
|
174
163
|
|
175
|
-
if ['true', 'false'].include?(
|
176
|
-
|
164
|
+
if ['true', 'false'].include?(identifier)
|
165
|
+
identifier = !!(identifier =~ /true/)
|
177
166
|
token_type = :BOOL
|
178
167
|
end
|
179
168
|
|
180
|
-
yield [token_type,
|
169
|
+
yield [token_type, identifier]
|
181
170
|
end
|
182
|
-
|
183
|
-
@prev_tokens << tok
|
184
171
|
end
|
185
172
|
|
186
173
|
yield [false, '$end']
|
187
174
|
end
|
188
175
|
private :scan
|
189
176
|
|
177
|
+
def backup
|
178
|
+
tok = yield
|
179
|
+
@backup << tok if tok
|
180
|
+
return tok
|
181
|
+
end
|
182
|
+
|
190
183
|
def parse
|
191
184
|
yyparse self, :scan
|
192
185
|
end
|
@@ -197,9 +190,17 @@ end
|
|
197
190
|
|
198
191
|
def raise_error(error_value)
|
199
192
|
header = "parse error on value: #{error_value}\n"
|
200
|
-
|
193
|
+
error_value = @backup.pop
|
194
|
+
|
195
|
+
if error_value =~ /\n\z/
|
196
|
+
error_value = '__' + error_value.chomp + "__\n"
|
197
|
+
else
|
198
|
+
error_value = '__' + error_value + '__'
|
199
|
+
end
|
200
|
+
|
201
|
+
prev = (@backup || [])
|
201
202
|
prev = prev.empty? ? '' : prev.join + ' '
|
202
|
-
errmsg = prev +
|
203
|
+
errmsg = prev + error_value
|
203
204
|
|
204
205
|
if @ss and @ss.rest?
|
205
206
|
errmsg << ' ' + @ss.rest
|
data/lib/rhcl/version.rb
CHANGED