rley 0.7.07 → 0.7.08

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +348 -54
  3. data/LICENSE.txt +1 -1
  4. data/README.md +3 -2
  5. data/examples/NLP/engtagger.rb +193 -190
  6. data/examples/NLP/nano_eng/nano_grammar.rb +5 -5
  7. data/examples/data_formats/JSON/cli_options.rb +1 -1
  8. data/examples/data_formats/JSON/json_ast_builder.rb +12 -9
  9. data/examples/data_formats/JSON/json_ast_nodes.rb +12 -21
  10. data/examples/data_formats/JSON/json_grammar.rb +2 -2
  11. data/examples/data_formats/JSON/json_lexer.rb +8 -8
  12. data/examples/data_formats/JSON/json_minifier.rb +1 -1
  13. data/examples/general/calc_iter1/calc_ast_builder.rb +13 -10
  14. data/examples/general/calc_iter1/calc_ast_nodes.rb +23 -37
  15. data/examples/general/calc_iter1/calc_grammar.rb +2 -2
  16. data/examples/general/calc_iter1/calc_lexer.rb +6 -4
  17. data/examples/general/calc_iter1/spec/calculator_spec.rb +5 -5
  18. data/examples/general/calc_iter2/calc_ast_builder.rb +5 -3
  19. data/examples/general/calc_iter2/calc_ast_nodes.rb +27 -43
  20. data/examples/general/calc_iter2/calc_grammar.rb +3 -3
  21. data/examples/general/calc_iter2/calc_lexer.rb +11 -10
  22. data/examples/general/calc_iter2/spec/calculator_spec.rb +26 -26
  23. data/examples/general/left.rb +2 -2
  24. data/examples/general/right.rb +2 -2
  25. data/lib/rley/base/dotted_item.rb +23 -31
  26. data/lib/rley/constants.rb +2 -2
  27. data/lib/rley/engine.rb +20 -23
  28. data/lib/rley/formatter/asciitree.rb +3 -3
  29. data/lib/rley/formatter/bracket_notation.rb +1 -8
  30. data/lib/rley/formatter/debug.rb +6 -6
  31. data/lib/rley/formatter/json.rb +2 -2
  32. data/lib/rley/gfg/call_edge.rb +1 -1
  33. data/lib/rley/gfg/edge.rb +5 -5
  34. data/lib/rley/gfg/end_vertex.rb +2 -6
  35. data/lib/rley/gfg/epsilon_edge.rb +1 -5
  36. data/lib/rley/gfg/grm_flow_graph.rb +27 -23
  37. data/lib/rley/gfg/item_vertex.rb +10 -10
  38. data/lib/rley/gfg/non_terminal_vertex.rb +4 -4
  39. data/lib/rley/gfg/scan_edge.rb +1 -1
  40. data/lib/rley/gfg/shortcut_edge.rb +2 -2
  41. data/lib/rley/gfg/start_vertex.rb +4 -8
  42. data/lib/rley/gfg/vertex.rb +43 -39
  43. data/lib/rley/lexical/token_range.rb +6 -6
  44. data/lib/rley/parse_forest_visitor.rb +5 -5
  45. data/lib/rley/parse_rep/ast_base_builder.rb +9 -11
  46. data/lib/rley/parse_rep/cst_builder.rb +5 -6
  47. data/lib/rley/parse_rep/parse_forest_builder.rb +20 -18
  48. data/lib/rley/parse_rep/parse_forest_factory.rb +3 -3
  49. data/lib/rley/parse_rep/parse_rep_creator.rb +11 -13
  50. data/lib/rley/parse_rep/parse_tree_builder.rb +4 -4
  51. data/lib/rley/parse_rep/parse_tree_factory.rb +27 -27
  52. data/lib/rley/parse_tree_visitor.rb +1 -1
  53. data/lib/rley/parser/error_reason.rb +4 -5
  54. data/lib/rley/parser/gfg_chart.rb +20 -22
  55. data/lib/rley/parser/gfg_parsing.rb +16 -30
  56. data/lib/rley/parser/parse_entry.rb +25 -31
  57. data/lib/rley/parser/parse_entry_set.rb +18 -15
  58. data/lib/rley/parser/parse_entry_tracker.rb +4 -4
  59. data/lib/rley/parser/parse_state.rb +16 -21
  60. data/lib/rley/parser/parse_state_tracker.rb +4 -4
  61. data/lib/rley/parser/parse_tracer.rb +13 -13
  62. data/lib/rley/parser/parse_walker_factory.rb +23 -28
  63. data/lib/rley/parser/state_set.rb +9 -10
  64. data/lib/rley/ptree/non_terminal_node.rb +7 -5
  65. data/lib/rley/ptree/parse_tree.rb +3 -3
  66. data/lib/rley/ptree/parse_tree_node.rb +5 -5
  67. data/lib/rley/ptree/terminal_node.rb +7 -7
  68. data/lib/rley/rley_error.rb +12 -12
  69. data/lib/rley/sppf/alternative_node.rb +6 -6
  70. data/lib/rley/sppf/composite_node.rb +7 -7
  71. data/lib/rley/sppf/epsilon_node.rb +3 -3
  72. data/lib/rley/sppf/leaf_node.rb +3 -3
  73. data/lib/rley/sppf/parse_forest.rb +16 -16
  74. data/lib/rley/sppf/sppf_node.rb +7 -8
  75. data/lib/rley/sppf/token_node.rb +3 -3
  76. data/lib/rley/syntax/grammar.rb +5 -5
  77. data/lib/rley/syntax/grammar_builder.rb +9 -9
  78. data/lib/rley/syntax/grm_symbol.rb +6 -6
  79. data/lib/rley/syntax/non_terminal.rb +9 -15
  80. data/lib/rley/syntax/production.rb +10 -10
  81. data/lib/rley/syntax/symbol_seq.rb +7 -9
  82. data/lib/rley/syntax/terminal.rb +4 -5
  83. data/lib/rley/syntax/verbatim_symbol.rb +3 -3
  84. data/lib/support/base_tokenizer.rb +19 -18
  85. data/spec/rley/base/dotted_item_spec.rb +2 -2
  86. data/spec/rley/engine_spec.rb +17 -15
  87. data/spec/rley/formatter/asciitree_spec.rb +7 -7
  88. data/spec/rley/formatter/bracket_notation_spec.rb +13 -13
  89. data/spec/rley/formatter/json_spec.rb +1 -1
  90. data/spec/rley/gfg/end_vertex_spec.rb +5 -5
  91. data/spec/rley/gfg/item_vertex_spec.rb +10 -10
  92. data/spec/rley/gfg/non_terminal_vertex_spec.rb +3 -3
  93. data/spec/rley/gfg/shortcut_edge_spec.rb +1 -1
  94. data/spec/rley/gfg/start_vertex_spec.rb +5 -5
  95. data/spec/rley/gfg/vertex_spec.rb +3 -3
  96. data/spec/rley/lexical/token_range_spec.rb +16 -16
  97. data/spec/rley/lexical/token_spec.rb +2 -2
  98. data/spec/rley/parse_forest_visitor_spec.rb +165 -163
  99. data/spec/rley/parse_rep/ambiguous_parse_spec.rb +44 -44
  100. data/spec/rley/parse_rep/ast_builder_spec.rb +6 -6
  101. data/spec/rley/parse_rep/cst_builder_spec.rb +5 -5
  102. data/spec/rley/parse_rep/groucho_spec.rb +21 -21
  103. data/spec/rley/parse_rep/parse_forest_builder_spec.rb +26 -26
  104. data/spec/rley/parse_rep/parse_forest_factory_spec.rb +6 -6
  105. data/spec/rley/parse_rep/parse_tree_factory_spec.rb +2 -2
  106. data/spec/rley/parse_tree_visitor_spec.rb +10 -8
  107. data/spec/rley/parser/error_reason_spec.rb +6 -6
  108. data/spec/rley/parser/gfg_earley_parser_spec.rb +4 -2
  109. data/spec/rley/parser/gfg_parsing_spec.rb +4 -8
  110. data/spec/rley/parser/parse_entry_spec.rb +19 -19
  111. data/spec/rley/parser/parse_state_spec.rb +5 -5
  112. data/spec/rley/parser/parse_walker_factory_spec.rb +1 -1
  113. data/spec/rley/parser/state_set_spec.rb +22 -22
  114. data/spec/rley/ptree/non_terminal_node_spec.rb +5 -3
  115. data/spec/rley/ptree/parse_tree_node_spec.rb +4 -4
  116. data/spec/rley/ptree/terminal_node_spec.rb +6 -6
  117. data/spec/rley/sppf/alternative_node_spec.rb +6 -6
  118. data/spec/rley/sppf/non_terminal_node_spec.rb +3 -3
  119. data/spec/rley/sppf/token_node_spec.rb +4 -4
  120. data/spec/rley/support/ambiguous_grammar_helper.rb +3 -4
  121. data/spec/rley/support/grammar_abc_helper.rb +2 -4
  122. data/spec/rley/support/grammar_ambig01_helper.rb +4 -5
  123. data/spec/rley/support/grammar_arr_int_helper.rb +4 -5
  124. data/spec/rley/support/grammar_b_expr_helper.rb +4 -5
  125. data/spec/rley/support/grammar_l0_helper.rb +10 -11
  126. data/spec/rley/support/grammar_pb_helper.rb +6 -5
  127. data/spec/rley/support/grammar_sppf_helper.rb +1 -1
  128. data/spec/rley/syntax/grammar_builder_spec.rb +5 -5
  129. data/spec/rley/syntax/grammar_spec.rb +6 -6
  130. data/spec/rley/syntax/grm_symbol_spec.rb +1 -1
  131. data/spec/rley/syntax/non_terminal_spec.rb +8 -8
  132. data/spec/rley/syntax/production_spec.rb +13 -13
  133. data/spec/rley/syntax/symbol_seq_spec.rb +2 -2
  134. data/spec/rley/syntax/terminal_spec.rb +5 -5
  135. data/spec/rley/syntax/verbatim_symbol_spec.rb +1 -1
  136. data/spec/spec_helper.rb +0 -12
  137. data/spec/support/base_tokenizer_spec.rb +7 -2
  138. metadata +21 -62
  139. data/.simplecov +0 -8
@@ -40,33 +40,33 @@ module Rley # This module is used as a namespace
40
40
  # The label of this vertex.
41
41
  # It is the same as the label of the corresponding dotted item.
42
42
  # @return [String] Label for this vertex
43
- def label()
44
- return dotted_item.to_s
43
+ def label
44
+ dotted_item.to_s
45
45
  end
46
46
 
47
47
  # Returns true if the dotted item has a dot at the end of the production.
48
48
  # @return [Boolean]
49
- def complete?()
50
- return dotted_item.reduce_item?
49
+ def complete?
50
+ dotted_item.reduce_item?
51
51
  end
52
52
 
53
53
  # Return the symbol before the dot.
54
54
  # @return [Syntax::GrmSymbol, NilClass] Previous symbol otherwise nil.
55
- def prev_symbol()
56
- return dotted_item.prev_symbol
55
+ def prev_symbol
56
+ dotted_item.prev_symbol
57
57
  end
58
58
 
59
59
  # Return the symbol after the dot.
60
60
  # @return [Syntax::GrmSymbol, NilClass] Next grammar symbol otherwise nil.
61
- def next_symbol()
62
- return dotted_item.next_symbol
61
+ def next_symbol
62
+ @next_symbol ||= dotted_item.next_symbol
63
63
  end
