Skip to main content

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

  1. Clone this repository:
git clone https://github.com/nginrsw/nginr.git
cd nginr
  1. Install in development mode:
pip install -e .

Requirements

  • Python 3.6 or newer
  • pip (Python package manager)

Basic Usage

  1. Create a file with .xg extension, for example hello.xg:
# hello.xg
fn hello(name):
    print(f"Hello, {name}!")

hello("World")
  1. Run the file with the command:
nginr hello.xg

How It Works

  1. Nginr reads files with .xg extension
  2. Performs simple preprocessing (replaces fn with def)
  3. 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: fn keyword as an alternative to def
  • 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 fn with def)
  • 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 .xg source

Contributing

Contributions are welcome! If you'd like to contribute, please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Lisensi

MIT

Editor Support

Visual Studio Code

  1. Make sure you have the Pyright extension installed
  2. Add the following configuration to .vscode/settings.json:
{
    "files.associations": {
        "*.xg": "python"
    },
    "python.analysis.extraPaths": ["."],
    "python.analysis.typeCheckingMode": "basic"
}

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nginr-0.1.3a0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nginr-0.1.3a0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file nginr-0.1.3a0.tar.gz.

File metadata

  • Download URL: nginr-0.1.3a0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for nginr-0.1.3a0.tar.gz
Algorithm Hash digest
SHA256 bee6a1cf532956a05cba652dd791d3ef4133259ecac96ddc7b0479c74e8f3b05
MD5 b5284b7a1e300b7aad0a6670ddfd728b
BLAKE2b-256 c9c1ef7ca4f3bafa06461e67c8051b2e0a397791e84575446eea9913e66e6d27

See more details on using hashes here.

File details

Details for the file nginr-0.1.3a0-py3-none-any.whl.

File metadata

  • Download URL: nginr-0.1.3a0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for nginr-0.1.3a0-py3-none-any.whl
Algorithm Hash digest
SHA256 970b168af2b9850c2885ebbb65c9847ace501930ebf41f77bf3fa40cf17fe145
MD5 bd4d3357b49bd3656f97cd756862fc16
BLAKE2b-256 96da850de845b474f7d342427145692bac46f92073f7857456000cff5f9edb7b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page