rley 0.8.14 → 0.8.15

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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -2
  3. data/CHANGELOG.md +3 -0
  4. data/examples/general/calc_iter1/spec/calculator_spec.rb +9 -9
  5. data/examples/general/calc_iter2/spec/calculator_spec.rb +39 -39
  6. data/examples/general/recursive_right.rb +2 -2
  7. data/lib/rley/constants.rb +1 -1
  8. data/lib/rley/gfg/grm_flow_graph.rb +0 -1
  9. data/lib/rley/parser/parse_entry_set.rb +0 -1
  10. data/lib/rley/parser/parse_walker_factory.rb +0 -1
  11. data/lib/rley/rgn/grammar_builder.rb +0 -2
  12. data/lib/rley/rgn/tokenizer.rb +1 -1
  13. data/lib/rley/syntax/base_grammar_builder.rb +0 -1
  14. data/lib/rley/syntax/grammar.rb +0 -1
  15. data/spec/rley/base/dotted_item_spec.rb +46 -46
  16. data/spec/rley/base/grm_items_builder_spec.rb +1 -1
  17. data/spec/rley/engine_spec.rb +50 -50
  18. data/spec/rley/formatter/asciitree_spec.rb +8 -8
  19. data/spec/rley/formatter/bracket_notation_spec.rb +10 -10
  20. data/spec/rley/formatter/debug_spec.rb +10 -10
  21. data/spec/rley/formatter/json_spec.rb +6 -7
  22. data/spec/rley/gfg/call_edge_spec.rb +6 -6
  23. data/spec/rley/gfg/edge_spec.rb +8 -7
  24. data/spec/rley/gfg/end_vertex_spec.rb +8 -7
  25. data/spec/rley/gfg/epsilon_edge_spec.rb +5 -4
  26. data/spec/rley/gfg/grm_flow_graph_spec.rb +33 -34
  27. data/spec/rley/gfg/item_vertex_spec.rb +34 -36
  28. data/spec/rley/gfg/non_terminal_vertex_spec.rb +12 -12
  29. data/spec/rley/gfg/return_edge_spec.rb +6 -6
  30. data/spec/rley/gfg/scan_edge_spec.rb +7 -6
  31. data/spec/rley/gfg/shortcut_edge_spec.rb +15 -15
  32. data/spec/rley/gfg/start_vertex_spec.rb +8 -8
  33. data/spec/rley/gfg/vertex_spec.rb +18 -18
  34. data/spec/rley/lexical/literal_spec.rb +5 -5
  35. data/spec/rley/lexical/token_range_spec.rb +55 -55
  36. data/spec/rley/lexical/token_spec.rb +17 -16
  37. data/spec/rley/parse_forest_visitor_spec.rb +30 -32
  38. data/spec/rley/parse_rep/ambiguous_parse_spec.rb +2 -2
  39. data/spec/rley/parse_rep/ast_builder_spec.rb +30 -30
  40. data/spec/rley/parse_rep/cst_builder_spec.rb +85 -85
  41. data/spec/rley/parse_rep/groucho_spec.rb +23 -23
  42. data/spec/rley/parse_rep/parse_forest_builder_spec.rb +42 -42
  43. data/spec/rley/parse_rep/parse_forest_factory_spec.rb +10 -12
  44. data/spec/rley/parse_rep/parse_tree_factory_spec.rb +10 -15
  45. data/spec/rley/parse_tree_visitor_spec.rb +43 -46
  46. data/spec/rley/parser/dangling_else_spec.rb +12 -12
  47. data/spec/rley/parser/error_reason_spec.rb +37 -37
  48. data/spec/rley/parser/gfg_chart_spec.rb +27 -29
  49. data/spec/rley/parser/gfg_earley_parser_spec.rb +55 -56
  50. data/spec/rley/parser/gfg_parsing_spec.rb +106 -103
  51. data/spec/rley/parser/parse_entry_set_spec.rb +63 -61
  52. data/spec/rley/parser/parse_entry_spec.rb +73 -71
  53. data/spec/rley/parser/parse_walker_factory_spec.rb +14 -15
  54. data/spec/rley/ptree/non_terminal_node_spec.rb +16 -16
  55. data/spec/rley/ptree/parse_tree_node_spec.rb +11 -11
  56. data/spec/rley/ptree/parse_tree_spec.rb +6 -8
  57. data/spec/rley/ptree/terminal_node_spec.rb +6 -6
  58. data/spec/rley/rgn/grammar_builder_spec.rb +69 -67
  59. data/spec/rley/rgn/parser_spec.rb +63 -63
  60. data/spec/rley/rgn/repetition_node_spec.rb +15 -15
  61. data/spec/rley/rgn/sequence_node_spec.rb +10 -10
  62. data/spec/rley/rgn/symbol_node_spec.rb +5 -6
  63. data/spec/rley/rgn/tokenizer_spec.rb +68 -67
  64. data/spec/rley/sppf/alternative_node_spec.rb +16 -16
  65. data/spec/rley/sppf/non_terminal_node_spec.rb +20 -20
  66. data/spec/rley/sppf/token_node_spec.rb +13 -13
  67. data/spec/rley/syntax/base_grammar_builder_spec.rb +76 -86
  68. data/spec/rley/syntax/grammar_spec.rb +40 -78
  69. data/spec/rley/syntax/grm_symbol_spec.rb +7 -7
  70. data/spec/rley/syntax/match_closest_spec.rb +8 -8
  71. data/spec/rley/syntax/non_terminal_spec.rb +25 -25
  72. data/spec/rley/syntax/production_spec.rb +33 -33
  73. data/spec/rley/syntax/symbol_seq_spec.rb +27 -27
  74. data/spec/rley/syntax/terminal_spec.rb +12 -11
  75. data/spec/support/base_tokenizer_spec.rb +9 -8
  76. metadata +2 -2
