Skip to main content

Custom Syntax for Python Language -- CSPLang

Project description

CSPLang – Custom Syntax for Python Language

GITHUB: https://github.com/Ansari-Codes/custom-syntax-for-python
PYPI: https://pypi.org/project/csp-lang/

CSPLang is a high-speed, symbolic syntactic wrapper for Python. It transforms a compact, symbol-heavy DSL into executable Python code. Designed with the principle of "Write less, do more," CSPLang turns Python's keyword-heavy structure into a sleek, streamlined experience.

The CSPLang Philosophy: What if you had the full power of the Python ecosystem, but with the minimalist elegance of a functional language?


🚀 Key Features (v2.0)

  • Recursive One-Liners: Define functions, loops, and conditions all on a single line.
  • Context-Aware Parsing: Intelligently distinguishes between logic colons and data colons (like in dictionaries or list slices).
  • Symbolic Identity: Replaces verbose keywords (def, while, return) with intuitive symbols ($, >>, ->).
  • Zero-Overhead Integration: Use any Python library (numpy, tqdm, asyncio) out of the box.

🛠 Installation

Using git

# Clone and Install
git clone https://github.com/Ansari-Codes/custom-syntax-for-python.git
cd custom-syntax-for-python
pip install .

Using pip+git

pip install git+https://github.com/Ansari-Codes/custom-syntax-for-python.git

From pypi

pip install csp-lang

📝 Syntax Overview

1. Variables & Assignment

Use the "flow" operator <- for assignment.

name <- `Abubakar`
age  <- 19
data <- [1, 2, 3]

2. Universal Strings

Forget f"", "", or ''' '''. Use backticks for everything. They support multiple lines and escaped backticks (`).

msg <- `This is a 
multi-line string with a \`backtick\` inside.`

# F-strings work naturally:
print(f`Hello, {name}!`)

3. Conditionals (Implicit If)

No need to type if. A standalone condition ending in a colon is automatically treated as a conditional.

x <- 10

x > 5:               # This is 'if'
    print(`Large`)
: x == 5:            # This is 'elif'
    print(`Medium`)
:                    # This is 'else'
    print(`Small`)

# NEW: One-liners are now supported!
x == 10: print(`Perfect Score`)

4. Loops

  • While: Use >>
  • For: Use => (where : replaces in)
# While Loop
count <- 3
>> count > 0: 
    print(count) 
    count <- count - 1

# For Loop
=> i:range(3):
    print(f`Iteration {i}`)

5. Functions & Methods

Defined using $ and []. The -> symbol acts as the return.

# Standard definition
$add[a, b]:
    -> a + b

# Works inside classes too!
class Math:
    $cube[self, n]: 
        -> n ** 3

⚡ Extreme Flexibility (v2.0 Stress Test)

Because CSPLang v2.0 uses a Recursive Split Strategy, it can handle complex Python constructs mixed with CSP symbols without breaking.

# Slicing and Dictionaries work perfectly!
data <- [10, 20, 30, 40]
subset <- data[1:3]             # Transpiler ignores the slice colon
results <- {`val`: subset[0]}    # Transpiler ignores the dict colon

# Complex nesting and one-lining
$check[n]: 
    >> n > 0: 
        n%2==0:
            print("Even: ", n)
        :n%2!=0: print("Odd: ", n)
        :print(n in [1, 2, 3, 4][:2])
        n <- n - 1
check(10)

💻 CLI Usage

Command Description
csp run file.csp Transpiles and executes immediately.
csp transpile file.csp -o out.py Converts CSP to a standalone Python file.
csp test Runs the internal test suite.

👨‍💻 Developer

I am Muhammad Abubakar Siddique Ansari, a 1st-year ICS student at KIPS College, Punjab (Pakistan). I'm passionate about Data Science, AI, and building tools that make developers' lives easier.

Portfolio: ansari-codes.github.io/portfolio


Logo

logo

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

csp_lang-2.0.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

csp_lang-2.0.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file csp_lang-2.0.0.tar.gz.

File metadata

  • Download URL: csp_lang-2.0.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for csp_lang-2.0.0.tar.gz
Algorithm Hash digest
SHA256 a82f61b764f5c5ae7421e3f4b301f833624129bd834e7f6a5e17f6f4d280c8ba
MD5 727feea941932d36b0fc56bb7fdf92c3
BLAKE2b-256 952050fc6f1c9b6a424776689b2f2d704400009f018016c7937bde8da18c4aca

See more details on using hashes here.

File details

Details for the file csp_lang-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: csp_lang-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for csp_lang-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08325057e7ee7510eee207169faa04b00c61c6839ccb076eeede755bef4455b9
MD5 5248eaef2bcb2c8f24d320c54e304fac
BLAKE2b-256 ac5db235ca28aa393d3f561602ac9949b27aee980d49346cfec45d6037e2ca3b

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