rFlex 0.1.2 → 0.1.3
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/lib/rflex.rb +86 -12
- 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: adcfbb66ef4f56d0a01f895cabce1b505889c40c
|
|
4
|
+
data.tar.gz: 47733bbfe72c8d69b79bb53f87dcc341b619f27e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 535c77e88bb146829e57b9c1fe0a79acb8b66667c53c32e699074a62f926be6af773921840aefc3aff847630a573c4f102a1c4758f422f3aec07a9fda005fe8e
|
|
7
|
+
data.tar.gz: eaca0a215ceee7f18dfc0f5cd9ec9458d8e0c94337e8ccefec27d48ed9bbe90c1ba3240f9a61949a4f9ec0843688c405f4f8e30658c27cae3571f081b40b4292
|
data/lib/rflex.rb
CHANGED
|
@@ -23,14 +23,78 @@ class TokenLexer
|
|
|
23
23
|
|
|
24
24
|
def lex input
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
inputT = input
|
|
27
|
+
temp = self.sliceL(inputT)
|
|
28
|
+
token = ""
|
|
29
|
+
if temp == nil
|
|
30
|
+
raise "\n\nUnconsumed Input:\n\n[#{inputT}]\n\n"
|
|
31
|
+
else
|
|
32
|
+
token = temp[:token]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
if token.length >= 1
|
|
27
36
|
if @block != nil
|
|
28
37
|
analyze(token, @regexp, @type)
|
|
29
38
|
end
|
|
30
|
-
|
|
39
|
+
if temp[:inputS].length == 0 # token is not empty and remaining input is empty
|
|
40
|
+
return { :success => true, :inputS => temp[:inputS], :done => true, :error => false }
|
|
41
|
+
else # token is not empty and remaining input is not empty
|
|
42
|
+
return { :success => true, :inputS => temp[:inputS], :done => false, :error => false }
|
|
43
|
+
end
|
|
44
|
+
else
|
|
45
|
+
if temp[:inputS].length >= 1 # token is empty and remaining input is not empty
|
|
46
|
+
# error
|
|
47
|
+
#raise "\n\nUnconsumed Input:\n\n[#{temp[:inputS]}]\n\n"
|
|
48
|
+
return { :success => false, :inputS => input, :done => false, :error => true }
|
|
49
|
+
else
|
|
50
|
+
# token is empty and input is not
|
|
51
|
+
return { :success => false, :inputS => input, :done => false, :error => false }
|
|
52
|
+
end
|
|
31
53
|
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def sliceL input
|
|
32
57
|
|
|
33
|
-
|
|
58
|
+
# puts "\n\n"
|
|
59
|
+
|
|
60
|
+
if input == nil
|
|
61
|
+
return { :token => "", :input => input }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
len = input.length
|
|
65
|
+
ii = 0
|
|
66
|
+
temp = ""
|
|
67
|
+
curMatch = ""
|
|
68
|
+
matched = false
|
|
69
|
+
inputT = input
|
|
70
|
+
|
|
71
|
+
until ii == len do
|
|
72
|
+
|
|
73
|
+
temp.concat(input[ii])
|
|
74
|
+
# print "[#{input[ii]}]"
|
|
75
|
+
if temp.match(@regexp)
|
|
76
|
+
matched = true
|
|
77
|
+
curMatch = temp
|
|
78
|
+
ii += 1
|
|
79
|
+
if ii == len
|
|
80
|
+
inputT = inputT[(ii)..-1].to_s
|
|
81
|
+
return { :token => curMatch[0..-1], :inputS => inputT }
|
|
82
|
+
end
|
|
83
|
+
next
|
|
84
|
+
else
|
|
85
|
+
ii += 1
|
|
86
|
+
if matched
|
|
87
|
+
inputT = inputT[(ii - 1)..-1].to_s
|
|
88
|
+
return { :token => curMatch[0..-2], :inputS => inputT }
|
|
89
|
+
else
|
|
90
|
+
if ii == len
|
|
91
|
+
return { :token => "", :inputS => inputT }
|
|
92
|
+
else
|
|
93
|
+
next
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
34
98
|
end
|
|
35
99
|
|
|
36
100
|
def analyze token, regex, type
|
|
@@ -104,21 +168,31 @@ class LexicalAnalyzer
|
|
|
104
168
|
input.concat("#{line}")
|
|
105
169
|
end
|
|
106
170
|
|
|
107
|
-
input = input[0..-
|
|
171
|
+
# input = input[0..-1].to_s
|
|
172
|
+
inputT = input
|
|
108
173
|
|
|
109
174
|
len = @lexers.length - 1
|
|
110
175
|
j = 0
|
|
111
176
|
|
|
112
177
|
matched = false
|
|
113
178
|
|
|
114
|
-
until
|
|
179
|
+
until inputT.length == 0
|
|
180
|
+
tempLex = { :success => false, :inputS => inputT }
|
|
115
181
|
0.upto(len) do |i|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
182
|
+
j = i
|
|
183
|
+
tempLex = @lexers[i].lex(inputT)
|
|
184
|
+
|
|
185
|
+
if tempLex[:success]
|
|
186
|
+
matched = tempLex[:success]
|
|
187
|
+
inputT = tempLex[:inputS]
|
|
188
|
+
if inputT.length == 0
|
|
189
|
+
break
|
|
190
|
+
end
|
|
119
191
|
else
|
|
192
|
+
matched = false
|
|
120
193
|
end
|
|
121
|
-
|
|
194
|
+
|
|
195
|
+
# j = i
|
|
122
196
|
end
|
|
123
197
|
|
|
124
198
|
# if we tried all options
|
|
@@ -126,9 +200,9 @@ class LexicalAnalyzer
|
|
|
126
200
|
# we didn't match
|
|
127
201
|
# and
|
|
128
202
|
# there is remaining input
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
203
|
+
## puts "j: #{j}, len: #{len}, matched: #{matched}, input: #{inputT}, length: #{inputT.length}, done: #{tempLex[:done]}, error: #{tempLex[:error]}"
|
|
204
|
+
if (j == len) and tempLex[:error]
|
|
205
|
+
raise "\n\nUnconsumed Input:\n\n\"#{inputT}\"\n\n"
|
|
132
206
|
end
|
|
133
207
|
|
|
134
208
|
matched = false
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rFlex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alice "Duchess" Archer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-02-
|
|
11
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: ruby lexical analysis library
|
|
14
14
|
email: iarcher@pdx.edu
|