srl_ruby 0.3.5 → 0.4.0
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 +9 -3
- data/CHANGELOG.md +20 -0
- data/README.md +326 -52
- data/bin/srl2ruby +95 -0
- data/bin/srl2ruby_cli_parser.rb +89 -0
- data/lib/regex/abstract_method.rb +1 -1
- data/lib/regex/alternation.rb +1 -1
- data/lib/regex/anchor.rb +3 -3
- data/lib/regex/atomic_expression.rb +2 -2
- data/lib/regex/capturing_group.rb +3 -3
- data/lib/regex/char_class.rb +5 -5
- data/lib/regex/char_range.rb +5 -5
- data/lib/regex/char_shorthand.rb +2 -2
- data/lib/regex/character.rb +6 -6
- data/lib/regex/compound_expression.rb +2 -2
- data/lib/regex/concatenation.rb +3 -3
- data/lib/regex/expression.rb +4 -4
- data/lib/regex/lookaround.rb +1 -1
- data/lib/regex/match_option.rb +2 -2
- data/lib/regex/monadic_expression.rb +3 -3
- data/lib/regex/multiplicity.rb +1 -1
- data/lib/regex/non_capturing_group.rb +1 -1
- data/lib/regex/polyadic_expression.rb +3 -3
- data/lib/regex/repetition.rb +2 -2
- data/lib/regex/wildcard.rb +3 -3
- data/lib/srl_ruby/ast_builder.rb +22 -22
- data/lib/srl_ruby/srl_token.rb +1 -1
- data/lib/srl_ruby/tokenizer.rb +7 -7
- data/lib/srl_ruby/version.rb +1 -1
- data/spec/acceptance/srl_test_suite_spec.rb +1 -1
- data/spec/acceptance/support/rule_file_ast_builder.rb +8 -8
- data/spec/acceptance/support/rule_file_token.rb +1 -1
- data/spec/acceptance/support/rule_file_tokenizer.rb +8 -8
- data/spec/regex/character_spec.rb +30 -30
- data/spec/regex/multiplicity_spec.rb +24 -24
- data/srl_ruby.gemspec +8 -5
- data/templates/base.erb +2 -0
- data/templates/srl_and_ruby.erb +9 -0
- data/templates/srl_block_and_ruby.erb +10 -0
- metadata +8 -4
- data/bin/srl_ruby +0 -51
data/lib/regex/alternation.rb
CHANGED
@@ -15,7 +15,7 @@ module Regex # This module is used as a namespace
|
|
15
15
|
|
16
16
|
# Conversion method re-definition.
|
17
17
|
# Purpose: Return the String representation of the concatented expressions.
|
18
|
-
def text_repr
|
18
|
+
def text_repr
|
19
19
|
result_children = children.map(&:to_str)
|
20
20
|
result = '(?:' + result_children.join('|') + ')'
|
21
21
|
|
data/lib/regex/anchor.rb
CHANGED
@@ -29,15 +29,15 @@ module Regex # This module is used as a namespace
|
|
29
29
|
|
30
30
|
# Conversion method re-definition.
|
31
31
|
# Purpose: Return the String representation of the expression.
|
32
|
-
def to_str
|
33
|
-
|
32
|
+
def to_str
|
33
|
+
AnchorToSymbol.rassoc(kind).first
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
37
37
|
|
38
38
|
# Return the symbolic value corresponding to the given lexeme.
|
39
39
|
def valid_kind(aKind)
|
40
|
-
|
40
|
+
AnchorToSymbol[aKind]
|
41
41
|
end
|
42
42
|
end # class
|
43
43
|
end # module
|
@@ -13,12 +13,12 @@ module Regex # This module is used as a namespace
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# Notification that the parse tree construction is complete.
|
16
|
-
def done!
|
16
|
+
def done!
|
17
17
|
# Do nothing
|
18
18
|
end
|
19
19
|
|
20
20
|
# Notification that all quantifiers are lazy
|
21
|
-
def lazy!
|
21
|
+
def lazy!
|
22
22
|
# Do nothing
|
23
23
|
end
|
24
24
|
end # class
|
@@ -29,13 +29,13 @@ module Regex # This module is used as a namespace
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# Return true iff the capturing group has a name
|
32
|
-
def named?
|
33
|
-
|
32
|
+
def named?
|
33
|
+
id.kind_of?(String)
|
34
34
|
end
|
35
35
|
|
36
36
|
# Conversion method re-definition.
|
37
37
|
# Purpose: Return the String representation of the captured expression.
|
38
|
-
def to_str
|
38
|
+
def to_str
|
39
39
|
prefix = named? ? "?<#{id}>" : ''
|
40
40
|
atomic = no_backtrack ? '?>' : ''
|
41
41
|
if child.is_a?(Regex::NonCapturingGroup)
|
data/lib/regex/char_class.rb
CHANGED
@@ -21,12 +21,12 @@ module Regex # This module is used as a namespace
|
|
21
21
|
|
22
22
|
# Conversion method re-definition.
|
23
23
|
# Purpose: Return the String representation of the character class.
|
24
|
-
def text_repr
|
25
|
-
result_children = children.inject('') do |
|
26
|
-
if
|
27
|
-
|
24
|
+
def text_repr
|
25
|
+
result_children = children.inject('') do |sub_result, child|
|
26
|
+
if child.kind_of?(Regex::Character) && Metachars.include?(child.codepoint)
|
27
|
+
sub_result << '\\' # Escape meta-character...
|
28
28
|
end
|
29
|
-
|
29
|
+
sub_result << child.to_str
|
30
30
|
end
|
31
31
|
result = '[' + (negated ? '^' : '') + result_children + ']'
|
32
32
|
|
data/lib/regex/char_range.rb
CHANGED
@@ -18,20 +18,20 @@ module Regex # This module is used as a namespace
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# Return the lower bound of the range.
|
21
|
-
def lower
|
22
|
-
|
21
|
+
def lower
|
22
|
+
children.first
|
23
23
|
end
|
24
24
|
|
25
25
|
# Return the upper bound of the range.
|
26
|
-
def upper
|
27
|
-
|
26
|
+
def upper
|
27
|
+
children.last
|
28
28
|
end
|
29
29
|
|
30
30
|
protected
|
31
31
|
|
32
32
|
# Conversion method re-definition.
|
33
33
|
# Purpose: Return the String representation of the concatented expressions.
|
34
|
-
def text_repr
|
34
|
+
def text_repr
|
35
35
|
result = lower.to_str + '-' + upper.to_str
|
36
36
|
|
37
37
|
return result
|
data/lib/regex/char_shorthand.rb
CHANGED
@@ -31,8 +31,8 @@ module Regex # This module is used as a namespace
|
|
31
31
|
|
32
32
|
# Conversion method re-definition.
|
33
33
|
# Purpose: Return the String representation of the expression.
|
34
|
-
def text_repr
|
35
|
-
|
34
|
+
def text_repr
|
35
|
+
"\\#{shortname}"
|
36
36
|
end
|
37
37
|
|
38
38
|
private
|
data/lib/regex/character.rb
CHANGED
@@ -80,14 +80,14 @@ module Regex # This module is used as a namespace
|
|
80
80
|
# RegAn::Character::codepoint2char(0x3a3) # Returns: Σ (
|
81
81
|
# The Unicode GREEK CAPITAL LETTER SIGMA)
|
82
82
|
def self.codepoint2char(aCodepoint)
|
83
|
-
|
83
|
+
[aCodepoint].pack('U') # Remark: chr() fails with codepoints > 256
|
84
84
|
end
|
85
85
|
|
86
86
|
# Convertion method that returns the codepoint for the given single character.
|
87
87
|
# Example:
|
88
88
|
# RegAn::Character::char2codepoint('Σ') # Returns: 0x3a3
|
89
89
|
def self.char2codepoint(aChar)
|
90
|
-
|
90
|
+
aChar.ord
|
91
91
|
end
|
92
92
|
|
93
93
|
# Convertion method that returns the codepoint for the given escape
|
@@ -109,7 +109,7 @@ module Regex # This module is used as a namespace
|
|
109
109
|
end
|
110
110
|
|
111
111
|
# Return the character as a String object
|
112
|
-
def char
|
112
|
+
def char
|
113
113
|
self.class.codepoint2char(@codepoint)
|
114
114
|
end
|
115
115
|
|
@@ -142,8 +142,8 @@ module Regex # This module is used as a namespace
|
|
142
142
|
end
|
143
143
|
|
144
144
|
# Return a plain English description of the character
|
145
|
-
def explain
|
146
|
-
|
145
|
+
def explain
|
146
|
+
"the character '#{to_str}'"
|
147
147
|
end
|
148
148
|
|
149
149
|
protected
|
@@ -153,7 +153,7 @@ module Regex # This module is used as a namespace
|
|
153
153
|
# If the Character was initially from a text (the lexeme), then the lexeme
|
154
154
|
# is returned back.
|
155
155
|
# Otherwise the character corresponding to the codepoint is returned.
|
156
|
-
def text_repr
|
156
|
+
def text_repr
|
157
157
|
return char if lexeme.nil?
|
158
158
|
return lexeme.dup
|
159
159
|
end
|
@@ -8,7 +8,7 @@ module Regex # This module is used as a namespace
|
|
8
8
|
class CompoundExpression < Expression
|
9
9
|
# Redefined method. Return false since it may have one or more children.
|
10
10
|
def atomic?
|
11
|
-
|
11
|
+
false
|
12
12
|
end
|
13
13
|
|
14
14
|
=begin
|
@@ -48,7 +48,7 @@ module Regex # This module is used as a namespace
|
|
48
48
|
protected
|
49
49
|
|
50
50
|
# Abstract method. Return the text representation of the child (if any)
|
51
|
-
def all_child_text
|
51
|
+
def all_child_text
|
52
52
|
abstract_method
|
53
53
|
end
|
54
54
|
end # class
|
data/lib/regex/concatenation.rb
CHANGED
@@ -16,9 +16,9 @@ module Regex # This module is used as a namespace
|
|
16
16
|
|
17
17
|
# Conversion method re-definition.
|
18
18
|
# Purpose: Return the String representation of the concatented expressions.
|
19
|
-
def text_repr
|
20
|
-
outcome = children.inject('') do |result,
|
21
|
-
result <<
|
19
|
+
def text_repr
|
20
|
+
outcome = children.inject('') do |result, child|
|
21
|
+
result << child.to_str
|
22
22
|
end
|
23
23
|
|
24
24
|
return outcome
|
data/lib/regex/expression.rb
CHANGED
@@ -14,7 +14,7 @@ module Regex # This module is used as a namespace
|
|
14
14
|
# Abstract method. Return true iff the expression is atomic
|
15
15
|
# (= doesn't not have any child).
|
16
16
|
# @return [Boolean]
|
17
|
-
def atomic?
|
17
|
+
def atomic?
|
18
18
|
abstract_method
|
19
19
|
end
|
20
20
|
|
@@ -30,7 +30,7 @@ module Regex # This module is used as a namespace
|
|
30
30
|
|
31
31
|
# Template method.
|
32
32
|
# @return [String] text representation of the expression.
|
33
|
-
def to_str
|
33
|
+
def to_str
|
34
34
|
result = ''
|
35
35
|
result << prefix
|
36
36
|
result << text_repr
|
@@ -41,11 +41,11 @@ module Regex # This module is used as a namespace
|
|
41
41
|
|
42
42
|
protected
|
43
43
|
|
44
|
-
def prefix
|
44
|
+
def prefix
|
45
45
|
begin_anchor ? begin_anchor.to_str : ''
|
46
46
|
end
|
47
47
|
|
48
|
-
def suffix
|
48
|
+
def suffix
|
49
49
|
end_anchor ? end_anchor.to_str : ''
|
50
50
|
end
|
51
51
|
end # class
|
data/lib/regex/lookaround.rb
CHANGED
@@ -37,7 +37,7 @@ module Regex # This module is used as a namespace
|
|
37
37
|
|
38
38
|
# Conversion method re-definition.
|
39
39
|
# Purpose: Return the String representation of the captured expression.
|
40
|
-
def to_str
|
40
|
+
def to_str
|
41
41
|
dir_syntax = (dir == :ahead) ? '' : '<'
|
42
42
|
kind_syntax = (kind == :positive) ? '=' : '!'
|
43
43
|
result = '(?' + dir_syntax + kind_syntax + child.to_str + ')'
|
data/lib/regex/match_option.rb
CHANGED
@@ -20,7 +20,7 @@ module Regex # This module is used as a namespace
|
|
20
20
|
# Combine all options/flags into one integer value that
|
21
21
|
# is compliant as second argument of with Regexp#new method.
|
22
22
|
# return [Integer]
|
23
|
-
def combine_opts
|
23
|
+
def combine_opts
|
24
24
|
result = 0
|
25
25
|
flags.each { |f| result |= f }
|
26
26
|
|
@@ -45,7 +45,7 @@ module Regex # This module is used as a namespace
|
|
45
45
|
|
46
46
|
# Conversion method re-definition.
|
47
47
|
# Purpose: Return the String representation of the concatented expressions.
|
48
|
-
def text_repr
|
48
|
+
def text_repr
|
49
49
|
all_child_text
|
50
50
|
end
|
51
51
|
end # class
|
@@ -17,19 +17,19 @@ module Regex # This module is used as a namespace
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# Notification that the parse tree construction is complete.
|
20
|
-
def done!
|
20
|
+
def done!
|
21
21
|
child.done!
|
22
22
|
end
|
23
23
|
|
24
24
|
# Notification that all quantifiers are lazy
|
25
|
-
def lazy!
|
25
|
+
def lazy!
|
26
26
|
child.lazy!
|
27
27
|
end
|
28
28
|
|
29
29
|
protected
|
30
30
|
|
31
31
|
# Return the text representation of the child (if any)
|
32
|
-
def all_child_text
|
32
|
+
def all_child_text
|
33
33
|
result = child.nil? ? '' : child.to_str
|
34
34
|
|
35
35
|
return result
|
data/lib/regex/multiplicity.rb
CHANGED
@@ -19,7 +19,7 @@ module Regex # This module is used as a namespace
|
|
19
19
|
|
20
20
|
# Conversion method re-definition.
|
21
21
|
# Purpose: Return the String representation of the captured expression.
|
22
|
-
def text_repr
|
22
|
+
def text_repr
|
23
23
|
result = '(?:' + all_child_text + ')'
|
24
24
|
return result
|
25
25
|
end
|
@@ -26,7 +26,7 @@ module Regex # This module is used as a namespace
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# Notification that the parse tree construction is complete.
|
29
|
-
def done!
|
29
|
+
def done!
|
30
30
|
children.each(&:done!)
|
31
31
|
children.each_with_index do |child, index|
|
32
32
|
break if index == children.size - 1
|
@@ -40,13 +40,13 @@ module Regex # This module is used as a namespace
|
|
40
40
|
end
|
41
41
|
|
42
42
|
# Apply the 'lazy' option to the child elements
|
43
|
-
def lazy!
|
43
|
+
def lazy!
|
44
44
|
children.each(&:lazy!)
|
45
45
|
end
|
46
46
|
|
47
47
|
# Build a depth-first in-order children visitor.
|
48
48
|
# The visitor is implemented as an Enumerator.
|
49
|
-
def df_visitor
|
49
|
+
def df_visitor
|
50
50
|
root = children # The visit will start from the children of this object
|
51
51
|
|
52
52
|
visitor = Enumerator.new do |result| # result is a Yielder
|
data/lib/regex/repetition.rb
CHANGED
@@ -18,7 +18,7 @@ module Regex # This module is used as a namespace
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# Apply the `lazy` flag.
|
21
|
-
def lazy!
|
21
|
+
def lazy!
|
22
22
|
multiplicity.policy = :lazy
|
23
23
|
super
|
24
24
|
end
|
@@ -27,7 +27,7 @@ module Regex # This module is used as a namespace
|
|
27
27
|
|
28
28
|
# Conversion method re-definition.
|
29
29
|
# @return [String] String representation of the concatented expressions.
|
30
|
-
def text_repr
|
30
|
+
def text_repr
|
31
31
|
result = all_child_text + multiplicity.to_str
|
32
32
|
return result
|
33
33
|
end
|
data/lib/regex/wildcard.rb
CHANGED
@@ -6,7 +6,7 @@ module Regex # This module is used as a namespace
|
|
6
6
|
# A wildcard matches any character (except for the newline).
|
7
7
|
class Wildcard < AtomicExpression
|
8
8
|
# Constructor
|
9
|
-
def initialize
|
9
|
+
def initialize
|
10
10
|
super
|
11
11
|
end
|
12
12
|
|
@@ -14,8 +14,8 @@ module Regex # This module is used as a namespace
|
|
14
14
|
|
15
15
|
# Conversion method re-definition.
|
16
16
|
# Purpose: Return the String representation of the expression.
|
17
|
-
def text_repr
|
18
|
-
|
17
|
+
def text_repr
|
18
|
+
'.'
|
19
19
|
end
|
20
20
|
end # class
|
21
21
|
end # module
|
data/lib/srl_ruby/ast_builder.rb
CHANGED
@@ -22,18 +22,18 @@ module SrlRuby
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# Notification that the parse tree construction is complete.
|
25
|
-
def done!
|
25
|
+
def done!
|
26
26
|
apply_options
|
27
27
|
super
|
28
28
|
end
|
29
29
|
|
30
30
|
protected
|
31
31
|
|
32
|
-
def terminal2node
|
32
|
+
def terminal2node
|
33
33
|
Terminal2NodeClass
|
34
34
|
end
|
35
35
|
|
36
|
-
def apply_options
|
36
|
+
def apply_options
|
37
37
|
tree_root = result.root
|
38
38
|
regexp_opts = []
|
39
39
|
options.each do |opt|
|
@@ -100,16 +100,16 @@ module SrlRuby
|
|
100
100
|
Regex::CharShorthand.new(shortName)
|
101
101
|
end
|
102
102
|
|
103
|
-
def wildcard
|
103
|
+
def wildcard
|
104
104
|
Regex::Wildcard.new
|
105
105
|
end
|
106
106
|
|
107
107
|
def repetition(expressionToRepeat, aMultiplicity)
|
108
|
-
|
108
|
+
Regex::Repetition.new(expressionToRepeat, aMultiplicity)
|
109
109
|
end
|
110
110
|
|
111
111
|
def begin_anchor
|
112
|
-
|
112
|
+
Regex::Anchor.new('^')
|
113
113
|
end
|
114
114
|
|
115
115
|
# rule('expression' => %w[pattern flags]).as 'flagged_expr'
|
@@ -120,7 +120,7 @@ module SrlRuby
|
|
120
120
|
|
121
121
|
# rule('pattern' => %w[pattern separator sub_pattern]).as 'pattern_sequence'
|
122
122
|
def reduce_pattern_sequence(_production, _range, _tokens, theChildren)
|
123
|
-
|
123
|
+
Regex::Concatenation.new(theChildren[0], theChildren[2])
|
124
124
|
end
|
125
125
|
|
126
126
|
# rule('pattern' => 'sub_pattern').as 'basic_pattern'
|
@@ -145,27 +145,27 @@ module SrlRuby
|
|
145
145
|
|
146
146
|
# rule('single_flag' => %w[CASE INSENSITIVE]).as 'case_insensitive'
|
147
147
|
def reduce_case_insensitive(_production, _range, _tokens, _children)
|
148
|
-
|
148
|
+
Regexp::IGNORECASE
|
149
149
|
end
|
150
150
|
|
151
151
|
# rule('single_flag' => %w[MULTI LINE]).as 'multi_line'
|
152
152
|
def reduce_multi_line(_production, _range, _tokens, _children)
|
153
|
-
|
153
|
+
Regexp::MULTILINE
|
154
154
|
end
|
155
155
|
|
156
156
|
# rule('single_flag' => %w[ALL LAZY]).as 'all_lazy'
|
157
157
|
def reduce_all_lazy(_production, _range, _tokens, _children)
|
158
|
-
|
158
|
+
:ALL_LAZY
|
159
159
|
end
|
160
160
|
|
161
161
|
# rule 'quantifiable' => %w[begin_anchor anchorable end_anchor]
|
162
162
|
def reduce_pinned_quantifiable(_production, _range, _tokens, theChildren)
|
163
|
-
|
163
|
+
Regex::Concatenation.new(*theChildren)
|
164
164
|
end
|
165
165
|
|
166
166
|
# rule 'quantifiable' => %w[begin_anchor anchorable]
|
167
167
|
def reduce_begin_anchor_quantifiable(_production, _range, _tokens, theChildren)
|
168
|
-
|
168
|
+
Regex::Concatenation.new(*theChildren)
|
169
169
|
end
|
170
170
|
|
171
171
|
# rule 'quantifiable' => %w[anchorable end_anchor]
|
@@ -185,27 +185,27 @@ module SrlRuby
|
|
185
185
|
|
186
186
|
# rule('end_anchor' => %w[separator MUST END]).as 'end_anchor'
|
187
187
|
def reduce_end_anchor(_production, _range, _tokens, _children)
|
188
|
-
|
188
|
+
Regex::Anchor.new('$')
|
189
189
|
end
|
190
190
|
|
191
191
|
# rule('assertion' => %w[IF FOLLOWED BY assertable]).as 'if_followed'
|
192
192
|
def reduce_if_followed(_production, _range, _tokens, theChildren)
|
193
|
-
|
193
|
+
Regex::Lookaround.new(theChildren.last, :ahead, :positive)
|
194
194
|
end
|
195
195
|
|
196
196
|
# rule('assertion' => %w[IF NOT FOLLOWED BY assertable]).as 'if_not_followed'
|
197
197
|
def reduce_if_not_followed(_production, _range, _tokens, theChildren)
|
198
|
-
|
198
|
+
Regex::Lookaround.new(theChildren.last, :ahead, :negative)
|
199
199
|
end
|
200
200
|
|
201
201
|
# rule('assertion' => %w[IF ALREADY HAD assertable]).as 'if_had'
|
202
202
|
def reduce_if_had(_production, _range, _tokens, theChildren)
|
203
|
-
|
203
|
+
Regex::Lookaround.new(theChildren.last, :behind, :positive)
|
204
204
|
end
|
205
205
|
|
206
206
|
# rule('assertion' => %w[IF NOT ALREADY HAD assertable]).as 'if_not_had'
|
207
207
|
def reduce_if_not_had(_production, _range, _tokens, theChildren)
|
208
|
-
|
208
|
+
Regex::Lookaround.new(theChildren.last, :behind, :negative)
|
209
209
|
end
|
210
210
|
|
211
211
|
# rule('assertable' => %w[term quantifier]).as 'quantified_assertable'
|
@@ -384,17 +384,17 @@ module SrlRuby
|
|
384
384
|
|
385
385
|
# rule('alternatives' => 'quantifiable').as 'simple_alternative'
|
386
386
|
def reduce_simple_alternative(_production, _range, _tokens, theChildren)
|
387
|
-
|
387
|
+
[theChildren.last]
|
388
388
|
end
|
389
389
|
|
390
390
|
# rule('grouping' => %w[LPAREN pattern RPAREN]).as 'grouping_parenthenses'
|
391
391
|
def reduce_grouping_parenthenses(_production, _range, _tokens, theChildren)
|
392
|
-
|
392
|
+
Regex::NonCapturingGroup.new(theChildren[1])
|
393
393
|
end
|
394
394
|
|
395
395
|
# rule('capturing_group' => %w[CAPTURE assertable]).as 'capture'
|
396
396
|
def reduce_capture(_production, _range, _tokens, theChildren)
|
397
|
-
|
397
|
+
Regex::CapturingGroup.new(theChildren[1])
|
398
398
|
end
|
399
399
|
|
400
400
|
# If the rightmost (sub)expression is a repetition, then make it lazy
|
@@ -491,12 +491,12 @@ module SrlRuby
|
|
491
491
|
|
492
492
|
# rule('times_suffix' => 'TIMES').as 'times_keyword'
|
493
493
|
def reduce_times_keyword(_production, _range, _tokens, _children)
|
494
|
-
|
494
|
+
nil
|
495
495
|
end
|
496
496
|
|
497
497
|
# rule('times_suffix' => []).as 'times_dropped'
|
498
498
|
def reduce_times_dropped(_production, _range, _tokens, _children)
|
499
|
-
|
499
|
+
nil
|
500
500
|
end
|
501
501
|
end # class
|
502
502
|
end # module
|
data/lib/srl_ruby/srl_token.rb
CHANGED
data/lib/srl_ruby/tokenizer.rb
CHANGED
@@ -96,7 +96,7 @@ module SrlRuby
|
|
96
96
|
@line_start = 0
|
97
97
|
end
|
98
98
|
|
99
|
-
def tokens
|
99
|
+
def tokens
|
100
100
|
tok_sequence = []
|
101
101
|
until @scanner.eos?
|
102
102
|
token = _next_token
|
@@ -108,7 +108,7 @@ module SrlRuby
|
|
108
108
|
|
109
109
|
private
|
110
110
|
|
111
|
-
def _next_token
|
111
|
+
def _next_token
|
112
112
|
skip_whitespaces
|
113
113
|
curr_ch = scanner.peek(1)
|
114
114
|
return nil if curr_ch.nil? || curr_ch.empty?
|
@@ -118,9 +118,9 @@ module SrlRuby
|
|
118
118
|
if '(),'.include? curr_ch
|
119
119
|
# Delimiters, separators => single character token
|
120
120
|
token = build_token(@@lexeme2name[curr_ch], scanner.getch)
|
121
|
-
elsif (lexeme = scanner.scan(/[0-9]{2,}((?=\s
|
121
|
+
elsif (lexeme = scanner.scan(/[0-9]{2,}((?=\s|,|\))|$)/))
|
122
122
|
token = build_token('INTEGER', lexeme) # An integer has 2..* digits
|
123
|
-
elsif (lexeme = scanner.scan(/[0-9]((?=\s
|
123
|
+
elsif (lexeme = scanner.scan(/[0-9]((?=\s|,|\))|$)/))
|
124
124
|
token = build_token('DIGIT_LIT', lexeme)
|
125
125
|
elsif (lexeme = scanner.scan(/"(?:\\"|[^"])*"/)) # Double quotes literal?
|
126
126
|
unquoted = lexeme.gsub(/(^")|("$)/, '')
|
@@ -128,7 +128,7 @@ module SrlRuby
|
|
128
128
|
elsif (lexeme = scanner.scan(/'(?:\\'|[^'])*'/)) # Single quotes literal?
|
129
129
|
unquoted = lexeme.gsub(/(^')|('$)/, '')
|
130
130
|
token = build_token('STRING_LIT', unquoted)
|
131
|
-
elsif (lexeme = scanner.scan(/[a-zA-Z]((?=\s
|
131
|
+
elsif (lexeme = scanner.scan(/[a-zA-Z]((?=\s|,|\))|$)/))
|
132
132
|
token = build_token('LETTER_LIT', lexeme)
|
133
133
|
elsif (lexeme = scanner.scan(/[a-zA-Z_][a-zA-Z0-9_]+/))
|
134
134
|
keyw = @@keywords[lexeme.upcase]
|
@@ -159,7 +159,7 @@ module SrlRuby
|
|
159
159
|
return token
|
160
160
|
end
|
161
161
|
|
162
|
-
def skip_whitespaces
|
162
|
+
def skip_whitespaces
|
163
163
|
pre_pos = scanner.pos
|
164
164
|
|
165
165
|
loop do
|
@@ -186,7 +186,7 @@ module SrlRuby
|
|
186
186
|
# @column += triplet[2].size + tab_count * (tab_size - 1) - 1
|
187
187
|
end
|
188
188
|
|
189
|
-
def tab_size
|
189
|
+
def tab_size
|
190
190
|
2
|
191
191
|
end
|
192
192
|
end # class
|
data/lib/srl_ruby/version.rb
CHANGED
@@ -20,13 +20,13 @@ module Acceptance
|
|
20
20
|
|
21
21
|
attr_reader :options
|
22
22
|
|
23
|
-
def done!
|
23
|
+
def done!
|
24
24
|
# Do nothing!
|
25
25
|
end
|
26
26
|
|
27
27
|
protected
|
28
28
|
|
29
|
-
def terminal2node
|
29
|
+
def terminal2node
|
30
30
|
Terminal2NodeClass
|
31
31
|
end
|
32
32
|
|
@@ -49,17 +49,17 @@ module Acceptance
|
|
49
49
|
|
50
50
|
# rule('srl_heading' => %w[SRL: SRL_SOURCE]).as 'srl_source'
|
51
51
|
def reduce_srl_source(_production, _range, _tokens, theChildren)
|
52
|
-
|
52
|
+
theChildren.last
|
53
53
|
end
|
54
54
|
|
55
55
|
# rule('srl_tests' => %w[srl_tests single_test]).as 'test_list'
|
56
56
|
def reduce_test_list(_production, _range, _tokens, theChildren)
|
57
|
-
|
57
|
+
theChildren[0] << theChildren[1]
|
58
58
|
end
|
59
59
|
|
60
60
|
# rule('srl_tests' => 'single_test').as 'one_test'
|
61
61
|
def reduce_one_test(_production, _range, _tokens, theChildren)
|
62
|
-
|
62
|
+
[theChildren.last]
|
63
63
|
end
|
64
64
|
|
65
65
|
# rule('match_test' => %w[MATCH: STRING_LIT]).as 'match_string'
|
@@ -80,18 +80,18 @@ module Acceptance
|
|
80
80
|
|
81
81
|
# rule('capture_heading' => %w[CAPTURE FOR STRING_LIT COLON]).as 'capture_string'
|
82
82
|
def reduce_capture_string(_production, _range, _tokens, theChildren)
|
83
|
-
|
83
|
+
theChildren[2]
|
84
84
|
end
|
85
85
|
|
86
86
|
# rule('capture_expectations' => %w[capture_expectations
|
87
87
|
# single_expectation]).as 'assertion_list'
|
88
88
|
def reduce_assertion_list(_production, _range, _tokens, theChildren)
|
89
|
-
|
89
|
+
theChildren[0] << theChildren[1]
|
90
90
|
end
|
91
91
|
|
92
92
|
# rule('capture_expectations' => 'single_expectation').as 'one_expectation'
|
93
93
|
def reduce_one_expectation(_production, _range, _tokens, theChildren)
|
94
|
-
|
94
|
+
[theChildren.last]
|
95
95
|
end
|
96
96
|
|
97
97
|
# rule('single_expectation' => %w[DASH INTEGER COLON capture_variable
|