rley 0.0.02
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.
- checksums.yaml +15 -0
- data/.rspec +1 -0
- data/.rubocop.yml +74 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.simplecov +7 -0
- data/.travis.yml +21 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +19 -0
- data/README.md +19 -0
- data/Rakefile +32 -0
- data/lib/rley/constants.rb +26 -0
- data/lib/rley/parser/chart.rb +39 -0
- data/lib/rley/parser/dotted_item.rb +80 -0
- data/lib/rley/parser/earley_parser.rb +177 -0
- data/lib/rley/parser/parse_state.rb +54 -0
- data/lib/rley/parser/parsing.rb +101 -0
- data/lib/rley/parser/state_set.rb +47 -0
- data/lib/rley/parser/token.rb +21 -0
- data/lib/rley/syntax/grammar.rb +59 -0
- data/lib/rley/syntax/grm_symbol.rb +18 -0
- data/lib/rley/syntax/literal.rb +20 -0
- data/lib/rley/syntax/non_terminal.rb +18 -0
- data/lib/rley/syntax/production.rb +42 -0
- data/lib/rley/syntax/symbol_seq.rb +36 -0
- data/lib/rley/syntax/terminal.rb +18 -0
- data/lib/rley/syntax/verbatim_symbol.rb +21 -0
- data/spec/rley/parser/chart_spec.rb +47 -0
- data/spec/rley/parser/dotted_item_spec.rb +108 -0
- data/spec/rley/parser/earley_parser_spec.rb +271 -0
- data/spec/rley/parser/parse_state_spec.rb +99 -0
- data/spec/rley/parser/parsing_spec.rb +118 -0
- data/spec/rley/parser/state_set_spec.rb +68 -0
- data/spec/rley/parser/token_spec.rb +40 -0
- data/spec/rley/syntax/grammar_spec.rb +149 -0
- data/spec/rley/syntax/grm_symbol_spec.rb +29 -0
- data/spec/rley/syntax/literal_spec.rb +32 -0
- data/spec/rley/syntax/non_terminal_spec.rb +29 -0
- data/spec/rley/syntax/production_spec.rb +50 -0
- data/spec/rley/syntax/symbol_seq_spec.rb +65 -0
- data/spec/rley/syntax/terminal_spec.rb +29 -0
- data/spec/rley/syntax/verbatim_symbol_spec.rb +32 -0
- data/spec/spec_helper.rb +21 -0
- metadata +166 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
# Load the class under test
|
4
|
+
require_relative '../../../lib/rley/syntax/grm_symbol'
|
5
|
+
|
6
|
+
module Rley # Open this namespace to avoid module qualifier prefixes
|
7
|
+
module Syntax # Open this namespace to avoid module qualifier prefixes
|
8
|
+
|
9
|
+
describe GrmSymbol do
|
10
|
+
let(:sample_name) { 'NP' }
|
11
|
+
subject { GrmSymbol.new(sample_name) }
|
12
|
+
|
13
|
+
context 'Initialization:' do
|
14
|
+
it 'should be created with a name' do
|
15
|
+
expect { GrmSymbol.new('NP') }.not_to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should know its name' do
|
19
|
+
expect(subject.name).to eq(sample_name)
|
20
|
+
end
|
21
|
+
end # context
|
22
|
+
|
23
|
+
end # describe
|
24
|
+
|
25
|
+
end # module
|
26
|
+
end # module
|
27
|
+
|
28
|
+
# End of file
|
29
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
# Load the class under test
|
4
|
+
require_relative '../../../lib/rley/syntax/literal'
|
5
|
+
|
6
|
+
module Rley # Open this namespace to avoid module qualifier prefixes
|
7
|
+
module Syntax # Open this namespace to avoid module qualifier prefixes
|
8
|
+
|
9
|
+
describe Literal do
|
10
|
+
let(:sample_name) { 'ordinal' }
|
11
|
+
subject { Literal.new(sample_name, /\d+/) }
|
12
|
+
|
13
|
+
context 'Initialization:' do
|
14
|
+
it 'should be created with a name and regexp' do
|
15
|
+
expect { Literal.new(sample_name, /\d+/) }.not_to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should know its name' do
|
19
|
+
expect(subject.name).to eq(sample_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should know its pattern' do
|
23
|
+
expect(subject.pattern).to eq(/\d+/)
|
24
|
+
end
|
25
|
+
end # context
|
26
|
+
|
27
|
+
end # describe
|
28
|
+
|
29
|
+
end # module
|
30
|
+
end # module
|
31
|
+
|
32
|
+
# End of file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
# Load the class under test
|
4
|
+
require_relative '../../../lib/rley/syntax/non_terminal'
|
5
|
+
|
6
|
+
module Rley # Open this namespace to avoid module qualifier prefixes
|
7
|
+
module Syntax # Open this namespace to avoid module qualifier prefixes
|
8
|
+
|
9
|
+
describe NonTerminal do
|
10
|
+
let(:sample_name) { 'noun' }
|
11
|
+
subject { NonTerminal.new(sample_name) }
|
12
|
+
|
13
|
+
context 'Initialization:' do
|
14
|
+
it 'should be created with a name' do
|
15
|
+
expect { NonTerminal.new('noun') }.not_to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should know its name' do
|
19
|
+
expect(subject.name).to eq(sample_name)
|
20
|
+
end
|
21
|
+
end # context
|
22
|
+
|
23
|
+
end # describe
|
24
|
+
|
25
|
+
end # module
|
26
|
+
end # module
|
27
|
+
|
28
|
+
# End of file
|
29
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
require_relative '../../../lib/rley/syntax/terminal'
|
4
|
+
require_relative '../../../lib/rley/syntax/non_terminal'
|
5
|
+
require_relative '../../../lib/rley/syntax/symbol_seq'
|
6
|
+
|
7
|
+
# Load the class under test
|
8
|
+
require_relative '../../../lib/rley/syntax/production'
|
9
|
+
|
10
|
+
module Rley # Open this namespace to avoid module qualifier prefixes
|
11
|
+
module Syntax # Open this namespace to avoid module qualifier prefixes
|
12
|
+
|
13
|
+
describe Production do
|
14
|
+
let(:sentence) { NonTerminal.new('Sentence') }
|
15
|
+
let(:np) { NonTerminal.new('NP') }
|
16
|
+
let(:vp) { NonTerminal.new('VP') }
|
17
|
+
let(:sequence) { [np, vp] }
|
18
|
+
|
19
|
+
# Default instantiation rule
|
20
|
+
subject { Production.new(sentence, sequence) }
|
21
|
+
|
22
|
+
context 'Initialization:' do
|
23
|
+
it 'should be created with a non-terminal and a symbol sequence' do
|
24
|
+
expect { Production.new(sentence, sequence) }.not_to raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should know its lhs' do
|
28
|
+
expect(subject.lhs).to eq(sentence)
|
29
|
+
expect(subject.head).to eq(sentence)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should know its rhs' do
|
33
|
+
expect(subject.rhs).to eq(sequence)
|
34
|
+
expect(subject.body).to eq(sequence)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should know whether its rhs is empty' do
|
38
|
+
expect(subject).not_to be_empty
|
39
|
+
|
40
|
+
instance = Production.new(sentence, [])
|
41
|
+
expect(instance).to be_empty
|
42
|
+
end
|
43
|
+
end # context
|
44
|
+
|
45
|
+
end # describe
|
46
|
+
|
47
|
+
end # module
|
48
|
+
end # module
|
49
|
+
|
50
|
+
# End of file
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
require_relative '../../../lib/rley/syntax/non_terminal'
|
4
|
+
|
5
|
+
# Load the class under test
|
6
|
+
require_relative '../../../lib/rley/syntax/symbol_seq'
|
7
|
+
|
8
|
+
module Rley # Open this namespace to avoid module qualifier prefixes
|
9
|
+
module Syntax # Open this namespace to avoid module qualifier prefixes
|
10
|
+
|
11
|
+
describe SymbolSeq do
|
12
|
+
let(:verb) { NonTerminal.new('Verb') }
|
13
|
+
let(:np) { NonTerminal.new('NP') }
|
14
|
+
let(:pp) { NonTerminal.new('PP') }
|
15
|
+
|
16
|
+
# Default instantiation rule
|
17
|
+
subject { SymbolSeq.new([verb, np, pp]) }
|
18
|
+
|
19
|
+
context 'Initialization:' do
|
20
|
+
it 'should be created with a list of symbols' do
|
21
|
+
# Case of non-empty sequence
|
22
|
+
expect { SymbolSeq.new([verb, np, pp]) }.not_to raise_error
|
23
|
+
|
24
|
+
# Case of empty sequence
|
25
|
+
expect { SymbolSeq.new([]) }.not_to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should know its members' do
|
29
|
+
expect(subject.members).to eq([verb, np, pp])
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should know whether it is empty' do
|
33
|
+
expect(subject).not_to be_empty
|
34
|
+
instance = SymbolSeq.new([])
|
35
|
+
expect(instance).to be_empty
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should the count of its members' do
|
39
|
+
expect(subject.size).to eq(3)
|
40
|
+
end
|
41
|
+
end # context
|
42
|
+
|
43
|
+
context 'Provided services:' do
|
44
|
+
it 'should compare compare with itself' do
|
45
|
+
expect(subject == subject).to eq(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should compare with another instance' do
|
49
|
+
empty_one = SymbolSeq.new([])
|
50
|
+
expect(subject == empty_one).not_to eq(true)
|
51
|
+
|
52
|
+
equal_one = SymbolSeq.new([verb, np, pp])
|
53
|
+
expect(subject == equal_one).to eq(true)
|
54
|
+
|
55
|
+
unequal_one = SymbolSeq.new([verb, pp, np])
|
56
|
+
expect(subject == unequal_one).not_to eq(true)
|
57
|
+
end
|
58
|
+
end # context
|
59
|
+
|
60
|
+
end # describe
|
61
|
+
|
62
|
+
end # module
|
63
|
+
end # module
|
64
|
+
|
65
|
+
# End of file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
# Load the class under test
|
4
|
+
require_relative '../../../lib/rley/syntax/terminal'
|
5
|
+
|
6
|
+
module Rley # Open this namespace to avoid module qualifier prefixes
|
7
|
+
module Syntax # Open this namespace to avoid module qualifier prefixes
|
8
|
+
|
9
|
+
describe Terminal do
|
10
|
+
let(:sample_name) { 'noun' }
|
11
|
+
subject { Terminal.new(sample_name) }
|
12
|
+
|
13
|
+
context 'Initialization:' do
|
14
|
+
it 'should be created with a name' do
|
15
|
+
expect { Terminal.new('noun') }.not_to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should know its name' do
|
19
|
+
expect(subject.name).to eq(sample_name)
|
20
|
+
end
|
21
|
+
end # context
|
22
|
+
|
23
|
+
end # describe
|
24
|
+
|
25
|
+
end # module
|
26
|
+
end # module
|
27
|
+
|
28
|
+
# End of file
|
29
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
# Load the class under test
|
4
|
+
require_relative '../../../lib/rley/syntax/verbatim_symbol'
|
5
|
+
|
6
|
+
module Rley # Open this namespace to avoid module qualifier prefixes
|
7
|
+
module Syntax # Open this namespace to avoid module qualifier prefixes
|
8
|
+
|
9
|
+
describe VerbatimSymbol do
|
10
|
+
let(:sample_name) { 'cheapest' }
|
11
|
+
subject { VerbatimSymbol.new(sample_name) }
|
12
|
+
|
13
|
+
context 'Initialization:' do
|
14
|
+
it 'should be created with a word' do
|
15
|
+
expect { VerbatimSymbol.new('cheapest') }.not_to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should know its name' do
|
19
|
+
expect(subject.name).to eq(sample_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should know its text representation' do
|
23
|
+
expect(subject.text).to eq(sample_name)
|
24
|
+
end
|
25
|
+
end # context
|
26
|
+
|
27
|
+
end # describe
|
28
|
+
|
29
|
+
end # module
|
30
|
+
end # module
|
31
|
+
|
32
|
+
# End of file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# File: spec_helper.rb
|
2
|
+
# Purpose: utility file that is loaded by all our RSpec files
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
|
7
|
+
require 'rspec' # Use the RSpec framework
|
8
|
+
require 'pp' # Use pretty-print for debugging purposes
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
# Disable the `should` syntax...
|
13
|
+
c.syntax = :expect
|
14
|
+
end
|
15
|
+
|
16
|
+
# Display stack trace in case of failure
|
17
|
+
config.full_backtrace = true
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
# End of file
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rley
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.02
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dimitri Geshef
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.5.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.5.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubygems
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.0
|
69
|
+
description: A Ruby implementation of the Earley's parsing algorithm
|
70
|
+
email: famished.tiger@yahoo.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- README.md
|
75
|
+
files:
|
76
|
+
- .rubocop.yml
|
77
|
+
- .rspec
|
78
|
+
- .ruby-gemset
|
79
|
+
- .ruby-version
|
80
|
+
- .simplecov
|
81
|
+
- .travis.yml
|
82
|
+
- .yardopts
|
83
|
+
- Gemfile
|
84
|
+
- Rakefile
|
85
|
+
- CHANGELOG.md
|
86
|
+
- LICENSE.txt
|
87
|
+
- README.md
|
88
|
+
- lib/rley/constants.rb
|
89
|
+
- lib/rley/parser/chart.rb
|
90
|
+
- lib/rley/parser/dotted_item.rb
|
91
|
+
- lib/rley/parser/earley_parser.rb
|
92
|
+
- lib/rley/parser/parse_state.rb
|
93
|
+
- lib/rley/parser/parsing.rb
|
94
|
+
- lib/rley/parser/state_set.rb
|
95
|
+
- lib/rley/parser/token.rb
|
96
|
+
- lib/rley/syntax/grammar.rb
|
97
|
+
- lib/rley/syntax/grm_symbol.rb
|
98
|
+
- lib/rley/syntax/literal.rb
|
99
|
+
- lib/rley/syntax/non_terminal.rb
|
100
|
+
- lib/rley/syntax/production.rb
|
101
|
+
- lib/rley/syntax/symbol_seq.rb
|
102
|
+
- lib/rley/syntax/terminal.rb
|
103
|
+
- lib/rley/syntax/verbatim_symbol.rb
|
104
|
+
- spec/rley/parser/chart_spec.rb
|
105
|
+
- spec/rley/parser/dotted_item_spec.rb
|
106
|
+
- spec/rley/parser/earley_parser_spec.rb
|
107
|
+
- spec/rley/parser/parse_state_spec.rb
|
108
|
+
- spec/rley/parser/parsing_spec.rb
|
109
|
+
- spec/rley/parser/state_set_spec.rb
|
110
|
+
- spec/rley/parser/token_spec.rb
|
111
|
+
- spec/rley/syntax/grammar_spec.rb
|
112
|
+
- spec/rley/syntax/grm_symbol_spec.rb
|
113
|
+
- spec/rley/syntax/literal_spec.rb
|
114
|
+
- spec/rley/syntax/non_terminal_spec.rb
|
115
|
+
- spec/rley/syntax/production_spec.rb
|
116
|
+
- spec/rley/syntax/symbol_seq_spec.rb
|
117
|
+
- spec/rley/syntax/terminal_spec.rb
|
118
|
+
- spec/rley/syntax/verbatim_symbol_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
homepage: https://github.com/famished-tiger/Rley
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message: ! '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
125
|
+
|
126
|
+
Thank you for installing Rley...
|
127
|
+
|
128
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
129
|
+
|
130
|
+
'
|
131
|
+
rdoc_options:
|
132
|
+
- --charset=UTF-8 --exclude="examples|features|spec"
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ! '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 1.9.3
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.0.3
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Ruby implementation of the Earley's parsing algorithm
|
151
|
+
test_files:
|
152
|
+
- spec/rley/parser/chart_spec.rb
|
153
|
+
- spec/rley/parser/dotted_item_spec.rb
|
154
|
+
- spec/rley/parser/earley_parser_spec.rb
|
155
|
+
- spec/rley/parser/parse_state_spec.rb
|
156
|
+
- spec/rley/parser/parsing_spec.rb
|
157
|
+
- spec/rley/parser/state_set_spec.rb
|
158
|
+
- spec/rley/parser/token_spec.rb
|
159
|
+
- spec/rley/syntax/grammar_spec.rb
|
160
|
+
- spec/rley/syntax/grm_symbol_spec.rb
|
161
|
+
- spec/rley/syntax/literal_spec.rb
|
162
|
+
- spec/rley/syntax/non_terminal_spec.rb
|
163
|
+
- spec/rley/syntax/production_spec.rb
|
164
|
+
- spec/rley/syntax/symbol_seq_spec.rb
|
165
|
+
- spec/rley/syntax/terminal_spec.rb
|
166
|
+
- spec/rley/syntax/verbatim_symbol_spec.rb
|