rlsm 0.2.2 → 0.2.3

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.
@@ -2,14 +2,23 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
- bin/rlsm
6
- lib/rlsm.rb
5
+ bin/smon
7
6
  lib/data/monoids.db
8
- lib/rlsm/monoid.rb
7
+ lib/rlsm.rb
9
8
  lib/rlsm/dfa.rb
10
- lib/rlsm/regexp.rb
11
- lib/rlsm/monoid_db.rb
9
+ lib/rlsm/exceptions.rb
12
10
  lib/rlsm/mgen.rb
13
11
  lib/rlsm/monkey_patching.rb
14
- lib/rlsm/exceptions.rb
12
+ lib/rlsm/monoid.rb
13
+ lib/rlsm/monoid_db.rb
14
+ lib/rlsm/regexp.rb
15
+ lib/smon/commands/exit.rb
16
+ lib/smon/commands/help.rb
17
+ lib/smon/commands/intro.rb
18
+ lib/smon/commands/monoid.rb
19
+ lib/smon/commands/quit.rb
20
+ lib/smon/commands/regexp.rb
21
+ lib/smon/commands/reload.rb
22
+ lib/smon/commands/show.rb
23
+ lib/smon/smon.rb
15
24
  test/test_rlsm.rb
data/Rakefile CHANGED
@@ -7,7 +7,6 @@ require './lib/rlsm.rb'
7
7
  Hoe.new('rlsm', RLSM::VERSION) do |p|
8
8
  #p.rubyforge_name = 'rlsm' # if different than lowercase project name
9
9
  p.developer('asmodis', 'g.diemant@gmx.net')
10
- p.extra_deps = ['sqlite3-ruby']
11
10
  end
12
11
 
13
12
  # vim: syntax=Ruby
@@ -0,0 +1,4 @@
1
+ #! /usr/bin/env ruby
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'smon', 'smon')
3
+
4
+ Smon.new
@@ -35,5 +35,5 @@ require "mgen"
35
35
  require "monoid_db"
36
36
 
37
37
  module RLSM
38
- VERSION = "0.2.2"
38
+ VERSION = "0.2.3"
39
39
  end
@@ -36,7 +36,7 @@ class Monoid
36
36
  def initialize(table, options = {})
37
37
  options[:normalize] = true if options[:normalize].nil?
38
38
 
39
- _create_binary_operation(table)
39
+ _create_binary_operation(table, options[:names])
40
40
  _check_form_of_binary_operation
41
41
  _check_associativity_of_binary_operation
42
42
 
@@ -463,7 +463,7 @@ class Monoid
463
463
  res.sort
464
464
  end
465
465
 
466
- def _create_binary_operation(table)
466
+ def _create_binary_operation(table, names)
467
467
  if table.instance_of? Array
468
468
  @order = table.size
469
469
  @bo = table
@@ -485,7 +485,14 @@ class Monoid
485
485
  end
486
486
 
487
487
  #Convert to internal represenation
488
- @names = @bo.flatten.uniq.clone
488
+ #Names given?
489
+ if names and names.class == Array and names.size == @order
490
+ @names = names
491
+ else
492
+ #Make a guess, works if convention is followed.
493
+ @names = @bo.flatten.uniq.clone
494
+ end
495
+
489
496
  @bo = (@bo.flatten.map { |e| @names.index(e) })/@order
490
497
  end
491
498
 
@@ -89,7 +89,7 @@ SQL
89
89
 
90
90
  private
91
91
  def initialize
92
- db_name = File.join(File.dirname(__FILE__), 'data', 'monoids.db')
92
+ db_name = File.join(File.dirname(__FILE__), '..', 'data', 'monoids.db')
93
93
  @db = SQLite3::Database.open(db_name)
94
94
  end
95
95
 
