srl_ruby 0.4.3 → 0.4.7

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.
Files changed (60) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +278 -22
  3. data/CHANGELOG.md +43 -1
  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 +15 -14
  9. data/bin/srl2ruby +17 -12
  10. data/bin/srl2ruby_cli_parser.rb +6 -6
  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 +4 -3
  20. data/lib/regex/char_shorthand.rb +3 -0
  21. data/lib/regex/character.rb +7 -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 +9 -9
  29. data/lib/regex/non_capturing_group.rb +3 -1
  30. data/lib/regex/polyadic_expression.rb +4 -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 +12 -1
  36. data/lib/srl_ruby/grammar.rb +48 -46
  37. data/lib/srl_ruby/regex_repr.rb +2 -0
  38. data/lib/srl_ruby/tokenizer.rb +14 -8
  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 +14 -8
  47. data/spec/regex/atomic_expression_spec.rb +2 -0
  48. data/spec/regex/character_spec.rb +12 -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 +3 -1
  56. data/spec/srl_ruby_spec.rb +8 -6
  57. data/srl_ruby.gemspec +7 -5
  58. metadata +16 -18
  59. data/lib/srl_ruby/srl_token.rb +0 -23
  60. data/spec/acceptance/support/rule_file_token.rb +0 -22
@@ -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
@@ -66,6 +65,7 @@ module Regex # This module is used as a namespace
66
65
  def valid_lower_bound(aLowerBound)
67
66
  err_msg = "Invalid lower bound of repetition count #{aLowerBound}"
68
67
  raise StandardError, err_msg unless aLowerBound.kind_of?(Integer)
68
+
69
69
  return aLowerBound
70
70
  end
71
71
 
@@ -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
@@ -30,6 +32,7 @@ module Regex # This module is used as a namespace
30
32
  children.each(&:done!)
31
33
  children.each_with_index do |child, index|
32
34
  break if index == children.size - 1
35
+
33
36
  next_child = children[index + 1]
34
37
  if next_child.kind_of?(Lookaround) && next_child.dir == :behind
35
38
  # Swap children: lookbehind regex must precede pattern
@@ -57,6 +60,7 @@ module Regex # This module is used as a namespace
57
60
  top = visit_stack.pop
58
61
  if top.kind_of?(Array)
59
62
  next if top.empty?
63
+
60
64
  currChild = top.pop
61
65
  visit_stack.push top
62
66
  else
@@ -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.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stringio'
2
4
  require_relative 'regex_repr'
3
5
 
@@ -44,6 +46,7 @@ module SrlRuby
44
46
  end
45
47
  end
46
48
  return if regexp_opts.empty?
49
+
47
50
  new_root = Regex::MatchOption.new(tree_root, regexp_opts)
48
51
  result.instance_variable_set(:@root, new_root)
49
52
  end
@@ -65,6 +68,8 @@ module SrlRuby
65
68
  return Regex::Multiplicity.new(lowerBound, upperBound, :greedy)
66
69
  end
67
70
 
71
+ # rubocop: disable Style/OptionalBooleanParameter
72
+
68
73
  def string_literal(aString, to_escape = true)
69
74
  if aString.size > 1
70
75
  chars = []
@@ -85,6 +90,7 @@ module SrlRuby
85
90
 
86
91
  return result
87
92
  end
93
+ # rubocop: enable Style/OptionalBooleanParameter
88
94
 
89
95
  def char_range(lowerBound, upperBound)
90
96
  lower = Regex::Character.new(lowerBound)
@@ -120,7 +126,12 @@ module SrlRuby
120
126
 
121
127
  # rule('pattern' => %w[pattern separator sub_pattern]).as 'pattern_sequence'
122
128
  def reduce_pattern_sequence(_production, _range, _tokens, theChildren)
123
- Regex::Concatenation.new(theChildren[0], theChildren[2])
129
+ third_member = theChildren[2]
130
+ if third_member.kind_of?(Regex::Lookaround) && third_member.dir == :behind
131
+ Regex::Concatenation.new(theChildren[2], theChildren[0])
132
+ else
133
+ Regex::Concatenation.new(theChildren[0], theChildren[2])
134
+ end
124
135
  end
125
136
 
126
137
  # rule('pattern' => 'sub_pattern').as 'basic_pattern'
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Grammar for SRL (Simple Regex Language)
2
4
  require 'rley' # Load the gem
3
5
  module SrlRuby
4
6
  ########################################
5
7
  # SRL grammar
6
- builder = Rley::Syntax::GrammarBuilder.new do
8
+ builder = Rley::Notation::GrammarBuilder.new do
7
9
  # Separators...
8
10
  add_terminals('LPAREN', 'RPAREN', 'COMMA')
9
11
 
@@ -30,33 +32,33 @@ module SrlRuby
30
32
 
31
33
  # Grammar rules...
32
34
  rule('srl' => 'expression').as 'start_rule'
33
- rule('expression' => %w[pattern flags]).as 'flagged_expr'
35
+ rule('expression' => 'pattern flags').as 'flagged_expr'
34
36
  rule('expression' => 'pattern').as 'simple_expr'
35
- rule('pattern' => %w[pattern separator sub_pattern]).as 'pattern_sequence'
37
+ rule('pattern' => 'pattern separator sub_pattern').as 'pattern_sequence'
36
38
  rule('pattern' => 'sub_pattern').as 'basic_pattern'
37
39
  rule('sub_pattern' => 'quantifiable').as 'quantifiable_sub_pattern'
38
40
  rule('sub_pattern' => 'assertion').as 'assertion_sub_pattern'
39
41
  rule('separator' => 'COMMA').as 'comma_separator'
40
42
  rule('separator' => []).as 'void_separator'
41
- rule('flags' => %w[flags separator single_flag]).as 'flag_sequence'
42
- rule('flags' => %w[separator single_flag]).as 'flag_simple'
43
- rule('single_flag' => %w[CASE INSENSITIVE]).as 'case_insensitive'
44
- rule('single_flag' => %w[MULTI LINE]).as 'multi_line'
45
- rule('single_flag' => %w[ALL LAZY]).as 'all_lazy'
46
- rule('quantifiable' => %w[begin_anchor anchorable end_anchor]).as 'pinned_quantifiable'
47
- rule('quantifiable' => %w[begin_anchor anchorable]).as 'begin_anchor_quantifiable'
48
- rule('quantifiable' => %w[anchorable end_anchor]).as 'end_anchor_quantifiable'
43
+ rule('flags' => 'flags separator single_flag').as 'flag_sequence'
44
+ rule('flags' => 'separator single_flag').as 'flag_simple'
45
+ rule('single_flag' => 'CASE INSENSITIVE').as 'case_insensitive'
46
+ rule('single_flag' => 'MULTI LINE').as 'multi_line'
47
+ rule('single_flag' => 'ALL LAZY').as 'all_lazy'
48
+ rule('quantifiable' => 'begin_anchor anchorable end_anchor').as 'pinned_quantifiable'
49
+ rule('quantifiable' => 'begin_anchor anchorable').as 'begin_anchor_quantifiable'
50
+ rule('quantifiable' => 'anchorable end_anchor').as 'end_anchor_quantifiable'
49
51
  rule('quantifiable' => 'anchorable').as 'simple_quantifiable'
50
- rule('begin_anchor' => %w[STARTS WITH]).as 'starts_with'
51
- rule('begin_anchor' => %w[BEGIN WITH]).as 'begin_with'
52
- rule('end_anchor' => %w[separator MUST END]).as 'end_anchor'
52
+ rule('begin_anchor' => 'STARTS WITH').as 'starts_with'
53
+ rule('begin_anchor' => 'BEGIN WITH').as 'begin_with'
54
+ rule('end_anchor' => 'separator MUST END').as 'end_anchor'
53
55
  rule('anchorable' => 'assertable').as 'simple_anchorable'
54
- rule('assertion' => %w[IF FOLLOWED BY assertable]).as 'if_followed'
55
- rule('assertion' => %w[IF NOT FOLLOWED BY assertable]).as 'if_not_followed'
56
- rule('assertion' => %w[IF ALREADY HAD assertable]).as 'if_had'
57
- rule('assertion' => %w[IF NOT ALREADY HAD assertable]).as 'if_not_had'
56
+ rule('assertion' => 'IF FOLLOWED BY assertable').as 'if_followed'
57
+ rule('assertion' => 'IF NOT FOLLOWED BY assertable').as 'if_not_followed'
58
+ rule('assertion' => 'IF ALREADY HAD assertable').as 'if_had'
59
+ rule('assertion' => 'IF NOT ALREADY HAD assertable').as 'if_not_had'
58
60
  rule('assertable' => 'term').as 'simple_assertable'
59
- rule('assertable' => %w[term quantifier]).as 'quantified_assertable'
61
+ rule('assertable' => 'term quantifier').as 'quantified_assertable'
60
62
  rule('term' => 'atom').as 'atom_term'
61
63
  rule('term' => 'alternation').as 'alternation_term'
62
64
  rule('term' => 'grouping').as 'grouping_term'
@@ -67,20 +69,20 @@ module SrlRuby
67
69
  rule('atom' => 'special_char').as 'special_char_atom'
68
70
  rule('atom' => 'literal').as 'literal_atom'
69
71
  rule('atom' => 'raw').as 'raw_atom'
70
- rule('letter_range' => %w[LETTER FROM LETTER_LIT TO LETTER_LIT]).as 'lowercase_from_to'
71
- rule('letter_range' => %w[UPPERCASE LETTER FROM LETTER_LIT TO LETTER_LIT]).as 'uppercase_from_to'
72
+ rule('letter_range' => 'LETTER FROM LETTER_LIT TO LETTER_LIT').as 'lowercase_from_to'
73
+ rule('letter_range' => 'UPPERCASE LETTER FROM LETTER_LIT TO LETTER_LIT').as 'uppercase_from_to'
72
74
  rule('letter_range' => 'LETTER').as 'any_lowercase'
73
- rule('letter_range' => %w[UPPERCASE LETTER]).as 'any_uppercase'
74
- rule('digit_range' => %w[digit_or_number FROM DIGIT_LIT TO DIGIT_LIT]).as 'digits_from_to'
75
- rule('character_class' => %w[ANY CHARACTER]).as 'any_character'
76
- rule('character_class' => %w[NO CHARACTER]).as 'no_character'
75
+ rule('letter_range' => 'UPPERCASE LETTER').as 'any_uppercase'
76
+ rule('digit_range' => 'digit_or_number FROM DIGIT_LIT TO DIGIT_LIT').as 'digits_from_to'
77
+ rule('character_class' => 'ANY CHARACTER').as 'any_character'
78
+ rule('character_class' => 'NO CHARACTER').as 'no_character'
77
79
  rule('character_class' => 'digit_or_number').as 'digit'
78
- rule('character_class' => %w[NO DIGIT]).as 'non_digit'
80
+ rule('character_class' => 'NO DIGIT').as 'non_digit'
79
81
  rule('character_class' => 'WHITESPACE').as 'whitespace'
80
- rule('character_class' => %w[NO WHITESPACE]).as 'no_whitespace'
82
+ rule('character_class' => 'NO WHITESPACE').as 'no_whitespace'
81
83
  rule('character_class' => 'ANYTHING').as 'anything'
82
- rule('character_class' => %w[ONE OF cclass]).as 'one_of'
83
- rule('character_class' => %w[NONE OF cclass]).as 'none_of'
84
+ rule('character_class' => 'ONE OF cclass').as 'one_of'
85
+ rule('character_class' => 'NONE OF cclass').as 'none_of'
84
86
  rule('cclass' => 'STRING_LIT').as 'quoted_cclass' # Preferred syntax
85
87
  rule('cclass' => 'INTEGER').as 'digits_cclass'
86
88
  rule('cclass' => 'IDENTIFIER').as 'identifier_cclass'
@@ -88,32 +90,32 @@ module SrlRuby
88
90
  rule('special_char' => 'TAB').as 'tab'
89
91
  rule('special_char' => 'VERTICAL TAB').as 'vtab'
90
92
  rule('special_char' => 'BACKSLASH').as 'backslash'
91
- rule('special_char' => %w[NEW LINE]).as 'new_line'
92
- rule('special_char' => %w[CARRIAGE RETURN]).as 'carriage_return'
93
- rule('special_char' => %w[WORD]).as 'word'
94
- rule('special_char' => %w[NO WORD]).as 'no_word'
95
- rule('literal' => %w[LITERALLY STRING_LIT]).as 'literally'
93
+ rule('special_char' => 'NEW LINE').as 'new_line'
94
+ rule('special_char' => 'CARRIAGE RETURN').as 'carriage_return'
95
+ rule('special_char' => 'WORD').as 'word'
96
+ rule('special_char' => 'NO WORD').as 'no_word'
97
+ rule('literal' => 'LITERALLY STRING_LIT').as 'literally'
96
98
  rule('raw' => 'RAW STRING_LIT').as 'raw_literal'
97
- rule('alternation' => %w[any_or_either OF LPAREN alternatives RPAREN]).as 'any_of'
98
- rule('alternatives' => %w[alternatives separator quantifiable]).as 'alternative_list'
99
+ rule('alternation' => 'any_or_either OF LPAREN alternatives RPAREN').as 'any_of'
100
+ rule('alternatives' => 'alternatives separator quantifiable').as 'alternative_list'
99
101
  rule('alternatives' => 'quantifiable').as 'simple_alternative'
100
102
  rule('any_or_either' => 'ANY').as 'any_keyword'
101
103
  rule('any_or_either' => 'EITHER').as 'either_keyword'
102
- rule('grouping' => %w[LPAREN pattern RPAREN]).as 'grouping_parenthenses'
103
- rule('capturing_group' => %w[CAPTURE assertable]).as 'capture'
104
- rule('capturing_group' => %w[CAPTURE assertable UNTIL assertable]).as 'capture_until'
105
- rule('capturing_group' => %w[CAPTURE assertable AS var_name]).as 'named_capture'
106
- rule('capturing_group' => %w[CAPTURE assertable AS var_name UNTIL assertable]).as 'named_capture_until'
104
+ rule('grouping' => 'LPAREN pattern RPAREN').as 'grouping_parenthenses'
105
+ rule('capturing_group' => 'CAPTURE assertable').as 'capture'
106
+ rule('capturing_group' => 'CAPTURE assertable UNTIL assertable').as 'capture_until'
107
+ rule('capturing_group' => 'CAPTURE assertable AS var_name').as 'named_capture'
108
+ rule('capturing_group' => 'CAPTURE assertable AS var_name UNTIL assertable').as 'named_capture_until'
107
109
  rule('var_name' => 'STRING_LIT').as 'var_name'
108
110
  rule('var_name' => 'IDENTIFIER').as 'var_ident' # capture name not enclosed between quotes
109
111
  rule('quantifier' => 'ONCE').as 'once'
110
112
  rule('quantifier' => 'TWICE').as 'twice'
111
- rule('quantifier' => %w[EXACTLY count TIMES]).as 'exactly'
112
- rule('quantifier' => %w[BETWEEN count AND count times_suffix]).as 'between_and'
113
+ rule('quantifier' => 'EXACTLY count TIMES').as 'exactly'
114
+ rule('quantifier' => 'BETWEEN count AND count times_suffix').as 'between_and'
113
115
  rule('quantifier' => 'OPTIONAL').as 'optional'
114
- rule('quantifier' => %w[ONCE OR MORE]).as 'once_or_more'
115
- rule('quantifier' => %w[NEVER OR MORE]).as 'never_or_more'
116
- rule('quantifier' => %w[AT LEAST count TIMES]).as 'at_least'
116
+ rule('quantifier' => 'ONCE OR MORE').as 'once_or_more'
117
+ rule('quantifier' => 'NEVER OR MORE').as 'never_or_more'
118
+ rule('quantifier' => 'AT LEAST count TIMES').as 'at_least'
117
119
  rule('digit_or_number' => 'DIGIT').as 'digit_keyword'
118
120
  rule('digit_or_number' => 'NUMBER').as 'number_keyword'
119
121
  rule('count' => 'DIGIT_LIT').as 'single_digit'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../regex/character'
2
4
  require_relative '../regex/char_range'
3
5
  require_relative '../regex/concatenation'
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # File: srl_tokenizer.rb
2
4
  # Tokenizer for SRL (Simple Regex Language)
3
5
  require 'strscan'
4
- require_relative 'srl_token'
6
+ require 'rley'
5
7
 
6
8
 
7
9
  module SrlRuby
@@ -15,10 +17,14 @@ module SrlRuby
15
17
  # Delimiters: parentheses '(' and ')'
16
18
  # Separators: comma (optional)
17
19
  class Tokenizer
20
+ # @return [StringScanner]
18
21
  attr_reader(:scanner)
22
+
23
+ # @return [Integer] current line number
19
24
  attr_reader(:lineno)
25
+
26
+ # @return [Integer] offset of start of current line within input
20
27
  attr_reader(:line_start)
21
- # attr_reader(:column)
22
28
 
23
29
  @@lexeme2name = {
24
30
  '(' => 'LPAREN',
@@ -84,7 +90,7 @@ module SrlRuby
84
90
  WHITESPACE
85
91
  WITH
86
92
  WORD
87
- ].map { |x| [x, x] } .to_h
93
+ ].map { |x| [x, x] }.to_h
88
94
 
89
95
  class ScanError < StandardError; end
90
96
 
@@ -132,7 +138,7 @@ module SrlRuby
132
138
  token = build_token('LETTER_LIT', lexeme)
133
139
  elsif (lexeme = scanner.scan(/[a-zA-Z_][a-zA-Z0-9_]+/))
134
140
  keyw = @@keywords[lexeme.upcase]
135
- tok_type = keyw ? keyw : 'IDENTIFIER'
141
+ tok_type = keyw || 'IDENTIFIER'
136
142
  token = build_token(tok_type, lexeme)
137
143
  elsif (lexeme = scanner.scan(/[^,"\s]{2,}/))
138
144
  token = build_token('CHAR_CLASS', lexeme)
@@ -149,11 +155,11 @@ module SrlRuby
149
155
  def build_token(aSymbolName, aLexeme)
150
156
  begin
151
157
  col = scanner.pos - aLexeme.size - @line_start + 1
152
- pos = Position.new(@lineno, col)
153
- token = SrlToken.new(aLexeme, aSymbolName, pos)
154
- rescue StandardError => exc
158
+ pos = Rley::Lexical::Position.new(@lineno, col)
159
+ token = Rley::Lexical::Token.new(aLexeme, aSymbolName, pos)
160
+ rescue StandardError => e
155
161
  puts "Failing with '#{aSymbolName}' and '#{aLexeme}'"
156
- raise exc
162
+ raise e
157
163
  end
158
164
 
159
165
  return token
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SrlRuby
2
- VERSION = '0.4.3'.freeze
4
+ VERSION = '0.4.7'
3
5
  end
data/lib/srl_ruby.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './srl_ruby/version'
2
4
  require_relative './srl_ruby/tokenizer'
3
5
  require_relative './srl_ruby/grammar'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../spec_helper'
2
4
  require_relative './support/rule_file_parser'
3
5
  require_relative '../../lib/srl_ruby'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'rule_file_nodes'
2
4
 
3
5
  module Acceptance
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # File: rule_file_grammar.rb
2
4
  require 'rley' # Load the Rley gem
3
5
 
@@ -5,20 +7,20 @@ require 'rley' # Load the Rley gem
5
7
  # [File format](https://github.com/SimpleRegex/Test-Rules/blob/master/README.md)
6
8
  ########################################
7
9
  # Define a grammar for basic arithmetical expressions
8
- builder = Rley::Syntax::GrammarBuilder.new do
10
+ builder = Rley::Notation::GrammarBuilder.new do
9
11
  # Punctuation
10
12
  add_terminals('COLON', 'DASH')
11
13
 
12
14
  # Keywords
13
15
  add_terminals('CAPTURE', 'FOR')
14
- add_terminals('MATCH:', 'NO', 'SRL:')
16
+ add_terminals('MATCH', 'NO', 'SRL')
15
17
 
16
18
  # Literals
17
19
  add_terminals('INTEGER', 'STRING_LIT')
18
20
  add_terminals('IDENTIFIER', 'SRL_SOURCE')
19
21
 
20
22
  rule('rule_file' => 'srl_heading srl_tests').as 'start_rule'
21
- rule('srl_heading' => 'SRL: SRL_SOURCE').as 'srl_source'
23
+ rule('srl_heading' => 'SRL SRL_SOURCE').as 'srl_source'
22
24
  rule('srl_tests' => 'srl_tests single_test').as 'test_list'
23
25
  rule('srl_tests' => 'single_test').as 'one_test'
24
26
  rule('single_test' => 'atomic_test').as 'single_atomic_test'
@@ -26,8 +28,8 @@ builder = Rley::Syntax::GrammarBuilder.new do
26
28
  rule('atomic_test' => 'match_test').as 'atomic_match'
27
29
  rule('atomic_test' => 'no_match_test').as 'atomic_no_match'
28
30
  rule('compound_test' => 'capture_test').as 'compound_capture'
29
- rule('match_test' => 'MATCH: STRING_LIT').as 'match_string'
30
- rule('no_match_test' => 'NO MATCH: STRING_LIT').as 'no_match_string'
31
+ rule('match_test' => 'MATCH STRING_LIT').as 'match_string'
32
+ rule('no_match_test' => 'NO MATCH STRING_LIT').as 'no_match_string'
31
33
  rule('capture_test' => 'capture_heading capture_expectations').as 'capture_test'
32
34
  rule('capture_heading' => 'CAPTURE FOR STRING_LIT COLON').as 'capture_string'
33
35
  rule('capture_expectations' => 'capture_expectations single_expectation').as 'assertion_list'