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 +4 -4
- data/CHANGELOG.md +21 -0
- data/lib/dendroid/formatters/bracket_notation.rb +1 -1
- data/lib/dendroid/grm_analysis/dotted_item.rb +4 -4
- data/lib/dendroid/lexical/literal.rb +5 -0
- data/lib/dendroid/lexical/token.rb +5 -0
- data/lib/dendroid/parsing/and_node.rb +25 -3
- data/lib/dendroid/parsing/chart_walker.rb +278 -184
- data/lib/dendroid/parsing/composite_parse_node.rb +5 -0
- data/lib/dendroid/parsing/empty_rule_node.rb +11 -1
- data/lib/dendroid/parsing/or_node.rb +22 -2
- data/lib/dendroid/parsing/parse_node.rb +17 -4
- data/lib/dendroid/parsing/parse_tree_visitor.rb +1 -1
- data/lib/dendroid/parsing/terminal_node.rb +5 -2
- data/lib/dendroid/parsing/walk_progress.rb +50 -9
- data/lib/dendroid/recognizer/e_item.rb +3 -1
- data/lib/dendroid/syntax/rule.rb +1 -1
- data/lib/dendroid.rb +0 -2
- data/spec/dendroid/lexical/literal_spec.rb +5 -1
- data/spec/dendroid/lexical/token_spec.rb +4 -0
- data/spec/dendroid/parsing/chart_walker_spec.rb +76 -84
- data/spec/dendroid/parsing/composite_parse_node_spec.rb +37 -0
- data/spec/dendroid/parsing/empty_rule_node_spec.rb +50 -0
- data/spec/dendroid/parsing/parse_node_spec.rb +25 -0
- data/spec/dendroid/parsing/terminal_node_spec.rb +4 -4
- data/spec/dendroid/parsing/walk_progress_spec.rb +61 -0
- data/version.txt +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27c301e0fa5d044507f9b3b670305852444b9dcd31592fa862fed32df0d1a46a
|
4
|
+
data.tar.gz: abd3263f035f72641bbf4f9a1219eb160be179d593487c3a4afd9a8889e479d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 [
|
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::
|
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
|
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(
|
37
|
+
def initialize(aRule, aPosition, index)
|
38
38
|
@alt_index = index
|
39
|
-
@rule = WeakRef.new(
|
39
|
+
@rule = WeakRef.new(aRule)
|
40
40
|
@position = valid_position(aPosition)
|
41
41
|
end
|
42
42
|
|
@@ -4,10 +4,18 @@ require_relative 'composite_parse_node'
|
|
4
4
|
|
5
5
|
module Dendroid
|
6
6
|
module Parsing
|
7
|
-
|
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
|
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]} #{
|
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.
|