sunxyw / pdx-code
一个用于解析(解码)Paradox格式代码的PHP库,包括Pdxtxt。
1.0.1
2023-06-24 09:30 UTC
Requires
- php: ^8.0
- phplrt/exception: *
- phplrt/runtime: ^3.2
Requires (Dev)
- phplrt/phplrt: ^3.2
- symfony/var-dumper: ^6.0
README
一个用于解析(解码)Paradox格式代码的PHP库,包括Pdxtxt。
由 phplrt 提供支持。
安装
composer require sunxyw/pdx-code
用法
$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;
$ast
实际上是一个数组,但在使用 echo
输出时会转换为XML格式的AST。
<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>