Skip to content

Commit b995ad3

Browse files
committed
Added @file and @line. Fixed an internal error.
1 parent 4f26831 commit b995ad3

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

misc/quickTest.lua2p

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ print("Metaprogram - someString: "..someString)
6666
local uhh = !(@insert"misc/quickTest.txt")
6767
print("Final program - uhh: "..uhh)
6868

69+
-- Misc.
6970
print(!("dataFromCommandLine: "..tostring(dataFromCommandLine)))
71+
print(!(("This file and line: %s:%d"):format(@file, @line)))
7072
print("The end.")
7173

7274
!(

misc/runTests.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ doTest("Output values of different types", function()
196196
assert(not luaOut)
197197
end)
198198

199-
-- @Incomplete: Add tests for @insert.
199+
-- @Incomplete: Add tests for @insert etc.
200200

201201

202202

preprocess.lua

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,15 @@ local function _processFileOrString(params, isFile)
14581458
local tok = tokenStack[#tokenStack]
14591459

14601460
if isToken(tok, "pp_keyword") then
1461-
if tok.value == "insert" then
1461+
if tok.value == "file" then
1462+
table.insert(tokens, {type="string", value=tok.file, representation=F("%q",tok.file)})
1463+
tokenStack[#tokenStack] = nil
1464+
1465+
elseif tok.value == "line" then
1466+
table.insert(tokens, {type="number", value=tok.line, representation=F("%d",tok.line)})
1467+
tokenStack[#tokenStack] = nil
1468+
1469+
elseif tok.value == "insert" then
14621470
local tokNext, iNext = getNextUsableToken(tokenStack, #tokenStack-1, nil, -1)
14631471
if not (tokNext and isToken(tokNext, "string")) then
14641472
errorAtToken(
@@ -1988,8 +1996,7 @@ local function processFileOrString(params, isFile)
19881996
local returnValues = nil
19891997
local errorToReturn = nil
19901998

1991-
isDebug = params.debug
1992-
pushErrorHandler(function(err, levelFromOurError)
1999+
local function errHand(err, levelFromOurError)
19932000
if err == ERROR_REDIRECTION then return end
19942001

19952002
errorToReturn = err
@@ -2001,9 +2008,12 @@ local function processFileOrString(params, isFile)
20012008
if params.onError then params.onError(errorToReturn) end
20022009

20032010
if levelFromOurError then _error(ERROR_REDIRECTION) end
2004-
end)
2011+
end
20052012

2006-
xpcall(
2013+
isDebug = params.debug
2014+
pushErrorHandler(errHand)
2015+
2016+
local xpcallOk, xpcallErr = xpcall(
20072017
function()
20082018
returnValues = pack(_processFileOrString(params, isFile))
20092019
end,
@@ -2020,8 +2030,16 @@ local function processFileOrString(params, isFile)
20202030
metaPathForErrorMessages = ""
20212031
outputFromMeta = nil
20222032

2033+
-- Unhandled error.
2034+
if not (returnValues or errorToReturn) then
2035+
pcall(errHand, (not xpcallOk and xpcallErr or "Unknown processing error."))
2036+
end
2037+
2038+
-- Handled error.
20232039
if errorToReturn then
20242040
return nil, errorToReturn
2041+
2042+
-- Success.
20252043
else
20262044
return unpack(returnValues, 1, returnValues.n)
20272045
end

0 commit comments

Comments
 (0)