Download the PHP package nathanntg/lite-lexer without Composer
On this page you can find all versions of the php package nathanntg/lite-lexer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nathanntg/lite-lexer
More information about nathanntg/lite-lexer
Files in nathanntg/lite-lexer
Package lite-lexer
Short Description A light-weight, relatively fast lexer for use in PHP. Example includes a simple query language.
License MIT
Homepage https://github.com/nathanntg/lite-lexer
Informations about the package lite-lexer
lite-lexer
A light-weight PHP-based string lexer. By defining parser blocks, a simple syntax can be defined. The parser will then build a tree representing the parsed string. This can then be interpreted for other uses.
I created this for a simple query language to read custom data from a model system, but it can easily be adapted to other syntaxes. It has relatively low overhead, and based on my testing performed fast (enough so for my application).
Installation
This package is available via composer and can be added to a project using the command:
Usage
The recommended usage is to subclass LiteLexer\Parser
to define your own syntax blocks
(see the example implementation). Then you can run your parser as follows:
Example Implementation
The example folder contains a QueryParser class that implements the parser needed to read a basic query language. Specifically, given an input string like the following:
It will produce the following parse tree:
Testing
You can run the PHPUnit tests using the following command (assuming installed via composer, and includes the developer requirements):