163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
# File 'lib/h2o/parser.rb', line 163
def lexer
s = StringScanner.new(@argument)
state = :initial
result = []
while ! s.eos?
next if s.scan(WHITESPACE_RE)
if state == :initial
if match = s.scan(OPERATOR_RE)
result << [:operator, match]
elsif match = s.scan(BOOLEAN_RE)
result << [:boolean, match]
elsif match = s.scan(NIL_RE)
result << [:nil, match]
elsif match = s.scan(NAMED_ARGS_RE)
result << [:named_argument, match]
elsif match = s.scan(NAME_RE)
result << [:name, match]
elsif match = s.scan(PIPE_RE)
state = :filter
result << [:filter_start, nil]
elsif match = s.scan(SEPERATOR_RE)
result << [:seperator, nil]
elsif match = s.scan(STRING_RE)
result << [:string, match]
elsif match = s.scan(NUMBER_RE)
result << [:number, match]
else
raise SyntaxError, "unexpected character #{s.getch} in tag"
end
elsif state == :filter
if match = s.scan(PIPE_RE)
result << [:filter_end, nil]
result << [:filter_start, nil]
elsif match = s.scan(SEPERATOR_RE)
result << [:seperator, nil]
elsif match = s.scan(FILTER_END_RE)
result << [:filter_end, nil]
state = :initial
elsif match = s.scan(BOOLEAN_RE)
result << [:boolean, match]
elsif match = s.scan(NIL_RE)
result << [:nil, match]
elsif match = s.scan(NAMED_ARGS_RE)
result << [:named_argument, match]
elsif match = s.scan(NAME_RE)
result << [:name, match]
elsif match = s.scan(STRING_RE)
result << [:string, match]
elsif match = s.scan(NUMBER_RE)
result << [:number, match]
else
raise SyntaxError, "unexpected character #{s.getch} in filter"
end
end
end
result << [:filter_end, nil] if state == :filter
result
end
|