reg 0.4.8 → 0.5.0a0

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.
Files changed (64) hide show
  1. checksums.yaml +4 -0
  2. data/COPYING +0 -0
  3. data/History.txt +14 -0
  4. data/Makefile +59 -0
  5. data/README +87 -40
  6. data/article.txt +838 -0
  7. data/{assert.rb → lib/assert.rb} +3 -3
  8. data/{reg.rb → lib/reg.rb} +11 -4
  9. data/lib/reg/version.rb +21 -0
  10. data/lib/regarray.rb +455 -0
  11. data/{regarrayold.rb → lib/regarrayold.rb} +33 -7
  12. data/lib/regbackref.rb +73 -0
  13. data/lib/regbind.rb +230 -0
  14. data/{regcase.rb → lib/regcase.rb} +15 -5
  15. data/lib/regcompiler.rb +2341 -0
  16. data/{regcore.rb → lib/regcore.rb} +196 -85
  17. data/{regdeferred.rb → lib/regdeferred.rb} +35 -4
  18. data/{regposition.rb → lib/regevent.rb} +36 -38
  19. data/lib/reggraphpoint.rb +28 -0
  20. data/lib/reghash.rb +631 -0
  21. data/lib/reginstrumentation.rb +36 -0
  22. data/{regitem_that.rb → lib/regitem_that.rb} +32 -11
  23. data/{regknows.rb → lib/regknows.rb} +4 -2
  24. data/{reglogic.rb → lib/reglogic.rb} +76 -59
  25. data/{reglookab.rb → lib/reglookab.rb} +31 -21
  26. data/lib/regmatchset.rb +323 -0
  27. data/{regold.rb → lib/regold.rb} +27 -27
  28. data/{regpath.rb → lib/regpath.rb} +91 -1
  29. data/lib/regposition.rb +79 -0
  30. data/lib/regprogress.rb +1522 -0
  31. data/lib/regrepeat.rb +307 -0
  32. data/lib/regreplace.rb +254 -0
  33. data/lib/regslicing.rb +581 -0
  34. data/lib/regsubseq.rb +72 -0
  35. data/lib/regsugar.rb +361 -0
  36. data/lib/regvar.rb +180 -0
  37. data/lib/regxform.rb +212 -0
  38. data/{trace.rb → lib/trace_during.rb} +6 -4
  39. data/lib/warning.rb +37 -0
  40. data/parser.txt +26 -8
  41. data/philosophy.txt +18 -0
  42. data/reg.gemspec +58 -25
  43. data/regguide.txt +18 -0
  44. data/test/andtest.rb +46 -0
  45. data/test/regcompiler_test.rb +346 -0
  46. data/test/regdemo.rb +20 -0
  47. data/{item_thattest.rb → test/regitem_thattest.rb} +2 -2
  48. data/test/regtest.rb +2125 -0
  49. data/test/test_all.rb +32 -0
  50. data/test/test_reg.rb +19 -0
  51. metadata +108 -73
  52. data/calc.reg +0 -73
  53. data/forward_to.rb +0 -49
  54. data/numberset.rb +0 -200
  55. data/regarray.rb +0 -675
  56. data/regbackref.rb +0 -126
  57. data/regbind.rb +0 -74
  58. data/reggrid.csv +1 -2
  59. data/reghash.rb +0 -318
  60. data/regprogress.rb +0 -1054
  61. data/regreplace.rb +0 -114
  62. data/regsugar.rb +0 -230
  63. data/regtest.rb +0 -1078
  64. data/regvar.rb +0 -76
