template :: TemplateString :: parse
text
and store them in macros
.Also build self
template parts using original template text.
# Finds all the macros contained in `text` and store them in `macros`.
#
# Also build `self` template parts using original template text.
private fun parse do
var text = tpl_text
var pos = 0
var out = new FlatBuffer
var start_pos: Int
var end_pos: Int
while pos < text.length do
# lookup opening tag
start_pos = text.read_until_char(pos, marker, out)
if start_pos < 0 then
text.read_until_pos(pos, text.length, out)
add out.to_s
break
end
add out.to_s
pos = start_pos + 1
# lookup closing tag
out.clear
end_pos = text.read_until_char(pos, marker, out)
if end_pos < 0 then
text.read_until_pos(pos, text.length, out)
add "%"
add out.to_s
break
end
pos = end_pos + 1
# check macro
var name = out.to_s
if name.is_valid_macro_name then
add make_macro(name, start_pos, end_pos)
else
add "%"
add name
add "%"
end
out.clear
end
end
lib/template/macro.nit:147,2--187,4