rley 0.3.04 → 0.3.05
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -3
- data/CHANGELOG.md +3 -0
- data/Rakefile +30 -30
- data/examples/parsers/parsing_L0.rb +1 -1
- data/examples/parsers/parsing_L1.rb +1 -1
- data/examples/parsers/parsing_abc.rb +1 -1
- data/examples/parsers/parsing_ambig.rb +1 -1
- data/examples/parsers/parsing_another.rb +1 -1
- data/examples/parsers/parsing_b_expr.rb +1 -1
- data/examples/parsers/parsing_err_expr.rb +1 -1
- data/examples/parsers/parsing_groucho.rb +1 -1
- data/examples/parsers/parsing_right_recursive.rb +1 -1
- data/examples/parsers/parsing_tricky.rb +1 -1
- data/lib/rley/constants.rb +2 -2
- data/lib/rley/formatter/base_formatter.rb +0 -2
- data/lib/rley/formatter/debug.rb +0 -2
- data/lib/rley/formatter/json.rb +1 -3
- data/lib/rley/gfg/call_edge.rb +31 -30
- data/lib/rley/gfg/edge.rb +22 -23
- data/lib/rley/gfg/end_vertex.rb +22 -24
- data/lib/rley/gfg/epsilon_edge.rb +20 -21
- data/lib/rley/gfg/grm_flow_graph.rb +39 -39
- data/lib/rley/gfg/item_vertex.rb +16 -17
- data/lib/rley/gfg/non_terminal_vertex.rb +3 -4
- data/lib/rley/gfg/return_edge.rb +32 -31
- data/lib/rley/gfg/scan_edge.rb +25 -26
- data/lib/rley/gfg/shortcut_edge.rb +25 -26
- data/lib/rley/gfg/start_vertex.rb +0 -2
- data/lib/rley/gfg/vertex.rb +8 -8
- data/lib/rley/parse_forest_visitor.rb +113 -115
- data/lib/rley/parse_tree_visitor.rb +0 -2
- data/lib/rley/parser/base_parser.rb +27 -27
- data/lib/rley/parser/chart.rb +14 -14
- data/lib/rley/parser/dotted_item.rb +33 -33
- data/lib/rley/parser/earley_parser.rb +6 -6
- data/lib/rley/parser/gfg_chart.rb +8 -15
- data/lib/rley/parser/gfg_earley_parser.rb +15 -13
- data/lib/rley/parser/gfg_parsing.rb +26 -22
- data/lib/rley/parser/grm_items_builder.rb +3 -2
- data/lib/rley/parser/parse_entry.rb +3 -9
- data/lib/rley/parser/parse_entry_set.rb +14 -19
- data/lib/rley/parser/parse_entry_tracker.rb +56 -56
- data/lib/rley/parser/parse_forest_builder.rb +215 -214
- data/lib/rley/parser/parse_forest_factory.rb +57 -56
- data/lib/rley/parser/parse_state.rb +8 -11
- data/lib/rley/parser/parse_state_tracker.rb +56 -56
- data/lib/rley/parser/parse_tracer.rb +3 -3
- data/lib/rley/parser/parse_tree_builder.rb +10 -10
- data/lib/rley/parser/parse_walker_factory.rb +30 -33
- data/lib/rley/parser/parsing.rb +8 -8
- data/lib/rley/parser/state_set.rb +23 -26
- data/lib/rley/ptree/non_terminal_node.rb +1 -1
- data/lib/rley/ptree/token_range.rb +2 -2
- data/lib/rley/sppf/alternative_node.rb +32 -34
- data/lib/rley/sppf/composite_node.rb +27 -27
- data/lib/rley/sppf/epsilon_node.rb +26 -27
- data/lib/rley/sppf/leaf_node.rb +11 -12
- data/lib/rley/sppf/non_terminal_node.rb +37 -38
- data/lib/rley/sppf/sppf_node.rb +1 -1
- data/lib/rley/sppf/token_node.rb +29 -29
- data/lib/rley/syntax/grammar.rb +1 -3
- data/lib/rley/syntax/grammar_builder.rb +8 -8
- data/lib/rley/syntax/non_terminal.rb +2 -4
- data/lib/rley/syntax/production.rb +3 -3
- data/lib/rley/syntax/symbol_seq.rb +1 -1
- data/spec/rley/gfg/call_edge_spec.rb +50 -51
- data/spec/rley/gfg/edge_spec.rb +33 -33
- data/spec/rley/gfg/end_vertex_spec.rb +26 -27
- data/spec/rley/gfg/epsilon_edge_spec.rb +25 -25
- data/spec/rley/gfg/grm_flow_graph_spec.rb +1 -1
- data/spec/rley/gfg/item_vertex_spec.rb +3 -4
- data/spec/rley/gfg/return_edge_spec.rb +51 -51
- data/spec/rley/gfg/scan_edge_spec.rb +32 -30
- data/spec/rley/gfg/shortcut_edge_spec.rb +1 -1
- data/spec/rley/gfg/vertex_spec.rb +3 -3
- data/spec/rley/parse_forest_visitor_spec.rb +239 -238
- data/spec/rley/parser/dotted_item_spec.rb +1 -1
- data/spec/rley/parser/earley_parser_spec.rb +16 -16
- data/spec/rley/parser/gfg_earley_parser_spec.rb +30 -31
- data/spec/rley/parser/gfg_parsing_spec.rb +11 -10
- data/spec/rley/parser/grm_items_builder_spec.rb +2 -2
- data/spec/rley/parser/parse_entry_set_spec.rb +4 -4
- data/spec/rley/parser/parse_entry_spec.rb +0 -2
- data/spec/rley/parser/parse_forest_builder_spec.rb +82 -57
- data/spec/rley/parser/parse_forest_factory_spec.rb +84 -82
- data/spec/rley/parser/parse_walker_factory_spec.rb +10 -9
- data/spec/rley/parser/parsing_spec.rb +0 -1
- data/spec/rley/sppf/alternative_node_spec.rb +2 -2
- data/spec/rley/sppf/non_terminal_node_spec.rb +0 -1
- data/spec/rley/support/ambiguous_grammar_helper.rb +1 -1
- data/spec/rley/support/expectation_helper.rb +37 -36
- data/spec/rley/support/grammar_abc_helper.rb +17 -17
- data/spec/rley/support/grammar_b_expr_helper.rb +40 -39
- data/spec/rley/support/grammar_helper.rb +2 -1
- data/spec/rley/support/{grammar_L0_helper.rb → grammar_l0_helper.rb} +82 -81
- data/spec/rley/support/grammar_sppf_helper.rb +24 -25
- data/spec/rley/syntax/grammar_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29bd8f0b4ab6dacef0a6086f91ccd464b0417aa5
|
4
|
+
data.tar.gz: ee3d9fde440b5936350b3cfc0779694eac4bc924
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd2d999e9d1534d11106b86139a87570a250ed7f3c7d525e4cc518bc2e023252e097ce4bd2f550a745d113551856765fc4ac7a45e318da640fca3a42f38fef91
|
7
|
+
data.tar.gz: 63f1f1bef8272d05da2cf35fb7f4030c6c9c6e8d0e666151e95be7867317b946c88d8591025b7fdc0f496d381eca6c164e9217c6f11891a979a2eb02ea6441d5
|
data/.rubocop.yml
CHANGED
@@ -2,11 +2,12 @@ AllCops:
|
|
2
2
|
Exclude:
|
3
3
|
- 'examples/**/*'
|
4
4
|
- 'features/**/*'
|
5
|
+
- 'exp/**/*'
|
5
6
|
- 'gems/**/*'
|
6
|
-
- '
|
7
|
+
- 'refs/**/*'
|
7
8
|
|
8
9
|
AbcSize:
|
9
|
-
Max:
|
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:
|
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
|
data/CHANGELOG.md
CHANGED
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
|
-
|
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
|
-
|
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
|
-
|
34
|
+
raise StandardError, "Unknown input character '#{ch}'" if terminal.nil?
|
35
35
|
Rley::Parser::Token.new(ch, terminal)
|
36
36
|
end
|
37
37
|
|
@@ -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
|
-
|
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)
|
data/lib/rley/constants.rb
CHANGED
@@ -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.
|
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.
|
data/lib/rley/formatter/debug.rb
CHANGED
data/lib/rley/formatter/json.rb
CHANGED
@@ -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('', "
|
32
|
+
print_text('', '"root":')
|
35
33
|
indent
|
36
34
|
end
|
37
35
|
|
data/lib/rley/gfg/call_edge.rb
CHANGED
@@ -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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end # module
|
29
|
-
|
30
|
-
|
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
|
data/lib/rley/gfg/edge.rb
CHANGED
@@ -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
|
-
|
20
|
-
|
21
|
-
|
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
|
data/lib/rley/gfg/end_vertex.rb
CHANGED
@@ -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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|