{"id":20639220,"url":"https://github.com/alexdremov/sxtree","last_synced_at":"2026-04-21T19:31:42.713Z","repository":{"id":146181957,"uuid":"365809499","full_name":"alexdremov/SxTree","owner":"alexdremov","description":"Generate AST syntax parser from grammar file","archived":false,"fork":false,"pushed_at":"2021-05-20T21:17:11.000Z","size":3949,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-17T19:50:21.071Z","etag":null,"topics":["grammar","grammar-parser","grammar-parser-generator","lexer","lexer-framework","lexer-parser","parser","parser-framework"],"latest_commit_sha":null,"homepage":"https://AlexRoar.github.io/SxTree/","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/alexdremov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2021-05-09T17:25:08.000Z","updated_at":"2021-05-21T13:09:09.000Z","dependencies_parsed_at":"2023-09-18T07:15:14.371Z","dependency_job_id":null,"html_url":"https://github.com/alexdremov/SxTree","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alexdremov/SxTree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdremov%2FSxTree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdremov%2FSxTree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdremov%2FSxTree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdremov%2FSxTree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexdremov","download_url":"https://codeload.github.com/alexdremov/SxTree/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdremov%2FSxTree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32106612,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["grammar","grammar-parser","grammar-parser-generator","lexer","lexer-framework","lexer-parser","parser","parser-framework"],"created_at":"2024-11-16T15:23:01.591Z","updated_at":"2026-04-21T19:31:42.697Z","avatar_url":"https://github.com/alexdremov.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SxTree\n\nGenerates AST parser and lexer from grammar files. Implements:\n\n- Lexer generator\n- Parser generator\n\n## Lexer generator\n\nGenerates lexer basing on syntax file. Example:\n\n```yaml\nspace       = (skip(\"\\s\"))\nlineBreak   = [\"[\\n]+\"]\ninteger     = (\"^[-+]?[0-9]\\d*\")\nfloat       = (\"^[+-]?([0-9]*[.])?[0-9]+\")\n\ndef         = (\"def\")\n```\n\nLexer syntax grammar:\n```bash\nG       := [Rule]*\nID      := regex(^[a-zA-Z_$][a-zA-Z_$0-9]*)\nRule    := ID '=' Exp '\\n'\nExp     := '('P [, P]*')' | '['P [, P]*']' | '?['P [, P]*']'\nP(part) := skip+Exp | regex | Exp\n```\n\nSeveral main types of rules are used:\n- `'('P [, P]*')'`  – sequence of parts, all parts must be met one by one.\n- `'['P [, P]*']'`  – any of listed parts.\n- `'?['P [, P]*']'` – any of listed parts or none.\n- `skip+Exp`        - get expression and skip it.\n\nTokens parsed from top to bottom – upper statements have higher priority.\n\n### Lexer generator usage\n\nGenerator takes lexer syntax file and generates a file used by SxTree parser further.\n```bash\n\u003e sxlgen -h\nGenerate lexer file from lexer syntax\nUsage:\n  SxTree Lexer Generator [OPTION...]\n\n  -i, --input arg         Input file [required]\n  -o, --output arg        Output file (default: lexer.cpp)\n  -p, --outputHeader arg  Output header file (default: lexer.h)\n  -q, --quiet             Quiet mode (do not show errors)\n  -h, --help              Print usage\n```\n\n### Example:\n\n```bash\nspace       = (skip(\"\\s\"))\nvar         = (\"var\")\nfuncDecl    = [\"def\", \"define\"]\nok          = (\"o\", ?[\"k\"])\n```\nGenerated lexer structure:\n```cpp\nenum LexemeType {\n    lex_NONE = 0,\n    lex_space = 1,\n    lex_var = 2,\n    lex_funcDecl = 3,\n    lex_ok = 4,\n};\n\nLexer coreLexer({\n    {1, {{{ R\"()\", Value::VAL_SKIP,{{{ R\"(\\s)\", Value::VAL_REGEXP,{{}, Expression::EXP_ONE}},}, Expression::EXP_ONE}},}, Expression::EXP_ONE}},\n    {2, {{{ R\"(var)\", Value::VAL_REGEXP,{{}, Expression::EXP_ONE}},}, Expression::EXP_ONE}},\n    {3, {{{ R\"(def)\", Value::VAL_REGEXP,{{}, Expression::EXP_ONE}},{ R\"(define)\", Value::VAL_REGEXP,{{}, Expression::EXP_ONE}},}, Expression::EXP_ANY}},\n    {4, {{{ R\"(o)\", Value::VAL_REGEXP,{{}, Expression::EXP_ONE}},{ R\"()\", Value::VAL_EXPRESSION,{{{ R\"(k)\", Value::VAL_REGEXP,{{}, Expression::EXP_ONE}},}, Expression::EXP_OPTIONAL}},}, Expression::EXP_ONE}},\n});\n```\n\nHere's an example that can be found in `/examples/simple`. It is extremely easy to adjust lexer for your needs.\n\n```python\ndef someFunction() {\n    \"Hello world\"\n}\n```\n\n```bash\nLexeme\u003cid=def, start=0, size=3\u003e('def')\nLexeme\u003cid=identifier, start=4, size=12\u003e('someFunction')\nLexeme\u003cid=leftPa, start=16, size=1\u003e('(')\nLexeme\u003cid=rightPa, start=17, size=1\u003e(')')\nLexeme\u003cid=leftBlock, start=19, size=1\u003e('{')\nLexeme\u003cid=lineBreak, start=20, size=1\u003e('\\n')\nLexeme\u003cid=margin, start=21, size=4\u003e('    ')\nLexeme\u003cid=string, start=25, size=13\u003e('\"Hello world\"')\nLexeme\u003cid=lineBreak, start=38, size=1\u003e('\\n')\nLexeme\u003cid=rightBlock, start=39, size=1\u003e('}')\n```\n\n## Parser\n\nIn progress\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdremov%2Fsxtree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexdremov%2Fsxtree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdremov%2Fsxtree/lists"}