summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Components/FieldDefinition.php7
-rw-r--r--src/Parser.php12
-rw-r--r--src/Statement.php20
3 files changed, 36 insertions, 3 deletions
diff --git a/src/Components/FieldDefinition.php b/src/Components/FieldDefinition.php
index 32a426b..351e8b5 100644
--- a/src/Components/FieldDefinition.php
+++ b/src/Components/FieldDefinition.php
@@ -241,6 +241,13 @@ class FieldDefinition extends Component
$state = 6;
++$list->idx;
break;
+ } else {
+ $parser->error(
+ __('A comma or a closing bracket was expected.'),
+ $token
+ );
+ $state = 0;
+ break;
}
}
}
diff --git a/src/Parser.php b/src/Parser.php
index 2d23f6a..36b6aec 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -321,7 +321,6 @@ namespace SqlParser {
/**
* Last transaction.
- *
* @var TransactionStatement
*/
$lastTransaction = null;
@@ -336,7 +335,7 @@ namespace SqlParser {
* Whether a union is parsed or not.
* @var bool $inUnion
*/
- $inUnion = true;
+ $inUnion = false;
/**
* The index of the last token from the last statement.
@@ -436,7 +435,14 @@ namespace SqlParser {
$lastTransaction = $statement;
$this->statements[] = $statement;
} elseif ($statement->type === TransactionStatement::TYPE_END) {
- $lastTransaction->end = $statement;
+ if ($lastTransaction === null) {
+ $this->error(
+ __('No transaction was previously started.'),
+ $token
+ );
+ } else {
+ $lastTransaction->end = $statement;
+ }
$lastTransaction = null;
}
continue;
diff --git a/src/Statement.php b/src/Statement.php
index 1494a0d..ea433c6 100644
--- a/src/Statement.php
+++ b/src/Statement.php
@@ -169,6 +169,16 @@ abstract class Statement
*/
public function parse(Parser $parser, TokensList $list)
{
+ /**
+ * Whether the beginning of this statement was previously parsed.
+ *
+ * This is used to delimit statements that don't use the usual
+ * delimiters.
+ *
+ * @var bool
+ */
+ $parsedBeginning = false;
+
// This may be corrected by the parser.
$this->first = $list->idx;
@@ -236,6 +246,16 @@ abstract class Statement
}
if (!empty(Parser::$STATEMENT_PARSERS[$token->value])) {
+ if ($parsedBeginning) {
+ // New statement has started. We let the parser construct a
+ // new statement and parse that one
+ $parser->error(
+ __('A new statement was found, but no delimiter between them.'),
+ $token
+ );
+ break;
+ }
+ $parsedBeginning = true;
if (!$parsedOptions) {
++$list->idx; // Skipping keyword.
$this->options = OptionsArray::parse(