kpeg 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -21,5 +21,6 @@ end
21
21
 
22
22
  desc "rebuild parser"
23
23
  task :parser do
24
+ sh "ruby -Ilib bin/kpeg -o lib/kpeg/string_escape.rb -f lib/kpeg/string_escape.kpeg"
24
25
  sh "ruby -Ilib bin/kpeg -o lib/kpeg/format_parser.rb -s -f lib/kpeg/format.kpeg"
25
26
  end
@@ -578,7 +578,7 @@ class KPeg::FormatParser
578
578
  return _tmp
579
579
  end
580
580
 
581
- # dbl_escapes = ("n" { "\n" } | "s" { " " } | "r" { "\r" } | "t" { "\t" } | "v" { "\v" } | "f" { "\f" } | "b" { "\b" } | "a" { "\a" } | "e" { "\e" } | "\\" { "\\" } | "\"" { "\"" } | num_escapes)
581
+ # dbl_escapes = ("n" { "\n" } | "s" { " " } | "r" { "\r" } | "t" { "\t" } | "v" { "\v" } | "f" { "\f" } | "b" { "\b" } | "a" { "\a" } | "e" { "\e" } | "\\" { "\\" } | "\"" { "\"" } | num_escapes | < . > { text })
582
582
  def _dbl_escapes
583
583
 
584
584
  _save = self.pos
@@ -782,6 +782,28 @@ class KPeg::FormatParser
782
782
  break if _tmp
783
783
  self.pos = _save
784
784
  _tmp = apply(:_num_escapes)
785
+ break if _tmp
786
+ self.pos = _save
787
+
788
+ _save12 = self.pos
789
+ while true # sequence
790
+ _text_start = self.pos
791
+ _tmp = get_byte
792
+ if _tmp
793
+ text = get_text(_text_start)
794
+ end
795
+ unless _tmp
796
+ self.pos = _save12
797
+ break
798
+ end
799
+ @result = begin; text ; end
800
+ _tmp = true
801
+ unless _tmp
802
+ self.pos = _save12
803
+ end
804
+ break
805
+ end # end sequence
806
+
785
807
  break if _tmp
786
808
  self.pos = _save
787
809
  break
@@ -791,7 +813,7 @@ class KPeg::FormatParser
791
813
  return _tmp
792
814
  end
793
815
 
794
- # num_escapes = (< /[0-7]{3}/ > { [text.to_i(8)].pack("U") } | "x" < /[0-9a-fA-F]{2}/ > { [text.to_i(16)].pack("U") })
816
+ # num_escapes = (< /[0-7]{1,3}/ > { [text.to_i(8)].pack("U") } | "x" < /[0-9a-fA-F]{2}/ > { [text.to_i(16)].pack("U") })
795
817
  def _num_escapes
796
818
 
797
819
  _save = self.pos
@@ -800,7 +822,7 @@ class KPeg::FormatParser
800
822
  _save1 = self.pos
801
823
  while true # sequence
802
824
  _text_start = self.pos
803
- _tmp = scan(/\A(?-mix:[0-7]{3})/)
825
+ _tmp = scan(/\A(?-mix:[0-7]{1,3})/)
804
826
  if _tmp
805
827
  text = get_text(_text_start)
806
828
  end
@@ -3075,8 +3097,8 @@ class KPeg::FormatParser
3075
3097
  Rules[:_kleene] = rule_info("kleene", "\"*\"")
3076
3098
  Rules[:_var] = rule_info("var", "< (\"-\" | /[a-zA-Z][\\-_a-zA-Z0-9]*/) > { text }")
3077
3099
  Rules[:_method] = rule_info("method", "< /[a-zA-Z_][a-zA-Z0-9_]*/ > { text }")
