srl_ruby 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +167 -9
- data/CHANGELOG.md +5 -0
- data/lib/regex/character.rb +2 -2
- data/lib/regex/raw_expression.rb +2 -2
- data/lib/srl_ruby/tokenizer.rb +8 -4
- data/lib/srl_ruby/version.rb +1 -1
- data/spec/acceptance/support/rule_file_tokenizer.rb +1 -1
- data/spec/regex/character_spec.rb +170 -166
- data/spec/srl_ruby/tokenizer_spec.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75b3f62195385724cef744d9d066001cacb56da7
|
4
|
+
data.tar.gz: c987288da96445ada26f5b115e1b9e64e5062fbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 288976a2ff3ce17282af5c74385c84ccd8a318626c773a6c567953e9937f9ef7c146af941646a7f426fea08b2072c88d2385dd1a13ed7b217e38dd7400a4cbb7
|
7
|
+
data.tar.gz: 2321788937a965131c417acdb731d7d5a1278790cd2e2933b5e163296272acb2a526d0add3fc080041836b2ba1224f11429fd2c65055b30c072fcc58cb8c35b6
|
data/.rubocop.yml
CHANGED
@@ -1,31 +1,189 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
|
-
- 'exp/**/*'
|
3
|
+
- 'exp/**/*'
|
4
|
+
|
5
|
+
Layout/CaseIndentation:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Layout/CommentIndentation:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Layout/ElseAlignment:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Layout/EmptyLines:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Layout/EndAlignment:
|
18
|
+
Enabled: false
|
4
19
|
|
5
20
|
Layout/EndOfLine:
|
6
21
|
Enabled: true
|
7
22
|
EnforcedStyle: lf
|
8
|
-
|
23
|
+
|
24
|
+
Layout/IndentationWidth:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Layout/IndentationConsistency:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Layout/MultilineHashBraceLayout:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Layout/SpaceAroundOperators:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Layout/SpaceInsideParens:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Layout/Tab:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
Layout/TrailingBlankLines:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Layout/TrailingWhitespace:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Lint/Loop:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
Lint/RescueException:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Lint/UnusedMethodArgument:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Lint/UselessAccessModifier:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Lint/Void:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Lint/UselessAssignment:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Metrics/AbcSize:
|
67
|
+
Enabled: false
|
68
|
+
|
9
69
|
Metrics/BlockLength:
|
10
70
|
Enabled: true
|
11
71
|
Max: 300
|
12
|
-
|
72
|
+
|
73
|
+
Metrics/ClassLength:
|
74
|
+
Enabled: true
|
75
|
+
Max: 300
|
76
|
+
|
77
|
+
Metrics/CyclomaticComplexity:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
Metrics/LineLength:
|
81
|
+
Enabled: false
|
82
|
+
Max: 90
|
83
|
+
|
13
84
|
Metrics/MethodLength:
|
14
85
|
Enabled: true
|
15
|
-
Max:
|
16
|
-
|
86
|
+
Max: 40
|
87
|
+
|
17
88
|
Metrics/ModuleLength:
|
18
89
|
Enabled: true
|
19
90
|
Max: 500
|
20
|
-
|
91
|
+
|
92
|
+
Metrics/PerceivedComplexity:
|
93
|
+
Enabled: false
|
94
|
+
|
21
95
|
Naming/ConstantName:
|
22
96
|
Enabled: false
|
97
|
+
|
98
|
+
Naming/ClassAndModuleCamelCase:
|
99
|
+
Enabled: false
|
23
100
|
|
24
|
-
Naming/
|
101
|
+
Naming/UncommunicativeBlockParamName:
|
25
102
|
Enabled: false
|
26
103
|
|
104
|
+
Naming/UncommunicativeMethodParamName:
|
105
|
+
Enabled: false
|
106
|
+
|
107
|
+
Naming/VariableName:
|
108
|
+
Enabled: false
|
109
|
+
|
110
|
+
Style/Alias:
|
111
|
+
Enabled: false
|
112
|
+
|
113
|
+
Layout/AlignHash:
|
114
|
+
Enabled: false
|
115
|
+
|
116
|
+
Style/AsciiComments:
|
117
|
+
Enabled: false
|
118
|
+
|
119
|
+
Style/BarePercentLiterals:
|
120
|
+
Enabled: false
|
121
|
+
|
122
|
+
Style/BlockComments:
|
123
|
+
Enabled: false
|
124
|
+
|
125
|
+
Style/CharacterLiteral:
|
126
|
+
Enabled: false
|
127
|
+
|
128
|
+
Style/ClassCheck:
|
129
|
+
Enabled: false
|
130
|
+
|
131
|
+
Style/ClassVars:
|
132
|
+
Enabled: false
|
133
|
+
|
134
|
+
Style/ColonMethodCall:
|
135
|
+
Enabled: false
|
136
|
+
|
137
|
+
Style/CommentAnnotation:
|
138
|
+
Enabled: false
|
139
|
+
|
27
140
|
Style/CommentedKeyword:
|
28
141
|
Enabled: false
|
29
|
-
|
142
|
+
|
143
|
+
Style/ConditionalAssignment:
|
144
|
+
Enabled: false
|
145
|
+
|
146
|
+
Style/DefWithParentheses:
|
147
|
+
Enabled: false
|
148
|
+
|
149
|
+
Style/Documentation:
|
150
|
+
Enabled: false
|
151
|
+
|
152
|
+
Style/ExpandPathArguments:
|
153
|
+
Enabled: false
|
154
|
+
|
155
|
+
Style/GuardClause:
|
156
|
+
Enabled: false
|
157
|
+
|
158
|
+
Style/IfUnlessModifier:
|
159
|
+
Enabled: false
|
160
|
+
|
161
|
+
Style/InverseMethods:
|
162
|
+
Enabled: false
|
163
|
+
|
164
|
+
Style/Next:
|
165
|
+
Enabled: false
|
166
|
+
|
167
|
+
Style/RaiseArgs:
|
168
|
+
Enabled: true
|
169
|
+
|
30
170
|
Style/RedundantReturn:
|
31
|
-
Enabled: false
|
171
|
+
Enabled: false
|
172
|
+
|
173
|
+
Style/RedundantSelf:
|
174
|
+
Enabled: true
|
175
|
+
|
176
|
+
Style/RegexpLiteral:
|
177
|
+
Enabled: false
|
178
|
+
|
179
|
+
Style/PercentLiteralDelimiters:
|
180
|
+
Enabled: false
|
181
|
+
|
182
|
+
Style/StringLiterals:
|
183
|
+
Enabled: false
|
184
|
+
|
185
|
+
Style/TernaryParentheses:
|
186
|
+
Enabled: false
|
187
|
+
|
188
|
+
Style/UnlessElse:
|
189
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## [0.3.4] - 2018-04-20
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
- Method `Tokenizer#_next_token` failed to recognize digit or integer value immediately followed by a comma
|
5
|
+
|
1
6
|
## [0.3.3] - 2018-04-19
|
2
7
|
### Changed
|
3
8
|
- Binary `srl_ruby` now accepts a SRL filename as command-line argument. Command-line documentation updated.
|
data/lib/regex/character.rb
CHANGED
@@ -125,10 +125,10 @@ module Regex # This module is used as a namespace
|
|
125
125
|
def ==(other)
|
126
126
|
result = case other
|
127
127
|
when Character
|
128
|
-
|
128
|
+
to_str == other.to_str
|
129
129
|
|
130
130
|
when Integer
|
131
|
-
|
131
|
+
codepoint == other
|
132
132
|
|
133
133
|
when String
|
134
134
|
other.size > 1 ? false : to_str == other
|
data/lib/regex/raw_expression.rb
CHANGED
@@ -4,7 +4,7 @@ module Regex # This module is used as a namespace
|
|
4
4
|
# A raw expression is a string that will be copied verbatim (as is)
|
5
5
|
# in the generated regular expression.
|
6
6
|
class RawExpression < AtomicExpression
|
7
|
-
|
7
|
+
attr_reader :raw
|
8
8
|
|
9
9
|
# Constructor
|
10
10
|
def initialize(rawLiteral)
|
@@ -16,7 +16,7 @@ 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 expression.
|
19
|
-
|
19
|
+
alias_method :text_repr, :raw
|
20
20
|
end # class
|
21
21
|
end # module
|
22
22
|
|
data/lib/srl_ruby/tokenizer.rb
CHANGED
@@ -5,6 +5,8 @@ require_relative 'srl_token'
|
|
5
5
|
|
6
6
|
|
7
7
|
module SrlRuby
|
8
|
+
# A tokenizer for the Simple Regex Language.
|
9
|
+
# Responsibility: break input SRL into a sequence of token objects.
|
8
10
|
# The tokenizer should recognize:
|
9
11
|
# Keywords: as, capture, letter
|
10
12
|
# Integer literals including single digit
|
@@ -86,6 +88,8 @@ module SrlRuby
|
|
86
88
|
|
87
89
|
class ScanError < StandardError; end
|
88
90
|
|
91
|
+
# Constructor. Initialize a tokenizer for SRL.
|
92
|
+
# @param srl_source [String] SRL text to tokenize.
|
89
93
|
def initialize(source)
|
90
94
|
@scanner = StringScanner.new(source)
|
91
95
|
@lineno = 1
|
@@ -114,10 +118,10 @@ module SrlRuby
|
|
114
118
|
if '(),'.include? curr_ch
|
115
119
|
# Delimiters, separators => single character token
|
116
120
|
token = build_token(@@lexeme2name[curr_ch], scanner.getch)
|
117
|
-
elsif (lexeme = scanner.scan(/[0-9]{2,}((?=\s)|$)/))
|
121
|
+
elsif (lexeme = scanner.scan(/[0-9]{2,}((?=\s|,)|$)/))
|
118
122
|
token = build_token('INTEGER', lexeme) # An integer has 2..* digits
|
119
|
-
elsif (lexeme = scanner.scan(/[0-9]((?=\s)|$)/))
|
120
|
-
|
123
|
+
elsif (lexeme = scanner.scan(/[0-9]((?=\s|,)|$)/))
|
124
|
+
token = build_token('DIGIT_LIT', lexeme)
|
121
125
|
elsif (lexeme = scanner.scan(/"(?:\\"|[^"])*"/)) # Double quotes literal?
|
122
126
|
unquoted = lexeme.gsub(/(^")|("$)/, '')
|
123
127
|
token = build_token('STRING_LIT', unquoted)
|
@@ -136,7 +140,7 @@ module SrlRuby
|
|
136
140
|
erroneous = curr_ch.nil? ? '' : scanner.scan(/./)
|
137
141
|
sequel = scanner.scan(/.{1,20}/)
|
138
142
|
erroneous += sequel unless sequel.nil?
|
139
|
-
raise ScanError
|
143
|
+
raise ScanError, "Unknown token #{erroneous} on line #{lineno}"
|
140
144
|
end
|
141
145
|
|
142
146
|
return token
|
data/lib/srl_ruby/version.rb
CHANGED
@@ -94,7 +94,7 @@ module Acceptance
|
|
94
94
|
erroneous = curr_ch.nil? ? '' : curr_ch
|
95
95
|
sequel = scanner.scan(/.{1,20}/)
|
96
96
|
erroneous += sequel unless sequel.nil?
|
97
|
-
raise ScanError
|
97
|
+
raise ScanError, "Unknown token #{erroneous}"
|
98
98
|
end
|
99
99
|
|
100
100
|
return token
|
@@ -1,166 +1,170 @@
|
|
1
|
-
# File: character_spec.rb
|
2
|
-
require_relative '../spec_helper' # Use the RSpec test framework
|
3
|
-
require_relative '../../lib/regex/character'
|
4
|
-
|
5
|
-
module Regex # Open this namespace, to get rid of scope qualifiers
|
6
|
-
describe Character do
|
7
|
-
# This constant holds an arbitrary selection of characters
|
8
|
-
SampleChars = [?a, ?\0, ?\u0107].freeze
|
9
|
-
|
10
|
-
# This constant holds the codepoints of the character selection
|
11
|
-
SampleInts = [0x61, 0, 0x0107].freeze
|
12
|
-
|
13
|
-
# This constant holds an arbitrary selection of two characters (digrams)
|
14
|
-
# escape sequences
|
15
|
-
SampleDigrams = %w[\n \e \0 \6 \k].freeze
|
16
|
-
|
17
|
-
# This constant holds an arbitrary selection of escaped octal
|
18
|
-
# or hexadecimal literals
|
19
|
-
SampleNumEscs = %w[\0 \07 \x07 \xa \x0F \u03a3 \u{a}].freeze
|
20
|
-
|
21
|
-
before(:all) do
|
22
|
-
# Ensure that the set of codepoints is mapping the set of chars...
|
23
|
-
expect(SampleChars.map(&:ord)).to eq(SampleInts)
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'Creation & initialization' do
|
27
|
-
it 'should be created with a with an integer value (codepoint) or...' do
|
28
|
-
SampleInts.each do |aCodepoint|
|
29
|
-
expect { Character.new(aCodepoint) }.not_to raise_error
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it '...could be created with a single character String or...' do
|
34
|
-
SampleChars.each do |aChar|
|
35
|
-
expect { Character.new(aChar) }.not_to raise_error
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it '...could be created with an escape sequence' do
|
40
|
-
# Case 1: escape sequence is a digram
|
41
|
-
SampleDigrams.each do |anEscapeSeq|
|
42
|
-
expect { Character.new(anEscapeSeq) }.not_to raise_error
|
43
|
-
end
|
44
|
-
|
45
|
-
# Case 2: escape sequence is an escaped octal or hexadecimal literal
|
46
|
-
SampleNumEscs.each do |anEscapeSeq|
|
47
|
-
expect { Character.new(anEscapeSeq) }.not_to raise_error
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end # context
|
51
|
-
|
52
|
-
context 'Provided services' do
|
53
|
-
it 'Should know its lexeme if created from a string' do
|
54
|
-
# Lexeme is defined when the character was initialised from a text
|
55
|
-
SampleChars.each do |aChar|
|
56
|
-
ch = Character.new(aChar)
|
57
|
-
expect(ch.lexeme).to eq(aChar)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'Should not know its lexeme representation from a codepoint' do
|
62
|
-
SampleInts.each do |aChar|
|
63
|
-
ch = Character.new(aChar)
|
64
|
-
expect(ch.lexeme).to be_nil
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should know its String representation' do
|
69
|
-
# Try for one character
|
70
|
-
newOne = Character.new(?\u03a3)
|
71
|
-
expect(newOne.char).to eq('Σ')
|
72
|
-
expect(newOne.to_str).to eq("\u03A3")
|
73
|
-
|
74
|
-
# Try with our chars sample
|
75
|
-
SampleChars.each
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
(
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
# Try
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
expect(newOne).
|
122
|
-
|
123
|
-
# Case
|
124
|
-
|
125
|
-
expect(newOne).
|
126
|
-
|
127
|
-
|
128
|
-
#
|
129
|
-
expect(newOne).to eq(
|
130
|
-
expect(newOne).not_to eq(
|
131
|
-
|
132
|
-
# Case
|
133
|
-
expect(newOne).
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
expect(newOne).not_to eq(
|
138
|
-
|
139
|
-
#
|
140
|
-
|
141
|
-
expect(
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
#
|
1
|
+
# File: character_spec.rb
|
2
|
+
require_relative '../spec_helper' # Use the RSpec test framework
|
3
|
+
require_relative '../../lib/regex/character'
|
4
|
+
|
5
|
+
module Regex # Open this namespace, to get rid of scope qualifiers
|
6
|
+
describe Character do
|
7
|
+
# This constant holds an arbitrary selection of characters
|
8
|
+
SampleChars = [?a, ?\0, ?\u0107].freeze
|
9
|
+
|
10
|
+
# This constant holds the codepoints of the character selection
|
11
|
+
SampleInts = [0x61, 0, 0x0107].freeze
|
12
|
+
|
13
|
+
# This constant holds an arbitrary selection of two characters (digrams)
|
14
|
+
# escape sequences
|
15
|
+
SampleDigrams = %w[\n \e \0 \6 \k].freeze
|
16
|
+
|
17
|
+
# This constant holds an arbitrary selection of escaped octal
|
18
|
+
# or hexadecimal literals
|
19
|
+
SampleNumEscs = %w[\0 \07 \x07 \xa \x0F \u03a3 \u{a}].freeze
|
20
|
+
|
21
|
+
before(:all) do
|
22
|
+
# Ensure that the set of codepoints is mapping the set of chars...
|
23
|
+
expect(SampleChars.map(&:ord)).to eq(SampleInts)
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'Creation & initialization' do
|
27
|
+
it 'should be created with a with an integer value (codepoint) or...' do
|
28
|
+
SampleInts.each do |aCodepoint|
|
29
|
+
expect { Character.new(aCodepoint) }.not_to raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it '...could be created with a single character String or...' do
|
34
|
+
SampleChars.each do |aChar|
|
35
|
+
expect { Character.new(aChar) }.not_to raise_error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it '...could be created with an escape sequence' do
|
40
|
+
# Case 1: escape sequence is a digram
|
41
|
+
SampleDigrams.each do |anEscapeSeq|
|
42
|
+
expect { Character.new(anEscapeSeq) }.not_to raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
# Case 2: escape sequence is an escaped octal or hexadecimal literal
|
46
|
+
SampleNumEscs.each do |anEscapeSeq|
|
47
|
+
expect { Character.new(anEscapeSeq) }.not_to raise_error
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end # context
|
51
|
+
|
52
|
+
context 'Provided services' do
|
53
|
+
it 'Should know its lexeme if created from a string' do
|
54
|
+
# Lexeme is defined when the character was initialised from a text
|
55
|
+
SampleChars.each do |aChar|
|
56
|
+
ch = Character.new(aChar)
|
57
|
+
expect(ch.lexeme).to eq(aChar)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'Should not know its lexeme representation from a codepoint' do
|
62
|
+
SampleInts.each do |aChar|
|
63
|
+
ch = Character.new(aChar)
|
64
|
+
expect(ch.lexeme).to be_nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should know its String representation' do
|
69
|
+
# Try for one character
|
70
|
+
newOne = Character.new(?\u03a3)
|
71
|
+
expect(newOne.char).to eq('Σ')
|
72
|
+
expect(newOne.to_str).to eq("\u03A3")
|
73
|
+
|
74
|
+
# Try with our chars sample
|
75
|
+
SampleChars.each do |aChar|
|
76
|
+
new_ch = Character.new(aChar).to_str
|
77
|
+
new_ch == aChar
|
78
|
+
end
|
79
|
+
|
80
|
+
# Try with our codepoint sample
|
81
|
+
mapped_chars = SampleInts.map do |aCodepoint|
|
82
|
+
Character.new(aCodepoint).char
|
83
|
+
end
|
84
|
+
expect(mapped_chars).to eq(SampleChars)
|
85
|
+
|
86
|
+
# Try with our escape sequence samples
|
87
|
+
(SampleDigrams + SampleNumEscs).each do |anEscSeq|
|
88
|
+
expectation = String.class_eval(%Q|"#{anEscSeq}"|, __FILE__, __LINE__)
|
89
|
+
new_ch = Character.new(anEscSeq).to_str
|
90
|
+
new_ch == expectation
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should know its codepoint' do
|
95
|
+
# Try for one character
|
96
|
+
newOne = Character.new(?\u03a3)
|
97
|
+
expect(newOne.codepoint).to eq(0x03a3)
|
98
|
+
|
99
|
+
# Try with our chars sample
|
100
|
+
allCodepoints = SampleChars.map do |aChar|
|
101
|
+
Character.new(aChar).codepoint
|
102
|
+
end
|
103
|
+
expect(allCodepoints).to eq(SampleInts)
|
104
|
+
|
105
|
+
# Try with our codepoint sample
|
106
|
+
mapped_chars = SampleInts.each do |aCodepoint|
|
107
|
+
expect(Character.new(aCodepoint).codepoint).to eq(aCodepoint)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Try with our escape sequence samples
|
111
|
+
(SampleDigrams + SampleNumEscs).each do |anEscSeq|
|
112
|
+
expectation = String.class_eval(%Q|"#{anEscSeq}".ord()|, __FILE__, __LINE__)
|
113
|
+
expect(Character.new(anEscSeq).codepoint).to eq(expectation)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should known whether it is equal to another Object' do
|
118
|
+
newOne = Character.new(?\u03a3)
|
119
|
+
|
120
|
+
# Case 1: test equality with itself
|
121
|
+
expect(newOne).to eq(newOne)
|
122
|
+
|
123
|
+
# Case 2: test equality with another Character
|
124
|
+
expect(newOne).to eq(Character.new(?\u03a3))
|
125
|
+
expect(newOne).not_to eq(Character.new(?\u0333))
|
126
|
+
|
127
|
+
# Case 3: test equality with an integer value
|
128
|
+
# (equality based on codepoint value)
|
129
|
+
expect(newOne).to eq(0x03a3)
|
130
|
+
expect(newOne).not_to eq(0x0333)
|
131
|
+
|
132
|
+
# Case 4: test equality with a single-character String
|
133
|
+
expect(newOne).to eq(?\u03a3)
|
134
|
+
expect(newOne).not_to eq(?\u0333)
|
135
|
+
|
136
|
+
# Case 5: test fails with multiple character strings
|
137
|
+
expect(newOne).not_to eq('03a3')
|
138
|
+
|
139
|
+
# Case 6: equality testing with arbitray object
|
140
|
+
expect(newOne).not_to eq(nil)
|
141
|
+
expect(newOne).not_to eq(Object.new)
|
142
|
+
|
143
|
+
# In case 6, equality is based on to_s method.
|
144
|
+
simulator = double('fake')
|
145
|
+
expect(simulator).to receive(:to_s).and_return(?\u03a3)
|
146
|
+
expect(newOne).to eq(simulator)
|
147
|
+
|
148
|
+
# Create a module that re-defines the existing to_s method
|
149
|
+
module Tweak_to_s
|
150
|
+
def to_s() # Overwrite the existing to_s method
|
151
|
+
return ?\u03a3
|
152
|
+
end
|
153
|
+
end # module
|
154
|
+
weird = Object.new
|
155
|
+
weird.extend(Tweak_to_s)
|
156
|
+
expect(newOne).to eq(weird)
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should know its readable description' do
|
160
|
+
ch1 = Character.new('a')
|
161
|
+
expect(ch1.explain).to eq("the character 'a'")
|
162
|
+
|
163
|
+
ch2 = Character.new(?\u03a3)
|
164
|
+
expect(ch2.explain).to eq("the character '\u03a3'")
|
165
|
+
end
|
166
|
+
end # context
|
167
|
+
end # describe
|
168
|
+
end # module
|
169
|
+
|
170
|
+
# End of file
|
@@ -82,6 +82,19 @@ module SrlRuby
|
|
82
82
|
]
|
83
83
|
match_expectations(subject, expectations)
|
84
84
|
end
|
85
|
+
|
86
|
+
it "should recognize 'letter from ... to ... followed by comma'" do
|
87
|
+
input = 'letter a to f,'
|
88
|
+
subject.scanner.string = input
|
89
|
+
expectations = [
|
90
|
+
%w[LETTER letter],
|
91
|
+
%w[LETTER_LIT a],
|
92
|
+
%w[TO to],
|
93
|
+
%w[LETTER_LIT f],
|
94
|
+
%w[COMMA ,]
|
95
|
+
]
|
96
|
+
match_expectations(subject, expectations)
|
97
|
+
end
|
85
98
|
end # context
|
86
99
|
|
87
100
|
context 'Quantifier tokenization:' do
|
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.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rley
|