@@ -0,0 +1,32 @@
1
+ =begin copyright
2
+ reg - the ruby extended grammar
3
+ Copyright (C) 2016 Caleb Clausen
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License as published by the Free Software Foundation; either
8
+ version 2.1 of the License, or (at your option) any later version.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ =end
19
+ $:.push File.expand_path(__FILE__+"/../..")
20
+ require 'test/test_reg'
21
+ require 'test/regitem_thattest'
22
+ $:.pop
23
+
24
+ class Array
25
+
26
+ alias to_s_without_warn to_s
27
+
28
+ def to_s
29
+ warn "calling Array#to_s from #{caller[0]}; but semantics have changed in 1.9"
30
+ to_s_without_warn
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ =begin copyright
2
+ reg - the ruby extended grammar
3
+ Copyright (C) 2016 Caleb Clausen
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License as published by the Free Software Foundation; either
8
+ version 2.1 of the License, or (at your option) any later version.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ =end
19
+ require 'test/regtest'
metadata CHANGED
@@ -1,95 +1,130 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: reg
3
- version: !ruby/object:Gem::Version
4
- version: 0.4.8
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0a0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Caleb Clausen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2010-01-03 00:00:00 -08:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
16
14
  name: sequence
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: Ron
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.2
17
34
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
21
38
  - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 0.2.3
24
- version:
25
- description:
26
- email: caleb @at@ inforadical.net
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.2
41
+ description: "Reg is a library for pattern matching in ruby data structures. Reg provides
42
+ \nRegexp-like match and match-and-replace for all data structures (particularly\nArrays,
43
+ Objects, and Hashes), not just Strings. \n\nReg is best thought of in analogy to
44
+ regular expressions; Regexps are special\ndata structures for matching Strings;
45
+ Regs are special data structures for\nmatching ANY type of ruby data (Strings included,
46
+ using Regexps). \n\n"
47
+ email: caleb (at) inforadical (dot) net
27
48
  executables: []
28
-
29
49
  extensions: []
30
-
31
- extra_rdoc_files: []
32
-
33
- files:
34
- - item_thattest.rb
35
- - regbackref.rb
36
- - regknows.rb
37
- - regtest.rb
38
- - numberset.rb
39
- - regbind.rb
40
- - reglogic.rb
41
- - regvar.rb
50
+ extra_rdoc_files:
51
+ - README
42
52
  - COPYING
43
- - parser.txt
44
- - regcase.rb
45
- - reglookab.rb
53
+ files:
54
+ - COPYING
55
+ - History.txt
56
+ - Makefile
46
57
  - README
47
- - regcore.rb
48
- - regold.rb
49
- - reg.gemspec
50
- - reggrid.csv
51
- - assert.rb
58
+ - article.txt
59
+ - lib/assert.rb
60
+ - lib/reg.rb
61
+ - lib/reg/version.rb
62
+ - lib/regarray.rb
63
+ - lib/regarrayold.rb
64
+ - lib/regbackref.rb
65
+ - lib/regbind.rb
66
+ - lib/regcase.rb
67
+ - lib/regcompiler.rb
68
+ - lib/regcore.rb
69
+ - lib/regdeferred.rb
70
+ - lib/regevent.rb
71
+ - lib/reggraphpoint.rb
72
+ - lib/reghash.rb
73
+ - lib/reginstrumentation.rb
74
+ - lib/regitem_that.rb
75
+ - lib/regknows.rb
76
+ - lib/reglogic.rb
77
+ - lib/reglookab.rb
78
+ - lib/regmatchset.rb
79
+ - lib/regold.rb
80
+ - lib/regpath.rb
81
+ - lib/regposition.rb
82
+ - lib/regprogress.rb
83
+ - lib/regrepeat.rb
84
+ - lib/regreplace.rb
85
+ - lib/regslicing.rb
86
+ - lib/regsubseq.rb
87
+ - lib/regsugar.rb
88
+ - lib/regvar.rb
89
+ - lib/regxform.rb
90
+ - lib/trace_during.rb
91
+ - lib/warning.rb
92
+ - parser.txt
52
93
  - philosophy.txt
