dendroid 0.0.10 → 0.0.12
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 +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +19 -0
- data/lib/dendroid/recognizer/chart.rb +55 -0
- data/lib/dendroid/recognizer/e_item.rb +47 -0
- data/lib/dendroid/recognizer/item_set.rb +38 -0
- data/lib/dendroid/recognizer/recognizer.rb +286 -0
- data/lib/dendroid/syntax/grammar.rb +1 -1
- data/spec/dendroid/grm_analysis/grm_analyzer_spec.rb +1 -72
- data/spec/dendroid/recognizer/chart_spec.rb +1 -0
- data/spec/dendroid/recognizer/e_item_spec.rb +59 -0
- data/spec/dendroid/recognizer/item_set_spec.rb +63 -0
- data/spec/dendroid/recognizer/recognizer_spec.rb +761 -0
- data/spec/dendroid/support/sample_grammars.rb +319 -0
- data/spec/dendroid/syntax/grammar_spec.rb +145 -0
- data/version.txt +1 -1
- metadata +11 -2
@@ -0,0 +1,63 @@
|
|
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
|
+
require_relative '../../../lib/dendroid/syntax/production'
|
8
|
+
require_relative '../../../lib/dendroid/grm_analysis/dotted_item'
|
9
|
+
require_relative '../../../lib/dendroid/recognizer/e_item'
|
10
|
+
require_relative '../../../lib/dendroid/recognizer/item_set'
|
11
|
+
|
12
|
+
describe Dendroid::Recognizer::ItemSet do
|
13
|
+
let(:num_symb) { Dendroid::Syntax::Terminal.new('NUMBER') }
|
14
|
+
let(:plus_symb) { Dendroid::Syntax::Terminal.new('PLUS') }
|
15
|
+
let(:expr_symb) { Dendroid::Syntax::NonTerminal.new('expression') }
|
16
|
+
let(:rhs) { Dendroid::Syntax::SymbolSeq.new([num_symb, plus_symb, num_symb]) }
|
17
|
+
let(:empty_body) { Dendroid::Syntax::SymbolSeq.new([]) }
|
18
|
+
let(:prod) { Dendroid::Syntax::Production.new(expr_symb, rhs) }
|
19
|
+
let(:empty_prod) { Dendroid::Syntax::Production.new(expr_symb, empty_body) }
|
20
|
+
let(:sample_dotted) { Dendroid::GrmAnalysis::DottedItem.new(prod, 1) }
|
21
|
+
let(:sample_origin) { 3 }
|
22
|
+
let(:other_dotted) { Dendroid::GrmAnalysis::DottedItem.new(empty_prod, 0) }
|
23
|
+
let(:first_element) { Dendroid::Recognizer::EItem.new(sample_dotted, sample_origin) }
|
24
|
+
let(:second_element) { Dendroid::Recognizer::EItem.new(other_dotted, 5) }
|
25
|
+
|
26
|
+
subject { described_class.new }
|
27
|
+
|
28
|
+
context 'Initialization:' do
|
29
|
+
it 'is initialized without argument' do
|
30
|
+
expect { described_class.new }.not_to raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'is empty at creation' do
|
34
|
+
expect(subject).to be_empty
|
35
|
+
end
|
36
|
+
end # context
|
37
|
+
|
38
|
+
context 'Provided services:' do
|
39
|
+
it 'adds a new element' do
|
40
|
+
subject.add_item(first_element)
|
41
|
+
expect(subject.size).to eq(1)
|
42
|
+
|
43
|
+
# Trying a second time, doesn't change the set
|
44
|
+
subject.add_item(first_element)
|
45
|
+
expect(subject.size).to eq(1)
|
46
|
+
|
47
|
+
subject.add_item(second_element)
|
48
|
+
expect(subject.size).to eq(2)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'can render a String representation of itself' do
|
52
|
+
subject.add_item(first_element)
|
53
|
+
subject.add_item(second_element)
|
54
|
+
|
55
|
+
expectations = [
|
56
|
+
'expression => NUMBER . PLUS NUMBER @ 3',
|
57
|
+
'expression => . @ 5'
|
58
|
+
].join("\n")
|
59
|
+
|
60
|
+
expect(subject.to_s).to eq(expectations)
|
61
|
+
end
|
62
|
+
end # context
|
63
|
+
end # describe
|