srl_ruby 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6aad01259ac0746c8e49a856822c5e8c53aaed52
4
- data.tar.gz: b814be25539c6304eab9471843c2eaa92abbbfc7
3
+ metadata.gz: 26a19da14fe9e1f84e095aa9eb4ac135915407ae
4
+ data.tar.gz: 2edefb6e8473d2e03df633fc35e2f1c5863df09a
5
5
  SHA512:
6
- metadata.gz: 3f93e5d7277bafd3c4ca6449855d6a423eae6b6912d4e5543f7f2042026d6f1b56a970c3241a5152ae184b3e78a72e68ab437cdeb1e37cfc694f96c68941d4ad
7
- data.tar.gz: f83cc31f5c5ccaeae1c14a0997d75da1eb4eed6ec3f306f822477de72c074383636d060530eb08f8176276a37870a4767a0635edf22035ed281987c88a9ff085
6
+ metadata.gz: 004a7a30442c6b5e49cf91a0eaa5689c1dd2f770a82593bb7bcc26450e91c009f743701e5d89a4afeb30c102fc8e2994e311ab70402600c7990b6c864e6b085f
7
+ data.tar.gz: b681c6cf73d7669cfd93b12c995b9844e0ad8b4933a7b0a98a130385a8f5f46608c39fcc114f1c625c469596a1cdc25e9b484b7023e2f968e293ede44d0a3da1
data/CHANGELOG.md CHANGED
@@ -6,7 +6,20 @@
6
6
  ### Fixed
7
7
  ### Security
8
8
 
9
+ ## [0.2.1] - 2018-03-15
10
+ SrlRuby passes 7 tests out of 15 standard SRL tests in total.
11
+ ### Changed
12
+ - File `acceptance/srl_test_suite_spec.rb`. More examples in spec file.
13
+ - File `ast_builder.rb` updates to reflect grammar changes.
14
+
15
+ ### Fixed
16
+ - SRL grammar now accepts a comma before 'must end' anchor
17
+ - SRL grammar now accepts a comma before an option
18
+ - Class `Tokenizer#_next_token` now recognizes correctly escaped quotes within string literal
19
+ - File `ast_builder.rb` fixed anchor implementation.
20
+
9
21
  ## [0.2.0] - 2018-03-14
22
+ SrlRuby passes 3 standard out of 15 standard SRL tests in total.
10
23
  ### Added
11
24
  - Added `spec/acceptance/support` directory. It contains test harness to use the .rule files from standard SRL test suite.
12
25
  - Added `acceptance/srl_test_suite_spec.rb`file. Spec file designed to standard SRL test suite. At this date, SrlRuby passes 3 tests out of 15 tests in total.
@@ -15,7 +15,7 @@ module SrlRuby
15
15
  attr_reader :options
16
16
 
17
17
  protected
18
-
18
+
19
19
  def terminal2node()
20
20
  Terminal2NodeClass
21
21
  end
@@ -80,14 +80,14 @@ module SrlRuby
80
80
  def repetition(expressionToRepeat, aMultiplicity)
81
81
  return Regex::Repetition.new(expressionToRepeat, aMultiplicity)
82
82
  end
83
-
83
+
84
84
  def begin_anchor
85
85
  return Regex::Anchor.new('^')
86
86
  end
87
-
88
- # rule('expression' => %w[pattern separator flags]).as 'flagged_expr'
87
+
88
+ # rule('expression' => %w[pattern flags]).as 'flagged_expr'
89
89
  def reduce_flagged_expr(_production, aRange, theTokens, theChildren)
90
- @options = theChildren[2] if theChildren[2]
90
+ @options = theChildren[1] if theChildren[1]
91
91
  return_first_child(aRange, theTokens, theChildren)
92
92
  end
93
93
 
@@ -100,6 +100,11 @@ module SrlRuby
100
100
  def reduce_flag_sequence(_production, _range, _tokens, theChildren)
101
101
  theChildren[0] << theChildren[2]
102
102
  end