64
64
 
65
65
  # Return the non-terminal symbol at the left-hand side of the production
66
66
  # @return [Syntax::GrmSymbol]
67
67
  # The non-terminal symbol at left side of production.
68
- def lhs()
69
- return dotted_item.lhs
68
+ def lhs
69
+ dotted_item.lhs
70
70
  end
71
71
  end # class
72
72
  end # module
@@ -5,7 +5,7 @@ require_relative 'vertex'
5
5
  module Rley # This module is used as a namespace
6
6
  module GFG # This module is used as a namespace
7
7
  # Abstract class.
8
- # Represents a specialized vertex in a grammar flow graph
8
+ # Represents a specialized vertex in a grammar flow graph
9
9
  # that is associated to a given non-terminal symbol and
10
10
  # that may have in-degree or out-degree > 1
11
11
  # Responsibilities (in addition to inherited ones):
@@ -14,20 +14,20 @@ module Rley # This module is used as a namespace
14
14
  # The non-terminal symbol associated to the vertex
15
15
  # @return [Syntax::NonTerminal]
16
16
  attr_reader :non_terminal
17
-
17
+
18
18
  # Constructor to specialize in subclasses.
19
19
  # @param aNonTerminal [Syntax::NonTerminal]
20
20
  def initialize(aNonTerminal)
