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.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -2
- data/CHANGELOG.md +3 -0
- data/examples/general/calc_iter1/spec/calculator_spec.rb +9 -9
- data/examples/general/calc_iter2/spec/calculator_spec.rb +39 -39
- data/examples/general/recursive_right.rb +2 -2
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/gfg/grm_flow_graph.rb +0 -1
- data/lib/rley/parser/parse_entry_set.rb +0 -1
- data/lib/rley/parser/parse_walker_factory.rb +0 -1
- data/lib/rley/rgn/grammar_builder.rb +0 -2
- data/lib/rley/rgn/tokenizer.rb +1 -1
- data/lib/rley/syntax/base_grammar_builder.rb +0 -1
- data/lib/rley/syntax/grammar.rb +0 -1
- data/spec/rley/base/dotted_item_spec.rb +46 -46
- data/spec/rley/base/grm_items_builder_spec.rb +1 -1
- data/spec/rley/engine_spec.rb +50 -50
- data/spec/rley/formatter/asciitree_spec.rb +8 -8
- data/spec/rley/formatter/bracket_notation_spec.rb +10 -10
- data/spec/rley/formatter/debug_spec.rb +10 -10
- data/spec/rley/formatter/json_spec.rb +6 -7
- data/spec/rley/gfg/call_edge_spec.rb +6 -6
- data/spec/rley/gfg/edge_spec.rb +8 -7
- data/spec/rley/gfg/end_vertex_spec.rb +8 -7
- data/spec/rley/gfg/epsilon_edge_spec.rb +5 -4
- data/spec/rley/gfg/grm_flow_graph_spec.rb +33 -34
- data/spec/rley/gfg/item_vertex_spec.rb +34 -36
- data/spec/rley/gfg/non_terminal_vertex_spec.rb +12 -12
- data/spec/rley/gfg/return_edge_spec.rb +6 -6
- data/spec/rley/gfg/scan_edge_spec.rb +7 -6
- data/spec/rley/gfg/shortcut_edge_spec.rb +15 -15
- data/spec/rley/gfg/start_vertex_spec.rb +8 -8
- data/spec/rley/gfg/vertex_spec.rb +18 -18
- data/spec/rley/lexical/literal_spec.rb +5 -5
- data/spec/rley/lexical/token_range_spec.rb +55 -55
- data/spec/rley/lexical/token_spec.rb +17 -16
- data/spec/rley/parse_forest_visitor_spec.rb +30 -32
- data/spec/rley/parse_rep/ambiguous_parse_spec.rb +2 -2
- data/spec/rley/parse_rep/ast_builder_spec.rb +30 -30
- data/spec/rley/parse_rep/cst_builder_spec.rb +85 -85
- data/spec/rley/parse_rep/groucho_spec.rb +23 -23
- data/spec/rley/parse_rep/parse_forest_builder_spec.rb +42 -42
- data/spec/rley/parse_rep/parse_forest_factory_spec.rb +10 -12
- data/spec/rley/parse_rep/parse_tree_factory_spec.rb +10 -15
- data/spec/rley/parse_tree_visitor_spec.rb +43 -46
- data/spec/rley/parser/dangling_else_spec.rb +12 -12
- data/spec/rley/parser/error_reason_spec.rb +37 -37
- data/spec/rley/parser/gfg_chart_spec.rb +27 -29
- data/spec/rley/parser/gfg_earley_parser_spec.rb +55 -56
- data/spec/rley/parser/gfg_parsing_spec.rb +106 -103
- data/spec/rley/parser/parse_entry_set_spec.rb +63 -61
- data/spec/rley/parser/parse_entry_spec.rb +73 -71
- data/spec/rley/parser/parse_walker_factory_spec.rb +14 -15
- data/spec/rley/ptree/non_terminal_node_spec.rb +16 -16
- data/spec/rley/ptree/parse_tree_node_spec.rb +11 -11
- data/spec/rley/ptree/parse_tree_spec.rb +6 -8
- data/spec/rley/ptree/terminal_node_spec.rb +6 -6
- data/spec/rley/rgn/grammar_builder_spec.rb +69 -67
- data/spec/rley/rgn/parser_spec.rb +63 -63
- data/spec/rley/rgn/repetition_node_spec.rb +15 -15
- data/spec/rley/rgn/sequence_node_spec.rb +10 -10
- data/spec/rley/rgn/symbol_node_spec.rb +5 -6
- data/spec/rley/rgn/tokenizer_spec.rb +68 -67
- data/spec/rley/sppf/alternative_node_spec.rb +16 -16
- data/spec/rley/sppf/non_terminal_node_spec.rb +20 -20
- data/spec/rley/sppf/token_node_spec.rb +13 -13
- data/spec/rley/syntax/base_grammar_builder_spec.rb +76 -86
- data/spec/rley/syntax/grammar_spec.rb +40 -78
- data/spec/rley/syntax/grm_symbol_spec.rb +7 -7
- data/spec/rley/syntax/match_closest_spec.rb +8 -8
- data/spec/rley/syntax/non_terminal_spec.rb +25 -25
- data/spec/rley/syntax/production_spec.rb +33 -33
- data/spec/rley/syntax/symbol_seq_spec.rb +27 -27
- data/spec/rley/syntax/terminal_spec.rb +12 -11
- data/spec/support/base_tokenizer_spec.rb +9 -8
- 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 '
|
25
|
-
expect {
|
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 '
|
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 {
|
33
|
+
expect { described_class.new(sentence, nil) }.to raise_error(err, msg)
|
34
34
|
end
|
35
35
|
|
36
|
-
it '
|
37
|
-
expect(
|
38
|
-
expect(
|
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 '
|
42
|
-
expect(
|
43
|
-
expect(
|
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 '
|
47
|
-
expect(
|
46
|
+
it 'is free from constraints at start' do
|
47
|
+
expect(a_production.constraints).to be_empty
|
48
48
|
end
|
49
49
|
|
50
|
-
it '
|
51
|
-
expect(
|
50
|
+
it 'knows whether its rhs is empty' do
|
51
|
+
expect(a_production).not_to be_empty
|
52
52
|
|
53
|
-
instance =
|
53
|
+
instance = described_class.new(sentence, [])
|
54
54
|
expect(instance).to be_empty
|
55
55
|
end
|
56
56
|
|
57
|
-
it '
|
58
|
-
expect(
|
57
|
+
it 'is anonymous at creation' do
|
58
|
+
expect(a_production.name).to be_nil
|
59
59
|
end
|
60
60
|
|
61
|
-
it '
|
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 {
|
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 '
|
71
|
+
it 'accepts a name (i)' do
|
72
72
|
a_name = 'nominem'
|
73
|
-
|
74
|
-
expect(
|
73
|
+
a_production.name = a_name
|
74
|
+
expect(a_production.name).to eq(a_name)
|
75
75
|
end
|
76
76
|
|
77
|
-
it '
|
77
|
+
it 'accepts a name (ii)' do
|
78
78
|
a_name = 'nominem'
|
79
|
-
|
80
|
-
expect(
|
79
|
+
a_production.as(a_name)
|
80
|
+
expect(a_production.name).to eq(a_name)
|
81
81
|
end
|
82
82
|
|
83
|
-
it '
|
84
|
-
|
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(
|
86
|
+
expect(a_production.inspect).to match(prefix)
|
87
87
|
pattern = /@lhs=Sentence @rhs=#<Rley::Syntax::SymbolSeq/
|
88
|
-
expect(
|
88
|
+
expect(a_production.inspect).to match(pattern)
|
89
89
|
suffix = /> @generative=>$/
|
90
|
-
expect(
|
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 '
|
21
|
+
it 'is created with a list of symbols' do
|
22
22
|
# Case of non-empty sequence
|
23
|
-
expect {
|
23
|
+
expect { described_class.new([verb, np, pp]) }.not_to raise_error
|
24
24
|
|
25
25
|
# Case of empty sequence
|
26
|
-
expect {
|
26
|
+
expect { described_class.new([]) }.not_to raise_error
|
27
27
|
end
|
28
28
|
|
29
|
-
it '
|
30
|
-
expect(
|
29
|
+
it 'knows its members' do
|
30
|
+
expect(symbol_sequence.members).to eq([verb, np, pp])
|
31
31
|
end
|
32
32
|
|
33
|
-
it '
|
34
|
-
expect(
|
35
|
-
instance =
|
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 '
|
40
|
-
expect(
|
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 '
|
46
|
-
me =
|
47
|
-
expect(
|
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 '
|
51
|
-
empty_one =
|
52
|
-
expect(
|
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 =
|
55
|
-
expect(
|
54
|
+
equal_one = described_class.new([verb, np, pp])
|
55
|
+
expect(symbol_sequence == equal_one).to be(true)
|
56
56
|
|
57
|
-
unequal_one =
|
58
|
-
expect(
|
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 '
|
61
|
+
it 'complains when unable to compare' do
|
62
62
|
err = StandardError
|
63
63
|
msg = 'Cannot compare a SymbolSeq with a String'
|
64
|
-
expect {
|
64
|
+
expect { symbol_sequence == 'dummy-text' }.to raise_error(err, msg)
|
65
65
|
end
|
66
66
|
|
67
|
-
it '
|
67
|
+
it 'provides human-readable representation of itself' do
|
68
68
|
suffix = /::SymbolSeq:\d+ @members=\["Verb", "NP", "PP"\]>$/
|
69
|
-
expect(
|
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 '
|
16
|
-
expect {
|
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 '
|
20
|
-
expect(
|
20
|
+
it 'knows its name' do
|
21
|
+
expect(the_terminal.name).to eq(sample_name)
|
21
22
|
end
|
22
23
|
|
23
|
-
it '
|
24
|
-
expect(
|
24
|
+
it 'knows that is a terminal symbol' do
|
25
|
+
expect(the_terminal).to be_terminal
|
25
26
|
end
|
26
27
|
|
27
|
-
it "
|
28
|
-
expect(
|
28
|
+
it "knows that isn't nullable" do
|
29
|
+
expect(the_terminal).not_to be_nullable
|
29
30
|
end
|
30
31
|
|
31
|
-
it '
|
32
|
-
expect(
|
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 {
|
12
|
+
subject(:tokenizer) { described_class.new(sample_input) }
|
12
13
|
|
13
|
-
it '
|
14
|
-
expect {
|
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 '
|
18
|
-
expect(
|
18
|
+
it 'has a scanner initialized' do
|
19
|
+
expect(tokenizer.scanner).to be_a(StringScanner)
|
19
20
|
end
|
20
21
|
|
21
|
-
it '
|
22
|
-
expect(
|
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 '
|
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.
|
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-
|
10
|
+
date: 2025-02-28 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: prime
|