{"id":16254352,"url":"https://github.com/celer/mouse","last_synced_at":"2025-03-19T21:30:27.897Z","repository":{"id":24025199,"uuid":"27409869","full_name":"celer/mouse","owner":"celer","description":"Mouse PEG Parser Runtime implementation for GoLang","archived":false,"fork":false,"pushed_at":"2014-12-03T01:14:59.000Z","size":652,"stargazers_count":7,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T21:05:58.915Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/celer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-02T01:51:54.000Z","updated_at":"2017-04-08T14:06:28.000Z","dependencies_parsed_at":"2022-08-22T09:40:54.214Z","dependency_job_id":null,"html_url":"https://github.com/celer/mouse","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Fmouse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Fmouse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Fmouse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/celer%2Fmouse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/celer","download_url":"https://codeload.github.com/celer/mouse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244021751,"owners_count":20385122,"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-10-10T15:21:16.889Z","updated_at":"2025-03-19T21:30:27.443Z","avatar_url":"https://github.com/celer.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PEG Based Parser for golang\n\nThis is a runtime implementation of the Mouse PEG parser for golang. \n\nFor more details see:\n\n * http://mousepeg.sourceforge.net/Manual.pdf\n * http://mousepeg.sourceforge.net/\n\nFrom the author Roman R. Redziejowski\n\n\u003e Parsing Expression Grammar (PEG) is a new way to specify recursive-descent parsers with\n\u003e limited backtracking. The use of backtracking lifts the LL(1) restriction usually imposed by\n\u003e top-down parsers. In addition, PEG can define parsers with integrated lexing.\n\u003e\n\u003e Mouse is a tool to transcribe PEG into an executable parser written in Java. Unlike some\n\u003e existing PEG generators (e.g., Rats!), Mouse does not produce a storage-hungry ”packrat\n\u003e parser”, but a collection of transparent recursive procedures.\n\u003e\n\u003e An integral feature of Mouse is the mechanism for specifying semantics (also in Java). This\n\u003e makes Mouse a convenient tool if one needs an ad-hoc language processor. Being written in\n\u003e Java, the processor is operating-system independent\n\n# Why use Mouse?\n\nIt generates easy to understand parsers which have integrated lexing, so a basic grammar\nmight look like so:\n\n```\n   Sum    = Number (\"+\" Number)* !_ {sum} ;\n   Number = [0-9]+ {number} ;\n``` \n\nWhich when run through mouse generates a go source file containing a very readable\noutput like so:\n\n```go\n//=========================================================================\n//\n//  Parsing procedures\n//\n//=========================================================================\n//=======================================================================\n//  Sum = Number (\"+\" Number)* !_ {sum} ;\n//=======================================================================\nfunc (this *MyParser) Sum() bool {\n\tthis.Begin(\"Sum\");\n\tif (!this.Number()) { return this.Reject(); }\n\tfor this.Sum_0() {};\n\tif (!this.AheadNot()){ return this.Reject(); }\n\treturn this.Accept();\n}\n\n//---------------------------------------------------------------------\n//  Sum_0 = \"+\" Number\n//---------------------------------------------------------------------\nfunc (this *MyParser) Sum_0() bool {\n\tthis.Begin(\"\");\n\tif (!this.NextRune(rune('+'))){ return this.RejectInner(); }\n\tif (!this.Number()) { return this.RejectInner(); }\n\treturn this.AcceptInner();\n}\n\n//=======================================================================\n//  Number = [0-9]+ {number} ;\n//=======================================================================\nfunc (this *MyParser) Number() bool {\n\tthis.Begin(\"Number\");\n\tif (!this.NextIn(rune('0'),rune('9'))){ return this.Reject(); }\n\tfor this.NextIn(rune('0'),rune('9')) {};\n\treturn this.Accept();\n}\n```\n\nIt has excellent error handling, making it very human friendly:\n\n```\n33+n:  After '33+': expected Number\n44+4a: After '44+4': expected [0-9] or '+' or end of text\n44-44: After '44': expected [0-9] or '+' or end of text\n```\n\nAnd it also is fairly easy to implement the supporting logic \nbased upon the fired rules. Each rule can have an assoicated\nmethod called when the rule is fired. The rule is results in some\nnumber of right hand results, and a single left hand result. \n\nTo gain a better understanding please see the mouse manual:\n\nhttp://mousepeg.sourceforge.net/Manual.pdf\n\n```go\n//---------------------------------------------------------------------\n//  Sum = Number (\"+\" Number)* !_\n//---------------------------------------------------------------------\nfunc (this *MySemantics) sum() {\n  s:=0;\n  for i:=0;i\u003cthis.RHSSize();i+=2 {\n    r,ok:=this.RHS(i).Get().(int);\n    if(ok){\n      s+=r;\n    }\n  }\n  this.result=s;\n}\n\n//---------------------------------------------------------------------\n//  Number = [0-9]+\n//---------------------------------------------------------------------\nfunc (this *MySemantics) number() {\n  var i int;\n  fmt.Sscanf(this.LHS().Text(),\"%d\",\u0026i);\n  this.LHS().Put(i);\n}\n```\n\n# Using it\n\t\nSee the /examples directory to get an idea of how to use it\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceler%2Fmouse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fceler%2Fmouse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceler%2Fmouse/lists"}