fa 0.1.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: 4b7eae1d9e0955a9ef22ede62cdf480030dbf27f
4
+ data.tar.gz: 2cb62222893579c9b18c61a550d90722417583f6
5
+ SHA512:
6
+ metadata.gz: 6b4644001fd36dac35f6f0c033a510e8b14e448ae615ec0bb3d74094277c3ed025b95ae6226fca3687611f31631e644a1e95b925fe91d6e46ddde83e014ae9fb
7
+ data.tar.gz: 0aa3a9e2338f14cb695d39a0873075c49a84f4adb05c6d749159c1869c679c8ffd83d5d457beb3f083061833cf887debda4cf7b8fbc8971c213ebcbca06d91da
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
data/AUTHORS ADDED
@@ -0,0 +1,3 @@
1
+ Written by:
2
+
3
+ David Lutterkort <lutter@watzmann.net>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fa.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 David Lutterkort
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # Fa
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fa`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'fa'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fa
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fa.
36
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fa"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fa/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fa"
8
+ spec.version = Fa::VERSION
9
+ spec.authors = ["David Lutterkort\n"]
10
+ spec.email = ["lutter@watzmann.net"]
11
+ spec.licenses = ["MIT"]
12
+
13
+ spec.summary = %q{Bindings for libfa, a library for computing with regular expressions.}
14
+ spec.description = <<EOS
15
+ Bindings for libfa, a library to manipulate finite automata. Automata are
16
+ constructed from regular expressions, using extended POSIX syntax, and make
17
+ it possible to compute interesting things like the intersection of two
18
+ regular expressions (all strings matched by both), or the complement of a
19
+ regular expression (all strings _not_ matched by the regular
20
+ expression). It is possible to convert from regular expression (compile) to
21
+ finite automaton, and from finite automaton to regular expression
22
+ (as_regexp)
23
+ EOS
24
+ spec.homepage = "https://github.com/lutter/ruby-fa"
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "ffi"
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.14"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "minitest", "~> 5.0"
38
+ end
@@ -0,0 +1,117 @@
1
+ require "fa/version"
2
+ require "fa/ffi"
3
+
4
+ module Fa
5
+ class Error < StandardError; end
6
+
7
+ class OutOfMemoryError < Error; end
8
+
9
+ class Automaton < ::FFI::AutoPointer
10
+ attr_reader :faptr
11
+
12
+ def initialize(faptr)
13
+ @faptr = faptr
14
+ end
15
+
16
+ def minimize
17
+ r = FFI::minimize(faptr)
18
+ raise Error if r < 0
19
+ self
20
+ end
21
+
22
+ def concat(other)
23
+ from_ptr( FFI::concat(faptr, other.faptr) )
24
+ end
25
+
26
+ def union(other)
27
+ from_ptr( FFI::union(faptr, other.faptr) )
28
+ end
29
+
30
+ def iter(min, max)
31
+ from_ptr( FFI::iter(faptr, min, max) )
32
+ end
33
+
34
+ def star
35
+ iter(0, -1)
36
+ end
37
+
38
+ def plus
39
+ iter(1, -1)
40
+ end
41
+
42
+ def maybe
43
+ iter(0, 1)
44
+ end
45
+
46
+ def intersect(other)
47
+ from_ptr( FFI::intersect(faptr, other.faptr) )
48
+ end
49
+
50
+ def minus(other)
51
+ from_ptr( FFI::minus(faptr, other.faptr) )
52
+ end
53
+
54
+ def complement
55
+ from_ptr( FFI::complement(faptr) )
56
+ end
57
+
58
+ def equals(other)
59
+ r = FFI::equals(faptr, other.faptr)
60
+ raise Error if r < 0
61
+ return r == 1
62
+ end
63
+
64
+ def contains(other)
65
+ # The C function works like fa1 <= fa2, and not how the
66
+ # Ruby nomenclature would suggest it, so swap the arguments
67
+ r = FFI::contains(other.faptr, faptr)
68
+ raise Error if r < 0
69
+ return r == 1
70
+ end
71
+
72
+ def is_basic(basic)
73
+ # FFI::is_basic checks if the automaton is structurally the same as
74
+ # +basic+; we just want to check here if they accept the same
75
+ # language. If is_basic fails, we therefore check for equality
76
+ r = FFI::is_basic(faptr, basic)
77
+ return true if r == 1
78
+ return equals(Fa::make_basic(basic))
79
+ end
80
+
81
+ def empty?; is_basic(:empty); end
82
+ def epsilon?; is_basic(:epsilon); end
83
+ def total?; is_basic(:total); end
84
+
85
+ def as_regexp
86
+ rx = ::FFI::MemoryPointer.new :string
87
+ rx_len = ::FFI::MemoryPointer.new :size_t
88
+ r = FFI::as_regexp(faptr, rx, rx_len)
89
+ raise OutOfMemoryError if r < 0
90
+ str_ptr = rx.read_pointer()
91
+ return str_ptr.null? ? nil : str_ptr.read_string()
92
+ end
93
+
94
+ def self.release(faptr)
95
+ FFI::free(faptr)
96
+ end
97
+
98
+ :private
99
+ def from_ptr(ptr)
100
+ raise OutOfMemoryError if ptr.nil?
101
+ Automaton.new(ptr)
102
+ end
103
+ end
104
+
105
+ def self.compile(rx)
106
+ faptr = ::FFI::MemoryPointer.new :pointer
107
+ r = FFI::compile(rx, rx.size, faptr)
108
+ raise Error if r < 0
109
+ Automaton.new(faptr.get_pointer(0))
110
+ end
111
+
112
+ def self.make_basic(kind)
113
+ faptr = FFI::make_basic(kind)
114
+ raise OutOfMemoryError if faptr.nil?
115
+ Automaton.new(faptr)
116
+ end
117
+ end
@@ -0,0 +1,42 @@
1
+ require 'ffi'
2
+
3
+ module Fa::FFI
4
+ extend FFI::Library
5
+
6
+ ffi_lib 'fa'
7
+
8
+ enum :basic, [ :empty, :epsilon, :total ]
9
+
10
+ attach_function :compile, :fa_compile, [ :string, :size_t, :pointer ], :int
11
+ attach_function :make_basic, :fa_make_basic, [ :basic ], :pointer
12
+
13
+ attach_function :minimize, :fa_minimize, [ :pointer ], :int
14
+
15
+ attach_function :concat, :fa_concat, [ :pointer, :pointer ], :pointer
16
+ attach_function :union, :fa_union, [ :pointer, :pointer ], :pointer
17
+ attach_function :intersect, :fa_intersect, [ :pointer, :pointer ], :pointer
18
+ attach_function :complement, :fa_complement, [ :pointer ], :pointer
19
+ attach_function :minus, :fa_minus, [ :pointer, :pointer ], :pointer
20
+ attach_function :iter, :fa_iter, [ :pointer, :int, :int ], :pointer
21
+
22
+ attach_function :contains, :fa_contains, [ :pointer, :pointer ], :int
23
+ attach_function :equals, :fa_equals, [ :pointer, :pointer ], :int
24
+ attach_function :is_basic, :fa_is_basic, [ :pointer, :basic ], :int
25
+
26
+ attach_function :as_regexp, :fa_as_regexp,
27
+ [ :pointer, :pointer, :pointer ], :int
28
+ attach_function :free, :fa_free, [ :pointer ], :void
29
+
30
+ # Missing bindings:
31
+ # fa_dot
32
+ # fa_overlap
33
+ # fa_example
34
+ # fa_ambig_example
35
+ # fa_as_regexp
36
+ # fa_restrict_alphabet
37
+ # fa_expand_char_ranges
38
+ # fa_nocase
39
+ # fa_is_nocase
40
+ # fa_expand_nocase
41
+ # fa_enumerate
42
+ end
@@ -0,0 +1,3 @@
1
+ module Fa
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - 'David Lutterkort
8
+
9
+ '
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2017-09-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ffi
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.14'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.14'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '10.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '10.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: minitest
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '5.0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '5.0'
71
+ description: |
72
+ Bindings for libfa, a library to manipulate finite automata. Automata are
73
+ constructed from regular expressions, using extended POSIX syntax, and make
74
+ it possible to compute interesting things like the intersection of two
75
+ regular expressions (all strings matched by both), or the complement of a
76
+ regular expression (all strings _not_ matched by the regular
77
+ expression). It is possible to convert from regular expression (compile) to
78
+ finite automaton, and from finite automaton to regular expression
79
+ (as_regexp)
80
+ email:
81
+ - lutter@watzmann.net
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - ".gitignore"
87
+ - ".travis.yml"
88
+ - AUTHORS
89
+ - Gemfile
90
+ - LICENSE
91
+ - README.md
92
+ - Rakefile
93
+ - bin/console
94
+ - bin/setup
95
+ - fa.gemspec
96
+ - lib/fa.rb
97
+ - lib/fa/ffi.rb
98
+ - lib/fa/version.rb
99
+ homepage: https://github.com/lutter/ruby-fa
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.5.1
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Bindings for libfa, a library for computing with regular expressions.
123
+ test_files: []