Skip to content

Commit a230715

Browse files
author
Dray Lacy
committed
Made the lexer case-insensitive.
1 parent 3bdc0a5 commit a230715

File tree

3 files changed

+62
-55
lines changed

3 files changed

+62
-55
lines changed

lib/sql/parser.rex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
class SQL::Parser
22

3+
option
4+
ignorecase
5+
36
macro
47
DIGIT [0-9]
58
UINT {DIGIT}+

lib/sql/parser.rex.rb

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -53,169 +53,169 @@ def scan_evaluate( str )
5353
case state
5454
when nil
5555
case
56-
when (text = ss.scan(/\"[0-9]+-[0-9]+-[0-9]+\"/))
56+
when (text = ss.scan(/\"[0-9]+-[0-9]+-[0-9]+\"/i))
5757
@rex_tokens.push action { [:date_string, Date.parse(text)] }
5858

59-
when (text = ss.scan(/\'[0-9]+-[0-9]+-[0-9]+\'/))
59+
when (text = ss.scan(/\'[0-9]+-[0-9]+-[0-9]+\'/i))
6060
@rex_tokens.push action { [:date_string, Date.parse(text)] }
6161

62-
when (text = ss.scan(/\"[^"]*\"/))
62+
when (text = ss.scan(/\"[^"]*\"/i))
6363
@rex_tokens.push action { [:character_string_literal, text[1..-2]] }
6464

65-
when (text = ss.scan(/\'[^']*\'/))
65+
when (text = ss.scan(/\'[^']*\'/i))
6666
@rex_tokens.push action { [:character_string_literal, text[1..-2]] }
6767

68-
when (text = ss.scan(/[0-9]+/))
68+
when (text = ss.scan(/[0-9]+/i))
6969
@rex_tokens.push action { [:unsigned_integer, text.to_i] }
7070

71-
when (text = ss.scan(/\s+/))
71+
when (text = ss.scan(/\s+/i))
7272
;
7373

74-
when (text = ss.scan(/SELECT/))
74+
when (text = ss.scan(/SELECT/i))
7575
@rex_tokens.push action { [:SELECT, text] }
7676

77-
when (text = ss.scan(/DATE/))
77+
when (text = ss.scan(/DATE/i))
7878
@rex_tokens.push action { [:DATE, text] }
7979

80-
when (text = ss.scan(/AS/))
80+
when (text = ss.scan(/AS/i))
8181
@rex_tokens.push action { [:AS, text] }
8282

83-
when (text = ss.scan(/FROM/))
83+
when (text = ss.scan(/FROM/i))
8484
@rex_tokens.push action { [:FROM, text] }
8585

86-
when (text = ss.scan(/WHERE/))
86+
when (text = ss.scan(/WHERE/i))
8787
@rex_tokens.push action { [:WHERE, text] }
8888

89-
when (text = ss.scan(/BETWEEN/))
89+
when (text = ss.scan(/BETWEEN/i))
9090
@rex_tokens.push action { [:BETWEEN, text] }
9191

92-
when (text = ss.scan(/AND/))
92+
when (text = ss.scan(/AND/i))
9393
@rex_tokens.push action { [:AND, text] }
9494

95-
when (text = ss.scan(/NOT/))
95+
when (text = ss.scan(/NOT/i))
9696
@rex_tokens.push action { [:NOT, text] }
9797

98-
when (text = ss.scan(/INNER/))
98+
when (text = ss.scan(/INNER/i))
9999
@rex_tokens.push action { [:INNER, text] }
100100

101-
when (text = ss.scan(/IN/))
101+
when (text = ss.scan(/IN/i))
102102
@rex_tokens.push action { [:IN, text] }
103103

104-
when (text = ss.scan(/OR/))
104+
when (text = ss.scan(/OR/i))
105105
@rex_tokens.push action { [:OR, text] }
106106

107-
when (text = ss.scan(/LIKE/))
107+
when (text = ss.scan(/LIKE/i))
108108
@rex_tokens.push action { [:LIKE, text] }
109109

110-
when (text = ss.scan(/IS/))
110+
when (text = ss.scan(/IS/i))
111111
@rex_tokens.push action { [:IS, text] }
112112

113-
when (text = ss.scan(/NULL/))
113+
when (text = ss.scan(/NULL/i))
114114
@rex_tokens.push action { [:NULL, text] }
115115

116-
when (text = ss.scan(/COUNT/))
116+
when (text = ss.scan(/COUNT/i))
117117
@rex_tokens.push action { [:COUNT, text] }
118118

119-
when (text = ss.scan(/AVG/))
119+
when (text = ss.scan(/AVG/i))
120120
@rex_tokens.push action { [:AVG, text] }
121121

122-
when (text = ss.scan(/MAX/))
122+
when (text = ss.scan(/MAX/i))
123123
@rex_tokens.push action { [:MAX, text] }
124124

125-
when (text = ss.scan(/MIN/))
125+
when (text = ss.scan(/MIN/i))
126126
@rex_tokens.push action { [:MIN, text] }
127127

128-
when (text = ss.scan(/SUM/))
128+
when (text = ss.scan(/SUM/i))
129129
@rex_tokens.push action { [:SUM, text] }
130130

131-
when (text = ss.scan(/GROUP/))
131+
when (text = ss.scan(/GROUP/i))
132132
@rex_tokens.push action { [:GROUP, text] }
133133

134-
when (text = ss.scan(/BY/))
134+
when (text = ss.scan(/BY/i))
135135
@rex_tokens.push action { [:BY, text] }
136136

137-
when (text = ss.scan(/HAVING/))
137+
when (text = ss.scan(/HAVING/i))
138138
@rex_tokens.push action { [:HAVING, text] }
139139

140-
when (text = ss.scan(/CROSS/))
140+
when (text = ss.scan(/CROSS/i))
141141
@rex_tokens.push action { [:CROSS, text] }
142142

143-
when (text = ss.scan(/JOIN/))
143+
when (text = ss.scan(/JOIN/i))
144144
@rex_tokens.push action { [:JOIN, text] }
145145

146-
when (text = ss.scan(/ON/))
146+
when (text = ss.scan(/ON/i))
147147
@rex_tokens.push action { [:ON, text] }
148148

149-
when (text = ss.scan(/LEFT/))
149+
when (text = ss.scan(/LEFT/i))
150150
@rex_tokens.push action { [:LEFT, text] }
151151

152-
when (text = ss.scan(/OUTER/))
152+
when (text = ss.scan(/OUTER/i))
153153
@rex_tokens.push action { [:OUTER, text] }
154154

155-
when (text = ss.scan(/RIGHT/))
155+
when (text = ss.scan(/RIGHT/i))
156156
@rex_tokens.push action { [:RIGHT, text] }
157157

158-
when (text = ss.scan(/FULL/))
158+
when (text = ss.scan(/FULL/i))
159159
@rex_tokens.push action { [:FULL, text] }
160160

161-
when (text = ss.scan(/USING/))
161+
when (text = ss.scan(/USING/i))
162162
@rex_tokens.push action { [:USING, text] }
163163

164-
when (text = ss.scan(/<>/))
164+
when (text = ss.scan(/<>/i))
165165
@rex_tokens.push action { [:not_equals_operator, text] }
166166

167-
when (text = ss.scan(/!=/))
167+
when (text = ss.scan(/!=/i))
168168
@rex_tokens.push action { [:not_equals_operator, text] }
169169

170-
when (text = ss.scan(/=/))
170+
when (text = ss.scan(/=/i))
171171
@rex_tokens.push action { [:equals_operator, text] }
172172

173-
when (text = ss.scan(/<=/))
173+
when (text = ss.scan(/<=/i))
174174
@rex_tokens.push action { [:less_than_or_equals_operator, text] }
175175

176-
when (text = ss.scan(/</))
176+
when (text = ss.scan(/</i))
177177
@rex_tokens.push action { [:less_than_operator, text] }
178178

179-
when (text = ss.scan(/>=/))
179+
when (text = ss.scan(/>=/i))
180180
@rex_tokens.push action { [:greater_than_or_equals_operator, text] }
181181

182-
when (text = ss.scan(/>/))
182+
when (text = ss.scan(/>/i))
183183
@rex_tokens.push action { [:greater_than_operator, text] }
184184

185-
when (text = ss.scan(/\(/))
185+
when (text = ss.scan(/\(/i))
186186
@rex_tokens.push action { [:left_paren, text] }
187187

188-
when (text = ss.scan(/\)/))
188+
when (text = ss.scan(/\)/i))
189189
@rex_tokens.push action { [:right_paren, text] }
190190

191-
when (text = ss.scan(/\*/))
191+
when (text = ss.scan(/\*/i))
192192
@rex_tokens.push action { [:asterisk, text] }
193193

194-
when (text = ss.scan(/\//))
194+
when (text = ss.scan(/\//i))
195195
@rex_tokens.push action { [:solidus, text] }
196196

197-
when (text = ss.scan(/\+/))
197+
when (text = ss.scan(/\+/i))
198198
@rex_tokens.push action { [:plus_sign, text] }
199199

200-
when (text = ss.scan(/\-/))
200+
when (text = ss.scan(/\-/i))
201201
@rex_tokens.push action { [:minus_sign, text] }
202202

203-
when (text = ss.scan(/\./))
203+
when (text = ss.scan(/\./i))
204204
@rex_tokens.push action { [:period, text] }
205205

206-
when (text = ss.scan(/,/))
206+
when (text = ss.scan(/,/i))
207207
@rex_tokens.push action { [:comma, text] }
208208

209-
when (text = ss.scan(/`\w+`/))
209+
when (text = ss.scan(/`\w+`/i))
210210
@rex_tokens.push action { [:identifier, text[1..-2]] }
211211

212-
when (text = ss.scan(/\w+/))
212+
when (text = ss.scan(/\w+/i))
213213
@rex_tokens.push action { [:identifier, text] }
214214

215-
when (text = ss.scan(/----/))
215+
when (text = ss.scan(/----/i))
216216
;
217217

218-
when (text = ss.scan(/require/))
218+
when (text = ss.scan(/require/i))
219219
;
220220

221221
else

test/test_parser.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
require 'test/unit'
33

44
class TestParser < Test::Unit::TestCase
5+
def test_case_insensitivity
6+
assert_sql 'SELECT * FROM users WHERE id = 1', 'select * from users where id = 1'
7+
end
8+
59
def test_full_outer_join
610
assert_understands 'SELECT * FROM t1 FULL OUTER JOIN t2 ON t1.a = t2.a'
711
assert_understands 'SELECT * FROM t1 FULL OUTER JOIN t2 ON t1.a = t2.a FULL OUTER JOIN t3 ON t2.a = t3.a'

0 commit comments

Comments
 (0)