PHPackages                             nathanntg/lite-lexer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. nathanntg/lite-lexer

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

nathanntg/lite-lexer
====================

A light-weight, relatively fast lexer for use in PHP. Example includes a simple query language.

0.1.0(8y ago)5133[2 issues](https://github.com/nathanntg/lite-lexer/issues)MITPHPPHP &gt;=5.3.0CI failing

Since Nov 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/nathanntg/lite-lexer)[ Packagist](https://packagist.org/packages/nathanntg/lite-lexer)[ Docs](https://github.com/nathanntg/lite-lexer)[ RSS](/packages/nathanntg-lite-lexer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (4)Used By (0)

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

[](#installation)

This package is available via composer and can be added to a project using the command:

```
$ composer require nathanntg/lite-lexer
```

Usage
-----

[](#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:

```
$parser = new MyParser();

// parse string
$tree = $parser->parseString($string_to_parse);

// optional: remove unneeded leaves and branches
$tree->prune();

// print debugging tree
$tree->debug();
```

Example Implementation
----------------------

[](#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:

```
customer.namelast='' AND customer.namefirst = '' OR ( customer.namelast='' AND customer.namefirst='' )  ORDER customer.namelast DESC , customer.namelast   LIMIT 2

```

It will produce the following parse tree:

```
root
	query
		conditions_main
			condition_set_values
				conditions
					condition
						condition_standard
							column; raw "customer.namelast"; customer.namelast
							operator
								unnamed leaf; raw "="; =
							value
								value_string; raw "''";
				condition_operator
					unnamed leaf; raw "AND"; AND
				conditions
					condition
						condition_standard
							column; raw "customer.namefirst"; customer.namefirst
							operator
								unnamed leaf; raw "="; =
							value
								value_string; raw "''";
				condition_operator
					unnamed leaf; raw "OR"; OR
				conditions
					condition_set
						unnamed leaf; raw "("; (
						condition_set_values
							conditions
								condition
									condition_standard
										column; raw "customer.namelast"; customer.namelast
										operator
											unnamed leaf; raw "="; =
										value
											value_string; raw "''";
							condition_operator
								unnamed leaf; raw "AND"; AND
							conditions
								condition
									condition_standard
										column; raw "customer.namefirst"; customer.namefirst
										operator
											unnamed leaf; raw "="; =
										value
											value_string; raw "''";
						unnamed leaf; raw ")"; )
		order_by_main
			unnamed leaf; raw "ORDER"; ORDER
			order_by_columns
				order_by_column
					column; raw "customer.namelast"; customer.namelast
					order_by_direction
						unnamed leaf; raw "DESC"; DESC
				order_by_column
					column; raw "customer.namelast"; customer.namelast
		limit_main
			unnamed leaf; raw "LIMIT"; LIMIT
			limit_count; raw "2"; 2

```

Testing
-------

[](#testing)

You can run the PHPUnit tests using the following command (assuming installed via composer, and includes the developer requirements):

```
$ vendor/bin/phpunit tests
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3102d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/814add1459d67158a366be384a67f490b20351cc3466c61ac81ad7f52ae3f443?d=identicon)[nathanntg](/maintainers/nathanntg)

---

Top Contributors

[![nathanntg](https://avatars.githubusercontent.com/u/194728?v=4)](https://github.com/nathanntg "nathanntg (10 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nathanntg-lite-lexer/health.svg)

```
[![Health](https://phpackages.com/badges/nathanntg-lite-lexer/health.svg)](https://phpackages.com/packages/nathanntg-lite-lexer)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M283](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M226](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M63](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M343](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
