rley 0.7.03 → 0.7.08

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 (174) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +362 -62
  3. data/.travis.yml +6 -7
  4. data/CHANGELOG.md +20 -1
  5. data/LICENSE.txt +1 -1
  6. data/README.md +6 -7
  7. data/Rakefile +2 -0
  8. data/appveyor.yml +2 -4
  9. data/examples/NLP/benchmark_pico_en.rb +2 -0
  10. data/examples/NLP/engtagger.rb +193 -188
  11. data/examples/NLP/nano_eng/nano_en_demo.rb +2 -0
  12. data/examples/NLP/nano_eng/nano_grammar.rb +7 -5
  13. data/examples/NLP/pico_en_demo.rb +2 -0
  14. data/examples/data_formats/JSON/cli_options.rb +3 -1
  15. data/examples/data_formats/JSON/json_ast_builder.rb +14 -9
  16. data/examples/data_formats/JSON/json_ast_nodes.rb +14 -21
  17. data/examples/data_formats/JSON/json_demo.rb +2 -0
  18. data/examples/data_formats/JSON/json_grammar.rb +4 -2
  19. data/examples/data_formats/JSON/json_lexer.rb +10 -8
  20. data/examples/data_formats/JSON/json_minifier.rb +3 -1
  21. data/examples/general/calc_iter1/calc_ast_builder.rb +15 -10
  22. data/examples/general/calc_iter1/calc_ast_nodes.rb +25 -37
  23. data/examples/general/calc_iter1/calc_demo.rb +2 -0
  24. data/examples/general/calc_iter1/calc_grammar.rb +4 -2
  25. data/examples/general/calc_iter1/calc_lexer.rb +8 -4
  26. data/examples/general/calc_iter1/spec/calculator_spec.rb +7 -5
  27. data/examples/general/calc_iter2/calc_ast_builder.rb +7 -3
  28. data/examples/general/calc_iter2/calc_ast_nodes.rb +29 -43
  29. data/examples/general/calc_iter2/calc_demo.rb +2 -0
  30. data/examples/general/calc_iter2/calc_grammar.rb +5 -3
  31. data/examples/general/calc_iter2/calc_lexer.rb +13 -10
  32. data/examples/general/calc_iter2/spec/calculator_spec.rb +28 -26
  33. data/examples/general/left.rb +4 -2
  34. data/examples/general/right.rb +4 -2
  35. data/lib/rley.rb +2 -0
  36. data/lib/rley/base/base_parser.rb +2 -0
  37. data/lib/rley/base/dotted_item.rb +38 -41
  38. data/lib/rley/base/grm_items_builder.rb +2 -0
  39. data/lib/rley/constants.rb +5 -3
  40. data/lib/rley/engine.rb +22 -24
  41. data/lib/rley/formatter/asciitree.rb +6 -4
  42. data/lib/rley/formatter/base_formatter.rb +2 -0
  43. data/lib/rley/formatter/bracket_notation.rb +3 -8
  44. data/lib/rley/formatter/debug.rb +8 -6
  45. data/lib/rley/formatter/json.rb +4 -2
  46. data/lib/rley/gfg/call_edge.rb +3 -1
  47. data/lib/rley/gfg/edge.rb +7 -5
  48. data/lib/rley/gfg/end_vertex.rb +4 -6
  49. data/lib/rley/gfg/epsilon_edge.rb +3 -5
  50. data/lib/rley/gfg/grm_flow_graph.rb +31 -25
  51. data/lib/rley/gfg/item_vertex.rb +12 -22
  52. data/lib/rley/gfg/non_terminal_vertex.rb +6 -4
  53. data/lib/rley/gfg/return_edge.rb +2 -0
  54. data/lib/rley/gfg/scan_edge.rb +3 -1
  55. data/lib/rley/gfg/shortcut_edge.rb +4 -2
  56. data/lib/rley/gfg/start_vertex.rb +6 -8
  57. data/lib/rley/gfg/vertex.rb +47 -41
  58. data/lib/rley/lexical/token.rb +3 -1
  59. data/lib/rley/lexical/token_range.rb +8 -6
  60. data/lib/rley/parse_forest_visitor.rb +7 -5
  61. data/lib/rley/parse_rep/ast_base_builder.rb +11 -11
  62. data/lib/rley/parse_rep/cst_builder.rb +7 -4
  63. data/lib/rley/parse_rep/parse_forest_builder.rb +36 -25
  64. data/lib/rley/parse_rep/parse_forest_factory.rb +5 -3
  65. data/lib/rley/parse_rep/parse_rep_creator.rb +18 -13
  66. data/lib/rley/parse_rep/parse_tree_builder.rb +15 -15
  67. data/lib/rley/parse_rep/parse_tree_factory.rb +27 -25
  68. data/lib/rley/parse_tree_visitor.rb +3 -1
  69. data/lib/rley/parser/error_reason.rb +9 -8
  70. data/lib/rley/parser/gfg_chart.rb +54 -22
  71. data/lib/rley/parser/gfg_earley_parser.rb +3 -1
  72. data/lib/rley/parser/gfg_parsing.rb +51 -31
  73. data/lib/rley/parser/parse_entry.rb +29 -33
  74. data/lib/rley/parser/parse_entry_set.rb +32 -27
  75. data/lib/rley/parser/parse_entry_tracker.rb +6 -4
  76. data/lib/rley/parser/parse_state.rb +18 -21
  77. data/lib/rley/parser/parse_state_tracker.rb +6 -4
  78. data/lib/rley/parser/parse_tracer.rb +15 -13
  79. data/lib/rley/parser/parse_walker_factory.rb +28 -29
  80. data/lib/rley/parser/state_set.rb +11 -10
  81. data/lib/rley/ptree/non_terminal_node.rb +10 -6
  82. data/lib/rley/ptree/parse_tree.rb +6 -4
  83. data/lib/rley/ptree/parse_tree_node.rb +7 -5
  84. data/lib/rley/ptree/terminal_node.rb +9 -7
  85. data/lib/rley/rley_error.rb +12 -10
  86. data/lib/rley/sppf/alternative_node.rb +8 -6
  87. data/lib/rley/sppf/composite_node.rb +9 -7
  88. data/lib/rley/sppf/epsilon_node.rb +5 -3
  89. data/lib/rley/sppf/leaf_node.rb +5 -3
  90. data/lib/rley/sppf/non_terminal_node.rb +2 -0
  91. data/lib/rley/sppf/parse_forest.rb +19 -17
  92. data/lib/rley/sppf/sppf_node.rb +9 -8
  93. data/lib/rley/sppf/token_node.rb +5 -3
  94. data/lib/rley/syntax/grammar.rb +7 -5
  95. data/lib/rley/syntax/grammar_builder.rb +11 -9
  96. data/lib/rley/syntax/grm_symbol.rb +8 -6
  97. data/lib/rley/syntax/literal.rb +2 -0
  98. data/lib/rley/syntax/non_terminal.rb +11 -15
  99. data/lib/rley/syntax/production.rb +13 -11
  100. data/lib/rley/syntax/symbol_seq.rb +10 -10
  101. data/lib/rley/syntax/terminal.rb +6 -5
  102. data/lib/rley/syntax/verbatim_symbol.rb +5 -3
  103. data/lib/support/base_tokenizer.rb +23 -20
  104. data/spec/rley/base/dotted_item_spec.rb +4 -2
  105. data/spec/rley/base/grm_items_builder_spec.rb +2 -0
  106. data/spec/rley/engine_spec.rb +47 -9
  107. data/spec/rley/formatter/asciitree_spec.rb +11 -9
  108. data/spec/rley/formatter/bracket_notation_spec.rb +16 -14
  109. data/spec/rley/formatter/debug_spec.rb +4 -2
  110. data/spec/rley/formatter/json_spec.rb +5 -3
  111. data/spec/rley/gfg/call_edge_spec.rb +2 -0
  112. data/spec/rley/gfg/edge_spec.rb +2 -0
  113. data/spec/rley/gfg/end_vertex_spec.rb +7 -5
  114. data/spec/rley/gfg/epsilon_edge_spec.rb +2 -0
  115. data/spec/rley/gfg/grm_flow_graph_spec.rb +2 -0
  116. data/spec/rley/gfg/item_vertex_spec.rb +12 -10
  117. data/spec/rley/gfg/non_terminal_vertex_spec.rb +5 -3
  118. data/spec/rley/gfg/return_edge_spec.rb +2 -0
  119. data/spec/rley/gfg/scan_edge_spec.rb +2 -0
  120. data/spec/rley/gfg/shortcut_edge_spec.rb +3 -1
  121. data/spec/rley/gfg/start_vertex_spec.rb +7 -5
  122. data/spec/rley/gfg/vertex_spec.rb +5 -3
  123. data/spec/rley/lexical/token_range_spec.rb +18 -16
  124. data/spec/rley/lexical/token_spec.rb +4 -2
  125. data/spec/rley/parse_forest_visitor_spec.rb +167 -163
  126. data/spec/rley/parse_rep/ambiguous_parse_spec.rb +46 -44
  127. data/spec/rley/parse_rep/ast_builder_spec.rb +8 -6
  128. data/spec/rley/parse_rep/cst_builder_spec.rb +7 -5
  129. data/spec/rley/parse_rep/groucho_spec.rb +25 -25
  130. data/spec/rley/parse_rep/parse_forest_builder_spec.rb +28 -26
  131. data/spec/rley/parse_rep/parse_forest_factory_spec.rb +8 -6
  132. data/spec/rley/parse_rep/parse_tree_factory_spec.rb +4 -2
  133. data/spec/rley/parse_tree_visitor_spec.rb +12 -8
  134. data/spec/rley/parser/error_reason_spec.rb +8 -6
  135. data/spec/rley/parser/gfg_chart_spec.rb +17 -4
  136. data/spec/rley/parser/gfg_earley_parser_spec.rb +16 -11
  137. data/spec/rley/parser/gfg_parsing_spec.rb +41 -252
  138. data/spec/rley/parser/parse_entry_set_spec.rb +2 -0
  139. data/spec/rley/parser/parse_entry_spec.rb +21 -19
  140. data/spec/rley/parser/parse_state_spec.rb +7 -5
  141. data/spec/rley/parser/parse_tracer_spec.rb +16 -14
  142. data/spec/rley/parser/parse_walker_factory_spec.rb +10 -8
  143. data/spec/rley/parser/state_set_spec.rb +24 -22
  144. data/spec/rley/ptree/non_terminal_node_spec.rb +7 -3
  145. data/spec/rley/ptree/parse_tree_node_spec.rb +6 -4
  146. data/spec/rley/ptree/parse_tree_spec.rb +2 -0
  147. data/spec/rley/ptree/terminal_node_spec.rb +8 -6
  148. data/spec/rley/sppf/alternative_node_spec.rb +8 -6
  149. data/spec/rley/sppf/non_terminal_node_spec.rb +5 -3
  150. data/spec/rley/sppf/token_node_spec.rb +6 -4
  151. data/spec/rley/support/ambiguous_grammar_helper.rb +5 -4
  152. data/spec/rley/support/expectation_helper.rb +2 -0
  153. data/spec/rley/support/grammar_abc_helper.rb +4 -4
  154. data/spec/rley/support/grammar_ambig01_helper.rb +6 -5
  155. data/spec/rley/support/grammar_arr_int_helper.rb +6 -5
  156. data/spec/rley/support/grammar_b_expr_helper.rb +6 -5
  157. data/spec/rley/support/grammar_helper.rb +2 -0
  158. data/spec/rley/support/grammar_l0_helper.rb +15 -16
  159. data/spec/rley/support/grammar_pb_helper.rb +8 -5
  160. data/spec/rley/support/grammar_sppf_helper.rb +3 -1
  161. data/spec/rley/syntax/grammar_builder_spec.rb +7 -5
  162. data/spec/rley/syntax/grammar_spec.rb +8 -6
  163. data/spec/rley/syntax/grm_symbol_spec.rb +3 -1
  164. data/spec/rley/syntax/literal_spec.rb +2 -0
  165. data/spec/rley/syntax/non_terminal_spec.rb +10 -8
  166. data/spec/rley/syntax/production_spec.rb +15 -13
  167. data/spec/rley/syntax/symbol_seq_spec.rb +4 -2
  168. data/spec/rley/syntax/terminal_spec.rb +7 -5
  169. data/spec/rley/syntax/verbatim_symbol_spec.rb +3 -1
  170. data/spec/spec_helper.rb +2 -12
  171. data/spec/support/base_tokenizer_spec.rb +9 -2
  172. metadata +21 -63
  173. data/.simplecov +0 -7
  174. data/Gemfile +0 -8
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
 
3
5
  require_relative '../../../lib/rley/syntax/terminal'
@@ -123,7 +125,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
123
125
 
124
126
  it 'should determine if it is a successor of another dotted item' do
125
127
  expect(subject).not_to be_successor_of(subject)
126
-
128
+
127
129
  # Case: different productions
128
130
  instance = DottedItem.new(empty_prod, 0)
129
131
  expect(subject).not_to be_successor_of(instance)
@@ -137,7 +139,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
137
139
  instance2 = DottedItem.new(sample_prod, 2)
138
140
  expect(instance).not_to be_successor_of(instance2)
139
141
  expect(subject).not_to be_successor_of(instance2)
140
- expect(instance2).to be_successor_of(subject)
142
+ expect(instance2).to be_successor_of(subject)
141
143
  end
142
144
 
143
145
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
 
3
5
  require_relative '../support/grammar_abc_helper'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../spec_helper'
2
4
 
3
5
 
@@ -17,11 +19,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
17
19
  end
18
20
 
19
21
  it 'could be created with block argument' do
20
- expect do
21
- Engine.new do |config|
22
- config.parse_repr = :raw
23
- end
24
- end.not_to raise_error
22
+ expect do
23
+ Engine.new do |config|
24
+ config.parse_repr = :raw
25
+ end
26
+ end.not_to raise_error
25
27
  end
