{"id":13896644,"url":"https://github.com/andremm/lua-parser","last_synced_at":"2025-04-04T08:03:42.240Z","repository":{"id":13083311,"uuid":"15764361","full_name":"andremm/lua-parser","owner":"andremm","description":"A Lua 5.3 parser written with LPegLabel","archived":false,"fork":false,"pushed_at":"2025-03-11T15:35:22.000Z","size":100,"stargazers_count":197,"open_issues_count":3,"forks_count":29,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-03-28T07:04:03.707Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andremm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2014-01-09T11:04:57.000Z","updated_at":"2025-03-12T14:40:55.000Z","dependencies_parsed_at":"2025-03-21T06:01:36.762Z","dependency_job_id":"ecd239f8-9c97-40dc-975b-f5d8543165fc","html_url":"https://github.com/andremm/lua-parser","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andremm%2Flua-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andremm%2Flua-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andremm%2Flua-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andremm%2Flua-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andremm","download_url":"https://codeload.github.com/andremm/lua-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247140761,"owners_count":20890499,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-08-06T18:03:03.532Z","updated_at":"2025-04-04T08:03:42.225Z","avatar_url":"https://github.com/andremm.png","language":"Lua","funding_links":[],"categories":["Lua","资源","Resources"],"sub_categories":["Analysis Tools and ASTs"],"readme":"lua-parser\n==========\n[![Build Status](https://travis-ci.org/andremm/lua-parser.svg?branch=master)](https://travis-ci.org/andremm/lua-parser)\n\nThis is a Lua 5.3 parser written with [LPegLabel](https://github.com/sqmedeiros/lpeglabel) that\ngenerates an AST in a format that is similar to the one specified by [Metalua](https://github.com/fab13n/metalua-parser).\nThe parser uses LPegLabel to provide more specific error messages.\n\nRequirements\n------------\n\n        lua \u003e= 5.1\n        lpeglabel \u003e= 1.6.0\n\nAPI\n---\n\nThe package `lua-parser` has two modules: `lua-parser.parser`\nand `lua-parser.pp`.\n\nThe module `lua-parser.parser` implements the function `parser.parse`:\n\n* `parser.parse (subject, filename)`\n\n    Both subject and filename should be strings.\n    It tries to parse subject and returns the AST in case of success.\n    It returns **nil** plus an error message in case of error.\n    In case of error, the parser uses the string filename to build an\n    error message.\n\nThe module `lua-parser.pp` implements a pretty printer to the AST and\na dump function:\n\n* `pp.tostring (ast)`\n\n    It converts the AST to a string and returns this string.\n\n* `pp.print (ast)`\n\n    It converts the AST to a string and prints this string.\n\n* `pp.dump (ast[, i])`\n\n    It dumps the AST to the screen.\n    The parameter **i** sets the indentation level.\n\nAST format\n----------\n\n\tblock: { stat* }\n\n\tstat:\n            `Do{ stat* }\n          | `Set{ {lhs+} {expr+} }                    -- lhs1, lhs2... = e1, e2...\n          | `While{ expr block }                      -- while e do b end\n          | `Repeat{ block expr }                     -- repeat b until e\n          | `If{ (expr block)+ block? }               -- if e1 then b1 [elseif e2 then b2] ... [else bn] end\n          | `Fornum{ ident expr expr expr? block }    -- for ident = e, e[, e] do b end\n          | `Forin{ {ident+} {expr+} block }          -- for i1, i2... in e1, e2... do b end\n          | `Local{ {ident+} {expr+}? }               -- local i1, i2... = e1, e2...\n          | `Localrec{ ident expr }                   -- only used for 'local function'\n          | `Goto{ \u003cstring\u003e }                         -- goto str\n          | `Label{ \u003cstring\u003e }                        -- ::str::\n          | `Return{ \u003cexpr*\u003e }                        -- return e1, e2...\n          | `Break                                    -- break\n          | apply\n\n\texpr:\n            `Nil\n          | `Dots\n          | `Boolean{ \u003cboolean\u003e }\n          | `Number{ \u003cnumber\u003e }\n          | `String{ \u003cstring\u003e }\n          | `Function{ { `Id{ \u003cstring\u003e }* `Dots? } block }\n          | `Table{ ( `Pair{ expr expr } | expr )* }\n          | `Op{ opid expr expr? }\n          | `Paren{ expr }       -- significant to cut multiple values returns\n          | apply\n          | lhs\n\n\tapply:\n             `Call{ expr expr* }\n           | `Invoke{ expr `String{ \u003cstring\u003e } expr* }\n\n\tlhs: `Id{ \u003cstring\u003e } | `Index{ expr expr }\n\n\topid:  -- includes additional operators from Lua 5.3 and all relational operators\n            'add'  | 'sub' | 'mul'  | 'div'\n          | 'idiv' | 'mod' | 'pow'  | 'concat'\n          | 'band' | 'bor' | 'bxor' | 'shl' | 'shr'\n          | 'eq'   | 'ne'  | 'lt'   | 'gt'  | 'le'   | 'ge'\n          | 'and'  | 'or'  | 'unm'  | 'len' | 'bnot' | 'not'\n\n\nUsage\n--------\n\n**Code example for parsing a string:**\n\n\n    local parser = require \"lua-parser.parser\"\n    local pp = require \"lua-parser.pp\"\n\n    if #arg ~= 1 then\n        print(\"Usage: parse.lua \u003cstring\u003e\")\n        os.exit(1)\n    end\n\n    local ast, error_msg = parser.parse(arg[1], \"example.lua\")\n    if not ast then\n        print(error_msg)\n        os.exit(1)\n    end\n\n    pp.print(ast)\n    os.exit(0)\n\n**Running the above code example using a string without syntax error:**\n\n    $ lua parse.lua \"for i=1, 10 do print(i) end\"\n    { `Fornum{ `Id \"i\", `Number \"1\", `Number \"10\", { `Call{ `Id \"print\", `Id \"i\" } } } }\n\n**Running the above code example using a string with syntax error:**\n\n    $ lua parse.lua \"for i=1, 10 do print(i) \"\n    example.lua:1:24: syntax error, expected 'end' to close the for loop\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandremm%2Flua-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandremm%2Flua-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandremm%2Flua-parser/lists"}