21
21
  super()
22
22
  @non_terminal = aNonTerminal
23
23
  end
24
-
24
+
25
25
  protected
26
26
 
27
27
  # Validation method for adding an outgoing edge to the vertex.
28
28
  # A start vertex may accept an indegree and outdegree greater than one
29
29
  def check_add_edge(anEdge)
30
- return anEdge
30
+ anEdge
31
31
  end
32
32
  end # class
33
33
  end # module
@@ -17,7 +17,7 @@ module Rley # This module is used as a namespace
17
17
  @terminal = aTerminal
18
18
  end
19
19
 
20
- def to_s()
20
+ def to_s
21
21
  " -#{terminal}-> #{successor.label}"
22
22
  end
23
23
  end # class
@@ -12,12 +12,12 @@ module Rley # This module is used as a namespace
12
12
  attr_reader :nonterminal
13
13
 
14
14
  def initialize(thePredecessor, theSuccessor)
15
- @successor = theSuccessor
15
+ super(nil, theSuccessor)
16
16
  @nonterminal = thePredecessor.next_symbol
17
17
  thePredecessor.shortcut = self
18
18
  end
19
19
 
20
- def to_s()
20
+ def to_s
21
21
  " -#{nonterminal}-> #{successor.label}"
22
22
  end
23
23
  end # class
@@ -5,19 +5,15 @@ require_relative 'non_terminal_vertex'
5
5
  module Rley # This module is used as a namespace
6
6
  module GFG # This module is used as a namespace
7
7
  # TODO: change definition.
8
- # Represents a specialized vertex in a grammar flow graph
8
+ # Represents a specialized vertex in a grammar flow graph
9
9
  # that is associated to a given non-terminal symbol.
10
10
  # Responsibilities (in addition to inherited ones):
11
11
  # - Know its related non-terminal symbol
12
12
  class StartVertex < NonTerminalVertex
13
- def initialize(aNonTerminal)
14
- super(aNonTerminal)
15
- end
16
-
17
13
  # @return [String]
18
- def label()
19
- return ".#{non_terminal}"
20
- end
14
+ def label
15
+ ".#{non_terminal}"
16
+ end
21
17
  end # class
22
18
  end # module
23
19
  end # module
@@ -10,60 +10,65 @@ module Rley # This module is used as a namespace
10
10
  # The edges linking the successor vertices to this one.
11
11
  # @return [Array<Edge>] The edge(s) linking this vertex to successor(s)
12
12
  attr_reader :edges
