rley 0.5.13 → 0.5.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 457b41c7e35823bc234ddad0419bac1416494790
4
- data.tar.gz: a50f2c9df76426c56c3106b2d5ef1dd46b319a98
3
+ metadata.gz: 331a505963faf201ef03664616805ce831a591e0
4
+ data.tar.gz: 1e80b03ca806612f72fa97db13dd49b1cc55e218
5
5
  SHA512:
6
- metadata.gz: db08ac3611d797984b6b196a5de5a4b15b5507b6b4973428ab28f1271b8b609b35b920bf54a883dbeb5d24dc503bf85b6952f5d0ad9c7bae74327e5cf411f0c8
7
- data.tar.gz: 2d0b8623dd36c3f8fcfa3d2515eadae0cfc5bfd4934e0d03838b2e5a7b029ca382d6d03b3dd9565b77107b8b49ae96ca9a35e024020c26e61a949d5e1b2b3a85
6
+ metadata.gz: e070d60d75abd4beace97c65d938a7bc4e81e1c9c4bc0c4d3f0b1bba4acd13662e3196f83113bfd5def31992d2df85367dc6a3fb6ab367480e6e1d51d9d6d98d
7
+ data.tar.gz: 3816e3675513be5608d731fba3b37e9c08b41ced276403182790dcb8d38235cd88c7908b8a3540bf2c5afc87fec84e3340a1b61f9caf55fa095e9b4f6092774d
@@ -1,3 +1,9 @@
1
+ ### 0.5.14 / 2018-XX-XX
2
+ * [NEW] Files spec/rley/sppf/token_node_spec.rb` Added RSpec file for testing `SPPF::TokenNode` class.
3
+ * [CHANGE] Files `lib/rley/sppf` Minor update in the YARD documentation of the SPPF node classes.
4
+ * [FIX] Method `Parser::CSTRawNode#initialize`. Yard warning because of duplicate parameter names in documentation.
5
+ * [FIX] Method `GFG::Edge#initialize`. Yard warning because parameter names were missing in documentation.
6
+
1
7
  ### 0.5.13 / 2018-02-09
2
8
  * [CHANGE] File `examples/general/SRL/grammar.rb added names to each production rule.
3
9
  * [CHANGE] File `examples/general/SRL/ast_builder.rb Code refactoring to take profit of rule naming.
@@ -24,7 +30,7 @@
24
30
  * [CHANGE] File `examples/general/SRL/grammar.rb increased coverage of Simple Regex Language parser.
25
31
  * [CHANGE] File `examples/general/SRL/ast_builder.rb Added transformation rules for constructing regular expressions.
26
32
  * [CHANGE] File `examples/general/SRL/spac/integration_spec.rb Added tests for SRL expressions.
27
- * [FIX] Added an custom `inspect` method to sevaral core classes. This was necessary because default implementation from Ruby got lost with object graphs.
33
+ * [FIX] Added an custom `inspect` method to several core classes. This was necessary because default implementation from Ruby got lost with object graphs.
28
34
 
29
35
  ### 0.5.10 / 2017-12-02
30
36
  * [CHANGE] Dir `examples/general/SRL/ Added support for digit range to Simple Regex Language parser.
@@ -1,8 +1,10 @@
1
1
  # Purpose: define a grammar with left-recursive rule
2
2
  require 'rley' # Load Rley library
3
3
 
4
- # Instantiate a builder object that will build the grammar for us
4
+ # Instantiate a builder object that will build the grammar for us.
5
5
  builder = Rley::Syntax::GrammarBuilder.new do
6
+ # The grammar defines a language that consists in a sequence
7
+ # of 0 or more dots...
6
8
  add_terminals('DOT')
7
9
 
8
10
  # Grammar with left recursive rule.
@@ -3,9 +3,11 @@ require 'rley' # Load Rley library
3
3
 
4
4
  # Instantiate a builder object that will build the grammar for us
5
5
  builder = Rley::Syntax::GrammarBuilder.new do
6
+ # The grammar defines a language that consists in a sequence
7
+ # of 0 or more dots...
6
8
  add_terminals('DOT')
7
9
 
8
- # Grammar with left recursive rule.
10
+ # Grammar with right recursive rule.
9
11
  rule 'r_dots' => []
