rley 0.3.04 → 0.3.05

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 (99) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -3
  3. data/CHANGELOG.md +3 -0
  4. data/Rakefile +30 -30
  5. data/examples/parsers/parsing_L0.rb +1 -1
  6. data/examples/parsers/parsing_L1.rb +1 -1
  7. data/examples/parsers/parsing_abc.rb +1 -1
  8. data/examples/parsers/parsing_ambig.rb +1 -1
  9. data/examples/parsers/parsing_another.rb +1 -1
  10. data/examples/parsers/parsing_b_expr.rb +1 -1
  11. data/examples/parsers/parsing_err_expr.rb +1 -1
  12. data/examples/parsers/parsing_groucho.rb +1 -1
  13. data/examples/parsers/parsing_right_recursive.rb +1 -1
  14. data/examples/parsers/parsing_tricky.rb +1 -1
  15. data/lib/rley/constants.rb +2 -2
  16. data/lib/rley/formatter/base_formatter.rb +0 -2
  17. data/lib/rley/formatter/debug.rb +0 -2
  18. data/lib/rley/formatter/json.rb +1 -3
  19. data/lib/rley/gfg/call_edge.rb +31 -30
  20. data/lib/rley/gfg/edge.rb +22 -23
  21. data/lib/rley/gfg/end_vertex.rb +22 -24
  22. data/lib/rley/gfg/epsilon_edge.rb +20 -21
  23. data/lib/rley/gfg/grm_flow_graph.rb +39 -39
  24. data/lib/rley/gfg/item_vertex.rb +16 -17
  25. data/lib/rley/gfg/non_terminal_vertex.rb +3 -4
  26. data/lib/rley/gfg/return_edge.rb +32 -31
  27. data/lib/rley/gfg/scan_edge.rb +25 -26
  28. data/lib/rley/gfg/shortcut_edge.rb +25 -26
  29. data/lib/rley/gfg/start_vertex.rb +0 -2
  30. data/lib/rley/gfg/vertex.rb +8 -8
  31. data/lib/rley/parse_forest_visitor.rb +113 -115
  32. data/lib/rley/parse_tree_visitor.rb +0 -2
  33. data/lib/rley/parser/base_parser.rb +27 -27
  34. data/lib/rley/parser/chart.rb +14 -14
  35. data/lib/rley/parser/dotted_item.rb +33 -33
  36. data/lib/rley/parser/earley_parser.rb +6 -6
  37. data/lib/rley/parser/gfg_chart.rb +8 -15
  38. data/lib/rley/parser/gfg_earley_parser.rb +15 -13
  39. data/lib/rley/parser/gfg_parsing.rb +26 -22
  40. data/lib/rley/parser/grm_items_builder.rb +3 -2
  41. data/lib/rley/parser/parse_entry.rb +3 -9
  42. data/lib/rley/parser/parse_entry_set.rb +14 -19
  43. data/lib/rley/parser/parse_entry_tracker.rb +56 -56
  44. data/lib/rley/parser/parse_forest_builder.rb +215 -214
  45. data/lib/rley/parser/parse_forest_factory.rb +57 -56
  46. data/lib/rley/parser/parse_state.rb +8 -11
  47. data/lib/rley/parser/parse_state_tracker.rb +56 -56
  48. data/lib/rley/parser/parse_tracer.rb +3 -3
  49. data/lib/rley/parser/parse_tree_builder.rb +10 -10
  50. data/lib/rley/parser/parse_walker_factory.rb +30 -33
  51. data/lib/rley/parser/parsing.rb +8 -8
  52. data/lib/rley/parser/state_set.rb +23 -26
  53. data/lib/rley/ptree/non_terminal_node.rb +1 -1
  54. data/lib/rley/ptree/token_range.rb +2 -2
  55. data/lib/rley/sppf/alternative_node.rb +32 -34
  56. data/lib/rley/sppf/composite_node.rb +27 -27
  57. data/lib/rley/sppf/epsilon_node.rb +26 -27
  58. data/lib/rley/sppf/leaf_node.rb +11 -12
  59. data/lib/rley/sppf/non_terminal_node.rb +37 -38
  60. data/lib/rley/sppf/sppf_node.rb +1 -1
  61. data/lib/rley/sppf/token_node.rb +29 -29
  62. data/lib/rley/syntax/grammar.rb +1 -3
  63. data/lib/rley/syntax/grammar_builder.rb +8 -8
  64. data/lib/rley/syntax/non_terminal.rb +2 -4
  65. data/lib/rley/syntax/production.rb +3 -3
  66. data/lib/rley/syntax/symbol_seq.rb +1 -1
  67. data/spec/rley/gfg/call_edge_spec.rb +50 -51
  68. data/spec/rley/gfg/edge_spec.rb +33 -33
  69. data/spec/rley/gfg/end_vertex_spec.rb +26 -27
  70. data/spec/rley/gfg/epsilon_edge_spec.rb +25 -25
  71. data/spec/rley/gfg/grm_flow_graph_spec.rb +1 -1
  72. data/spec/rley/gfg/item_vertex_spec.rb +3 -4
  73. data/spec/rley/gfg/return_edge_spec.rb +51 -51
  74. data/spec/rley/gfg/scan_edge_spec.rb +32 -30
  75. data/spec/rley/gfg/shortcut_edge_spec.rb +1 -1
  76. data/spec/rley/gfg/vertex_spec.rb +3 -3
  77. data/spec/rley/parse_forest_visitor_spec.rb +239 -238
  78. data/spec/rley/parser/dotted_item_spec.rb +1 -1
  79. data/spec/rley/parser/earley_parser_spec.rb +16 -16
  80. data/spec/rley/parser/gfg_earley_parser_spec.rb +30 -31
  81. data/spec/rley/parser/gfg_parsing_spec.rb +11 -10
  82. data/spec/rley/parser/grm_items_builder_spec.rb +2 -2
  83. data/spec/rley/parser/parse_entry_set_spec.rb +4 -4
  84. data/spec/rley/parser/parse_entry_spec.rb +0 -2
  85. data/spec/rley/parser/parse_forest_builder_spec.rb +82 -57
  86. data/spec/rley/parser/parse_forest_factory_spec.rb +84 -82
  87. data/spec/rley/parser/parse_walker_factory_spec.rb +10 -9
  88. data/spec/rley/parser/parsing_spec.rb +0 -1
  89. data/spec/rley/sppf/alternative_node_spec.rb +2 -2
  90. data/spec/rley/sppf/non_terminal_node_spec.rb +0 -1
  91. data/spec/rley/support/ambiguous_grammar_helper.rb +1 -1
  92. data/spec/rley/support/expectation_helper.rb +37 -36
  93. data/spec/rley/support/grammar_abc_helper.rb +17 -17
  94. data/spec/rley/support/grammar_b_expr_helper.rb +40 -39
  95. data/spec/rley/support/grammar_helper.rb +2 -1
  96. data/spec/rley/support/{grammar_L0_helper.rb → grammar_l0_helper.rb} +82 -81
  97. data/spec/rley/support/grammar_sppf_helper.rb +24 -25
  98. data/spec/rley/syntax/grammar_spec.rb +1 -1
  99. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c5e18168fe007f5fb819f2df4f1f1944bae971d
