Skip to content

Commit bd21e7d

Browse files
committed
Reintroduce trim expander + handle node path relative to cwd
1 parent 37a67e6 commit bd21e7d

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"Pre\\Plugin\\": "source"
88
},
99
"files": [
10+
"source/expanders.php",
1011
"source/functions.php",
1112
"source/autoload.php",
1213
"source/macros.php"

source/Parser.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ public function format($code)
178178
})
179179
'";
180180

181+
$cwd = getcwd();
182+
chdir(__DIR__);
181183
exec($command, $output);
184+
chdir($cwd);
182185

183186
if (!$output) {
184187
return $code;

source/expanders.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Yay\DSL\Expanders {
4+
use Yay\Engine;
5+
use Yay\TokenStream;
6+
7+
function trim(TokenStream $stream, Engine $engine): TokenStream {
8+
return \Pre\Plugin\Expanders\trim($stream, $engine);
9+
}
10+
}
11+
12+
namespace Pre\Plugin\Expanders {
13+
use Yay\Engine;
14+
use Yay\TokenStream;
15+
16+
function _stream(string $source, Engine $engine): TokenStream {
17+
return TokenStream::fromSource(
18+
$engine->expand($source, "", Engine::GC_ENGINE_DISABLED)
19+
);
20+
}
21+
22+
function trim(TokenStream $stream, Engine $engine): TokenStream {
23+
$stream = \trim($stream);
24+
return _stream($stream, $engine);
25+
}
26+
}

0 commit comments

Comments
 (0)