rley 0.1.08 → 0.1.09

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +8 -8
  2. data/.rubocop.yml +81 -74
  3. data/CHANGELOG.md +4 -0
  4. data/Rakefile +4 -6
  5. data/examples/grammars/grammar_L0.rb +31 -31
  6. data/examples/grammars/grammar_abc.rb +26 -26
  7. data/lib/rley/constants.rb +1 -1
  8. data/lib/rley/formatter/base_formatter.rb +1 -3
  9. data/lib/rley/formatter/debug.rb +1 -3
  10. data/lib/rley/formatter/json.rb +2 -5
  11. data/lib/rley/parse_tree_visitor.rb +0 -2
  12. data/lib/rley/parser/dotted_item.rb +3 -1
  13. data/lib/rley/parser/earley_parser.rb +4 -4
  14. data/lib/rley/parser/parsing.rb +10 -9
  15. data/lib/rley/parser/state_set.rb +1 -3
  16. data/lib/rley/ptree/non_terminal_node.rb +1 -1
  17. data/lib/rley/ptree/parse_tree.rb +32 -34
  18. data/lib/rley/ptree/parse_tree_node.rb +1 -3
  19. data/lib/rley/ptree/terminal_node.rb +1 -2
  20. data/lib/rley/ptree/token_range.rb +14 -14
  21. data/spec/rley/formatter/debug_spec.rb +65 -68
  22. data/spec/rley/formatter/json_spec.rb +69 -72
  23. data/spec/rley/parse_tree_visitor_spec.rb +5 -7
  24. data/spec/rley/parser/chart_spec.rb +0 -4
  25. data/spec/rley/parser/dotted_item_spec.rb +0 -3
  26. data/spec/rley/parser/earley_parser_spec.rb +0 -1
  27. data/spec/rley/parser/parse_state_spec.rb +0 -5
  28. data/spec/rley/parser/parsing_spec.rb +0 -3
  29. data/spec/rley/parser/state_set_spec.rb +0 -4
  30. data/spec/rley/parser/token_spec.rb +0 -4
  31. data/spec/rley/ptree/non_terminal_node_spec.rb +0 -1
  32. data/spec/rley/ptree/parse_tree_node_spec.rb +4 -4
  33. data/spec/rley/ptree/parse_tree_spec.rb +2 -3
  34. data/spec/rley/ptree/token_range_spec.rb +16 -17
  35. data/spec/rley/support/grammar_abc_helper.rb +0 -2
  36. data/spec/rley/syntax/grammar_builder_spec.rb +1 -4
  37. data/spec/rley/syntax/grammar_spec.rb +0 -9
  38. data/spec/rley/syntax/grm_symbol_spec.rb +0 -1
  39. data/spec/rley/syntax/literal_spec.rb +0 -1
  40. data/spec/rley/syntax/non_terminal_spec.rb +0 -1
  41. data/spec/rley/syntax/production_spec.rb +0 -2
  42. data/spec/rley/syntax/symbol_seq_spec.rb +0 -1
  43. data/spec/rley/syntax/terminal_spec.rb +0 -1
  44. data/spec/rley/syntax/verbatim_symbol_spec.rb +0 -1
  45. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmY4NjgxZjUxYjM0MTQ3OWIzMDA3MmU4ZjhjOWMwNDE2NTk5MzJmMw==
4
+ ODQ1OTNmNjQ5YjA1NTFkMWU2MjczMDgzYjI1OGMwYjU4MGMzOWU4Mw==
5
5
  data.tar.gz: !binary |-
6
- NzAwNjgzMTE0MjkzY2ZiNzE4MDIzYThlYjMxNjNjMjdhYzU5Y2I5NQ==
6
+ NDRhZTcyNDkxZjYxZWIwYzA4YWVlM2Q5NTNkZDAwNGM1MTI2YjdlMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDY0ZWZhOWVhZjdlYzIwZjgwMzk2ZTFmY2RjNjE4NGFjYzE3ODcwODBkOTdm
10
- MGZlY2IzYjAxN2ExN2Y2N2M5ZWQyMzc2YWZiMDc5ODEyOGQ0YzM3ZDY3ZmYw
11
- NjllY2M5YWVhYzc4NTNkNDdjYTc0MjkwNjQ5YWY5NzQ0NmJkM2Q=
9
+ ZThlM2MwMGYzYmNlZmU4MzVjM2I3YWQwNTAwYzA3MWU1NzhjMGI1MTZmYTI4
10
+ NDU5ZTg4NzVjZTBlOGViYmQxNDJhYjQyM2M3NjM3ZTZhNDFiMzU1NjZmYTdj
11
+ YjM5YjRkYWFhZGNjNmYwOTVmN2QwODM2N2IyNGExMzgzODFiNjM=
12
12
  data.tar.gz: !binary |-
