diff --git a/DMS.xml b/DMS.xml index 215b4d6..0cad60e 100644 --- a/DMS.xml +++ b/DMS.xml @@ -24,20 +24,20 @@ /* */ - ENABLE DISABLE LOAD ENTRY - if then return - leaking debugging - ceil tan CSIM log10 sinh GOTOE lshift deg MUL QUIT cosh exp rad GOTO SUB log ADD JUMP error POW randomseed floor tanh max atan SKIP acos DIV abs rshif COMPARE print atan2 asin cos sin mod sqrt function + ENABLE DISABLE LOAD ENTRY VERSION + if then return and or + leaking debugging warnings + ceil tan CSIM log10 sinh GOTOE lshift deg MUL QUIT cosh exp rad GOTO SUB log ADD JUMP error POW randomseed floor tanh max atan SKIP acos DIV abs rshif COMPARE print atan2 asin cos sin mod sqrt function random getInput - 00:: 01 02:: 03 04 05 06" 07 08" 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 + 00:: 01 02:: 03$ 04 05$ 06" 07 08" 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 - - - + + + diff --git a/parseManager/extendedDefine.lua b/parseManager/extendedDefine.lua new file mode 100644 index 0000000..15953cd --- /dev/null +++ b/parseManager/extendedDefine.lua @@ -0,0 +1,10 @@ +function parseManager:extendedDefine() + self:define{ + newThread = function() + -- We allow for thread creation + end, + testfunc = function() + print("It worked") + end, + } +end diff --git a/parseManager/init.lua b/parseManager/init.lua index 5642c40..c8c1504 100644 --- a/parseManager/init.lua +++ b/parseManager/init.lua @@ -1,5 +1,6 @@ require("bin") parseManager={} +parseManager.VERSION = 3.4 parseManager.__index=parseManager parseManager.chunks={} parseManager.stats={} @@ -22,8 +23,8 @@ function readonlytable(tab) __metatable=false }) end -function debug(...) - if parseManager.stats.debugging then +function parseManager:debug(...) + if self.stats.debugging then print("",...) end end @@ -87,21 +88,42 @@ function parseManager:load(path,c) file.data=file.data:gsub("\2","//") file.data=file.data:gsub("\t","") file:trim() - for fn in file:gmatch("LOAD (.-)\n") do - debug("L",fn) - self:load(fn,c) - end for fn in file:gmatch("ENABLE (.-)\n") do - debug("E",fn) - self.stats[string.lower(fn)]=true + self:debug("E",fn) + c.stats[string.lower(fn)]=true + end + for fn in file:gmatch("LOAD (.-)\n") do + self:debug("L",fn) + c:load(fn,c) end for fn in file:gmatch("DISABLE (.-)\n") do - debug("D",fn) - self.stats[string.lower(fn)]=false + self:debug("D",fn) + c.stats[string.lower(fn)]=false end for fn in file:gmatch("ENTRY (.-)\n") do - debug("E",fn) - self.entry=fn + self:debug("E",fn) + c.entry=fn + end + for fn in file:gmatch("USING (.-)\n") do + self:debug("U",fn) + local m = require("parseManager."..fn) + if not m then + self:pushError(fn.." was not found as an import that can be used!") + else + c[fn](c) + end + end + for fn in file:gmatch("VERSION (.-)\n") do + self:debug("V",fn) + local num = tonumber(fn) + local int = tonumber(c.VERSION) + if not num then + c:pushWarning("VERSION: "..fn.." is not valid! Assuming "..c.VERSION) + else + if num>int then + c:pushWarning("This script was written for a version that is greater than what this interperter was built for!") + end + end end for name,data in file:gmatch("%[(.-)[:.-]?%].-{(.-)}") do local ctype="BLOCK" @@ -264,7 +286,30 @@ function table.print(tbl, indent) end end function parseManager:pushError(err,sym) - error(err.." "..tostring(sym)) + local lines = bin.load(self.currentChunk.path):lines() + local chunk = self.currentChunk[self.currentChunk.pos-1] + -- table.print(chunk) + for i=1,#lines do + if sym then + if lines[i]:find(sym) then + print(err.." At line: "..i.." "..(lines[i]:gsub("^\t+","")).." ("..tostring(sym)..")") + break + end + elseif chunk.Type=="fwor" or chunk.Type=="fwr" then + if lines[i]:match(chunk.Func.."%(") then + print(err.." At line: "..i.." "..(lines[i]:gsub("^\t+","")).." ("..tostring(sym)..")") + break + end + else + + end + end + io.read() + os.exit() +end +function parseManager:pushWarning(warn) + if not self.stats["warnings"] then return end + print("WARNING: "..warn) end local function pieceList(list,self,name) if #list==0 then @@ -363,8 +408,8 @@ function parseManager:compileAssign(assignA,assignB,name) for k=1,#listA do local mathTest=false local parsetest=false - debug("VAL: "..listB[k]) - debug("NAME: "..listA[k]) + self:debug("VAL: "..listB[k]) + self:debug("NAME: "..listA[k]) if tonumber(listB[k]) then assign.vals[#assign.vals+1]=tonumber(listB[k]) elseif listB[k]:sub(1,1)=="[" and listB[k]:sub(-1,-1)=="]" then @@ -404,7 +449,7 @@ function parseManager:compileAssign(assignA,assignB,name) if not mathTest and not parsetest then assign.vars[#assign.vars+1]=pieceAssign(listA[k],self,name) else - debug(assignA,assignB,name) + self:debug(assignA,assignB,name) end end table.insert(self.chunks[name],assign) @@ -587,13 +632,6 @@ function parseManager:compileLogic(condition,iff,elsee,name) conds=conds.." or 1==0" conds=conds:gsub(" and ","\4") conds=conds:gsub(" or ","\5") - -- conds=conds:gsub("(\".*[\4].*\")",function(a) - -- return a:gsub("\4"," and ") - -- end) - -- print(conds) - -- conds=conds:gsub("(\".*[\5].*\")",function(a) - -- return a:gsub("\4"," or ") - -- end) local count=0 local mathass=0 _conds=conds:gsub("%s*\5".."1==0","") @@ -610,24 +648,18 @@ function parseManager:compileLogic(condition,iff,elsee,name) } local l,r=(l:gsub("[\4\5\6]*%(","")),(r:gsub("%)","")) if l=="true" then - -- print("L",1,r) cmds.args[1]=true elseif l=="false" then - -- print("L",2,r) cmds.args[1]=false elseif tonumber(l) then - -- print("L",3,r) cmds.args[1]=tonumber(l) elseif l:match("[%w_]+")==l then - -- print("L",4,r) cmds.args[1]="\1"..l elseif l:match("[%._%w%+%-/%*%^%(%)%%]+")==l then - -- print("L",5,r) self:compileExpr("&"..charM,l,name) cmds.args[1]="\1&"..charM mathass=mathass+1 elseif l:sub(1,1)=="\"" and l:sub(-1,-1) then - -- print("L",6,r) cmds.args[1]=l:sub(2,-2) else self:pushError("Invalid Syntax in logical expression!",l) @@ -635,24 +667,18 @@ function parseManager:compileLogic(condition,iff,elsee,name) r=r:gsub("%s*\5".."1==0","") charM=string.char(mathass+65) if r=="true" then - -- print(1,r) cmds.args[2]=true elseif r=="false" then - -- print(2,r) cmds.args[2]=false elseif tonumber(r) then - -- print(3,r) cmds.args[2]=tonumber(r) elseif r:match("[%w_]+")==r then - -- print(4,r) cmds.args[2]="\1"..r elseif r:match("[_%w%+%-/%*%^%(%)%%]+")==r then - -- print(5,r) self:compileExpr("&"..charM,r,name) cmds.args[2]="\1&"..charM mathass=mathass+1 elseif r:sub(1,1)=="\"" and r:sub(-1,-1) then - -- print(6,r) cmds.args[2]=r:sub(2,-2) else self:pushError("Invalid Syntax in logical expression!",r) @@ -709,7 +735,7 @@ function parseManager:compile(name,ctype,data) args=pieceList(FBArgs,self,name) }) end - debug("COMPILING Block: "..name) + self:debug("COMPILING Block: "..name) local data=bin.new(data):lines() local choiceBlock=false local choice={} @@ -934,7 +960,7 @@ function parseManager:parseHeader2(data) end else -- regular strings - debug("PARSE DATA: "..tostring(self.currentENV[dat])) + self:debug("PARSE DATA: "..tostring(self.currentENV[dat])) if self.currentENV[dat]~=nil then if type(self.currentENV[dat])=="table" then local str={} @@ -953,7 +979,7 @@ end function parseManager:parseHeader(data) if type(data)=="string" then data=data:gsub("%$([%w_,:%.%[%]%-\"']+)%$",function(dat) - debug("PARSE: "..dat) + self:debug("PARSE: "..dat) if dat:find(":") and not dat:find("%[") then local var,num = dat:match("(.-):(.+)") local num = tonumber(num) @@ -1010,7 +1036,7 @@ function parseManager:parseHeader(data) end else -- regular strings - debug("PARSE DATA: "..tostring(self.currentENV[dat])) + self:debug("PARSE DATA: "..tostring(self.currentENV[dat])) if self.currentENV[dat]~=nil then if type(self.currentENV[dat])=="table" then local str="" @@ -1032,8 +1058,8 @@ function parseManager:parseHeader(data) end function parseManager:pairAssign(vars,vals,envF) for i=1,#vars do - debug("ASSIGN NAME: "..tostring(vars[i])) - debug("ASSIGN DATA: "..tostring(self:dataToValue(vals[i],envF))) + self:debug("ASSIGN NAME: "..tostring(vars[i])) + self:debug("ASSIGN DATA: "..tostring(self:dataToValue(vals[i],envF))) if type(vars[i])=="table" then if type(self.currentENV[vars[i][1]])~="table" then self:pushError("Attempt to index a non table object:",vars[i][1].."[\""..vars[i][2].."\"]") @@ -1069,7 +1095,7 @@ function parseManager:next(block,choice) data=chunk[chunk.pos] end chunk.pos=chunk.pos+1 - debug("TYPE: "..data.Type) + self:debug("TYPE: "..data.Type) if data.Type=="text" then self.lastCall=nil return {Type="text",text=self:parseHeader(data.text)} diff --git a/parsetest.txt b/parsetest.dms similarity index 100% rename from parsetest.txt rename to parsetest.dms diff --git a/parsetest2.txt b/parsetest2.dms similarity index 100% rename from parsetest2.txt rename to parsetest2.dms diff --git a/parsetest3.txt b/rps.dms similarity index 100% rename from parsetest3.txt rename to rps.dms diff --git a/test.lua b/test.lua index 4d85055..92aced6 100644 --- a/test.lua +++ b/test.lua @@ -3,19 +3,19 @@ local bin = require("bin") --~ local multi = require("multi") require("parseManager") require("bit") -parseManager:define({ - rshift=function(self,a,b) - return bit.rshift(a,b) - end, - lshift=function(self,a,b) - return bit.lshift(a,b) - end, - testfunc=function(self,a,b,c) - print(tostring(a).." "..tostring(b).." "..tostring(c)) - end -}) -test=parseManager:load("parsetest3.txt") -print(test:dump()) +--~ parseManager:define({ +--~ rshift=function(self,a,b) +--~ return bit.rshift(a,b) +--~ end, +--~ lshift=function(self,a,b) +--~ return bit.lshift(a,b) +--~ end, +--~ testfunc=function(self,a,b,c) +--~ print(tostring(a).." "..tostring(b).." "..tostring(c)) +--~ end +--~ }) +test=parseManager:load("textadventure.dms") +--~ print(test:dump()) t=test:next() while true do if not t then break end diff --git a/test2.lua b/test2.lua index 426574f..a1a652e 100644 --- a/test2.lua +++ b/test2.lua @@ -1,5 +1,16 @@ -function round(num, numDecimalPlaces) - local mult = 10^(numDecimalPlaces or 0) - return math.floor(num * mult + 0.5) / mult -end -print(round(123456.345,2)) +io.flush() +i = io.input() +i:seek("cur") +i:read(2) +print(i) +--~ g={} +--~ while t~="q" do +--~ g[#g+1]=t +--~ io.flush() +--~ t=io.read(1) +--~ io.write("\b") +--~ end +--~ print("done") +--~ io.write("\b") +--~ io.flush() +--~ io.read() diff --git a/textadventure.dms b/textadventure.dms new file mode 100644 index 0000000..13e3977 --- /dev/null +++ b/textadventure.dms @@ -0,0 +1,14 @@ +ENTRY MAIN +VERSION 3.4 +USING extendedDefine +ENABLE warnings +// ENABLE debugging +[MAIN]{ + ::name:: + name = getInput("Enter your name: ") + if name=="" then GOTO("name")|SKIP(0) + ::good:: + print("Player Name: $name$") + choice = getInput("Is this name correct? (y/n): ") + if choice=="y" then SKIP(0)|GOTO("name") +} \ No newline at end of file