2017 © Pedro Peláez
 

library rql-parser

image

xiag/rql-parser

  • Saturday, March 11, 2017
  • by mrix
  • Repository
  • 3 Watchers
  • 18 Stars
  • 21,725 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 9 Forks
  • 2 Open issues
  • 17 Versions
  • 14 % Grown

The README.md

RQL parser

CI Packagist Version Packagist Downloads Packagist License, (*1)

This is a RQL parsing library written in PHP., (*2)

This library consists of the following parts: - lexer for tokenization RQL code - parser for creating abstract syntax tree, (*3)

Installation

The preferred way to install library is through composer., (*4)

Either run, (*5)

composer require graviton/rql-parser

or add, (*6)

"graviton/rql-parser": "*",

to the require section of your composer.json., (*7)

Basic usage

<?php
require 'vendor/autoload.php';

// default lexer supports all RQL rules
$lexer = new Graviton\RqlParser\Lexer();

// default parser contains all parsing strategies
$parser = new Graviton\RqlParser\Parser();


// RQL code
$rql = '(eq(a,string:1)|lt(b,2)|(c<>3&d>=string:4&e=eq=boolean:1))&u!=5&not(or(u=6,ge(i,10)))&z=1&(a==2|b<-3|in(c,(2,float:3)))&select(a,b)&sort(+a,-b)&limit(1,2)';

// tokenize RQL
$tokens = $lexer->tokenize($rql);


// parsing
var_dump($parser->parse($tokens));

See also rql-command library. This is a console application to debug RQL lexing and parsing., (*8)

Advanced usage

See examples:, (*9)

Current state

Operators

Basic syntax

  • scalar operators
    • eq(a,b)
    • ne(a,b)
    • lt(a,b)
    • gt(a,b)
    • le(a,b)
    • ge(a,b)
  • array operators
    • in(a,(b,c))
    • out(a,(b,c))
  • logic operators
    • and(eq(a,b),ne(c,d))
    • or(eq(a,b),ne(c,d))
    • not(eq(a,b))

Short logic syntax

  • (eq(a,b)&ne(b,c))
  • (eq(a,b)|ne(b,c))

FIQL syntax

  • scalar operators
    • a=eq=b
    • a=ne=b
    • a=lt=b
    • a=gt=b
    • a=le=b
    • a=ge=b
  • array operators
    • a=in=(b,c)
    • a=out=(b,c)

Simplified FIQL syntax

  • a=b
  • a==b
  • a<>b
  • a!=b
  • a<b
  • a>b
  • a<=b
  • a>=b

Other

  • select(a,b,c)
  • sort(+a,-b)
  • limit(1,2)

All syntax variations may be used together., (*10)

Value types

  • string
    • abc
    • abc%20def
  • integer
    • 1, +1, -1
  • float
    • 1., +1., -1.
    • 0.1, +0.1, -0.1,
    • 0.1e5, +0.1e+5, -0.1e-5
    • .1, +.1, -.1
    • .1e5, +.1e+5, -.1e-5
  • boolean
    • true()
    • false()
  • null
    • null()
  • empty
    • empty()
  • date
    • 2015-06-02T20:00:00Z
  • glob
    • abc*
    • ?abc
    • abc*def?

Type casting

  • string:1
  • boolean:0
  • integer:a
  • float:1

Encoding rules

String values

In string values all non-alphanumeric characters must be encoded with a percent (%) sign followed by two hex digits., (*11)

Examples:, (*12)

eq(string,2015%2D05%2D30T15%3A10%3A00Z)
in(string,(%2B1%2E5,%2D1%2E5))
in(string,(null%28%29,empty%28%29,true%28%29,false%28%29))

String encoding in PHP:

function encodeString($value)
{
    return strtr(rawurlencode($value), [
        '-' => '%2D',
        '_' => '%5F',
        '.' => '%2E',
        '~' => '%7E',
    ]);
}

String encoding in JavaScript:

function encodeString(value) {
    return encodeURIComponent(value).replace(/[\-_\.~!\\'\*\(\)]/g, function (char) {
        return '%' + char.charCodeAt(0).toString(16).toUpperCase();
    });
}

Other values

Date, number and const-function values must not be encoded., (*13)

Examples:, (*14)

eq(date,2015-05-30T15:10:00Z)
in(number,(+1.5,-1.5))
in(const,(null(),empty(),true(),false()))

Resources

The Versions

11/03 2017

dev-master

9999999-dev

  Sources   Download

GPL-2.0

The Requires

  • php >=5.5

 

The Development Requires

language parser rest query resource rql

11/03 2017

v2.0.1

2.0.1.0

  Sources   Download

GPL-2.0

The Requires

  • php >=5.5

 

The Development Requires

language parser rest query resource rql

03/07 2016

v2.0.0

2.0.0.0

  Sources   Download

GPL-2.0

The Requires

  • php >=5.5

 

The Development Requires

language parser rest query resource rql

03/07 2016

1.0.x-dev

1.0.9999999.9999999-dev

  Sources   Download

GPL-2.0

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

03/07 2016

v1.0.2

1.0.2.0

  Sources   Download

GPL-2.0

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

21/08 2015

v1.0.1

1.0.1.0

  Sources   Download

GPL-2.0

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

10/06 2015

v1.0.0

1.0.0.0

  Sources   Download

GPL-2.0

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

02/06 2015

v0.6.1

0.6.1.0

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

30/05 2015

v0.6.0

0.6.0.0

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

19/04 2015

v0.5.0

0.5.0.0

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

19/04 2015

v0.4.0

0.4.0.0

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

19/04 2015

v0.3.1

0.3.1.0

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

19/04 2015

v0.3.0

0.3.0.0

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

19/04 2015

v0.2.1

0.2.1.0

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

19/04 2015

v0.2.0

0.2.0.0

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

16/04 2015

v0.1.0

0.1.0.0

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql

15/04 2015

v0.0.0

0.0.0.0

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

language parser rest query resource rql