dendroid 0.2.02 → 0.2.04

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
  SHA256:
3
- metadata.gz: bb58d7b275f7eb65ccfef37ee213fc53319c5634cf8dbd79020451c79769a3c3
4
- data.tar.gz: f075b751545df13bda67d3e2df1c3861dfdaffa8fc416a7a735d0c4fc2da01bb
3
+ metadata.gz: 27c301e0fa5d044507f9b3b670305852444b9dcd31592fa862fed32df0d1a46a
4
+ data.tar.gz: abd3263f035f72641bbf4f9a1219eb160be179d593487c3a4afd9a8889e479d6
5
5
  SHA512:
6
- metadata.gz: 1f3598bbc4f19ff183e655a92ca86908615a10b2f142982c09eb11b01b9fd05296db1ce5b9fa14be9d5f71c8358fd60535a0eb8b0feea8fcddafae5100fe8df4
7
- data.tar.gz: c3227a5e8cb2675d2de6d011091e3b665e0217e62401619db36e43967a9d407c06a50205031c03dacc43f72b01cd1b0ebf66132240194d61de1ae1e167594113
6
+ metadata.gz: 011f8688d569b73abacfd4a75c4b6dea7f1524701e4af98fad7ebd426bb3ed01e0552e4eb80a0c6d633c4c28d8805c48d6dd75879d73274f6a898cbf70f1c83c
7
+ data.tar.gz: add10309df54041eef176bb38190c86fc3bfda400148dfc784863d69a9765fee37e9491449a62b35c805fc67338825791c82429c0a4527dc6ccf782ef2921a99
data/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.2.04] - 2023-12-24
6
+ Some code refactoring.
7
+
8
+ ### Added
9
+ - File `walk_progress_spec.rb`
10
+
11
+ ### Changed
12
+ - Class `WalkProgress` refactoring & documentation
13
+ - Class `ChartWalker` refactoring & documentation
14
+
15
+ ## [0.2.03] - 2023-12-21
16
+
17
+ ### Added
18
+ - YARD documentation for the `ParseNode` hierarchy.
19
+ - Classes `Token` and `Literal` added the predicate method `literal?`
20
+
21
+ ### Changed
22
+ - Class rename: `ANDNode` became `AndNode`
23
+ - Class `ParseNode`: method rename: `ParseNode#to_s` became `ParseNode#range_to_s`
24
+ - Class `ParseNode`: attribute `range` is now of type `Range`
25
+
5
26
  ## [0.2.02] - 2023-12-18
6
27
  Code re-styling to fix most Rubocop offenses.
7
28
 
@@ -6,7 +6,7 @@ class BracketNotation < BaseFormatter
6
6
  # Method called by a ParseTreeVisitor to which the formatter subscribed.
7
7
  # Notification of a visit event: the visitor is about to visit
8
8
  # a non-terminal node
9
- # @param and_node [ANDNode]
9
+ # @param and_node [AndNode]
10
10
  def before_and_node(and_node)
11
11
  write("[#{and_node.rule.lhs.name} ")
12
12
  end
@@ -21,7 +21,7 @@ module Dendroid
21
21
  # An item with the dot not at the beginning is sometimes referred to as a kernel item
22
22
  class DottedItem
23
23
  # (Weak) reference to the production rule
24
- # @return [Dendroid::Syntax::Production]
24
+ # @return [Dendroid::Syntax::Rule]
25
25
  attr_reader :rule
26
26
 
27
27
  # @return [Integer] the dot position
@@ -31,12 +31,12 @@ module Dendroid
31
31
  attr_reader :alt_index
32
32
 
33
33
  # Constructor.
34
- # @param aChoice [Dendroid::Syntax::Rule]
34
+ # @param aRule[Dendroid::Syntax::Rule]
35
35
  # @param aPosition [Integer] Position of the dot in rhs of production.
36
36
  # @param index [Integer] the rank of the alternative at hand
37
- def initialize(aChoice, aPosition, index)
37
+ def initialize(aRule, aPosition, index)
38
38
  @alt_index = index
39
- @rule = WeakRef.new(aChoice)
39
+ @rule = WeakRef.new(aRule)
40
40
  @position = valid_position(aPosition)
