dendroid 0.0.0 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c0559bafc9e9cb01c84eff72c403a538e744b88fb12b02f59f2e2de6cfb8a93
4
- data.tar.gz: 238e91d9e6e909062c7fca3fb8a9455795fb6f24861fd5ad3be973bdda2c4269
3
+ metadata.gz: 23f7c3fcf4a7f0df335e5b2fbc7f25f89a60f4d66cc9bfd1ce37680fbb133b83
4
+ data.tar.gz: fc4a399d2a5812d4c0e01b28bc261e810386b3d54c353ba2e54190d3df508e3f
5
5
  SHA512:
6
- metadata.gz: 779c2551fc57e8f2e0c185e5307815348bda51b2782f4b2fd616112e831cf847920f787b115c5d65035303bdab53aa2768f1f0a36e8c3da409fb4e8a7cd44094
7
- data.tar.gz: 5be45c19d4d7ae74fc88333367362cf6c05f3278ecf94fe4110bd6f51db682edf33a1584155cfd3cffc67bc9c4efafa1c1e0444fa96a7bfea639539c1f9c4f69
6
+ metadata.gz: c4f9ec0db43dcf581d2c5a3866fb383f757bd0a99b4526348b41326a22b0c39b04200768b1cb7a1dfd03ae3272d60de0fc09f73c9a7d9df3269bdf1721f8f19b
7
+ data.tar.gz: dd5a819b7946149c38e39822489d2ef08838abb87f6f6e549e2dbade55fa77edf99d91503664506bfe0b07a5c66d5408a7b409c0b090297f70d488696ecd88bc
data/.rubocop.yml CHANGED
@@ -1,3 +1,7 @@
1
+ Metrics/BlockLength:
2
+ Enabled: true
3
+ Max: 50
4
+
1
5
  Naming/MethodParameterName:
2
6
  Enabled: false
3
7
 
