srl_ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +4 -0
- data/.rubocop.yml +3 -0
- data/.yardopts +6 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +16 -0
- data/bin/srl_ruby +58 -0
- data/lib/regex/abstract_method.rb +35 -0
- data/lib/regex/alternation.rb +27 -0
- data/lib/regex/anchor.rb +45 -0
- data/lib/regex/atomic_expression.rb +16 -0
- data/lib/regex/capturing_group.rb +51 -0
- data/lib/regex/char_class.rb +38 -0
- data/lib/regex/char_range.rb +51 -0
- data/lib/regex/char_shorthand.rb +50 -0
- data/lib/regex/character.rb +204 -0
- data/lib/regex/compound_expression.rb +57 -0
- data/lib/regex/concatenation.rb +29 -0
- data/lib/regex/expression.rb +60 -0
- data/lib/regex/lookaround.rb +50 -0
- data/lib/regex/match_option.rb +34 -0
- data/lib/regex/monadic_expression.rb +28 -0
- data/lib/regex/multiplicity.rb +91 -0
- data/lib/regex/non_capturing_group.rb +27 -0
- data/lib/regex/polyadic_expression.rb +60 -0
- data/lib/regex/quantifiable.rb +22 -0
- data/lib/regex/repetition.rb +29 -0
- data/lib/regex/wildcard.rb +23 -0
- data/lib/srl_ruby/ast_builder.rb +384 -0
- data/lib/srl_ruby/grammar.rb +106 -0
- data/lib/srl_ruby/regex_repr.rb +13 -0
- data/lib/srl_ruby/tokenizer.rb +147 -0
- data/lib/srl_ruby/version.rb +3 -0
- data/lib/srl_ruby.rb +4 -0
- data/spec/integration_spec.rb +451 -0
- data/spec/regex/character_spec.rb +166 -0
- data/spec/regex/multiplicity_spec.rb +79 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/srl_ruby/srl_ruby_spec.rb +7 -0
- data/spec/srl_ruby/tokenizer_spec.rb +147 -0
- data/srl_ruby.gemspec +58 -0
- metadata +150 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'rspec' # Use the RSpec framework
|
3
|
+
require_relative '../lib/srl_ruby'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
# Enable flags like --only-failures and --next-failure
|
7
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
8
|
+
|
9
|
+
config.expect_with :rspec do |c|
|
10
|
+
# Disable the `should` syntax...
|
11
|
+
c.syntax = :expect
|
12
|
+
end
|
13
|
+
|
14
|
+
# Display stack trace in case of failure
|
15
|
+
config.full_backtrace = true
|
16
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require_relative '../spec_helper' # Use the RSpec framework
|
2
|
+
require_relative '../../lib/srl_ruby/tokenizer' # Load the class under test
|
3
|
+
|
4
|
+
module SrlRuby
|
5
|
+
describe Tokenizer do
|
6
|
+
def match_expectations(aTokenizer, theExpectations)
|
7
|
+
aTokenizer.tokens.each_with_index do |token, i|
|
8
|
+
terminal, lexeme = theExpectations[i]
|
9
|
+
expect(token.terminal).to eq(terminal)
|
10
|
+
expect(token.lexeme).to eq(lexeme)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { Tokenizer.new('') }
|
15
|
+
|
16
|
+
context 'Initialization:' do
|
17
|
+
it 'should be initialized with a text to tokenize and a grammar' do
|
18
|
+
expect { Tokenizer.new('anything') }.not_to raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have its scanner initialized' do
|
22
|
+
expect(subject.scanner).to be_kind_of(StringScanner)
|
23
|
+
end
|
24
|
+
end # context
|
25
|
+
|
26
|
+
context 'Single token recognition:' do
|
27
|
+
it 'should tokenize delimiters and separators' do
|
28
|
+
subject.scanner.string = ','
|
29
|
+
token = subject.tokens.first
|
30
|
+
expect(token).to be_kind_of(Rley::Lexical::Token)
|
31
|
+
expect(token.terminal).to eq('COMMA')
|
32
|
+
expect(token.lexeme).to eq(',')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should tokenize keywords' do
|
36
|
+
sample = 'between Exactly oncE optional TWICE'
|
37
|
+
subject.scanner.string = sample
|
38
|
+
subject.tokens.each do |tok|
|
39
|
+
expect(tok).to be_kind_of(Rley::Lexical::Token)
|
40
|
+
expect(tok.terminal).to eq(tok.lexeme.upcase)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should tokenize integer values' do
|
45
|
+
subject.scanner.string = ' 123 '
|
46
|
+
token = subject.tokens.first
|
47
|
+
expect(token).to be_kind_of(Rley::Lexical::Token)
|
48
|
+
expect(token.terminal).to eq('INTEGER')
|
49
|
+
expect(token.lexeme).to eq('123')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should tokenize single digits' do
|
53
|
+
subject.scanner.string = ' 1 '
|
54
|
+
token = subject.tokens.first
|
55
|
+
expect(token).to be_kind_of(Rley::Lexical::Token)
|
56
|
+
expect(token.terminal).to eq('DIGIT_LIT')
|
57
|
+
expect(token.lexeme).to eq('1')
|
58
|
+
end
|
59
|
+
end # context
|
60
|
+
|
61
|
+
context 'String literal tokenization:' do
|
62
|
+
it "should recognize 'literally ...'" do
|
63
|
+
input = 'literally "hello"'
|
64
|
+
subject.scanner.string = input
|
65
|
+
expectations = [
|
66
|
+
%w[LITERALLY literally],
|
67
|
+
%w[STRING_LIT hello]
|
68
|
+
]
|
69
|
+
match_expectations(subject, expectations)
|
70
|
+
end
|
71
|
+
end # context
|
72
|
+
|
73
|
+
context 'Character range tokenization:' do
|
74
|
+
it "should recognize 'letter from ... to ...'" do
|
75
|
+
input = 'letter a to f'
|
76
|
+
subject.scanner.string = input
|
77
|
+
expectations = [
|
78
|
+
%w[LETTER letter],
|
79
|
+
%w[LETTER_LIT a],
|
80
|
+
%w[TO to],
|
81
|
+
%w[LETTER_LIT f]
|
82
|
+
]
|
83
|
+
match_expectations(subject, expectations)
|
84
|
+
end
|
85
|
+
end # context
|
86
|
+
|
87
|
+
context 'Quantifier tokenization:' do
|
88
|
+
it "should recognize 'exactly ... times'" do
|
89
|
+
input = 'exactly 4 Times'
|
90
|
+
subject.scanner.string = input
|
91
|
+
expectations = [
|
92
|
+
%w[EXACTLY exactly],
|
93
|
+
%w[DIGIT_LIT 4],
|
94
|
+
%w[TIMES Times]
|
95
|
+
]
|
96
|
+
match_expectations(subject, expectations)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should recognize 'between ... and ... times'" do
|
100
|
+
input = 'Between 2 AND 4 times'
|
101
|
+
subject.scanner.string = input
|
102
|
+
expectations = [
|
103
|
+
%w[BETWEEN Between],
|
104
|
+
%w[DIGIT_LIT 2],
|
105
|
+
%w[AND AND],
|
106
|
+
%w[DIGIT_LIT 4],
|
107
|
+
%w[TIMES times]
|
108
|
+
]
|
109
|
+
match_expectations(subject, expectations)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should recognize 'once or more'" do
|
113
|
+
input = 'Once or MORE'
|
114
|
+
subject.scanner.string = input
|
115
|
+
expectations = [
|
116
|
+
%w[ONCE Once],
|
117
|
+
%w[OR or],
|
118
|
+
%w[MORE MORE]
|
119
|
+
]
|
120
|
+
match_expectations(subject, expectations)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should recognize 'never or more'" do
|
124
|
+
input = 'never or more'
|
125
|
+
subject.scanner.string = input
|
126
|
+
expectations = [
|
127
|
+
%w[NEVER never],
|
128
|
+
%w[OR or],
|
129
|
+
%w[MORE more]
|
130
|
+
]
|
131
|
+
match_expectations(subject, expectations)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should recognize 'at least ... times'" do
|
135
|
+
input = 'at least 10 times'
|
136
|
+
subject.scanner.string = input
|
137
|
+
expectations = [
|
138
|
+
%w[AT at],
|
139
|
+
%w[LEAST least],
|
140
|
+
%w[INTEGER 10],
|
141
|
+
%w[TIMES times]
|
142
|
+
]
|
143
|
+
match_expectations(subject, expectations)
|
144
|
+
end
|
145
|
+
end # context
|
146
|
+
end # describe
|
147
|
+
end # module
|
data/srl_ruby.gemspec
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'srl_ruby/version'
|
5
|
+
|
6
|
+
module PkgExtending
|
7
|
+
def self.pkg_files(aPackage)
|
8
|
+
file_list = Dir[
|
9
|
+
'.rubocop.yml',
|
10
|
+
'.rspec',
|
11
|
+
'.yardopts',
|
12
|
+
'Gemfile',
|
13
|
+
'Rakefile',
|
14
|
+
'CHANGELOG.md',
|
15
|
+
'LICENSE.txt',
|
16
|
+
'README.md',
|
17
|
+
'srl_ruby.gemspec',
|
18
|
+
'lib/*.*',
|
19
|
+
'lib/**/*.rb',
|
20
|
+
'spec/**/*.rb'
|
21
|
+
]
|
22
|
+
aPackage.files = file_list
|
23
|
+
aPackage.test_files = Dir['spec/**/*_spec.rb']
|
24
|
+
aPackage.require_path = 'lib'
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.pkg_documentation(aPackage)
|
28
|
+
aPackage.rdoc_options << '--charset=UTF-8 --exclude="examples|features|spec"'
|
29
|
+
aPackage.extra_rdoc_files = ['README.md']
|
30
|
+
end
|
31
|
+
end # module
|
32
|
+
|
33
|
+
Gem::Specification.new do |spec|
|
34
|
+
spec.name = 'srl_ruby'
|
35
|
+
spec.version = SrlRuby::VERSION
|
36
|
+
spec.authors = ['Dimitri Geshef']
|
37
|
+
spec.email = ['famished.tiger@yahoo.com']
|
38
|
+
|
39
|
+
spec.summary = %q(Ruby implementation of the Simple Regex Language)
|
40
|
+
spec.description = %q(Ruby implementation of the Simple Regex Language)
|
41
|
+
spec.homepage = 'https://github.com/famished-tiger/SRL-Ruby'
|
42
|
+
spec.license = 'MIT'
|
43
|
+
|
44
|
+
spec.bindir = 'bin'
|
45
|
+
spec.executables << 'srl_ruby'
|
46
|
+
spec.require_paths = ['lib']
|
47
|
+
PkgExtending::pkg_files(spec)
|
48
|
+
PkgExtending::pkg_documentation(spec)
|
49
|
+
spec.required_ruby_version = '>= 2.1.0'
|
50
|
+
|
51
|
+
# Runtime dependencies
|
52
|
+
spec.add_dependency 'rley', '~> 0.6.00'
|
53
|
+
|
54
|
+
# Development dependencies
|
55
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
56
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
57
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: srl_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dimitri Geshef
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rley
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.00
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.00
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Ruby implementation of the Simple Regex Language
|
70
|
+
email:
|
71
|
+
- famished.tiger@yahoo.com
|
72
|
+
executables:
|
73
|
+
- srl_ruby
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files:
|
76
|
+
- README.md
|
77
|
+
files:
|
78
|
+
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- ".yardopts"
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/srl_ruby
|
86
|
+
- lib/regex/abstract_method.rb
|
87
|
+
- lib/regex/alternation.rb
|
88
|
+
- lib/regex/anchor.rb
|
89
|
+
- lib/regex/atomic_expression.rb
|
90
|
+
- lib/regex/capturing_group.rb
|
91
|
+
- lib/regex/char_class.rb
|
92
|
+
- lib/regex/char_range.rb
|
93
|
+
- lib/regex/char_shorthand.rb
|
94
|
+
- lib/regex/character.rb
|
95
|
+
- lib/regex/compound_expression.rb
|
96
|
+
- lib/regex/concatenation.rb
|
97
|
+
- lib/regex/expression.rb
|
98
|
+
- lib/regex/lookaround.rb
|
99
|
+
- lib/regex/match_option.rb
|
100
|
+
- lib/regex/monadic_expression.rb
|
101
|
+
- lib/regex/multiplicity.rb
|
102
|
+
- lib/regex/non_capturing_group.rb
|
103
|
+
- lib/regex/polyadic_expression.rb
|
104
|
+
- lib/regex/quantifiable.rb
|
105
|
+
- lib/regex/repetition.rb
|
106
|
+
- lib/regex/wildcard.rb
|
107
|
+
- lib/srl_ruby.rb
|
108
|
+
- lib/srl_ruby/ast_builder.rb
|
109
|
+
- lib/srl_ruby/grammar.rb
|
110
|
+
- lib/srl_ruby/regex_repr.rb
|
111
|
+
- lib/srl_ruby/tokenizer.rb
|
112
|
+
- lib/srl_ruby/version.rb
|
113
|
+
- spec/integration_spec.rb
|
114
|
+
- spec/regex/character_spec.rb
|
115
|
+
- spec/regex/multiplicity_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/srl_ruby/srl_ruby_spec.rb
|
118
|
+
- spec/srl_ruby/tokenizer_spec.rb
|
119
|
+
- srl_ruby.gemspec
|
120
|
+
homepage: https://github.com/famished-tiger/SRL-Ruby
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options:
|
126
|
+
- --charset=UTF-8 --exclude="examples|features|spec"
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 2.1.0
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.6.13
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Ruby implementation of the Simple Regex Language
|
145
|
+
test_files:
|
146
|
+
- spec/integration_spec.rb
|
147
|
+
- spec/regex/character_spec.rb
|
148
|
+
- spec/regex/multiplicity_spec.rb
|
149
|
+
- spec/srl_ruby/srl_ruby_spec.rb
|
150
|
+
- spec/srl_ruby/tokenizer_spec.rb
|