diff --git a/compiler2.lua b/compiler2.lua index 9c5a90a..900874f 100644 --- a/compiler2.lua +++ b/compiler2.lua @@ -1,6 +1,18 @@ file = io.open("test.dms","rb") content = file:read("*a") line_num = 0 +CMD = {} +CMD.__index = CMD +function CMD:new(ln,cmd,args) + local c = {} + setmetatable(c,self) + c.line_num = ln + c.command = cmd + c.args = args +end +function CMD:process() + +end function string:trim() return (self:gsub("^%s*(.-)%s*$", "%1")) end @@ -8,12 +20,16 @@ local choice for line in content:gmatch("(.-)\n") do line_num = line_num + 1 line = line:trim() + line = line:gsub("") + if line=="" then goto continue end ::back:: if line:match("^%[[_:,%w%(%)]+%]") then print(line_num,"BLOCK_START",line) elseif line:match("choice%s+\".+\"%s*:") then print(line_num,"CHOICE_BLOCK",line) choice = true + elseif line:match("::([_:,%w%(%)]+)::") then + print(line_num,"LABEL_BLOCK",line) elseif choice then choice = false if line:match("\".*\"%s*[_:,%w%(%)]+%(.*%)") then @@ -25,4 +41,5 @@ for line in content:gmatch("(.-)\n") do else print(line_num,line) end + ::continue:: end \ No newline at end of file diff --git a/test.dms b/test.dms index 87472cb..677b02e 100644 --- a/test.dms +++ b/test.dms @@ -7,33 +7,33 @@ LOADFILE "This works!" "What's up" - Ryan: "Hello how are you doing?" - Bob: "I'm good you?" + Ryan "Hello how are you doing?" + Bob "I'm good you?" list = {1,2,3,true,false, {1,2,3}} a = list[1] list[1] = "Hello" - + ::label:: - choice "Pick one:": + choice "Pick one:" "first" func() "second" func() "third" func() - - for x = 1,10: + + for x = 1,10 ... - - while cond: + + while cond ... - - if cond: + + if cond ... - elseif cond: + elseif cond ... - else: + else ... - + var1,var2 = func(1,"string", 2+5) [newblock:function()]