mirror of
https://github.com/TangentFoxy/etlua.git
synced 2025-07-28 02:52:17 +00:00
trim newline
This commit is contained in:
13
elua.moon
13
elua.moon
@@ -38,13 +38,24 @@ class Parser
|
|||||||
@pos += 1
|
@pos += 1
|
||||||
|
|
||||||
close_start, close_stop = @str\find @close_tag, @pos, true
|
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
|
while @in_string @pos, close_start
|
||||||
close_start, close_stop = @str\find @close_tag, close_stop, true
|
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"
|
kind = modifier == "=" and "interplate" or "code"
|
||||||
@push_code kind, @pos, close_start - 1
|
@push_code kind, @pos, close_start - 1
|
||||||
|
|
||||||
@pos = close_stop + 1
|
@pos = close_stop + 1
|
||||||
|
|
||||||
|
if trim_newline
|
||||||
|
if match = @str\match "^\n", @pos
|
||||||
|
@pos += #match
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
-- see if stop leaves us in the middle of a string
|
-- see if stop leaves us in the middle of a string
|
||||||
@@ -140,7 +151,7 @@ class Parser
|
|||||||
|
|
||||||
-- validate syntax
|
-- validate syntax
|
||||||
unless loadstring assign
|
unless loadstring assign
|
||||||
error "failed to parse: #{chunk[2]}"
|
error "failed to parse as expression: #{chunk[2]}"
|
||||||
|
|
||||||
push "_b_i = _b_i + 1"
|
push "_b_i = _b_i + 1"
|
||||||
push assign
|
push assign
|
||||||
|
@@ -76,12 +76,28 @@ This is my message to <%= [=[oh yeah %>"]=] %>]]
|
|||||||
visitor: "yeah"
|
visitor: "yeah"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
"hello"
|
||||||
|
"<%= 'hello' -%>
|
||||||
|
"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for case in *cases
|
for case in *cases
|
||||||
it "should run template", ->
|
it "should run template", ->
|
||||||
assert.same case[1], render unpack case, 2
|
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", ->
|
describe "Parser.in_string", ->
|
||||||
cases = {
|
cases = {
|
||||||
{ "hello world", false }
|
{ "hello world", false }
|
||||||
|
Reference in New Issue
Block a user