@@ -0,0 +1,9 @@
1
+ #category base
2
+
3
+ =begin help
4
+ A synonym for quit.
5
+
6
+ =end
7
+ def exit
8
+ quit
9
+ end
@@ -0,0 +1,31 @@
1
+ #category help
2
+ =begin help
3
+ Prints help topics.
4
+
5
+ Usage: help "command"
6
+ Prints the help topic for +command+.
7
+ The command name must be surrounded by " (double quote).
8
+ Example: help help -> prints this text.
9
+
10
+ =end
11
+ def help(cmd = nil)
12
+ if cmd.nil?
13
+ puts "Known Commands:"
14
+ Categories.each_pair do |cat, cmds|
15
+ puts " Category #{cat}"
16
+ cmds.each do |cmd|
17
+ puts " #{cmd} : #{(CmdHelp[cmd] || [cmd]).first}"
18
+ end
19
+ end
20
+ puts
21
+ puts 'Type help "command" for more information for "command"'
22
+ puts '(command must be surrounded by double quotes!)'
23
+ puts
24
+ else
25
+ if CmdHelp[cmd]
26
+ puts CmdHelp[cmd].join
27
+ else
28
+ puts " Nothing known about #{cmd}"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ #category help
2
+ =begin help
3
+ Displays a small introduction.
4
+
5
+ Usage: intro
6
+
7
+ Shows some of the rules for work with the program.
8
+ =end
9
+
10
+ def intro
11
+ puts <<INTRO
12
+ ======================
13
+ INTRODUCTION TO SMON
14
+ ======================
15
+
16
+ ==Basic rules
17
+ - Every input, which should be interpreted literally
18
+ must be surrounded by quotes or double quotes.
19
+
20
+ - Parenthesis for commands may be omitted in the most cases.
21
+ When in doubt, write the parenthesis.
22
+
23
+ - Basicly, every valid Ruby command is allowed.
24
+
25
+ ==Basic Usage
26
+ - Type < help > for an overview of availible commands.
27
+
28
+ - If you wanna use variables, just type < @var = ... >.
29
+ The @-sign is important!
30
+
31
+ INTRO
32
+ end
@@ -0,0 +1,27 @@
1
+ #category RLSM
2
+
3
+ =begin help
4
+ Creates a monoid.
5
+
6
+ Usage: monoid desc or monoid(desc)
7
+
8
+ +desc+ is here the description of a binary operation. The form of the
9
+ description follows some simple rules:
10
+ - A binary operation is represented as a quadratic matrix
11
+ - Rows are seperated by ' ' (space)
12
+ - Columns are seperated by ',' (comma)
13
+ The comma may be omitted if every element descriptor is only one
14
+ char.
15
+ - The first row and column belongs to the neutral element.
16
+ - The +desc+ parameter must be surrounded by " (double quote)
17
+
18
+ Examples:
19
+ monoid "1a aa"
20
+ monoid "1ab aab bab"
21
+ monoid "1,a a,1"
22
+ =end
23
+
24
+ def monoid(desc)
25
+ RLSM::Monoid.new desc
26
+ end
27
+
@@ -0,0 +1,10 @@
1
+ #category base
2
+
3
+ =begin help
4
+ Exits the program.
5
+
6
+ =end
7
+ def quit
8
+ puts "Bye."
9
+ @quit = true
10
+ end
@@ -0,0 +1,20 @@
1
+ #category RLSM
2
+ =begin help
3
+ Creates a new Regular Expression.
4
+
5
+ Usage: regexp "desc"
6
+
7
+ +desc+ is here a description of the regexp.
8
+ A regexp may consist of
9
+ - normal characters like a,b,c, 1,2, ...
10
+ - Special characters are
11
+ - & : the emmpty word
12
+ - | : Union
13
+ - ( ) : Grouping of expressions
14
+ - * : Kleene star
15
+
16
+ =end
17
+
18
+ def regexp(desc)
19
+ RLSM::RegExp.new desc
20
+ end
@@ -0,0 +1,22 @@
1
+ #category base
2
+ =begin help
3
+ Reloads a command.
4
+
5
+ Usage: reload "cmd"
6
+
7
+ Unloads the command +cmd+ if it exists, then tries to reload it.
8
+ For reloading, the program searches for an file "cmd.rb" in the load path.
9
+ =end
10
+
11
+ def reload(cmd)
12
+ return false unless Commands.include? cmd
13
+
14
+ #Removes the help entries and the command
15
+ Commands.delete cmd
16
+ CmdHelp.delete cmd
17
+ Categories.each do |cat|
18
+ cat.delete cmd
19
+ end
20
+
21
+ load(File.join(LoadPath, cmd + '.rb'))
22
+ end
@@ -0,0 +1,34 @@
1
+ #category RLSM
2
+ =begin help
3
+ Shows a monoid or a regexp.
4
+
5
+ Usage: show obj
6
+
7
+ +obj+ is either a regexp or a monoid. If regexp a string representation is shown
8
+ if monoid, the binary operation is shown as a table.
9
+ Example: show monoid("0")
10
+ Not working: show "0" !
11
+ =end
12
+
13
+ def show(obj)
14
+ if obj.class == RLSM::Monoid
15
+ rows = obj.binary_operation.map { |row| row.join(' | ')}
16
+ rows.map! { |r| '| ' + r.gsub(/\w/) { |c| obj.elements[c.to_i] } + " |\n" }
17
+ row_sep = rows.first.scan(/./m).map do |c|
18
+ case c
19
+ when '|' : '+'
20
+ when "\n" : "\n"
21
+ else
22
+ '-'
23
+ end
24
+ end.join
25
+
26
+ puts row_sep
27
+ puts rows.join(row_sep)
28
+ puts row_sep
29
+ puts
30
+ else
31
+ puts obj.to_s
32
+ puts
33
+ end
34
+ end
@@ -0,0 +1,80 @@
1
+ require "readline"
2
+ require "abbrev"
3
+ require "rubygems"
4
+ require "rlsm"
5
+
6
+ class Smon
7
+ Commands = []
8
+ CmdHelp = {}
9
+ Categories = {}
10
+ LoadPath = File.join(File.dirname(__FILE__), 'commands')
11
+
12
+ def initialize
13
+ #Load all commands
14
+ cmds = Dir.glob(File.join(LoadPath, '*.rb'))
15
+ cmds.each do |cmd|
16
+ load cmd, false
17
+ end
18
+
19
+ #Add the built-in commands to the help system
20
+ Commands << 'load'
21
+ CmdHelp['load'] = ["Loads a command into the system.\n",
22
+ "\nUsage: load /path/to/cmd\n",
23
+ "\n Loads the file at the given location and prints a small message if loading succeded."]
24
+ Categories['built-in'] = ['load']
25
+
26
+ #Initialize the help system
27
+ @cmd_abbrev = Commands.abbrev
28
+
29
+ #Setting up readline
30
+ Readline.completion_proc do |str|
31
+ @cmd_abbrev[str]
32
+ end
33
+
34
+ loop do
35
+ begin
36
+ instance_eval Readline.readline("rlsm (help for help) :> ", true)
37
+ rescue Exception => e
38
+ puts "Something went wrong."
39
+ puts e
40
+ end
41
+
42
+ break if @quit
43
+ end
44
+ end
45
+
46
+ def load(file, reinit = true)
47
+ #Parsing the file
48
+ cat = nil
49
+ name = nil
50
+ help = []
51
+ parse_help = false
52
+ input = []
53
+ File.open(file).each_line do |line|
54
+ #Extracting the help
55
+ parse_help = false if line =~ Regexp.new("=end.*")
56
+ help << line if parse_help
57
+ parse_help = true if line =~ Regexp.new("=begin.*")
58
+
59
+
60
+ #Getting the category
61
+ cat = $1.dup if line =~ Regexp.new("#category\\s\+\(\\w\+\)")
62
+
63
+ #Getting the name
64
+ name = $1.dup if line =~ /def\s+(\w+)/
65
+
66
+ input << line
67
+ end
68
+
69
+ #Adding the method
70
+ self.class.class_eval input.join
71
+
72
+ #Setting up the help system
73
+ (Categories[cat] ||= []) << name
74
+ Commands << name
75
+ CmdHelp[name] = help
76
+
77
+ @cmd_abbrev = Commands.abbrev if reinit
78
+ end
79
+ end
80
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rlsm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - asmodis
@@ -12,16 +12,6 @@ cert_chain: []
12
12
  date: 2008-11-10 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: sqlite3-ruby
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
15
  - !ruby/object:Gem::Dependency
