예제 #1
0
파일: fammel.php 프로젝트: rgigger/zinc
 function parse($input)
 {
     try {
         global $LINE;
         $tok = new Tokeniser($input);
         $parser = new parse_engine($this->_haml);
         $parser->reset();
         $tokens = $tok->get_all_tokens();
         $tokens = array_merge(array(new Token('INDENT', 0)), $tokens);
         foreach ($tokens as $t) {
             $LINE = $this->_line = $t->line();
             $parser->eat($t->type(), $t->value());
         }
         $parser->eat_eof();
         return true;
     } catch (parse_error $e) {
         $token = $value = '';
         preg_match('/\\((.*?)\\)\\((.*?)\\)/', $e->getMessage(), $matches);
         if ($matches) {
             $token = $matches[1];
             $value = $matches[2];
             $message = "Parse error: unexpected {$token} ('{$value}')";
         } else {
             $message = $e->getMessage();
         }
         $message .= " at line {$this->_line}";
         if ($this->_file) {
             $message .= " in {$this->_file}";
         }
         $message .= "\n";
         throw new FammelParseException($message, $this->_line, $token, $value);
     }
 }
예제 #2
0
 function it_should_return_an_array_of_tokens()
 {
     $tok = new Tokeniser("%tag .class #id :attr-name\n");
     $tokens = $tok->get_all_tokens();
     $this->spec(is_array($tokens))->should->beTrue();
     $this->spec(count($tokens))->should->equal(5);
 }