3078
- Rules[:_dbl_escapes] = rule_info("dbl_escapes", "(\"n\" { \"\\n\" } | \"s\" { \" \" } | \"r\" { \"\\r\" } | \"t\" { \"\\t\" } | \"v\" { \"\\v\" } | \"f\" { \"\\f\" } | \"b\" { \"\\b\" } | \"a\" { \"\\a\" } | \"e\" { \"\\e\" } | \"\\\\\" { \"\\\\\" } | \"\\\"\" { \"\\\"\" } | num_escapes)")
3079
- Rules[:_num_escapes] = rule_info("num_escapes", "(< /[0-7]{3}/ > { [text.to_i(8)].pack(\"U\") } | \"x\" < /[0-9a-fA-F]{2}/ > { [text.to_i(16)].pack(\"U\") })")
3100
+ Rules[:_dbl_escapes] = rule_info("dbl_escapes", "(\"n\" { \"\\n\" } | \"s\" { \" \" } | \"r\" { \"\\r\" } | \"t\" { \"\\t\" } | \"v\" { \"\\v\" } | \"f\" { \"\\f\" } | \"b\" { \"\\b\" } | \"a\" { \"\\a\" } | \"e\" { \"\\e\" } | \"\\\\\" { \"\\\\\" } | \"\\\"\" { \"\\\"\" } | num_escapes | < . > { text })")
3101
+ Rules[:_num_escapes] = rule_info("num_escapes", "(< /[0-7]{1,3}/ > { [text.to_i(8)].pack(\"U\") } | \"x\" < /[0-9a-fA-F]{2}/ > { [text.to_i(16)].pack(\"U\") })")
3080
3102
  Rules[:_dbl_seq] = rule_info("dbl_seq", "< /[^\\\\\"]+/ > { text }")
3081
3103
  Rules[:_dbl_not_quote] = rule_info("dbl_not_quote", "(\"\\\\\" dbl_escapes:s | dbl_seq:s)*:ary { Array(ary) }")
3082
3104
  Rules[:_dbl_string] = rule_info("dbl_string", "\"\\\"\" dbl_not_quote:s \"\\\"\" { @g.str(s.join) }")
@@ -13,203 +13,170 @@ class KPeg::StringEscape < KPeg::CompiledParser
13
13
  _save = self.pos
14
14
  while true # choice
15
15
 
16
- _save1 = self.pos
17
- while true # sequence
18
- _text_start = self.pos
19
- _tmp = scan(/\A(?-mix:[\w ]+)/)
20
- if _tmp
21
- text = get_text(_text_start)
22
- end
23
- unless _tmp
24
- self.pos = _save1
25
- break
26
- end
27
- @result = begin; text ; end
28
- _tmp = true
29
- unless _tmp
30
- self.pos = _save1
31
- end
32
- break
33
- end # end sequence
34
-
35
- break if _tmp
36
- self.pos = _save
37
-
38
- _save2 = self.pos
39
- while true # sequence
40
- _tmp = match_string("\\")
41
- unless _tmp
42
- self.pos = _save2
43
- break
44
- end
45
- @result = begin; "\\\\" ; end
46
- _tmp = true
47
- unless _tmp
48
- self.pos = _save2
49
- end
50
- break
51
- end # end sequence
52
-
53
- break if _tmp
54
- self.pos = _save
55
-
56
- _save3 = self.pos
57
- while true # sequence
58
- _tmp = match_string("\n")
59
- unless _tmp
60
- self.pos = _save3
61
- break
62
- end
63
- @result = begin; "\\n" ; end
64
- _tmp = true
65
- unless _tmp
66
- self.pos = _save3
67
- end
68
- break
69
- end # end sequence
70
-
71
- break if _tmp
72
- self.pos = _save
73
-
74
- _save4 = self.pos
75
- while true # sequence
76
- _tmp = match_string("\t")
77
- unless _tmp
78
- self.pos = _save4
79
- break
80
- end
81
- @result = begin; "\\t" ; end
82
- _tmp = true
83
- unless _tmp
84
- self.pos = _save4
85
- end
86
- break
87
- end # end sequence
16
+ _save1 = self.pos
17
+ while true # sequence
18
+ _text_start = self.pos
19
+ _tmp = scan(/\A(?-mix:[\w ]+)/)
20
+ if _tmp
21
+ text = get_text(_text_start)
22
+ end
23
+ unless _tmp
24
+ self.pos = _save1
25
+ break
26
+ end
27
+ @result = begin; text ; end
28
+ _tmp = true
29
+ unless _tmp
30
+ self.pos = _save1
31
+ end
32
+ break
33
+ end # end sequence
34
+
35
+ break if _tmp
36
+ self.pos = _save
88
37
 
89
- break if _tmp
90
- self.pos = _save
38
+ _save2 = self.pos
39
+ while true # sequence
40
+ _tmp = match_string("\\")
41
+ unless _tmp
42
+ self.pos = _save2
43
+ break
44
+ end
45
+ @result = begin; "\\\\" ; end
46
+ _tmp = true
47
+ unless _tmp
48
+ self.pos = _save2
49
+ end
50
+ break
51
+ end # end sequence
52
+
53
+ break if _tmp
54
+ self.pos = _save
91
55
 
