Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
parameterized the name of the error function for telescoped asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio Mascarenhas committed Oct 13, 2009
1 parent bc4c72e commit 68a6370
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/shake/stir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ local ALL = m.Ct((ASSERT + 1)^0)
-- FUNCTIONS ---------------------------------

-- takes an ASSERT capture and builds the equivalent [assertName] call
local function buildNewAssert(info, assertName)
local function buildNewAssert(info, assertName, errorName)
local exp1, op, exp2 = info.exp.exp1, info.exp.op, info.exp.exp2
local comment, msg, text = info.comment, info.msg, info.text

Expand Down Expand Up @@ -218,7 +218,7 @@ local function buildNewAssert(info, assertName)
..', '..com
..', '..textStr
..', '..func
..[[) end), (function (e) ___STIR_error(]]
..[[) end), (function (e) ]]..newassert..errorName..[[(]]
..str1
..', '..(op and '"'..op..'"' or 'nil')
..', '..str2
Expand All @@ -237,15 +237,16 @@ local function sub(str, new_str, i, j)
end

-- replaces all asserts in input by their ___STIR_assert counterparts
function stir(input, assertName)
function stir(input, assertName, errorName)
assertName = assertName or '___STIR_assert'
errorName = errorName or '___STIR_error'
local asserts = ALL:match(input)

for i = #asserts, 1, -1 do
local v = asserts[i]

v.text = input:sub(v.start, v.finish)
input = sub(input, buildNewAssert(v, assertName), v.start, v.finish)
input = sub(input, buildNewAssert(v, assertName, errorName), v.start, v.finish)
end

return input
Expand Down

0 comments on commit 68a6370

Please sign in to comment.