10
12
  rule 'r_dots' => %w[DOT r_dots]
11
13
  end
@@ -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.5.13'.freeze
6
+ Version = '0.5.14'.freeze
7
7
 
8
8
  # Brief description of the gem.
9
9
  Description = "Ruby implementation of the Earley's parsing algorithm".freeze
@@ -8,8 +8,8 @@ module Rley # This module is used as a namespace
8
8
  attr_reader :successor
9
9
 
10
10
  # Construct a directed edge between two given vertices
11
- # @param [Vertex]
12
- # @param [Vertex]
11
+ # @param thePredecessor [Vertex]
12
+ # @param theSuccessor [Vertex]
13
13
  def initialize(thePredecessor, theSuccessor)
14
14
  @successor = theSuccessor
15
15
  thePredecessor.add_edge(self)
@@ -13,7 +13,7 @@ module Rley # This module is used as a namespace
13
13
  # Structure used internally by ParseTreeBuilder class.
14
14
  CSTRawNode = Struct.new(:range, :symbol, :children) do
15
15
  # Constructor.
16
- # @param aSymbol [Lexical::TokenRange] The token position range.
16
+ # @param aRange [Lexical::TokenRange] The token position range.
17
17
  # @param aSymbol [Syntax::Symbol] A symbol from grammar.
18
18
  def initialize(aRange, aSymbol)
19
19
  super
@@ -5,16 +5,17 @@ module Rley # This module is used as a namespace
5
5
  # A node in a parse forest that is a child
6
6
  # of a parent node with :or refinement
7
7
  class AlternativeNode < CompositeNode
8
- # GFG vertex label
8
+ # @return [String] GFG vertex label
9
9
  attr_reader(:label)
10
10
 
11
- # Link to lhs symbol
11
+ # @return [Syntax::NonTerminal] Link to lhs symbol
12
12
  attr_reader(:symbol)
13
13
 
14
- # @param aVertex [ItemVertex] An GFG vertex that corresponds
15
- # a dotted item (with the dot at the end)for the alternative under
16
- # consideration.
17
- # @param aRange [TokenRange]
14
+ # @param aVertex [GFG::ItemVertex]
15
+ # A GFG vertex that corresponds to a dotted item
16
+ # with the dot at the end) for the alternative under consideration.
17
+ # @param aRange [Lexical::TokenRange]
18
+ # A range of token indices corresponding to this node.
18
19
  def initialize(aVertex, aRange)
19
20
  super(aRange)
20
21
  @label = aVertex.label
@@ -23,6 +24,7 @@ module Rley # This module is used as a namespace
23
24
 
24
25
  # Emit a (formatted) string representation of the node.
25
26
  # Mainly used for diagnosis/debugging purposes.
27
+ # @return [String]
26
28
  def to_string(indentation)
27
29
  return "Alt(#{label})#{range.to_string(indentation)}"
28
30
  end
@@ -5,18 +5,28 @@ module Rley # This module is used as a namespace
5
5
  # Abstract class. The generalization for nodes that have
6
6
  # children node(s).
7
7
  class CompositeNode < SPPFNode
8
- # Array of sub-nodes.
8
+ # @return [Array<SPFFNode>] Sub-nodes (children).
9
9
  attr_reader(:subnodes)
10
10
 
11
+ # Constructor
12
+ # @param aRange [Lexical::TokenRange]
11
13
  def initialize(aRange)
12
14
  super(aRange)
13
15
  @subnodes = []
14
16
  end
15
17
 
18
+ # Add a sub-node (child) to this one.
19
+ # @param aSubnode [SPPFNode]
16
20
  def add_subnode(aSubnode)
17
21
  subnodes.unshift(aSubnode)
18
22
  end
23
+
24
+ # @return [String] a text representation of the node.
25
+ def inspect()
26
+ key
27
+ end
19
28
 
29
+ # @return [String]
20
30
  def key()
21
31
  @key ||= to_string(0)
22
32
  end
@@ -5,7 +5,7 @@ module Rley # This module is used as a namespace
5
5
  # A leaf node in a parse forest that matches an empty
6
6
  # string from the input
7
7
  class EpsilonNode < LeafNode
8
- # aPosition is the position of the token in the input stream.
8
+ # aPosition [Integer] is the position of the token in the input stream.
9
9
  def initialize(aPosition)
