{"id":29878138,"url":"https://github.com/bencz/go-plus","last_synced_at":"2026-05-18T09:38:17.971Z","repository":{"id":307094811,"uuid":"1028303236","full_name":"bencz/go-plus","owner":"bencz","description":"A transpiler that adds classes and exceptions to Go, converting Go-Extended syntax to standard Go code. Supports multi-file projects with dependency resolution","archived":false,"fork":false,"pushed_at":"2025-07-29T12:34:41.000Z","size":77,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-29T12:51:58.164Z","etag":null,"topics":["compiler","exceptions","go","golang","oop","transpiler"],"latest_commit_sha":null,"homepage":"","language":"Python","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/bencz.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-29T10:27:12.000Z","updated_at":"2025-07-29T12:34:44.000Z","dependencies_parsed_at":"2025-07-29T12:52:00.583Z","dependency_job_id":"850ab47b-30dd-4449-bd7d-af37933450da","html_url":"https://github.com/bencz/go-plus","commit_stats":null,"previous_names":["bencz/go-plus"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/bencz/go-plus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencz%2Fgo-plus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencz%2Fgo-plus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencz%2Fgo-plus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencz%2Fgo-plus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bencz","download_url":"https://codeload.github.com/bencz/go-plus/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencz%2Fgo-plus/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268003444,"owners_count":24179290,"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","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["compiler","exceptions","go","golang","oop","transpiler"],"created_at":"2025-07-31T07:01:19.224Z","updated_at":"2026-05-18T09:38:12.934Z","avatar_url":"https://github.com/bencz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go-Plus Transpiler\n\n**ATTENTION: THIS IS AN EXPERIMENTAL PROJECT!**\n\nA complete transpiler that extends Go with object-oriented features like classes, inheritance, and exception handling, then converts the extended syntax back to idiomatic standard Go code.\n\n## Key Features:\n- Classes with inheritance and constructors\n- Exception handling (try/catch/finally/throw)\n- Multi-file project support with automatic dependency resolution\n- Centralized exception management\n- Complete CLI with project scaffolding\n- Generates clean, readable Go code\n\nPerfect for developers who want OOP features in Go while maintaining compatibility with the standard Go ecosystem.\n\n**Supports both single files and complete multi-file projects with packages.**\n\n## Features\n\n### Supported Extensions\n\n#### Classes\n- Class definitions with fields and methods\n- Custom constructors\n- Simple inheritance with `extends`\n- `this` reference for the current object\n- `super` reference for the parent class\n- Instantiation with `new ClassName(args)`\n\n#### Exceptions\n- `try/catch/finally` blocks\n- `throw` command to throw exceptions\n- Multiple `catch` blocks with specific types\n- Exception system based on interfaces\n\n### Go-Plus Syntax\n\n#### Classes\n```go\nclass Person {\n    name string\n    age int\n    \n    // Constructor\n    Person(n string, a int) {\n        this.name = n\n        this.age = a\n    }\n    \n    getName() string {\n        return this.name\n    }\n    \n    setAge(a int) {\n        if a \u003c 0 {\n            throw new Exception(\"InvalidAge\", \"Age cannot be negative\")\n        }\n        this.age = a\n    }\n}\n\nclass Student extends Person {\n    studentId string\n    \n    Student(n string, a int, id string) {\n        super(n, a)\n        this.studentId = id\n    }\n    \n    study() {\n        fmt.Printf(\"%s is studying\\n\", this.name)\n    }\n}\n```\n\n#### Exceptions\n```go\nfunc main() {\n    try {\n        person := new Person(\"John\", -5)\n    } catch (Exception e) {\n        fmt.Printf(\"Error: %s\\n\", e.Error())\n    } finally {\n        fmt.Println(\"Cleanup\")\n    }\n}\n```\n\n## How to Use\n\n### Installation\n```bash\n# Clone or download the transpiler files\ncd goe2go\n```\n\n### Main CLI - goe2go.py\n\nThe transpiler offers two operation modes:\n\n#### 1. Complete Projects (Recommended)\n\n```bash\n# Initialize new project\npython3 goe2go.py init my_project --module github.com/user/my_project\n\n# Build project\npython3 goe2go.py build\n\n# Build and run\npython3 goe2go.py run\n\n# Show project information\npython3 goe2go.py info\n```\n\n#### 2. Single Files\n\n```bash\n# Transpile a single file\npython3 goe2go.py transpile examples/example1.gox -o output.go\n\n# Verbose mode\npython3 goe2go.py transpile examples/example1.gox -o output.go -v\n```\n\n### Project Structure\n\nA Go-Plus project has the following structure:\n\n```\nmy_project/\n├── goe2go.json          # Project configuration\n├── src/                 # Go-Plus source code\n│   ├── main/\n│   │   └── main.gox\n│   ├── models/\n│   │   ├── person.gox\n│   │   └── student.gox\n│   └── utils/\n│       └── validator.gox\n└── build/               # Generated Go code\n    ├── go.mod\n    ├── exceptions/\n    │   └── exceptions.go\n    └── src/\n        ├── main/\n        ├── models/\n        └── utils/\n```\n\n### Project Configuration (goe2go.json)\n\n```json\n{\n  \"name\": \"my_project\",\n  \"version\": \"1.0.0\",\n  \"main_package\": \"main\",\n  \"source_dir\": \"src\",\n  \"output_dir\": \"build\",\n  \"go_mod_name\": \"github.com/user/my_project\"\n}\n```\n\n### Testing\n```bash\n# Run tests\npython3 test_transpiler.py\n\n# Complete demonstration\npython3 demo.py\n```\n\n## Architecture\n\n### Components\n\n1. **Lexer** (`lexer.py`)\n   - Converts source code to tokens\n   - Supports all Go keywords + extensions\n   - Handles comments, strings and numbers\n\n2. **Parser** (`parser.py`) \n   - Converts tokens to AST (Abstract Syntax Tree)\n   - Implements grammar for Go + classes + exceptions\n   - Syntax analysis with error recovery\n\n3. **AST Nodes** (`ast_nodes.py`)\n   - Syntax tree node definitions\n   - Structures for classes, methods, exceptions\n   - Well-defined type hierarchy\n\n4. **Transpiler** (`transpiler.py`)\n   - Converts AST to standard Go code\n   - Classes → structs + methods with receivers\n   - Exceptions → defer/recover + interfaces\n   - Constructors → `NewClassName` functions\n\n5. **Project Manager** (`project_manager.py`)\n   - Manages multi-file projects\n   - Resolves dependencies between packages\n   - Topological sorting for transpilation\n   - Generates centralized exceptions file\n\n6. **CLI** (`goe2go.py`)\n   - Main command line interface\n   - Support for projects and single files\n   - Commands: init, build, run, info, transpile\n\n### Main Conversions\n\n#### Classes to Structs\n```go\n// Go-Plus\nclass Person {\n    name string\n    age int\n    \n    Person(n string, a int) {\n        this.name = n\n        this.age = a\n    }\n    \n    greet() {\n        fmt.Printf(\"Hello, I'm %s\\n\", this.name)\n    }\n}\n\n// Standard Go\ntype Person struct {\n    name string\n    age int\n}\n\nfunc NewPerson(n string, a int) *Person {\n    obj := \u0026Person{}\n    obj.name = n\n    obj.age = a\n    return obj\n}\n\nfunc (this *Person) greet() {\n    fmt.Printf(\"Hello, I'm %s\\n\", this.name)\n}\n```\n\n#### Inheritance to Embedding\n```go\n// Go-Plus\nclass Student extends Person {\n    studentId string\n    \n    Student(n string, a int, id string) {\n        super(n, a)\n        this.studentId = id\n    }\n}\n\n// Standard Go\ntype Student struct {\n    Person\n    studentId string\n}\n\nfunc NewStudent(n string, a int, id string) *Student {\n    obj := \u0026Student{}\n    obj.Person = *NewPerson(n, a)\n    obj.studentId = id\n    return obj\n}\n```\n\n#### Exceptions to Defer/Recover\n```go\n// Go-Plus\ntry {\n    riskyOperation()\n} catch (Exception e) {\n    fmt.Println(\"Error:\", e.Error())\n} finally {\n    cleanup()\n}\n\n// Standard Go (with centralized exceptions file)\nfunc() {\n    defer func() {\n        if r := recover(); r != nil {\n            var ex exceptions.Exception\n            if e, ok := r.(exceptions.Exception); ok {\n                ex = e\n            } else {\n                ex = exceptions.NewException(\"RuntimeError\", fmt.Sprintf(\"%v\", r))\n            }\n            \n            if true {\n                e := ex\n                fmt.Println(\"Error:\", e.Error())\n            }\n        }\n    }()\n    \n    defer func() {\n        cleanup()\n    }()\n    \n    riskyOperation()\n}()\n```\n\n#### Centralized Exception System\n\nIn projects, exceptions are centralized in a dedicated package:\n\n```go\n// exceptions/exceptions.go\npackage exceptions\n\ntype Exception interface {\n    Error() string\n    Type() string\n}\n\ntype BaseException struct {\n    message string\n    exType string\n}\n\nfunc NewException(exType, message string) Exception {\n    return \u0026BaseException{message: message, exType: exType}\n}\n```\n\nEach file that uses exceptions automatically imports:\n```go\nimport \"github.com/user/project/exceptions\"\n```\n\n## Examples\n\n### Example 1: Complete Project\n\nLet's create an example project with multiple packages:\n\n```bash\n# Create project\npython3 goe2go.py init example --module github.com/user/example\ncd example\n```\n\n#### Compiling the Provided Example Project\n\nTo build the included example project, run:\n\n```bash\npython3 goe2go.py build -d example_project -v\n```\n\n#### src/models/person.gox\n```go\npackage models\n\nimport \"fmt\"\n\nclass Person {\n    name string\n    age int\n    \n    Person(n string, a int) {\n        this.name = \"Unknown\"\n        this.age = 0\n        \n        if a \u003c 0 {\n            throw new Exception(\"InvalidAge\", \"Age cannot be negative\")\n        }\n        \n        this.name = n\n        this.age = a\n    }\n    \n    getName() string {\n        return this.name\n    }\n    \n    setAge(a int) {\n        if a \u003c 0 {\n            throw new Exception(\"InvalidAge\", \"Age cannot be negative\")\n        }\n        this.age = a\n    }\n    \n    greet() {\n        fmt.Printf(\"Hello, I'm %s and I'm %d years old\\n\", this.name, this.age)\n    }\n}\n```\n\n#### src/models/student.gox\n```go\npackage models\n\nimport \"fmt\"\n\nclass Student extends Person {\n    studentId string\n    grade float64\n    \n    Student(n string, a int, id string) {\n        super(n, a)\n        this.studentId = id\n        this.grade = 0.0\n    }\n    \n    setGrade(g float64) {\n        if g \u003c 0.0 || g \u003e 10.0 {\n            throw new Exception(\"InvalidGrade\", \"Grade must be between 0 and 10\")\n        }\n        this.grade = g\n    }\n    \n    study() {\n        fmt.Printf(\"%s (ID: %s) is studying\\n\", this.name, this.studentId)\n    }\n}\n```\n\n#### src/main/main.gox\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/user/example/src/models\"\n)\n\nfunc main() {\n    try {\n        person := new models.Person(\"John\", 25)\n        person.greet()\n        \n        student := new models.Student(\"Mary\", 20, \"S123\")\n        student.setGrade(8.5)\n        student.study()\n        \n    } catch (Exception e) {\n        fmt.Printf(\"Error: %s\\n\", e.Error())\n    }\n}\n```\n\n#### Build and Run\n```bash\n# Build project\npython3 goe2go.py build\n\n# Run\npython3 goe2go.py run\n```\n\n### Example 2: Single File\n\nSee `examples/example1.gox` for a single file example:\n- Classes with inheritance\n- Constructors\n- Methods\n- Exception handling\n\n```bash\n# Transpile single file\npython3 goe2go.py transpile examples/example1.gox -o output.go\n```\n\n## Current Limitations\n\n1. **Classes**\n   - No access modifiers (private, protected)\n   - No static methods/fields\n   - Multiple inheritance not supported\n   - No interfaces as field types\n\n2. **Exceptions**\n   - Simplified string-based system\n   - No detailed stack traces\n   - Finally always executes (even with panic)\n\n3. **General**\n   - No generics support\n   - Limited type analysis\n   - Basic error messages\n\n## Recent Improvements\n\n### System Features\n- Complete multi-file project support\n- Automatic dependency resolution between packages\n- Topological sorting for correct transpilation\n- Centralized exceptions file (avoids duplication)\n- Complete CLI with `init`, `build`, `run`, `info` commands\n\n### Exception Management\n- Centralized system in dedicated `exceptions` package\n- Avoids code duplication between files\n- Automatic imports for files using exceptions\n- Go modules compatibility\n\n### CLI Improvements\n- Project vs single file mode\n- Custom directory support\n- Verbose mode for debugging\n- Automatic `go.mod` generation\n\n## Project Files\n\n```\ngoe2go/\n├── goe2go.py              # Main CLI\n├── main.py                # Single file CLI (legacy)\n├── tokens.py              # Token definitions\n├── lexer.py               # Lexical analyzer\n├── ast_nodes.py           # AST nodes\n├── parser.py              # Syntax analyzer\n├── transpiler.py          # Go code generator\n├── project_manager.py     # Project manager\n├── test_transpiler.py     # Automated tests\n├── README.md              # Documentation\n├── requirements.txt       # Python dependencies\n├── examples/              # Single file examples\n│   ├── example1.gox\n│   ├── example2.gox\n│   └── advanced_example.gox\n└── example_project/       # Example project\n    ├── goe2go.json\n    ├── src/\n    │   ├── main/\n    │   ├── models/\n    │   └── utils/\n    └── build/             # Generated Go code\n        ├── go.mod\n        ├── exceptions/\n        └── src/\n```\n\n## Contributing\n\n1. Fork the project\n2. Create a branch for your feature\n3. Add tests for new functionality\n4. Run `python3 test_transpiler.py` to verify\n5. Commit your changes\n6. Open a Pull Request\n\n## License\n\nThis project is open source. Feel free to use, modify and distribute.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbencz%2Fgo-plus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbencz%2Fgo-plus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbencz%2Fgo-plus/lists"}