{"id":19720021,"url":"https://github.com/discus-lang/inchworm","last_synced_at":"2025-04-29T21:30:44.672Z","repository":{"id":62436236,"uuid":"65643647","full_name":"discus-lang/inchworm","owner":"discus-lang","description":"Simple parser combinators for lexical analysis.","archived":false,"fork":false,"pushed_at":"2021-11-07T10:27:15.000Z","size":35,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-18T05:45:51.522Z","etag":null,"topics":["haskell","lexical-analysis","parser-combinators","parsing"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/discus-lang.png","metadata":{"files":{"readme":"Readme.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-14T01:03:43.000Z","updated_at":"2024-05-31T17:20:26.000Z","dependencies_parsed_at":"2022-11-01T20:46:12.502Z","dependency_job_id":null,"html_url":"https://github.com/discus-lang/inchworm","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discus-lang%2Finchworm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discus-lang%2Finchworm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discus-lang%2Finchworm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discus-lang%2Finchworm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/discus-lang","download_url":"https://codeload.github.com/discus-lang/inchworm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251585739,"owners_count":21613270,"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":["haskell","lexical-analysis","parser-combinators","parsing"],"created_at":"2024-11-11T23:10:04.242Z","updated_at":"2025-04-29T21:30:44.351Z","avatar_url":"https://github.com/discus-lang.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Inchworm\n\nInchworm is a simple parser combinator framework specialized to\nlexical analysis.\nTokens are specified via simple fold functions, and we include\nbaked in source location handling.\n\nMatchers for standard tokens like comments and strings \nare in the `Text.Lexer.Inchworm.Char` module.\n\nNo dependencies other than the Haskell `base` library.\n\nIf you want to parse expressions instead of performing lexical\nanalysis then try the `parsec` or `attoparsec` packages, which\nhave more general purpose combinators.\n\n## Minimal example\n\nThe following code demonstrates how to perform lexical analysis\nof a simple LISP-like language. We use two separate name classes,\none for variables that start with a lower-case letter, \nand one for constructors that start with an upper case letter. \n\nIntegers are scanned using the `scanInteger` function from the \n`Text.Lexer.Inchworm.Char` module.\n\nThe result of `scanStringIO` contains the list of leftover input\ncharacters that could not be parsed. In a real lexer you should\ncheck that this is empty to ensure there has not been a lexical\nerror.\n\n\n```\nimport Text.Lexer.Inchworm.Char\nimport qualified Data.Char as Char\n\n-- | A source token.\ndata Token \n        = KBra | KKet | KVar String | KCon String | KInt Integer\n        deriving Show\n\n-- | A thing with attached location information.\ndata Located a\n        = Located FilePath (Range Location) a\n        deriving Show\n\n-- | Scanner for a lispy language.\nscanner :: FilePath\n        -\u003e Scanner IO Location [Char] (Located Token)\nscanner fileName\n = skip Char.isSpace\n $ alts [ fmap (stamp id)   $ accept '(' KBra\n        , fmap (stamp id)   $ accept ')' KKet\n        , fmap (stamp KInt) $ scanInteger \n        , fmap (stamp KVar)\n          $ munchWord (\\ix c -\u003e if ix == 0 then Char.isLower c\n                                           else Char.isAlpha c) \n        , fmap (stamp KCon) \n          $ munchWord (\\ix c -\u003e if ix == 0 then Char.isUpper c\n                                           else Char.isAlpha c)\n        ]\n where  -- Stamp a token with source location information.\n        stamp k (range, t) \n          = Located fileName range (k t)\n\nmain :: IO ()\nmain \n = do   let fileName = \"Source.lispy\"\n        let source   = \"(some (Lispy like) 26 Program 93 (for you))\"\n        let toks     = scanString source (scanner fileName)\n        print toks\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscus-lang%2Finchworm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiscus-lang%2Finchworm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscus-lang%2Finchworm/lists"}