{"id":29506620,"url":"https://github.com/ofabricio/walker","last_synced_at":"2026-01-22T22:52:18.410Z","repository":{"id":304199965,"uuid":"1017963898","full_name":"ofabricio/walker","owner":"ofabricio","description":"A simple text parser in c","archived":false,"fork":false,"pushed_at":"2025-07-11T15:27:21.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-11T17:47:36.977Z","etag":null,"topics":["c","parser","scanner","text-analysis"],"latest_commit_sha":null,"homepage":"","language":"C","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/ofabricio.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,"zenodo":null}},"created_at":"2025-07-11T11:30:07.000Z","updated_at":"2025-07-11T15:27:24.000Z","dependencies_parsed_at":"2025-07-11T17:47:56.938Z","dependency_job_id":"ec4d24e8-303f-4050-9d52-1305af656fd0","html_url":"https://github.com/ofabricio/walker","commit_stats":null,"previous_names":["ofabricio/walker"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ofabricio/walker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofabricio%2Fwalker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofabricio%2Fwalker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofabricio%2Fwalker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofabricio%2Fwalker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ofabricio","download_url":"https://codeload.github.com/ofabricio/walker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofabricio%2Fwalker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265476123,"owners_count":23772732,"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":["c","parser","scanner","text-analysis"],"created_at":"2025-07-16T02:02:32.325Z","updated_at":"2025-10-12T10:33:09.202Z","avatar_url":"https://github.com/ofabricio.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# walker\n\nGeneral purpose text parser in C++.\n\n## Example\n\nThis example shows how to collect the names and the arguments of the statements.\n\n```cpp\n#include \u003ciostream\u003e\n#include \"walker.hpp\"\n\nint main()\n{\n    Parser p(\"point(1 20)\\n\"\n             \"vector(-2 -30)\");\n\n    while (p.More()) {\n        auto m = p.Mark();\n        if (p.While({ 'a', 'z' })) {\n            auto tok = p.Token(m);\n            int x, y;\n            if (p.Match('(') \u0026\u0026 p.Number(x) \u0026\u0026 p.Space() \u0026\u0026 p.Number(y) \u0026\u0026 p.Match(')')) {\n                std::cout \u003c\u003c \"name: \" \u003c\u003c tok \u003c\u003c \", x: \" \u003c\u003c x \u003c\u003c \", y: \" \u003c\u003c y \u003c\u003c std::endl;\n            }\n        } else {\n            p.Next();\n        }\n    }\n\n    // name: point, x: 1, y: 20\n    // name: vector, x: -2, y: -30\n\n    return 0;\n}\n```\n\n## Example: math expression\n\nThis example shows how to parse a math expression.\nNote that this example is not production-ready.\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cfunctional\u003e\n#include \"walker.hpp\"\n\nint main()\n{\n    Parser p(\"(2+3)*4\");\n\n    std::function\u003cbool(int\u0026)\u003e expr, term, fact;\n\n    expr = [\u0026](int\u0026 out) {\n        if (term(out)) {\n            int r;\n            if (p.Match('+') \u0026\u0026 expr(r)) {\n                out += r;\n            } else if (p.Match('-') \u0026\u0026 expr(r)) {\n                out -= r;\n            }\n            return true;\n        }\n        return false;\n    };\n    term = [\u0026](int\u0026 out) {\n        if (fact(out)) {\n            int r;\n            if (p.Match('*') \u0026\u0026 term(r)) {\n                out *= r;\n            } else if (p.Match('/') \u0026\u0026 term(r)) {\n                out /= r;\n            }\n            return true;\n        }\n        return false;\n    };\n    fact = [\u0026](int\u0026 out) {\n        return (p.Match('(') \u0026\u0026 expr(out) \u0026\u0026 p.Match(')')) || p.Number(out);\n    };\n\n    int out = 0;\n    expr(out);\n    std::cout \u003c\u003c out \u003c\u003c std::endl;\n    // 20\n\n    return 0;\n}\n```\n\n## Example: json\n\nThis example shows how to parse a Json and get all string values.\nNote that this example is not production-ready.\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cfunctional\u003e\n#include \"walker.hpp\"\n\nint main()\n{\n    Parser p(R\"({ \"name\": \"John\", \"country\": [ \"USA\", \"BRAZIL\" ] })\");\n\n    std::function\u003cbool(std::string\u0026)\u003e jsn, obj, arr, str, key;\n\n    jsn = [\u0026](std::string\u0026 out) {\n        p.Space();\n        return obj(out) || arr(out) || str(out);\n    };\n    obj = [\u0026](std::string\u0026 out) {\n        if (p.Match('{')) {\n            if (key(out)) {\n                while (p.Match(',') \u0026\u0026 key(out)) { }\n            }\n            p.Space();\n            return p.Match('}');\n        }\n        return false;\n    };\n    arr = [\u0026](std::string\u0026 out) {\n        if (p.Match('[')) {\n            if (jsn(out)) {\n                while (p.Match(',') \u0026\u0026 jsn(out)) { }\n            }\n            p.Space();\n            return p.Match(']');\n        }\n        return false;\n    };\n    str = [\u0026](std::string\u0026 out) {\n        auto m = p.Mark();\n        if (p.String('\"')) {\n            out += std::string(p.Token(m)) + \"; \";\n            return true;\n        }\n        return false;\n    };\n    key = [\u0026](std::string\u0026 out) {\n        p.Space();\n        return p.String('\"') \u0026\u0026 p.Match(':') \u0026\u0026 jsn(out);\n    };\n\n    std::string out;\n    jsn(out);\n    std::cout \u003c\u003c out \u003c\u003c std::endl;\n    // \"John\"; \"USA\"; \"BRAZIL\";\n\n    return 0;\n}\n```\n\n## Introduction\n\nThis library implements a Mark-Match-Move mechanism,\nwhich is a simple way to parse and collect tokens.\n\nAll matching operations are based on this pattern:\n\n```cpp\nauto m = p.Mark();\nif (p.Match(\"something\")) {\n    auto t = p.Token(m);\n}\n```\n\nFirst a mark is set to the current position.\nThen the parser advances on a match.\nFinally, the mark is used to extract the matched token on success.\nIt could be used to move the parser back to the marked position if needed.\n\nThat's all about it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofabricio%2Fwalker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fofabricio%2Fwalker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofabricio%2Fwalker/lists"}