2017 © Pedro Peláez
 

library lgml-parser

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

image

lastwhitebird/lgml-parser

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

  • Sunday, November 5, 2017
  • by lastwhitebird
  • Repository
  • 3 Watchers
  • 1 Stars
  • 36 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

Synopsis

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

Code Example

PHP:, (*2)

        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, (*3)

/*...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!, (*4)

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., (*5)

God bless Hamish Friedlander and SilverStripe Limited for the php-peg parser., (*6)

Installation

composer require lastwhitebird/lgml-parser, (*7)

API Reference

The main class:, (*8)

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:, (*9)

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:, (*10)

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, (*11)

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

cd vendor\lastwhitebird\lgml-parser\tests\ php runtest.php, (*12)

License

This library is licensed under LGPL v2.1, (*13)

The Versions

05/11 2017

dev-master

9999999-dev

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

  Sources   Download

LGPL-2.1

The Requires

 

05/11 2017

0.0.6alpha1

0.0.6.0-alpha1

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

  Sources   Download

LGPL-2.1

The Requires

 

05/07 2017

0.0.5alpha1

0.0.5.0-alpha1

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

  Sources   Download

LGPL-2.1

The Requires

 

02/07 2017

0.0.4alpha6

0.0.4.0-alpha6

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

  Sources   Download

LGPL-2.1

The Requires

 

02/07 2017

0.0.4alpha5

0.0.4.0-alpha5

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

  Sources   Download

LGPL-2.1

The Requires

 

01/07 2017

0.0.4alpha4

0.0.4.0-alpha4

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

  Sources   Download

LGPL-2.1

The Requires

 

01/07 2017

0.0.4alpha3

0.0.4.0-alpha3

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

  Sources   Download

LGPL-2.1

The Requires

 

23/06 2017

0.0.4alpha2

0.0.4.0-alpha2

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

  Sources   Download

LGPL-2.1

The Requires

 

20/06 2017

0.0.4alpha1

0.0.4.0-alpha1

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

  Sources   Download

LGPL-2.1

The Requires

 

19/06 2017

0.0.3alpha3

0.0.3.0-alpha3

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

  Sources   Download

LGPL-2.1

The Requires

 

11/11 2016

0.0.3alpha2

0.0.3.0-alpha2

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

  Sources   Download

LGPL-2.1

The Requires

 

11/11 2016

0.0.3alpha1

0.0.3.0-alpha1

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

  Sources   Download

LGPL-2.1

The Requires

 

02/11 2016

v0.0.2-alpha1

0.0.2.0-alpha1

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

  Sources   Download

LGPL-2.1

The Requires

 

02/11 2016

v0.0.1-beta1

0.0.1.0-beta1

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

  Sources   Download

LGPL-2.1

The Requires

 

02/11 2016

v0.0.1-alpha2

0.0.1.0-alpha2

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

  Sources   Download

LGPL-2.1

The Requires

 

02/11 2016

v0.0.1-alpha1

0.0.1.0-alpha1

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

  Sources   Download

LGPL-2.1

The Requires