4
- data.tar.gz: ccb8abe6ea9d8d135a0fc896ebfa4dbf5fe6f674
3
+ metadata.gz: 29bd8f0b4ab6dacef0a6086f91ccd464b0417aa5
4
+ data.tar.gz: ee3d9fde440b5936350b3cfc0779694eac4bc924
5
5
  SHA512:
6
- metadata.gz: d2eab437aba2c78676529651cca3a0a1fd9cf0b23f14f7003bf631add424a50295a14ddc1065e63db907c3003a415ae1c20427a1d6594243f5724a25203f248b
7
- data.tar.gz: 4fc6fa566e1f8c847dd34a862e27d73d7dc758bfcd557e84343b41951f6f52dd2993d0be4d92c60ec40241887065021ca006ef4b96dd1e609264b9976da6a433
6
+ metadata.gz: cd2d999e9d1534d11106b86139a87570a250ed7f3c7d525e4cc518bc2e023252e097ce4bd2f550a745d113551856765fc4ac7a45e318da640fca3a42f38fef91
7
+ data.tar.gz: 63f1f1bef8272d05da2cf35fb7f4030c6c9c6e8d0e666151e95be7867317b946c88d8591025b7fdc0f496d381eca6c164e9217c6f11891a979a2eb02ea6441d5
@@ -2,11 +2,12 @@ AllCops:
2
2
  Exclude:
3
3
  - 'examples/**/*'
4
4
  - 'features/**/*'
5
+ - 'exp/**/*'
5
6
  - 'gems/**/*'
6
- - 'lab/**/*'
7
+ - 'refs/**/*'
7
8
 
8
9
  AbcSize:
9
- Max: 35
10
+ Max: 45
10
11
 
11
12
  # This is disabled because some demos use UTF-8
12
13
  AsciiComments:
@@ -60,7 +61,7 @@ MethodLength:
60
61
 
61
62
  # Avoid modules longer than 500 lines of code
62
63
  ModuleLength:
63
- Max: 500
64
+ Max: 700
64
65
 
65
66
  NonNilCheck:
66
67
  Enabled: false
@@ -84,4 +85,7 @@ TrailingWhitespace:
84
85
  Enabled: false
85
86
 
86
87
  VariableName:
88
+ Enabled: false
89
+
90
+ VariableNumber:
87
91
  Enabled: false
@@ -1,3 +1,6 @@
1
+ ### 0.3.05 / 2016-11-01
2
+ * [CHANGE] Code re-styling to please Rubocop 0.45.0: only 2 offences remain (from a few hundreds!)
3
+
1
4
  ### 0.3.04 / 2016-11-01
2
5
  * [FIX] File `state_set_spec.rb` : Failing mock tests. Reverted `expect` to `allow` expectations.
3
6
 
data/Rakefile CHANGED
@@ -1,30 +1,30 @@
1
- require 'rubygems'
2
- require_relative './lib/rley/constants'
3
-
4
- namespace :gem do
5
- desc 'Push the gem to rubygems.org'
6
- task :push do
7
- system("gem push rley-#{Rley::Version}.gem")
8
- end
9
- end # namespace
10
-
11
-
12
- # Testing-specific tasks
13
-
14
- # RSpec as testing tool
15
- require 'rspec/core/rake_task'
16
- desc 'Run RSpec'
17
- RSpec::Core::RakeTask.new do |spec|
18
- spec.pattern = 'spec/**/*_spec.rb'
19
- end
20
-
21
-
22
- # Combine RSpec tests
23
- desc 'Run tests, with RSpec'
24
- task test: [:spec]
25
-
26
-
27
- # Default rake task
28
- task default: :test
29
-
30
- # End of file
1
+ require 'rubygems'
2
+ require_relative './lib/rley/constants'
3
+
4
+ namespace :gem do
5
+ desc 'Push the gem to rubygems.org'
6
+ task :push do
7
+ system("gem push rley-#{Rley::Version}.gem")
8
+ end
9
+ end # namespace
10
+
11
+
12
+ # Testing-specific tasks
13
+
14
+ # RSpec as testing tool
15
+ require 'rspec/core/rake_task'
16
+ desc 'Run RSpec'
17
+ RSpec::Core::RakeTask.new do |spec|
18
+ spec.pattern = 'spec/**/*_spec.rb'
19
+ end
20
+
21
+
22
+ # Combine RSpec tests
23
+ desc 'Run tests, with RSpec'
24
+ task test: [:spec]
25
+
26
+
27
+ # Default rake task
28
+ task default: :test
29
+
30
+ # End of file
@@ -80,7 +80,7 @@ def tokenizer(aText, aGrammar)
80
80
  tokens = aText.scan(/\S+/).map do |word|
81
81
  term_name = L0_lexicon[word]
82
82
  if term_name.nil?
83
- fail StandardError, "Word '#{word}' not found in lexicon"
83
+ raise StandardError, "Word '#{word}' not found in lexicon"
84
84
  end
85
85
  terminal = aGrammar.name2symbol[term_name]
86
86
  Rley::Parser::Token.new(word, terminal)
