dendroid 0.2.02 → 0.2.04

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.
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../spec_helper'
4
+ require_relative '../../../lib/dendroid/parsing/parse_node'
5
+
6
+ RSpec.describe Dendroid::Parsing::ParseNode do
7
+ let(:sample_range) { 3..5 }
8
+ subject { described_class.new(3, 5) }
9
+
10
+ context 'Initialization:' do
11
+ it 'should be initialized with two token positions' do
12
+ expect { described_class.new(3, 5) }.not_to raise_error
13
+ end
14
+
15
+ it 'knows its origin and end positions' do
16
+ expect(subject.range).to eq(sample_range)
17
+ end
18
+ end # context
19
+
20
+ context 'Provided services:' do
21
+ it 'renders a String representation of its range' do
22
+ expect(subject.send(:range_to_s)).to eq('[3..5]')
23
+ end
24
+ end # context
25
+ end # describe
@@ -22,15 +22,15 @@ RSpec.describe Dendroid::Parsing::TerminalNode do
22
22
  it 'should be initialized with a symbol, terminal and a rank' do
23
23
  expect { described_class.new(ex_terminal, plus_token, 3) }.not_to raise_error
24
24
  end
25
- end
25
+ end # context
26
26
 
27
- context 'provided services' do
27
+ context 'provided services:' do
28
28
  it 'renders a String representation of itself' do
29
- expect(plus_node.to_s).to eq('PLUS [3, 4]')
29
+ expect(plus_node.to_s).to eq('PLUS [3..4]')
30
30
  end
31
31
 
32
32
  it 'renders also the token value (if any)' do
33
- expect(int_node.to_s).to eq('INTEGER: 2 [5, 6]')
33
+ expect(int_node.to_s).to eq('INTEGER: 2 [5..6]')
34
34
  end
35
35
  end
36
36
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../spec_helper'
4
+ require_relative '../support/sample_grammars'
5
+ require_relative '../../../lib/dendroid/recognizer/recognizer'
6
+ require_relative '../../../lib/dendroid/parsing/walk_progress'
7
+
8
+ RSpec.describe Dendroid::Parsing::WalkProgress do
9
+ include SampleGrammars
10
+
11
+ def retrieve_success_item(chart, grammar)
12
+ last_item_set = chart.item_sets.last
13
+ result = nil
14
+ last_item_set.items.reverse_each do |itm|
15
+ if itm.origin.zero? && itm.dotted_item.completed? && itm.dotted_item.rule.lhs == grammar.start_symbol
16
+ result = itm
17
+ break
18
+ end
19
+ end
20
+
21
+ result
22
+ end
23
+
24
+ def recognizer_for(grammar, tokenizer)
25
+ Dendroid::Recognizer::Recognizer.new(grammar, tokenizer)
26
+ end
27
+
28
+ def success_entry(chart, recognizer)
29
+ retrieve_success_item(chart, recognizer.grm_analysis.grammar)
30
+ end
31
+
32
+ subject do
33
+ recognizer = recognizer_for(grammar_l8, tokenizer_l8)
34
+ chart = recognizer.run('x x x x')
35
+ described_class.new(4, success_entry(chart, recognizer), [])
36
+ end
37
+
38
+ context 'Initialization:' do
39
+ it 'should be initialized with a symbol, terminal and a rank' do
40
+ recognizer = recognizer_for(grammar_l8, tokenizer_l8)
41
+ chart = recognizer.run('x x x x')
42
+ expect { described_class.new(4, success_entry(chart, recognizer), []) }.not_to raise_error
43
+ end
44
+
45
+ it 'is in New state' do
46
+ expect(subject.state).to eq(:New)
47
+ end
48
+
49
+ it 'has no overriding predecessor at start' do
50
+ expect(subject.predecessor).to be_nil
51
+ end
52
+
53
+ it 'knows the current rank' do
54
+ expect(subject.curr_rank).to eq(4)
55
+ end
56
+
57
+ it 'knows the current item' do
58
+ expect(subject.curr_item.to_s).to eq('S => S S . @ 0')
59
+ end
60
+ end # context
61
+ end # describe
data/version.txt CHANGED
@@ -1 +1 @@
1
- 0.2.02
1
+ 0.2.04
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.2.02
4
+ version: 0.2.04
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-12-18 00:00:00.000000000 Z
11
+ date: 2023-12-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: WIP. A Ruby implementation of an Earley parser
14
14
  email: famished.tiger@yahoo.com
@@ -62,7 +62,11 @@ files:
62
62
  - spec/dendroid/lexical/token_position_spec.rb
63
63
  - spec/dendroid/lexical/token_spec.rb
64
64
  - spec/dendroid/parsing/chart_walker_spec.rb
65
+ - spec/dendroid/parsing/composite_parse_node_spec.rb
66
+ - spec/dendroid/parsing/empty_rule_node_spec.rb
67
+ - spec/dendroid/parsing/parse_node_spec.rb
65
68
  - spec/dendroid/parsing/terminal_node_spec.rb
69
+ - spec/dendroid/parsing/walk_progress_spec.rb
66
70
  - spec/dendroid/recognizer/chart_spec.rb
67
71
  - spec/dendroid/recognizer/e_item_spec.rb
68
72
  - spec/dendroid/recognizer/item_set_spec.rb