Skip to content

rp is an abstraction of the programming language php. It has clean syntax, free of some repetitive php elements, including support for many php functions and segments that help you create files with less code content.

License

Notifications You must be signed in to change notification settings

juliandavidmr/rp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rp

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.

Features

  • 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.

Resources

Language Reference

rp detects and solves basic mathematical expressions, thus shortening the resulting source code in php.

Generic

Arrays

[
    item -> "Hello",
    item2 -> 23,
]

The equivalent in PHP is:

array(
    item  => ("Hello"),
    item2 => (23)
)

Go to resources

Imports

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 Namespace

The 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

Declare variable

abc = 2

The equivalent in PHP is:

$abc = 2;

Go to resources

Print message

println "abc"
print 2*4

The equivalent in PHP is:

echo "abc" . PHP_EOL;
echo 8;

Go to resources

Types

The types of variables available in rp are identical to php.

rp php
integer integer
float float
string string
array array

Go to resources

Try catch

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
end

Note that the variable e can 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

Functions

If the function has no arguments then the parentheses can be omitted

def hello
    abc = "Hello"
    println abc
end

The equivalent in PHP is:

function hello(){
    $abc = "Hello";
    echo $abc . PHP_EOL;
}

Go to resources

Arguments

def hello(msg:string)
    print "Hello " . msg
end

The equivalent in PHP is:

function hello(string $msg){
    echo "Hello " . $msg;
}

Go to resources

Flow controls

If

if abc
    print "This is " . abc
end

The equivalent in PHP is:

if($abc) {
    echo "This is " . $abc;
}

Go to resources

Basic loop

for 10
    println "This is repeated 10 times."
end

The equivalent in PHP is:

for ($__index__ = 0; $__index__ <= 10; $__index__++) {
    echo "This is repeated 10 times." . PHP_EOL;
}

Go to resources

Each

each abc as x
    print "Hello" . x
end

The equivalent in PHP is:

foreach ($abc as $x) {
    echo "Hello" . $x;
}

Go to resources

Comments

The definition of comments is the same as in php, except comments with the symbol #.

// This a comment

/*
* Another longer comment
*/

Go to resources

Classes

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
end

The equivalent in PHP is:

class database {
    function __construct() {
        echo "Initialized...";
    }
}

class database extends mysqli {
    function __construct() {
        echo "Initialized...";
    }
}

Go to resources

Attributes

The @ character is used to define or retrieve an object from a class.

Note the attribute name in the example here:

class Pet
    private name = "Kitty"
    public age = 2

    def getName
        return @name
    end
end

The equivalent in PHP is:

class Pet {
    private $name = "Kitty";
    public $age = 2;

    function getName() {
        return $this->$name;
    }
}

Go to resources

Segments

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)

Install

TODO: Write doc

Development

You can test the rp locally with these steps:

  1. Install jison-gho globally. (npm install -g jison-gho)

  2. Compile grammar.

    cd src
    jison grammar.jison
    
    # you can also run this command
    npm run build
  3. Ready, write your magic.

Test

Unit tests

npm test

Remember to install the npm packages: npm install or yarn

TODO

  • Arrays
  • Inheritance of multiple classes
  • 'implements'
  • Special conditions, as well as coffeescript...
  • Access to PHP's own functions
  • CLI

Many more features come...

About

rp is an abstraction of the programming language php. It has clean syntax, free of some repetitive php elements, including support for many php functions and segments that help you create files with less code content.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published