@@ -93,7 +93,7 @@ def tokenizer(aText, aGrammar)
93
93
  tokens = aText.scan(/\S+/).map do |word|
94
94
  term_name = L1_lexicon[word]
95
95
  if term_name.nil?
96
- fail StandardError, "Word '#{word}' not found in lexicon"
96
+ raise StandardError, "Word '#{word}' not found in lexicon"
97
97
  end
98
98
  terminal = aGrammar.name2symbol[term_name]
99
99
  Rley::Parser::Token.new(word, terminal)
@@ -31,7 +31,7 @@ grammar_abc = builder.grammar
31
31
  def tokenizer(aText, aGrammar)
32
32
  tokens = aText.chars.map do |ch|
33
33
  terminal = aGrammar.name2symbol[ch]
34
- fail StandardError, "Unknown input character '#{ch}'" if terminal.nil?
34
+ raise StandardError, "Unknown input character '#{ch}'" if terminal.nil?
35
35
  Rley::Parser::Token.new(ch, terminal)
36
36
  end
37
37
 
@@ -41,7 +41,7 @@ def tokenizer(aText, aGrammar)
41
41
  terminal = aGrammar.name2symbol['integer']
42
42
  else
43
43
  msg = "Unknown input text '#{lexeme}'"
44
- fail StandardError, msg
44
+ raise StandardError, msg
45
45
  end
46
46
  Rley::Parser::Token.new(lexeme, terminal)
47
47
  end
@@ -37,7 +37,7 @@ def tokenizer(aText, aGrammar)
37
37
  terminal = aGrammar.name2symbol[lexeme]
38
38
  else
39
39
  msg = "Unknown input text '#{lexeme}'"
40
- fail StandardError, msg
40
+ raise StandardError, msg
41
41
  end
42
42
  Rley::Parser::Token.new(lexeme, terminal)
43
43
  end
@@ -42,7 +42,7 @@ def tokenizer(aText, aGrammar)
42
42
  terminal = aGrammar.name2symbol['integer']
43
43
  else
44
44
  msg = "Unknown input text '#{lexeme}'"
45
- fail StandardError, msg
45
+ raise StandardError, msg
46
46
  end
47
47
  Rley::Parser::Token.new(lexeme, terminal)
48
48
  end
@@ -41,7 +41,7 @@ def tokenizer(aText, aGrammar)
41
41
  terminal = aGrammar.name2symbol['integer']
42
42
  else
43
43
  msg = "Unknown input text '#{lexeme}'"
44
- fail StandardError, msg
44
+ raise StandardError, msg
45
45
  end
46
46
  Rley::Parser::Token.new(lexeme, terminal)
47
47
  end
@@ -53,7 +53,7 @@ def tokenizer(aText, aGrammar)
53
53
  tokens = aText.scan(/\S+/).map do |word|
54
54
  term_name = Groucho_lexicon[word]
55
55
  if term_name.nil?
56
- fail StandardError, "Word '#{word}' not found in lexicon"
56
+ raise StandardError, "Word '#{word}' not found in lexicon"
57
57
  end
58
58
  terminal = aGrammar.name2symbol[term_name]
59
59
  Rley::Parser::Token.new(word, terminal)
@@ -38,7 +38,7 @@ def tokenizer(aText, aGrammar)
38
38
  terminal = aGrammar.name2symbol[lexeme]
39
39
  else
40
40
  msg = "Unknown input text '#{lexeme}'"
41
- fail StandardError, msg
41
+ raise StandardError, msg
42
42
  end
43
43
  Rley::Parser::Token.new(lexeme, terminal)
44
44
  end
@@ -41,7 +41,7 @@ def tokenizer(aText, aGrammar)
41
41
  terminal = aGrammar.name2symbol[lexeme]
42
42
  else
43
43
  msg = "Unknown input text '#{lexeme}'"
44
- fail StandardError, msg
44
+ raise StandardError, msg
45
45
  end
46
46
  Rley::Parser::Token.new(lexeme, terminal)
47
47
  end
@@ -3,10 +3,10 @@
3
3
 
4
4
  module Rley # Module used as a namespace
5
5
  # The version number of the gem.
6
- Version = '0.3.04'
6
+ Version = '0.3.05'.freeze
7
7
 
