Created
July 15, 2013 18:10
-
-
Save datayja/6002079 to your computer and use it in GitHub Desktop.
Insignificant whitespace postprocessor filter for Coral programming language, a part of proof-of-concept PHP implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Coral\Compiler\Postprocessor; | |
use Coral\Compiler\Tokenizer\Tokens\Token; | |
use Coral\Compiler\Tokenizer\Tokens\WhitespaceToken; | |
use Coral\Internal\Object; | |
class InsignificantWhitespaceFilter extends Object implements Filter | |
{ | |
public function apply_filter ($tokens) | |
{ | |
return \array_filter($tokens, function ($token) { | |
return $this->is_token_allowed($token); | |
}); | |
} | |
private function is_token_allowed (Token $token) | |
{ | |
if (!($token instanceof WhitespaceToken)) | |
{ | |
return true; | |
} | |
elseif ($token->getContent() === "\n") | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment