rley 0.1.08 → 0.1.09
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.
- checksums.yaml +8 -8
- data/.rubocop.yml +81 -74
- data/CHANGELOG.md +4 -0
- data/Rakefile +4 -6
- data/examples/grammars/grammar_L0.rb +31 -31
- data/examples/grammars/grammar_abc.rb +26 -26
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/formatter/base_formatter.rb +1 -3
- data/lib/rley/formatter/debug.rb +1 -3
- data/lib/rley/formatter/json.rb +2 -5
- data/lib/rley/parse_tree_visitor.rb +0 -2
- data/lib/rley/parser/dotted_item.rb +3 -1
- data/lib/rley/parser/earley_parser.rb +4 -4
- data/lib/rley/parser/parsing.rb +10 -9
- data/lib/rley/parser/state_set.rb +1 -3
- data/lib/rley/ptree/non_terminal_node.rb +1 -1
- data/lib/rley/ptree/parse_tree.rb +32 -34
- data/lib/rley/ptree/parse_tree_node.rb +1 -3
- data/lib/rley/ptree/terminal_node.rb +1 -2
- data/lib/rley/ptree/token_range.rb +14 -14
- data/spec/rley/formatter/debug_spec.rb +65 -68
- data/spec/rley/formatter/json_spec.rb +69 -72
- data/spec/rley/parse_tree_visitor_spec.rb +5 -7
- data/spec/rley/parser/chart_spec.rb +0 -4
- data/spec/rley/parser/dotted_item_spec.rb +0 -3
- data/spec/rley/parser/earley_parser_spec.rb +0 -1
- data/spec/rley/parser/parse_state_spec.rb +0 -5
- data/spec/rley/parser/parsing_spec.rb +0 -3
- data/spec/rley/parser/state_set_spec.rb +0 -4
- data/spec/rley/parser/token_spec.rb +0 -4
- data/spec/rley/ptree/non_terminal_node_spec.rb +0 -1
- data/spec/rley/ptree/parse_tree_node_spec.rb +4 -4
- data/spec/rley/ptree/parse_tree_spec.rb +2 -3
- data/spec/rley/ptree/token_range_spec.rb +16 -17
- data/spec/rley/support/grammar_abc_helper.rb +0 -2
- data/spec/rley/syntax/grammar_builder_spec.rb +1 -4
- data/spec/rley/syntax/grammar_spec.rb +0 -9
- data/spec/rley/syntax/grm_symbol_spec.rb +0 -1
- data/spec/rley/syntax/literal_spec.rb +0 -1
- data/spec/rley/syntax/non_terminal_spec.rb +0 -1
- data/spec/rley/syntax/production_spec.rb +0 -2
- data/spec/rley/syntax/symbol_seq_spec.rb +0 -1
- data/spec/rley/syntax/terminal_spec.rb +0 -1
- data/spec/rley/syntax/verbatim_symbol_spec.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODQ1OTNmNjQ5YjA1NTFkMWU2MjczMDgzYjI1OGMwYjU4MGMzOWU4Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDRhZTcyNDkxZjYxZWIwYzA4YWVlM2Q5NTNkZDAwNGM1MTI2YjdlMQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZThlM2MwMGYzYmNlZmU4MzVjM2I3YWQwNTAwYzA3MWU1NzhjMGI1MTZmYTI4
|
10
|
+
NDU5ZTg4NzVjZTBlOGViYmQxNDJhYjQyM2M3NjM3ZTZhNDFiMzU1NjZmYTdj
|
11
|
+
YjM5YjRkYWFhZGNjNmYwOTVmN2QwODM2N2IyNGExMzgzODFiNjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDIwNDE2Y2RiODNlN2UwZGRhNzY0NTJjMjVjZjE1ZmU5NmNjNDhiMDBkOGRi
|
14
|
+
Yjk3OWViNDdlOGNkMWY3NTE1MDIxNTEzZWI3N2M5OTVhYzFkNDg2OWU4ODVm
|
15
|
+
NzE4Mjg5MzliNThhOTk5ZDRiM2RiNDhmNmZhYzdjYzRlYzFiMmI=
|
data/.rubocop.yml
CHANGED
@@ -1,74 +1,81 @@
|
|
1
|
-
AllCops:
|
2
|
-
Exclude:
|
3
|
-
- 'examples/**/*'
|
4
|
-
- 'features/**/*'
|
5
|
-
- 'gems/**/*'
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'examples/**/*'
|
4
|
+
- 'features/**/*'
|
5
|
+
- 'gems/**/*'
|
6
|
+
- 'refs/**/*'
|
7
|
+
|
8
|
+
# This is disabled because some demos use UTF-8
|
9
|
+
AsciiComments:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
BlockComments:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
CaseIndentation:
|
16
|
+
IndentWhenRelativeTo: end
|
17
|
+
IndentOneStep: true
|
18
|
+
|
19
|
+
# Rubocop enforces the use of is_a? instead of kind_of?
|
20
|
+
# Which is contrary to modelling practice.
|
21
|
+
ClassCheck:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
ClassLength:
|
25
|
+
Max: 250
|
26
|
+
CountComments: false
|
27
|
+
|
28
|
+
ConstantName:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
CyclomaticComplexity:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
DefWithParentheses:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Documentation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
EmptyLines:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
EmptyLinesAroundBody:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Encoding:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
FileName:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
IndentationWidth :
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
|
56
|
+
# Avoid methods longer than 50 lines of code
|
57
|
+
MethodLength:
|
58
|
+
Max: 50
|
59
|
+
CountComments: false
|
60
|
+
|
61
|
+
NonNilCheck:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
NumericLiterals:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
RaiseArgs:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
RedundantReturn:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
SpaceInsideBrackets:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
TrailingWhitespace:
|
77
|
+
Enabled: false
|
78
|
+
|
79
|
+
VariableName:
|
80
|
+
Enabled: false
|
81
|
+
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
@@ -2,12 +2,10 @@ require 'rubygems'
|
|
2
2
|
require_relative './lib/rley/constants'
|
3
3
|
|
4
4
|
namespace :gem do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
5
|
+
desc 'Push the gem to rubygems.org'
|
6
|
+
task :push do
|
7
|
+
system("gem push rley-#{Rley::Version}.gem")
|
8
|
+
end
|
11
9
|
end # namespace
|
12
10
|
|
13
11
|
|
@@ -1,32 +1,32 @@
|
|
1
|
-
# Purpose: to demonstrate how to build a very simple grammar
|
2
|
-
require 'rley' # Load the gem
|
3
|
-
|
4
|
-
# Sample grammar for a very limited English language
|
5
|
-
# based on the language L0 from Jurafsky & Martin
|
6
|
-
|
7
|
-
# Let's create the grammar step-by-step with the grammar builder:
|
8
|
-
builder = Rley::Syntax::GrammarBuilder.new
|
9
|
-
|
10
|
-
# Enumerate the POS Part-Of-Speech...
|
11
|
-
builder.add_terminals('Noun', 'Verb', 'Adjective')
|
12
|
-
builder.add_terminals('Pronoun', 'Proper-Noun', 'Determiner')
|
13
|
-
builder.add_terminals('Preposition', 'Conjunction')
|
14
|
-
|
15
|
-
# Now the production rules...
|
16
|
-
builder.add_production('S'=> ['NP', 'VP']) # e.g. I + want a morning flight
|
17
|
-
builder.add_production('NP' => 'Pronoun') # e.g. I
|
18
|
-
builder.add_production('NP' => 'Proper-Noun') # e.g. Los Angeles
|
19
|
-
builder.add_production('NP' => ['Determiner', 'Nominal']) # e.g. a + flight
|
20
|
-
builder.add_production('Nominal' => %w(Nominal Noun)) # morning + flight
|
21
|
-
builder.add_production('Nominal' => 'Noun') # e.g. flights
|
22
|
-
builder.add_production('VP' => 'Verb') # e.g. do
|
23
|
-
builder.add_production('VP' => ['Verb', 'NP']) # e.g. want + a flight
|
24
|
-
builder.add_production('VP' => ['Verb', 'NP', 'PP'])
|
25
|
-
builder.add_production('VP' => ['Verb', 'PP']) # leaving + on Thursday
|
26
|
-
builder.add_production('PP' => ['Preposition', 'NP']) # from + Los Angeles
|
27
|
-
|
28
|
-
# And now we 're ready to build the grammar...
|
29
|
-
grammar_L0 = builder.grammar
|
30
|
-
|
31
|
-
# Prove that it is a grammar
|
1
|
+
# Purpose: to demonstrate how to build a very simple grammar
|
2
|
+
require 'rley' # Load the gem
|
3
|
+
|
4
|
+
# Sample grammar for a very limited English language
|
5
|
+
# based on the language L0 from Jurafsky & Martin
|
6
|
+
|
7
|
+
# Let's create the grammar step-by-step with the grammar builder:
|
8
|
+
builder = Rley::Syntax::GrammarBuilder.new
|
9
|
+
|
10
|
+
# Enumerate the POS Part-Of-Speech...
|
11
|
+
builder.add_terminals('Noun', 'Verb', 'Adjective')
|
12
|
+
builder.add_terminals('Pronoun', 'Proper-Noun', 'Determiner')
|
13
|
+
builder.add_terminals('Preposition', 'Conjunction')
|
14
|
+
|
15
|
+
# Now the production rules...
|
16
|
+
builder.add_production('S'=> ['NP', 'VP']) # e.g. I + want a morning flight
|
17
|
+
builder.add_production('NP' => 'Pronoun') # e.g. I
|
18
|
+
builder.add_production('NP' => 'Proper-Noun') # e.g. Los Angeles
|
19
|
+
builder.add_production('NP' => ['Determiner', 'Nominal']) # e.g. a + flight
|
20
|
+
builder.add_production('Nominal' => %w(Nominal Noun)) # morning + flight
|
21
|
+
builder.add_production('Nominal' => 'Noun') # e.g. flights
|
22
|
+
builder.add_production('VP' => 'Verb') # e.g. do
|
23
|
+
builder.add_production('VP' => ['Verb', 'NP']) # e.g. want + a flight
|
24
|
+
builder.add_production('VP' => ['Verb', 'NP', 'PP'])
|
25
|
+
builder.add_production('VP' => ['Verb', 'PP']) # leaving + on Thursday
|
26
|
+
builder.add_production('PP' => ['Preposition', 'NP']) # from + Los Angeles
|
27
|
+
|
28
|
+
# And now we 're ready to build the grammar...
|
29
|
+
grammar_L0 = builder.grammar
|
30
|
+
|
31
|
+
# Prove that it is a grammar
|
32
32
|
puts grammar_L0.class.name
|
@@ -1,26 +1,26 @@
|
|
1
|
-
# Purpose: to demonstrate how to build a very simple grammar
|
2
|
-
require 'rley' # Load the gem
|
3
|
-
|
4
|
-
# A very simple language
|
5
|
-
# It recognizes/generates strings like 'b', 'abc', 'aabcc', 'aaabccc',...
|
6
|
-
# (based on example in N. Wirth's book "Compiler Construction", p. 6)
|
7
|
-
# S ::= A.
|
8
|
-
# A ::= "a" A "c".
|
9
|
-
# A ::= "b".
|
10
|
-
|
11
|
-
|
12
|
-
# Let's create the grammar step-by-step with the grammar builder:
|
13
|
-
builder = Rley::Syntax::GrammarBuilder.new
|
14
|
-
builder.add_terminals('a', 'b', 'c')
|
15
|
-
builder.add_production('S' => 'A')
|
16
|
-
builder.add_production('A' => %w(a A c))
|
17
|
-
builder.add_production('A' => 'b')
|
18
|
-
|
19
|
-
# And now build the grammar...
|
20
|
-
grammar_abc = builder.grammar
|
21
|
-
|
22
|
-
# Prove that it is a grammar
|
23
|
-
puts grammar_abc.class.name
|
24
|
-
|
25
|
-
# End of file
|
26
|
-
|
1
|
+
# Purpose: to demonstrate how to build a very simple grammar
|
2
|
+
require 'rley' # Load the gem
|
3
|
+
|
4
|
+
# A very simple language
|
5
|
+
# It recognizes/generates strings like 'b', 'abc', 'aabcc', 'aaabccc',...
|
6
|
+
# (based on example in N. Wirth's book "Compiler Construction", p. 6)
|
7
|
+
# S ::= A.
|
8
|
+
# A ::= "a" A "c".
|
9
|
+
# A ::= "b".
|
10
|
+
|
11
|
+
|
12
|
+
# Let's create the grammar step-by-step with the grammar builder:
|
13
|
+
builder = Rley::Syntax::GrammarBuilder.new
|
14
|
+
builder.add_terminals('a', 'b', 'c')
|
15
|
+
builder.add_production('S' => 'A')
|
16
|
+
builder.add_production('A' => %w(a A c))
|
17
|
+
builder.add_production('A' => 'b')
|
18
|
+
|
19
|
+
# And now build the grammar...
|
20
|
+
grammar_abc = builder.grammar
|
21
|
+
|
22
|
+
# Prove that it is a grammar
|
23
|
+
puts grammar_abc.class.name
|
24
|
+
|
25
|
+
# End of file
|
26
|
+
|
data/lib/rley/constants.rb
CHANGED
@@ -2,11 +2,10 @@ module Rley # This module is used as a namespace
|
|
2
2
|
|
3
3
|
# Namespace dedicated to parse tree formatters.
|
4
4
|
module Formatter
|
5
|
-
|
6
5
|
# Superclass for parse tree formatters.
|
7
6
|
class BaseFormatter
|
8
7
|
# The IO output stream in which the formatter's result will be sent.
|
9
|
-
|
8
|
+
attr_reader(:output)
|
10
9
|
|
11
10
|
# Constructor.
|
12
11
|
# @param anIO [IO] an output IO where the formatter's result will
|
@@ -25,7 +24,6 @@ module Rley # This module is used as a namespace
|
|
25
24
|
aVisitor.start
|
26
25
|
aVisitor.unsubscribe(self)
|
27
26
|
end
|
28
|
-
|
29
27
|
end # class
|
30
28
|
end # module
|
31
29
|
end # module
|
data/lib/rley/formatter/debug.rb
CHANGED
@@ -4,12 +4,11 @@ require_relative 'base_formatter'
|
|
4
4
|
module Rley # This module is used as a namespace
|
5
5
|
# Namespace dedicated to parse tree formatters.
|
6
6
|
module Formatter
|
7
|
-
|
8
7
|
# A formatter class that renders the visit notification events
|
9
8
|
# from a parse tree visitor
|
10
9
|
class Debug < BaseFormatter
|
11
10
|
# Current indentation level
|
12
|
-
|
11
|
+
attr_reader(:indentation)
|
13
12
|
|
14
13
|
# Constructor.
|
15
14
|
# @param anIO [IO] The output stream to which the rendered grammar
|
@@ -107,7 +106,6 @@ module Rley # This module is used as a namespace
|
|
107
106
|
def output_event(anEvent, indentationLevel)
|
108
107
|
output.puts "#{' ' * 2 * indentationLevel}#{anEvent}"
|
109
108
|
end
|
110
|
-
|
111
109
|
end # class
|
112
110
|
end # module
|
113
111
|
end # module
|
data/lib/rley/formatter/json.rb
CHANGED
@@ -4,15 +4,14 @@ require_relative 'base_formatter'
|
|
4
4
|
module Rley # This module is used as a namespace
|
5
5
|
# Namespace dedicated to parse tree formatters.
|
6
6
|
module Formatter
|
7
|
-
|
8
7
|
# A formatter class that renders a parse tree in JSON format
|
9
8
|
class Json < BaseFormatter
|
10
9
|
# Current indentation level
|
11
|
-
|
10
|
+
attr_reader(:indentation)
|
12
11
|
|
13
12
|
# Array of booleans (one per indentation level).
|
14
13
|
# Set to true after first child was visited.
|
15
|
-
|
14
|
+
attr_reader(:sibling_flags)
|
16
15
|
|
17
16
|
# Constructor.
|
18
17
|
# @param anIO [IO] The output stream to which the rendered grammar
|
@@ -98,7 +97,6 @@ module Rley # This module is used as a namespace
|
|
98
97
|
# @param _ptree [ParseTree]
|
99
98
|
def after_ptree(_ptree)
|
100
99
|
dedent
|
101
|
-
#print_text("\n", ']')
|
102
100
|
dedent
|
103
101
|
print_text("\n", '}')
|
104
102
|
end
|
@@ -117,7 +115,6 @@ module Rley # This module is used as a namespace
|
|
117
115
|
output.print aSeparator
|
118
116
|
output.print "#{' ' * 2 * @indentation}#{aText}" unless aText.nil?
|
119
117
|
end
|
120
|
-
|
121
118
|
end # class
|
122
119
|
end # module
|
123
120
|
end # module
|
@@ -92,8 +92,10 @@ module Rley # This module is used as a namespace
|
|
92
92
|
when -1
|
93
93
|
result = (production.rhs.size == 1) ? 0 : (production.rhs.size - 1)
|
94
94
|
else
|
95
|
-
result = position-1
|
95
|
+
result = position - 1
|
96
96
|
end
|
97
|
+
|
98
|
+
return result
|
97
99
|
end
|
98
100
|
|
99
101
|
# An item with the dot in front of a terminal is called a shift item
|
@@ -142,10 +142,10 @@ module Rley # This module is used as a namespace
|
|
142
142
|
aParsing.push_state(an_item, aPosition, aPosition)
|
143
143
|
end
|
144
144
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
145
|
+
return unless aNonTerminal.nullable?
|
146
|
+
# Ayock-Horspool trick for nullable rules
|
147
|
+
next_item = next_mapping[aState.dotted_rule]
|
148
|
+
aParsing.push_state(next_item, aState.origin, aPosition)
|
149
149
|
end
|
150
150
|
|
151
151
|
# This method is called when a parse state for chart entry at position
|