kpeg 0.10.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7cbdc1c35b943bc3f71391cb377b422b91e68f52
4
+ data.tar.gz: 43d2cb391965f7ffd22f9afcbfee3f02b952ae3c
5
+ SHA512:
6
+ metadata.gz: 0a6aa682aefebb2c59f72e17a88be5a7c956bb87d8d1700b29916bbb624297959e7273ab57262f895ea073e2a08a91dd40b2879d532dfdef729720df980fb3fb
7
+ data.tar.gz: cdb1452be3a93769b4aba53e58cc13224b66eeca67b21b21df4731d4445d06b84c85f70432510e004f011e6902d1dcf34d3bb205fe661eacbaf1a6fda088f2d0
@@ -0,0 +1,15 @@
1
+ ---
2
+ script: rake travis
3
+ before_script:
4
+ - gem install hoe-travis --no-rdoc --no-ri
5
+ - rake travis:before -t
6
+ language: ruby
7
+ notifications:
8
+ email:
9
+ - evan@fallingsnow.net
10
+ - drbrain@segment7.net
11
+ rvm:
12
+ - 1.8.7
13
+ - 1.9.2
14
+ - 1.9.3
15
+ - 2.0.0
@@ -1,4 +1,5 @@
1
1
  .autotest
2
+ .travis.yml
2
3
  History.txt
3
4
  LICENSE
4
5
  Manifest.txt
@@ -1,42 +1,42 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # stub: kpeg 1.0.0.20140103162640 ruby lib
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "kpeg"
5
- s.version = "0.8.5.20120306163408"
6
+ s.version = "1.0.0.20140103162640"
6
7
 
7
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Eric Hodel"]
9
- s.cert_chain = ["/Users/drbrain/.gem/gem-public_cert.pem"]
10
- s.date = "2012-03-07"
9
+ s.authors = ["Evan Phoenix"]
10
+ s.date = "2014-01-04"
11
11
  s.description = "KPeg is a simple PEG library for Ruby. It provides an API as well as native\ngrammar to build the grammar.\n\nKPeg strives to provide a simple, powerful API without being too exotic.\n\nKPeg supports direct left recursion of rules via the\n{OMeta memoization}[http://www.vpri.org/pdf/tr2008003_experimenting.pdf] trick."
12
- s.email = ["drbrain@segment7.net"]
12
+ s.email = ["evan@fallingsnow.net"]
13
13
  s.executables = ["kpeg"]
