Beispiel #1
0
 /**
  * @dataProvider expressionProvider
  */
 public function testExpression($exp, $compileResult)
 {
     $tpl = '{{' . $exp . '}}';
     $lexer = new \Comos\Tage\Compiler\Lexer();
     $tokenStream = $lexer->lex($tpl);
     $tokenStream->next();
     //skip {{
     $expressionParser = new \Comos\Tage\Compiler\Parser\ExpressionParser();
     $expressionNode = $expressionParser->parse($tokenStream);
     $this->assertEquals($compileResult, $expressionNode->compile());
 }
Beispiel #2
0
                background-color: #000000;
            }
        </style>
    </head>
    <body>
        <form method="post">
            <h1><a href="/">Home</a>/Expression Demo</h1>
            <pre class="code">
                <?php 
if (!empty($code)) {
    try {
        $tplCode = '{{' . $code . '}}';
        $lexer = new \Comos\Tage\Compiler\Lexer();
        $tokenStream = $lexer->lex($tplCode, 'TageLexerDemoCode');
        $tokenStream->next();
        $expressionParser = new \Comos\Tage\Compiler\Parser\ExpressionParser();
        $expressionNode = $expressionParser->parse($tokenStream);
        $tokenStream->expect(\Comos\Tage\Compiler\Token::TYPE_TAG_END);
        $res = $expressionNode->compile();
        $transform = '';
        $uuid = 0;
        foreach (preg_split('/(?<!^)(?!$)/u', $res) as $char) {
            if ($char == '(') {
                $uuid++;
                $transform .= sprintf('<code class="bracket bracket-%s"> (', $uuid);
            } elseif ($char == ')') {
                $transform .= ') </code>';
            } else {
                $transform .= $char;
            }
        }