26
28
 
27
29
  it "shouldn't have a link to a grammar yet" do
@@ -43,13 +45,14 @@ module Rley # Open this namespace to avoid module qualifier prefixes
43
45
  end
44
46
  end # context
45
47
 
48
+ # rubocop: disable Lint/ConstantDefinitionInBlock
46
49
  class ABCTokenizer
47
50
  # Constructor
48
51
  def initialize(someText)
49
52
  @input = someText.dup
50
53
  end
51
54
 
52
- def each()
55
+ def each
53
56
  pos = Rley::Lexical::Position.new(1, 1) # Dummy position
54
57
  lexemes = @input.scan(/\S/)
55
58
  lexemes.each do |ch|
@@ -61,6 +64,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
61
64
  end
62
65
  end
63
66
  end # class
67
+ # rubocop: enable Lint/ConstantDefinitionInBlock
64
68
 
65
69
  # Utility method. Ensure that the engine
66
70
  # has the defnition of a sample grammar
@@ -100,6 +104,23 @@ module Rley # Open this namespace to avoid module qualifier prefixes
100
104
  ABCTokenizer.new(sample_text)
101
105
  end
102
106
 
107
+ it 'should build a parse tree even for a nullable production' do
108
+ instance = Engine.new
109
+ instance.build_grammar do
110
+ add_terminals('a', 'b', 'c')
111
+ add_production 'S' => 'A BC'
112
+ add_production 'A' => 'a'
113
+ add_production 'BC' => 'B_opt C_opt'
114
+ add_production 'B_opt' => 'b'
115
+ add_production 'B_opt' => []
116
+ add_production 'C_opt' => 'c'
117
+ add_production 'C_opt' => []
118
+ end
119
+ input = ABCTokenizer.new('a')
120
+ raw_result = instance.parse(input)
121
+ expect { instance.to_ptree(raw_result) }.not_to raise_error
122
+ end
123
+
103
124
  it 'should build default parse trees' do
