{"id":24558068,"url":"https://github.com/rse/parsing-techniques","last_synced_at":"2025-04-19T09:58:36.863Z","repository":{"id":54377064,"uuid":"36599483","full_name":"rse/parsing-techniques","owner":"rse","description":"Lecture on Parsing Techniques","archived":false,"fork":false,"pushed_at":"2021-09-13T12:33:36.000Z","size":40,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T21:55:49.097Z","etag":null,"topics":["javascript","parser","parsing","regexp","scanner","technique"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/rse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-31T11:08:19.000Z","updated_at":"2025-01-28T06:34:00.000Z","dependencies_parsed_at":"2022-08-13T13:50:32.684Z","dependency_job_id":null,"html_url":"https://github.com/rse/parsing-techniques","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/rse%2Fparsing-techniques","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fparsing-techniques/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fparsing-techniques/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fparsing-techniques/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rse","download_url":"https://codeload.github.com/rse/parsing-techniques/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249669923,"owners_count":21308668,"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":["javascript","parser","parsing","regexp","scanner","technique"],"created_at":"2025-01-23T05:47:18.170Z","updated_at":"2025-04-19T09:58:36.838Z","avatar_url":"https://github.com/rse.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nParsing Techniques\n==================\n\nThere are lots of [formal languages](LANGUAGES.md) for various kinds of\npractical purposes. But they all have one thing in common: for further\nprocessing them inside a program, they first have to be parsed from\ntheir character string representation. This is the material of a lecture\nabout various techniques to perform this parsing step.\n\nNotice: the code is all written in [ECMAScript\n6](http://en.wikipedia.org/wiki/ECMAScript), is on-the-fly transpiled\nto ECMAScript 5 and then executed under [Node.js](http://nodejs.org/),\nbut it actually doesn't matter very much. Equivalent code can be written\nin Java or C#, too. The only major point is just that the required\nthird-party libraries have to be also changed, of course.\n\nParsing Input\n-------------\n\nLet's imagine a formal language for describing key/value based\nconfigurations in a redundancy-free nested structure.\nA [sample configuration](sample.cfg) can be:\n\n```\nfoo {\n    baz = 7 // some comment\n    bar {\n        quux = 42\n        hello = \"{hello} = \\\"world\\\"!\"\n    }\n    quux = 3\n}\nbar  = 1\nquux = 2\n```\n\nThis is a very simple formal language, but it already has\nsome cruxes which can become a hurdle for parsing:\n\n1. nested sections\n2. intermixed comments\n3. alternatives (value is either number or string)\n4. string value can contain spaces, quotes and section braces\n\nParsing Output\n--------------\n\nLet's imagine we want to parse configurations in the above format into a\n[simple key/value format](sample.kv) where the sections are flattened:\n\n```\nfoo.bar.quux 42\nfoo.bar.hello {hello} = \"world\"!\nfoo.baz 7\nfoo.quux 3\nbar 1\nquux 2\n```\n\nParsing Techniques\n------------------\n\nThere are various parsing techniques available, each with their pros and\ncons. For illustration purposes we've implemented a bunch of them. Each\none can be run by executing `make \u003cid\u003e` where `\u003cid\u003e` is one of `0-re`,\n`1-sm`, `2-sm-ast`, `3-ls-rdp-ast` or `4-peg-ast`. Follow the above\nlinks to their particular source code and documentation.\n\n- [`cfg2kv-0-re/`](cfg2kv-0-re/):\u003cbr/\u003e\n  **Regular Expressions (RE)**\n\n- [`cfg2kv-1-sm/`](cfg2kv-1-sm/):\u003cbr/\u003e\n  **State Machine (SM)**\n\n- [`cfg2kv-2-sm-ast/`](cfg2kv-2-sm-ast/):\u003cbr/\u003e\n  **State Machine (SM), Abstract Syntax Tree (AST)**\n\n- [`cfg2kv-3-ls-rdp-ast/`](cfg2kv-3-ls-rdp-ast/):\u003cbr/\u003e\n  **Lexical Scanner (LS), Recursive Descent Parser (RDP), Abstract Syntax Tree (AST)**\n\n- [`cfg2kv-4-pc-ast/`](cfg2kv-4-pc-ast/):\u003cbr/\u003e\n  **Parser Combinators (PC), Abstract Syntax Tree (AST)**\n\n- [`cfg2kv-5-peg-ast/`](cfg2kv-4-peg-ast/):\u003cbr/\u003e\n  **Parsing Expression Grammar (PEG) Parser, Abstract Syntax Tree (AST)**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frse%2Fparsing-techniques","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frse%2Fparsing-techniques","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frse%2Fparsing-techniques/lists"}