41
41
  end
42
42
 
@@ -23,6 +23,11 @@ module Dendroid
23
23
  super(original, pos, symbol)
24
24
  @value = aValue
25
25
  end
26
+
27
+ # @return [Boolean] true if the token is a literal (has a value associated with is)
28
+ def literal?
29
+ true
30
+ end
26
31
  end # class
27
32
  end # module
28
33
  end # module
@@ -41,6 +41,11 @@ module Dendroid
41
41
  def pos_to_s
42
42
  position.to_s
43
43
  end
44
+
45
+ # @return [Boolean] true if the token is a literal (has a value associated with is)
46
+ def literal?
47
+ false
48
+ end
44
49
  end # class
45
50
  end # module
46
51
  end # module
@@ -4,10 +4,18 @@ require_relative 'composite_parse_node'
4
4
 
5
5
  module Dendroid
6
6
  module Parsing
7
- class ANDNode < CompositeParseNode
7
+ # A composite parse node that matches the sequence of grammar symbols from
8
+ # a right-hand side of a rule to a range of input tokens. The child nodes
9
+ # correspond to the grammar symbols in the RHS of the rule.
10
+ class AndNode < CompositeParseNode
11
+ # @return [WeakRef<Dendroid::Syntax::Rule>] Grammar rule
8
12
  attr_reader :rule
13
+
14
+ # @return [Integer] Index of the rule alternative.
9
15
  attr_reader :alt_index
10
16
 
17
+ # @param anEItem [Dendroid::Recognizer::EItem] An entry from the chart.
18
+ # @param rank [Integer] rank of the last input token matched by this node
11
19
  def initialize(anEItem, rank)
12
20
  @rule = WeakRef.new(anEItem.dotted_item.rule)
13
21
  @alt_index = anEItem.dotted_item.alt_index
@@ -15,14 +23,22 @@ module Dendroid
15
23
  super(anEItem.origin, upper_bound, rule.rhs[alt_index].size)
16
24
  end
17
25
 
26
+ # Add a child a given available position.
27
+ # @param child_node [Dendroid::Parsing::ParseNode] Node to add as a child
28
+ # @param index [Integer] position of the child node in the `children` array
18
29
  def add_child(child_node, index)
19
30
  raise StandardError unless children[index].nil? # Is slot available?
20
31
 
21
32
  super(child_node, index)
22
33
  end
23
34
 
35
+ # Is the given chart entry matching this node?
36
+ # The chart entry matches this node if:
37
+ # - its origin equals to the start of the range; and,
38
+ # - both rules are the same; and,
39
+ # @return [Boolean] true if the entry corresponds to this node.
24
40
  def match(anEItem)
25
- return false if range[0] != anEItem.origin
41
+ return false if range.begin != anEItem.origin
26
42
 
27
43
  dotted = anEItem.dotted_item
28
44
  same_rule = (rule.lhs == dotted.rule.lhs) && (alt_index == dotted.alt_index)
@@ -31,17 +47,23 @@ module Dendroid
31
47
  dotted.initial_pos? ? true : partial?
32
48
  end
33
49
 
50
+ # Is this node expecting at given RHS index, the given symbol?
51
+ # @param symbol [Dendroid::Syntax::GrmSymbol]
52
+ # @param position [Integer] index of given member in RHS of the rule
34
53
  def expecting?(symbol, position)
35
54
  symb_seq = rule.rhs[alt_index]
36
55
  symb_seq[position] == symbol
37
56
  end
38
57
 
58
+ # @return [Boolean] true if at least one of the children slots is free.
39
59
  def partial?
40
60
  children.any?(&:nil?)
41
61
  end
42
62
 
63
+ # Return a String representation of itself
64
+ # @return [String] text representation of itself
43
65
  def to_s
44
- "#{rule.lhs} => #{rule.rhs[alt_index]} #{range}"
66
+ "#{rule.lhs} => #{rule.rhs[alt_index]} #{range_to_s}"
45
67
  end
46
68
 
47
69
  # Part of the 'visitee' role in Visitor design pattern.