104
125
  raw_result = subject.parse(sample_tokenizer)
105
126
  ptree = subject.convert(raw_result)
@@ -133,13 +154,30 @@ module Rley # Open this namespace to avoid module qualifier prefixes
133
154
  sample_text = 'a a b c c'
134
155
  ABCTokenizer.new(sample_text)
135
156
  end
136
-
157
+
158
+ it 'should build a parse forest even for a nullable production' do
159
+ instance = Engine.new
160
+ instance.build_grammar do
161
+ add_terminals('a', 'b', 'c')
162
+ add_production 'S' => 'A BC'
163
+ add_production 'A' => 'a'
164
+ add_production 'BC' => 'B_opt C_opt'
165
+ add_production 'B_opt' => 'b'
166
+ add_production 'B_opt' => []
167
+ add_production 'C_opt' => 'c'
168
+ add_production 'C_opt' => []
169
+ end
170
+ input = ABCTokenizer.new('a')
171
+ raw_result = instance.parse(input)
172
+ expect { instance.to_pforest(raw_result) }.not_to raise_error
173
+ end
174
+
137
175
  it 'should build parse forest' do
138
176
  raw_result = subject.parse(sample_tokenizer)
139
177
  pforest = subject.to_pforest(raw_result)
140
178
  expect(pforest).to be_kind_of(SPPF::ParseForest)