14
- s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
15
- s.files = [".autotest", "Gemfile", "Gemfile.lock", "History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "bin/kpeg", "examples/calculator/calculator.kpeg", "examples/calculator/calculator.rb", "examples/foreign_reference/literals.kpeg", "examples/foreign_reference/matcher.kpeg", "examples/foreign_reference/matcher.rb", "examples/lua_string/driver.rb", "examples/lua_string/lua_string.kpeg", "examples/lua_string/lua_string.kpeg.rb", "examples/phone_number/README.md", "examples/phone_number/phone_number.kpeg", "examples/phone_number/phone_number.rb", "examples/upper/README.md", "examples/upper/upper.kpeg", "examples/upper/upper.rb", "kpeg.gemspec", "lib/kpeg.rb", "lib/kpeg/code_generator.rb", "lib/kpeg/compiled_parser.rb", "lib/kpeg/format.kpeg", "lib/kpeg/format_parser.rb", "lib/kpeg/grammar.rb", "lib/kpeg/grammar_renderer.rb", "lib/kpeg/match.rb", "lib/kpeg/parser.rb", "lib/kpeg/position.rb", "lib/kpeg/string_escape.kpeg", "lib/kpeg/string_escape.rb", "lib/kpeg/version.rb", "test/inputs/comments.kpeg", "test/test_file_parser_roundtrip.rb", "test/test_gen_calc.rb", "test/test_kpeg.rb", "test/test_kpeg_code_generator.rb", "test/test_kpeg_compiled_parser.rb", "test/test_kpeg_format.rb", "test/test_kpeg_grammar_renderer.rb", "test/test_left_recursion.rb", "vim/syntax_kpeg/ftdetect/kpeg.vim", "vim/syntax_kpeg/syntax/kpeg.vim", ".gemtest"]
14
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc", "examples/phone_number/README.md", "examples/upper/README.md"]
15
+ s.files = [".autotest", ".travis.yml", "History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "bin/kpeg", "examples/calculator/calculator.kpeg", "examples/calculator/calculator.rb", "examples/foreign_reference/literals.kpeg", "examples/foreign_reference/matcher.kpeg", "examples/foreign_reference/matcher.rb", "examples/lua_string/driver.rb", "examples/lua_string/lua_string.kpeg", "examples/lua_string/lua_string.kpeg.rb", "examples/phone_number/README.md", "examples/phone_number/phone_number.kpeg", "examples/phone_number/phone_number.rb", "examples/upper/README.md", "examples/upper/upper.kpeg", "examples/upper/upper.rb", "kpeg.gemspec", "lib/hoe/kpeg.rb", "lib/kpeg.rb", "lib/kpeg/code_generator.rb", "lib/kpeg/compiled_parser.rb", "lib/kpeg/format_parser.kpeg", "lib/kpeg/format_parser.rb", "lib/kpeg/grammar.rb", "lib/kpeg/grammar_renderer.rb", "lib/kpeg/match.rb", "lib/kpeg/parser.rb", "lib/kpeg/position.rb", "lib/kpeg/string_escape.kpeg", "lib/kpeg/string_escape.rb", "test/inputs/comments.kpeg", "test/test_kpeg.rb", "test/test_kpeg_code_generator.rb", "test/test_kpeg_compiled_parser.rb", "test/test_kpeg_format.rb", "test/test_kpeg_format_parser_round_trip.rb", "test/test_kpeg_grammar.rb", "test/test_kpeg_grammar_renderer.rb", "vim/syntax_kpeg/ftdetect/kpeg.vim", "vim/syntax_kpeg/syntax/kpeg.vim", "test/test_kpeg_string_escape.rb", ".gemtest"]
16
16
  s.homepage = "https://github.com/evanphx/kpeg"
17
+ s.licenses = ["MIT"]
17
18
  s.rdoc_options = ["--main", "README.rdoc"]
18
19
  s.require_paths = ["lib"]
19
20
  s.rubyforge_project = "kpeg"
20
- s.rubygems_version = "1.8.12"
21
- s.signing_key = "/Users/drbrain/.gem/gem-private_key.pem"
21
+ s.rubygems_version = "2.1.10"
22
22
  s.summary = "KPeg is a simple PEG library for Ruby"
23
- s.test_files = ["test/test_file_parser_roundtrip.rb", "test/test_gen_calc.rb", "test/test_kpeg.rb", "test/test_kpeg_code_generator.rb", "test/test_kpeg_compiled_parser.rb", "test/test_kpeg_format.rb", "test/test_kpeg_grammar_renderer.rb", "test/test_left_recursion.rb"]
23
+ s.test_files = ["test/test_kpeg.rb", "test/test_kpeg_code_generator.rb", "test/test_kpeg_compiled_parser.rb", "test/test_kpeg_format.rb", "test/test_kpeg_format_parser_round_trip.rb", "test/test_kpeg_grammar.rb", "test/test_kpeg_grammar_renderer.rb", "test/test_kpeg_string_escape.rb"]
24
24
 
25
25
  if s.respond_to? :specification_version then
26
- s.specification_version = 3
26
+ s.specification_version = 4
27
27
 
28
28
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29
- s.add_development_dependency(%q<minitest>, ["~> 2.11"])
30
- s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
31
- s.add_development_dependency(%q<hoe>, ["~> 2.15"])
29
+ s.add_development_dependency(%q<minitest>, ["~> 5.2"])
30
+ s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
31
+ s.add_development_dependency(%q<hoe>, ["~> 3.7"])
32
32
  else
33
- s.add_dependency(%q<minitest>, ["~> 2.11"])
34
- s.add_dependency(%q<rdoc>, ["~> 3.10"])
35
- s.add_dependency(%q<hoe>, ["~> 2.15"])
33
+ s.add_dependency(%q<minitest>, ["~> 5.2"])
34
+ s.add_dependency(%q<rdoc>, ["~> 4.0"])
35
+ s.add_dependency(%q<hoe>, ["~> 3.7"])
36
36
  end
37
37
  else
38
- s.add_dependency(%q<minitest>, ["~> 2.11"])
39
- s.add_dependency(%q<rdoc>, ["~> 3.10"])
40
- s.add_dependency(%q<hoe>, ["~> 2.15"])
38
+ s.add_dependency(%q<minitest>, ["~> 5.2"])
39
+ s.add_dependency(%q<rdoc>, ["~> 4.0"])
40
+ s.add_dependency(%q<hoe>, ["~> 3.7"])
41
41
  end
42
42
  end
@@ -1,6 +1,6 @@
1
1
  module KPeg
2
2
 
3
- VERSION = "0.10.0"
3
+ VERSION = "1.0.0"
4
4
 
5
5
  def self.grammar
6
6
  g = Grammar.new
@@ -83,11 +83,14 @@ module KPeg
83
83
 
84
84
  if output_node
85
85
  code << " end\n"
86
+ code << " module #{root}Construction\n"
86
87
  methods.each do |short, name, attrs|
87
- code << " def #{short}(#{attrs.join(', ')})\n"
88
- code << " #{root}::#{name}.new(#{attrs.join(', ')})\n"
89
- code << " end\n"
88
+ code << " def #{short}(#{attrs.join(', ')})\n"
89
+ code << " #{root}::#{name}.new(#{attrs.join(', ')})\n"
90
+ code << " end\n"
90
91
  end
92
+ code << " end\n"
93
+ code << " include #{root}Construction\n"
91
94
  end
92
95
  end
93
96
 
@@ -124,7 +127,7 @@ module KPeg
124
127
  left = op.start[0]
125
128
  right = op.fin[0]
126
129
  end
127
-
130
+
128
131
  code << indentify(" unless _tmp >= #{left} and _tmp <= #{right}\n", indent)
129
132
  code << indentify(" self.pos = #{ss}\n", indent)
130
133
  code << indentify(" _tmp = nil\n", indent)
@@ -140,7 +143,7 @@ module KPeg
140
143
  code << indentify("while true # choice\n", indent)
141
144
  op.ops.each_with_index do |n,idx|
142
145
  output_op code, n, (indent+1)
143
-
146
+
144
147
  code << indentify(" break if _tmp\n", indent)
145
148
  code << indentify(" self.pos = #{ss}\n", indent)
146
149
  if idx == op.ops.size - 1
@@ -447,7 +450,7 @@ module KPeg
447
450
  cpi = standalone_region("compiled_parser.rb", "INITIALIZE")
448
451
  pp = standalone_region("position.rb")
449
452
 
450
- cp.gsub!(/include Position/, pp)
453
+ cp.gsub!(/^\s*include Position/, pp)
451
454
  code << " # :stopdoc:\n"
452
455
  code << cpi << "\n" unless @grammar.variables['custom_initialize']
453
456
  code << cp << "\n"
@@ -27,8 +27,7 @@ module KPeg
27
27
  # Prepares for parsing +str+. If you define a custom initialize you must
28
28
  # call this method before #parse
29
29
  def setup_parser(str, debug=false)
30
- @string = str
31
- @pos = 0
30
+ set_string str, 0
32
31
  @memoizations = Hash.new { |h,k| h[k] = {} }
33
32
  @result = nil
34
33
  @failed_rule = nil
@@ -47,6 +46,13 @@ module KPeg
47
46
  @string[start..@pos-1]
48
47
  end
49
48
 
49
+ # Sets the string and current parsing position for the parser.
50
+ def set_string string, pos
51
+ @string = string
52
+ @string_size = string ? string.size : 0
53
+ @pos = pos
54
+ end
55
+
50
56
  def show_pos
51
57
  width = 10
52
58
  if @pos < width
@@ -153,19 +159,19 @@ module KPeg
153
159
  return nil
154
160
  end
155
161
 
156
- if "".respond_to? :getbyte
162
+ if "".respond_to? :ord
157
163
  def get_byte
158
- if @pos >= @string.size
164
+ if @pos >= @string_size
159
165
  return nil
160
166
  end
161
167
 
162
- s = @string.getbyte @pos
168
+ s = @string[@pos].ord
163
169
  @pos += 1
164
170
  s
165
171
  end
166
172
  else
167
173
  def get_byte
168
- if @pos >= @string.size
174
+ if @pos >= @string_size
169
175
  return nil
170
176
  end
171
177
 
@@ -214,8 +220,7 @@ module KPeg
214
220
  old_pos = @pos
215
221
  old_string = @string
216
222
 
217
- @pos = other.pos
218
- @string = other.string
223
+ set_string other.string, other.pos
219
224
 
220
225
  begin
221
226
  if val = __send__(rule, *args)
@@ -226,8 +231,7 @@ module KPeg
226
231
  end
227
232
  val
228
233
  ensure
229
- @pos = old_pos
230
- @string = old_string
234
+ set_string old_string, old_pos
231
235
  end
232
236
  end
233
237
 
@@ -5,8 +5,7 @@ class KPeg::FormatParser
5
5
  # Prepares for parsing +str+. If you define a custom initialize you must
6
6
  # call this method before #parse
7
7
  def setup_parser(str, debug=false)
8
- @string = str
9
- @pos = 0
8
+ set_string str, 0
10
9
  @memoizations = Hash.new { |h,k| h[k] = {} }
11
10
  @result = nil
12
11
  @failed_rule = nil
@@ -19,7 +18,6 @@ class KPeg::FormatParser
19
18
  attr_reader :failing_rule_offset
20
19
  attr_accessor :result, :pos
21
20
 
22
-
23
21
  def current_column(target=pos)
24
22
  if c = string.rindex("\n", target-1)
25
23
  return target - c - 1
@@ -53,6 +51,13 @@ class KPeg::FormatParser
53
51
  @string[start..@pos-1]
54
52
  end
55
53
 
54
+ # Sets the string and current parsing position for the parser.
55
+ def set_string string, pos
56
+ @string = string
57
+ @string_size = string ? string.size : 0
58
+ @pos = pos
59
+ end
60
+
56
61
  def show_pos
57
62
  width = 10
58
63
  if @pos < width
@@ -159,19 +164,19 @@ class KPeg::FormatParser
159
164
  return nil
160
165
  end
161
166
 
162
- if "".respond_to? :getbyte
167
+ if "".respond_to? :ord
163
168
  def get_byte
164
- if @pos >= @string.size
169
+ if @pos >= @string_size
165
170
  return nil
166
171
  end
167
172
 
168
- s = @string.getbyte @pos
173
+ s = @string[@pos].ord
169
174
  @pos += 1
170
175
  s
171
176
  end
172
177
  else
173
178
  def get_byte
174
- if @pos >= @string.size
179
+ if @pos >= @string_size
175
180
  return nil
176
181
  end
177
182
 
@@ -220,8 +225,7 @@ class KPeg::FormatParser
220
225
  old_pos = @pos
221
226
  old_string = @string
222
227
 
223
- @pos = other.pos
224
- @string = other.string
228
+ set_string other.string, other.pos
225
229
 
226
230
  begin
227
231
  if val = __send__(rule, *args)
@@ -232,8 +236,7 @@ class KPeg::FormatParser
232
236
  end
233
237
  val
234
238
  ensure
235
- @pos = old_pos
236
- @string = old_string
239
+ set_string old_string, old_pos
237
240
  end
238
241
  end
239
242
 
@@ -834,7 +834,7 @@ module KPeg
834
834
  # Invoke a rule defined on a foreign grammar
835
835
  # == Parameters:
836
836
  # gram::
837
- # The name of the grammar that the rule will be reference from
837
+ # The name of the grammar that the rule will be reference from
838
838
  # name::
839
839
  # The name of the rule that will be invoked
840
840
  # args::
@@ -7,6 +7,7 @@
7
7
  segment = < /[\w ]+/ > { text } # Don't use \s because that matchs \n
8
8
  | "\\" { "\\\\" }
9
9
  | "\n" { "\\n" }
10
+ | "\r" { "\\r" }
10
11
  | "\t" { "\\t" }
11
12
  | "\b" { "\\b" }
12
13
  | "\"" { "\\\"" }
@@ -13,8 +13,7 @@ class KPeg::StringEscape
13
13
  # Prepares for parsing +str+. If you define a custom initialize you must
14
14
  # call this method before #parse
15
15
  def setup_parser(str, debug=false)
16
- @string = str
17
- @pos = 0
16
+ set_string str, 0
18
17
  @memoizations = Hash.new { |h,k| h[k] = {} }
19
18
  @result = nil
20
19
  @failed_rule = nil
@@ -27,7 +26,6 @@ class KPeg::StringEscape
27
26
  attr_reader :failing_rule_offset
28
27
  attr_accessor :result, :pos
29
28
 
30
-
31
29
  def current_column(target=pos)
32
30
  if c = string.rindex("\n", target-1)
33
31
  return target - c - 1
@@ -61,6 +59,13 @@ class KPeg::StringEscape
61
59
  @string[start..@pos-1]
62
60
  end
63
61
 
62
+ # Sets the string and current parsing position for the parser.
63
+ def set_string string, pos
64
+ @string = string
65
+ @string_size = string ? string.size : 0
66
+ @pos = pos
67
+ end
68
+
64
69
  def show_pos
65
70
  width = 10
66
71
  if @pos < width
@@ -167,19 +172,19 @@ class KPeg::StringEscape
167
172
  return nil
168
173
  end
169
174
 
170
- if "".respond_to? :getbyte
175
+ if "".respond_to? :ord
171
176
  def get_byte
172
- if @pos >= @string.size
177
+ if @pos >= @string_size
173
178
  return nil
174
179
  end
175
180
 
176
- s = @string.getbyte @pos
181
+ s = @string[@pos].ord
177
182
  @pos += 1
178
183
  s
179
184
  end
180
185
  else
181
186
  def get_byte
182
- if @pos >= @string.size
187
+ if @pos >= @string_size
183
188
  return nil
184
189
  end
185
190
 
@@ -228,8 +233,7 @@ class KPeg::StringEscape
228
233
  old_pos = @pos
229
234
  old_string = @string
230
235
 
231
- @pos = other.pos
232
- @string = other.string
236
+ set_string other.string, other.pos
233
237
 
234
238
  begin
235
239
  if val = __send__(rule, *args)
@@ -240,8 +244,7 @@ class KPeg::StringEscape
240
244
  end
241
245
  val
242
246
  ensure
243
- @pos = old_pos
244
- @string = old_string
247
+ set_string old_string, old_pos
245
248
  end
246
249
  end
247
250
 
@@ -359,7 +362,7 @@ class KPeg::StringEscape
359
362
  # :stopdoc:
360
363
  def setup_foreign_grammar; end
361
364
 
362
- # segment = (< /[\w ]+/ > { text } | "\\" { "\\\\" } | "\n" { "\\n" } | "\t" { "\\t" } | "\b" { "\\b" } | "\"" { "\\\"" } | < . > { text })
365
+ # segment = (< /[\w ]+/ > { text } | "\\" { "\\\\" } | "\n" { "\\n" } | "\r" { "\\r" } | "\t" { "\\t" } | "\b" { "\\b" } | "\"" { "\\\"" } | < . > { text })
363
366
  def _segment
364
367
 
365
368
  _save = self.pos
@@ -425,12 +428,12 @@ class KPeg::StringEscape
425
428
 
426
429
  _save4 = self.pos
427
430
  while true # sequence
428
- _tmp = match_string("\t")
431
+ _tmp = match_string("\r")
429
432
  unless _tmp
430
433
  self.pos = _save4
431
434
  break
432
435
  end
433
- @result = begin; "\\t" ; end
436
+ @result = begin; "\\r" ; end
434
437
  _tmp = true
435
438
  unless _tmp
436
439
  self.pos = _save4
@@ -443,12 +446,12 @@ class KPeg::StringEscape
443
446
 
444
447
  _save5 = self.pos
445
448
  while true # sequence
446
- _tmp = match_string("\b")
449
+ _tmp = match_string("\t")
447
450
  unless _tmp
448
451
  self.pos = _save5
449
452
  break
450
453
  end
451
- @result = begin; "\\b" ; end
454
+ @result = begin; "\\t" ; end
452
455
  _tmp = true
453
456
  unless _tmp
454
457
  self.pos = _save5
@@ -461,12 +464,12 @@ class KPeg::StringEscape
461
464
 
462
465
  _save6 = self.pos
463
466
  while true # sequence
464
- _tmp = match_string("\"")
467
+ _tmp = match_string("\b")
465
468
  unless _tmp
466
469
  self.pos = _save6
467
470
  break
468
471
  end
469
- @result = begin; "\\\"" ; end
472
+ @result = begin; "\\b" ; end
470
473
  _tmp = true
471
474
  unless _tmp
472
475
  self.pos = _save6
@@ -478,6 +481,24 @@ class KPeg::StringEscape
478
481
  self.pos = _save
479
482
 
480
483
  _save7 = self.pos
484
+ while true # sequence
485
+ _tmp = match_string("\"")
486
+ unless _tmp
487
+ self.pos = _save7
488
+ break
489
+ end
490
+ @result = begin; "\\\"" ; end
491
+ _tmp = true
492
+ unless _tmp
493
+ self.pos = _save7
494
+ end
495
+ break
496
+ end # end sequence
497
+
498
+ break if _tmp
499
+ self.pos = _save
500
+
501
+ _save8 = self.pos
481
502
  while true # sequence
482
503
  _text_start = self.pos
483
504
  _tmp = get_byte
@@ -485,13 +506,13 @@ class KPeg::StringEscape
485
506
  text = get_text(_text_start)
486
507
  end
487
508
  unless _tmp
488
- self.pos = _save7
509
+ self.pos = _save8
489
510
  break
490
511
  end
491
512
  @result = begin; text ; end
492
513
  _tmp = true
493
514
  unless _tmp
494
- self.pos = _save7
515
+ self.pos = _save8
495
516
  end
496
517
  break
497
518
  end # end sequence
@@ -599,7 +620,7 @@ class KPeg::StringEscape
599
620
  end
600
621
 
601
622
  Rules = {}
602
- Rules[:_segment] = rule_info("segment", "(< /[\\w ]+/ > { text } | \"\\\\\" { \"\\\\\\\\\" } | \"\\n\" { \"\\\\n\" } | \"\\t\" { \"\\\\t\" } | \"\\b\" { \"\\\\b\" } | \"\\\"\" { \"\\\\\\\"\" } | < . > { text })")
623
+ Rules[:_segment] = rule_info("segment", "(< /[\\w ]+/ > { text } | \"\\\\\" { \"\\\\\\\\\" } | \"\\n\" { \"\\\\n\" } | \"\\r\" { \"\\\\r\" } | \"\\t\" { \"\\\\t\" } | \"\\b\" { \"\\\\b\" } | \"\\\"\" { \"\\\\\\\"\" } | < . > { text })")
603
624
  Rules[:_root] = rule_info("root", "segment*:s { @text = s.join }")
604
625
  Rules[:_embed_seg] = rule_info("embed_seg", "(\"\#\" { \"\\\\\#\" } | segment)")
605
626
  Rules[:_embed] = rule_info("embed", "embed_seg*:s { @text = s.join }")
@@ -2,7 +2,7 @@ require 'minitest/autorun'
2
2
  require 'kpeg'
3
3
  require 'stringio'
4
4
 
5
- class TestKPeg < MiniTest::Unit::TestCase
5
+ class TestKPeg < Minitest::Test
6
6
  def assert_match(m, str)
7
7
  assert_kind_of KPeg::MatchString, m
8
8
  assert_equal str, m.string
@@ -4,7 +4,7 @@ require 'kpeg'
4
4
  require 'kpeg/code_generator'
5
5
  require 'stringio'
6
6
 
7
- class TestKPegCodeGenerator < MiniTest::Unit::TestCase
7
+ class TestKPegCodeGenerator < Minitest::Test
8
8
  def test_dot
9
9
  gram = KPeg.grammar do |g|
10
10
  g.root = g.dot
@@ -1661,15 +1661,18 @@ class Test < KPeg::CompiledParser
1661
1661
  end
1662
1662
  end
1663
1663
  end
1664
- def bracket(receiver, argument)
1665
- AST::BracketOperator.new(receiver, argument)
1666
- end
1667
- def simple()
1668
- AST::Simple.new()
1669
- end
1670
- def simple2()
1671
- AST::Simple2.new()
1664
+ module ASTConstruction
1665
+ def bracket(receiver, argument)
1666
+ AST::BracketOperator.new(receiver, argument)
1667
+ end
1668
+ def simple()
1669
+ AST::Simple.new()
1670
+ end
1671
+ def simple2()
1672
+ AST::Simple2.new()
1673
+ end
1672
1674
  end
1675
+ include ASTConstruction
1673
1676
 
1674
1677
  # root = .
1675
1678
  def _root
@@ -1715,9 +1718,12 @@ class Test < KPeg::CompiledParser
1715
1718
  attr_reader :argument
1716
1719
  end
1717
1720
  end
1718
- def bracket(receiver, argument)
1719
- MegaAST::BracketOperator.new(receiver, argument)
1721
+ module MegaASTConstruction
1722
+ def bracket(receiver, argument)
1723
+ MegaAST::BracketOperator.new(receiver, argument)
1724
+ end
1720
1725
  end
1726
+ include MegaASTConstruction
1721
1727
 
1722
1728
  # root = .
1723
1729
  def _root
@@ -3,7 +3,7 @@ require 'kpeg'
3
3
  require 'kpeg/compiled_parser'
4
4
  require 'stringio'
5
5
 
6
- class TestKPegCompiledParser < MiniTest::Unit::TestCase
6
+ class TestKPegCompiledParser < Minitest::Test
7
7
 
8
8
  gram = <<-GRAM
9
9
  letter = [a-z]
@@ -5,7 +5,7 @@ require 'kpeg/grammar_renderer'
5
5
  require 'stringio'
6
6
  require 'rubygems'
7
7
 
8
- class TestKPegFormat < MiniTest::Unit::TestCase
8
+ class TestKPegFormat < Minitest::Test
9
9
  G = KPeg::Grammar.new
10
10
 
11
11
  gram = File.read File.expand_path("../../lib/kpeg/format_parser.kpeg", __FILE__)
@@ -157,9 +157,9 @@ b(p) = x
157
157
  end
158
158
 
159
159
  def test_regexp
160
- assert_rule G.reg(/foo/), match('a=/foo/')
161
- assert_rule G.reg(/foo\/bar/), match('a=/foo\/bar/')
162
- assert_rule G.reg(/[^"]/), match('a=/[^"]/')
160
+ assert_rule G.reg('foo'), match('a=/foo/')
161
+ assert_rule G.reg('foo\\/bar'), match('a=/foo\/bar/')
162
+ assert_rule G.reg('[^"]'), match('a=/[^"]/')
163
163
  end
164
164
 
165
165
  def test_regexp_options
@@ -5,7 +5,7 @@ require 'kpeg/grammar_renderer'
5
5
  require 'kpeg/code_generator'
6
6
  require 'stringio'
7
7
 
8
- class TestKPegFormatParserRoundtrip < MiniTest::Unit::TestCase
8
+ class TestKPegFormatParserRoundtrip < Minitest::Test
9
9
  PATH = File.expand_path("../../lib/kpeg/format_parser.kpeg", __FILE__)
10
10
  def test_roundtrip
11
11
  data = File.read(PATH)
@@ -4,7 +4,7 @@ require 'kpeg/format_parser'
4
4
  require 'kpeg/code_generator'
5
5
  require 'stringio'
6
6
 
7
- class TestKpegGrammar < MiniTest::Unit::TestCase
7
+ class TestKpegGrammar < Minitest::Test
8
8
  LEFT_RECURSION = <<-'STR'
9
9
 
10
10
  name = name:n "[]" { [:array, n] }
@@ -3,7 +3,7 @@ require 'kpeg'
3
3
  require 'kpeg/grammar_renderer'
4
4
  require 'stringio'
5
5
 
6
- class TestKPegGrammarRenderer < MiniTest::Unit::TestCase
6
+ class TestKPegGrammarRenderer < Minitest::Test
7
7
  def test_escape
8
8
  str = "hello\nbob"
9
9
  assert_equal 'hello\nbob', KPeg::GrammarRenderer.escape(str)
@@ -0,0 +1,42 @@
1
+ require 'minitest/autorun'
2
+ require 'kpeg'
3
+ require 'kpeg/string_escape'
4
+
5
+ class TestKPegStringEscape < Minitest::Test
6
+
7
+ def test_bell
8
+ assert_equal '\b', parse("\b")
9
+ end
10
+
11
+ def test_carriage_return
12
+ assert_equal '\r', parse("\r")
13
+ end
14
+
15
+ def test_newline
16
+ assert_equal '\n', parse("\n")
17
+ end
18
+
19
+ def test_quote
20
+ assert_equal '\\\\\"', parse('\\"')
21
+ end
22
+
23
+ def test_slash
24
+ assert_equal '\\\\', parse('\\')
25
+ end
26
+
27
+ def test_tab
28
+ assert_equal '\t', parse("\t")
29
+ end
30
+
31
+ def parse(str, embed = false)
32
+ se = KPeg::StringEscape.new(str)
33
+
34
+ rule = (embed ? 'embed' : nil)
35
+
36
+ se.raise_error unless se.parse(rule)
37
+
38
+ se.text
39
+ end
40
+
41
+ end
42
+
metadata CHANGED
@@ -1,87 +1,79 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: kpeg
3
- version: !ruby/object:Gem::Version
4
- hash: 55
5
- prerelease:
6
- segments:
7
- - 0
8
- - 10
9
- - 0
10
- version: 0.10.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Evan Phoenix
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-04-16 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2014-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: minitest
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
26
17
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 27
29
- segments:
30
- - 2
31
- - 12
32
- version: "2.12"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
33
20
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rdoc
37
21
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
41
31
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 19
44
- segments:
45
- - 3
46
- - 10
47
- version: "3.10"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
48
34
  type: :development
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: hoe
52
35
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hoe
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
56
45
  - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 35
59
- segments:
60
- - 2
61
- - 16
62
- version: "2.16"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.7'
63
48
  type: :development
64
- version_requirements: *id003
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.7'
65
55
  description: |-
66
56
  KPeg is a simple PEG library for Ruby. It provides an API as well as native
67
57
  grammar to build the grammar.
68
-
58
+
69
59
  KPeg strives to provide a simple, powerful API without being too exotic.
70
-
60
+
71
61
  KPeg supports direct left recursion of rules via the
72
62
  {OMeta memoization}[http://www.vpri.org/pdf/tr2008003_experimenting.pdf] trick.
73
- email:
63
+ email:
74
64
  - evan@fallingsnow.net
75
- executables:
65
+ executables:
76
66
  - kpeg
77
67
  extensions: []
78
-
79
- extra_rdoc_files:
68
+ extra_rdoc_files:
80
69
  - History.txt
81
70
  - Manifest.txt
82
71
  - README.rdoc
83
- files:
72
+ - examples/phone_number/README.md
73
+ - examples/upper/README.md
74
+ files:
84
75
  - .autotest
76
+ - .travis.yml
85
77
  - History.txt
86
78
  - LICENSE
87
79
  - Manifest.txt
@@ -126,42 +118,35 @@ files:
126
118
  - test/test_kpeg_grammar_renderer.rb
127
119
  - vim/syntax_kpeg/ftdetect/kpeg.vim
128
120
  - vim/syntax_kpeg/syntax/kpeg.vim
121
+ - test/test_kpeg_string_escape.rb
129
122
  - .gemtest
130
123
  homepage: https://github.com/evanphx/kpeg
131
- licenses: []
132
-
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
133
127
  post_install_message:
134
- rdoc_options:
128
+ rdoc_options:
135
129
  - --main
136
130
  - README.rdoc
137
- require_paths:
131
+ require_paths:
138
132
  - lib
139
- required_ruby_version: !ruby/object:Gem::Requirement
140
- none: false
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- hash: 3
145
- segments:
146
- - 0
147
- version: "0"
148
- required_rubygems_version: !ruby/object:Gem::Requirement
149
- none: false
150
- requirements:
151
- - - ">="
152
- - !ruby/object:Gem::Version
153
- hash: 3
154
- segments:
155
- - 0
156
- version: "0"
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
157
143
  requirements: []
158
-
159
144
  rubyforge_project: kpeg
160
- rubygems_version: 1.8.22
145
+ rubygems_version: 2.1.10
161
146
  signing_key:
162
- specification_version: 3
147
+ specification_version: 4
163
148
  summary: KPeg is a simple PEG library for Ruby
164
- test_files:
149
+ test_files:
165
150
  - test/test_kpeg.rb
166
151
  - test/test_kpeg_code_generator.rb
167
152
  - test/test_kpeg_compiled_parser.rb
@@ -169,3 +154,4 @@ test_files:
169
154
  - test/test_kpeg_format_parser_round_trip.rb
170
155
  - test/test_kpeg_grammar.rb
171
156
  - test/test_kpeg_grammar_renderer.rb
157
+ - test/test_kpeg_string_escape.rb