lean2/src/builtin/find.lua
Leonardo de Moura 66178ae65a refactor(extra): move extra to builtin
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-12-28 22:06:11 -08:00

27 lines
1,015 B
Lua

-- Define the command
--
-- Find [regex]
--
-- It displays objects in the environment whose name match the given regular expression.
-- Example: the command
-- Find "^[cC]on"
-- Displays all objects that start with the string "con" or "Con"
cmd_macro("Find",
{ macro_arg.String },
function(env, pattern)
local opts = get_options()
-- Do not display the definition value
opts = opts:update({"lean", "pp", "definition_value"}, false)
local fmt = get_formatter()
local found = false
for obj in env:objects() do
if obj:has_name() and obj:has_type() and string.match(tostring(obj:get_name()), pattern) then
print(fmt(obj, opts))
found = true
end
end
if not found then
error("no object name in the environment matches the regular expression '" .. pattern .. "'")
end
end
)