13
-
13
+
14
+ # Return the object id in string format
15
+ # @return [String]
16
+ attr_reader :oid_str
17
+
14
18
  # Constructor to extend in subclasses.
15
- def initialize()
19
+ def initialize
16
20
  @edges = []
21
+ @oid_str = object_id.to_s
17
22
  end
18
-
19
- # Add an graph edge to this vertex.
20
- # @param anEdge [Edge] the edge to be added.
21
- def add_edge(anEdge)
22
- arrow = check_add_edge(anEdge)
23
- edges << arrow
24
- end
25
-
26
- # Determine if the vertex corresponds to an dotted item that has
23
+
24
+ # Determine if the vertex corresponds to an dotted item that has
27
25
  # its dot at the end of a production (i.e. is a reduced item).
28
26
  # @return [Boolean] true iff vertex corresponds to reduced item.
29
- def complete?()
30
- return false # Default implementation
27
+ def complete?
28
+ false # Default implementation
31
29
  end
32
-
33
- # Returns a string containing a human-readable representation of the
30
+
31
+ # Returns a string containing a human-readable representation of the
34
32
  # vertex.
35
33
  # @return [String]
36
- def inspect()
34
+ def inspect
37
35
  result = +'#<'
38
36
  result << selfie
39
37
  edges.each { |e| result << e.inspect }
40
38
  result << specific_inspect
41
39
  result << '>'
42
-
43
- return result
40
+
41
+ result
44
42
  end
45
-
46
- # Returns a string containing a human-readable representation of the
43
+
44
+ # Returns a string containing a human-readable representation of the
47
45
  # vertex without the edges.
48
- # @return [String]
49
- def selfie()
46
+ # @return [String]
47
+ def selfie
50
48
  result = +"#{self.class.name}:#{object_id}"
51
49
  result << %( label="#{label}")
52
- return result
50
+ result
53
51
  end
54
-
52
+
55
53
  # Retrieve the grammar symbol before the dot.
56
54
  # @return [GrmSymbol, NilClass] The symbol or otherwise nil.
57
- def prev_symbol()
58
- return nil # Default implementation
59
- end
60
-
55
+ def prev_symbol
56
+ nil # Default implementation
57
+ end
58
+
61
59
  # Retrieve the grammar symbol after the dot.
62
- # @return [GrmSymbol, NilClass] The symbol or otherwise nil.
63
- def next_symbol()
64
- return nil # Default implementation
60
+ # @return [GrmSymbol, NilClass] The symbol or otherwise nil.
61
+ def next_symbol
62
+ nil # Default implementation
63
+ end
64
+
65
+ # Add an graph edge to this vertex.
66
+ # @param anEdge [Edge] the edge to be added.
67
+ def add_edge(anEdge)
68
+ arrow = check_add_edge(anEdge)
69
+ edges << arrow
65
70
  end
66
-
71
+
67
72
  protected
68
73
 
69
74
  # Validation method for adding an outgoing edge to the vertex.
@@ -71,14 +76,13 @@ module Rley # This module is used as a namespace
71
76
  # unless this method is overridden in subclasses
72
77
  def check_add_edge(anEdge)
73
78
  raise StandardError, 'At most one edge accepted' unless edges.empty?
74
-
75
- return anEdge
79
+
80
+ anEdge
81
+ end
82
+
83
+ def specific_inspect
84
+ ''
76
85
  end
77
-
78
- def specific_inspect()
79
- return ''
80
- end
81
-
82
86
  end # class
83
87
  end # module
84
88
  end # module
@@ -2,13 +2,13 @@
2
2
 
3
3
  module Rley # This module is used as a namespace
4
4
  module Lexical # This module is used as a namespace
5
- # A token range (also called an extent) represents an interval
5
+ # A token range (also called an extent) represents an interval
6
6
  # of token positions that is matched by a given grammar symbol.
7
7
  # For instance consider the expression E: 3 + 11,
8
8
  # let's assume that the integer literal '3' is the fifth input token and
9
9
  # that the '+' and '11' tokens are respectively at position 6 and 7;
10
10
  # then the token range associated with E is [5, 7]
11
- # While the parse tree/forest is being constructed the boundaries of the
11
+ # While the parse tree/forest is being constructed the boundaries of the
12
12
  # token range can be temporarily undefined (= set to nil)
13
13
  class TokenRange
14
14
  # The index of the lower bound of token range
@@ -47,8 +47,8 @@ module Rley # This module is used as a namespace
47
47
  end
48
48
 
49
49
  # true when both bounds aren't nil.
50
- def bounded?()
51
- return !(low.nil? || high.nil?)
50
+ def bounded?
51
+ !(low.nil? || high.nil?)
52
52
  end
53
53
 
54
54
  # Conditional assign
@@ -73,8 +73,8 @@ module Rley # This module is used as a namespace
73
73
  def to_string(_indentation)
74
74
  low_text = low.nil? ? '?' : low.to_s
75
75
  high_text = high.nil? ? '?' : high.to_s
76
-
77
- return "[#{low_text}, #{high_text}]"
76
+
77
+ "[#{low_text}, #{high_text}]"
78
78
  end
79
79
 
80
80
  private
@@ -15,8 +15,8 @@ module Rley # This module is used as a namespace
15
15
  @signatures = subnodes.map { |_| prime_enumerator.next }
16
16
  end
17
17
 
18
- def signature_exist?()
19
- @signatures.nil? ? false : true
18
+ def signature_exist?
19
+ !@signatures.nil?
20
20
  end
21
21
  end # class
22
22
  end # module
@@ -69,7 +69,7 @@ module Rley # This module is used as a namespace
69
69
  end
70
70
 
71
71
  # The signal to begin the visit of the parse forest.
72
- def start()
72
+ def start
73
73
  pforest.accept(self)
74
74
  end
75
75
 
@@ -169,7 +169,7 @@ module Rley # This module is used as a namespace
169
169
  def broadcast(msg, *args)
170
170
  subscribers.each do |subscr|
171
171
  next unless subscr.respond_to?(msg) || subscr.respond_to?(:accept_all)
172
-
172
+
173
173
  subscr.send(msg, *args)
174
174
  end
175
175
  end
@@ -190,7 +190,7 @@ module Rley # This module is used as a namespace
190
190
 
191
191
  def pop_node
192
192
  return if legs.empty?
193
-
193
+
194
194
  legs.pop
195
195
  end
196
196
  end # class
@@ -20,14 +20,14 @@ module Rley # This module is used as a namespace
20
20
  # Returned hash contains pairs of the form:
21
21
  # terminal name => Class implementing the terminal tokens
22
22
  # terminal name => Hash with pairs: production name => Class
23
- def terminal2node()
23
+ def terminal2node
24
24
  raise NotImplementedError
25
25
  end
26
26
 
27
27
  # Method to override in subclass.
28
28
  # Default class for representing terminal nodes.
29
29
  # @return [Class]
30
- def terminalnode_class()
30
+ def terminalnode_class
31
31
  PTree::TerminalNode
32
32
  end
33
33
 
@@ -37,7 +37,7 @@ module Rley # This module is used as a namespace
37
37
  # @param aProductionName [String]
38
38
  # @return [String]
39
39
  def method_name(aProductionName)
40
- return 'reduce_' + aProductionName
40
+ "reduce_#{aProductionName}"
41
41
  end
42
42
 
43
43
  # Utility method.
@@ -46,7 +46,7 @@ module Rley # This module is used as a namespace
46
46
  # @param _tokens [Array<Lexical::Token>]
47
47
  # @param theChildren [Array<Object>]
48
48
  def return_first_child(_range, _tokens, theChildren)
49
- return theChildren[0]
49
+ theChildren[0]
50
50
  end
51
51
 
52
52
  # Utility method.
@@ -55,7 +55,7 @@ module Rley # This module is used as a namespace
55
55
  # @param _tokens [Array<Lexical::Token>]
56
56
  # @param theChildren [Array<Object>]
57
57
  def return_second_child(_range, _tokens, theChildren)
58
- return theChildren[1]
58
+ theChildren[1]
59
59
  end
60
60
 
61
61
  # Utility method.
@@ -64,7 +64,7 @@ module Rley # This module is used as a namespace
64
64
  # @param _tokens [Array<Lexical::Token>]
65
65
  # @param theChildren [Array<Object>]
66
66
  def return_last_child(_range, _tokens, theChildren)
67
- return theChildren[-1]
67
+ theChildren[-1]
68
68
  end
69
69
 
70
70
  # Simply return an epsilon symbol
@@ -72,7 +72,7 @@ module Rley # This module is used as a namespace
72
72
  # @param _tokens [Array<Lexical::Token>]
73
73
  # @param _children [Array<Object>]
74
74
  def return_epsilon(_range, _tokens, _children)
75
- return nil
75
+ nil
76
76
  end
77
77
 
78
78
  protected
@@ -81,7 +81,7 @@ module Rley # This module is used as a namespace
81
81
  # Create a parse tree object with given
82
82
  # node as root node.
83
83
  def create_tree(aRootNode)
84
- return Rley::PTree::ParseTree.new(aRootNode)
84
+ Rley::PTree::ParseTree.new(aRootNode)
85
85
  end
86
86
 
87
87
  # Factory method for creating a node object for the given
@@ -96,9 +96,7 @@ module Rley # This module is used as a namespace
96
96
  # Lexical ambiguity...
97
97
  klass = klass.fetch(aProduction.name)
98
98
  end
99
- node = klass.new(aToken, aTokenPosition)
100
-
101
- return node
99
+ klass.new(aToken, aTokenPosition)
102
100
  end
103
101
 
104
102
  # Method to override.
@@ -16,13 +16,13 @@ module Rley # This module is used as a namespace
16
16
  # nodes) and using a step by step approach.
17
17
  class CSTBuilder < ParseTreeBuilder
18
18
  protected
19
-
19
+
20
20
  # Method to override
21
21
  # Create a parse tree object with given
22
22
  # node as root node.
23
23
  def create_tree(aRootNode)
24
24
  return Rley::PTree::ParseTree.new(aRootNode)
25
- end
25
+ end
26
26
 
27
27
  # Method to override
28
28
  # Factory method for creating a node object for the given
@@ -42,10 +42,9 @@ module Rley # This module is used as a namespace
42
42
  # @param theChildren [Array] Children nodes (one per rhs symbol)
43
43
  def new_parent_node(aProduction, aRange, _tokens, theChildren)
44
44
  node = Rley::PTree::NonTerminalNode.new(aProduction.lhs, aRange)
45
- if theChildren
46
- theChildren.reverse_each { |child| node.add_subnode(child) }
47
- end
48
- return node
45
+ theChildren&.reverse_each { |child| node.add_subnode(child) }
46
+
47
+ node
49
48
  end
50
49
  end # class
51
50
  end # module
@@ -44,7 +44,7 @@ module Rley # This module is used as a namespace
44
44
  end
45
45
 
46
46
  # Notify the builder that the construction is over
47
- def done!()
47
+ def done!
48
48
  result.done!
49
49
  end
50
50
 
@@ -64,7 +64,7 @@ module Rley # This module is used as a namespace
64
64
  end
65
65
 
66
66
  # Return the current_parent node
67
- def curr_parent()
67
+ def curr_parent
68
68
  curr_path.last
69
69
  end
70
70
 
@@ -110,18 +110,18 @@ module Rley # This module is used as a namespace
110
110
  def process_item_entry(anEvent, anEntry, anIndex)
111
111
  case anEvent
112
112
  when :visit
113
- if anEntry.exit_entry?
113
+ if anEntry.exit_entry? && last_visitee.end_entry? &&
114
+ last_visitee.antecedents.size > 1
114
115
  # Previous entry was an end entry (X. pattern)
115
116
  # Does the previous entry have multiple antecedent?
116
- if last_visitee.end_entry? && last_visitee.antecedents.size > 1
117
- # Store current path for later backtracking
118
- # puts "Store backtrack context #{last_visitee}"
119
- # puts "path [#{curr_path.map{|e|e.to_string(0)}.join(', ')}]"
120
- entry2path_to_alt[last_visitee] = curr_path.dup
121
- curr_parent.refinement = :or
122
-
123
- create_alternative_node(anEntry)
124
- end
117
+
118
+ # Store current path for later backtracking
119
+ # puts "Store backtrack context #{last_visitee}"
120
+ # puts "path [#{curr_path.map{|e|e.to_string(0)}.join(', ')}]"
121
+ entry2path_to_alt[last_visitee] = curr_path.dup
122
+ curr_parent.refinement = :or
123
+
124
+ create_alternative_node(anEntry)
125
125
  end
126
126
 
127
127
  # Does this entry have multiple antecedent?
@@ -179,7 +179,7 @@ module Rley # This module is used as a namespace
179
179
 
180
180
  # Create an empty parse forest
181
181
  def create_forest(aRootNode)
182
- return Rley::SPPF::ParseForest.new(aRootNode)
182
+ Rley::SPPF::ParseForest.new(aRootNode)
183
183
  end
184
184
 
185
185
  # Factory method. Build and return an SPPF non-terminal node.
@@ -190,7 +190,7 @@ module Rley # This module is used as a namespace
190
190
  add_subnode(new_node)
191
191
  # puts "FOREST ADD #{curr_parent.key if curr_parent}/#{new_node.key}"
192
192
 
193
- return new_node
193
+ new_node
194
194
  end
195
195
 
196
196
  # Add an alternative node to the forest
@@ -202,7 +202,7 @@ module Rley # This module is used as a namespace
202
202
  result.is_ambiguous = true
203
203
  # puts "FOREST ADD #{alternative.key}"
204
204
 
205
- return alternative
205
+ alternative
206
206
  end
207
207
 
208
208
  # create a token node,
@@ -216,7 +216,7 @@ module Rley # This module is used as a namespace
216
216
  candidate = add_node_to_forest(new_node)
217
217
  entry2node[anEntry] = candidate
218
218
 
219
- return candidate
219
+ candidate
220
220
  end
221
221
 
222
222
  def create_epsilon_node(anEntry, anIndex)
@@ -224,7 +224,7 @@ module Rley # This module is used as a namespace
224
224
  candidate = add_node_to_forest(new_node)
225
225
  entry2node[anEntry] = candidate
226
226
 
227
- return candidate
227
+ candidate
228
228
  end
229
229
 
230
230
  # Add the given node if not yet present in parse forest
@@ -239,17 +239,19 @@ module Rley # This module is used as a namespace
239
239
  end
240
240
  add_subnode(new_node, false)
241
241
 
242
- return new_node
242
+ new_node
243
243
  end
244
244
 
245
245
  # Add the given node as sub-node of current parent node
246
246
  # Optionally add the node to the current path
247
+ # rubocop: disable Style/OptionalBooleanParameter
247
248
  def add_subnode(aNode, addToPath = true)
248
249
  raise StandardError, 'node is nil' if aNode.nil?
249
250
 
250
251
  curr_parent.add_subnode(aNode) unless curr_path.empty?
251
252
  curr_path << aNode if addToPath
252
253
  end
254
+ # rubocop: enable Style/OptionalBooleanParameter
253
255
  end # class
254
256
  end # module
255
257
  end # module