{"id":27761025,"url":"https://github.com/tsoding/alexer","last_synced_at":"2025-06-12T08:33:12.841Z","repository":{"id":263071568,"uuid":"889263069","full_name":"tsoding/alexer","owner":"tsoding","description":"Very basic lexer for very basic cases","archived":false,"fork":false,"pushed_at":"2024-11-18T12:18:15.000Z","size":53,"stargazers_count":81,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-29T12:19:15.886Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/tsoding.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":"2024-11-15T23:46:54.000Z","updated_at":"2025-04-24T19:37:53.000Z","dependencies_parsed_at":"2025-04-29T12:19:16.850Z","dependency_job_id":"f1486482-228e-4838-aebd-2f9f10aaa3ba","html_url":"https://github.com/tsoding/alexer","commit_stats":null,"previous_names":["tsoding/alexer.h","tsoding/alexer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tsoding/alexer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsoding%2Falexer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsoding%2Falexer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsoding%2Falexer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsoding%2Falexer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsoding","download_url":"https://codeload.github.com/tsoding/alexer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsoding%2Falexer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259430170,"owners_count":22856198,"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":"2025-04-29T12:19:07.933Z","updated_at":"2025-06-12T08:33:12.823Z","avatar_url":"https://github.com/tsoding.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alexer\n\nVery basic lexer for very basic cases. Don't expect it to be fast or super flexible.\n\n## Quick Start\n\n```c\n#define ALEXER_IMPLEMENTATION\n#include \"alexer.h\"\n\ntypedef enum {\n    PUNCT_PLUS,\n    PUNCT_MULT,\n    PUNCT_EQUALS,\n    PUNCT_OPAREN,\n    PUNCT_CPAREN,\n    PUNCT_OCURLY,\n    PUNCT_CCURLY,\n    PUNCT_SEMICOLON,\n    COUNT_PUNCTS,\n} Punct_Index;\n\nstatic_assert(COUNT_PUNCTS == 8, \"Amount of puncts have changed\");\nconst char *puncts[COUNT_PUNCTS] = {\n    [PUNCT_PLUS]      = \"+\",\n    [PUNCT_MULT]      = \"*\",\n    [PUNCT_OPAREN]    = \"(\",\n    [PUNCT_CPAREN]    = \")\",\n    [PUNCT_OCURLY]    = \"{\",\n    [PUNCT_CCURLY]    = \"}\",\n    [PUNCT_EQUALS]    = \"==\",\n    [PUNCT_SEMICOLON] = \";\",\n};\n\ntypedef enum {\n    KEYWORD_IF,\n    KEYWORD_RETURN,\n    COUNT_KEYWORDS,\n} Keyword_Index;\n\nstatic_assert(COUNT_KEYWORDS == 2, \"Amount of keywords have changed\");\nconst char *keywords[COUNT_KEYWORDS] = {\n    [KEYWORD_IF]     = \"if\",\n    [KEYWORD_RETURN] = \"return\",\n};\n\nconst char *sl_comments[] = {\n    \"//\",\n    \"#\",\n};\n\nAlexer_ML_Comments ml_comments[] = {\n    {\"/*\", \"*/\"},\n};\n\nint main()\n{\n    const char *file_path = \"example/path\"; // The file path is only needed for diagnostic message\n    const char *content =\n        \"#include \u003cstdio.h\u003e\\n\"\n        \"if (a == 17*2 + 35) { // single line comment\\n\"\n        \"    /* multi\\n\"\n        \"     * line\\n\"\n        \"     * comment\\n\"\n        \"     */\\n\"\n        \"    return b;\\n\"\n        \"}\\n\";\n    Alexer l = alexer_create(file_path, content, strlen(content));\n    l.puncts = puncts;\n    l.puncts_count = ALEXER_ARRAY_LEN(puncts);\n    l.keywords = keywords;\n    l.keywords_count = ALEXER_ARRAY_LEN(keywords);\n    l.sl_comments = sl_comments;\n    l.sl_comments_count = ALEXER_ARRAY_LEN(sl_comments);\n    l.ml_comments = ml_comments;\n    l.ml_comments_count = ALEXER_ARRAY_LEN(ml_comments);\n    Alexer_Token t = {0};\n    while (alexer_get_token(\u0026l, \u0026t)) {\n        l.diagf(t.loc, \"INFO\", \"%s: %.*s\", alexer_kind_name(ALEXER_KIND(t.id)), t.end - t.begin, t.begin);\n    }\n    if (!alexer_expect_id(\u0026l, t, ALEXER_END)) return 1;\n    return 0;\n}\n```\n\n```console\n$ cc -o nob nob.c\n$ ./nob\n[INFO] CMD: cc -Wall -Wextra -Wswitch-enum -ggdb -o example example.c\n[INFO] CMD: ./example\nexample/path:2:1: INFO: KEYWORD: if\nexample/path:2:4: INFO: PUNCT: (\nexample/path:2:5: INFO: SYMBOL: a\nexample/path:2:7: INFO: PUNCT: ==\nexample/path:2:10: INFO: INT: 17\nexample/path:2:12: INFO: PUNCT: *\nexample/path:2:13: INFO: INT: 2\nexample/path:2:15: INFO: PUNCT: +\nexample/path:2:17: INFO: INT: 35\nexample/path:2:19: INFO: PUNCT: )\nexample/path:2:21: INFO: PUNCT: {\nexample/path:7:5: INFO: KEYWORD: return\nexample/path:7:12: INFO: SYMBOL: b\nexample/path:7:13: INFO: PUNCT: ;\nexample/path:8:1: INFO: PUNCT: }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsoding%2Falexer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsoding%2Falexer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsoding%2Falexer/lists"}