rley 0.5.09 → 0.5.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/CHANGELOG.md +3 -0
- data/examples/general/SRL/lib/ast_builder.rb +45 -16
- data/examples/general/SRL/lib/grammar.rb +7 -1
- data/examples/general/SRL/lib/tokenizer.rb +2 -0
- data/examples/general/SRL/spec/integration_spec.rb +25 -0
- data/examples/general/SRL/srl_demo.rb +1 -0
- data/lib/rley/constants.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce33adee17693fccafcc29ce8340f57694c229fb
|
4
|
+
data.tar.gz: 8acb3af15c3bd7c292209e3e1cc2e81b20ba3d9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dba9c01e5cb72954185ec5b2a973a7983202bc1733808637bd887feb6a473a57c6b3ef155090dec47f848b0e367ee558f04d0f7463d50b3494dad627ed7101fb
|
7
|
+
data.tar.gz: ffb5e41e0325f51c1ae74cc2bb7739eb21b94dca87611f528067e70295a0cd03c956b7b3a75e32593b611abafd1007853917d32db9691d89ea4948df666ad7cc
|
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
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
|
-
|
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'
|
@@ -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
|
data/lib/rley/constants.rb
CHANGED