|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object tribble.parse.sql.ExprLexer
Utility methods for SQL-like query expression parsing.
Copyright ©2001 by David R. Tribble, all rights reserved.
Permission is granted to any person or entity except those designated by
by the United States Department of State as a terrorist, or terrorist
government or agency, to use and distribute this source code provided
that the original copyright notice remains present and unaltered.
Method Summary | |
static int |
getToken(java.lang.String line,
int pos,
java.lang.StringBuffer tok)
Extract the next word token from an SQL-like query expression. |
static java.lang.String[] |
getTokens(java.lang.String line)
Split an SQL-like query expression into separate word tokens. |
static void |
main(java.lang.String[] args)
Test driver for this class. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static void main(java.lang.String[] args) throws java.lang.Exception
Usage
java tribble.parse.sql.ExprLexer textline...
This splits the textline into separate tokens.
args
- Command line arguments.
java.lang.Exception
- Thrown if an error occurs.public static int getToken(java.lang.String line, int pos, java.lang.StringBuffer tok) throws java.text.ParseException
Words may be quoted by surrounding them with single quote (') or double quote (") characters. If a word contains either of these characters, it must be quoted, and the embedded quote characters must be preceded by a backslash character (\). (Embedded backslash characters should not be preceded by another backslash, however.)
Example
Consider the following input text line:
Date\ 2 = "2001-01-01" & `I.D.` like '%\'s' & Rec.Sz >= 80 0123456789_123456789_123456789_123456789_123456789_12345The line above contains the following word tokens at the string offsets shown:
0: "Date 2" 5: "=" 7: "\"2001-01-01\"" 20: "&" 22: "I.D." 29: "like" 34: "'%'s'" 41: "&" 43: "Rec" 46: "." 47: "Sz" 50: ">=" 53: "80"
line
- A string containing one or more SQL-like query expression word tokens
separated by whitespace.pos
- Position within line where token parsing is to begin.tok
- The text of the extracted word token is returned in this object.
java.text.ParseException
- Thrown if a token is malformed, such as missing a closing quote.getTokens(java.lang.String)
public static java.lang.String[] getTokens(java.lang.String line) throws java.text.ParseException
Words may be quoted by surrounding them with single quote (') or double quote (") characters. If a word contains either of these characters, it must be quoted, and the embedded quote characters must be preceded by a backslash character (\). (Embedded backslash characters should not be preceded by another backslash, however.)
Example
Consider the following input text line:
Date\ 2 = "2001-01-01" & `I.D.` like '%\'s' & Rec.Sz >= 80The line above is split into the following tokens:
[0]: "Date 2" [1]: "=" [2]: "\"2001-01-01\"" [3]: "&" [4]: "I.D." [5]: "like" [6]: "'%'s'" [7]: "&" [8]: "Rec" [9]: "." [10]: "Sz" [11]: ">=" [10]: "80"
line
- A string containing one or more text tokens separated by whitespace.
java.text.ParseException
- Thrown if a token is malformed, such as missing a closing quote.getToken(java.lang.String, int, java.lang.StringBuffer)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |