ride/lib-tokenizer

There is no license information available for the latest version (1.0.2) of this package.

Tokenizer library of the Ride framework.

1.0.2 2018-03-29 09:43 UTC

This package is auto-updated.

Last update: 2024-10-13 00:11:41 UTC


README

This library gives you some classes to parse a string into tokens.

Code Sample

Some example code in the context of the ORM module:

<?php

use ride\library\tokenizer\symbol\NestedSymbol;
use ride\library\tokenizer\symbol\SimpleSymbol;
use ride\library\tokenizer\Tokenizer;

$tokenizer = new Tokenizer();
$tokenizer->setWillTrimTokens(true);
$tokenizer->addSymbol(new SimpleSymbol('AND'));
$tokenizer->addSymbol(new SimpleSymbol('OR'));
$tokenizer->addSymbol(new NestedSymbol('(', ')', $tokenizer));

$condition = '{field} = %2% AND {field2} <= %1%';
$tokens = $tokenizer->tokenize($condition);
// array(
//    '{field} = %2%', 
//    'AND', 
//    '{field2} <= %1%'
// )

$condition = '{field} = 5 AND ({field2} <= %1% OR {field2} >= %2%)';
$tokens = $tokenizer->tokenize($condition);
// array(
//    '{field} = 5', 
//    'AND', 
//    array(
//        '{field2} <= %1%'), 
//        'OR', 
//        '{field2} >= %2%'),
//    )
// )

Implementations

For more examples, you can check the following implementation of this library:

Installation

You can use Composer to install this library.

composer require ride/lib-tokenizer