53
- - regdeferred.rb
54
- - regpath.rb
55
- - regposition.rb
56
- - trace.rb
57
- - calc.reg
58
- - reg.rb
94
+ - reg.gemspec
59
95
  - regguide.txt
60
- - regprogress.rb
61
- - reghash.rb
62
- - regreplace.rb
63
- - forward_to.rb
64
- - regarray.rb
65
- - regarrayold.rb
66
- - regitem_that.rb
67
- - regsugar.rb
68
- has_rdoc: false
96
+ - test/andtest.rb
97
+ - test/regcompiler_test.rb
98
+ - test/regdemo.rb
99
+ - test/regitem_thattest.rb
100
+ - test/regtest.rb
101
+ - test/test_all.rb
102
+ - test/test_reg.rb
69
103
  homepage: http://github.com/coatl/reg
104
+ licenses:
105
+ - LGPL-2.1
106
+ metadata: {}
70
107
  post_install_message:
71
- rdoc_options: []
72
-
73
- require_paths:
74
- - .
75
- required_ruby_version: !ruby/object:Gem::Requirement
76
- requirements:
108
+ rdoc_options:
109
+ - "--main"
110
+ - README
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
77
115
  - - ">="
78
- - !ruby/object:Gem::Version
79
- version: "0"
80
- version:
81
- required_rubygems_version: !ruby/object:Gem::Requirement
82
- requirements:
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
83
120
  - - ">="
84
- - !ruby/object:Gem::Version
85
- version: "0"
86
- version:
87
- requirements:
88
- - none
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
89
124
  rubyforge_project: reg
90
- rubygems_version: 1.3.1
125
+ rubygems_version: 2.5.1
91
126
  signing_key:
92
127
  specification_version: 2
93
- summary: The reg pattern matching/replacement language
94
- test_files: []
95
-
128
+ summary: Reg is a library for pattern matching in ruby data structures.
129
+ test_files:
130
+ - test/test_all.rb
data/calc.reg DELETED
@@ -1,73 +0,0 @@
1
- =begin copyright
2
- reg - the ruby extended grammar
3
- Copyright (C) 2005 Caleb Clausen
4
-
5
- This library is free software; you can redistribute it and/or
6
- modify it under the terms of the GNU Lesser General Public
7
- License as published by the Free Software Foundation; either
8
- version 2.1 of the License, or (at your option) any later version.
9
-
10
- This library is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- Lesser General Public License for more details.
14
-
15
- You should have received a copy of the GNU Lesser General Public
16
- License along with this library; if not, write to the Free Software
17
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
- =end
19
- require 'reg'
20
-
21
- #warning: this code is untested
22
- #currently, it will not work because it depends on
23
- #features of reg which do not exist (backreferences and substitutions). in addition,
24
- #it is likely to contain serious bugs, as it has
25
- #not been thoroughly tested or assured in any way.
26
- #nevertheless, it should give you a good idea of
27
- #how this sort of thing works.
28
-
29
-
30
- precedence={
31
- :'('=>10, :p=>10,
32
- :* =>9, :/ =>9,
33
- :+ =>8, :- =>8,
34
- :'='=>7,
35
- :';'=>6
36
- }
37
- name=String.reg
38
- exp=name|PrintExp|OpExp|AssignExp|Number #definitions of the expression classes ommitted for brevity
39
- leftop=/^[*\/;+-]$/
40
- rightop=/^=$/
41
- op=leftop|rightop
42
- def lowerop opname
43
- regproc{
44
- leftop & proceq(Symbol) {|v| precedence[opname] >= precedence[v] }
45
- }
46
- end
47
-
48
- #last element is always lookahead
49
- Reduce=
50
- -[ -[:p, '(', exp, ')'].sub {PrintExp.new BR[2]}, OB ] | # p(exp)
51
- -[ -['(', exp, ')'] .sub {BR[1]}, OB ] | # (exp)
52
- -[ -[exp, leftop, exp] .sub {OpExp.new *BR[0..2]}, lowerop(BR[1]) ] | # exp+exp
53
- -[ exp, -[';'] .sub [], :EOI ] | #elide final trailing ;
54
- -[ -[name, '=', exp] .sub {AssignExp.new BR[0],BR[2]}, lowerop('=') ] #name=exp
55
-
56
- #last element of stack is always lookahead
57
- def reduceloop(stack)
58
- old_stack=stack
59
- while stack.match +[OBS, Reduce]
60
- end
61
- stack.equal? old_stack or raise 'error'
62
- end
63
-
64
- #last element of stack is always lookahead
65
- def parse(input)
66
- input<<:EOI
67
- stack=[input.shift]
68
- until input.empty? and +[OB,:EOI]===stack
69
- stack.push input.shift #shift
70
- reduceloop stack
71
- end
72
- return stack.first
73
- end
@@ -1,49 +0,0 @@
1
- =begin copyright
2
- reg - the ruby extended grammar
3
- Copyright (C) 2005,2009 Caleb Clausen
4
-
5
- This library is free software; you can redistribute it and/or
6
- modify it under the terms of the GNU Lesser General Public
7
- License as published by the Free Software Foundation; either
8
- version 2.1 of the License, or (at your option) any later version.
9
-
10
- This library is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- Lesser General Public License for more details.
14
-
15
- You should have received a copy of the GNU Lesser General Public
16
- License along with this library; if not, write to the Free Software
17
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
- =end
19
- module Kernel
20
- #forward or delegate one or more methods to
21
- #something else. this is sort of like aliasing
22
- #a method, but the receiver can be changed as well.
23
- #target is where the methods are forwarded to.
24
- #(the new receiver.)
25
- #it may be a Module or Class or a String or Symbol
26
- #containing the name of an instance, class, or
27
- #global variable. actually, the target string
28
- #may contain any code (to be evaluated in the context
29
- #of an object of the current class).
30
- #multiple names to forward may be provided. if the
31
- #hash slot is used, it may contain methods whose
32
- #names are changed while forwarding, in the form
33
- # :localname=>:targetname
34
- protected
35
- def forward_to(target,*names)
36
- Module===target and target="::#{target}"
37
-
38
- eval names.pop.map{|myname,targetname|
39
- "def #{myname}(*args,&block) (#{target}).#{targetname}(*args,&block) end\n"
40
- }.join if Hash===names.last
41
- eval names.map{|name|
42
- "def #{name}(*args,&block) (#{target}).#{name}(*args,&block) end\n"
43
- }.join
44
- end
45
- end
46
-
47
- class Module
48
- public :forward_to
49
- end
@@ -1,200 +0,0 @@
1
- =begin copyright
2
- reg - the ruby extended grammar
3
- Copyright (C) 2005 Caleb Clausen
4
-
5
- This library is free software; you can redistribute it and/or
6
- modify it under the terms of the GNU Lesser General Public
7
- License as published by the Free Software Foundation; either
8
- version 2.1 of the License, or (at your option) any later version.
9
-
10
- This library is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- Lesser General Public License for more details.
14
-
15
- You should have received a copy of the GNU Lesser General Public
16
- License along with this library; if not, write to the Free Software
17
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
- =end
19
- require "forward_to"
20
-
21
- SpaceshipPirate=proc{
22
- alias spaceship__withoutpirates <=>
23
- def <=>(other)
24
- if NumberSet::Part===other
25
- res=other<=>self
26
- res and -res
27
- else
28
- spaceship__withoutpirates other
29
- end
30
- end
31
- }
32
-
33
-
34
- [Fixnum,Bignum,Float].each{|cl| cl.instance_eval SpaceshipPirate }
35
-
36
- class NumberSet
37
-
38
- def initialize(*pieces)
39
- pieces.map {|r| self.insert r}
40
- end
41
- class<<self
42
- alias [] new
43
- end
44
-
45
- forward_to :@pieces, :[]
46
-
47
- def insert
48
- mid=high-low/2
49
- case
50
- end
51
-
52
- def ===(num)
53
- @pieces.empty? and return
54
-
55
- low,high=0,@pieces.size-1
56
-
57
- loop {
58
- case num <=> @pieces[mid=high-low/2]
59
- when 1: low=mid+1
60
- when 0: return true
61
- when -1: high=mid-1
62
- when nil: return false
63
- else fail "didn't expect anything else from <=>"
64
- end
65
- (-1..1)===high-low and
66
- }
67
- end
68
-
69
- class Part
70
- def initialize
71
- abstract
72
- end
73
-
74
- def ===
75
- abstract
76
- end
77
-
78
- def first
79
- abstract
80
- end
81
-
82
- def last
83
- abstract
84
- end
85
-
86
- def <=>(other)
87
- if Part===other
88
- result=(self<=>other.first)
89
- return(result == (self<=>other.last) and result)
90
- end
91
-
92
- if first> other: -1
93
- elsif last < other: 1
94
- elsif self===other: 0
95
- end
96
- #else other's in our range, but not in the bitset, what else to do?
97
- end
98
-
99
- end
100
-
101
- class Range < Part
102
- include Enumerable
103
-
104
- def initialize(first,last=nil,exclude_end=nil)
105
- last or first,last,exclude_end=first.first,first.last,first.exclude_end?
106
- @first,@last,@exclude_end=first,last,exclude_end||nil
107
- end
108
- class <<self; alias [] new; end
109
-
110
- attr_reader :first,:last
111
- alias begin first
112
- alias end last
113
-
114
- def exclude_end?; @exclude_end end
115
-
116
- def ===(num)
117
- lt=@exclude_end && :< || :<=
118
- num>=@first and num.send lt,@last
119
- end
120
- alias member? ===
121
- alias include? ===
122
-
123
- def to_s
124
- "#{@first}..#{@exclude_end && "."}#{@last}"
125
- end
126
- alias inspect to_s
127
-
128
- def eql?(other)
129
- Range===other||::Range===other and
130
- @first.eql? other.first and
131
- @last.eql? other.last and
132
- @exclude_end==other.exclude_end?
133
- end
134
-
135
- def each
136
- item=@first
137
- until item==@last
138
- yield item
139
- item=item.succ!
140
- end
141
- yield item unless @exclude_end
142
- return self
143
- end
144
-
145
- def step(skipcnt)
146
- item=@first
147
- cnt=1
148
- until item==@last
149
- if (cnt-=1).zero?
150
- cnt=skipcnt
151
- yield item
152
- end
153
- item=item.succ!
154
- end
155
- yield item unless @exclude_end || cnt!=1
156
- return self
157
- end
158
- end
159
-
160
-
161
- class Fragment < Part
162
- include Enumerable
163
-
164
- attr_reader :base, :bits
165
-
166
-
167
- def begin
168
- assert @bits[0].nonzero?
169
- @base+@bits[0].ffs-1
170
- end
171
-
172
- def end
173
- assert @bits[-1].fls.nonzero?
174
- @base+ (@bits.length-1)*8 + @bits[-1].fls-1
175
- end
176
-
177
- alias first begin
178
- alias last end
179
-
180
- def ===(num)
181
- num-=@base
182
- num<0 and return false
183
- bitidx=num&7
184
- byteidx=(num&~7)>>3
185
- (@bits[byteidx]&(1<<bitidx)).nonzero?
186
- end
187
-
188
- def each
189
- (0...@bits.size).each{|idx|
190
- bits=@bits[idx]
191
- until bits.zero?
192
- bit=bits.ffs-1
193
- yield @base + idx*8 + bit
194
- bits &= ~(1<<bit)
195
- end
196
- }
197
- return self
198
- end
199
- end
200
- end