Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
LuaMacro/tests/rawhash.lua
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (29 sloc)
1.05 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local M = require 'macro' | |
| local concat = table.concat | |
| M.define ('Tab',function(get) | |
| get() -- skip space | |
| -- 'Tab' acts as a 'type' followed by a variable list | |
| local vars,endt = get:idens (function(t,v) | |
| return t == '=' or (t == 'space' and v:find '\n') | |
| end) | |
| local values = {} | |
| for i,name in ipairs(vars) do | |
| M.define_scoped(name,function(get,put) | |
| local t,v = get:peek(1) | |
| if t ~= '[' then return nil, true end -- pass-through; plain var reference | |
| get:expecting '[' | |
| local args = get:list(']','') | |
| local index = args[1] | |
| for i = 1,#index do | |
| if index[i][1] == '#' and (i == #index or index[i+1][1] ~= 'iden') then | |
| table.insert(index,i+1,{'iden',name}) | |
| end | |
| end | |
| return '['..tostring(index)..']',true | |
| end) | |
| values[i] = '{}' | |
| end | |
| local lcal = M._interactive and '' or 'local ' | |
| local res = lcal..concat(vars,',')..' = '..concat(values,',')..tostring(endt) | |
| return res | |
| end) | |