diff --git a/h.lua b/h.lua index 6892408..5b24422 100644 --- a/h.lua +++ b/h.lua @@ -32,9 +32,9 @@ local voidTags = { local function isVoidTag(tag) for _, voidTag in ipairs(voidTags) do - if voidTag == tag then - return true - end + if voidTag == tag then + return true + end end return false end diff --git a/luax.lua b/luax.lua index 5951a10..3994d3e 100644 --- a/luax.lua +++ b/luax.lua @@ -19,14 +19,14 @@ local function decentParserAST(input) -- escape " ' encapsulation -- opening tag if tok == "<" and not deepString and not deepStringApos then - local nextSpacingPos = input:find('%s',pos) + local nextSpacingPos = input:find("%s", pos) local tagRange = input:sub(pos, nextSpacingPos) local tagName = tagRange:match("<(%w+)", 0) local tagNameEnd = tagRange:match("(%w+)>", 0) if tagName then deepNode = deepNode + 1 end if tagNameEnd then deepNode = deepNode - 1 end pos = pos + 1 - + if tagName and not deepString then isTag = true textNode = false @@ -37,13 +37,13 @@ local function decentParserAST(input) end local step = 1 -- enclose attributes if it empty - if tagRange:sub(#tagRange-1, #tagRange):gsub("[\r\n]", ""):match("^%s*(.-)$") == '>' then step = 0 end + if tagRange:sub(#tagRange - 1, #tagRange):gsub("[\r\n]", ""):match("^%s*(.-)$") == ">" then step = 0 end pos = pos + #tagName + step elseif tagNameEnd then if isTag and not textNode then isTag = not isTag - local trail = input:sub(0, pos-2):gsub("[%s\r\n]", "") - if trail:sub(#trail-1, #trail-1) == '/' then + local trail = input:sub(0, pos - 2):gsub("[%s\r\n]", "") + if trail:sub(#trail - 1, #trail - 1) == '/' then output = output .. ")" else output = output .. "})" @@ -72,33 +72,33 @@ local function decentParserAST(input) output = output .. tok pos = pos + 1 elseif tok == ">" and deepNode > 0 and not deepString and not deepStringApos then - if not textNode and isTag and input:sub(pos-1, pos-1) ~= "/" then + if not textNode and isTag and input:sub(pos - 1, pos - 1) ~= "/" then isTag = not isTag textNode = not textNode - output = output .. '}' + output = output .. "}" else isTag = not isTag - -- textNode = not textNode - output = output .. '})' + deepNode = deepNode - 1 + output = output .. "})" end pos = pos + 1 - elseif tok == "/" and input:sub(pos+1, pos+1) == '>' and not deepString and not deepStringApos then + elseif tok == "/" and input:sub(pos + 1, pos + 1) == ">" and not deepString and not deepStringApos then deepNode = deepNode - 1 - output = output .. '})' + output = output .. "})" pos = pos + 2 - elseif tok == '{' and deepNode > 0 and not deepString and not deepStringApos then + elseif tok == "{" and deepNode > 0 and not deepString and not deepStringApos then var = not var if not isTag then - output = output .. ',' + output = output .. "," end pos = pos + 1 - elseif tok == '}' and deepNode > 0 and not deepString and not deepStringApos then + elseif tok == "}" and deepNode > 0 and not deepString and not deepStringApos then var = not var pos = pos + 1 elseif deepNode > 0 and not deepString and not deepStringApos then if tok:match("%s") then - if isTag and output:sub(-1) ~= "{" and output:sub(-1) == "\"" or - isTag and input:sub(pos -1, pos -1) == "}" then + if not var and isTag and output:sub(-1) ~= "{" and output:sub(-1) == "\"" or + isTag and input:sub(pos - 1, pos - 1) == "}" then output = output .. "," end end @@ -118,8 +118,11 @@ local function decentParserAST(input) textNode = not textNode if textNode then local subNode = input:match("%s*<(%w+)", pos) + local trail = input:sub(pos - 10, pos):gsub("[%s\r\n]", "") if isTag and not subNode then - output = output .. "}, [[" + if trail:sub(#trail, #trail) ~= ">" then + output = output .. "}, [[" + end elseif deepNode > 0 and not subNode then output = output .. "[[" end diff --git a/test/line_break.luax b/test/10_line_break.luax similarity index 100% rename from test/line_break.luax rename to test/10_line_break.luax diff --git a/test/props.luax b/test/11_props.luax similarity index 100% rename from test/props.luax rename to test/11_props.luax diff --git a/test/test.luax b/test/12_test.luax similarity index 98% rename from test/test.luax rename to test/12_test.luax index af5ccd6..411c285 100644 --- a/test/test.luax +++ b/test/12_test.luax @@ -27,4 +27,4 @@ return
+end + +return module \ No newline at end of file diff --git a/test/9_input2.luax b/test/9_input2.luax new file mode 100644 index 0000000..c7d9ff6 --- /dev/null +++ b/test/9_input2.luax @@ -0,0 +1,11 @@ +local todo = { id="1", done = false } + + return \ No newline at end of file diff --git a/test/input.luax b/test/input.luax deleted file mode 100644 index 7db8f9b..0000000 --- a/test/input.luax +++ /dev/null @@ -1,2 +0,0 @@ -local todo = { id = "0", title = "foo" } -return \ No newline at end of file diff --git a/test/test_ast.lua b/test/test_ast.lua index 11e5a00..2cab3f9 100644 --- a/test/test_ast.lua +++ b/test/test_ast.lua @@ -28,40 +28,44 @@ local node_value = require('test.2_node_value') h(node_value) -local element = require('test.element') +local content = require('test.4_content') -h(element) +h(content) -local varin = require('test.varin') +local element = require('test.5_element') -h(varin) +h(element) -local foo = require('test.foo') +local foo = require('test.6_foo') h(foo) -local content = require('test.content') +local input_with_con = require('test.7_input_with_con') -h(content) +h(input_with_con) -local input = require('test.input') +local module = require('test.8_input') -h(input) +h(module.EditTodo({ editing = true, title = "task", id = "1" })) -local input_with_con = require('test.input_with_con') +local input2 = require('test.9_input2') -h(input_with_con) +h(input2) -local props = require('test.props') +local linebreak = require('test.10_line_break') -h(props) +h(linebreak) -local linebreak = require('test.line_break') +local props = require('test.11_props') -h(linebreak) -print("========================") +h(props) -local test = require('test.test') +local test = require('test.12_test') h(test) +local varin = require('test.13_varin') + +h(varin) + + diff --git a/test/test_spec.lua b/test/test_spec.lua index d0fa4ea..7f17dc3 100644 --- a/test/test_spec.lua +++ b/test/test_spec.lua @@ -45,59 +45,67 @@ describe("LuaX", function() assert.is.equal('Hello, world!
foobar!
Hello, world!