@@ -19,17 +19,17 @@ discard block |
||
| 19 | 19 | /* @var null|string */ |
| 20 | 20 | public $error; |
| 21 | 21 | |
| 22 | - public const EXCLUDE_DIRECTIVES = 1;//DONT include_directive |
|
| 23 | - public const IGNORE_COMMENTS = 2;//DONT include_comments |
|
| 24 | - public const NO_PARSING_EXCEPTIONS = 4;//THROW Exception on parsing Errors |
|
| 25 | - public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
|
| 22 | + public const EXCLUDE_DIRECTIVES = 1; //DONT include_directive |
|
| 23 | + public const IGNORE_COMMENTS = 2; //DONT include_comments |
|
| 24 | + public const NO_PARSING_EXCEPTIONS = 4; //THROW Exception on parsing Errors |
|
| 25 | + public const NO_OBJECT_FOR_DATE = 8; //DONT import date strings as dateTime Object |
|
| 26 | 26 | //privates |
| 27 | 27 | /* @var null|string */ |
| 28 | 28 | private $content; |
| 29 | 29 | /* @var null|string */ |
| 30 | 30 | private $filePath; |
| 31 | 31 | /* @var integer */ |
| 32 | - private $debug = 0;///TODO: determine levels |
|
| 32 | + private $debug = 0; ///TODO: determine levels |
|
| 33 | 33 | /* @var integer */ |
| 34 | 34 | private $options = 0; |
| 35 | 35 | //Exceptions messages |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $target->add($n); |
| 118 | 118 | $previous = $n; |
| 119 | 119 | } |
| 120 | - if ($this->debug === 2) echo "\033[33mParsed Structure\033[0m\n",var_export($root, true); |
|
| 120 | + if ($this->debug === 2) echo "\033[33mParsed Structure\033[0m\n", var_export($root, true); |
|
| 121 | 121 | $out = Builder::buildContent($root, $this->debug); |
| 122 | 122 | return $out; |
| 123 | 123 | } catch (\Error|\Exception|\ParseError $e) { |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | $deepest->parse($deepest->value.' '.ltrim($lineString)); |
| 156 | 156 | return true; |
| 157 | 157 | } |
| 158 | - if(($previous->type & Y::LITTERALS) || (($deepest->type & Y::LITTERALS) && is_null($deepest->value))) { |
|
| 158 | + if (($previous->type & Y::LITTERALS) || (($deepest->type & Y::LITTERALS) && is_null($deepest->value))) { |
|
| 159 | 159 | $n->type = Y::SCALAR; |
| 160 | 160 | $n->identifier = null; |
| 161 | 161 | $n->value = trim($lineString); |
@@ -87,7 +87,9 @@ discard block |
||
| 87 | 87 | { |
| 88 | 88 | $source = $this->content ?? preg_split("/([^\n\r]+)/um", $strContent, 0, PREG_SPLIT_DELIM_CAPTURE); |
| 89 | 89 | //TODO : be more permissive on $strContent values |
| 90 | - if (!is_array($source) || !count($source)) throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
|
| 90 | + if (!is_array($source) || !count($source)) { |
|
| 91 | + throw new \Exception(self::EXCEPTION_LINE_SPLIT); |
|
| 92 | + } |
|
| 91 | 93 | $previous = $root = new Node(); |
| 92 | 94 | $emptyLines = []; |
| 93 | 95 | try { |
@@ -99,7 +101,9 @@ discard block |
||
| 99 | 101 | foreach ($gen() as $lineNb => $lineString) { |
| 100 | 102 | $n = new Node($lineString, $lineNb); |
| 101 | 103 | if ($n->type & (Y::LITTERALS|Y::BLANK)) { |
| 102 | - if ($this->onSpecialType($n, $previous, $emptyLines)) continue; |
|
| 104 | + if ($this->onSpecialType($n, $previous, $emptyLines)) { |
|
| 105 | + continue; |
|
| 106 | + } |
|
| 103 | 107 | } else { |
| 104 | 108 | foreach ($emptyLines as $blankNode) { |
| 105 | 109 | $blankNode->getParent()->add($blankNode); |
@@ -113,11 +117,15 @@ discard block |
||
| 113 | 117 | break; |
| 114 | 118 | default: $target = $previous; |
| 115 | 119 | } |
| 116 | - if ($this->onContextType($n, $target, $lineString)) continue; |
|
| 120 | + if ($this->onContextType($n, $target, $lineString)) { |
|
| 121 | + continue; |
|
| 122 | + } |
|
| 117 | 123 | $target->add($n); |
| 118 | 124 | $previous = $n; |
| 119 | 125 | } |
| 120 | - if ($this->debug === 2) echo "\033[33mParsed Structure\033[0m\n",var_export($root, true); |
|
| 126 | + if ($this->debug === 2) { |
|
| 127 | + echo "\033[33mParsed Structure\033[0m\n",var_export($root, true); |
|
| 128 | + } |
|
| 121 | 129 | $out = Builder::buildContent($root, $this->debug); |
| 122 | 130 | return $out; |
| 123 | 131 | } catch (\Error|\Exception|\ParseError $e) { |
@@ -137,8 +145,12 @@ discard block |
||
| 137 | 145 | { |
| 138 | 146 | $deepest = $previous->getDeepestNode(); |
| 139 | 147 | if ($n->type & Y::BLANK) { |
| 140 | - if ($previous->type & Y::SCALAR) $emptyLines[] = $n->setParent($previous->getParent()); |
|
| 141 | - if ($deepest->type & Y::LITTERALS) $emptyLines[] = $n->setParent($deepest); |
|
| 148 | + if ($previous->type & Y::SCALAR) { |
|
| 149 | + $emptyLines[] = $n->setParent($previous->getParent()); |
|
| 150 | + } |
|
| 151 | + if ($deepest->type & Y::LITTERALS) { |
|
| 152 | + $emptyLines[] = $n->setParent($deepest); |
|
| 153 | + } |
|
| 142 | 154 | return true; |
| 143 | 155 | } |
| 144 | 156 | return false; |