rley 0.6.00 → 0.6.01
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/.rubocop.yml +8 -1
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -1
- data/examples/NLP/benchmark_pico_en.rb +6 -10
- data/examples/NLP/nano_eng/nano_en_demo.rb +2 -2
- data/examples/NLP/nano_eng/nano_grammar.rb +1 -2
- data/examples/data_formats/JSON/json_ast_builder.rb +8 -8
- data/examples/general/SRL/lib/ast_builder.rb +74 -72
- data/examples/general/SRL/lib/grammar.rb +2 -2
- data/examples/general/SRL/lib/regex/abstract_method.rb +28 -28
- data/examples/general/SRL/lib/regex/alternation.rb +21 -25
- data/examples/general/SRL/lib/regex/anchor.rb +6 -9
- data/examples/general/SRL/lib/regex/atomic_expression.rb +10 -15
- data/examples/general/SRL/lib/regex/capturing_group.rb +15 -14
- data/examples/general/SRL/lib/regex/char_class.rb +10 -13
- data/examples/general/SRL/lib/regex/char_range.rb +45 -46
- data/examples/general/SRL/lib/regex/char_shorthand.rb +8 -9
- data/examples/general/SRL/lib/regex/character.rb +196 -191
- data/examples/general/SRL/lib/regex/compound_expression.rb +47 -50
- data/examples/general/SRL/lib/regex/concatenation.rb +23 -27
- data/examples/general/SRL/lib/regex/expression.rb +53 -56
- data/examples/general/SRL/lib/regex/lookaround.rb +23 -20
- data/examples/general/SRL/lib/regex/match_option.rb +26 -28
- data/examples/general/SRL/lib/regex/monadic_expression.rb +20 -23
- data/examples/general/SRL/lib/regex/multiplicity.rb +17 -20
- data/examples/general/SRL/lib/regex/non_capturing_group.rb +9 -12
- data/examples/general/SRL/lib/regex/polyadic_expression.rb +51 -55
- data/examples/general/SRL/lib/regex/quantifiable.rb +14 -20
- data/examples/general/SRL/lib/regex/repetition.rb +20 -23
- data/examples/general/SRL/lib/regex/wildcard.rb +15 -19
- data/examples/general/SRL/lib/regex_repr.rb +1 -1
- data/examples/general/SRL/lib/tokenizer.rb +2 -2
- data/examples/general/SRL/spec/integration_spec.rb +17 -12
- data/examples/general/SRL/spec/regex/character_spec.rb +160 -153
- data/examples/general/SRL/spec/regex/multiplicity_spec.rb +27 -31
- data/examples/general/SRL/spec/spec_helper.rb +1 -1
- data/examples/general/SRL/spec/tokenizer_spec.rb +25 -27
- data/examples/general/calc_iter1/calc_ast_builder.rb +10 -10
- data/examples/general/calc_iter2/calc_ast_builder.rb +7 -9
- data/examples/general/calc_iter2/calc_ast_nodes.rb +5 -6
- data/examples/general/calc_iter2/calc_lexer.rb +3 -5
- data/examples/general/calc_iter2/spec/calculator_spec.rb +16 -14
- data/examples/general/left.rb +8 -8
- data/examples/general/right.rb +8 -8
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/engine.rb +16 -20
- data/lib/rley/formatter/json.rb +1 -1
- data/lib/rley/gfg/grm_flow_graph.rb +1 -1
- data/lib/rley/gfg/item_vertex.rb +6 -5
- data/lib/rley/gfg/vertex.rb +3 -3
- data/lib/rley/lexical/token.rb +4 -3
- data/lib/rley/parse_rep/ast_base_builder.rb +4 -3
- data/lib/rley/parse_rep/parse_rep_creator.rb +1 -1
- data/lib/rley/parse_rep/parse_tree_builder.rb +3 -2
- data/lib/rley/parser/error_reason.rb +1 -1
- data/lib/rley/parser/gfg_chart.rb +6 -6
- data/lib/rley/parser/gfg_parsing.rb +19 -19
- data/lib/rley/parser/parse_entry.rb +3 -3
- data/lib/rley/parser/parse_entry_set.rb +1 -1
- data/lib/rley/parser/parse_walker_factory.rb +15 -15
- data/lib/rley/syntax/grammar.rb +1 -1
- data/lib/rley/syntax/grammar_builder.rb +2 -2
- data/lib/rley/syntax/production.rb +4 -3
- data/lib/rley/syntax/symbol_seq.rb +2 -2
- data/spec/rley/base/grm_items_builder_spec.rb +1 -1
- data/spec/rley/engine_spec.rb +3 -6
- data/spec/rley/formatter/asciitree_spec.rb +0 -1
- data/spec/rley/formatter/bracket_notation_spec.rb +0 -1
- data/spec/rley/formatter/debug_spec.rb +2 -3
- data/spec/rley/gfg/grm_flow_graph_spec.rb +19 -19
- data/spec/rley/parse_rep/ast_builder_spec.rb +12 -12
- data/spec/rley/parser/gfg_earley_parser_spec.rb +1 -1
- data/spec/rley/parser/parse_entry_set_spec.rb +5 -5
- data/spec/rley/parser/parse_state_spec.rb +8 -3
- data/spec/rley/parser/parse_tracer_spec.rb +3 -1
- data/spec/rley/parser/parse_walker_factory_spec.rb +1 -1
- data/spec/rley/ptree/parse_tree_node_spec.rb +1 -1
- data/spec/rley/syntax/grammar_builder_spec.rb +1 -1
- data/spec/rley/syntax/grammar_spec.rb +1 -1
- metadata +2 -3
- data/spec/rley/support/ast_builder.rb +0 -403
@@ -1,33 +1,29 @@
|
|
1
1
|
# File: concatenation.rb
|
2
2
|
|
3
|
-
require_relative 'polyadic_expression'
|
3
|
+
require_relative 'polyadic_expression' # Access the superclass
|
4
4
|
|
5
5
|
module Regex # This module is used as a namespace
|
6
|
-
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end # class
|
30
|
-
|
6
|
+
# Abstract class. A n-ary matching operator.
|
7
|
+
# It succeeds when each child succeeds to match the subject text in the same
|
8
|
+
# serial arrangement than defined by this concatenation.
|
9
|
+
class Concatenation < PolyadicExpression
|
10
|
+
# Constructor.
|
11
|
+
def initialize(*theChildren)
|
12
|
+
super(theChildren)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
# Conversion method re-definition.
|
18
|
+
# Purpose: Return the String representation of the concatented expressions.
|
19
|
+
def text_repr()
|
20
|
+
outcome = children.inject('') do |result, aChild|
|
21
|
+
result << aChild.to_str
|
22
|
+
end
|
23
|
+
|
24
|
+
return outcome
|
25
|
+
end
|
26
|
+
end # class
|
31
27
|
end # module
|
32
28
|
|
33
|
-
# End of file
|
29
|
+
# End of file
|
@@ -3,61 +3,58 @@
|
|
3
3
|
require_relative 'abstract_method'
|
4
4
|
|
5
5
|
module Regex # This module is used as a namespace
|
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
|
-
end # class
|
60
|
-
|
6
|
+
# Abstract class. The generalization of any valid regular (sub)expression.
|
7
|
+
class Expression
|
8
|
+
attr_accessor :begin_anchor
|
9
|
+
attr_accessor :end_anchor
|
10
|
+
|
11
|
+
# Constructor
|
12
|
+
def initialize(); end
|
13
|
+
|
14
|
+
# Abstract method. Return true iff the expression is atomic
|
15
|
+
# (= may not have any child).
|
16
|
+
def atomic?()
|
17
|
+
abstract_method
|
18
|
+
end
|
19
|
+
|
20
|
+
# Abstract method. Return the number of values that match this expression.
|
21
|
+
# [_parent_options] an Hash of matching options. They are overridden
|
22
|
+
# by options with same name that are bound to this object.
|
23
|
+
def cardinality(_parent_options)
|
24
|
+
abstract_method
|
25
|
+
end
|
26
|
+
|
27
|
+
# Determine the matching options to apply to this object, given the options
|
28
|
+
# coming from the parent
|
29
|
+
# and options that are local to this object. Local options take precedence.
|
30
|
+
# @param theParentOptions [Hash] matching options. They are overridden
|
31
|
+
# by options with same name that are bound to this object.
|
32
|
+
def options(theParentOptions)
|
33
|
+
resulting_options = theParentOptions.merge(@local_options)
|
34
|
+
return resulting_options
|
35
|
+
end
|
36
|
+
|
37
|
+
# Template method.
|
38
|
+
# Purpose: Return the String representation of the expression.
|
39
|
+
def to_str()
|
40
|
+
result = ''
|
41
|
+
result << prefix
|
42
|
+
result << text_repr
|
43
|
+
result << suffix
|
44
|
+
|
45
|
+
return result
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def prefix()
|
51
|
+
begin_anchor ? begin_anchor.to_str : ''
|
52
|
+
end
|
53
|
+
|
54
|
+
def suffix()
|
55
|
+
end_anchor ? end_anchor.to_str : ''
|
56
|
+
end
|
57
|
+
end # class
|
61
58
|
end # module
|
62
59
|
|
63
|
-
# End of file
|
60
|
+
# End of file
|
@@ -1,47 +1,50 @@
|
|
1
1
|
# File: Lookaround.rb
|
2
2
|
|
3
3
|
########################
|
4
|
-
# TODO: make it a binary expression
|
4
|
+
# TODO: make it a binary expression
|
5
5
|
########################
|
6
6
|
|
7
7
|
|
8
|
-
require_relative 'polyadic_expression'
|
8
|
+
require_relative 'polyadic_expression' # Access the superclass
|
9
9
|
|
10
10
|
module Regex # This module is used as a namespace
|
11
|
-
# Lookaround is a zero-width assertion just like the start and end of line
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
11
|
+
# Lookaround is a zero-width assertion just like the start and end of line
|
12
|
+
# anchors.
|
13
|
+
# The difference is that lookarounds will actually match characters, but only
|
14
|
+
# return the result of the match: match or no match.
|
15
|
+
# That is why they are called "assertions". They do not consume characters
|
16
|
+
# from the subject, but only assert whether a match is possible or not.
|
15
17
|
class Lookaround < PolyadicExpression
|
16
|
-
# The "direction" of the lookaround. Can be ahead or behind. It specifies
|
17
|
-
#
|
18
|
+
# The "direction" of the lookaround. Can be ahead or behind. It specifies
|
19
|
+
# the relative position of the expression to match compared to
|
20
|
+
# the current 'position' in the subject text.
|
18
21
|
attr_reader(:dir)
|
19
|
-
|
20
|
-
# The kind indicates whether the assertion is positive
|
22
|
+
|
23
|
+
# The kind indicates whether the assertion is positive
|
24
|
+
# (succeeds when there is a match) or negative
|
21
25
|
# (assertion succeeds when there is NO match).
|
22
26
|
attr_reader(:kind)
|
23
|
-
|
27
|
+
|
24
28
|
# Constructor.
|
25
|
-
# [assertedExpression]
|
26
|
-
# [theDir]
|
29
|
+
# [assertedExpression] A sub-expression to match.
|
30
|
+
# [theDir] One of the following values: [ :ahead, :behind ]
|
27
31
|
# [theKind] One of the following values: [ :positive, :negative ]
|
28
32
|
def initialize(assertedExpression, theDir, theKind)
|
29
33
|
super([assertedExpression])
|
30
|
-
@dir
|
34
|
+
@dir = theDir
|
35
|
+
@kind = theKind
|
31
36
|
end
|
32
|
-
|
33
|
-
public
|
37
|
+
|
34
38
|
# Conversion method re-definition.
|
35
39
|
# Purpose: Return the String representation of the captured expression.
|
36
40
|
def to_str()
|
37
41
|
result = children[0].to_str
|
38
42
|
dir_syntax = (dir == :ahead) ? '' : '<'
|
39
|
-
kind_syntax = (kind == :positive)? '=' : '!'
|
40
|
-
result << '(?' + dir_syntax + kind_syntax + children[1].to_str +
|
43
|
+
kind_syntax = (kind == :positive) ? '=' : '!'
|
44
|
+
result << '(?' + dir_syntax + kind_syntax + children[1].to_str + ')'
|
41
45
|
return result
|
42
46
|
end
|
43
|
-
|
44
47
|
end # class
|
45
48
|
end # module
|
46
49
|
|
47
|
-
# End of file
|
50
|
+
# End of file
|
@@ -1,36 +1,34 @@
|
|
1
1
|
# File: MatchOption.rb
|
2
2
|
|
3
3
|
module Regex # This module is used as a namespace
|
4
|
+
# Represents an option that influences the way a regular (sub)expression
|
5
|
+
# can perform its matching.
|
6
|
+
class MatchOption
|
7
|
+
# The symbolic name of the option
|
8
|
+
attr_reader(:name)
|
4
9
|
|
5
|
-
#
|
6
|
-
|
7
|
-
# The symbolic name of the option
|
8
|
-
attr_reader(:name)
|
9
|
-
|
10
|
-
# An indicator that tells whether the option is turned on or off
|
11
|
-
attr_reader(:setting)
|
12
|
-
|
13
|
-
# Constructor.
|
14
|
-
def initialize(theName, theSetting)
|
15
|
-
@name, @setting = theName, theSetting
|
16
|
-
end
|
17
|
-
|
18
|
-
public
|
19
|
-
# Equality operator
|
20
|
-
def ==(another)
|
21
|
-
return true if self.object_id == another.object_id
|
22
|
-
|
23
|
-
if another.kind_of?(MatchOption)
|
24
|
-
isEqual = ((name == another.name) && (setting == another.setting))
|
25
|
-
else
|
26
|
-
isEqual = false
|
27
|
-
end
|
28
|
-
|
29
|
-
return isEqual
|
30
|
-
end
|
10
|
+
# An indicator that tells whether the option is turned on or off
|
11
|
+
attr_reader(:setting)
|
31
12
|
|
32
|
-
|
13
|
+
# Constructor.
|
14
|
+
def initialize(theName, theSetting)
|
15
|
+
@name = theName
|
16
|
+
@setting = theSetting
|
17
|
+
end
|
18
|
+
|
19
|
+
# Equality operator
|
20
|
+
def ==(other)
|
21
|
+
return true if object_id == other.object_id
|
33
22
|
|
23
|
+
if other.kind_of?(MatchOption)
|
24
|
+
isEqual = ((name == other.name) && (setting == other.setting))
|
25
|
+
else
|
26
|
+
isEqual = false
|
27
|
+
end
|
28
|
+
|
29
|
+
return isEqual
|
30
|
+
end
|
31
|
+
end # class
|
34
32
|
end # module
|
35
33
|
|
36
|
-
# End of file
|
34
|
+
# End of file
|
@@ -1,31 +1,28 @@
|
|
1
1
|
# File: monadic_expression.rb
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative 'compound_expression' # Access the superclass
|
4
4
|
|
5
5
|
module Regex # This module is used as a namespace
|
6
|
+
# Abstract class. An element that is part of a regular expression &
|
7
|
+
# that can have up to one child sub-expression.
|
8
|
+
class MonadicExpression < CompoundExpression
|
9
|
+
# The (optional) child sub-expression
|
10
|
+
attr_reader(:child)
|
6
11
|
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# Constructor.
|
14
|
-
def initialize(theChild)
|
15
|
-
super()
|
16
|
-
@child = theChild
|
17
|
-
end
|
18
|
-
|
19
|
-
protected
|
20
|
-
# Return the text representation of the child (if any)
|
21
|
-
def all_child_text()
|
22
|
-
result = child.nil? ? '' : child.to_str()
|
23
|
-
|
24
|
-
return result
|
25
|
-
end
|
12
|
+
# Constructor.
|
13
|
+
def initialize(theChild)
|
14
|
+
super()
|
15
|
+
@child = theChild
|
16
|
+
end
|
26
17
|
|
27
|
-
|
18
|
+
protected
|
19
|
+
|
20
|
+
# Return the text representation of the child (if any)
|
21
|
+
def all_child_text()
|
22
|
+
result = child.nil? ? '' : child.to_str
|
28
23
|
|
24
|
+
return result
|
25
|
+
end
|
26
|
+
end # class
|
29
27
|
end # module
|
30
|
-
|
31
|
-
# End of file
|
28
|
+
# End of file
|
@@ -6,13 +6,13 @@ module SRL
|
|
6
6
|
class Multiplicity
|
7
7
|
# The lowest acceptable repetition count
|
8
8
|
attr_reader(:lower_bound)
|
9
|
-
|
9
|
+
|
10
10
|
# The highest possible repetition count
|
11
11
|
attr_reader(:upper_bound)
|
12
12
|
|
13
13
|
# An indicator that specifies how to repeat (:greedy, :lazy, :possessive)
|
14
14
|
attr_reader(:policy)
|
15
|
-
|
15
|
+
|
16
16
|
# @param aLowerBound [Integer]
|
17
17
|
# @param anUpperBound [Integer, Symbol] integer or :more symbol
|
18
18
|
# @param aPolicy [Symbol] One of: (:greedy, :lazy, :possessive)
|
@@ -21,8 +21,7 @@ module SRL
|
|
21
21
|
@upper_bound = valid_upper_bound(anUpperBound)
|
22
22
|
@policy = valid_policy(aPolicy)
|
23
23
|
end
|
24
|
-
|
25
|
-
public
|
24
|
+
|
26
25
|
# Purpose: Return the String representation of the multiplicity.
|
27
26
|
def to_str()
|
28
27
|
case upper_bound
|
@@ -35,7 +34,7 @@ module SRL
|
|
35
34
|
else
|
36
35
|
subresult = "{#{lower_bound},}"
|
37
36
|
end
|
38
|
-
|
37
|
+
|
39
38
|
when lower_bound
|
40
39
|
subresult = "{#{lower_bound}}"
|
41
40
|
else
|
@@ -45,7 +44,7 @@ module SRL
|
|
45
44
|
subresult = "{#{lower_bound},#{upper_bound}}"
|
46
45
|
end
|
47
46
|
end
|
48
|
-
|
47
|
+
|
49
48
|
suffix = case policy
|
50
49
|
when :greedy
|
51
50
|
''
|
@@ -54,41 +53,39 @@ module SRL
|
|
54
53
|
when :possessive
|
55
54
|
'+'
|
56
55
|
end
|
57
|
-
|
56
|
+
|
58
57
|
return subresult + suffix
|
59
58
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
|
60
|
+
private
|
61
|
+
|
63
62
|
# Validation method. Return the validated lower bound value
|
64
63
|
def valid_lower_bound(aLowerBound)
|
65
64
|
err_msg = "Invalid lower bound of repetition count #{aLowerBound}"
|
66
|
-
raise StandardError, err_msg unless aLowerBound.kind_of?(Integer)
|
65
|
+
raise StandardError, err_msg unless aLowerBound.kind_of?(Integer)
|
67
66
|
return aLowerBound
|
68
67
|
end
|
69
|
-
|
68
|
+
|
70
69
|
# Validation method. Return the validated lower bound value
|
71
70
|
def valid_upper_bound(anUpperBound)
|
72
71
|
err_msg = "Invalid upper bound of repetition count #{anUpperBound}"
|
73
|
-
unless anUpperBound.kind_of?(Integer) || (anUpperBound == :more)
|
72
|
+
unless anUpperBound.kind_of?(Integer) || (anUpperBound == :more)
|
74
73
|
raise StandardError, err_msg
|
75
74
|
end
|
76
|
-
|
75
|
+
|
77
76
|
return anUpperBound
|
78
|
-
end
|
79
|
-
|
77
|
+
end
|
78
|
+
|
80
79
|
# Validation method. Return the validated policy value.
|
81
80
|
def valid_policy(aPolicy)
|
82
81
|
err_msg = "Invalid repetition policy '#{aPolicy}'."
|
83
|
-
valid_policies = [
|
82
|
+
valid_policies = %i[greedy lazy possessive]
|
84
83
|
raise StandardError, err_msg unless valid_policies.include? aPolicy
|
85
84
|
|
86
85
|
return aPolicy
|
87
86
|
end
|
88
|
-
|
89
87
|
end # class
|
90
|
-
|
91
88
|
end # module
|
92
89
|
end # module
|
93
90
|
|
94
|
-
# End of file
|
91
|
+
# End of file
|