srl_ruby 0.4.5 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +298 -23
  3. data/CHANGELOG.md +41 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE.txt +1 -1
  6. data/README.md +1 -1
  7. data/Rakefile +3 -0
  8. data/appveyor.yml +14 -12
  9. data/bin/srl2ruby +13 -9
  10. data/bin/srl2ruby_cli_parser.rb +3 -3
  11. data/features/lib/step_definitions/srl_testing_steps.rb +2 -0
  12. data/features/lib/support/env..rb +2 -0
  13. data/lib/regex/abstract_method.rb +2 -0
  14. data/lib/regex/alternation.rb +3 -3
  15. data/lib/regex/anchor.rb +3 -0
  16. data/lib/regex/atomic_expression.rb +2 -0
  17. data/lib/regex/capturing_group.rb +8 -3
  18. data/lib/regex/char_class.rb +4 -2
  19. data/lib/regex/char_range.rb +3 -3
  20. data/lib/regex/char_shorthand.rb +3 -0
  21. data/lib/regex/character.rb +5 -2
  22. data/lib/regex/compound_expression.rb +2 -0
  23. data/lib/regex/concatenation.rb +3 -1
  24. data/lib/regex/expression.rb +6 -1
  25. data/lib/regex/lookaround.rb +3 -1
  26. data/lib/regex/match_option.rb +2 -0
  27. data/lib/regex/monadic_expression.rb +2 -0
  28. data/lib/regex/multiplicity.rb +8 -9
  29. data/lib/regex/non_capturing_group.rb +3 -1
  30. data/lib/regex/polyadic_expression.rb +2 -0
  31. data/lib/regex/quantifiable.rb +3 -1
  32. data/lib/regex/raw_expression.rb +2 -0
  33. data/lib/regex/repetition.rb +2 -0
  34. data/lib/regex/wildcard.rb +2 -5
  35. data/lib/srl_ruby/ast_builder.rb +81 -121
  36. data/lib/srl_ruby/grammar.rb +80 -92
  37. data/lib/srl_ruby/regex_repr.rb +2 -0
  38. data/lib/srl_ruby/tokenizer.rb +10 -4
  39. data/lib/srl_ruby/version.rb +3 -1
  40. data/lib/srl_ruby.rb +2 -0
  41. data/spec/acceptance/srl_test_suite_spec.rb +2 -0
  42. data/spec/acceptance/support/rule_file_ast_builder.rb +2 -0
  43. data/spec/acceptance/support/rule_file_grammar.rb +7 -5
  44. data/spec/acceptance/support/rule_file_nodes.rb +2 -0
  45. data/spec/acceptance/support/rule_file_parser.rb +2 -0
  46. data/spec/acceptance/support/rule_file_tokenizer.rb +10 -3
  47. data/spec/regex/atomic_expression_spec.rb +2 -0
  48. data/spec/regex/character_spec.rb +16 -6
  49. data/spec/regex/match_option_spec.rb +2 -0
  50. data/spec/regex/monadic_expression_spec.rb +2 -0
  51. data/spec/regex/multiplicity_spec.rb +4 -0
  52. data/spec/regex/repetition_spec.rb +2 -0
  53. data/spec/spec_helper.rb +2 -0
  54. data/spec/srl_ruby/srl_ruby_spec.rb +2 -0
  55. data/spec/srl_ruby/tokenizer_spec.rb +2 -0
  56. data/spec/srl_ruby_spec.rb +8 -6
  57. data/srl_ruby.gemspec +6 -4
  58. 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: atomic_expression.rb
2
4
 
3
5
  require_relative 'expression' # Access the superclass
@@ -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
- result = '(' + atomic + prefix + child.child.to_str + ')'
47
+ suffix = child.child.to_str
44
48
  else
45
- result = '(' + atomic + prefix + child.to_str + ')'
49
+ suffix = child.to_str
46
50
  end
47
- return result
51
+ "(#{atomic}#{prefix}#{suffix})"
48
52
  end
53
+ # rubocop: enable Style/OptionalBooleanParameter
49
54
  end # class
50
55
  end # module
51
56
 
@@ -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 = '[' + (negated ? '^' : '') + result_children + ']'
33
+ result = "[#{negated ? '^' : ''}#{result_children}]"
32
34
 
33
35
  return result
34
36
  end
@@ -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
- result = lower.to_str + '-' + upper.to_str
36
-
37
- return result
37
+ "#{lower.to_str}-#{upper.to_str}"
38
38
  end
39
39
 
40
40
  private
@@ -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
 
@@ -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 = '\^$.|+?*()[]{}'.freeze
29
- MetaCharsInClass = '\^[]-'.freeze # Characters with special meaning in char. class
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # File: compound_expression.rb
2
4
 
3
5
  require_relative 'expression' # Access the superclass
@@ -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
 
@@ -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
@@ -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 = '(?' + dir_syntax + kind_syntax + child.to_str + ')'
45
+ result = "(?#{dir_syntax}#{kind_syntax}#{child.to_str})"
44
46
  return result
45
47
  end
46
48
  end # class
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # File: MatchOption.rb
2
4
  require_relative 'monadic_expression'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # File: monadic_expression.rb
2
4
 
3
5
  require_relative 'compound_expression' # Access the superclass
@@ -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
- suffix = case policy
52
- when :greedy
53
- ''
54
- when :lazy
55
- '?'
56
- when :possessive
57
- '+'
58
- end
53
+ policy2suffix = {
54
+ greedy: '',
55
+ lazy: '?',
56
+ possessive: '+'
57
+ }
59
58
 
60
- return subresult + suffix
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 = '(?:' + all_child_text + ')'
25
+ result = "(?:#{all_child_text})"
24
26
  return result
25
27
  end
26
28
  end # class
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # File: polyadic_expression.rb
2
4
 
3
5
  require_relative 'compound_expression' # Access the superclass
@@ -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 @quantifier.nil? ? false : true
11
+ return !@quantifier.nil?
10
12
  end
11
13
 
12
14
  def quantifier
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'atomic_expression' # Access the superclass
2
4
 
3
5
  module Regex # This module is used as a namespace
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # File: repetition.rb
2
4
 
3
5
  require_relative 'monadic_expression' # Access the superclass
@@ -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.