Skip to content

Instantly share code, notes, and snippets.

@datayja
Created July 15, 2013 18:10
Show Gist options
  • Save datayja/6002079 to your computer and use it in GitHub Desktop.
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
<?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