Skip to content

kdl-org/kdl-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c0933c1 · Feb 24, 2021

History

24 Commits
Jan 5, 2021
Feb 24, 2021
Feb 24, 2021
Dec 28, 2020
Feb 24, 2021
Dec 28, 2020
Jan 13, 2021
Jan 5, 2021
Feb 24, 2021
Jan 8, 2021
Dec 28, 2020
Jan 7, 2021
Dec 30, 2020

Repository files navigation

Latest Stable Version License Status

KDL-PHP

A PHP library for the KDL Document Language (pronounced like "cuddle").

alt text

Installation

The KDL library can be included to your project using Composer:

composer require kdl/kdl

Limitations

For now, this library only supports parsing.

Parsing is quite slow for now - for example, parsing a 45 line file with a tree depth of 5 is likely to take about 60ms. This library favours correctness over performance - however, the aim is to optimise the parsing to a point of reasonable speed.

The parser uses Parsica as an underlying parsing library in order to map fairly directly and clearly onto the published KDL grammar - Parsica uses FP principles, and one result of this is that the call stack depth used during parsing may be high. Be warned if you are using e.g. xdebug, as parsing may exceed any normal maximum stack depth that you may set.

Examples

$document = Kdl\Kdl\Kdl::parse($kdlString);
foreach ($document as $node) {
    $node->getName(); //gets the name for the node @see https://github.com/kdl-org/kdl/blob/main/SPEC.md#node
    $node->getValues(); //gets a list of values for a node @see https://github.com/kdl-org/kdl/blob/main/SPEC.md#value
    $node->getProperties(); //gets an associative array of properties @see https://github.com/kdl-org/kdl/blob/main/SPEC.md#property
    foreach ($node->getChildren() as $child) {
        $child->getName(); //name for the child
       //etc
    }
}

License

The code is available under the MIT license.