rp is an abstraction of the programming language php. It has clean syntax, free of some repetitive php elements (such as $), including support for many php functions and segments (called snippets) that help you create files with less code content.
- Simple Syntax
- Normal Object-oriented Features (e.g. class, method calls)
- Highly Portable (works on many Unix-like/POSIX compatible platforms as well as Windows, macOS, Haiku, etc.), i. e. all platforms supported by NodeJS.
- Fast compilation.
rp detects and solves basic mathematical expressions, thus shortening the resulting source code in php.
[
item -> "Hello",
item2 -> 23,
]The equivalent in PHP is:
array(
item => ("Hello"),
item2 => (23)
)Go to resources
The packet import has a pattern similar to php; def instead of function.
use "My\Full\Namespace"
use "My\Full\Namespace" as Namespace
use def "My\Full\Namespace"
use def "My\Full\Namespace" as NamespaceThe equivalent in PHP is:
use My\Full\Namespace;
use My\Full\Namespace as Namespace;
use function My\Full\Namespace;
use function My\Full\Namespace as Namespace;Go to resources
abc = 2The equivalent in PHP is:
$abc = 2;Go to resources
println "abc"
print 2*4The equivalent in PHP is:
echo "abc" . PHP_EOL;
echo 8;Go to resources
The types of variables available in rp are identical to php.
| rp | php |
|---|---|
| integer | integer |
| float | float |
| string | string |
| array | array |
Go to resources
You can quickly create a try catch without specifying the exception type. By default rp will assign the generic exception for PHP, called Exception.
try
print "Hello"
/* Something with errors */
catch
print "Error" . e
endNote that the variable
ecan be called from rp without it being visually defined since in PHP it is.
The equivalent in PHP is:
try {
echo "Hello";
/* Something with errors */
} catch (Exception $e) {
echo "Error" . $e;
}Go to resources
If the function has no arguments then the parentheses can be omitted
def hello
abc = "Hello"
println abc
endThe equivalent in PHP is:
function hello(){
$abc = "Hello";
echo $abc . PHP_EOL;
}Go to resources
def hello(msg:string)
print "Hello " . msg
endThe equivalent in PHP is:
function hello(string $msg){
echo "Hello " . $msg;
}Go to resources
if abc
print "This is " . abc
endThe equivalent in PHP is:
if($abc) {
echo "This is " . $abc;
}Go to resources
for 10
println "This is repeated 10 times."
endThe equivalent in PHP is:
for ($__index__ = 0; $__index__ <= 10; $__index__++) {
echo "This is repeated 10 times." . PHP_EOL;
}Go to resources
each abc as x
print "Hello" . x
endThe equivalent in PHP is:
foreach ($abc as $x) {
echo "Hello" . $x;
}Go to resources
The definition of comments is the same as in php, except comments with the symbol #.
// This a comment
/*
* Another longer comment
*/Go to resources
The classes to be inherited are declared after the colon symbol.
Note: The possibility of allowing the inheritance of multiple objects is being evaluated.
class database
def __construct
print "Initialized..."
end
end
class database : mysqli
def __construct
print "Initialized..."
end
endThe equivalent in PHP is:
class database {
function __construct() {
echo "Initialized...";
}
}
class database extends mysqli {
function __construct() {
echo "Initialized...";
}
}Go to resources
The @ character is used to define or retrieve an object from a class.
Note the attribute
namein the example here:
class Pet
private name = "Kitty"
public age = 2
def getName
return @name
end
endThe equivalent in PHP is:
class Pet {
private $name = "Kitty";
public $age = 2;
function getName() {
return $this->$name;
}
}Go to resources
| Description | rp | php |
|---|---|---|
| get the type of data | typeof value |
gettype($value) |
| returns a number vector from a range | 1..6 |
array(1,2,3,4,5,6) |
TODO: Write doc
You can test the rp locally with these steps:
-
Install jison-gho globally. (
npm install -g jison-gho) -
Compile grammar.
cd src jison grammar.jison # you can also run this command npm run build
-
Ready, write your magic.
Unit tests
npm testRemember to install the npm packages: npm install or yarn
- Arrays
- Inheritance of multiple classes
- 'implements'
- Special conditions, as well as coffeescript...
- Access to PHP's own functions
- CLI
Many more features come...