Skip to content

devdasher/php-dsl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

⚙️ PHP DSL Converter (from .ephp to .php)

✨ A lightweight, smart DSL (Domain-Specific Language) that compiles .ephp files into modern, readable PHP — helping you write PHP faster, cleaner, and more pythonic 🐍➡️🐘


🚀 What is this?

This is a simple DSL that allows you to write .ephp files (inspired by Python syntax) and convert them to standard PHP code.

Yes! You can write Python-style code that becomes valid PHP!

No need to worry about {} or $ or even boilerplate functions. Just focus on logic — this tool handles the transformation.


✅ Features

  • func keyword for PHP functions (with type hints and default values)
  • with ... as ...: context blocks (auto fclose on file handles)
  • match ...: expressions with case, default, assignment or return
  • do: and while ... structure
  • for x in range(...) and for x in collection: loops
  • Inline ternary expressions
  • Anonymous functions: x = fn(...) => ... and multiline ones too
  • Python-like expressions (a and b, not, True, len(x)count($x), etc.)
  • F-Strings: f"Hello {name}!""Hello " . $name . "!"
  • Auto $ handling
  • Constants with UPPER_CASE = value
  • Native PHP support inside .ephp files
  • Readable, pretty formatted PHP output

🛣️ Roadmap

  • IntelliSense / language extension for VS Code
  • Syntax highlighting
  • Better error handling and CLI feedback
  • class / OOP support (currently not planned)
  • Support for try-except blocks
  • More advanced list and dict operations

📦 Example

example.ephp

import "utils.ephp"

func greet(name = "World") str:
    return f"Hello, {name}!"

name = input("Enter your name:")
print(greet(name))

➡️ Will be converted to:

<?php
// Generated by DSL to PHP converter
require_once "utils.php";

function greet(string $name = "World"): string {
    return "Hello, " . $name . "!";
}

$name = readline("Enter your name:");
echo greet($name);

📚 Syntax Examples

🧮 Assignments & Expressions

x = 10
name = input("Your name:")
greeting = f"Hi, {name}"

➡️

$x = 10;
$name = readline("Your name:");
$greeting = "Hi, " . $name;

🌀 Loops & Conditionals

for i in range(5):
    print(i)

if x > 5:
    print("Big")
else:
    print("Small")

➡️

for ($i = 0; $i < 5; $i += 1) {
    echo $i;
}
if ($x > 5) {
    echo "Big";
} else {
    echo "Small";
}

🔀 Match Expressions

result = match x:
    case 1: "One"
    case 2 or 3: "Two or Three"
    default: "Other"

➡️

$result = match ($x) {
    1 => "One",
    2, 3 => "Two or Three",
    default => "Other",
};

🧠 Who built this?

This entire project — including this README — was built with the help of ChatGPT and DeepSeek AI 🤖

We used AI assistance to prototype, refine, and ship this converter faster.


🙏 Contribute!

This DSL is meant to simplify PHP development and boost productivity. However, it’s still a work in progress.

If you’re a PHP developer or just love compilers / syntax tools, we’d love your help!

Why contribute?

  • Help build a minimal, powerful PHP DSL
  • Learn about DSLs, code parsing, AST-like transforms
  • Make PHP more fun and friendly

PRs are welcome. Bug reports too. Let’s make PHP great again 😄


📝 Notes

  • You can directly use any native PHP functions in .ephp files.
  • It won’t touch those lines — they'll be passed as-is.
  • Currently, IntelliSense and syntax highlighting in editors like VSCode are not available.
    • You can help by building a VSCode extension for .ephp

📂 Usage

python php_dsl.py file.ephp
# OR
python php_dsl.py file.ephp output.php

📃 License

MIT — free to use, modify, or extend.


⭐ Show your support

Star the repo if you like it. Fork it, play with it, improve it! 😎


💡 Pro Tip

Use .ephp to prototype your PHP logic faster. Once ready, convert it to .php and deploy with confidence!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages