srl_ruby 0.4.5 → 0.4.9
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 +5 -5
- data/.rubocop.yml +298 -23
- data/CHANGELOG.md +41 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/Rakefile +3 -0
- data/appveyor.yml +14 -12
- data/bin/srl2ruby +13 -9
- data/bin/srl2ruby_cli_parser.rb +3 -3
- data/features/lib/step_definitions/srl_testing_steps.rb +2 -0
- data/features/lib/support/env..rb +2 -0
- data/lib/regex/abstract_method.rb +2 -0
- data/lib/regex/alternation.rb +3 -3
- data/lib/regex/anchor.rb +3 -0
- data/lib/regex/atomic_expression.rb +2 -0
- data/lib/regex/capturing_group.rb +8 -3
- data/lib/regex/char_class.rb +4 -2
- data/lib/regex/char_range.rb +3 -3
- data/lib/regex/char_shorthand.rb +3 -0
- data/lib/regex/character.rb +5 -2
- data/lib/regex/compound_expression.rb +2 -0
- data/lib/regex/concatenation.rb +3 -1
- data/lib/regex/expression.rb +6 -1
- data/lib/regex/lookaround.rb +3 -1
- data/lib/regex/match_option.rb +2 -0
- data/lib/regex/monadic_expression.rb +2 -0
- data/lib/regex/multiplicity.rb +8 -9
- data/lib/regex/non_capturing_group.rb +3 -1
- data/lib/regex/polyadic_expression.rb +2 -0
- data/lib/regex/quantifiable.rb +3 -1
- data/lib/regex/raw_expression.rb +2 -0
- data/lib/regex/repetition.rb +2 -0
- data/lib/regex/wildcard.rb +2 -5
- data/lib/srl_ruby/ast_builder.rb +81 -121
- data/lib/srl_ruby/grammar.rb +80 -92
- data/lib/srl_ruby/regex_repr.rb +2 -0
- data/lib/srl_ruby/tokenizer.rb +10 -4
- data/lib/srl_ruby/version.rb +3 -1
- data/lib/srl_ruby.rb +2 -0
- data/spec/acceptance/srl_test_suite_spec.rb +2 -0
- data/spec/acceptance/support/rule_file_ast_builder.rb +2 -0
- data/spec/acceptance/support/rule_file_grammar.rb +7 -5
- data/spec/acceptance/support/rule_file_nodes.rb +2 -0
- data/spec/acceptance/support/rule_file_parser.rb +2 -0
- data/spec/acceptance/support/rule_file_tokenizer.rb +10 -3
- data/spec/regex/atomic_expression_spec.rb +2 -0
- data/spec/regex/character_spec.rb +16 -6
- data/spec/regex/match_option_spec.rb +2 -0
- data/spec/regex/monadic_expression_spec.rb +2 -0
- data/spec/regex/multiplicity_spec.rb +4 -0
- data/spec/regex/repetition_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/srl_ruby/srl_ruby_spec.rb +2 -0
- data/spec/srl_ruby/tokenizer_spec.rb +2 -0
- data/spec/srl_ruby_spec.rb +8 -6
- data/srl_ruby.gemspec +6 -4
- metadata +13 -14
data/lib/regex/anchor.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: anchor.rb
|
2
4
|
|
3
5
|
require_relative 'atomic_expression' # Access the superclass
|
@@ -24,6 +26,7 @@ module Regex # This module is used as a namespace
|
|
24
26
|
# Constructor
|
25
27
|
# @param aKind [String] Lexeme representation of the anchor
|
26
28
|
def initialize(aKind)
|
29
|
+
super()
|
27
30
|
@kind = valid_kind(aKind)
|
28
31
|
end
|
29
32
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: capturing_group.rb
|
2
4
|
|
3
5
|
require_relative 'monadic_expression' # Access the superclass
|
@@ -6,6 +8,8 @@ module Regex # This module is used as a namespace
|
|
6
8
|
# An association between a capture variable and an expression
|
7
9
|
# the subject text in the same serial arrangement
|
8
10
|
class CapturingGroup < MonadicExpression
|
11
|
+
# rubocop: disable Style/OptionalBooleanParameter
|
12
|
+
|
9
13
|
# The capture variable id. It is a Fixnum when the capture group gets
|
10
14
|
# a sequence number,
|
11
15
|
# a String when it is an user-defined name
|
@@ -40,12 +44,13 @@ module Regex # This module is used as a namespace
|
|
40
44
|
atomic = no_backtrack ? '?>' : ''
|
41
45
|
if child.is_a?(Regex::NonCapturingGroup)
|
42
46
|
# Minor optimization
|
43
|
-
|
47
|
+
suffix = child.child.to_str
|
44
48
|
else
|
45
|
-
|
49
|
+
suffix = child.to_str
|
46
50
|
end
|
47
|
-
|
51
|
+
"(#{atomic}#{prefix}#{suffix})"
|
48
52
|
end
|
53
|
+
# rubocop: enable Style/OptionalBooleanParameter
|
49
54
|
end # class
|
50
55
|
end # module
|
51
56
|
|
data/lib/regex/char_class.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: char_class.rb
|
2
4
|
|
3
5
|
require_relative 'polyadic_expression' # Access the superclass
|
@@ -22,13 +24,13 @@ module Regex # This module is used as a namespace
|
|
22
24
|
# Conversion method re-definition.
|
23
25
|
# Purpose: Return the String representation of the character class.
|
24
26
|
def text_repr
|
25
|
-
result_children = children.inject('') do |sub_result, child|
|
27
|
+
result_children = children.inject(+'') do |sub_result, child|
|
26
28
|
if child.kind_of?(Regex::Character) && Metachars.include?(child.codepoint)
|
27
29
|
sub_result << '\\' # Escape meta-character...
|
28
30
|
end
|
29
31
|
sub_result << child.to_str
|
30
32
|
end
|
31
|
-
result =
|
33
|
+
result = "[#{negated ? '^' : ''}#{result_children}]"
|
32
34
|
|
33
35
|
return result
|
34
36
|
end
|
data/lib/regex/char_range.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: char_range.rb
|
2
4
|
|
3
5
|
require_relative 'polyadic_expression' # Access the superclass
|
@@ -32,9 +34,7 @@ module Regex # This module is used as a namespace
|
|
32
34
|
# Conversion method re-definition.
|
33
35
|
# Purpose: Return the String representation of the concatented expressions.
|
34
36
|
def text_repr
|
35
|
-
|
36
|
-
|
37
|
-
return result
|
37
|
+
"#{lower.to_str}-#{upper.to_str}"
|
38
38
|
end
|
39
39
|
|
40
40
|
private
|
data/lib/regex/char_shorthand.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: char_shorthand.rb
|
2
4
|
|
3
5
|
require_relative 'atomic_expression' # Access the superclass
|
@@ -24,6 +26,7 @@ module Regex # This module is used as a namespace
|
|
24
26
|
|
25
27
|
# Constructor
|
26
28
|
def initialize(aShortname)
|
29
|
+
super()
|
27
30
|
@shortname = valid_shortname(aShortname)
|
28
31
|
end
|
29
32
|
|
data/lib/regex/character.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: character.rb
|
2
4
|
|
3
5
|
require_relative 'atomic_expression' # Access the superclass
|
@@ -25,8 +27,8 @@ module Regex # This module is used as a namespace
|
|
25
27
|
'\7' => 7
|
26
28
|
}.freeze
|
27
29
|
|
28
|
-
MetaChars = '\^$.|+?*()[]{}'
|
29
|
-
MetaCharsInClass = '\^[]-'
|
30
|
+
MetaChars = '\^$.|+?*()[]{}'
|
31
|
+
MetaCharsInClass = '\^[]-' # Characters with special meaning in char. class
|
30
32
|
|
31
33
|
# The integer value that uniquely identifies the character.
|
32
34
|
attr_reader(:codepoint)
|
@@ -57,6 +59,7 @@ module Regex # This module is used as a namespace
|
|
57
59
|
# RegAn::Character.new('\n') # Represents a newline
|
58
60
|
# RegAn::Character.new('\u03a3') # Represents a Σ
|
59
61
|
def initialize(aValue)
|
62
|
+
super()
|
60
63
|
case aValue
|
61
64
|
when String
|
62
65
|
if aValue.size == 1
|
data/lib/regex/concatenation.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: concatenation.rb
|
2
4
|
|
3
5
|
require_relative 'polyadic_expression' # Access the superclass
|
@@ -17,7 +19,7 @@ module Regex # This module is used as a namespace
|
|
17
19
|
# Conversion method re-definition.
|
18
20
|
# Purpose: Return the String representation of the concatented expressions.
|
19
21
|
def text_repr
|
20
|
-
outcome = children.inject('') do |result, child|
|
22
|
+
outcome = children.inject(+'') do |result, child|
|
21
23
|
result << child.to_str
|
22
24
|
end
|
23
25
|
|
data/lib/regex/expression.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: expression.rb
|
2
4
|
|
3
5
|
require_relative 'abstract_method'
|
@@ -5,7 +7,10 @@ require_relative 'abstract_method'
|
|
5
7
|
module Regex # This module is used as a namespace
|
6
8
|
# Abstract class. The generalization of any valid regular (sub)expression.
|
7
9
|
class Expression
|
10
|
+
# @return [NilClass, Anchor]
|
8
11
|
attr_accessor :begin_anchor
|
12
|
+
|
13
|
+
# @return [NilClass, Anchor]
|
9
14
|
attr_accessor :end_anchor
|
10
15
|
|
11
16
|
# Constructor
|
@@ -31,7 +36,7 @@ module Regex # This module is used as a namespace
|
|
31
36
|
# Template method.
|
32
37
|
# @return [String] text representation of the expression.
|
33
38
|
def to_str
|
34
|
-
result = ''
|
39
|
+
result = +''
|
35
40
|
result << prefix
|
36
41
|
result << text_repr
|
37
42
|
result << suffix
|
data/lib/regex/lookaround.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: Lookaround.rb
|
2
4
|
|
3
5
|
########################
|
@@ -40,7 +42,7 @@ module Regex # This module is used as a namespace
|
|
40
42
|
def to_str
|
41
43
|
dir_syntax = (dir == :ahead) ? '' : '<'
|
42
44
|
kind_syntax = (kind == :positive) ? '=' : '!'
|
43
|
-
result =
|
45
|
+
result = "(?#{dir_syntax}#{kind_syntax}#{child.to_str})"
|
44
46
|
return result
|
45
47
|
end
|
46
48
|
end # class
|
data/lib/regex/match_option.rb
CHANGED
data/lib/regex/multiplicity.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: Multiplicity.rb
|
2
4
|
|
3
5
|
module Regex # This module is used as a namespace
|
@@ -48,16 +50,13 @@ module Regex # This module is used as a namespace
|
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
when :possessive
|
57
|
-
'+'
|
58
|
-
end
|
53
|
+
policy2suffix = {
|
54
|
+
greedy: '',
|
55
|
+
lazy: '?',
|
56
|
+
possessive: '+'
|
57
|
+
}
|
59
58
|
|
60
|
-
return subresult +
|
59
|
+
return subresult + policy2suffix[policy]
|
61
60
|
end
|
62
61
|
|
63
62
|
private
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: non_capturing_group.rb
|
2
4
|
|
3
5
|
require_relative 'monadic_expression' # Access the superclass
|
@@ -20,7 +22,7 @@ module Regex # This module is used as a namespace
|
|
20
22
|
# Conversion method re-definition.
|
21
23
|
# Purpose: Return the String representation of the captured expression.
|
22
24
|
def text_repr
|
23
|
-
result =
|
25
|
+
result = "(?:#{all_child_text})"
|
24
26
|
return result
|
25
27
|
end
|
26
28
|
end # class
|
data/lib/regex/quantifiable.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: quantifiable.rb
|
2
4
|
|
3
5
|
require_relative 'multiplicity'
|
@@ -6,7 +8,7 @@ module Regex # This module is used as a namespace
|
|
6
8
|
module Quantifiable
|
7
9
|
# Redefined method. Return true since it may not have any child.
|
8
10
|
def quantified?
|
9
|
-
return
|
11
|
+
return !@quantifier.nil?
|
10
12
|
end
|
11
13
|
|
12
14
|
def quantifier
|
data/lib/regex/raw_expression.rb
CHANGED
data/lib/regex/repetition.rb
CHANGED
data/lib/regex/wildcard.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# File: wildcard.rb
|
2
4
|
|
3
5
|
require_relative 'atomic_expression' # Access the superclass
|
@@ -5,11 +7,6 @@ require_relative 'atomic_expression' # Access the superclass
|
|
5
7
|
module Regex # This module is used as a namespace
|
6
8
|
# A wildcard matches any character (except for the newline).
|
7
9
|
class Wildcard < AtomicExpression
|
8
|
-
# Constructor
|
9
|
-
def initialize
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
10
|
protected
|
14
11
|
|
15
12
|
# Conversion method re-definition.
|