26
16
  name: hoe
27
17
  type: :development
@@ -36,7 +26,7 @@ description: "This is a ruby implementation of three concepts: - Deterministic F
36
26
  email:
37
27
  - g.diemant@gmx.net
38
28
  executables:
39
- - rlsm
29
+ - smon
40
30
  extensions: []
41
31
 
42
32
  extra_rdoc_files:
@@ -48,16 +38,25 @@ files:
48
38
  - Manifest.txt
49
39
  - README.txt
50
40
  - Rakefile
51
- - bin/rlsm
52
- - lib/rlsm.rb
41
+ - bin/smon
53
42
  - lib/data/monoids.db
54
- - lib/rlsm/monoid.rb
43
+ - lib/rlsm.rb
55
44
  - lib/rlsm/dfa.rb
56
- - lib/rlsm/regexp.rb
57
- - lib/rlsm/monoid_db.rb
45
+ - lib/rlsm/exceptions.rb
58
46
  - lib/rlsm/mgen.rb
59
47
  - lib/rlsm/monkey_patching.rb
60
- - lib/rlsm/exceptions.rb
48
+ - lib/rlsm/monoid.rb
49
+ - lib/rlsm/monoid_db.rb
50
+ - lib/rlsm/regexp.rb
51
+ - lib/smon/commands/exit.rb
52
+ - lib/smon/commands/help.rb
53
+ - lib/smon/commands/intro.rb
54
+ - lib/smon/commands/monoid.rb
55
+ - lib/smon/commands/quit.rb
56
+ - lib/smon/commands/regexp.rb
57
+ - lib/smon/commands/reload.rb
58
+ - lib/smon/commands/show.rb
59
+ - lib/smon/smon.rb
61
60
  - test/test_rlsm.rb
62
61
  has_rdoc: true
63
62
  homepage: http://www.github.com/asmodis/rlsm
data/bin/rlsm DELETED
File without changes