rlsm 1.1.0 → 1.8.1

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/rlsm/regexp.rb CHANGED
@@ -3,6 +3,7 @@ require File.join(File.dirname(__FILE__), 'regexp_parser')
3
3
  require File.join(File.dirname(__FILE__), 'dfa')
4
4
 
5
5
  module RLSM
6
+ # @private
6
7
  class RegExp
7
8
  #Returns a RegExp which is the empty word.
8
9
  def self.empty_word
@@ -27,7 +28,7 @@ module RLSM
27
28
  #
28
29
  #Whitspaces will be ignored and the empty string represents the empty language.
29
30
  def initialize(description)
30
- @parse_tree = RE::Parser[ description ]
31
+ @parse_tree = RLSM::RE::Parser[ description ]
31
32
  @string = @parse_tree.to_s
32
33
  end
33
34
 
@@ -1,6 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  module RLSM
4
+ # @private
4
5
  module RE #:nodoc:
5
6
  module ParserHelpers #:nodoc:
6
7
  OpenBracket = '('
@@ -118,7 +119,7 @@ module RLSM
118
119
  end
119
120
 
120
121
  if unbalanced_brackets?(input)
121
- raise RegExpError, "Parse Error: Unbalanced brackets."
122
+ raise RLSM::Error, "Parse Error: Unbalanced brackets."
122
123
  end
123
124
 
124
125
  parse(input)
data/rlsm.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rake"
4
+ require File.join(File.dirname(__FILE__), 'lib', 'rlsm')
5
+
6
+ Gem::Specification.new do |s|
7
+ s.author = "Gunther Diemant"
8
+ s.email = "g.diemant@gmx.net"
9
+ s.homepage = "http://github.com/asmodis/rlsm"
10
+ s.rubyforge_project = 'rlsm'
11
+
12
+ s.name = 'rlsm'
13
+ s.version = RLSM::VERSION
14
+ s.add_development_dependency('minitest')
15
+ s.add_development_dependency('thoughtbot-shoulda')
16
+ s.summary = "Library for investigating regular languages and syntactic monoids."
17
+ s.description = "see README"
18
+
19
+ s.files = File.open("Manifest").to_a.map { |file| file.strip }
20
+ s.test_files = FileList['test/test_*.rb']
21
+ s.extensions = FileList['ext/**/extconf.rb']
22
+
23
+ s.has_rdoc = true
24
+ s.extra_rdoc_files = ['README']
25
+ s.rdoc_options << '--main' << 'README'
26
+ end
data/test/test_dfa.rb CHANGED
@@ -11,7 +11,7 @@ context "Parsing the description of a DFA." do
11
11
  end
12
12
 
13
13
  test "The empty string is not accepted" do
14
- assert_raises DFAError do
14
+ assert_raises RLSM::Error do
15
15
  RLSM::DFA.new ""
16
16
  end
17
17
  end
@@ -23,13 +23,13 @@ context "Parsing the description of a DFA." do
23
23
  end
24
24
 
25
25
  test "The description must include an initial state indicator." do
26
- assert_raises DFAError do
26
+ assert_raises RLSM::Error do
27
27
  RLSM::DFA.new "s1"
28
28
  end
29
29
  end
30
30
 
31
31
  test "The description may not include more than one initial state." do
32
- assert_raises DFAError do
32
+ assert_raises RLSM::Error do
33
33
  RLSM::DFA.new "}s1-a->}s2"
34
34
  end
35
35
  end
@@ -41,29 +41,29 @@ context "Parsing the description of a DFA." do
41
41
  end
42
42
 
43
43
  test "A transition arrow must have a starting dash." do
44
- assert_raises DFAError do
44
+ assert_raises RLSM::Error do
45
45
  RLSM::DFA.new "}s1 a-> s2"
46
46
  end
47
47
  end
48
48
 
49
49
  test "A transition arrow must have a closing arrow." do
50
- assert_raises DFAError do
50
+ assert_raises RLSM::Error do
51
51
  RLSM::DFA.new "}s1 -a> s2"
52
52
  end
53
53
 
54
- assert_raises DFAError do
54
+ assert_raises RLSM::Error do
55
55
  RLSM::DFA.new "}s1 -a- s2"
56
56
  end
57
57
  end
58
58
 
59
59
  test "A transition must have at least one label." do
60
- assert_raises DFAError do
60
+ assert_raises RLSM::Error do
61
61
  RLSM::DFA.new "}s1 --> s2"
62
62
  end
63
63
  end
64
64
 
65
65
  test "Multiple labels must be seperated by a comma." do
66
- assert_raises DFAError do
66
+ assert_raises RLSM::Error do
67
67
  RLSM::DFA.new "}s1 -a;b-> s2"
68
68
  end
69
69
  end
@@ -75,13 +75,13 @@ context "Parsing the description of a DFA." do
75
75
  end
76
76
 
77
77
  test "A transition must start with a state." do
78
- assert_raises DFAError do
78
+ assert_raises RLSM::Error do
79
79
  RLSM::DFA.new " -a-> }s2"
80
80
  end
81
81
  end
82
82
 
83
83
  test "A transition must end with a state." do
84
- assert_raises DFAError do
84
+ assert_raises RLSM::Error do
85
85
  RLSM::DFA.new "}s1 -a-> "
86
86
  end
87
87
  end
@@ -139,7 +139,7 @@ context "Creation of a DFA." do
139
139
  end
140
140
 
141
141
  test "Transition labels out from one state must be unique" do
142
- assert_raises DFAError do
142
+ assert_raises RLSM::Error do
143
143
  RLSM::DFA.new "}s1 -a-> s2 s1-a->s3"
144
144
  end
145
145
  end
@@ -207,11 +207,11 @@ context "Properties of a state" do
207
207
 
208
208
  test "Arguments for state properties must be states of the DFA." do
209
209
  dfa = RLSM::DFA.new "}s1"
210
- assert_raises DFAError do
210
+ assert_raises RLSM::Error do
211
211
  dfa.dead? "s3"
212
212
  end
213
213
 
214
- assert_raises DFAError do
214
+ assert_raises RLSM::Error do
215
215
  dfa.reachable? "s3"
216
216
  end
217
217
  end
@@ -382,7 +382,7 @@ context "Accepting of words, transition monoid" do
382
382
  end
383
383
 
384
384
  test "Requesting a transition from a nonexistant state." do
385
- assert_raises DFAError do
385
+ assert_raises RLSM::Error do
386
386
  RLSM::DFA.new("}s1")['s2', 'a']
387
387
  end
388
388
  end
@@ -401,6 +401,8 @@ context "Accepting of words, transition monoid" do
401
401
  refute dfa.accepts?("aab")
402
402
  end
403
403
 
404
+
405
+
404
406
  test "Calculating the transition monoid." do
405
407
  dfa = RLSM::DFA.new "}s1-a->s2 s2 -a-> *s3 s3 -b-> s2"