92
- _save5 = self.pos
93
- while true # sequence
94
- _tmp = match_string("\b")
95
- unless _tmp
96
- self.pos = _save5
97
- break
98
- end
99
- @result = begin; "\\b" ; end
100
- _tmp = true
101
- unless _tmp
102
- self.pos = _save5
103
- end
104
- break
105
- end # end sequence
56
+ _save3 = self.pos
57
+ while true # sequence
58
+ _tmp = match_string("\n")
59
+ unless _tmp
60
+ self.pos = _save3
61
+ break
62
+ end
63
+ @result = begin; "\\n" ; end
64
+ _tmp = true
65
+ unless _tmp
66
+ self.pos = _save3
67
+ end
68
+ break
69
+ end # end sequence
70
+
71
+ break if _tmp
72
+ self.pos = _save
106
73
 
107
- break if _tmp
108
- self.pos = _save
74
+ _save4 = self.pos
75
+ while true # sequence
76
+ _tmp = match_string("\t")
77
+ unless _tmp
78
+ self.pos = _save4
79
+ break
80
+ end
81
+ @result = begin; "\\t" ; end
82
+ _tmp = true
83
+ unless _tmp
84
+ self.pos = _save4
85
+ end
86
+ break
87
+ end # end sequence
88
+
89
+ break if _tmp
90
+ self.pos = _save
109
91
 
110
- _save6 = self.pos
111
- while true # sequence
112
- _tmp = match_string("\"")
113
- unless _tmp
114
- self.pos = _save6
115
- break
116
- end
117
- @result = begin; "\\\"" ; end
118
- _tmp = true
119
- unless _tmp
120
- self.pos = _save6
121
- end
122
- break
123
- end # end sequence
92
+ _save5 = self.pos
93
+ while true # sequence
94
+ _tmp = match_string("\b")
95
+ unless _tmp
96
+ self.pos = _save5
97
+ break
98
+ end
99
+ @result = begin; "\\b" ; end
100
+ _tmp = true
101
+ unless _tmp
102
+ self.pos = _save5
103
+ end
104
+ break
105
+ end # end sequence
106
+
107
+ break if _tmp
108
+ self.pos = _save
124
109
 
125
- break if _tmp
126
- self.pos = _save
110
+ _save6 = self.pos
111
+ while true # sequence
112
+ _tmp = match_string("\"")
113
+ unless _tmp
114
+ self.pos = _save6
115
+ break
116
+ end
117
+ @result = begin; "\\\"" ; end
118
+ _tmp = true
119
+ unless _tmp
120
+ self.pos = _save6
121
+ end
122
+ break
123
+ end # end sequence
124
+
125
+ break if _tmp
126
+ self.pos = _save
127
127
 
128
- _save7 = self.pos
129
- while true # sequence
130
- _text_start = self.pos
131
- _tmp = get_byte
132
- if _tmp
133
- text = get_text(_text_start)
134
- end
135
- unless _tmp
136
- self.pos = _save7
128
+ _save7 = self.pos
129
+ while true # sequence
130
+ _text_start = self.pos
131
+ _tmp = get_byte
132
+ if _tmp
133
+ text = get_text(_text_start)
134
+ end
135
+ unless _tmp
136
+ self.pos = _save7
137
+ break
138
+ end
139
+ @result = begin; text ; end
140
+ _tmp = true
141
+ unless _tmp
142
+ self.pos = _save7
143
+ end
144
+ break
145
+ end # end sequence
146
+
147
+ break if _tmp
148
+ self.pos = _save
137
149
  break
138
- end
139
- @result = begin; text ; end
140
- _tmp = true
141
- unless _tmp
142
- self.pos = _save7
143
- end
144
- break
145
- end # end sequence
146
-
147
- break if _tmp
148
- self.pos = _save
149
- break
150
150
  end # end choice
151
151
 
152
152
  set_failed_rule :_segment unless _tmp
153
153
  return _tmp
154
154
  end
155
155
 