@@ -12,82 +12,82 @@ require_relative '../../../lib/rley/syntax/production'
12
12
  module Rley # Open this namespace to avoid module qualifier prefixes
13
13
  module Syntax # Open this namespace to avoid module qualifier prefixes
14
14
  describe Production do
15
+ # Default instantiation rule
16
+ subject(:a_production) { described_class.new(sentence, sequence) }
17
+
15
18
  let(:sentence) { NonTerminal.new('Sentence') }
16
19
  let(:np) { NonTerminal.new('NP') }
17
20
  let(:vp) { NonTerminal.new('VP') }
18
21
  let(:sequence) { [np, vp] }
19
22
 
20
- # Default instantiation rule
21
- subject { Production.new(sentence, sequence) }
22
-
23
23
  context 'Initialization:' do
24
- it 'should be created with a non-terminal and a symbol sequence' do
25
- expect { Production.new(sentence, sequence) }.not_to raise_error
24
+ it 'is created with a non-terminal and a symbol sequence' do
25
+ expect { described_class.new(sentence, sequence) }.not_to raise_error
26
26
  end
27
27
 
28
- it 'should complain when its rhs is nil' do
28
+ it 'complains when its rhs is nil' do
29
29
  err = StandardError
30
30
  msg_prefix = 'Right side of a production of the kind '
31
31
  msg_suffix = "'Sentence' => ... is nil."
32
32
  msg = msg_prefix + msg_suffix
33
- expect { Production.new(sentence, nil) }.to raise_error(err, msg)
33
+ expect { described_class.new(sentence, nil) }.to raise_error(err, msg)
34
34
  end
35
35
 
36
- it 'should know its lhs' do
37
- expect(subject.lhs).to eq(sentence)
38
- expect(subject.head).to eq(sentence)
36
+ it 'knows its lhs' do
37
+ expect(a_production.lhs).to eq(sentence)
38
+ expect(a_production.head).to eq(sentence)
39
39
  end
40
40
 
41
- it 'should know its rhs' do
42
- expect(subject.rhs).to eq(sequence)
43
- expect(subject.body).to eq(sequence)
41
+ it 'knows its rhs' do
42
+ expect(a_production.rhs).to eq(sequence)
43
+ expect(a_production.body).to eq(sequence)
44
44
  end
45
45
 
46
- it 'should be free from constraints at start' do
47
- expect(subject.constraints).to be_empty
46
+ it 'is free from constraints at start' do
47
+ expect(a_production.constraints).to be_empty
48
48
  end
49
49
 
50
- it 'should know whether its rhs is empty' do
51
- expect(subject).not_to be_empty
50
+ it 'knows whether its rhs is empty' do
51
+ expect(a_production).not_to be_empty
52
52
 
53
- instance = Production.new(sentence, [])
53
+ instance = described_class.new(sentence, [])
54
54
  expect(instance).to be_empty
55
55
  end
56
56
 
57
- it 'should be anonymous at creation' do
58
- expect(subject.name).to be_nil
57
+ it 'is anonymous at creation' do
58
+ expect(a_production.name).to be_nil
59
59
  end
60
60
 
61
- it 'should complain if its lhs is not a non-terminal' do
61
+ it 'complains if its lhs is not a non-terminal' do
62
62
  err = StandardError
63
63
  msg_prefix = 'Left side of production must be a non-terminal symbol'
64
64
  msg_suffix = ", found a #{String} instead."
65
65
  msg = msg_prefix + msg_suffix
66
- expect { Production.new('wrong', sequence) }.to raise_error(err, msg)
66
+ expect { described_class.new('wrong', sequence) }.to raise_error(err, msg)
67
67
  end
68
68
  end # context
69
69
 
70
70
  context 'Provided services:' do
71
- it 'should accept a name (i)' do
71
+ it 'accepts a name (i)' do
72
72
  a_name = 'nominem'
73
- subject.name = a_name
74
- expect(subject.name).to eq(a_name)
73
+ a_production.name = a_name
74
+ expect(a_production.name).to eq(a_name)
75
75
  end
76
76
 
77
- it 'should accept a name (ii)' do
77
+ it 'accepts a name (ii)' do
78
78
  a_name = 'nominem'
79
- subject.as(a_name)
80
- expect(subject.name).to eq(a_name)
79
+ a_production.as(a_name)
80
+ expect(a_production.name).to eq(a_name)
81
81
  end
82
82
 
83
- it 'should provide human-readable representation of itself' do
84
- subject.name = 'some name'
83
+ it 'provides a human-readable representation of itself' do
84
+ a_production.name = 'some name'
85
85
  prefix = /^#<Rley::Syntax::Production:\d+ @name="some name"/
86
- expect(subject.inspect).to match(prefix)
86
+ expect(a_production.inspect).to match(prefix)
87
87
  pattern = /@lhs=Sentence @rhs=#<Rley::Syntax::SymbolSeq/
88
- expect(subject.inspect).to match(pattern)
88
+ expect(a_production.inspect).to match(pattern)
89
89
  suffix = /> @generative=>$/
90
- expect(subject.inspect).to match(suffix)
90
+ expect(a_production.inspect).to match(suffix)
91
91
  end
92
92
  end # context
93
93
  end # describe
@@ -10,63 +10,63 @@ require_relative '../../../lib/rley/syntax/symbol_seq'
10
10
  module Rley # Open this namespace to avoid module qualifier prefixes
11
11
  module Syntax # Open this namespace to avoid module qualifier prefixes
12
12
  describe SymbolSeq do
13
+ # Default instantiation rule
14
+ subject(:symbol_sequence) { described_class.new([verb, np, pp]) }
15
+
13
16
  let(:verb) { NonTerminal.new('Verb') }
14
17
  let(:np) { NonTerminal.new('NP') }
15
18
  let(:pp) { NonTerminal.new('PP') }
16
19
 
17
- # Default instantiation rule
18
- subject { SymbolSeq.new([verb, np, pp]) }
19
-
20
20
  context 'Initialization:' do
21
- it 'should be created with a list of symbols' do
21
+ it 'is created with a list of symbols' do
22
22
  # Case of non-empty sequence
23
- expect { SymbolSeq.new([verb, np, pp]) }.not_to raise_error
23
+ expect { described_class.new([verb, np, pp]) }.not_to raise_error
24
24
 
25
25
  # Case of empty sequence
26
- expect { SymbolSeq.new([]) }.not_to raise_error
26
+ expect { described_class.new([]) }.not_to raise_error
27
27
  end
28
28
 
29
- it 'should know its members' do
30
- expect(subject.members).to eq([verb, np, pp])
29
+ it 'knows its members' do
30
+ expect(symbol_sequence.members).to eq([verb, np, pp])
31
31
  end
32
32
 
33
- it 'should know whether it is empty' do
34
- expect(subject).not_to be_empty
35
- instance = SymbolSeq.new([])
33
+ it 'knows whether it is empty' do
34
+ expect(symbol_sequence).not_to be_empty
35
+ instance = described_class.new([])
36
36
  expect(instance).to be_empty
37
37
  end
38
38
 
39
- it 'should the count of its members' do
40
- expect(subject.size).to eq(3)
39
+ it 'knows the count of its members' do
40
+ expect(symbol_sequence.size).to be(3)
41
41
  end
42
42
  end # context
43
43
 
44
44
  context 'Provided services:' do
45
- it 'should compare compare with itself' do
46
- me = subject # Use another name to please Rubocop
47
- expect(subject == me).to eq(true)
45
+ it 'compares with itself' do
46
+ me = symbol_sequence # Use another name to please Rubocop
47
+ expect(symbol_sequence == me).to be(true)
48
48
  end
49
49
 
50
- it 'should compare with another instance' do
51
- empty_one = SymbolSeq.new([])
52
- expect(subject == empty_one).not_to eq(true)
50
+ it 'compares with another instance' do
51
+ empty_one = described_class.new([])
52
+ expect(symbol_sequence == empty_one).not_to be(true)
53
53
 
