summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Lexer.php59
-rw-r--r--src/Token.php1
2 files changed, 46 insertions, 14 deletions
diff --git a/src/Lexer.php b/src/Lexer.php
index 96be968..de44eea 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -559,26 +559,33 @@ namespace SqlParser {
// Below are the states of the machines and the conditions to change
// the state.
//
- // 1 ---------------------[ + or - ]---------------------> 1
- // 1 --------------------[ 0x or 0X ]--------------------> 2
- // 1 ---------------------[ 0 to 9 ]---------------------> 3
- // 1 ------------------------[ . ]-----------------------> 4
+ // 1 --------------------[ + or - ]-------------------> 1
+ // 1 -------------------[ 0x or 0X ]------------------> 2
+ // 1 --------------------[ 0 to 9 ]-------------------> 3
+ // 1 -----------------------[ . ]---------------------> 4
+ // 1 -----------------------[ b ]---------------------> 7
//
- // 2 ---------------------[ 0 to F ]---------------------> 2
+ // 2 --------------------[ 0 to F ]-------------------> 2
//
- // 3 ---------------------[ 0 to 9 ]---------------------> 3
- // 3 ------------------------[ . ]-----------------------> 4
- // 3 ---------------------[ e or E ]---------------------> 5
+ // 3 --------------------[ 0 to 9 ]-------------------> 3
+ // 3 -----------------------[ . ]---------------------> 4
+ // 3 --------------------[ e or E ]-------------------> 5
//
- // 4 ---------------------[ 0 to 9 ]---------------------> 4
- // 4 ---------------------[ e or E ]---------------------> 5
+ // 4 --------------------[ 0 to 9 ]-------------------> 4
+ // 4 --------------------[ e or E ]-------------------> 5
//
- // 5 ----------------[ + or - or 0 to 9 ]----------------> 6
+ // 5 ---------------[ + or - or 0 to 9 ]--------------> 6
+ //
+ // 7 -----------------------[ ' ]---------------------> 8
+ //
+ // 8 --------------------[ 0 or 1 ]-------------------> 8
+ // 8 -----------------------[ ' ]---------------------> 9
//
// State 1 may be reached by negative numbers.
// State 2 is reached only by hex numbers.
// State 4 is reached only by float numbers.
// State 5 is reached only by numbers in approximate form.
+ // State 7 is reached only by numbers in bit representation.
//
// Valid final states are: 2, 3, 4 and 6. Any parsing that finished in a
// state other than these is invalid.
@@ -590,8 +597,10 @@ namespace SqlParser {
if ($state === 1) {
if ($this->str[$this->last] === '-') {
$flags |= Token::FLAG_NUMBER_NEGATIVE;
- } elseif (($this->str[$this->last] === '0') && ($this->last + 1 < $this->len)
- && (($this->str[$this->last + 1] === 'x') || ($this->str[$this->last + 1] === 'X'))
+ } elseif (($this->last + 1 < $this->len)
+ && ($this->str[$this->last] === '0')
+ && (($this->str[$this->last + 1] === 'x')
+ || ($this->str[$this->last + 1] === 'X'))
) {
$token .= $this->str[$this->last++];
$state = 2;
@@ -599,6 +608,8 @@ namespace SqlParser {
$state = 3;
} elseif ($this->str[$this->last] === '.') {
$state = 4;
+ } elseif ($this->str[$this->last] === 'b') {
+ $state = 7;
} elseif ($this->str[$this->last] !== '+') {
// `+` is a valid character in a number.
break;
@@ -642,10 +653,30 @@ namespace SqlParser {
// Just digits are valid characters.
break;
}
+ } elseif ($state === 7) {
+ $flags |= Token::FLAG_NUMBER_BINARY;
+ if ($this->str[$this->last] === '\'') {
+ $state = 8;
+ } else {
+ break;
+ }
+ } elseif ($state === 8) {
+ if ($this->str[$this->last] === '\'') {
+ $state = 9;
+ } elseif (($this->str[$this->last] !== '0')
+ && ($this->str[$this->last] !== '1')
+ ) {
+ break;
+ }
+ } elseif ($state === 9) {
+ break;
}
$token .= $this->str[$this->last];
}
- if (($state === 2) || ($state === 3) || (($token !== '.') && ($state === 4)) || ($state === 6)) {
+ if (($state === 2) || ($state === 3)
+ || (($token !== '.') && ($state === 4))
+ || ($state === 6) || ($state === 9)
+ ) {
--$this->last;
return new Token($token, Token::TYPE_NUMBER, $flags);
}
diff --git a/src/Token.php b/src/Token.php
index c57b907..56b46b5 100644
--- a/src/Token.php
+++ b/src/Token.php
@@ -134,6 +134,7 @@ class Token
const FLAG_NUMBER_FLOAT = 2;
const FLAG_NUMBER_APPROXIMATE = 4;
const FLAG_NUMBER_NEGATIVE = 8;
+ const FLAG_NUMBER_BINARY = 16;
// Strings related flags.
const FLAG_STRING_SINGLE_QUOTES = 1;