8
8
  # Brief description of the gem.
9
- Description = "Ruby implementation of the Earley's parsing algorithm"
9
+ Description = "Ruby implementation of the Earley's parsing algorithm".freeze
10
10
 
11
11
  # Constant Rley::RootDir contains the absolute path of Rley's
12
12
  # start directory. Note: it also ends with a slash character.
@@ -13,8 +13,6 @@ module Rley # This module is used as a namespace
13
13
  @output = anIO
14
14
  end
15
15
 
16
- public
17
-
18
16
  # Given a parse tree visitor, perform the visit
19
17
  # and render the visit events in the output stream.
20
18
  # @param aVisitor [ParseTreeVisitor]
@@ -18,8 +18,6 @@ module Rley # This module is used as a namespace
18
18
  @indentation = 0
19
19
  end
20
20
 
21
- public
22
-
23
21
  # Method called by a ParseTreeVisitor to which the formatter subscribed.
24
22
  # Notification of a visit event: the visitor is about to visit the given
25
23
  # parse tree
@@ -22,8 +22,6 @@ module Rley # This module is used as a namespace
22
22
  @sibling_flags = [ false ]
23
23
  end
24
24
 
25
- public
26
-
27
25
  # Method called by a ParseTreeVisitor to which the formatter subscribed.
28
26
  # Notification of a visit event: the visitor is about to visit the given
29
27
  # parse tree
@@ -31,7 +29,7 @@ module Rley # This module is used as a namespace
31
29
  def before_ptree(_ptree)
32
30
  print_text('', "{\n")
33
31
  indent
34
- print_text('', "\"root\":")
32
+ print_text('', '"root":')
35
33
  indent
36
34
  end
37
35
 
@@ -1,30 +1,31 @@
1
- require_relative 'edge'
2
-
3
- module Rley # This module is used as a namespace
4
- module GFG # This module is used as a namespace
5
- # Specialization of an edge in a grammar flow graph
6
- # that has a item vertex as its head (predecessor).
7
- # and a start vertex (.X) as its tail (successor).
8
- # Responsibilities:
9
- # - To know the successor vertex (tail)
10
- class CallEdge < Edge
11
- attr_reader(:key)
12
-
13
- # Pre-condition: thePredecessor is an ItemVertex
14
- # Pre-condition: theSuccessor is an StartVertex
15
- def initialize(thePredecessor, theSuccessor)
16
- super(thePredecessor, theSuccessor)
17
- do_set_key(thePredecessor, theSuccessor)
18
- end
19
-
20
- private
21
- def do_set_key(thePredecessor, theSuccessor)
22
- tail_d_item = thePredecessor.dotted_item
23
- @key = "CALL_#{tail_d_item.production.object_id}_#{tail_d_item.position}"
24
- end
25
-
26
- end # class
27
- end # module
28
- end # module
29
-
30
- # End of file
1
+ require_relative 'edge'
2
+
3
+ module Rley # This module is used as a namespace
4
+ module GFG # This module is used as a namespace
5
+ # Specialization of an edge in a grammar flow graph
6
+ # that has a item vertex as its head (predecessor).
7
+ # and a start vertex (.X) as its tail (successor).
8
+ # Responsibilities:
9
+ # - To know the successor vertex (tail)
10
+ class CallEdge < Edge
11
+ attr_reader(:key)
12
+
13
+ # Pre-condition: thePredecessor is an ItemVertex
14
+ # Pre-condition: theSuccessor is an StartVertex
15
+ def initialize(thePredecessor, theSuccessor)
16
+ super(thePredecessor, theSuccessor)
17
+ do_set_key(thePredecessor, theSuccessor)
18
+ end
19
+
20
+ private
21
+
22
+ def do_set_key(thePredecessor, _theSuccessor)
23
+ tail_d_item = thePredecessor.dotted_item
24
+ tail_production = tail_d_item.production
25
+ @key = "CALL_#{tail_production.object_id}_#{tail_d_item.position}"
26
+ end
27
+ end # class
28
+ end # module
29
+ end # module
30
+
31
+ # End of file
@@ -1,23 +1,22 @@
1
- module Rley # This module is used as a namespace
2
- module GFG # This module is used as a namespace
3
- # Abstract class. Represents an edge in a grammar flow graph.
4
- # Responsibilities:
5
- # - To know the successor vertex
6
- class Edge
7
- # The destination vertex of the edge .
8
- attr_reader :successor
9
-
10
- def initialize(thePredecessor, theSuccessor)
11
- @successor = theSuccessor
12
- thePredecessor.add_edge(self)
13
- end
14
-
15
- def to_s()
16
- " --> #{successor.label}"
17
- end
18
-
19
- end # class
20
- end # module
21
- end # module
22
-
23
- # End of file
1
+ module Rley # This module is used as a namespace
2
+ module GFG # This module is used as a namespace
3
+ # Abstract class. Represents an edge in a grammar flow graph.
4
+ # Responsibilities:
5
+ # - To know the successor vertex
6
+ class Edge
7
+ # The destination vertex of the edge .
8
+ attr_reader :successor
9
+
10
+ def initialize(thePredecessor, theSuccessor)
11
+ @successor = theSuccessor
12
+ thePredecessor.add_edge(self)
13
+ end
14
+
15
+ def to_s()
16
+ " --> #{successor.label}"
17
+ end
18
+ end # class
19
+ end # module
20
+ end # module
21
+
22
+ # End of file
@@ -1,24 +1,22 @@
1
- require_relative 'non_terminal_vertex'
2
-
3
- module Rley # This module is used as a namespace
4
- module GFG # This module is used as a namespace
5
- # TODO: change definition.
6
- # Represents a specialized vertex in a grammar flow graph
7
- # that is associated to a given non-terminal symbol.
8
- # Responsibilities (in addition to inherited ones):
9
- # - Know its related non-terminal symbol
10
- class EndVertex < NonTerminalVertex
11
-
12
- def initialize(aNonTerminal)
13
- super(aNonTerminal)
14
- end
15
-
16
- def label()
17
- return "#{non_terminal}."
18
- end
19
-
20
- end # class
21
- end # module
22
- end # module
23
-
24
- # End of file
1
+ require_relative 'non_terminal_vertex'
2
+
3
+ module Rley # This module is used as a namespace
4
+ module GFG # This module is used as a namespace
5
+ # TODO: change definition.
6
+ # Represents a specialized vertex in a grammar flow graph
7
+ # that is associated to a given non-terminal symbol.
8
+ # Responsibilities (in addition to inherited ones):
9
+ # - Know its related non-terminal symbol
10
+ class EndVertex < NonTerminalVertex
11
+ def initialize(aNonTerminal)
12
+ super(aNonTerminal)
13
+ end
14
+
15
+ def label()
16
+ return "#{non_terminal}."
17
+ end
18
+ end # class
19
+ end # module
20
+ end # module
21
+
22
+ # End of file
@@ -1,21 +1,20 @@
1
- require_relative 'edge'
2
-
3
- module Rley # This module is used as a namespace
4
- module GFG # This module is used as a namespace
5
- # Represents an edge in a grammar flow graph
6
- # without change of the position in the input stream.
7
- # Responsibilities:
8
- # - To know the successor vertex
9
- class EpsilonEdge < Edge
10
- # The destination vertex of the edge .
11
- attr_reader :successor
12
-
13
- def initialize(thePredecessor, theSuccessor)
14
- super(thePredecessor, theSuccessor)
15
- end
16
-
17
- end # class
18
- end # module
19
- end # module
20
-
21
- # End of file
1
+ require_relative 'edge'
2
+
3
+ module Rley # This module is used as a namespace
4
+ module GFG # This module is used as a namespace
5
+ # Represents an edge in a grammar flow graph
6
+ # without change of the position in the input stream.
7
+ # Responsibilities:
8
+ # - To know the successor vertex
9
+ class EpsilonEdge < Edge
10
+ # The destination vertex of the edge .
11
+ attr_reader :successor
12
+
13
+ def initialize(thePredecessor, theSuccessor)
14
+ super(thePredecessor, theSuccessor)
15
+ end
16
+ end # class
17
+ end # module
18
+ end # module
19
+
20
+ # End of file