54
- equal_one = SymbolSeq.new([verb, np, pp])
55
- expect(subject == equal_one).to eq(true)
54
+ equal_one = described_class.new([verb, np, pp])
55
+ expect(symbol_sequence == equal_one).to be(true)
56
56
 
57
- unequal_one = SymbolSeq.new([verb, pp, np])
58
- expect(subject == unequal_one).not_to eq(true)
57
+ unequal_one = described_class.new([verb, pp, np])
58
+ expect(symbol_sequence == unequal_one).not_to be(true)
59
59
  end
60
60
 
61
- it 'should complain when unable to compare' do
61
+ it 'complains when unable to compare' do
62
62
  err = StandardError
63
63
  msg = 'Cannot compare a SymbolSeq with a String'
64
- expect { subject == 'dummy-text' }.to raise_error(err, msg)
64
+ expect { symbol_sequence == 'dummy-text' }.to raise_error(err, msg)
65
65
  end
66
66
 
67
- it 'should provide human-readable representation of itself' do
67
+ it 'provides human-readable representation of itself' do
68
68
  suffix = /::SymbolSeq:\d+ @members=\["Verb", "NP", "PP"\]>$/
69
- expect(subject.inspect).to match(suffix)
69
+ expect(symbol_sequence.inspect).to match(suffix)
70
70
  end
71
71
  end # context
72
72
  end # describe
@@ -8,28 +8,29 @@ require_relative '../../../lib/rley/syntax/terminal'
8
8
  module Rley # Open this namespace to avoid module qualifier prefixes
9
9
  module Syntax # Open this namespace to avoid module qualifier prefixes
10
10
  describe Terminal do
11
+ subject(:the_terminal) { described_class.new(sample_name) }
12
+
11
13
  let(:sample_name) { 'noun' }
12
- subject { Terminal.new(sample_name) }
13
14
 
14
15
  context 'Initialization:' do
15
- it 'should be created with a name' do
16
- expect { Terminal.new('noun') }.not_to raise_error
16
+ it 'is created with a name' do
17
+ expect { described_class.new('noun') }.not_to raise_error
17
18
  end
18
19
 
19
- it 'should know its name' do
20
- expect(subject.name).to eq(sample_name)
20
+ it 'knows its name' do
21
+ expect(the_terminal.name).to eq(sample_name)
21
22
  end
22
23
 
23
- it 'should know that is a terminal symbol' do
24
- expect(subject).to be_terminal
24
+ it 'knows that is a terminal symbol' do
25
+ expect(the_terminal).to be_terminal
25
26
  end
26
27
 
27
- it "should know that isn't nullable" do
28
- expect(subject).not_to be_nullable
28
+ it "knows that isn't nullable" do
29
+ expect(the_terminal).not_to be_nullable
29
30
  end
30
31
 
31
- it 'should know that it is generative' do
32
- expect(subject).to be_generative
32
+ it 'knows that it is generative' do
33
+ expect(the_terminal).to be_generative
33
34
  end
34
35
  end # context
35
36
  end # describe
@@ -7,19 +7,20 @@ require_relative '../../lib/support/base_tokenizer'
7
7
 
8
8
  describe BaseTokenizer do
9
9
  let(:sample_input) { '7 + (8 + 9)' }
10
+
10
11
  context 'Standard creation & initialization:' do
11
- subject { BaseTokenizer.new(sample_input) }
12
+ subject(:tokenizer) { described_class.new(sample_input) }
12
13
 
13
- it 'should be initialized with a text argument' do
14
- expect { BaseTokenizer.new(sample_input) }.not_to raise_error
14
+ it 'is initialized with a text argument' do
15
+ expect { described_class.new(sample_input) }.not_to raise_error
15
16
  end
16
17
 
17
- it 'should have a scanner initialized' do
18
- expect(subject.scanner).to be_kind_of(StringScanner)
18
+ it 'has a scanner initialized' do
19
+ expect(tokenizer.scanner).to be_a(StringScanner)
19
20
  end
20
21
 
21
- it 'should have line number initialized' do
22
- expect(subject.lineno).to eq(1)
22
+ it 'has line number initialized' do
23
+ expect(tokenizer.lineno).to eq(1)
23
24
  end
24
25
  end # context
25
26
 
@@ -58,7 +59,7 @@ describe BaseTokenizer do
58
59
  tokenizer.tokens
59
60
  end
60
61
 
61
- it 'should return a sequence of tokens' do
62
+ it 'returns a sequence of tokens' do
62
63
  sequence = tokenize(sample_input)
63
64
  checks = [
64
65
  ['int', 7, [1, 1]],
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.14
4
+ version: 0.8.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-26 00:00:00.000000000 Z
10
+ date: 2025-02-28 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: prime