141
- end
142
-
179
+ end
180
+
143
181
  it 'should provide a parse visitor' do
144
182
  raw_result = subject.parse(sample_tokenizer)
145
183
  ptree = subject.to_pforest(raw_result)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
  require 'stringio'
3
5
 
@@ -21,12 +23,12 @@ module Rley # Re-open the module to get rid of qualified names
21
23
  builder = sandbox.grammar_abc_builder
22
24
  builder.grammar
23
25
  end
24
-
26
+
25
27
  # Variables for the terminal symbols
26
28
  let(:a_) { grammar_abc.name2symbol['a'] }
27
29
  let(:b_) { grammar_abc.name2symbol['b'] }
28
30
  let(:c_) { grammar_abc.name2symbol['c'] }
29
-
31
+
30
32
  # Helper method that mimicks the output of a tokenizer
31
33
  # for the language specified by grammar_abc
32
34
  let(:grm_abc_tokens1) do
@@ -48,27 +50,27 @@ module Rley # Re-open the module to get rid of qualified names
48
50
  # Capital letters represent non-terminal nodes
49
51
  let(:grm_abc_ptree1) do
50
52
  engine = Rley::Engine.new
51
- engine.use_grammar(grammar_abc)
53
+ engine.use_grammar(grammar_abc)
52
54
  parse_result = engine.parse(grm_abc_tokens1)
53
55
  ptree = engine.convert(parse_result)
54
56
  ptree
55
57
  end
56
-
57
- let(:destination) { StringIO.new('', 'w') }
58
+
59
+ let(:destination) { StringIO.new(+'', 'w') }
58
60
  subject { Asciitree.new(destination) }
59
61
 
60
62
  context 'Standard creation & initialization:' do
61
63
  it 'should be initialized with an IO argument' do
62
- expect { Asciitree.new(StringIO.new('', 'w')) }.not_to raise_error
64
+ expect { Asciitree.new(StringIO.new(+'', 'w')) }.not_to raise_error
63
65
  end
64
-
66
+
65
67
  it 'should know its output destination' do
66
68
  expect(subject.output).to eq(destination)
67
69
  end
68
70
  end # context
69
-
70
71
 
71
- context 'Rendering:' do
72
+
73
+ context 'Rendering:' do
72
74
  it 'should render a parse tree' do
73
75
  visitor = Rley::ParseTreeVisitor.new(grm_abc_ptree1)
74
76
  subject.render(visitor)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
  require 'stringio'
3
5
 
@@ -21,12 +23,12 @@ module Rley # Re-open the module to get rid of qualified names
21
23
  builder = sandbox.grammar_abc_builder
22
24
  builder.grammar
23
25
  end
24
-
26
+
25
27
  # Variables for the terminal symbols
26
28
  let(:a_) { grammar_abc.name2symbol['a'] }
27
29
  let(:b_) { grammar_abc.name2symbol['b'] }
28
30
  let(:c_) { grammar_abc.name2symbol['c'] }
29
-
31
+
30
32
  # Helper method that mimicks the output of a tokenizer
31
33
  # for the language specified by grammar_abc
32
34
  let(:grm_abc_tokens1) do
@@ -48,45 +50,45 @@ module Rley # Re-open the module to get rid of qualified names
48
50
  # Capital letters represent non-terminal nodes
49
51
  let(:grm_abc_ptree1) do
50
52
  engine = Rley::Engine.new
