PHP code example of sunxyw / pdx-code
1. Go to this page and download the library: Download sunxyw/pdx-code library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sunxyw / pdx-code example snippets
$sample = <<<'SAMPLE'
energy = {
tradable = yes
category = basic
max = 50000
deficit_situation = situation_energy_deficit
ai_weight = {
weight = 1.5
}
ai_wants = {
base = 500
}
}
SAMPLE;
$parser = new \Sunxyw\ParadoxCode\Parser();
$ast = $parser->parse($sample);
echo $ast;
xml
<Root offset="0">
<Pair offset="0">
<T_STRING offset="0">energy</T_STRING>
<Object offset="9">
<Pair offset="12">
<T_STRING offset="12">tradable</T_STRING>
<T_BOOL_TRUE offset="23">yes</T_BOOL_TRUE>
</Pair>
<Pair offset="28">
<T_STRING offset="28">category</T_STRING>
<T_STRING offset="39">basic</T_STRING>
</Pair>
<Pair offset="46">
<T_STRING offset="46">max</T_STRING>
<T_INTEGER offset="52">50000</T_INTEGER>
</Pair>
<Pair offset="60">
<T_STRING offset="60">deficit_situation</T_STRING>
<T_STRING offset="80">situation_energy_deficit</T_STRING>
</Pair>
<Pair offset="107">
<T_STRING offset="107">ai_weight</T_STRING>
<Object offset="119">
<Pair offset="123">
<T_STRING offset="123">weight</T_STRING>
<T_FLOAT offset="132">1.5</T_FLOAT>
</Pair>
</Object>
</Pair>
<Pair offset="141">
<T_STRING offset="141">ai_wants</T_STRING>
<Object offset="152">
<Pair offset="156">
<T_STRING offset="156">base</T_STRING>
<T_INTEGER offset="163">500</T_INTEGER>
</Pair>
</Object>
</Pair>
</Object>
</Pair>
</Root>