PHPackages                             lastwhitebird/lgml-parser - 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. lastwhitebird/lgml-parser

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

lastwhitebird/lgml-parser
=========================

Configuration parser custom indented config file format (like YAML, python etc.)

0.0.6beta2(6y ago)1117LGPL-2.1PHPPHP &gt;=5.6.0

Since Nov 2Pushed 3y ago3 watchersCompare

[ Source](https://github.com/lastwhitebird/lgml-parser)[ Packagist](https://packagist.org/packages/lastwhitebird/lgml-parser)[ RSS](/packages/lastwhitebird-lgml-parser/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (18)Used By (0)

Synopsis
--------

[](#synopsis)

Configuration parser custom indented config file format (like YAML, python etc.)

Code Example
------------

[](#code-example)

PHP:

```
		use \LWB\LGMLParser\Tree as Tree;
		$tree = Tree::factoryFromFile('tree.lgml');
		//serialization
		file_put_contents('tree.json', $tree->toJSON());
		//accessing tree nodes
		if (isset($tree['domains'][0]))
		foreach ($tree['domains'][0] as $domain)
			$domains[$domain['@!element']] = $domain['@'];
```

tree.lgml

```
/*...config sample*/
domains
      year, type dateTime,
      		validator "digits_between:4,4"
      date, type dateTime
tables
  admin_rights, timestamps, softdeletes,
   section "user"
    columns
      key, type string, title "Key (in the form of: latin_letters)"
      name, type string,  title "Readable name"
    rows
      row
       key. process_complain_cancel
       name. Processing cancelling payment on customer complain

```

and more!

Motivation
----------

[](#motivation)

This component is made just to make life better: tabs, dots and commas are more easy to type in. Even in Russian keyboard layout or whatever u want.

God bless Hamish Friedlander and [SilverStripe Limited](www.silverstripe.com) for the php-peg parser.

Installation
------------

[](#installation)

composer require lastwhitebird/lgml-parser

API Reference
-------------

[](#api-reference)

The main class:

```
namespace LWB\LGMLParser;
class Tree
{
	use Tree\Quotes;
	/* 2 helper methods. dunno, they must be in the Basic class probably */
	public static function textNode($text);
	public static function node($element, $attributes = [])
	/* serialize methods */
	public function __toString()
	public function toXML($filename, $quote_function = false, $quote_attribute_function = false)
	public function toJSON()
	/* factory methods */
	public static function factoryFromJSON($string, array $options = [])
	public static function factoryFromFile($filename, array $options = [])
	public static function factoryFromString($string, array $options = [])
	public function fromJSON($string)
	public function fromFile($filename)
	/* the basic "read" method. You may use it with the generator yielding each line with no \r\n-s
	 * (working with sockets or whatever
	 */
	public function fromGenerator($generator)
```

Parent class:

```
namespace LWB\LGMLParser\Tree;
class Configurable extends Basic
{
	/* yes, it's public. you may use it directly */
	public $options;
	/* all the methods are self-documenting */
	public function __construct(array $options = []) {}
	public function setOption($name, $value) {}
	/* this 2 methods return $this */
	public function setOptions(array $options) {}
	public function getOption($name) {}
}
```

Helper functions:

```
namespace LWB\LGMLParser\Tree;
trait Quotes
{
	/* this un-escapes \" and \\ */
	public static function unEscapeDoubleQuotes($string) {}
	/* this un-escapes \' and \\ */
	public static function unEscapeSingleQuotes($string) {}
	/*this surrounds with proper quotes pair the 1st argument in k=>v pair of the
 	 * markup language, i.e. element's or attribute's name if needed
	 */
	public static function quoteProperly1($string) {}
	/* this surrounds with proper quotes pair the 2nd argument in k=>v pair of the
 	 * markup language, i.e. attribute's value if needed
	 */
	public static function quoteProperly2($string) {}
	/* adds indentation ($level spaces) to each every-but-1st line of the multiline string.
	 * if $first===true adds the same spaces to the 1st line.
	 * or $first*spaces if $first is not false
	 */
	public static function addIndent($level, $string, $first = false) {}
	/* converts tabs to spaces (by default tab=4*space. use ->setOption('tabs') method
	 * to overrride
	 */
	private function normalizeTabs($string) {}
}
```

Basic class. Implements \\Iterator, \\ArrayAccess, \\Countable

```
namespace LWB\LGMLParser\Tree;
class Basic
{
	/* the tree data structure itself */
	public $tree = null;
	/* this allows us to iterate only certain kind of nodes, i.e. "table" */
	public $filter = false;
	/* "factory" method */
	public static function factoryFromTree(array &$tree, $filter = false) {}
	/* Iterating in foreach operator section */
	function rewind() {}
	function current() {}
	function key() {}
	function next() {}
	function valid() {}
	/* this allows us to get count($tree_instance) */
	public function count() {}
	/* check if tree_as_array's offset exists e.g.: isset($tree_object['table']) */
	public function offsetExists($offset) {}
	/* treating tree as array e.g.: $tree_object['table'][0] */
	public function offsetGet($offset) {}
}
```

Tests
-----

[](#tests)

cd vendor\\lastwhitebird\\lgml-parser\\tests
php runtest.php

License
-------

[](#license)

This library is licensed under LGPL v2.1

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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

Every ~70 days

Recently: every ~220 days

Total

17

Last Release

2402d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13571877?v=4)[Alyoshenka](/maintainers/lastwhitebird)[@lastwhitebird](https://github.com/lastwhitebird)

---

Top Contributors

[![developer-se](https://avatars.githubusercontent.com/u/77615424?v=4)](https://github.com/developer-se "developer-se (2 commits)")[![lastwhitebird](https://avatars.githubusercontent.com/u/13571877?v=4)](https://github.com/lastwhitebird "lastwhitebird (2 commits)")

### Embed Badge

![Health badge](/badges/lastwhitebird-lgml-parser/health.svg)

```
[![Health](https://phpackages.com/badges/lastwhitebird-lgml-parser/health.svg)](https://phpackages.com/packages/lastwhitebird-lgml-parser)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

46143.1k6](/packages/jstewmc-rtf)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

112.9k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

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