51
- engine.use_grammar(grammar_abc)
53
+ engine.use_grammar(grammar_abc)
52
54
  parse_result = engine.parse(grm_abc_tokens1)
53
55
  ptree = engine.convert(parse_result)
54
- ptree
56
+ ptree
55
57
  end
56
-
57
- let(:destination) { StringIO.new('', 'w') }
58
+
59
+ let(:destination) { StringIO.new(+'', 'w') }
58
60
  subject { BracketNotation.new(destination) }
59
61
 
60
62
  context 'Standard creation & initialization:' do
61
63
  it 'should be initialized with an IO argument' do
62
- expect do
63
- BracketNotation.new(StringIO.new('', 'w'))
64
+ expect do
65
+ BracketNotation.new(StringIO.new(+'', 'w'))
64
66
  end.not_to raise_error
65
67
  end
66
-
68
+
67
69
  it 'should know its output destination' do
68
70
  expect(subject.output).to eq(destination)
69
71
  end
70
72
  end # context
71
-
72
73
 
73
- context 'Formatting events:' do
74
+
75
+ context 'Formatting events:' do
74
76
  it 'should support visit events of a parse tree' do
75
77
  visitor = Rley::ParseTreeVisitor.new(grm_abc_ptree1)
76
78
  subject.render(visitor)
77
79
  expectations = '[S [A [a a][A [a a][A [b b]][c c]][c c]]]'
78
80
  expect(destination.string).to eq(expectations)
79
81
  end
80
-
82
+
81
83
  it 'should escape square brackets' do
82
84
  f_node = double('fake-node')
83
85
  f_token = double('fake-token')
84
86
  expect(f_node).to receive(:token).and_return(f_token)
85
87
  expect(f_token).to receive(:lexeme).and_return('[][]')
86
-
88
+
87
89
  subject.after_terminal(f_node)
88
90
  expectations = '\[\]\[\]]'
89
- expect(destination.string).to eq(expectations)
91
+ expect(destination.string).to eq(expectations)
90
92
  end
91
93
  end # context
92
94
  end # describe
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
  require 'stringio'
3
5
 
@@ -74,11 +76,11 @@ module Rley # Re-open the module to get rid of qualified names
74
76
  engine.to_pforest(parse_result)
75
77
  end
76
78
 
77
- let(:destination) { StringIO.new('', 'w') }
79
+ let(:destination) { StringIO.new(+'', 'w') }
78
80
 
79
81
  context 'Standard creation & initialization:' do
80
82
  it 'should be initialized with an IO argument' do
81
- expect { Debug.new(StringIO.new('', 'w')) }.not_to raise_error
83
+ expect { Debug.new(StringIO.new(+'', 'w')) }.not_to raise_error
82
84
  end
83
85
 
84
86
  it 'should know its output destination' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
  require 'stringio'
3
5
 
@@ -47,17 +49,17 @@ module Rley # Re-open the module to get rid of qualified names
47
49
  # Capital letters represent non-terminal nodes
48
50
  let(:grm_abc_ptree1) do
49
51
  engine = Rley::Engine.new
50
- engine.use_grammar(grammar_abc)
52
+ engine.use_grammar(grammar_abc)
51
53
  parse_result = engine.parse(grm_abc_tokens1)
52
54
  ptree = engine.convert(parse_result)
53
55
  ptree
54
56
  end
55
57
 
56
- let(:destination) { StringIO.new('', 'w') }
58
+ let(:destination) { StringIO.new(+'', 'w') }
57
59
 
58
60
  context 'Standard creation & initialization:' do
59
61
  it 'should be initialized with an IO argument' do
60
- expect { Json.new(StringIO.new('', 'w')) }.not_to raise_error
62
+ expect { Json.new(StringIO.new(+'', 'w')) }.not_to raise_error
61
63
  end
62
64
 
63
65
  it 'should know its output destination' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
 
3
5
  require_relative '../../../lib/rley/syntax/terminal'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
 
3
5
  require_relative '../../../lib/rley/gfg/start_vertex'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
  require_relative '../../../lib/rley/syntax/non_terminal'
3
5
 
@@ -21,12 +23,12 @@ module Rley # Open this namespace to avoid module qualifier prefixes
21
23
  end
22
24
  end # context
