Last active
December 19, 2015 13:19
-
-
Save TheTomster/5961200 to your computer and use it in GitHub Desktop.
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 function tokenize(program) | |
program = string.gsub(program, "%-%-.-\n", "\n"); | |
program = string.gsub(program, "(%g+);", "%1 ;"); | |
coroutine.yield() | |
for token in string.gmatch(program, "[a-z0-9_:;]+") do | |
coroutine.yield(token) | |
end | |
return nil | |
end | |
local function get_tokenizer(program) | |
tk = coroutine.wrap(tokenize) | |
tk(program) | |
return tk | |
end | |
function M.parse(program) | |
local tokenizer = get_tokenizer(program) | |
for tok in tokenizer do | |
print(tok) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment