srl_ruby 0.4.6 → 0.4.10
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 +298 -23
- data/CHANGELOG.md +29 -1
- data/LICENSE.txt +1 -1
- data/Rakefile +1 -0
- data/bin/srl2ruby +8 -6
- data/bin/srl2ruby_cli_parser.rb +1 -3
- data/lib/regex/alternation.rb +1 -3
- data/lib/regex/anchor.rb +1 -0
- data/lib/regex/capturing_group.rb +6 -3
- data/lib/regex/char_class.rb +1 -1
- data/lib/regex/char_range.rb +1 -3
- data/lib/regex/char_shorthand.rb +1 -0
- data/lib/regex/character.rb +1 -0
- data/lib/regex/expression.rb +3 -0
- data/lib/regex/lookaround.rb +1 -1
- data/lib/regex/multiplicity.rb +6 -9
- data/lib/regex/non_capturing_group.rb +1 -1
- data/lib/regex/quantifiable.rb +1 -1
- data/lib/regex/wildcard.rb +0 -5
- data/lib/srl_ruby/ast_builder.rb +79 -120
- data/lib/srl_ruby/grammar.rb +78 -92
- data/lib/srl_ruby/tokenizer.rb +6 -2
- data/lib/srl_ruby/version.rb +1 -1
- data/spec/acceptance/support/rule_file_ast_builder.rb +1 -22
- data/spec/acceptance/support/rule_file_grammar.rb +16 -21
- data/spec/acceptance/support/rule_file_tokenizer.rb +6 -1
- data/spec/regex/character_spec.rb +14 -6
- data/spec/regex/multiplicity_spec.rb +2 -0
- data/spec/srl_ruby_spec.rb +6 -6
- data/srl_ruby.gemspec +3 -3
- metadata +11 -11
data/lib/srl_ruby/grammar.rb
CHANGED
|
@@ -5,7 +5,7 @@ require 'rley' # Load the gem
|
|
|
5
5
|
module SrlRuby
|
|
6
6
|
########################################
|
|
7
7
|
# SRL grammar
|
|
8
|
-
builder = Rley::
|
|
8
|
+
builder = Rley::grammar_builder do
|
|
9
9
|
# Separators...
|
|
10
10
|
add_terminals('LPAREN', 'RPAREN', 'COMMA')
|
|
11
11
|
|
|
@@ -31,97 +31,83 @@ module SrlRuby
|
|
|
31
31
|
add_terminals('LAZY')
|
|
32
32
|
|
|
33
33
|
# Grammar rules...
|
|
34
|
-
rule('srl' => 'expression').
|
|
35
|
-
rule('expression' =>
|
|
36
|
-
rule('
|
|
37
|
-
rule('
|
|
38
|
-
rule('
|
|
39
|
-
rule('
|
|
40
|
-
rule('
|
|
41
|
-
rule('
|
|
42
|
-
rule('
|
|
43
|
-
rule('
|
|
44
|
-
rule('
|
|
45
|
-
rule('
|
|
46
|
-
rule('
|
|
47
|
-
rule('
|
|
48
|
-
rule('
|
|
49
|
-
rule('
|
|
50
|
-
rule('
|
|
51
|
-
rule('
|
|
52
|
-
rule('
|
|
53
|
-
rule('
|
|
54
|
-
rule('
|
|
55
|
-
rule('
|
|
56
|
-
rule('
|
|
57
|
-
rule('
|
|
58
|
-
rule('
|
|
59
|
-
rule('
|
|
60
|
-
rule('
|
|
61
|
-
rule('
|
|
62
|
-
rule('
|
|
63
|
-
rule('
|
|
64
|
-
rule('
|
|
65
|
-
rule('
|
|
66
|
-
rule('
|
|
67
|
-
rule('
|
|
68
|
-
rule('
|
|
69
|
-
rule('
|
|
70
|
-
rule('
|
|
71
|
-
rule('
|
|
72
|
-
rule('
|
|
73
|
-
rule('
|
|
74
|
-
rule('
|
|
75
|
-
rule('
|
|
76
|
-
rule('
|
|
77
|
-
rule('
|
|
78
|
-
rule('
|
|
79
|
-
rule('
|
|
80
|
-
rule('
|
|
81
|
-
rule('
|
|
82
|
-
rule('
|
|
83
|
-
rule('
|
|
84
|
-
rule('
|
|
85
|
-
rule('
|
|
86
|
-
rule('
|
|
87
|
-
rule('
|
|
88
|
-
rule('
|
|
89
|
-
rule('
|
|
90
|
-
rule('
|
|
91
|
-
rule('
|
|
92
|
-
rule('
|
|
93
|
-
rule('
|
|
94
|
-
rule('
|
|
95
|
-
rule('
|
|
96
|
-
rule('
|
|
97
|
-
rule('
|
|
98
|
-
rule('
|
|
99
|
-
rule('
|
|
100
|
-
rule('
|
|
101
|
-
rule('
|
|
102
|
-
rule('
|
|
103
|
-
rule('
|
|
104
|
-
rule('
|
|
105
|
-
rule('
|
|
106
|
-
rule('
|
|
107
|
-
rule('
|
|
108
|
-
rule('
|
|
109
|
-
rule('
|
|
110
|
-
rule('
|
|
111
|
-
rule('quantifier' => 'ONCE').as 'once'
|
|
112
|
-
rule('quantifier' => 'TWICE').as 'twice'
|
|
113
|
-
rule('quantifier' => %w[EXACTLY count TIMES]).as 'exactly'
|
|
114
|
-
rule('quantifier' => %w[BETWEEN count AND count times_suffix]).as 'between_and'
|
|
115
|
-
rule('quantifier' => 'OPTIONAL').as 'optional'
|
|
116
|
-
rule('quantifier' => %w[ONCE OR MORE]).as 'once_or_more'
|
|
117
|
-
rule('quantifier' => %w[NEVER OR MORE]).as 'never_or_more'
|
|
118
|
-
rule('quantifier' => %w[AT LEAST count TIMES]).as 'at_least'
|
|
119
|
-
rule('digit_or_number' => 'DIGIT').as 'digit_keyword'
|
|
120
|
-
rule('digit_or_number' => 'NUMBER').as 'number_keyword'
|
|
121
|
-
rule('count' => 'DIGIT_LIT').as 'single_digit'
|
|
122
|
-
rule('count' => 'INTEGER').as 'integer_count'
|
|
123
|
-
rule('times_suffix' => 'TIMES').as 'times_keyword'
|
|
124
|
-
rule('times_suffix' => []).as 'times_dropped'
|
|
34
|
+
rule('srl' => 'expression').tag 'start_rule'
|
|
35
|
+
rule('expression' => 'pattern flags?').tag 'flagged_expr'
|
|
36
|
+
rule('pattern' => 'sub_pattern (separator sub_pattern)*').tag 'pattern_sequence'
|
|
37
|
+
rule('sub_pattern' => 'quantifiable').tag 'quantifiable_sub_pattern'
|
|
38
|
+
rule('sub_pattern' => 'assertion').tag 'assertion_sub_pattern'
|
|
39
|
+
rule('separator' => 'COMMA?')
|
|
40
|
+
rule('flags' => '(separator single_flag)+').tag 'flag_sequence'
|
|
41
|
+
rule('single_flag' => 'CASE INSENSITIVE').tag 'case_insensitive'
|
|
42
|
+
rule('single_flag' => 'MULTI LINE').tag 'multi_line'
|
|
43
|
+
rule('single_flag' => 'ALL LAZY').tag 'all_lazy'
|
|
44
|
+
rule('quantifiable' => 'begin_anchor? anchorable end_anchor?').tag 'quantifiable'
|
|
45
|
+
rule('begin_anchor' => 'STARTS WITH').tag 'starts_with'
|
|
46
|
+
rule('begin_anchor' => 'BEGIN WITH').tag 'begin_with'
|
|
47
|
+
rule('end_anchor' => 'separator MUST END').tag 'end_anchor'
|
|
48
|
+
rule('anchorable' => 'assertable').tag 'simple_anchorable'
|
|
49
|
+
rule('assertion' => 'IF NOT? FOLLOWED BY assertable').tag 'if_followed'
|
|
50
|
+
rule('assertion' => 'IF NOT? ALREADY HAD assertable').tag 'if_had'
|
|
51
|
+
rule('assertable' => 'term quantifier?').tag 'assertable'
|
|
52
|
+
rule('term' => 'atom').tag 'atom_term'
|
|
53
|
+
rule('term' => 'alternation').tag 'alternation_term'
|
|
54
|
+
rule('term' => 'grouping').tag 'grouping_term'
|
|
55
|
+
rule('term' => 'capturing_group').tag 'capturing_group_atom'
|
|
56
|
+
rule('atom' => 'letter_range').tag 'letter_range_atom'
|
|
57
|
+
rule('atom' => 'digit_range').tag 'digit_range_atom'
|
|
58
|
+
rule('atom' => 'character_class').tag 'character_class_atom'
|
|
59
|
+
rule('atom' => 'special_char').tag 'special_char_atom'
|
|
60
|
+
rule('atom' => 'literal').tag 'literal_atom'
|
|
61
|
+
rule('atom' => 'raw').tag 'raw_atom'
|
|
62
|
+
rule('letter_range' => 'LETTER FROM LETTER_LIT TO LETTER_LIT').tag 'lowercase_from_to'
|
|
63
|
+
rule('letter_range' => 'UPPERCASE LETTER FROM LETTER_LIT TO LETTER_LIT').tag 'uppercase_from_to'
|
|
64
|
+
rule('letter_range' => 'LETTER').tag 'any_lowercase'
|
|
65
|
+
rule('letter_range' => 'UPPERCASE LETTER').tag 'any_uppercase'
|
|
66
|
+
rule('digit_range' => 'digit_or_number FROM DIGIT_LIT TO DIGIT_LIT').tag 'digits_from_to'
|
|
67
|
+
rule('character_class' => 'ANY CHARACTER').tag 'any_character'
|
|
68
|
+
rule('character_class' => 'NO CHARACTER').tag 'no_character'
|
|
69
|
+
rule('character_class' => 'digit_or_number').tag 'digit'
|
|
70
|
+
rule('character_class' => 'NO DIGIT').tag 'non_digit'
|
|
71
|
+
rule('character_class' => 'WHITESPACE').tag 'whitespace'
|
|
72
|
+
rule('character_class' => 'NO WHITESPACE').tag 'no_whitespace'
|
|
73
|
+
rule('character_class' => 'ANYTHING').tag 'anything'
|
|
74
|
+
rule('character_class' => 'ONE OF cclass').tag 'one_of'
|
|
75
|
+
rule('character_class' => 'NONE OF cclass').tag 'none_of'
|
|
76
|
+
rule('cclass' => 'STRING_LIT').tag 'quoted_cclass' # Preferred syntax
|
|
77
|
+
rule('cclass' => 'INTEGER').tag 'digits_cclass'
|
|
78
|
+
rule('cclass' => 'IDENTIFIER').tag 'identifier_cclass'
|
|
79
|
+
rule('cclass' => 'CHAR_CLASS').tag 'unquoted_cclass'
|
|
80
|
+
rule('special_char' => 'TAB').tag 'tab'
|
|
81
|
+
rule('special_char' => 'VERTICAL TAB').tag 'vtab'
|
|
82
|
+
rule('special_char' => 'BACKSLASH').tag 'backslash'
|
|
83
|
+
rule('special_char' => 'NEW LINE').tag 'new_line'
|
|
84
|
+
rule('special_char' => 'CARRIAGE RETURN').tag 'carriage_return'
|
|
85
|
+
rule('special_char' => 'WORD').tag 'word'
|
|
86
|
+
rule('special_char' => 'NO WORD').tag 'no_word'
|
|
87
|
+
rule('literal' => 'LITERALLY STRING_LIT').tag 'literally'
|
|
88
|
+
rule('raw' => 'RAW STRING_LIT').tag 'raw_literal'
|
|
89
|
+
rule('alternation' => 'any_or_either OF LPAREN alternatives RPAREN').tag 'any_of'
|
|
90
|
+
rule('alternatives' => 'alternatives separator quantifiable').tag 'alternative_list'
|
|
91
|
+
rule('alternatives' => 'quantifiable').tag 'simple_alternative'
|
|
92
|
+
rule('any_or_either' => 'ANY').tag 'any_keyword'
|
|
93
|
+
rule('any_or_either' => 'EITHER').tag 'either_keyword'
|
|
94
|
+
rule('grouping' => 'LPAREN pattern RPAREN').tag 'grouping_parenthenses'
|
|
95
|
+
rule('capturing_group' => 'CAPTURE assertable (UNTIL assertable)?').tag 'capture'
|
|
96
|
+
rule('capturing_group' => 'CAPTURE assertable AS var_name (UNTIL assertable)?').tag 'named_capture'
|
|
97
|
+
rule('var_name' => 'STRING_LIT').tag 'var_name'
|
|
98
|
+
rule('var_name' => 'IDENTIFIER').tag 'var_ident' # capture name not enclosed between quotes
|
|
99
|
+
rule('quantifier' => 'ONCE').tag 'once'
|
|
100
|
+
rule('quantifier' => 'TWICE').tag 'twice'
|
|
101
|
+
rule('quantifier' => 'EXACTLY count TIMES').tag 'exactly'
|
|
102
|
+
rule('quantifier' => 'BETWEEN count AND count TIMES?').tag 'between_and'
|
|
103
|
+
rule('quantifier' => 'OPTIONAL').tag 'optional'
|
|
104
|
+
rule('quantifier' => 'ONCE OR MORE').tag 'once_or_more'
|
|
105
|
+
rule('quantifier' => 'NEVER OR MORE').tag 'never_or_more'
|
|
106
|
+
rule('quantifier' => 'AT LEAST count TIMES').tag 'at_least'
|
|
107
|
+
rule('digit_or_number' => 'DIGIT').tag 'digit_keyword'
|
|
108
|
+
rule('digit_or_number' => 'NUMBER').tag 'number_keyword'
|
|
109
|
+
rule('count' => 'DIGIT_LIT').tag 'single_digit'
|
|
110
|
+
rule('count' => 'INTEGER').tag 'integer_count'
|
|
125
111
|
end
|
|
126
112
|
|
|
127
113
|
# And now build the grammar and make it accessible via a global constant
|
data/lib/srl_ruby/tokenizer.rb
CHANGED
|
@@ -17,10 +17,14 @@ module SrlRuby
|
|
|
17
17
|
# Delimiters: parentheses '(' and ')'
|
|
18
18
|
# Separators: comma (optional)
|
|
19
19
|
class Tokenizer
|
|
20
|
+
# @return [StringScanner]
|
|
20
21
|
attr_reader(:scanner)
|
|
22
|
+
|
|
23
|
+
# @return [Integer] current line number
|
|
21
24
|
attr_reader(:lineno)
|
|
25
|
+
|
|
26
|
+
# @return [Integer] offset of start of current line within input
|
|
22
27
|
attr_reader(:line_start)
|
|
23
|
-
# attr_reader(:column)
|
|
24
28
|
|
|
25
29
|
@@lexeme2name = {
|
|
26
30
|
'(' => 'LPAREN',
|
|
@@ -86,7 +90,7 @@ module SrlRuby
|
|
|
86
90
|
WHITESPACE
|
|
87
91
|
WITH
|
|
88
92
|
WORD
|
|
89
|
-
].map { |x| [x, x] }
|
|
93
|
+
].map { |x| [x, x] }.to_h
|
|
90
94
|
|
|
91
95
|
class ScanError < StandardError; end
|
|
92
96
|
|
data/lib/srl_ruby/version.rb
CHANGED
|
@@ -32,7 +32,7 @@ module Acceptance
|
|
|
32
32
|
Terminal2NodeClass
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
# rule('rule_file' =>
|
|
35
|
+
# rule('rule_file' => 'srl_heading tests').as 'start_rule'
|
|
36
36
|
def reduce_start_rule(_production, _range, _tokens, theChildren)
|
|
37
37
|
rule_file = RuleFileTests.new(theChildren[0])
|
|
38
38
|
tests = theChildren.last.flatten
|
|
@@ -54,16 +54,6 @@ module Acceptance
|
|
|
54
54
|
theChildren.last
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
# rule('srl_tests' => %w[srl_tests single_test]).as 'test_list'
|
|
58
|
-
def reduce_test_list(_production, _range, _tokens, theChildren)
|
|
59
|
-
theChildren[0] << theChildren[1]
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# rule('srl_tests' => 'single_test').as 'one_test'
|
|
63
|
-
def reduce_one_test(_production, _range, _tokens, theChildren)
|
|
64
|
-
[theChildren.last]
|
|
65
|
-
end
|
|
66
|
-
|
|
67
57
|
# rule('match_test' => %w[MATCH: STRING_LIT]).as 'match_string'
|
|
68
58
|
def reduce_match_string(_production, _range, _tokens, theChildren)
|
|
69
59
|
MatchTest.new(theChildren.last)
|
|
@@ -85,17 +75,6 @@ module Acceptance
|
|
|
85
75
|
theChildren[2]
|
|
86
76
|
end
|
|
87
77
|
|
|
88
|
-
# rule('capture_expectations' => %w[capture_expectations
|
|
89
|
-
# single_expectation]).as 'assertion_list'
|
|
90
|
-
def reduce_assertion_list(_production, _range, _tokens, theChildren)
|
|
91
|
-
theChildren[0] << theChildren[1]
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# rule('capture_expectations' => 'single_expectation').as 'one_expectation'
|
|
95
|
-
def reduce_one_expectation(_production, _range, _tokens, theChildren)
|
|
96
|
-
[theChildren.last]
|
|
97
|
-
end
|
|
98
|
-
|
|
99
78
|
# rule('single_expectation' => %w[DASH INTEGER COLON capture_variable
|
|
100
79
|
# COLON STRING_LIT]).as 'capture_expectation'
|
|
101
80
|
def reduce_capture_expectation(_production, _range, _tokens, theChildren)
|
|
@@ -6,37 +6,32 @@ require 'rley' # Load the Rley gem
|
|
|
6
6
|
# Grammar for Test-Rule files
|
|
7
7
|
# [File format](https://github.com/SimpleRegex/Test-Rules/blob/master/README.md)
|
|
8
8
|
########################################
|
|
9
|
-
|
|
10
|
-
builder = Rley::Syntax::GrammarBuilder.new do
|
|
9
|
+
builder = Rley::grammar_builder do
|
|
11
10
|
# Punctuation
|
|
12
11
|
add_terminals('COLON', 'DASH')
|
|
13
12
|
|
|
14
13
|
# Keywords
|
|
15
14
|
add_terminals('CAPTURE', 'FOR')
|
|
16
|
-
add_terminals('MATCH
|
|
15
|
+
add_terminals('MATCH', 'NO', 'SRL')
|
|
17
16
|
|
|
18
17
|
# Literals
|
|
19
18
|
add_terminals('INTEGER', 'STRING_LIT')
|
|
20
19
|
add_terminals('IDENTIFIER', 'SRL_SOURCE')
|
|
21
20
|
|
|
22
|
-
rule('rule_file' => 'srl_heading
|
|
23
|
-
rule('srl_heading' => 'SRL
|
|
24
|
-
rule('
|
|
25
|
-
rule('
|
|
26
|
-
rule('
|
|
27
|
-
rule('
|
|
28
|
-
rule('
|
|
29
|
-
rule('
|
|
30
|
-
rule('
|
|
31
|
-
rule('
|
|
32
|
-
rule('
|
|
33
|
-
rule('
|
|
34
|
-
rule('
|
|
35
|
-
rule('
|
|
36
|
-
rule('capture_expectations' => 'single_expectation').as 'one_expectation'
|
|
37
|
-
rule('single_expectation' => 'DASH INTEGER COLON capture_variable COLON STRING_LIT').as 'capture_expectation'
|
|
38
|
-
rule('capture_variable' => 'INTEGER').as 'var_integer'
|
|
39
|
-
rule('capture_variable' => 'IDENTIFIER').as 'var_identifier'
|
|
21
|
+
rule('rule_file' => 'srl_heading srl_test+').tag 'start_rule'
|
|
22
|
+
rule('srl_heading' => 'SRL SRL_SOURCE').tag 'srl_source'
|
|
23
|
+
rule('srl_test' => 'atomic_test').tag 'single_atomic_test'
|
|
24
|
+
rule('srl_test' => 'compound_test').tag 'single_compound_test'
|
|
25
|
+
rule('atomic_test' => 'match_test').tag 'atomic_match'
|
|
26
|
+
rule('atomic_test' => 'no_match_test').tag 'atomic_no_match'
|
|
27
|
+
rule('compound_test' => 'capture_test').tag 'compound_capture'
|
|
28
|
+
rule('match_test' => 'MATCH STRING_LIT').tag 'match_string'
|
|
29
|
+
rule('no_match_test' => 'NO MATCH STRING_LIT').tag 'no_match_string'
|
|
30
|
+
rule('capture_test' => 'capture_heading capture_expectation+').tag 'capture_test'
|
|
31
|
+
rule('capture_heading' => 'CAPTURE FOR STRING_LIT COLON').tag 'capture_string'
|
|
32
|
+
rule('capture_expectation' => 'DASH INTEGER COLON capture_variable COLON STRING_LIT').tag 'capture_expectation'
|
|
33
|
+
rule('capture_variable' => 'INTEGER').tag 'var_integer'
|
|
34
|
+
rule('capture_variable' => 'IDENTIFIER').tag 'var_identifier'
|
|
40
35
|
end
|
|
41
36
|
|
|
42
37
|
# And now build the grammar...
|
|
@@ -16,8 +16,13 @@ module Acceptance
|
|
|
16
16
|
# Delimiters: parentheses '(' and ')'
|
|
17
17
|
# Separators: comma (optional)
|
|
18
18
|
class RuleFileTokenizer
|
|
19
|
+
# @return [StringScanner]
|
|
19
20
|
attr_reader(:scanner)
|
|
21
|
+
|
|
22
|
+
# @return [Integer] current line number
|
|
20
23
|
attr_reader(:lineno)
|
|
24
|
+
|
|
25
|
+
# @return [Integer] offset of start of current line within input
|
|
21
26
|
attr_reader(:line_start)
|
|
22
27
|
|
|
23
28
|
# Can be :default, :expecting_srl
|
|
@@ -82,7 +87,7 @@ module Acceptance
|
|
|
82
87
|
elsif (lexeme = scanner.scan(/[0-9]+/))
|
|
83
88
|
token = build_token('INTEGER', lexeme)
|
|
84
89
|
elsif (lexeme = scanner.scan(/srl:|match:/))
|
|
85
|
-
token = build_token(@@keywords[lexeme], lexeme)
|
|
90
|
+
token = build_token(@@keywords[lexeme].chop, lexeme.chop)
|
|
86
91
|
@state = :expecting_srl if lexeme == 'srl:'
|
|
87
92
|
elsif (lexeme = scanner.scan(/[a-zA-Z_][a-zA-Z0-9_]*/))
|
|
88
93
|
keyw = @@keywords[lexeme]
|
|
@@ -6,6 +6,8 @@ require_relative '../../lib/regex/character'
|
|
|
6
6
|
|
|
7
7
|
module Regex # Open this namespace, to get rid of scope qualifiers
|
|
8
8
|
describe Character do
|
|
9
|
+
# rubocop: disable Lint/ConstantDefinitionInBlock
|
|
10
|
+
|
|
9
11
|
# This constant holds an arbitrary selection of characters
|
|
10
12
|
SampleChars = [?a, ?\0, ?\u0107].freeze
|
|
11
13
|
|
|
@@ -87,6 +89,8 @@ module Regex # Open this namespace, to get rid of scope qualifiers
|
|
|
87
89
|
|
|
88
90
|
# Try with our escape sequence samples
|
|
89
91
|
(SampleDigrams + SampleNumEscs).each do |escape_seq|
|
|
92
|
+
|
|
93
|
+
# Build a string from escape sequence literal
|
|
90
94
|
expectation = String.class_eval(%Q|"#{escape_seq}"|, __FILE__, __LINE__)
|
|
91
95
|
new_ch = Character.new(escape_seq).to_str
|
|
92
96
|
new_ch == expectation
|
|
@@ -111,11 +115,20 @@ module Regex # Open this namespace, to get rid of scope qualifiers
|
|
|
111
115
|
|
|
112
116
|
# Try with our escape sequence samples
|
|
113
117
|
(SampleDigrams + SampleNumEscs).each do |escape_seq|
|
|
118
|
+
|
|
119
|
+
# Get ordinal value of given escape sequence
|
|
114
120
|
expectation = String.class_eval(%Q|"#{escape_seq}".ord()|, __FILE__, __LINE__)
|
|
115
121
|
expect(Character.new(escape_seq).codepoint).to eq(expectation)
|
|
116
122
|
end
|
|
117
123
|
end
|
|
118
124
|
|
|
125
|
+
# Create a module that re-defines the existing to_s method
|
|
126
|
+
module Tweak_to_s
|
|
127
|
+
def to_s # Overwrite the existing to_s method
|
|
128
|
+
?\u03a3
|
|
129
|
+
end
|
|
130
|
+
end # module
|
|
131
|
+
|
|
119
132
|
it 'should known whether it is equal to another Object' do
|
|
120
133
|
newOne = Character.new(?\u03a3)
|
|
121
134
|
|
|
@@ -147,12 +160,6 @@ module Regex # Open this namespace, to get rid of scope qualifiers
|
|
|
147
160
|
expect(simulator).to receive(:to_s).and_return(?\u03a3)
|
|
148
161
|
expect(newOne).to eq(simulator)
|
|
149
162
|
|
|
150
|
-
# Create a module that re-defines the existing to_s method
|
|
151
|
-
module Tweak_to_s
|
|
152
|
-
def to_s # Overwrite the existing to_s method
|
|
153
|
-
?\u03a3
|
|
154
|
-
end
|
|
155
|
-
end # module
|
|
156
163
|
weird = Object.new
|
|
157
164
|
weird.extend(Tweak_to_s)
|
|
158
165
|
expect(newOne).to eq(weird)
|
|
@@ -166,6 +173,7 @@ module Regex # Open this namespace, to get rid of scope qualifiers
|
|
|
166
173
|
expect(ch2.explain).to eq("the character '\u03a3'")
|
|
167
174
|
end
|
|
168
175
|
end # context
|
|
176
|
+
# rubocop: enable Lint/ConstantDefinitionInBlock
|
|
169
177
|
end # describe
|
|
170
178
|
end # module
|
|
171
179
|
|
|
@@ -23,6 +23,7 @@ module Regex # This module is used as a namespace
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
context 'Provided services' do
|
|
26
|
+
# rubocop: disable Style/CombinableLoops
|
|
26
27
|
it 'should know its text representation' do
|
|
27
28
|
policy2text = { greedy: '', lazy: '?', possessive: '+' }
|
|
28
29
|
|
|
@@ -73,6 +74,7 @@ module Regex # This module is used as a namespace
|
|
|
73
74
|
end
|
|
74
75
|
end
|
|
75
76
|
end
|
|
77
|
+
# rubocop: enable Style/CombinableLoops
|
|
76
78
|
end
|
|
77
79
|
end
|
|
78
80
|
end # module
|
data/spec/srl_ruby_spec.rb
CHANGED
|
@@ -226,7 +226,7 @@ SRL
|
|
|
226
226
|
let(:prefix) { 'letter from p to t ' }
|
|
227
227
|
|
|
228
228
|
it "should parse 'once' syntax" do
|
|
229
|
-
regexp = SrlRuby.parse(prefix
|
|
229
|
+
regexp = SrlRuby.parse("#{prefix}once")
|
|
230
230
|
expect(regexp.source).to eq('[p-t]{1}')
|
|
231
231
|
end
|
|
232
232
|
|
|
@@ -246,26 +246,26 @@ SRL
|
|
|
246
246
|
end
|
|
247
247
|
|
|
248
248
|
it "should parse 'between ... and ... times' syntax" do
|
|
249
|
-
regexp = SrlRuby.parse(prefix
|
|
249
|
+
regexp = SrlRuby.parse("#{prefix}between 2 and 4 times")
|
|
250
250
|
expect(regexp.source).to eq('[p-t]{2,4}')
|
|
251
251
|
|
|
252
252
|
# Dropping 'times' keyword is a shorter alternative syntax
|
|
253
|
-
regexp = SrlRuby.parse(prefix
|
|
253
|
+
regexp = SrlRuby.parse("#{prefix}between 2 and 4")
|
|
254
254
|
expect(regexp.source).to eq('[p-t]{2,4}')
|
|
255
255
|
end
|
|
256
256
|
|
|
257
257
|
it "should parse 'once or more' syntax" do
|
|
258
|
-
regexp = SrlRuby.parse(prefix
|
|
258
|
+
regexp = SrlRuby.parse("#{prefix}once or more")
|
|
259
259
|
expect(regexp.source).to eq('[p-t]+')
|
|
260
260
|
end
|
|
261
261
|
|
|
262
262
|
it "should parse 'never or more' syntax" do
|
|
263
|
-
regexp = SrlRuby.parse(prefix
|
|
263
|
+
regexp = SrlRuby.parse("#{prefix}never or more")
|
|
264
264
|
expect(regexp.source).to eq('[p-t]*')
|
|
265
265
|
end
|
|
266
266
|
|
|
267
267
|
it "should parse 'at least ... times' syntax" do
|
|
268
|
-
regexp = SrlRuby.parse(prefix
|
|
268
|
+
regexp = SrlRuby.parse("#{prefix}at least 10 times")
|
|
269
269
|
expect(regexp.source).to eq('[p-t]{10,}')
|
|
270
270
|
end
|
|
271
271
|
end # context
|
data/srl_ruby.gemspec
CHANGED
|
@@ -65,13 +65,13 @@ SUMMARY
|
|
|
65
65
|
spec.require_paths = ['lib']
|
|
66
66
|
PkgExtending.pkg_files(spec)
|
|
67
67
|
PkgExtending.pkg_documentation(spec)
|
|
68
|
-
spec.required_ruby_version = '>= 2.
|
|
68
|
+
spec.required_ruby_version = '>= 2.5.0'
|
|
69
69
|
|
|
70
70
|
# Runtime dependencies
|
|
71
|
-
spec.add_dependency 'rley', '~> 0.
|
|
71
|
+
spec.add_dependency 'rley', '~> 0.8.08'
|
|
72
72
|
|
|
73
73
|
# Development dependencies
|
|
74
|
-
spec.add_development_dependency 'bundler', '~> 2.
|
|
74
|
+
spec.add_development_dependency 'bundler', '~> 2.2.0'
|
|
75
75
|
spec.add_development_dependency 'cucumber', '>= 2.2.0'
|
|
76
76
|
spec.add_development_dependency 'rake', '~> 12.0'
|
|
77
77
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: srl_ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dimitri Geshef
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-11-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rley
|
|
@@ -16,28 +16,28 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.
|
|
19
|
+
version: 0.8.08
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.
|
|
26
|
+
version: 0.8.08
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: bundler
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 2.
|
|
33
|
+
version: 2.2.0
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 2.
|
|
40
|
+
version: 2.2.0
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: cucumber
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -190,7 +190,7 @@ homepage: https://github.com/famished-tiger/SRL-Ruby
|
|
|
190
190
|
licenses:
|
|
191
191
|
- MIT
|
|
192
192
|
metadata: {}
|
|
193
|
-
post_install_message:
|
|
193
|
+
post_install_message:
|
|
194
194
|
rdoc_options:
|
|
195
195
|
- --charset=UTF-8 --exclude="examples|spec"
|
|
196
196
|
require_paths:
|
|
@@ -199,15 +199,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
199
199
|
requirements:
|
|
200
200
|
- - ">="
|
|
201
201
|
- !ruby/object:Gem::Version
|
|
202
|
-
version: 2.
|
|
202
|
+
version: 2.5.0
|
|
203
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
204
|
requirements:
|
|
205
205
|
- - ">="
|
|
206
206
|
- !ruby/object:Gem::Version
|
|
207
207
|
version: '0'
|
|
208
208
|
requirements: []
|
|
209
|
-
rubygems_version: 3.
|
|
210
|
-
signing_key:
|
|
209
|
+
rubygems_version: 3.1.4
|
|
210
|
+
signing_key:
|
|
211
211
|
specification_version: 4
|
|
212
212
|
summary: A parser for the [Simple Regex Language](https://simple-regex.com/). It translates
|
|
213
213
|
patterns expressed in SRL into plain Ruby Regexp objects or in regex literals. Use
|