{"id":26859609,"url":"https://github.com/basemax/simple-lexer-c","last_synced_at":"2025-06-17T22:06:31.341Z","repository":{"id":285263925,"uuid":"957538205","full_name":"BaseMax/simple-lexer-c","owner":"BaseMax","description":"A lightweight and easy-to-use lexer library written in C. This library—named simple-lexer—is designed to simplify the creation of lexers by providing a set of utility functions and a flexible API for iterating over tokens.","archived":false,"fork":false,"pushed_at":"2025-03-30T16:53:11.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-09T22:47:08.828Z","etag":null,"topics":["c","c-language","c-lexer","clang","lexer","lexer-analyzer","lexer-c","lexer-example","lexer-generator","lexer-library","lexer-parser","lexers","simple-lexer"],"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/BaseMax.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":"2025-03-30T16:06:54.000Z","updated_at":"2025-03-31T04:45:36.000Z","dependencies_parsed_at":"2025-03-30T17:32:54.616Z","dependency_job_id":"0067d8c1-56a4-4391-8be0-b0212113d4ff","html_url":"https://github.com/BaseMax/simple-lexer-c","commit_stats":null,"previous_names":["basemax/simple-lexer-c"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BaseMax/simple-lexer-c","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2Fsimple-lexer-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2Fsimple-lexer-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2Fsimple-lexer-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2Fsimple-lexer-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BaseMax","download_url":"https://codeload.github.com/BaseMax/simple-lexer-c/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2Fsimple-lexer-c/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260447678,"owners_count":23010546,"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","c-language","c-lexer","clang","lexer","lexer-analyzer","lexer-c","lexer-example","lexer-generator","lexer-library","lexer-parser","lexers","simple-lexer"],"created_at":"2025-03-31T01:21:02.329Z","updated_at":"2025-06-17T22:06:26.327Z","avatar_url":"https://github.com/BaseMax.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-lexer-c\n\nA lightweight and easy-to-use lexer library written in C. This library—named **simple-lexer**—is designed to simplify the creation of lexers by providing a set of utility functions and a flexible API for iterating over tokens.\n\n## Features\n\n- **Simple API:** Easily define token types (e.g. punctuations, keywords) and iterate over them.\n- **Customizable:** Supports custom token rules, single-line and multi-line comments.\n- **Portable:** Written in standard C with minimal dependencies.\n- **Extensible:** Designed to be adapted and extended for different projects.\n\n## Files\n\n- **simple-lexer.h**: The main header file containing the public API.\n- **simple-lexer.c**: The implementation file (enable by defining `SIMPLELEXER_IMPLEMENTATION`).\n- **example.c**: An example usage of the library demonstrating how to build and use the lexer.\n\n## Getting Started\n\n### Prerequisites\n\nA C compiler (e.g. `gcc`, `clang`) and a standard POSIX environment (or any environment supporting standard C).\n\n### Building the Example\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/BaseMax/simple-lexer-c.git\n   cd simple-lexer-c\n   ```\n\n2. Compile the example using gcc:\n\n    ```bash\n    gcc -o simple_lexer_example example.c simple-lexer.c\n    ```\n\n3. Run the example:\n\n    ```bash\n    ./simple_lexer_example\n    ```\n\n4. Integrating Into Your Project\n\nSimply include the header in your source files:\n\n```c\n#include \"simple-lexer.h\"\n```\n\nThen compile the implementation file (simple-lexer.c) along with your project. Customize token types, comment markers, and other settings as needed.\n\n## Example\n\nBelow is a short excerpt of how to initialize and use the lexer:\n\n```c\n#include \u003cstring.h\u003e\n\n#include \"simple-lexer.h\"\n\nint main(void) {\n    const char *file_path = \"example.input\";\n    const char *content =\n        \"#include \u003cstdio.h\u003e\\n\"\n        \"if (a == 180*2 + 50) { // single line comment\\n\"\n        \"    /* multi-line\\n\"\n        \"       comment */\\n\"\n        \"    return b;\\n\"\n        \"}\\n\";\n\n    SimpleLexer lexer = simplelexer_create(file_path, content, strlen(content));\n    SimpleLexer_Token token = {0};\n    while (simplelexer_get_token(\u0026lexer, \u0026token)) {\n        lexer.diagf(token.loc, \"TOKEN\", \"%s: %.*s\",\n                    simplelexer_kind_name(SIMPLELEXER_KIND(token.id)),\n                    (int)(token.end - token.begin), token.begin);\n    }\n    return 0;\n}\n```\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n## Contributing\n\nContributions are welcome! Feel free to fork this repository and submit pull requests. For major changes, please open an issue first to discuss what you would like to change.\n\n## Acknowledgements\n\nSpecial thanks to [this YouTube video](https://www.youtube.com/watch?v=pdsq1YeHLuQ) for helping and inspiring me to reproduce it.\n\nCopyright 2025, Max Base\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasemax%2Fsimple-lexer-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasemax%2Fsimple-lexer-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasemax%2Fsimple-lexer-c/lists"}