13
- ZmFiMzBiZDY5N2Q5YTI2OWYzM2VkYzUwZjE4MmY1N2YzNDE4ZGI0YWU2NTRl
14
- N2E3YjcxNzBjMDQ3NjIyM2MzZWJhY2E5ZDRhOWMxMzBlYWQxYmE3M2I3NTFh
15
- ZmQyMTBhODg2NWMzNDEzZDBhNWEyNjFlZGZkMjJiZTUzYWU4MzA=
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
- # This is disabled because some demos use UTF-8
8
- AsciiComments:
9
- Enabled: false
10
-
11
- CaseIndentation:
12
- IndentWhenRelativeTo: end
13
- IndentOneStep: true
14
-
15
- # Rubocop enforces the use of is_a? instead of kind_of?
16
- # Which is contrary to modelling practice.
17
- ClassCheck:
18
- Enabled: false
19
-
20
- ClassLength:
21
- Max: 250
22
- CountComments: false
23
-
24
- ConstantName:
25
- Enabled: false
26
-
27
- CyclomaticComplexity:
28
- Enabled: false
29
-
30
- DefWithParentheses:
31
- Enabled: false
32
-
33
- Documentation:
34
- Enabled: false
35
-
36
- EmptyLines:
37
- Enabled: false
38
-
39
- EmptyLinesAroundBody:
40
- Enabled: false
41
-
42
- Encoding:
43
- Enabled: false
44
-
45
- FileName:
46
- Enabled: false
47
-
48
- IndentationWidth :
49
- Enabled: false
50
-
51
-
52
- # Avoid methods longer than 50 lines of code
53
- MethodLength:
54
- Max: 50
55
- CountComments: false
56
-
57
- NonNilCheck:
58
- Enabled: false
59
-
60
- NumericLiterals:
61
- Enabled: false
62
-
63
- RaiseArgs:
64
- Enabled: false
65
-
66
- RedundantReturn:
67
- Enabled: false
68
-
69
- SpaceInsideBrackets:
70
- Enabled: false
71
-
72
- TrailingWhitespace:
73
- Enabled: false
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
@@ -1,3 +1,7 @@
1
+ ### 0.1.09 / 2014-12-14
2
+ * [CHANGE] Source code refactored to please Rubocop (0.28.0)
3
+ * [CHANGE] File `.rubucop.yml` Disabled VariableNam style cop.
4
+
1
5
  ### 0.1.08 / 2014-12-13
2
6
  * [CHANGE] File `README.md` added coveralls badge (for the test coverage)
3
7
 
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
- desc 'Push the gem to rubygems.org'
7
- task :push do
8
- system("gem push rley-#{Rley::Version}.gem")
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
+
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Rley # Module used as a namespace
5
5
  # The version number of the gem.
6
- Version = '0.1.08'
6
+ Version = '0.1.09'
7
7
 
8
8
  # Brief description of the gem.
9
9
  Description = "Ruby implementation of the Earley's parsing algorithm"
@@ -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
- attr(:output)
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
@@ -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
- attr(:indentation)
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
@@ -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
- attr(:indentation)
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
- attr(:sibling_flags)
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
@@ -94,8 +94,6 @@ module Rley # This module is used as a namespace
94
94
  a_subscriber.send(msg, *args)
95
95
  end
96
96
  end
97
-
98
-
99
97
  end # class
100
98
  end # module
101
99
 
@@ -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
- if aNonTerminal.nullable? # Ayock-Horspool trick for nullable rules
146
- next_item = next_mapping[aState.dotted_rule]
147
- aParsing.push_state(next_item, aState.origin, aPosition)
148
- end
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