406
408
  expected_monoid = RLSM::Monoid[ <<MONOID
data/test/test_monoid.rb CHANGED
@@ -49,41 +49,41 @@ context "Creation of a monoid:" do
49
49
  end
50
50
 
51
51
  test "Monoid::new : Should reject an empty description." do
52
- assert_raises ArgumentError do
52
+ assert_raises RLSM::Error do
53
53
  RLSM::Monoid[ "" ]
54
54
  end
55
55
  end
56
56
 
57
57
  test "Monoid::new : Should reject a description with only whitespaces." do
58
- assert_raises ArgumentError do
58
+ assert_raises RLSM::Error do
59
59
  RLSM::Monoid[ " \t\n" ]
60
60
  end
61
61
  end
62
62
 
63
63
  test "Monoid::new : Description should describe a quadratic matrix." do
64
- assert_raises ParseError do
64
+ assert_raises RLSM::Error do
65
65
  RLSM::Monoid[ "012 120 20" ]
66
66
  end
67
67
  end
68
68
 
69
69
  test "Monoid::new : Described n x n - matrix should contain n symbols." do
70
- assert_raises ParseError do
70
+ assert_raises RLSM::Error do
71
71
  RLSM::Monoid[ "123 456 789" ]
72
72
  end
73
73
 
74
- assert_raises ParseError do
74
+ assert_raises RLSM::Error do
75
75
  RLSM::Monoid[ "000 000 000" ]
76
76
  end
77
77
  end
78
78
 
79
79
  test "Monoid::new : Identity should be first row and column." do
80
- assert_raises MonoidError do
80
+ assert_raises RLSM::Error do
81
81
  RLSM::Monoid[ "00 01" ]
82
82
  end
83
83
  end
84
84
 
85
85
  test "Monoid::new : Described monoid should be associative." do
86
- assert_raises BinOpError do
86
+ assert_raises RLSM::Error do
87
87
  RLSM::Monoid[ "012 100 200" ]
88
88
  end
89
89
  end
@@ -96,7 +96,7 @@ context "Creation of a monoid:" do
96
96
  end
97
97
 
98
98
  test "Monoid::new : Column seperators must either be used or not in a row." do
99
- assert_raises ParseError do
99
+ assert_raises RLSM::Error do
100
100
  RLSM::Monoid[ "0,12 120 201" ]
101
101
  end
102
102
  end
@@ -116,11 +116,11 @@ context "Multiplication of elements:" do
116
116
  end
117
117
 
118
118
  test "Monoid#[] : Should require at least two arguments." do
119
- assert_raises ArgumentError do
119
+ assert_raises RLSM::Error do
120
120
  @monoid["2"]
121
121
  end
122
122
 
123
- assert_raises ArgumentError do
123
+ assert_raises RLSM::Error do
124
124
  @monoid[]
125
125
  end
126
126
  end
@@ -134,7 +134,7 @@ context "Multiplication of elements:" do
134
134
 
135
135
 
136
136
  test "Monoid#[] : Should raise BinOpError for unknown elements." do
137
- assert_raises ArgumentError do
137
+ assert_raises RLSM::Error do
138
138
  @monoid["1","3"]
139
139
  end
140
140
  end
@@ -201,7 +201,7 @@ context "Generating submonoids:" do
201
201
  test "Monoid#generated_set : Should raise BinOpError for unknown elements." do
202
202
  m1 = RLSM::Monoid[ "0123 1203 2013 3333" ]
203
203
 
204
- assert_raises ArgumentError do
204
+ assert_raises RLSM::Error do
205
205
  m1.generated_set(["4"])
206
206
  end
207
207
  end
@@ -507,45 +507,45 @@ context "Iterator: " do
507
507
  i = 0
508
508
  RLSM::Monoid.each(3) { i += 1 }
509
509
 
510
- assert_equal 6, i
510
+ assert_equal 6, i, "order3"
511
511
 
512
512
  i = 0
513
513
  RLSM::Monoid.each(4) { i += 1 }
514
514
 
515
- assert_equal 27, i
515
+ assert_equal 27, i, "order4"
516
516
 
517
517
  i = 0
518
518
  RLSM::Monoid.each(5) { i += 1 }
519
519
 
520
- assert_equal 156, i
521
-
522
- order4 = [RLSM::Monoid[ '0123 1032 2301 3210' ],
523
- RLSM::Monoid[ '0123 1032 2310 3201' ],
524
- RLSM::Monoid[ '0123 1023 2222 3322' ],
525
- RLSM::Monoid[ '0123 1023 2223 3332' ],
526
- RLSM::Monoid[ '0123 1032 2323 3232' ],
527
- RLSM::Monoid[ '0123 1023 2222 3323' ],
528
- RLSM::Monoid[ '0123 1023 2222 3333' ],
529
- RLSM::Monoid[ '0123 1023 2323 3223' ],
530
- RLSM::Monoid[ '0123 1111 2111 3111' ],
531
- RLSM::Monoid[ '0123 1113 2113 3331' ],
532
- RLSM::Monoid[ '0123 1122 2211 3211' ],
533
- RLSM::Monoid[ '0123 1111 2111 3112' ],
534
- RLSM::Monoid[ '0123 1111 2111 3113' ],
535
- RLSM::Monoid[ '0123 1111 2111 3123' ],
536
- RLSM::Monoid[ '0123 1111 2111 3333' ],
537
- RLSM::Monoid[ '0123 1111 2112 3123' ],
538
- RLSM::Monoid[ '0123 1113 2113 3333' ],
539
- RLSM::Monoid[ '0123 1121 2212 3123' ],
540
- RLSM::Monoid[ '0123 1123 2213 3333' ],
541
- RLSM::Monoid[ '0123 1111 2121 3113' ],
542
- RLSM::Monoid[ '0123 1111 2121 3333' ],
543
- RLSM::Monoid[ '0123 1111 2122 3123' ],
544
- RLSM::Monoid[ '0123 1111 2122 3133' ],
545
- RLSM::Monoid[ '0123 1111 2123 3333' ],
546
- RLSM::Monoid[ '0123 1111 2222 3333' ],
547
- RLSM::Monoid[ '0123 1111 2130 3102' ],
548
- RLSM::Monoid['0123 1123 2231 3312']]
520
+ assert_equal 156, i, "order5"
521
+
522
+ order4 = [RLSM::Monoid[ [0,1,2,3,1,0,3,2,2,3,0,1,3,2,1,0] ],
523
+ RLSM::Monoid[ [0,1,2,3,1,0,3,2,2,3,1,0,3,2,0,1] ],
524
+ RLSM::Monoid[ [0,1,2,3,1,0,2,3,2,2,2,2,3,3,2,2] ],
525
+ RLSM::Monoid[ [0,1,2,3,1,0,2,3,2,2,2,3,3,3,3,2] ],
526
+ RLSM::Monoid[ [0,1,2,3,1,0,3,2,2,3,2,3,3,2,3,2] ],
527
+ RLSM::Monoid[ [0,1,2,3,1,0,2,3,2,2,2,2,3,3,2,3] ],
528
+ RLSM::Monoid[ [0,1,2,3,1,0,2,3,2,2,2,2,3,3,3,3] ],
529
+ RLSM::Monoid[ [0,1,2,3,1,0,2,3,2,3,2,3,3,2,2,3] ],
530
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,1,1,3,1,1,1] ],
531
+ RLSM::Monoid[ [0,1,2,3,1,1,1,3,2,1,1,3,3,3,3,1] ],
532
+ RLSM::Monoid[ [0,1,2,3,1,1,2,2,2,2,1,1,3,2,1,1] ],
533
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,1,1,3,1,1,2] ],
534
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,1,1,3,1,1,3] ],
535
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,1,1,3,1,2,3] ],
536
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,1,1,3,3,3,3] ],
537
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,1,2,3,1,2,3] ],
538
+ RLSM::Monoid[ [0,1,2,3,1,1,1,3,2,1,1,3,3,3,3,3] ],
539
+ RLSM::Monoid[ [0,1,2,3,1,1,2,1,2,2,1,2,3,1,2,3] ],
540
+ RLSM::Monoid[ [0,1,2,3,1,1,2,3,2,2,1,3,3,3,3,3] ],
541
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,2,1,3,1,1,3] ],
542
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,2,1,3,3,3,3] ],
543
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,2,2,3,1,2,3] ],
544
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,2,2,3,1,3,3] ],
545
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,2,3,3,3,3,3] ],
546
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,2,2,2,3,3,3,3] ],
547
+ RLSM::Monoid[ [0,1,2,3,1,1,1,1,2,1,3,0,3,1,0,2] ],
548
+ RLSM::Monoid[ [0,1,2,3,1,1,2,3,2,2,3,1,3,3,1,2] ]]
549
549
 