23
25
 
24
- context 'Provided services:' do
26
+ context 'Provided services:' do
25
27
  it 'should provide human-readable representation of itself' do
26
- pattern = /^#<Rley::GFG::EndVertex:\d+ label="NT\."/
27
- expect(subject.inspect).to match(pattern)
28
- end
29
- end # context
28
+ pattern = /^#<Rley::GFG::EndVertex:\d+ label="NT\."/
29
+ expect(subject.inspect).to match(pattern)
30
+ end
31
+ end # context
30
32
  end # describe
31
33
  end # module
32
34
  end # module
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
 
3
5
  require_relative '../../../lib/rley/gfg/start_vertex'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
 
3
5
  require_relative '../support/grammar_abc_helper'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
  require_relative '../../../lib/rley/syntax/terminal'
3
5
  require_relative '../../../lib/rley/syntax/non_terminal'
@@ -71,10 +73,10 @@ module Rley # Open this namespace to avoid module qualifier prefixes
71
73
  # Case: dot is after first symbol
72
74
  instance1 = ItemVertex.new(sample_item)
73
75
  expect(instance1.prev_symbol).to eq(t_a)
74
-
76
+
75
77
  # Case: dot is after second or later symbol
76
78
  instance2 = ItemVertex.new(next_item)
77
- expect(instance2.prev_symbol).to eq(nt_b_sequence)
79
+ expect(instance2.prev_symbol).to eq(nt_b_sequence)
78
80
 
79
81
  # Case: dot is at begin
80
82
  instance3 = ItemVertex.new(Base::DottedItem.new(sample_prod, 0))
@@ -84,8 +86,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
84
86
  instance4 = ItemVertex.new(Base::DottedItem.new(empty_prod, 0))
85
87
  expect(instance4.prev_symbol).to be_nil
86
88
  end
87
-
88
-
89
+
90
+
89
91
  it 'should know the next symbol (if any) in the rhs' do
90
92
  # Case: dot is not penultimate
91
93
  expect(subject.next_symbol).to eq(nt_b_sequence)
@@ -110,21 +112,21 @@ module Rley # Open this namespace to avoid module qualifier prefixes
110
112
  shortcut = ShortcutEdge.new(subject, next_vertex)
111
113
  expect(subject.shortcut).to eq(shortcut)
112
114
  end
113
-
115
+
114
116
  it 'should reject an invalid shortcut edge' do
115
117
  err = StandardError
116
118
  err_msg = 'Invalid shortcut argument'
117
119
  expect { subject.shortcut = 'invalid' }.to raise_error(err, err_msg)
118
- end
120
+ end
119
121
  end # context
120
122
 
121
123
  context 'Provided services:' do
122
124
  it 'should provide human-readable representation of itself' do
123
- prefix = /^#<Rley::GFG::ItemVertex:\d+/
125
+ prefix = /^#<Rley::GFG::ItemVertex:\d+/
124
126
  expect(subject.inspect).to match(prefix)
125
- suffix = /label="sentence => a \. b_sequence c">$/
126
- expect(subject.inspect).to match(suffix)
127
- end
127
+ suffix = /label="sentence => a \. b_sequence c">$/
128
+ expect(subject.inspect).to match(suffix)
129
+ end
128
130
  end # context
129
131
  end # describe
130
132
  end # module
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
 
3
5
  # Load the class under test
@@ -17,7 +19,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
17
19
  it 'should know its non-terminal' do
18
20
  expect(subject.non_terminal).to eq(sample_nt)
19
21
  end
20
-
22
+
21
23
 
22
24
  it 'should accept at more than one outgoing edge' do
23
25
  edge1 = double('fake-edge1')
@@ -26,11 +28,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
26
28
  expect { subject.add_edge(edge1) }.not_to raise_error
27
29
  expect(subject.edges.size).to eq(1)
28
30
  expect(subject.edges.last).to eq(edge1)
29
-
31
+
30
32
  expect { subject.add_edge(edge2) }.not_to raise_error
31
33
  expect(subject.edges.size).to eq(2)
32
34
  expect(subject.edges.last).to eq(edge2)
33
- end
35
+ end
34
36
  end # context
35
37
  end # describe
36
38
  end # module