rework everything; add emacs output mode
[php-sqllint.git] / src / phpsqllint / Renderer / Text.php
1 <?php
2 /**
3  * Part of php-sqllint
4  *
5  * PHP version 5
6  *
7  * @category Tools
8  * @package  PHP-SQLlint
9  * @author   Christian Weiske <cweiske@cweiske.de>
10  * @license  http://www.gnu.org/licenses/agpl.html GNU AGPL v3
11  * @link     http://cweiske.de/php-sqllint.htm
12  */
13 namespace phpsqllint;
14
15 /**
16  * Textual output, easily readable by humans.
17  *
18  * @category Tools
19  * @package  PHP-SQLlint
20  * @author   Christian Weiske <cweiske@cweiske.de>
21  * @license  http://www.gnu.org/licenses/agpl.html GNU AGPL v3
22  * @link     http://www.emacswiki.org/emacs/CreatingYourOwnCompileErrorRegexp
23  */
24 class Renderer_Text implements Renderer
25 {
26     /**
27      * Begin syntax check output rendering
28      *
29      * @param string $filename Path to the SQL file
30      *
31      * @return void
32      */
33     public function startRendering($filename)
34     {
35         echo "Checking SQL syntax of " . $filename . "\n";
36     }
37
38     /**
39      * Show the error to the user.
40      *
41      * @param string  $msg   Error message
42      * @param string  $token Character which caused the error
43      * @param integer $line  Line at which the error occured
44      * @param integer $col   Column at which the error occured
45      *
46      * @return void
47      */
48     public function displayError($msg, $token, $line, $col)
49     {
50         echo ' Line ' . $line
51             . ', col ' . $col
52             . ' at "' . $this->niceToken($token) . '":'
53             . ' ' . $msg
54             . "\n";
55     }
56
57     /**
58      * Finish syntax check output rendering; no syntax errors found
59      *
60      * @return void
61      */
62     public function finishOk()
63     {
64         echo " OK\n";
65     }
66
67     /**
68      * Convert the token string to a readable one, especially special
69      * characters like newline and tabs
70      *
71      * @param string $str String with possibly special characters
72      *
73      * @return string Escaped string
74      */
75     protected function niceToken($str)
76     {
77         return str_replace(
78             ["\n", "\r", "\t"],
79             ['\n', '\r', '\t'],
80             $str
81         );
82     }
83 }
84 ?>