trim newline

This commit is contained in:
leaf corcoran
2013-10-23 23:35:01 -07:00
parent 8957308167
commit 5cf2890dba
2 changed files with 28 additions and 1 deletions

View File

@@ -38,13 +38,24 @@ class Parser
@pos += 1
close_start, close_stop = @str\find @close_tag, @pos, true
error "failed to find closing tag" unless close_start
while @in_string @pos, close_start
close_start, close_stop = @str\find @close_tag, close_stop, true
trim_newline = if "-" == @str\sub close_start - 1, close_start - 1
close_start -= 1
true
kind = modifier == "=" and "interplate" or "code"
@push_code kind, @pos, close_start - 1
@pos = close_stop + 1
if trim_newline
if match = @str\match "^\n", @pos
@pos += #match
true
-- see if stop leaves us in the middle of a string
@@ -140,7 +151,7 @@ class Parser
-- validate syntax
unless loadstring assign
error "failed to parse: #{chunk[2]}"
error "failed to parse as expression: #{chunk[2]}"
push "_b_i = _b_i + 1"
push assign

View File

@@ -76,12 +76,28 @@ This is my message to <%= [=[oh yeah %>"]=] %>]]
visitor: "yeah"
}
}
{
"hello"
"<%= 'hello' -%>
"
}
}
for case in *cases
it "should run template", ->
assert.same case[1], render unpack case, 2
it "should error on unclosed tag", ->
assert.has_error ->
render "hello <%= world"
it "should fail on bad template", ->
assert.has_error ->
render "hello <%= if hello then print(nil) end%>"
describe "Parser.in_string", ->
cases = {
{ "hello world", false }