10
10
  range = { low: aPosition, high: aPosition }
11
11
  super(range)
@@ -13,13 +13,10 @@ module Rley # This module is used as a namespace
13
13
 
14
14
  # Emit a (formatted) string representation of the node.
15
15
  # Mainly used for diagnosis/debugging purposes.
16
+ # @return [String]
16
17
  def to_string(indentation)
17
18
  return "_#{range.to_string(indentation)}"
18
19
  end
19
-
20
- def key()
21
- @key ||= to_string(0)
22
- end
23
20
  end # class
24
21
  end # module
25
22
  end # module
@@ -2,9 +2,18 @@ require_relative 'sppf_node'
2
2
 
3
3
  module Rley # This module is used as a namespace
4
4
  module SPPF # This module is used as a namespace
5
- # Abstract class. The generalization for nodes that don't have
5
+ # Abstract class. The generalization for SPPF nodes that don't have
6
6
  # child node.
7
7
  class LeafNode < SPPFNode
8
+ # @return [String] a text representation of the node.
9
+ def inspect()
10
+ key
11
+ end
12
+
13
+ # @return [String]
14
+ def key()
15
+ @key ||= to_string(0)
16
+ end
8
17
  end # class
9
18
  end # module
10
19
  end # module
@@ -3,21 +3,26 @@ require_relative 'composite_node'
3
3
  module Rley # This module is used as a namespace
4
4
  module SPPF # This module is used as a namespace
5
5
  # A node in a parse forest that matches exactly one
6
- # non-terminal symbol
6
+ # non-terminal symbol.
7
7
  class NonTerminalNode < CompositeNode
8
- # Link to the non-terminal symbol
8
+ # @return [Syntax::NonTerminal] Link to the non-terminal symbol
9
9
  attr_reader(:symbol)
10
10
 
11
11
  # Indication on how the sub-nodes contribute to the 'success'
12
12
  # of parent node. Possible values: :and, :or
13
13
  attr_accessor :refinement
14
14
 
15
+ # Constructor
16
+ # @param aNonTerminal [Syntax::NonTerminal]
17
+ # @param aRange [Lexical::TokenRange]
15
18
  def initialize(aNonTerminal, aRange)
16
19
  super(aRange)
17
20
  @symbol = aNonTerminal
18
21
  @refinement = :and
19
22
  end
20
23
 
24
+ # Add a sub-node (child) to this one.
25
+ # @param aSubnode [SPPFNode]
21
26
  def add_subnode(aSubnode)
22
27
  if refinement == :or
23
28
  subnodes << aSubnode
@@ -28,6 +33,7 @@ module Rley # This module is used as a namespace
28
33
 
29
34
  # Emit a (formatted) string representation of the node.
30
35
  # Mainly used for diagnosis/debugging purposes.
36
+ # @return [String] a text representation of the node.
31
37
  def to_string(indentation)
32
38
  return "#{symbol.name}#{range.to_string(indentation)}"
33
39
  end
@@ -3,18 +3,22 @@ require_relative '../lexical/token_range'
3
3
  module Rley # This module is used as a namespace
4
4
  module SPPF # This module is used as a namespace
5
5
  # Abstract class. The generalization for all kinds of nodes
6
- # occurring in a shared packed parse forest.
6
+ # occurring in a shared packed parse forest (SPPF).
7
7
  class SPPFNode
8
8
 
9
- # A range of indices for tokens matching this node.
9
+ # @return [Lexical::TokenRange]
10
+ # A range of token indices corresponding to this node.
10
11
  attr_reader(:range)
11
12
 
13
+ # Constructor
14
+ # @param aRange [Lexical::TokenRange]
12
15
  def initialize(aRange)
13
16
  @range = Lexical::TokenRange.new(aRange)
14
17
  end
15
18
 
16
- # Return the origin (= lower bound of the range
17
- # = position of first token matched by the symbol)
19
+ # Return the origin, that is, the index of the
20
+ # first token matched by this node.
21
+ # @return [Integer]
18
22
  def origin()
19
23
  return range.low
20
24
  end
@@ -2,12 +2,16 @@ require_relative 'leaf_node'
2
2
 
3
3
  module Rley # This module is used as a namespace
4
4
  module SPPF # This module is used as a namespace
5
- # A node in a parse forest that matches exactly one
6
- # token from the input
5
+ # A SPPF node that matches exactly one
6
+ # token from the input.
7
7
  class TokenNode < LeafNode
8
+ # @return [Lexical::Token]
9
+ # The input token that is represented by this parse node.
8
10
  attr_reader(:token)
9
11
 
10
- # aPosition is the position of the token in the input stream.
12
+ # Constructor
13
+ # @param aToken [Lexical::Token] input token represented by this node.
14
+ # @param aPosition [Integer] index of the token in the input stream.
11
15
  def initialize(aToken, aPosition)
12
16
  range = { low: aPosition, high: aPosition + 1 }
13
17
  super(range)
@@ -16,13 +20,11 @@ module Rley # This module is used as a namespace
16
20
 
17
21
  # Emit a (formatted) string representation of the node.
18
22
  # Mainly used for diagnosis/debugging purposes.
23
+ # @param indentation [Integer]
24
+ # @return [String]
19
25
  def to_string(indentation)
20
26
  return "#{token.terminal.name}#{range.to_string(indentation)}"
21
27
  end
22
-
23
- def key()
24
- @key ||= to_string(0)
25
- end
26
28
  end # class
27
29
  end # module
28
30
  end # module
@@ -0,0 +1,46 @@
1
+ require 'ostruct'
2
+ require_relative '../../spec_helper'
3
+
4
+ require_relative '../../../lib/rley/syntax/terminal'
5
+ require_relative '../../../lib/rley/lexical/token_range'
6
+ require_relative '../../../lib/rley/lexical/token'
7
+
8
+ # Load the class under test
9
+ require_relative '../../../lib/rley/sppf/token_node'
10
+
11
+ module Rley # Open this namespace to avoid module qualifier prefixes
12
+ module SPPF # Open this namespace to avoid module qualifier prefixes
13
+ describe TokenNode do
14
+ let(:sample_symbol) { Syntax::Terminal.new('Noun') }
15
+ let(:sample_token) { Lexical::Token.new('language', sample_symbol) }
16
+ let(:sample_position) { 3 }
17
+
18
+ subject { TokenNode.new(sample_token, sample_position) }
19
+
20
+ context 'Initialization:' do
21
+ it 'should know its token' do
22
+ expect(subject.token).to eq(sample_token)
23
+ end
24
+
25
+ it 'should know its token range' do
26
+ expect(subject.origin).to eq(sample_position)
27
+ expect(subject.range.low).to eq(sample_position)
28
+ expect(subject.range.high).to eq(sample_position + 1)
29
+ end
30
+ end # context
31
+
32
+ context 'Provided services:' do
33
+ it 'should know its string representation' do
34
+ expect(subject.to_string(0)).to eq('Noun[3, 4]')
35
+ expect(subject.inspect).to eq('Noun[3, 4]')
36
+ end
37
+
38
+ it 'should return a key value of itself' do
39
+ expect(subject.key).to eq('Noun[3, 4]')
40
+ end
41
+ end # context
42
+ end # describe
43
+ end # module
44
+ end # module
45
+
46
+ # End of file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.13
4
+ version: 0.5.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
@@ -304,6 +304,7 @@ files:
304
304
  - spec/rley/ptree/terminal_node_spec.rb
305
305
  - spec/rley/sppf/alternative_node_spec.rb
306
306
  - spec/rley/sppf/non_terminal_node_spec.rb
307
+ - spec/rley/sppf/token_node_spec.rb
307
308
  - spec/rley/support/ambiguous_grammar_helper.rb
308
309
  - spec/rley/support/expectation_helper.rb
309
310
  - spec/rley/support/grammar_abc_helper.rb
@@ -398,6 +399,7 @@ test_files:
398
399
  - spec/rley/ptree/terminal_node_spec.rb
399
400
  - spec/rley/sppf/alternative_node_spec.rb
400
401
  - spec/rley/sppf/non_terminal_node_spec.rb
402
+ - spec/rley/sppf/token_node_spec.rb
401
403
  - spec/rley/syntax/grammar_builder_spec.rb
402
404
  - spec/rley/syntax/grammar_spec.rb
403
405
  - spec/rley/syntax/grm_symbol_spec.rb