data/LICENSE CHANGED
@@ -1,22 +1,22 @@
1
- The MIT License
2
-
3
- Copyright (c) 2023 Dimitri Geshef
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- 'Software'), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ The MIT License
2
+
3
+ Copyright (c) 2023 Dimitri Geshef
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,60 +1,60 @@
1
- dendroid
2
- ===========
3
-
4
- FIXME (describe your package)
5
-
6
- Features
7
- --------
8
-
9
- * FIXME (list of features and unsolved problems)
10
-
11
- Examples
12
- --------
13
-
14
- FIXME (code sample of usage)
15
-
16
- Requirements
17
- ------------
18
-
19
- * FIXME (list of requirements)
20
-
21
- Install
22
- -------
23
-
24
- * FIXME (sudo gem install, anything else)
25
-
26
- Author
27
- ------
28
-
29
- Original author: FIXME (author's name)
30
-
31
- Contributors:
32
-
33
- * FIXME (contributor 1?)
34
- * FIXME (contributor 2?)
35
-
36
- License
37
- -------
38
-
39
- (The MIT License) FIXME (different license?)
40
-
41
- Copyright (c) 2023 FIXME (author's name)
42
-
43
- Permission is hereby granted, free of charge, to any person obtaining
44
- a copy of this software and associated documentation files (the
45
- 'Software'), to deal in the Software without restriction, including
46
- without limitation the rights to use, copy, modify, merge, publish,
47
- distribute, sublicense, and/or sell copies of the Software, and to
48
- permit persons to whom the Software is furnished to do so, subject to
49
- the following conditions:
50
-
51
- The above copyright notice and this permission notice shall be
52
- included in all copies or substantial portions of the Software.
53
-
54
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
55
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
57
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
58
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
59
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
60
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ dendroid
2
+ ===========
3
+
4
+ A Ruby implementation of the Earley parsing algorithm. WIP
5
+
6
+ Features
7
+ --------
8
+
9
+ * WIP
10
+
11
+ Examples
12
+ --------
13
+
14
+ FIXME (code sample of usage)
15
+
16
+ Requirements
17
+ ------------
18
+
19
+ * FIXME (list of requirements)
20
+
21
+ Install
22
+ -------
23
+
24
+ * FIXME (sudo gem install, anything else)
25
+
26
+ Author
27
+ ------
28
+
29
+ Original author: Dimitri Geshef
30
+
31
+ Contributors:
32
+
33
+ * FIXME (contributor 1?)
34
+ * FIXME (contributor 2?)
35
+
36
+ License
37
+ -------
38
+
39
+ (The MIT License)
40
+
41
+ Copyright (c) 2023 Dimitri Geshef
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining
44
+ a copy of this software and associated documentation files (the
45
+ 'Software'), to deal in the Software without restriction, including
46
+ without limitation the rights to use, copy, modify, merge, publish,
47
+ distribute, sublicense, and/or sell copies of the Software, and to
48
+ permit persons to whom the Software is furnished to do so, subject to
49
+ the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be
52
+ included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
57
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
58
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
59
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
60
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/dendroid CHANGED
@@ -1,7 +1,6 @@
1
- #!/usr/bin/env ruby
2
-
3
- root = File.expand_path('../..', __FILE__)
4
- require File.join(root, %w[lib dendroid])
5
-
6
- # Put your code here
7
-
1
+ #!/usr/bin/env ruby
2
+
3
+ root = File.expand_path('../..', __FILE__)
4
+ require File.join(root, %w[lib dendroid])
5
+
6
+ # Put your code here
data/dendroid.gemspec CHANGED
@@ -2,22 +2,27 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'dendroid'
5
- s.version = '0.0.0'
5
+ s.version = begin
6
+ libpath = ::File.expand_path(__FILE__) + ::File::SEPARATOR
7
+ path = ::File.dirname(libpath) + ::File::SEPARATOR
8
+ ::File.read("#{path}version.txt").strip
9
+ end
6
10
  s.summary = 'Dendroid. TODO'
7
11
  s.description = 'WIP. A Ruby implementation of a Earley parser'
8
12
  s.authors = ['Dimitri Geshef']
9
13
  s.email = 'famished.tiger@yahoo.com'
10
14
  s.files = Dir['bin/dendroid',
11
- 'lib/*.*',
12
- 'lib/**/*.rb',
13
- 'spec/**/*.rb',
14
- '.rubocop.yml',
15
- 'dendroid.gemspec',
16
- 'LICENSE',
17
- 'Rakefile',
18
- 'README.md',
19
- 'version.txt'
15
+ 'lib/*.*',
16
+ 'lib/**/*.rb',
17
+ 'spec/**/*.rb',
18
+ '.rubocop.yml',
19
+ 'dendroid.gemspec',
20
+ 'LICENSE',
21
+ 'Rakefile',
22
+ 'README.md',
23
+ 'version.txt'
20
24
  ]
21
- s.homepage = 'https://rubygems.org/gems/dendroid'
25
+ s.required_ruby_version = '>=3.1'
26
+ s.homepage = 'https://github.com/famished-tiger/Dendroid'
22
27
  s.license = 'MIT'
23
28
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Namespace for all modules, classes and constants from Dendroid library.
4
+ module Dendroid
5
+ end # module
@@ -1,45 +1,45 @@
1
- # frozen_string_literal: true
2
-
3
- module Dendroid
4
- module Syntax
5
- # Abstract class for grammar symbols.
6
- # A grammar symbol is an element that appears in grammar rules.
7
- class GrmSymbol
8
- # @return [String] The name of the grammar symbol
9
- attr_reader :name
10
-
11
- # Constructor.
12
- # aSymbolName [String] The name of the grammar symbol.
13
- def initialize(symbolName)
14
- @name = valid_name(symbolName)
15
- end
16
-
17
- # The String representation of the grammar symbol
18
- # @return [String]
19
- def to_s
20
- name.to_s
21
- end
22
-
23
- # Equality testing (based on symbol name)
24
- # @return [Boolean]
25
- def ==(other)
26
- name == other.name
27
- end
28
-
29
- private
30
-
31
- def valid_name(symbolName)
32
- if symbolName.is_a?(String)
33
- stripped = symbolName.strip
34
- if stripped.empty?
35
- err_msg = 'A symbol name cannot be empty.'
36
- raise StandardError, err_msg
37
- end
38
- stripped.to_sym
39
- else
40
- symbolName
41
- end
42
- end
43
- end # class
44
- end # module
45
- end # module
1
+ # frozen_string_literal: true
2
+
3
+ module Dendroid
4
+ module Syntax
5
+ # Abstract class for grammar symbols.
6
+ # A grammar symbol is an element that appears in grammar rules.
7
+ class GrmSymbol
8
+ # @return [String] The name of the grammar symbol
9
+ attr_reader :name
10
+
11
+ # Constructor.
12
+ # aSymbolName [String] The name of the grammar symbol.
13
+ def initialize(symbolName)
14
+ @name = valid_name(symbolName)
15
+ end
16
+
17
+ # The String representation of the grammar symbol
18
+ # @return [String]
19
+ def to_s
20
+ name.to_s
21
+ end
22
+
23
+ # Equality testing (based on symbol name)
24
+ # @return [Boolean]
25
+ def ==(other)
26
+ name == other.name
27
+ end
28
+
29
+ private
30
+
31
+ def valid_name(symbolName)
32
+ if symbolName.is_a?(String)
33
+ stripped = symbolName.strip
34
+ if stripped.empty?
35
+ err_msg = 'A symbol name cannot be empty.'
36
+ raise StandardError, err_msg
37
+ end
38
+ stripped.to_sym
39
+ else
40
+ symbolName
41
+ end
42
+ end
43
+ end # class
44
+ end # module
45
+ end # module
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'grm_symbol'
4
+
5
+ module Dendroid
6
+ module Syntax
7
+ # A non-terminal symbol (sometimes called a syntactic variable) represents
8
+ # a composition of terminal or non-terminal symbols
9
+ class NonTerminal < GrmSymbol
10
+ # @return [Boolean] true if symbol can derive the null token
11
+ attr_accessor :nullable
12
+
13
+ # @return [Boolean] true iff the symbol always matches a non-empty
14
+ # sequence of terminal symbols
15
+ attr_accessor :productive
16
+
17
+ # Predicate method to check whether the symbol is a terminal symbol.
18
+ # @return [FalseClass]
19
+ def terminal?
20
+ false
21
+ end
22
+
23
+ # Predicate method to check whether the symbol can derive (match)
24
+ # the null token.
25
+ # @return [Boolean]
26
+ def nullable?
27
+ @nullable
28
+ end
29
+
30
+ # Predicate method to check whether the symbol always matches
31
+ # a non-empty sequence of terminal symbols.
32
+ # @return [Boolean]
33
+ def productive?
34
+ @productive
35
+ end
36
+ end # class
37
+ end # module
38
+ end # module
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require_relative 'grm_symbol'
5
+
6
+ module Dendroid
7
+ module Syntax
8
+ # A sequence of grammar symbols. This class is used to represent
9
+ # members of right-hand side of production rules
10
+ class SymbolSeq
11
+ extend Forwardable
12
+
13
+ # @return [Array<Dendroid::Syntax::GrmSymbol>] The sequence of symbols
14
+ attr_reader :members
15
+
16
+ def_delegators(:@members, :empty?, :first, :map, :size)
17
+
18
+ # Create a sequence of grammar symbols (as in right-hand side of
19
+ # a production rule).
20
+ # @param symbols [Array<Dendroid::Syntax::GrmSymbol>] An array of symbols.
21
+ def initialize(symbols)
22
+ @members = symbols
23
+ end
24
+
25
+ # @return [String] A text representation of the symbol sequence
26
+ def to_s
27
+ members.join(' ')
28
+ end
29
+
30
+ # Retrieve all the non-terminal symbols in the sequence.
31
+ # @return [Array<Dendroid::Syntax::NonTerminal>] array of non-terminals.
32
+ def nonterminals
33
+ members.reject(&:terminal?)
34
+ end
35
+
36
+ # Retrieve all the terminal symbols in the sequence.
37
+ # @return [Array<Dendroid::Syntax::Terminal>] array of terminals
38
+ def terminals
39
+ members.select(&:terminal?)
40
+ end
41
+
42
+ # Predicate method to check whether the sequence always derives (matches)
43
+ # a non-empty sequence of terminal symbols.
44
+ # @return [Boolean]
45
+ def productive?
46
+ empty? || members.all?(&:productive?)
47
+ end
48
+
49
+ # Equality operator.
50
+ # @param other [Dendroid::Syntax::SymbolSeq]
51
+ # @return [Boolean] true when members are equal to the ones from `other`
52
+ def ==(other)
53
+ members == other.members
54
+ end
55
+
56
+ private
57
+
58
+ def valid_members(symbols)
59
+ raise StandardError unless symbols.all? { |symb| symb.is_a?(GrmSymbol) }
60
+ end
61
+ end # class
62
+ end # module
63
+ end # module
@@ -1,40 +1,39 @@
1
- # frozen_string_literal: true
2
- require_relative 'grm_symbol'
3
-
4
- module Dendroid
5
- module Syntax
6
- # A terminal symbol is an elementary symbol of the language defined by the grammar.
7
- # More specifically, it represents a class of 'words'(or a token) of the language.
8
- class Terminal < GrmSymbol
9
- # Constructor.
10
- # aSymbolName [String] The name of the grammar symbol.
11
- def initialize(symbolName)
12
- super(symbolName)
13
- freeze
14
- end
15
-
16
- # Predicate method to check whether the symbol is a terminal symbol.
17
- # @return [TrueClass]
18
- def terminal?
19
- true
20
- end
21
-
22
- # Predicate method to check whether the symbol derives (matches)
23
- # the empty string. As terminal symbol corresponds to an input token,
24
- # so it is by definition non-nullable.
25
- # @return [FalseClass]
26
- def nullable?
27
- false
28
- end
29
-
30
- # Predicate method to check whether the symbol matches a non-empty sequence
31
- # of terminal symbols.
32
- # @return [TrueClass]
33
- def productive?
34
- true
35
- end
36
- end # class
37
- end # module
38
- end # module
39
-
40
-
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'grm_symbol'
4
+
5
+ module Dendroid
6
+ module Syntax
7
+ # A terminal symbol is an elementary symbol of the language defined by the grammar.
8
+ # More specifically, it represents a class of 'words'(or a token) of the language.
9
+ class Terminal < GrmSymbol
10
+ # Constructor.
11
+ # aSymbolName [String] The name of the grammar symbol.
12
+ def initialize(symbolName)
13
+ super(symbolName)
14
+ freeze
15
+ end
16
+
17
+ # Predicate method to check whether the symbol is a terminal symbol.
18
+ # @return [TrueClass]
19
+ def terminal?
20
+ true
21
+ end
22
+
23
+ # Predicate method to check whether the symbol derives (matches)
24
+ # the empty string. As a terminal symbol corresponds to an input token,
25
+ # it is by definition non-nullable.
26
+ # @return [FalseClass]
27
+ def nullable?
28
+ false
29
+ end
30
+
31
+ # Predicate method to check whether the symbol always matches
32
+ # a non-empty sequence of terminal symbols.
33
+ # @return [TrueClass]
34
+ def productive?
35
+ true
36
+ end
37
+ end # class
38
+ end # module
39
+ end # module
@@ -1,43 +1,45 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '..\..\spec_helper'
4
- require_relative '..\..\..\lib\dendroid\syntax\grm_symbol'
5
-
6
- describe Dendroid::Syntax::GrmSymbol do
7
- let(:sample_symbol_name) { 'INTEGER' }
8
-
9
- subject { described_class.new(sample_symbol_name) }
10
-
11
- context 'Initialization:' do
12
- it 'is initialized with a name as String' do
13
- expect { described_class.new(sample_symbol_name) }.not_to raise_error
14
- end
15
-
16
- it 'is initialized with a name as Symbol' do
17
- expect { described_class.new(:INTEGER) }.not_to raise_error
18
- end
19
-
20
- it 'raises an error if the symbol name is empty' do
21
- err_msg = 'A symbol name cannot be empty.'
22
- expect { described_class.new('') }.to raise_error(StandardError, err_msg)
23
- end
24
- end # context
25
-
26
- context 'Provided services:' do
27
- it 'knows its name as a Symbol' do
28
- expect(subject.name).to eq(sample_symbol_name.to_sym)
29
- end
30
-
31
- it 'renders a String representation of itself' do
32
- expect(subject.to_s).to eq(sample_symbol_name)
33
- end
34
-
35
- it 'can compare with another symbol' do
36
- expect(subject == subject).to be_truthy
37
- same = described_class.new(sample_symbol_name)
38
- expect(subject == same).to be_truthy
39
- different = described_class.new('NUMBER')
40
- expect(subject == different).to be_falsey
41
- end
42
- end # context
43
- end # describe
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '..\..\spec_helper'
4
+ require_relative '..\..\..\lib\dendroid\syntax\grm_symbol'
5
+
6
+ describe Dendroid::Syntax::GrmSymbol do
7
+ let(:sample_symbol_name) { 'INTEGER' }
8
+
9
+ subject { described_class.new(sample_symbol_name) }
10
+
11
+ context 'Initialization:' do
12
+ it 'is initialized with a name as String' do
13
+ expect { described_class.new(sample_symbol_name) }.not_to raise_error
14
+ end
15
+
16
+ it 'is initialized with a name as Symbol' do
17
+ expect { described_class.new(:INTEGER) }.not_to raise_error
18
+ end
19
+
20
+ it 'raises an error if the symbol name is empty' do
21
+ err_msg = 'A symbol name cannot be empty.'
22
+ expect { described_class.new('') }.to raise_error(StandardError, err_msg)
23
+ end
24
+ end # context
25
+
26
+ context 'Provided services:' do
27
+ it 'knows its name as a Symbol' do
28
+ expect(subject.name).to eq(sample_symbol_name.to_sym)
29
+ end
30
+
31
+ it 'renders a String representation of itself' do
32
+ expect(subject.to_s).to eq(sample_symbol_name)
33
+ end
34
+
35
+ # rubocop: disable Lint/BinaryOperatorWithIdenticalOperands
36
+ it 'can compare with another symbol' do
37
+ expect(subject == subject).to be_truthy
38
+ same = described_class.new(sample_symbol_name)
39
+ expect(subject == same).to be_truthy
40
+ different = described_class.new('NUMBER')
41
+ expect(subject == different).to be_falsey
42
+ end
43
+ # rubocop: enable Lint/BinaryOperatorWithIdenticalOperands
44
+ end # context
45
+ end # describe
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '..\..\spec_helper'
4
+ require_relative '..\..\..\lib\dendroid\syntax\non_terminal'
5
+
6
+ describe Dendroid::Syntax::NonTerminal do
7
+ let(:sample_nonterminal_name) { 'EXPRESSION' }
8
+
9
+ subject { described_class.new(sample_nonterminal_name) }
10
+
11
+ context 'Provided services:' do
12
+ it 'knows it is not a terminal symbol' do
13
+ expect(subject.terminal?).to be_falsey
14
+ end
15
+ end # context
16
+ end # describe
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '..\..\spec_helper'
4
+ require_relative '..\..\..\lib\dendroid\syntax\terminal'
5
+ require_relative '..\..\..\lib\dendroid\syntax\non_terminal'
6
+ require_relative '..\..\..\lib\dendroid\syntax\symbol_seq'
7
+
8
+ describe Dendroid::Syntax::SymbolSeq do
9
+ let(:num_symb) { Dendroid::Syntax::Terminal.new('NUMBER') }
10
+ let(:plus_symb) { Dendroid::Syntax::Terminal.new('PLUS') }
11
+
12
+ subject { described_class.new([num_symb, plus_symb, num_symb]) }
13
+
14
+ context 'Initialization:' do
15
+ it 'is initialized with an empty array' do
16
+ expect { described_class.new([]) }.not_to raise_error
17
+ end
18
+
19
+ it 'is initialized with an array of GrmSymbols' do
20
+ expect { described_class.new([num_symb, plus_symb, num_symb]) }.not_to raise_error
21
+ end
22
+
23
+ it 'knows its members' do
24
+ expect(subject.members).to eq([num_symb, plus_symb, num_symb])
25
+ end
26
+ end # context
27
+
28
+ context 'Provided services:' do
29
+ let(:expr_symb) { Dendroid::Syntax::NonTerminal.new('PLUS') }
30
+
31
+ it 'knows whether its body empty is empty or not' do
32
+ expect(described_class.new([]).empty?).to be_truthy
33
+ expect(subject.empty?).to be_falsey
34
+ end
35
+
36
+ it 'renders a String representation of itself' do
37
+ expect(subject.to_s).to eq('NUMBER PLUS NUMBER')
38
+ end
39
+
40
+ it 'knows its non-terminal members' do
41
+ instance = described_class.new([expr_symb, plus_symb, expr_symb])
42
+ expect(instance.nonterminals).to eq([expr_symb, expr_symb])
43
+ end
44
+
45
+ it 'knows its terminal members' do
46
+ expect(subject.terminals).to eq([num_symb, plus_symb, num_symb])
47
+ end
48
+
49
+ # rubocop: disable Lint/BinaryOperatorWithIdenticalOperands
50
+ it 'can compare with another symbol sequence' do
51
+ expect(subject == subject).to be_truthy
52
+ same = described_class.new([num_symb, plus_symb, num_symb])
53
+ expect(subject == same).to be_truthy
54
+ different = described_class.new([num_symb, plus_symb, plus_symb])
55
+ expect(subject == different).to be_falsey
56
+
57
+ # Comparing two empty sequences
58
+ empty = described_class.new([])
59
+ void = described_class.new([])
60
+ expect(empty == void).to be_truthy
61
+ end
62
+ # rubocop: enable Lint/BinaryOperatorWithIdenticalOperands
63
+
64
+ it 'knows whether it is productive' do
65
+ # Case: all members are productive
66
+ expect(subject.productive?).to be_truthy
67
+
68
+ # Case: at least one member is non-productive (expr_symb.productive is nil)
69
+ instance = described_class.new([expr_symb, plus_symb, num_symb])
70
+ expect(instance.productive?).to be_falsey
71
+ end
72
+ end # context
73
+ end # describe
@@ -1,29 +1,28 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '..\..\spec_helper'
4
- require_relative '..\..\..\lib\dendroid\syntax\terminal'
5
-
6
- describe Dendroid::Syntax::Terminal do
7
- let(:sample_terminal_name) { 'INTEGER' }
8
-
9
- subject { described_class.new(sample_terminal_name) }
10
-
11
- context 'Provided services:' do
12
- it 'knows it is a terminal symbol' do
13
- expect(subject.terminal?).to be_truthy
14
- end
15
-
16
- it 'is frozen after initialization' do
17
- expect(subject).to be_frozen
18
- end
19
-
20
- it 'is not nullable' do
21
- expect(subject).not_to be_nullable
22
- end
23
-
24
- it 'is productive (generative)' do
25
- expect(subject).to be_productive
26
- end
27
- end # context
28
- end # describe
29
-
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '..\..\spec_helper'
4
+ require_relative '..\..\..\lib\dendroid\syntax\terminal'
5
+
6
+ describe Dendroid::Syntax::Terminal do
7
+ let(:sample_terminal_name) { 'INTEGER' }
8
+
9
+ subject { described_class.new(sample_terminal_name) }
10
+
11
+ context 'Provided services:' do
12
+ it 'knows it is a terminal symbol' do
13
+ expect(subject.terminal?).to be_truthy
14
+ end
15
+
16
+ it 'is frozen after initialization' do
17
+ expect(subject).to be_frozen
18
+ end
19
+
20
+ it 'is not nullable' do
21
+ expect(subject).not_to be_nullable
22
+ end
23
+
24
+ it 'is productive (generative)' do
25
+ expect(subject).to be_productive
26
+ end
27
+ end # context
28
+ end # describe
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- # require 'rubygems'
4
- require 'rspec'
5
-
6
- RSpec.configure do |config|
7
- # Enable flags like --only-failures and --next-failure
8
- config.example_status_persistence_file_path = ".rspec_status"
9
- config.expect_with :rspec do |c|
10
- c.syntax = :expect
11
- end
12
- end
13
-
1
+ # frozen_string_literal: true
2
+
3
+ # require 'rubygems'
4
+ require 'rspec'
5
+
6
+ RSpec.configure do |config|
7
+ # Enable flags like --only-failures and --next-failure
8
+ config.example_status_persistence_file_path = '.rspec_status'
9
+ config.expect_with :rspec do |c|
10
+ c.syntax = :expect
11
+ end
12
+ end
data/version.txt CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.2
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dendroid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-27 00:00:00.000000000 Z
11
+ date: 2023-10-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: WIP. A Ruby implementation of a Earley parser
14
14
  email: famished.tiger@yahoo.com
@@ -24,12 +24,16 @@ files:
24
24
  - dendroid.gemspec
25
25
  - lib/dendroid/dendroid.rb
26
26
  - lib/dendroid/syntax/grm_symbol.rb
27
+ - lib/dendroid/syntax/non_terminal.rb
28
+ - lib/dendroid/syntax/symbol_seq.rb
27
29
  - lib/dendroid/syntax/terminal.rb
28
30
  - spec/dendroid/syntax/grm_symbol_spec.rb
31
+ - spec/dendroid/syntax/non_terminal_spec.rb
32
+ - spec/dendroid/syntax/symbol_seq_spec.rb
29
33
  - spec/dendroid/syntax/terminal_spec.rb
30
34
  - spec/spec_helper.rb
31
35
  - version.txt
32
- homepage: https://rubygems.org/gems/dendroid
36
+ homepage: https://github.com/famished-tiger/Dendroid
33
37
  licenses:
34
38
  - MIT
35
39
  metadata: {}
@@ -41,7 +45,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
41
45
  requirements:
42
46
  - - ">="
43
47
  - !ruby/object:Gem::Version
44
- version: '0'
48
+ version: '3.1'
45
49
  required_rubygems_version: !ruby/object:Gem::Requirement
46
50
  requirements:
47
51
  - - ">="