如果检测到错误,如何停止解析器?
示例
def t_error(t):
print("Illegal character '%s'" % t.value[0])
t.lexer.skip(1)
只显示跳过但我需要停止。如何存档?
答案 0 :(得分:1)
当您在词法分析器中遇到错误时,可以引发异常。例如:
use \Symfony\Component\HttpFoundation\RedirectResponse;
class Controller {
public function action( \Silex\Application $app ){
$response = new RedirectResponse('/login', 302);
// the headers public attribute is a ResponseHeaderBag
$response->headers->set('Content-Type', 'text/plain');
return $response;
}
}