{"id":22188840,"url":"https://github.com/qwreey/parser-lua","last_synced_at":"2026-02-13T01:40:11.144Z","repository":{"id":214607083,"uuid":"736739291","full_name":"qwreey/parser-lua","owner":"qwreey","description":"Parsing support lib","archived":false,"fork":false,"pushed_at":"2024-11-17T10:44:11.000Z","size":15,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-08T18:56:27.333Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qwreey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-28T18:27:27.000Z","updated_at":"2025-05-17T20:12:15.000Z","dependencies_parsed_at":"2024-11-18T01:34:22.647Z","dependency_job_id":null,"html_url":"https://github.com/qwreey/parser-lua","commit_stats":null,"previous_names":["qwreey/parser.lua","qwreey/parser-lua"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/qwreey/parser-lua","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwreey%2Fparser-lua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwreey%2Fparser-lua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwreey%2Fparser-lua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwreey%2Fparser-lua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qwreey","download_url":"https://codeload.github.com/qwreey/parser-lua/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwreey%2Fparser-lua/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29392027,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-13T00:53:09.511Z","status":"ssl_error","status_checked_at":"2026-02-13T00:53:09.126Z","response_time":55,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T11:12:50.380Z","updated_at":"2026-02-13T01:40:11.127Z","avatar_url":"https://github.com/qwreey.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parser.lua - qwreey/parser\n\nSimple parser utility\n\n## Parser options\n\n## Basic uses\n\n### noEOF - Simple ${value} parser\nAll parser should have 'init', 'stop', 'orphans' and regex/handlers (Not always)\n```lua\n-- Execute all regular expressions, and execute the function of the closest match.\n-- If they exist in exactly the same place, execute the function of the one further up in the code (preceded by the index).\nlocal simpleParser = createParser {\n\t-- Regex, and handle function\n\t\"%${([%w_]+)}\", function(self,str,pos,startAt,endAt,match1) -- self(context), original string, and string.find results\n\t\ttable.insert(self.inst,{t=\"val\", v=match1})\n\t\t-- Handler function can return next search start position and whether parsing has ended\n\t\t-- If function returns nothing, use endAt+1 as next search position\n\tend;\n\n\t-- Handle characters not found by matching\n\torphans = function (self,orphan)\n\t\t-- Raise an error if a character not found by matching shouldn't exist\n\t\t-- Or handle orphan string\n\t\ttable.insert(self.inst,{t=\"str\", v=orphan})\n\tend;\n\n\t-- Execute when parsing started\n\tinit = function (self,str,pos)\n\t\t-- print(pos) -- 1, starting position\n\t\tself.inst = {}\n\t\t-- init can return starting position. If return nothing, use pos as staring position\n\tend;\n\n\t-- Execute when parsing ended. it should return result (If not, use self as result)\n\tstop = function (self)\n\t\treturn self.inst\n\tend;\n\n\t-- This means that there may be no terminator (EOF), and parsing may proceed to the end of the string.\n\t-- If this value is not present, an error will be thrown if no terminator is found before the end of the string is reached\n\tnoEOF = true;\n\n\t-- Whether use result caching. Only use if result won't change every time you parse same value\n\t-- This can be useful if you'll be using the same value over and over again\n\tcache = true;\n}\n-- simpleParser will return result and ending position\nlocal result,endPos = simpleParser(\"test${value1}test\")\nprint(result,endPos)\n-- { {t=\"str\", v=\"test\"}, {t=\"val\", v=\"value1\"}, {t=\"str\", v=\"test\"} }\n-- 17\nprint(simpleParser(\"test${value1}test\") == result)\n-- true (cached)\n```\n\n#### Extend - Formatter\nYou can create simple formatter like below (append to above code)\n```lua\nlocal function f(format)\n\tlocal parsed = simpleParser(format)\n\treturn function (tbl)\n\t\tlocal buffer = {}\n\t\tfor _,item in ipairs(parsed) do\n\t\t\tif item.t == \"str\" then\n\t\t\t\ttable.insert(buffer,item.v)\n\t\t\telseif item.t == \"val\" then\n\t\t\t\ttable.insert(buffer,tostring(tbl[item.v]))\n\t\t\tend\n\t\tend\n\t\treturn table.concat(buffer)\n\tend\nend\nprint(\n\tf \"Hello ${name}\" {\n\t\tname = \"qwreey\";\n\t}\n) -- Hello qwreey\n```\n\n### EOF - Simple string parsing\n```lua\nlocal simpleStringParser = createParser {\n\t-- Ending\n\t\"['\\\"]\" = function (self,str,pos,startAt,endAt)\n\t\t-- If return true like below, parsing will end up\n\t\treturn endAt+1,true\n\tend;\n\n\t-- Escape\n\t\"\\\\(['\\\"])\" = function (self,str,pos,startAt,endAt,match1)\n\t\ttable.insert(self.buffer,match1)\n\tend;\n\n\torphans = function (self,orphan)\n\t\ttable.insert(self.buffer,orphan)\n\tend;\n\tinit = function (self,str,pos)\n\t\tself.start == str:sub(pos,pos) -- save starting char\n\t\tself.buffer = {}\n\t\tif self.start ~= \"'\" and self.start ~= \"\\\"\" then -- check starting\n\t\t\terror(\"Not allowed starting \" .. tostring(self.start))\n\t\tend\n\t\treturn pos+1 -- 2, means first char should be ignored (Processed)\n\tend;\n\tstop = function (self)\n\t\treturn table.concat(self.buffer)\n\tend;\n\n\t-- Whether there should be no more trailing characters after the end of parsing.\n\tmustReachEnd = true;\n}\nprint(simpleStringParser('\"Hello world\"')) -- 'Hello world'  13\n-- print(simpleStringParser('\"Hello world\" tailing characters')) -- error\nsimpleStringParser.mustReachEnd = false\nprint(simpleStringParser(' \"Hello world\" tailing characters'), 2) -- 'Hello world'  14\n```\n\n## template\n\n## subParser\n\n## basic escapes\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqwreey%2Fparser-lua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqwreey%2Fparser-lua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqwreey%2Fparser-lua/lists"}