Nginr - Python Alt syntax with fn keyword and .xg files
Project description
Nginr
Nginr is a Python syntax alternative that allows using the fn keyword instead of def. Nginr is not a new programming language, but rather a preprocessor that converts code with the .xg extension into standard Python code before execution.
Installation
Using pip (easiest way)
pip install nginr
Installation from source
- Clone this repository:
git clone https://github.com/nginrsw/nginr.git
cd nginr
- Install in development mode:
pip install -e .
Requirements
- Python 3.6 or newer
- pip (Python package manager)
Basic Usage
- Create a file with
.xgextension, for examplehello.xg:
# hello.xg
fn hello(name):
print(f"Hello, {name}!")
hello("World")
- Run the file with the command:
nginr hello.xg
How It Works
- Nginr reads files with
.xgextension - Performs simple preprocessing (replaces
fnwithdef) - Executes the resulting Python code
More Examples
Function with Parameters
fn add(a, b):
return a + b
result = add(5, 3)
print(f"5 + 3 = {result}")
Loops and Conditionals
fn factorial(n):
if n <= 1:
return 1
return n * factorial(n - 1)
for i in range(1, 6):
print(f"{i}! = {factorial(i)}")
Features
- Full Python Compatibility: Use any Python library or framework
- Alternative Syntax:
fnkeyword as an alternative todef - Seamless Integration: Works with existing Python code and tools
- Lightweight: Simple preprocessing with minimal overhead
- Extensible: Supports all Python 3.7+ features and libraries
Python Library Compatibility
Nginr is 100% compatible with Python libraries. You can use any Python package in your .xg files:
# Using external libraries
fn calculate_stats(data):
import numpy as np
import pandas as pd
df = pd.DataFrame(data)
return {
'mean': np.mean(df.values),
'std': np.std(df.values),
'sum': np.sum(df.values)
}
# Using standard library
fn get_weather(city):
import json
from urllib.request import urlopen
with urlopen(f'https://weather.example.com/api?city={city}') as response:
return json.load(response)
Installing Dependencies
You can install Python packages using pip as usual:
# Install packages for your Nginr project
pip install numpy pandas requests
Limitations
- Only performs simple preprocessing (replaces
fnwithdef) - No additional features beyond standard Python
- Lacks full programming language features like type systems or custom compilers
- Debugging shows the generated Python code, not the original
.xgsource
Contributing
Contributions are welcome! If you'd like to contribute, please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Lisensi
MIT
Editor Support
Visual Studio Code
- Make sure you have the Pyright extension installed
- Add the following configuration to
.vscode/settings.json:
{
"files.associations": {
"*.xg": "python"
},
"python.analysis.extraPaths": ["."],
"python.analysis.typeCheckingMode": "basic"
}
Pyright Support
For better LSP support, use the Nginr Pyright plugin:
- Install the plugin:
pip install git+https://github.com/nginrsw/nginr.git#subdirectory=pyright_plugin_nginr
- Buat file
pyrightconfig.jsondi root project:
{
"plugins": ["nginr_pyright"],
"include": ["**/*.py", "**/*.xg"],
"exclude": ["**/node_modules", "**/__pycache__"]
}
Support
If you encounter any issues or have questions, please open a new issue in the repository.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nginr-0.1.1.tar.gz.
File metadata
- Download URL: nginr-0.1.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a83b5ba4e3f19704d1e2bd9244f5895d3d239bc96a5b6a3243bc4da0c293afa
|
|
| MD5 |
d317a5be9be2888d30f61840862deefc
|
|
| BLAKE2b-256 |
d4bbe1568f366a0d75bd777a6edf8aa7c0ec12a8b427ea0a7cd420c132aed6d3
|
File details
Details for the file nginr-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nginr-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
694f5310fd49b528ad897722bb7ee41be220375726172f59c379b75692fba109
|
|
| MD5 |
dd970f2285ec5c1fb44ca295c0e6ba60
|
|
| BLAKE2b-256 |
7cbdfa20e2473367bef4def5f66e2be330dec144ece0f69a418979be6d0b647b
|