Code Monkey home page Code Monkey logo

rp's Introduction

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

rp's People

Contributors

juliandavidmr avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rp's Issues

Casting

Define casting objects, use keyword as. Example:

Myvariable as int

Sent from my Moto G(4) using FastHub

Interfaces implementation

It is proposed that the implementation of class interfaces could be:

class Abc < Ixyz 
    /* something... */
end

The < symbol is used to implement interface Ixyz

Arrow functions

The arrow functions could be:

hello = (msg) => "Hello" . msg

converts to:

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

Define enum var

It is proposed to create enum type variables based on the answer given here.

rp

enum Response {
    No = 0,
    Yes = 1,
}

php

abstract class Response {
    const No = 0;
    const Yes = 1;
}

for - julia

julia> for i = 1:2, j = 3:4
println((i, j))
end
(1, 3)
(1, 4)
(2, 3)
(2, 4)

Create CLI

Create CLI:

  1. Process multiple (or one) files with extension ". rp" to PHP. The program must preserve the original directory tree.
  2. Help commands.
  3. Some utilities......

Future

It could be that RP is beginning to become oriented to be a language with a lot of mathematical functions, something similar to R, Julia, Matlab, and others.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.