rley 0.5.09 → 0.5.10

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: d95e1ed6a38d8e1ed70e456f46c812275a1d4530
4
- data.tar.gz: fcf7b54ff98d107fa38239139db10e7bbf1f7825
3
+ metadata.gz: ce33adee17693fccafcc29ce8340f57694c229fb
4
+ data.tar.gz: 8acb3af15c3bd7c292209e3e1cc2e81b20ba3d9f
5
5
  SHA512:
6
- metadata.gz: e185aa4e7ca59e5995f6e87379efd4f921d4242307abd55718e46bf346e7414c487b56f753f446d8518ffab74e783774aaa2adc9b7fcf8a014fdba96b8da090d
7
- data.tar.gz: 5c990777d79432c813c92dda0b21e7af3dcf587485b868e9723d30e3d1c1b3b2d6e1bc8dc7235fb1ba32c1b27ddeb6f829ef3e1b7b9248d5be1199f27e153849
6
+ metadata.gz: dba9c01e5cb72954185ec5b2a973a7983202bc1733808637bd887feb6a473a57c6b3ef155090dec47f848b0e367ee558f04d0f7463d50b3494dad627ed7101fb
7
+ data.tar.gz: ffb5e41e0325f51c1ae74cc2bb7739eb21b94dca87611f528067e70295a0cd03c956b7b3a75e32593b611abafd1007853917d32db9691d89ea4948df666ad7cc
@@ -1,3 +1,6 @@
1
+ ### 0.5.10 / 2017-12-02
2
+ * [CHANGE] Dir `examples/general/SRL/ Added support for digit range to Simple Regex Language parser.
3
+
1
4
  ### 0.5.09 / 2017-12-02
2
5
  * [CHANGE] Dir `examples/general/SRL/ Added support for letter range to Simple Regex Language parser.
3
6
 
@@ -44,20 +44,32 @@ class ASTBuilder < Rley::Parser::ParseTreeBuilder
44
44
  when 'term_1' # rule 'term' => %w[atom quantifier]
45
45
  reduce_term_1(aProduction, aRange, theTokens, theChildren)
46
46
 
47
- when 'atom_0' #rule 'atom' => 'letter_range'
47
+ when 'atom_0' # rule 'atom' => 'letter_range'
48
48
  return_first_child(aRange, theTokens, theChildren)
49
-
50
- when 'letter_range_0' # rule 'letter_range' => %w[LETTER FROM LETTER_LIT TO LETTER_LIT]
51
- reduce_letter_range_0(aProduction, aRange, theTokens, theChildren)
52
49
 
53
- when 'letter_range_1' #rule 'letter_range' => %w[UPPERCASE LETTER FROM LETTER_LIT TO LETTER_LIT]
50
+ when 'atom_1' # rule 'atom' => 'digit_range'
51
+ return_first_child(aRange, theTokens, theChildren)
52
+
53
+ # rule 'letter_range' => %w[LETTER FROM LETTER_LIT TO LETTER_LIT]
54
+ when 'letter_range_0'
55
+ reduce_letter_range_0(aProduction, aRange, theTokens, theChildren)
56
+
57
+ #rule 'letter_range' => %w[UPPERCASE LETTER FROM LETTER_LIT TO LETTER_LIT]
58
+ when 'letter_range_1'
54
59
  reduce_letter_range_1(aProduction, aRange, theTokens, theChildren)
55
-
60
+
56
61
  when 'letter_range_2' # rule 'letter_range' => 'LETTER'
57
62
  reduce_letter_range_2(aProduction, aRange, theTokens, theChildren)
58
63
 
59
64
  when 'letter_range_3' # rule 'letter_range' => %w[UPPERCASE LETTER]
60
- reduce_letter_range_3(aProduction, aRange, theTokens, theChildren)
65
+ reduce_letter_range_3(aProduction, aRange, theTokens, theChildren)
66
+
67
+ # rule 'digit_range' => %w[digit_or_number FROM DIGIT_LIT TO DIGIT_LIT]
68
+ when 'digit_range_0'
69
+ reduce_digit_range_0(aProduction, aRange, theTokens, theChildren)
70
+
71
+ when 'digit_range_1' #rule 'digit_range' => 'digit_or_number'
72
+ reduce_digit_range_1(aProduction, aRange, theTokens, theChildren)
61
73
 
62
74
  when 'quantifier_0' # rule 'quantifier' => 'ONCE'
63
75
  multiplicity(1, 1)
@@ -68,7 +80,8 @@ class ASTBuilder < Rley::Parser::ParseTreeBuilder
68
80
  when 'quantifier_2' # rule 'quantifier' => %w[EXACTLY count TIMES]
69
81
  reduce_quantifier_2(aProduction, aRange, theTokens, theChildren)
70
82
 
71
- when 'quantifier_3' # rule 'quantifier' => %w[BETWEEN count AND count times_suffix]
83
+ # rule 'quantifier' => %w[BETWEEN count AND count times_suffix]
84
+ when 'quantifier_3'
72
85
  reduce_quantifier_3(aProduction, aRange, theTokens, theChildren)
73
86
 
74
87
  when 'quantifier_4' # rule 'quantifier' => 'OPTIONAL'
@@ -82,6 +95,11 @@ class ASTBuilder < Rley::Parser::ParseTreeBuilder
82
95
 
83
96
  when 'quantifier_7' # rule 'quantifier' => %w[AT LEAST count TIMES]
84
97
  reduce_quantifier_7(aProduction, aRange, theTokens, theChildren)
98
+
99
+ # rule 'digit_or_number' => 'DIGIT'
100
+ # rule 'digit_or_number' => 'NUMER'
101
+ when 'digit_or_number_0', 'digit_or_number_1'
102
+ return_first_child(aRange, theTokens, theChildren)
85
103
 
86
104
  when 'count_0', 'count_1'
87
105
  return_first_child(aRange, theTokens, theChildren)
@@ -100,16 +118,16 @@ class ASTBuilder < Rley::Parser::ParseTreeBuilder
100
118
  end
101
119
 
102
120
  def char_range(lowerBound, upperBound)
103
- # TODO fix module nesting
121
+ # TODO fix module nesting
104
122
  lower = Regex::Character.new(lowerBound)
105
123
  upper = Regex::Character.new(upperBound)
106
124
  return Regex::CharRange.new(lower, upper)
107
125
  end
108
-
126
+
109
127
  def char_class(toNegate, *theChildren)
110
128
  Regex::CharClass.new(toNegate, *theChildren)
111
129
  end
112
-
130
+
113
131
  def repetition(expressionToRepeat, aMultiplicity)
114
132
  return Regex::Repetition.new(expressionToRepeat, aMultiplicity)
115
133
  end
@@ -128,7 +146,7 @@ class ASTBuilder < Rley::Parser::ParseTreeBuilder
128
146
  ch_range = char_range(lower, upper)
129
147
  char_class(false, ch_range)
130
148
  end
131
-
149
+
132
150
  # rule 'letter_range' => %w[UPPERCASE LETTER FROM LETTER_LIT TO LETTER_LIT]
133
151
  def reduce_letter_range_1(aProduction, aRange, theTokens, theChildren)
134
152
  lower = theChildren[3].token.lexeme
@@ -136,17 +154,28 @@ class ASTBuilder < Rley::Parser::ParseTreeBuilder
136
154
  ch_range = char_range(lower.upcase, upper.upcase)
137
155
  char_class(false, ch_range)
138
156
  end
139
-
157
+
140
158
  # rule 'letter_range' => 'LETTER'
141
159
  def reduce_letter_range_2(aProduction, aRange, theTokens, theChildren)
142
160
  ch_range = char_range('a', 'z')
143
- char_class(false, ch_range)
161
+ char_class(false, ch_range)
144
162
  end
145
-
163
+
146
164
  #rule 'letter_range' => %w[UPPERCASE LETTER]
147
165
  def reduce_letter_range_3(aProduction, aRange, theTokens, theChildren)
148
166
  ch_range = char_range('A', 'Z')
149
- char_class(false, ch_range)
167
+ char_class(false, ch_range)
168
+ end
169
+
170
+ # rule 'digit_range' => %w[digit_or_number FROM DIGIT_LIT TO DIGIT_LIT]
171
+ def reduce_digit_range_0(aProduction, aRange, theTokens, theChildren)
172
+ reduce_letter_range_0(aProduction, aRange, theTokens, theChildren)
173
+ end
174
+
175
+ # rule 'digit_range' => 'digit_or_number'
176
+ def reduce_digit_range_1(aProduction, aRange, theTokens, theChildren)
177
+ ch_range = char_range('0', '9')
178
+ char_class(false, ch_range)
150
179
  end
151
180
 
152
181
  # rule 'quantifier' => %w[EXACTLY count TIMES]
@@ -8,6 +8,7 @@ module SRL
8
8
  builder = Rley::Syntax::GrammarBuilder.new do
9
9
  add_terminals('DIGIT_LIT', 'INTEGER', 'LETTER_LIT')
10
10
  add_terminals('UPPERCASE', 'LETTER', 'FROM', 'TO')
11
+ add_terminals('DIGIT', 'NUMBER')
11
12
  add_terminals('EXACTLY', 'TIMES', 'ONCE', 'TWICE')
12
13
  add_terminals('BETWEEN', 'AND', 'OPTIONAL', 'OR')
13
14
  add_terminals('MORE', 'NEVER', 'AT', 'LEAST')
@@ -17,10 +18,13 @@ module SRL
17
18
  rule 'term' => 'atom'
18
19
  rule 'term' => %w[atom quantifier]
19
20
  rule 'atom' => 'letter_range'
21
+ rule 'atom' => 'digit_range'
20
22
  rule 'letter_range' => %w[LETTER FROM LETTER_LIT TO LETTER_LIT]
21
23
  rule 'letter_range' => %w[UPPERCASE LETTER FROM LETTER_LIT TO LETTER_LIT]
22
24
  rule 'letter_range' => 'LETTER'
23
- rule 'letter_range' => %w[UPPERCASE LETTER]
25
+ rule 'letter_range' => %w[UPPERCASE LETTER]
26
+ rule 'digit_range' => %w[digit_or_number FROM DIGIT_LIT TO DIGIT_LIT]
27
+ rule 'digit_range' => 'digit_or_number'
24
28
  rule 'quantifier' => 'ONCE'
25
29
  rule 'quantifier' => 'TWICE'
26
30
  rule 'quantifier' => %w[EXACTLY count TIMES]
@@ -29,6 +33,8 @@ module SRL
29
33
  rule 'quantifier' => %w[ONCE OR MORE]
30
34
  rule 'quantifier' => %w[NEVER OR MORE]
31
35
  rule 'quantifier' => %w[AT LEAST count TIMES]
36
+ rule 'digit_or_number' => 'DIGIT'
37
+ rule 'digit_or_number' => 'NUMBER'
32
38
  rule 'count' => 'DIGIT_LIT'
33
39
  rule 'count' => 'INTEGER'
34
40
  rule 'times_suffix' => 'TIMES'
@@ -28,12 +28,14 @@ module SRL
28
28
  AND
29
29
  AT
30
30
  BETWEEN
31
+ DIGIT
31
32
  EXACTLY
32
33
  FROM
33
34
  LEAST
34
35
  LETTER
35
36
  MORE
36
37
  NEVER
38
+ NUMBER
37
39
  ONCE
38
40
  OPTIONAL
39
41
  OR
@@ -16,6 +16,7 @@ describe 'Integration tests:' do
16
16
  end
17
17
 
18
18
  context 'Parsing character ranges:' do
19
+
19
20
  it "should parse 'letter from ... to ...' syntax" do
20
21
  result = parse('letter from a to f')
21
22
  expect(result).to be_success
@@ -48,6 +49,30 @@ describe 'Integration tests:' do
48
49
  expect(regexp.to_str).to eq('[A-Z]')
49
50
  end
50
51
 
52
+ it "should parse 'digit from ... to ...' syntax" do
53
+ result = parse('digit from 1 to 4')
54
+ expect(result).to be_success
55
+
56
+ regexp = regexp_repr(result)
57
+ expect(regexp.to_str).to eq('[1-4]')
58
+ end
59
+
60
+ it "should parse 'digit' syntax" do
61
+ result = parse('digit')
62
+ expect(result).to be_success
63
+
64
+ regexp = regexp_repr(result)
65
+ expect(regexp.to_str).to eq('[0-9]')
66
+ end
67
+
68
+ it "should parse 'number' syntax" do
69
+ result = parse('number')
70
+ expect(result).to be_success
71
+
72
+ regexp = regexp_repr(result)
73
+ expect(regexp.to_str).to eq('[0-9]')
74
+ end
75
+
51
76
  end # context
52
77
 
53
78
  context 'Parsing quantifiers:' do
@@ -36,6 +36,7 @@ Command-line syntax:
36
36
  Examples:
37
37
  ruby #{my_name} "letter from a to f exactly 4 times"
38
38
  ruby #{my_name} "uppercase letter between 2 and 3 times"
39
+ ruby #{my_name} "digit from 0 to 7 once or more"
39
40
  END_MSG
40
41
  puts msg
41
42
  exit(1)
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Rley # Module used as a namespace
5
5
  # The version number of the gem.
6
- Version = '0.5.09'.freeze
6
+ Version = '0.5.10'.freeze
7
7
 
8
8
  # Brief description of the gem.
9
9
  Description = "Ruby implementation of the Earley's parsing algorithm".freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.09
4
+ version: 0.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef