1 package net.sourceforge.phpdt.sql.parser;
3 import java.util.Vector;
6 private static String endline = ";";
7 private static String dash = "-";
8 public static Vector parse(String text) {
9 Vector tokens = new Vector();
10 StringPointer p = new StringPointer(text);
13 int offset = p.getOffset();
15 //System.out.print(c);
16 if (Character.isWhitespace(c)) {
17 StringBuffer value = new StringBuffer();
18 while (Character.isWhitespace(c) && !p.isDone()) {
23 // done because of is done
24 if (Character.isWhitespace(c)) {
29 tokens.addElement(new Token(Token.WHITESPACE, value.toString(), offset, offset + value.length()));
30 } else if (Character.isLetter(c) || c == '_') {
31 StringBuffer value = new StringBuffer();
32 while ((Character.isLetterOrDigit(c) || c == '_') && !p.isDone()) {
37 if ((Character.isLetterOrDigit(c) || c == '_')) {
42 tokens.addElement(new Token(Token.IDENTIFIER, value.toString(), offset, offset + value.length()));
43 } else if (c == '\'') {
44 StringBuffer value = new StringBuffer();
48 while (c != '\'' && c != '\n' && !p.isDone()) {
52 if (c == '\'' || p.isDone()) {
56 tokens.addElement(new Token(Token.LITERAL, value.toString(), offset, offset + value.length()));
57 } else if (c == '-') {
60 tokens.addElement(new Token(Token.SYMBOL, dash, offset, offset + 1));
62 char next = p.getNext();
64 StringBuffer value = new StringBuffer("--");
67 while (c != '\n' && !p.isDone()) {
75 tokens.addElement(new Token(Token.COMMENT, value.toString(), offset, offset + value.length()));
77 tokens.addElement(new Token(Token.SYMBOL, dash, offset, offset + 1));
81 } else if (c == ';') {
82 tokens.addElement(new Token(Token.SEPARATOR, endline, offset, offset + 1));
83 StringBuffer value = new StringBuffer();
86 while (c != '\n' && !p.isDone()) {
94 tokens.addElement(new Token(Token.COMMENT, value.toString(), offset, offset + value.length()));
96 } else if (Character.isDigit(c)) {
97 StringBuffer value = new StringBuffer();
98 while ((Character.isDigit(c) || c == '.') && !p.isDone()) {
103 if ((Character.isDigit(c) || c == '.')) {
108 tokens.addElement(new Token(Token.NUMERIC, value.toString(), offset, offset + value.length()));
110 tokens.addElement(new Token(Token.SYMBOL, new String(new char[] {c}), offset, offset + 1));
113 } catch (RuntimeException e) {
117 //System.out.println("-------------------");
118 //for (int i = 0; i < tokens.size(); i++) {
119 // System.out.println((Token) tokens.elementAt(i));