156
- # segments = (segment:s segments:r { "#{s}#{r}" } | segment)
157
- def _segments
158
-
159
- _save = self.pos
160
- while true # choice
161
-
162
- _save1 = self.pos
163
- while true # sequence
164
- _tmp = apply(:_segment)
165
- s = @result
166
- unless _tmp
167
- self.pos = _save1
168
- break
169
- end
170
- _tmp = apply(:_segments)
171
- r = @result
172
- unless _tmp
173
- self.pos = _save1
174
- break
175
- end
176
- @result = begin; "#{s}#{r}" ; end
177
- _tmp = true
178
- unless _tmp
179
- self.pos = _save1
180
- end
181
- break
182
- end # end sequence
183
-
184
- break if _tmp
185
- self.pos = _save
186
- _tmp = apply(:_segment)
187
- break if _tmp
188
- self.pos = _save
189
- break
190
- end # end choice
191
-
192
- set_failed_rule :_segments unless _tmp
193
- return _tmp
194
- end
195
-
196
- # root = segments:s { @text = s }
156
+ # root = segment*:s { @text = s.join }
197
157
  def _root
198
158
 
199
159
  _save = self.pos
200
160
  while true # sequence
201
- _tmp = apply(:_segments)
202
- s = @result
203
- unless _tmp
204
- self.pos = _save
161
+ _ary = []
162
+ while true
163
+ _tmp = apply(:_segment)
164
+ _ary << @result if _tmp
165
+ break unless _tmp
166
+ end
167
+ _tmp = true
168
+ @result = _ary
169
+ s = @result
170
+ unless _tmp
171
+ self.pos = _save
172
+ break
173
+ end
174
+ @result = begin; @text = s.join ; end
175
+ _tmp = true
176
+ unless _tmp
177
+ self.pos = _save
178
+ end
205
179
  break
206
- end
207
- @result = begin; @text = s ; end
208
- _tmp = true
209
- unless _tmp
210
- self.pos = _save
211
- end
212
- break
213
180
  end # end sequence
214
181
 
215
182
  set_failed_rule :_root unless _tmp
@@ -222,90 +189,57 @@ class KPeg::StringEscape < KPeg::CompiledParser
222
189
  _save = self.pos
223
190
  while true # choice
224
191
 
225
- _save1 = self.pos
226
- while true # sequence
227
- _tmp = match_string("#")
228
- unless _tmp
229
- self.pos = _save1
192
+ _save1 = self.pos
193
+ while true # sequence
194
+ _tmp = match_string("#")
195
+ unless _tmp
196
+ self.pos = _save1
197
+ break
198
+ end
199
+ @result = begin; "\\#" ; end
200
+ _tmp = true
201
+ unless _tmp
202
+ self.pos = _save1
203
+ end
204
+ break
205
+ end # end sequence
206
+
207
+ break if _tmp
208
+ self.pos = _save
209
+ _tmp = apply(:_segment)
210
+ break if _tmp
211
+ self.pos = _save
230
212
  break
231
- end
232
- @result = begin; "\\#" ; end
233
- _tmp = true
234
- unless _tmp
235
- self.pos = _save1
236
- end
237
- break
238
- end # end sequence
239
-
240
- break if _tmp
241
- self.pos = _save
242
- _tmp = apply(:_segment)
243
- break if _tmp
244
- self.pos = _save
245
- break
246
213
  end # end choice
247
214
 
248
215
  set_failed_rule :_embed_seg unless _tmp
249
216
  return _tmp
250
217
  end
251
218
 
252
- # embed_segs = (embed_seg:s embed_segs:r { "#{s}#{r}" } | embed_seg)
253
- def _embed_segs
254
-
255
- _save = self.pos
256
- while true # choice
257
-
258
- _save1 = self.pos
259
- while true # sequence
260
- _tmp = apply(:_embed_seg)
261
- s = @result
262
- unless _tmp
263
- self.pos = _save1
264
- break
265
- end
266
- _tmp = apply(:_embed_segs)
267
- r = @result
268
- unless _tmp
269
- self.pos = _save1
270
- break
271
- end
272
- @result = begin; "#{s}#{r}" ; end
273
- _tmp = true
274
- unless _tmp
275
- self.pos = _save1
276
- end
277
- break
278
- end # end sequence
279
-
280
- break if _tmp
281
- self.pos = _save
282
- _tmp = apply(:_embed_seg)
283
- break if _tmp
284
- self.pos = _save
285
- break
286
- end # end choice
287
-
288
- set_failed_rule :_embed_segs unless _tmp
289
- return _tmp
290
- end
291
-
292
- # embed = embed_segs:s { @text = s }
219
+ # embed = embed_seg*:s { @text = s.join }
293
220
  def _embed
294
221
 
295
222
  _save = self.pos
296
223
  while true # sequence
297
- _tmp = apply(:_embed_segs)
298
- s = @result
299
- unless _tmp
300
- self.pos = _save
224
+ _ary = []
225
+ while true
226
+ _tmp = apply(:_embed_seg)
227
+ _ary << @result if _tmp
228
+ break unless _tmp
229
+ end
230
+ _tmp = true
231
+ @result = _ary
232
+ s = @result
233
+ unless _tmp
234
+ self.pos = _save
235
+ break
236
+ end
237
+ @result = begin; @text = s.join ; end
238
+ _tmp = true
239
+ unless _tmp
240
+ self.pos = _save
241
+ end
301
242
  break
302
- end
303
- @result = begin; @text = s ; end
304
- _tmp = true
305
- unless _tmp
306
- self.pos = _save
307
- end
308
- break
309
243
  end # end sequence
310
244
 
311
245
  set_failed_rule :_embed unless _tmp
@@ -314,9 +248,7 @@ class KPeg::StringEscape < KPeg::CompiledParser
314
248
 
315
249
  Rules = {}
316
250
  Rules[:_segment] = rule_info("segment", "(< /[\\w ]+/ > { text } | \"\\\\\" { \"\\\\\\\\\" } | \"\\n\" { \"\\\\n\" } | \"\\t\" { \"\\\\t\" } | \"\\b\" { \"\\\\b\" } | \"\\\"\" { \"\\\\\\\"\" } | < . > { text })")
317
- Rules[:_segments] = rule_info("segments", "(segment:s segments:r { \"\#{s}\#{r}\" } | segment)")
318
- Rules[:_root] = rule_info("root", "segments:s { @text = s }")
251
+ Rules[:_root] = rule_info("root", "segment*:s { @text = s.join }")
319
252
  Rules[:_embed_seg] = rule_info("embed_seg", "(\"\#\" { \"\\\\\#\" } | segment)")
320
- Rules[:_embed_segs] = rule_info("embed_segs", "(embed_seg:s embed_segs:r { \"\#{s}\#{r}\" } | embed_seg)")
321
- Rules[:_embed] = rule_info("embed", "embed_segs:s { @text = s }")
253
+ Rules[:_embed] = rule_info("embed", "embed_seg*:s { @text = s.join }")
322
254
  end
@@ -1,3 +1,3 @@
1
1
  module KPeg
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
@@ -147,8 +147,12 @@ b(p) = x
147
147
  assert_rule G.str(""), match('a=""')
148
148
  assert_rule G.str("hello"), match('a="hello"')
149
149
  assert_rule G.str("hello\ngoodbye"), match('a="hello\ngoodbye"')
150
- assert_rule G.str("\n\s\r\t\v\f\b\a\r\\\"\012\x1b"),
151
- match('a="\n\s\r\t\v\f\b\a\r\\\\\\"\012\x1b"')
150
+ assert_rule G.str("hello\n\0goodbye"), match('a="hello\n\0goodbye"')
151
+ assert_rule G.str("hello\n\017goodbye"), match('a="hello\n\017goodbye"')
152
+ assert_rule G.str("hello\n\017goodbye"), match('a="hello\n\017goodbye"')
153
+ assert_rule G.str("hello\n\9goodbye"), match('a="hello\n\9goodbye"')
154
+ assert_rule G.str("\n\s\r\t\v\f\b\a\r\\\"\0172\x1b"),
155
+ match('a="\n\s\r\t\v\f\b\a\r\\\\\\"\0172\x1b"')
152
156
  assert_rule G.str("h\"ello"), match('a="h\"ello"')
153
157
  end
154
158
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kpeg
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 3
10
- version: 0.8.3
9
+ - 4
10
+ version: 0.8.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Evan Phoenix
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-05 00:00:00 -07:00
19
- default_executable:
18
+ date: 2011-10-01 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: rake
@@ -67,7 +66,6 @@ files:
67
66
  - test/test_kpeg_compiled_parser.rb
68
67
  - test/test_kpeg_format.rb
69
68
  - test/test_kpeg_grammar_renderer.rb
70
- has_rdoc: true
71
69
  homepage: https://github.com/evanphx/kpeg
72
70
  licenses: []
73
71
 
@@ -97,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
95
  requirements: []
98
96
 
99
97
  rubyforge_project:
100
- rubygems_version: 1.6.2
98
+ rubygems_version: 1.8.10
101
99
  signing_key:
102
100
  specification_version: 3
103
101
  summary: Peg-based Code Generator