/** * @dataProvider typeToStringProvider */ public function testTypeToString($type, $string) { $this->assertEquals($string, Token::typeToString($type)); }
<body> <form method="post"> <h1><a href="/">Home</a>/Tage Lexer Demo</h1> <pre class="code"> <div class="line-number"></div> <?php if (!empty($code)) { try { $lexer = new \Comos\Tage\Compiler\Lexer(); $tokenStream = $lexer->lex($code, 'TageLexerDemoCode'); $defaultTypeStringMap = array(\Comos\Tage\Compiler\Token::TYPE_TAG_START => '{{', \Comos\Tage\Compiler\Token::TYPE_TAG_END => "}}", \Comos\Tage\Compiler\Token::TYPE_TEXT => ' '); $lastLine = 0; $lastToken = null; while (!$tokenStream->isEOF()) { $token = $tokenStream->next(); $type = \Comos\Tage\Compiler\Token::typeToString($token->type); $val = trim($token->value); if (empty($val)) { $val = $defaultTypeStringMap[$token->type]; } // if($token->type == \Tage\Compiler\Token::TYPE_STRING){ // $val="'$val'"; // } $lineNumber = ''; if ($lastLine != $token->line) { $val = "\n" . $val; $lastLine = $token->line; $lineNumber = str_pad($token->line, 3, ' ', STR_PAD_LEFT); } $lastToken = $token; echo sprintf('<code class="token %s" data-line="%s" title="%s">%s</code>', $type, $lineNumber, $type, htmlspecialchars($val, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'));