{"id":19215231,"url":"https://github.com/sergey0xff/lexit","last_synced_at":"2025-05-12T23:27:35.013Z","repository":{"id":86874786,"uuid":"138517360","full_name":"sergey0xff/lexit","owner":"sergey0xff","description":"An open source lexer generator","archived":false,"fork":false,"pushed_at":"2018-10-21T14:59:41.000Z","size":10,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-20T19:37:41.574Z","etag":null,"topics":["compiler","grammar","grammar-parser","lexer","lexer-generator","lexical-analyzer","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sergey0xff.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-06-24T21:41:52.000Z","updated_at":"2024-08-11T23:54:37.000Z","dependencies_parsed_at":"2023-05-29T16:00:30.089Z","dependency_job_id":null,"html_url":"https://github.com/sergey0xff/lexit","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/sergey0xff%2Flexit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergey0xff%2Flexit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergey0xff%2Flexit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergey0xff%2Flexit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sergey0xff","download_url":"https://codeload.github.com/sergey0xff/lexit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253839340,"owners_count":21972313,"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":["compiler","grammar","grammar-parser","lexer","lexer-generator","lexical-analyzer","python","python3"],"created_at":"2024-11-09T14:13:05.161Z","updated_at":"2025-05-12T23:27:34.975Z","avatar_url":"https://github.com/sergey0xff.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lexit\nLexit is an open source lexer generator written in Python3.6 using new features like `NamedTuple`, type hinting and `__init_subclass__` hook.\n\n## Simple example\n```python\nfrom typing import Iterable\n\nfrom lexit import Lexer, Token\n\n\nclass MyLexer(Lexer):\n    NUMBER = '\\d+'\n    ADD = '\\+'\n    SUB = '-'\n    MUL = '\\*'\n    DIV = '/'\n\n    ignore = r'\\s+'\n\n\ntokens_iter: Iterable[Token] = MyLexer.lex('2 + 2')\nprint(*tokens_iter, sep='\\n')\n```\nProduces the following output\n```python\nToken(type='NUMBER', value='2', line=1, column=1)\nToken(type='ADD', value='+', line=1, column=3)\nToken(type='NUMBER', value='2', line=1, column=5)\n```\n\n## Requirements\n* The only requirement is Python3.6+\n* For testing the `pytest` library is used\n\n## Installation\n```bash\npip install lexit\n```\n\n## Error handling\n```\ntry:\n    tokens = list(JsonLexer.lex('${\"hello\": \"world\"}'))\nexcept LexerError as e:\n    print(e.pretty())\n    exit(1)\n\n# The error message is self-describing\n# It shows what happened and where \nNo match for character '$' in line 1 column 1\n${\"hello\": \"world\"}\n^\n```\n\n## Design decisions\n* Should be easy to use\n* Longest match priority (`++` always wins over `+` despite of the order in which the tokens are defined in the lexer class)\n* Self-describing errors for humans (it's should be obvious what happened and where)\n\n## More examples\n### JSON lexer\n```python\nfrom lexit import Lexer\n\n\nclass JsonLexer(Lexer):\n    NUMBER = r'-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?'\n    STRING = r'\"(\\\\\\\"|\\\\\\\\|[^\"\\n])*?\"i?'\n    L_BRACE = r'{'\n    R_BRACE = r'}'\n    L_BRACKET = r'\\['\n    R_BRACKET = r'\\]'\n    TRUE = r'true'\n    FALSE = r'false'\n    NULL = r'null'\n    COMMA = r','\n    COLON = r':'\n\n    ignore = r'\\s+'\n\n\ntokens = list(JsonLexer.lex('{\"hello\": \"world\"}'))\n``` \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergey0xff%2Flexit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergey0xff%2Flexit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergey0xff%2Flexit/lists"}