103
+
104
+ # rule('flags' => %w[separator single_flag]).as 'flag_simple'
105
+ def reduce_flag_simple(_production, _range, _tokens, theChildren)
106
+ [theChildren.last]
107
+ end
103
108
 
104
109
  # rule('single_flag' => %w[CASE INSENSITIVE]).as 'case_insensitive'
105
110
  def reduce_case_insensitive(_production, _range, _tokens, _children)
@@ -118,21 +123,17 @@ module SrlRuby
118
123
 
119
124
  # rule 'quantifiable' => %w[begin_anchor anchorable end_anchor]
120
125
  def reduce_pinned_quantifiable(_production, _range, _tokens, theChildren)
121
- theChildren[1].begin_anchor = theChildren[0]
122
- theChildren[1].end_anchor = theChildren[2]
123
- return theChildren[1]
126
+ return Regex::Concatenation.new(*theChildren)
124
127
  end
125
128
 
126
129
  # rule 'quantifiable' => %w[begin_anchor anchorable]
127
130
  def reduce_begin_anchor_quantifiable(_production, _range, _tokens, theChildren)
128
- theChildren[1].begin_anchor = theChildren[0]
129
- return theChildren[1]
131
+ return Regex::Concatenation.new(*theChildren)
130
132
  end
131
133
 
132
134
  # rule 'quantifiable' => %w[anchorable end_anchor]
133
135
  def reduce_end_anchor_quantifiable(_production, _range, _tokens, theChildren)
134
- theChildren[0].end_anchor = theChildren[1]
135
- return theChildren[0]
136
+ return Regex::Concatenation.new(*theChildren)
136
137
  end
137
138
 
138
139
  # rule 'begin_anchor' => %w[STARTS WITH]
@@ -140,12 +141,12 @@ module SrlRuby
140
141
  begin_anchor
141
142
  end
142
143
 
143
- # rule 'begin_anchor' => %w[BEGIN WITH]
144
+ # rule 'begin_anchor' => %w[BEGIN WITH]
144
145
  def reduce_begin_with(_production, _range, _tokens, _children)
145
146
  begin_anchor
146
- end
147
+ end
147
148
 
148
- # rule 'end_anchor' => %w[MUST END].as 'end_anchor'
149
+ # rule('end_anchor' => %w[separator MUST END]).as 'end_anchor'
149
150
  def reduce_end_anchor(_production, _range, _tokens, _children)
150
151
  return Regex::Anchor.new('$')
151
152
  end
@@ -312,30 +313,30 @@ module SrlRuby
312
313
  return Regex::Concatenation.new(group, theChildren[3])
313
314
  end
314
315
 
315
- # rule('capturing_group' => %w[CAPTURE assertable AS var_name]).as
316
+ # rule('capturing_group' => %w[CAPTURE assertable AS var_name]).as
316
317
  # 'named_capture'
317
318
  def reduce_named_capture(_production, _range, _tokens, theChildren)
318
319
  name = theChildren[3].token.lexeme.dup
319
320
  return Regex::CapturingGroup.new(theChildren[1], name)
320
321
  end
321
322
 
322
- # rule('capturing_group' => %w[CAPTURE assertable AS var_name
323
+ # rule('capturing_group' => %w[CAPTURE assertable AS var_name
323
324
  # UNTIL assertable]).as 'named_capture_until'
324
325
  def reduce_named_capture_until(_production, _range, _tokens, theChildren)
325
326
  name = theChildren[3].token.lexeme.dup
326
327
  group = Regex::CapturingGroup.new(theChildren[1], name)
327
328
  return Regex::Concatenation.new(group, theChildren[5])
328
329
  end
329
-
330
+
330
331
  # rule('quantifier' => 'ONCE').as 'once'
331
332
  def reduce_once(_production, _range, _tokens, _children)
332
333
  multiplicity(1, 1)
333
334
  end
334
-
335
+
335
336
  # rule('quantifier' => 'TWICE').as 'twice'
336
337
  def reduce_twice(_production, _range, _tokens, _children)
337
338
  multiplicity(2, 2)
338
- end
339
+ end
339
340
 
340
341
  # rule('quantifier' => %w[EXACTLY count TIMES]).as 'exactly'
341
342
  def reduce_exactly(_production, _range, _tokens, theChildren)
@@ -350,7 +351,7 @@ module SrlRuby
350
351
  upper = theChildren[3].token.lexeme.to_i
351
352
  multiplicity(lower, upper)
352
353
  end
353
-
354
+
354
355
  # rule('quantifier' => 'OPTIONAL').as 'optional'
355
356
  def reduce_optional(_production, _range, _tokens, _children)
356
357
  multiplicity(0, 1)
@@ -360,27 +361,27 @@ module SrlRuby
360
361
  def reduce_once_or_more(_production, _range, _tokens, _children)
361
362
  multiplicity(1, :more)
362
363
  end
363
-
364
+
364
365
  # rule('quantifier' => %w[NEVER OR MORE]).as 'never_or_more'
365
366
  def reduce_never_or_more(_production, _range, _tokens, _children)
366
367
  multiplicity(0, :more)
367
368
  end
368
-
369
- # rule('quantifier' => %w[AT LEAST count TIMES]).as 'at_least'
369
+
370
+ # rule('quantifier' => %w[AT LEAST count TIMES]).as 'at_least'
370
371
  def reduce_at_least(_production, _range, _tokens, theChildren)
371
372
  count = theChildren[2].token.lexeme.to_i
372
373
  multiplicity(count, :more)
373
- end
374
-
374
+ end
375
+
375
376
  # rule('times_suffix' => 'TIMES').as 'times_keyword'
376
377
  def reduce_times_keyword(_production, _range, _tokens, _children)
377
378
  return nil
378
379
  end
379
-
380
+
380
381
  # rule('times_suffix' => []).as 'times_dropped'
381
382
  def reduce_times_dropped(_production, _range, _tokens, _children)
382
383
  return nil
383
- end
384
+ end
384
385
  end # class
385
386
  end # module
386
387
  # End of file
@@ -24,13 +24,14 @@ module SrlRuby
24
24
  add_terminals('LAZY')
25
25
 
26
26
  rule('srl' => 'expression').as 'start_rule'
27
- rule('expression' => %w[pattern separator flags]).as 'flagged_expr'
27
+ rule('expression' => %w[pattern flags]).as 'flagged_expr'
28
28
  rule('expression' => 'pattern').as 'simple_expr'
29
29
  rule('pattern' => %w[pattern separator quantifiable]).as 'pattern_sequence'
30
30
  rule('pattern' => 'quantifiable').as 'basic_pattern'
31
31
  rule('separator' => 'COMMA').as 'comma_separator'
32
32
  rule('separator' => []).as 'void_separator'
33
33
  rule('flags' => %w[flags separator single_flag]).as 'flag_sequence'
34
+ rule('flags' => %w[separator single_flag]).as 'flag_simple'
34
35
  rule('single_flag' => %w[CASE INSENSITIVE]).as 'case_insensitive'
35
36
  rule('single_flag' => %w[MULTI LINE]).as 'multi_line'
36
37
  rule('single_flag' => %w[ALL LAZY]).as 'all_lazy'
@@ -40,7 +41,7 @@ module SrlRuby
40
41
  rule('quantifiable' => 'anchorable').as 'simple_quantifiable'
41
42
  rule('begin_anchor' => %w[STARTS WITH]).as 'starts_with'
42
43
  rule('begin_anchor' => %w[BEGIN WITH]).as 'begin_with'
43
- rule('end_anchor' => %w[MUST END]).as 'end_anchor'
44
+ rule('end_anchor' => %w[separator MUST END]).as 'end_anchor'
44
45
  rule('anchorable' => 'assertable').as 'simple_anchorable'
45
46
  rule('anchorable' => %w[assertable assertion]).as 'asserted_anchorable'
46
47
  rule('assertion' => %w[IF FOLLOWED BY assertable]).as 'if_followed'
@@ -11,3 +11,4 @@ require_relative '../regex/non_capturing_group'
11
11
  require_relative '../regex/anchor'
12
12
  require_relative '../regex/lookaround'
13
13
  require_relative '../regex/capturing_group'
14
+ require_relative '../regex/match_option'
@@ -116,10 +116,10 @@ module SrlRuby
116
116
  # TODO: handle case unknown identifier
117
117
  elsif (lexeme = scanner.scan(/[a-zA-Z]((?=\s)|$)/))
118
118
  token = build_token('LETTER_LIT', lexeme)
119
- elsif (lexeme = scanner.scan(/"([^"]|\\")*"/)) # Double quotes literal?
119
+ elsif (lexeme = scanner.scan(/"(?:\\"|[^"])*"/)) # Double quotes literal?
120
120
  unquoted = lexeme.gsub(/(^")|("$)/, '')
121
121
  token = build_token('STRING_LIT', unquoted)
122
- elsif (lexeme = scanner.scan(/'([^']|\\')*'/)) # Single quotes literal?
122
+ elsif (lexeme = scanner.scan(/'(?:\\'|[^'])*'/)) # Single quotes literal?
123
123
  unquoted = lexeme.gsub(/(^')|('$)/, '')
124
124
  token = build_token('STRING_LIT', unquoted)
125
125
  else # Unknown token
@@ -137,9 +137,9 @@ module SrlRuby
137
137
  col = scanner.pos - aLexeme.size - @line_start + 1
138
138
  pos = Position.new(@lineno, col)
139
139
  token = SrlToken.new(aLexeme, aSymbolName, pos)
140
- rescue StandardError
140
+ rescue StandardError => exc
141
141
  puts "Failing with '#{aSymbolName}' and '#{aLexeme}'"
142
- raise ex
142
+ raise exc
143
143
  end
144
144
 
145
145
  return token
@@ -1,3 +1,3 @@
1
1
  module SrlRuby
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
data/lib/srl_ruby.rb CHANGED
@@ -42,6 +42,8 @@ module SrlRuby # This module is used as a namespace
42
42
 
43
43
  # Now output the regexp literal
44
44
  root = ast_ptree.root
45
+ # puts root.to_str # TODO remove this line
46
+ # pp root
45
47
  return Regexp.new(root.to_str)
46
48
  end
47
49
  end # module
@@ -39,19 +39,37 @@ RSpec.describe Acceptance do
39
39
  end
40
40
 
41
41
  it 'should match a backslash' do
42
- puts __FILE__
43
42
  rule_file_repr = load_file('backslash.rule')
44
43
  test_rule_file(rule_file_repr)
45
44
  end
46
45
 
46
+ it 'should support named capture group' do
47
+ rule_file_repr = load_file('basename_capture_group.rule')
48
+ test_rule_file(rule_file_repr)
49
+ end
50
+
51
+ it 'should match uppercase letter(s)' do
52
+ rule_file_repr = load_file('issue_17_uppercase_letter.rule')
53
+ test_rule_file(rule_file_repr)
54
+ end
55
+
47
56
  it 'should not trim literal strings' do
48
57
  rule_file_repr = load_file('literally_spaces.rule')
49
58
  test_rule_file(rule_file_repr)
50
- end
59
+ end
60
+
61
+ it 'should match a tab' do
62
+ rule_file_repr = load_file('tab.rule')
63
+ test_rule_file(rule_file_repr)
64
+ end
65
+
66
+ it 'should match mail address' do
67
+ rule_file_repr = load_file('website_example_email.rule')
68
+ test_rule_file(rule_file_repr)
69
+ end
51
70
 
52
71
  it 'should support lookahead' do
53
72
  rule_file_repr = load_file('website_example_lookahead.rule')
54
73
  test_rule_file(rule_file_repr)
55
74
  end
56
-
57
75
  end
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.2.0
4
+ version: 0.2.1
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-03-14 00:00:00.000000000 Z
11
+ date: 2018-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley