rley 0.7.07 → 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 (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
@@ -11,7 +11,7 @@ module Rley # This module is used as a namespace
11
11
  # The set of parse states
12
12
  attr_reader(:states)
13
13
 
14
- def initialize()
14
+ def initialize
15
15
  @states = []
16
16
  end
17
17
 
@@ -34,7 +34,7 @@ module Rley # This module is used as a namespace
34
34
  # @param aSymbol [GrmSymbol] the expected symbol
35
35
  # (=on the right of the dot)
36
36
  def states_expecting(aSymbol)
37
- return states.select { |s| s.dotted_rule.next_symbol == aSymbol }
37
+ states.select { |s| s.dotted_rule.next_symbol == aSymbol }
38
38
  end
39
39
 
40
40
  # The list of complete ParseState that have the given non-terminal
@@ -47,7 +47,7 @@ module Rley # This module is used as a namespace
47
47
 
48
48
  # The list of ParseState that involve the given production
49
49
  def states_for(aProduction)
50
- return states.select { |s| s.dotted_rule.production == aProduction }
50
+ states.select { |s| s.dotted_rule.production == aProduction }
51
51
  end
52
52
 
53
53
  # Retrieve the parse state that is the predecessor of the given one.
@@ -55,23 +55,22 @@ module Rley # This module is used as a namespace
55
55
  dotted_rule = aPState.dotted_rule
56
56
  raise StandardError, aPState.to_s unless dotted_rule.prev_position
57
57
 
58
- candidate = states.find { |s| s.precedes?(aPState) }
59
- return candidate
58
+ states.find { |s| s.precedes?(aPState) }
60
59
  end
61
60
 
62
61
  # The list of distinct expected terminal symbols. An expected symbol
63
62
  # is on the left of a dot in a parse state of the parse set.
64
- def expected_terminals()
63
+ def expected_terminals
65
64
  expecting_terminals = states.select do |s|
66
65
  s.dotted_rule.next_symbol.kind_of?(Rley::Syntax::Terminal)
67
66
  end
68
67
 
69
68
  terminals = expecting_terminals.map { |s| s.dotted_rule.next_symbol }
70
- return terminals.uniq
69
+ terminals.uniq
71
70
  end
72
71
 
73
72
  # Return an Array of Arrays of ambiguous parse states.
74
- def ambiguities()
73
+ def ambiguities
75
74
  complete_states = states.select(&:complete?)
76
75
  return [] if complete_states.size <= 1
77
76
 
@@ -86,14 +85,14 @@ module Rley # This module is used as a namespace
86
85
  ambiguous_groups << a_group if a_group.size > 1
87
86
  end
88
87
 
89
- return ambiguous_groups
88
+ ambiguous_groups
90
89
  end
91
90
 
92
91
  private
93
92
 
94
93
  def include?(aState)
95
94
  # TODO: make it better than linear search
96
- return states.include?(aState)
95
+ states.include?(aState)
97
96
  end
98
97
  end # class
99
98
  end # module
@@ -18,20 +18,22 @@ module Rley # This module is used as a namespace
18
18
  def add_subnode(aSubnode)
19
19
  subnodes.unshift(aSubnode)
20
20
  end
21
-
21
+
22
22
  # Emit a (formatted) string representation of the node.
23
23
  # Mainly used for diagnosis/debugging purposes.
24
+ # rubocop: disable Style/StringConcatenation
24
25
  def to_string(indentation)
25
26
  connector = '+- '
26
27
  selfie = super(indentation)
27
28
  prefix = "\n" + (' ' * connector.size * indentation) + connector
28
29
  subnodes_repr = subnodes.reduce(+'') do |sub_result, subnode|
29
- sub_result << prefix + subnode.to_string(indentation + 1)
30
+ sub_result << prefix + subnode.to_string(indentation + 1)
30
31
  end
31
-
32
- return selfie + subnodes_repr
32
+
33
+ selfie + subnodes_repr
33
34
  end
34
-
35
+ # rubocop: enable Style/StringConcatenation
36
+
35
37
  # Part of the 'visitee' role in Visitor design pattern.
36
38
  # @param aVisitor[ParseTreeVisitor] the visitor
37
39
  def accept(aVisitor)
@@ -6,12 +6,12 @@ require_relative 'non_terminal_node'
6
6
  module Rley # This module is used as a namespace
7
7
  module PTree # This module is used as a namespace
8
8
  # A parse tree (a.k.a. concrete syntax tree) is a tree-based representation
9
- # for the parse that corresponds to the input text. In a parse tree,
9
+ # for the parse that corresponds to the input text. In a parse tree,
10
10
  # a node corresponds to a grammar symbol used during the parsing:
11
11
  # - a leaf node maps to a terminal symbol occurring in
12
12
  # the input, and
13
13
  # - a intermediate node maps to a non-terminal node reduced
14
- # during the parse.
14
+ # during the parse.
15
15
  # The root node corresponds to the main/start symbol of the grammar.
16
16
  class ParseTree
17
17
  # @return [ParseTreeNode] The root node of the tree.
@@ -21,7 +21,7 @@ module Rley # This module is used as a namespace
21
21
  def initialize(theRootNode)
22
22
  @root = theRootNode
23
23
  end
24
-
24
+
25
25
  # Notification from the builder telling that the parse tree construction
26
26
  # is over. This method can be overriden.
27
27
  def done!
@@ -15,9 +15,9 @@ module Rley # This module is used as a namespace
15
15
  @symbol = aSymbol
16
16
  @range = Lexical::TokenRange.new(aRange)
17
17
  end
18
-
18
+
19
19
  # Notify the builder that the construction is over
20
- def done!()
20
+ def done!
21
21
  # Do nothing
22
22
  end
23
23
 
@@ -29,13 +29,13 @@ module Rley # This module is used as a namespace
29
29
  # Emit a (formatted) string representation of the node.
30
30
  # Mainly used for diagnosis/debugging purposes.
31
31
  def to_string(indentation)
32
- return "#{symbol.name}#{range.to_string(indentation)}"
32
+ "#{symbol.name}#{range.to_string(indentation)}"
33
33
  end
34
34
 
35
35
  # Emit a short string representation of the node.
36
36
  # Mainly used for diagnosis/debugging purposes.
37
- def to_s()
38
- return "#{symbol.name}#{range.to_string(0)}"
37
+ def to_s
38
+ "#{symbol.name}#{range.to_string(0)}"
39
39
  end
40
40
  end # class
41
41
  end # module
@@ -9,10 +9,10 @@ module Rley # This module is used as a namespace
9
9
  attr_reader(:token)
10
10
 
11
11
  # @param aToken [Lexical::Token] Input Token object
12
- # @param aPos [Integer] position of the token in the input stream.
12
+ # @param aPos [Integer] position of the token in the input stream.
13
13
  def initialize(aToken, aPos)
14
- # (major, minor) =
15
-
14
+ # (major, minor) =
15
+
16
16
  # Use '1.class' trick to support both Integer and Fixnum classes
17
17
  range = aPos.kind_of?(1.class) ? { low: aPos, high: aPos + 1 } : aPos
18
18
  super(aToken.terminal, range)
@@ -24,18 +24,18 @@ module Rley # This module is used as a namespace
24
24
  def to_string(indentation)
25
25
  return super + ": '#{token.lexeme}'"
26
26
  end
27
-
27
+
28
28
  # Emit a short string representation of the node.
29
29
  # Mainly used for diagnosis/debugging purposes.
30
- def to_s()
30
+ def to_s
31
31
  return super + ": '#{token.lexeme}'"
32
- end
32
+ end
33
33
 
34
34
  # Part of the 'visitee' role in Visitor design pattern.
35
35
  # @param aVisitor[ParseTreeVisitor] the visitor
36
36
  def accept(aVisitor)
37
37
  aVisitor.visit_terminal(self)
38
- end
38
+ end
39
39
  end # class
40
40
  end # module
41
41
  end # module
@@ -1,12 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- # File: rley_error.rb
4
-
5
- module Rley # Module used as a namespace
6
- # @abstract
7
- # Base class for any exception explicitly raised by Rley code.
8
- class RleyError < StandardError
9
- end # class
10
- end # module
11
-
12
- # End of file
1
+ # frozen_string_literal: true
2
+
3
+ # File: rley_error.rb
4
+
5
+ module Rley # Module used as a namespace
6
+ # @abstract
7
+ # Base class for any exception explicitly raised by Rley code.
8
+ class RleyError < StandardError
9
+ end # class
10
+ end # module
11
+
12
+ # End of file
@@ -13,10 +13,10 @@ module Rley # This module is used as a namespace
13
13
  # @return [Syntax::NonTerminal] Link to lhs symbol
14
14
  attr_reader(:symbol)
15
15
 
16
- # @param aVertex [GFG::ItemVertex]
17
- # A GFG vertex that corresponds to a dotted item
16
+ # @param aVertex [GFG::ItemVertex]
17
+ # A GFG vertex that corresponds to a dotted item
18
18
  # with the dot at the end) for the alternative under consideration.
19
- # @param aRange [Lexical::TokenRange]
19
+ # @param aRange [Lexical::TokenRange]
20
20
  # A range of token indices corresponding to this node.
21
21
  def initialize(aVertex, aRange)
22
22
  super(aRange)
@@ -28,14 +28,14 @@ module Rley # This module is used as a namespace
28
28
  # Mainly used for diagnosis/debugging purposes.
29
29
  # @return [String]
30
30
  def to_string(indentation)
31
- return "Alt(#{label})#{range.to_string(indentation)}"
31
+ "Alt(#{label})#{range.to_string(indentation)}"
32
32
  end
33
-
33
+
34
34
  # Part of the 'visitee' role in Visitor design pattern.
35
35
  # @param aVisitor[ParseTreeVisitor] the visitor
36
36
  def accept(aVisitor)
37
37
  aVisitor.visit_alternative(self)
38
- end
38
+ end
39
39
  end # class
40
40
  end # module
41
41
  end # module
@@ -9,11 +9,11 @@ module Rley # This module is used as a namespace
9
9
  class CompositeNode < SPPFNode
10
10
  # @return [Array<SPFFNode>] Sub-nodes (children).
11
11
  attr_reader(:subnodes)
12
-
13
- alias children subnodes
12
+
13
+ alias children subnodes
14
14
 
15
15
  # Constructor
16
- # @param aRange [Lexical::TokenRange]
16
+ # @param aRange [Lexical::TokenRange]
17
17
  def initialize(aRange)
18
18
  super(aRange)
19
19
  @subnodes = []
@@ -24,14 +24,14 @@ module Rley # This module is used as a namespace
24
24
  def add_subnode(aSubnode)
25
25
  subnodes.unshift(aSubnode)
26
26
  end
27
-
27
+
28
28
  # @return [String] a text representation of the node.
29
- def inspect()
29
+ def inspect
30
30
  key
31
- end
31
+ end
32
32
 
33
33
  # @return [String]
34
- def key()
34
+ def key
35
35
  @key ||= to_string(0)
36
36
  end
37
37
  end # class
@@ -17,14 +17,14 @@ module Rley # This module is used as a namespace
17
17
  # Mainly used for diagnosis/debugging purposes.
18
18
  # @return [String]
19
19
  def to_string(indentation)
20
- return "_#{range.to_string(indentation)}"
20
+ "_#{range.to_string(indentation)}"
21
21
  end
22
-
22
+
23
23
  # Part of the 'visitee' role in Visitor design pattern.
24
24
  # @param aVisitor[ParseTreeVisitor] the visitor
25
25
  def accept(aVisitor)
26
26
  aVisitor.visit_epsilon(self)
27
- end
27
+ end
28
28
  end # class
29
29
  end # module
30
30
  end # module
@@ -8,14 +8,14 @@ module Rley # This module is used as a namespace
8
8
  # child node.
9
9
  class LeafNode < SPPFNode
10
10
  # @return [String] a text representation of the node.
11
- def inspect()
11
+ def inspect
12
12
  key
13
13
  end
14
14
 
15
15
  # @return [String]
16
- def key()
16
+ def key
17
17
  @key ||= to_string(0)
18
- end
18
+ end
19
19
  end # class
20
20
  end # module
21
21
  end # module
@@ -7,19 +7,19 @@ require_relative 'alternative_node'
7
7
  module Rley # This module is used as a namespace
8
8
  module SPPF # This module is used as a namespace
9
9
  # In an ambiguous grammar there are valid inputs that can result in multiple
10
- # parse trees. A set of parse trees is commonly referred to as a parse
11
- # forest. More specifically a parse forest is a graph data
10
+ # parse trees. A set of parse trees is commonly referred to as a parse
11
+ # forest. More specifically a parse forest is a graph data
12
12
  # structure designed to represent a set of equally syntactically correct
13
13
  # parse trees. Parse forests generated by Rley are so-called Shared Packed
14
- # Parse Forests (SPPF). SPPFs allow very compact representation of parse
14
+ # Parse Forests (SPPF). SPPFs allow very compact representation of parse
15
15
  # trees by sharing common sub-tree amongst the parse trees.
16
16
  class ParseForest
17
17
  # The root node of the forest
18
18
  attr_reader(:root)
19
-
19
+
20
20
  # A Hash with pairs of the kind node key => node
21
21
  attr_reader(:key2node)
22
-
22
+
23
23
  # A setter that tells that the parse is ambiguous.
24
24
  attr_writer(:is_ambiguous)
25
25
 
@@ -30,34 +30,34 @@ module Rley # This module is used as a namespace
30
30
  @key2node = {}
31
31
  @is_ambiguous = false
32
32
  end
33
-
33
+
34
34
  # Notification that the SPPF construction is over
35
35
  def done!
36
36
  # Do nothing
37
37
  end
38
-
38
+
39
39
  # Returns true if the given node is present in the forest.
40
40
  def include?(aNode)
41
- return key2node.include?(aNode)
41
+ key2node.include?(aNode)
42
42
  end
43
-
43
+
44
44
  # Returns true if the parse encountered a structural ambiguity
45
45
  # (i.e. more than one parse tree for the given input)
46
- def ambiguous?()
47
- return @is_ambiguous
46
+ def ambiguous?
47
+ @is_ambiguous
48
48
  end
49
-
50
- # Create an Enumerator that helps to iterate over the possible
51
- # parse trees. That enumerator will generate a parse tree when
49
+
50
+ # Create an Enumerator that helps to iterate over the possible
51
+ # parse trees. That enumerator will generate a parse tree when
52
52
  # called with `next` method.
53
53
  # @return [Enumerator]
54
- def to_ptree_enum()
54
+ def to_ptree_enum
55
55
  # How to implement?
56
56
  # One visits the forest => beware of dependency
57
57
  # At each visited item create a corresponding tree node.
58
58
  # At end of visit & stack not empty
59
59
  # Re-generate another ptree
60
- end
60
+ end
61
61
 
62
62
  # Part of the 'visitee' role in the Visitor design pattern.
63
63
  # A visitee is expected to accept the visit from a visitor object
@@ -7,23 +7,22 @@ module Rley # This module is used as a namespace
7
7
  # Abstract class. The generalization for all kinds of nodes
8
8
  # occurring in a shared packed parse forest (SPPF).
9
9
  class SPPFNode
10
-
11
- # @return [Lexical::TokenRange]
10
+ # @return [Lexical::TokenRange]
12
11
  # A range of token indices corresponding to this node.
13
12
  attr_reader(:range)
14
-
13
+
15
14
  # Constructor
16
15
  # @param aRange [Lexical::TokenRange]
17
16
  def initialize(aRange)
18
17
  @range = Lexical::TokenRange.new(aRange)
19
18
  end
20
-
21
- # Return the origin, that is, the index of the
19
+
20
+ # Return the origin, that is, the index of the
22
21
  # first token matched by this node.
23
22
  # @return [Integer]
24
- def origin()
25
- return range.low
26
- end
23
+ def origin
24
+ range.low
25
+ end
27
26
  end # class
28
27
  end # module
29
28
  end # module
@@ -25,14 +25,14 @@ module Rley # This module is used as a namespace
25
25
  # @param indentation [Integer]
26
26
  # @return [String]
27
27
  def to_string(indentation)
28
- return "#{token.terminal.name}#{range.to_string(indentation)}"
28
+ "#{token.terminal.name}#{range.to_string(indentation)}"
29
29
  end
30
-
30
+
31
31
  # Part of the 'visitee' role in Visitor design pattern.
32
32
  # @param aVisitor[ParseTreeVisitor] the visitor
33
33
  def accept(aVisitor)
34
34
  aVisitor.visit_terminal(self)
35
- end
35
+ end
36
36
  end # class
37
37
  end # module
38
38
  end # module
@@ -48,13 +48,13 @@ module Rley # This module is used as a namespace
48
48
  end
49
49
 
50
50
  # @return [Array] The list of non-terminals in the grammar.
51
- def non_terminals()
51
+ def non_terminals
52
52
  @non_terminals ||= symbols.select { |s| s.kind_of?(NonTerminal) }
53
53
  end
54
54
 
55
55
  # @return [Production] The start production of the grammar (i.e.
56
56
  # the rule that specifies the syntax for the start symbol.
57
- def start_production()
57
+ def start_production
58
58
  return rules[0]
59
59
  end
60
60
 
@@ -99,7 +99,7 @@ module Rley # This module is used as a namespace
99
99
  end
100
100
 
101
101
  # Perform some check of the grammar.
102
- def diagnose()
102
+ def diagnose
103
103
  mark_undefined
104
104
  mark_generative
105
105
  compute_nullable
@@ -193,7 +193,7 @@ module Rley # This module is used as a namespace
193
193
 
194
194
  # For each non-terminal determine whether it is nullable or not.
195
195
  # A nullable nonterminal is a nonterminal that can match an empty string.
196
- def compute_nullable()
196
+ def compute_nullable
197
197
  non_terminals.each { |nterm| nterm.nullable = false }
198
198
  nullable_sets = [direct_nullable]
199
199
 
@@ -236,7 +236,7 @@ module Rley # This module is used as a namespace
236
236
  nullables << prod.lhs
237
237
  end
238
238
 
239
- return nullables
239
+ nullables
240
240
  end
241
241
 
242
242
  # For each prodction determine whether it is nullable or not.