newest quantum CVS sources
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / sql / parser / SQLLexx.java
index e901266..543b1ef 100644 (file)
@@ -2,6 +2,21 @@ package com.quantum.sql.parser;
 
 import java.util.Vector;
 
+/**
+ * <p>An SQL Lexer.  From 
+ * <a href="http://www.dictionary.com/">dictionary.com</a>:
+ * 
+ * <blockquote>
+ * <p><b>lexer</b>
+ *
+ * <p>/lek'sr/ n. Common hacker shorthand for 'lexical
+ * analyzer', the input-tokenizing stage in the parser for a language
+ * (the part that breaks it into word-like pieces).
+ * </blockquote>
+ * 
+ * <p>Note that this class has nothing to do with the Sci-fi channel's
+ * <a href="http://www.scifi.com/lexx/">Lexx</a> TV series.
+ */
 public class SQLLexx {
        private static String endline = ";"; //$NON-NLS-1$
        private static String dash = "-"; //$NON-NLS-1$
@@ -130,22 +145,12 @@ public class SQLLexx {
                                        p.mark();
                                        // If we have '/*', it's a comment till '*/' found or eof
                                        if (p.peek() == '*') {
-                                               StringBuffer value = new StringBuffer();
-                                               c = p.getNext();
-                                               value.append('/');
-                                               while (!( c == '*' && p.peek() == '/' ) && !p.isDone()) {
-                                                       value.append(c);
-                                                       c = p.getNext();
-                                               }
-                                               if (!p.isDone()){
-                                                       value.append(c);
-                                                       c = p.getNext();
-                                                       value.append(c);        
-                                               }
-                                               tokens.addElement(new Token(Token.COMMENT, value.toString(), offset, offset + value.length()));
+                                               tokens.addElement(tokenizeComment(p, offset));
                                        } else {
                                                // It's not '/*' , so it's a group token
-                                               tokens.addElement(new Token(Token.GROUP, group, offset, offset + 1));
+                                               // BCH ??? what's this business about groups?  
+                                               // Shouldn't '/' be a divide operator?
+                                               tokens.addElement(new Token(Token.SYMBOL, new String(new char[] {c}) /*group*/, offset, offset + 1));
                                                p.reset();
                                        }
                                // Adds SYMBOL token;
@@ -163,4 +168,25 @@ public class SQLLexx {
 //             }
                return tokens;
        }
+       /**
+        * @param tokens
+        * @param p
+        * @param offset
+        */
+       private static Token tokenizeComment(StringPointer p, int offset) {
+               char c;
+               StringBuffer value = new StringBuffer();
+               c = p.getNext();
+               value.append('/');
+               while (!( c == '*' && p.peek() == '/' ) && !p.isDone()) {
+                       value.append(c);
+                       c = p.getNext();
+               }
+               if (!p.isDone()){
+                       value.append(c);
+                       c = p.getNext();
+                       value.append(c);        
+               }
+               return new Token(Token.COMMENT, value.toString(), offset, offset + value.length());
+       }
 }