Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local argv = { ... }
- local argc = #argv
- if argc < 1 then
- printError "Usage: metaparser <file>"
- return
- end
- local file = fs.open(argv[1], "r")
- local line = ""
- local hasMatched = false
- local function isEmpty(str)
- return str == nil or str == ""
- end
- while true do
- line = file.readLine()
- -- When the end of the file is reached
- -- stop reading.
- if line == nil then
- break
- end
- local metadata, key, param, value = line:match("(%-%-%s-@(%w+)%s-%[?(%w-)]?:%s(.+))")
- -- Only print when something was found.
- if metadata ~= nil then
- hasMatched = true
- print("Key: " .. tostring(key))
- print("Param: " .. tostring(param))
- print("Value: " .. tostring(value))
- print()
- elseif (metadata == nil and hasMatched) and not isEmpty(line) then
- -- If the line can't be matched
- -- and there already have been parsed
- -- lines, end the scanning process.
- break
- end
- end
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment