diff --git a/src/Core.php b/src/Core.php new file mode 100644 index 000000000..ecca4dc38 --- /dev/null +++ b/src/Core.php @@ -0,0 +1,52 @@ +strict) { + throw $error; + } + $this->errors[] = $error; + } +} diff --git a/src/Lexer.php b/src/Lexer.php index 9de2a7ab1..1a706d2c3 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -41,7 +41,7 @@ * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ * @see Context */ -class Lexer +class Lexer extends Core { /** @@ -79,15 +79,6 @@ class Lexer 'parseSymbol', 'parseKeyword', 'parseLabel', 'parseUnknown' ); - /** - * Whether errors should throw exceptions or just be stored. - * - * @var bool - * - * @see static::$errors - */ - public $strict = false; - /** * The string to be parsed. * @@ -145,19 +136,6 @@ class Lexer */ public $delimiterLen; - /** - * List of errors that occurred during lexing. - * - * Usually, the lexing does not stop once an error occurred because that - * error might be false positive or a partial result (even a bad one) - * might be needed. - * - * @var LexerException[] - * - * @see Lexer::error() - */ - public $errors = array(); - /** * Gets the tokens list parsed by a new instance of a lexer. * @@ -375,10 +353,7 @@ public function lex() public function error($msg = '', $str = '', $pos = 0, $code = 0) { $error = new LexerException($msg, $str, $pos, $code); - if ($this->strict) { - throw $error; - } - $this->errors[] = $error; + parent::error($error); } /** diff --git a/src/Parser.php b/src/Parser.php index ddefc7ee7..b18b02d84 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -23,7 +23,7 @@ * @package SqlParser * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ -class Parser +class Parser extends Core { /** @@ -318,28 +318,6 @@ class Parser */ public $list; - /** - * Whether errors should throw exceptions or just be stored. - * - * @var bool - * - * @see static::$errors - */ - public $strict = false; - - /** - * List of errors that occurred during parsing. - * - * Usually, the parsing does not stop once an error occurred because that - * error might be a false positive or a partial result (even a bad one) - * might be needed. - * - * @var ParserException[] - * - * @see Parser::error() - */ - public $errors = array(); - /** * List of statements parsed. * @@ -599,9 +577,6 @@ public function parse() public function error($msg = '', Token $token = null, $code = 0) { $error = new ParserException($msg, $token, $code); - if ($this->strict) { - throw $error; - } - $this->errors[] = $error; + parent::error($error); } }