550
550
  RLSM::Monoid.each(4) { |m| assert order4.include? m }
551
551
  end
data/test/test_regexp.rb CHANGED
@@ -19,11 +19,11 @@ context "Parsing of a regexp:" do
19
19
  end
20
20
 
21
21
  test "RegExp::new : Should check that parentheses are balanced." do
22
- assert_raises RegExpError do
22
+ assert_raises RLSM::Error do
23
23
  RLSM::RegExp.new "(ab(cUd)"
24
24
  end
25
25
 
26
- assert_raises RegExpError do
26
+ assert_raises RLSM::Error do
27
27
  RLSM::RegExp.new "ab)((cUd)"
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rlsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ hash: 53
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 8
9
+ - 1
10
+ version: 1.8.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Gunther Diemant
@@ -9,116 +15,73 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-10-09 00:00:00 +02:00
18
+ date: 2010-09-02 00:00:00 +02:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: minitest
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
23
32
  version: "0"
24
- version:
33
+ type: :development
34
+ version_requirements: *id001
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: thoughtbot-shoulda
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
30
40
  requirements:
31
41
  - - ">="
32
42
  - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
33
46
  version: "0"
34
- version:
35
- description: |+
36
- = rlsm
37
- rlsm stands for *R*egular *L*anguages and *S*yntactic *M*onoids.
38
-
39
- Source is availible from
40
- http://github.com/asmodis/rlsm
41
-
42
- RDoc-Documentation is availible from
43
- http://rlsm.rubyforge.org
44
-
45
- == DESCRIPTION:
46
-
47
- This is a ruby implementation of three concepts:
48
- - Deterministic Finite Automata
49
- - Regular Expressions (in the sense of theoretical computer sience)
50
- - Monoids
51
-
52
-
53
- == SYNOPSIS:
54
-
55
- require 'rlsm'
56
-
57
- m = RLSM::Monoid.new '012 112 212'
58
- m.syntactic? # => true
59
- m.isomorph_to?(m) # => true
60
- m.commutative? # => false
61
-
62
- == INSTALL:
63
-
64
- gem install rlsm
65
-
66
-
67
- == LICENSE:
68
-
69
- (The MIT License)
70
-
71
- Copyright (c) 2009 Gunther Diemant <g.diemant@gmx.net>
72
-
73
- Permission is hereby granted, free of charge, to any person obtaining
74
- a copy of this software and associated documentation files (the
75
- 'Software'), to deal in the Software without restriction, including
76
- without limitation the rights to use, copy, modify, merge, publish,
77
- distribute, sublicense, and/or sell copies of the Software, and to
78
- permit persons to whom the Software is furnished to do so, subject to
79
- the following conditions:
80
-
81
- The above copyright notice and this permission notice shall be
82
- included in all copies or substantial portions of the Software.
83
-
84
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
85
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
86
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
87
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
88
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
89
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
90
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
91
-
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: see README
92
50
  email: g.diemant@gmx.net
93
51
  executables: []
94
52
 
95
53
  extensions:
96
54
  - ext/array/extconf.rb
97
- - ext/binop/extconf.rb
98
55
  - ext/monoid/extconf.rb
99
56
  extra_rdoc_files:
100
57
  - README
101
58
  files:
102
- - lib/rlsm/binary_operation.rb
103
- - lib/rlsm/dfa.rb
59
+ - Rakefile
60
+ - Manifest
61
+ - README
62
+ - rlsm.gemspec
63
+ - lib/rlsm.rb
104
64
  - lib/rlsm/helper.rb
105
65
  - lib/rlsm/monoid.rb
66
+ - lib/rlsm/dfa.rb
106
67
  - lib/rlsm/regexp.rb
107
68
  - lib/rlsm/regexp_parser.rb
108
- - lib/rlsm.rb
109
- - ext/array/array_c_ext.c
110
- - ext/binop/binop_c_ext.c
69
+ - ext/monoid/extconf.rb
111
70
  - ext/monoid/monoid_c_ext.c
112
71
  - ext/array/extconf.rb
113
- - ext/binop/extconf.rb
114
- - ext/monoid/extconf.rb
72
+ - ext/array/array_c_ext.c
115
73
  - test/helpers.rb
116
- - test/test_binop.rb
117
- - test/test_dfa.rb
118
74
  - test/test_monoid.rb
75
+ - test/test_dfa.rb
119
76
  - test/test_regexp.rb
120
- - Rakefile
121
- - README
77
+ - data/monoids.db
78
+ - examples/creating_db.rb
79
+ - examples/creating_lists.rb
80
+ - examples/presenting_monoids_in_tex.rb
81
+ - examples/regular_monoids.rb
82
+ - examples/order8.rb
83
+ - examples/benchmark.rb
84
+ - examples/numbers.rb
122
85
  has_rdoc: true
123
86
  homepage: http://github.com/asmodis/rlsm
124
87
  licenses: []
@@ -130,26 +93,31 @@ rdoc_options:
130
93
  require_paths:
131
94
  - lib
132
95
  required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
133
97
  requirements:
134
98
  - - ">="
135
99
  - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
136
103
  version: "0"
137
- version:
138
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
139
106
  requirements:
140
107
  - - ">="
141
108
  - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
142
112
  version: "0"
143
- version:
144
113
  requirements: []
145
114
 
146
115
  rubyforge_project: rlsm
147
- rubygems_version: 1.3.5
116
+ rubygems_version: 1.3.7
148
117
  signing_key:
149
118
  specification_version: 3
150
119
  summary: Library for investigating regular languages and syntactic monoids.
151
120
  test_files:
152
- - test/test_binop.rb
153
121
  - test/test_dfa.rb
154
122
  - test/test_monoid.rb
155
123
  - test/test_regexp.rb