cvs: pear /SQL_Parser Lexer.php
| From: | Brent Cook | Date: | Fri, 27 Dec 2002 21:04:43 +0000 |
| Subject: | cvs: pear /SQL_Parser Lexer.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-7972@lists.php.net to get a copy of this message | ||
busterb Fri Dec 27 16:04:43 2002 EDT
Modified files:
/pear/SQL_Parser Lexer.php
Log:
add support for Windows/Mac newlines, update isOper()
Index: pear/SQL_Parser/Lexer.php
diff -u pear/SQL_Parser/Lexer.php:1.4 pear/SQL_Parser/Lexer.php:1.5
--- pear/SQL_Parser/Lexer.php:1.4 Tue Dec 24 09:37:01 2002
+++ pear/SQL_Parser/Lexer.php Fri Dec 27 16:04:42 2002
@@ -18,7 +18,7 @@
// | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA|
// +----------------------------------------------------------------------+
//
-// $Id: Lexer.php,v 1.4 2002/12/24 14:37:01 busterb Exp $
+// $Id: Lexer.php,v 1.5 2002/12/27 21:04:42 busterb Exp $
//
include 'SQL/ctype.php';
@@ -81,8 +81,34 @@
}
function isCompop($c) {
- return (($c == '<') || ($c == '>') || ($c == '='));
+ return (($c == '<') || ($c == '>') || ($c == '=') ||
($c == '!'));
}
+
+ function isWhiteSpace($c) {
+ return (($c == ' ') || ($c == "\t") || ($c == "\n") || ($c ==
"\r"));
+ }
+
+ function skipWhiteSpace() {
+ $c = $this->get();
+ while ($this->isWhiteSpace($c)) {
+ // Handle Unix line endings
+ if ($c == "\n") {
+ ++$this->lineNo;
+ $this->lineBegin = $this->tokPtr;
+ // Handle Mac/Windows line endings
+ } elseif ($c == "\r") {
+ $c = $this->skip;
+ if ($c != "\n")
+ $this->unget();
+ ++$this->lineNo;
+ $this->lineBegin = $this->tokPtr;
+ }
+ $c = $this->skip();
+ $this->tokLen = 1;
+ }
+ return $c;
+ }
+
// }}}
// {{{ lex()
@@ -98,15 +124,7 @@
$this->tokPtr = $this->tokStart;
$this->tokText = '';
$this->tokLen = 0;
- $c = $this->get();
- while (($c == ' ') || ($c == "\t") || ($c == "\n")) {
- if ($c == "\n") {
- ++$this->lineNo;
- $this->lineBegin = $this->tokPtr;
- }
- $c = $this->skip();
- $this->tokLen = 1;
- }
+ $c = $this->skipWhiteSpace();
if (($c == '\'') || ($c == '"')) {
$quote = $c;
$state = 12;
@@ -315,8 +333,15 @@
// {{{ State 14: Comment
case 14:
$c = $this->skip();
- if ($c == '\n') {
+ // Handle Unix line endings
+ if ($c == "\n") {
$state = 0;
+ // Handle Mac/Windows line endings
+ } elseif ($c == "\r") {
+ $c = $this->skip();
+ if ($c != "\n") {
+ $this->unget();
+ }
} else {
$state = 14;
}