|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object tribble.net.ftp.shell.CommandParser
class CommandParser
FTP command script parser. Parses a command script text input stream containing FTP commands into a parse tree.
The parser uses a recursive-descent LL(1) parsing algorithm.
See the package summary for details about syntax and lexicon.
Example
Loop1: foreach *.tar { get $F if ($Error != 0) continue Loop1 del $F !tar -xf $F !del $F }
The example script above parses into the following command parse tree:
1 (block "file") 2 (filename "foo.ftp" 3 (label "loop1") 4 (foreach &1 "remote" "*.tar" 0 nil) 5 (get &1 "$F") 6 (if (!= "$Error" "0")) 7 (continue "loop1") 8 (del &1 "$F") 9 (! "tar" "-xf" "$F") 10 (! "del" "$F")
Copyright ©2007-2008 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.
CommandLexer
,
CommandTokens
,
CommandNode
,
BlockDef
Field Summary | |
---|---|
(package private) int |
m_lineNo
Source line number of the last token read. |
(package private) int |
m_nErrors
Errors produced. |
(package private) int |
m_nWarnings
Warnings produced. |
(package private) static java.lang.String |
REV
Revision information. |
Fields inherited from interface tribble.net.ftp.shell.VarNames |
---|
VAR_CMDPORT, VAR_COMMANDCNT, VAR_DATAPORT, VAR_ERROR, VAR_ERRORCMD, VAR_ERRORCNT, VAR_ERRORMSG, VAR_FILE, VAR_FILE_DIR, VAR_FILE_DIRSEP, VAR_FILE_EXT, VAR_FILE_FILE, VAR_FILE_GROUP, VAR_FILE_HOST, VAR_FILE_NAME, VAR_FILE_OWNER, VAR_FILE_PATH, VAR_FILE_PERMS, VAR_FILE_SIZE, VAR_FILE_TYPE, VAR_FILENAME, VAR_HOST, VAR_LINENUM, VAR_LOCALDIR, VAR_PASSWORD, VAR_PORT, VAR_RANDOM, VAR_REMOTEDIR, VAR_SESSIONCNT, VAR_TIME, VAR_TIMEOUT, VAR_TZOFFSET, VAR_USER |
Constructor Summary | |
---|---|
CommandParser(java.io.Reader in)
Constructor. |
|
CommandParser(java.io.Reader in,
java.io.Writer out)
Constructor. |
Method Summary | |
---|---|
(package private) CommandNode |
parse()
Parse a command script. |
(package private) CommandNode |
parseAnExpr()
Parse an expression. |
(package private) java.lang.String |
readToken()
Read the next input token from the source script. |
(package private) void |
setSourceName(java.lang.String name)
Establish the name of the source stream (the command script). |
(package private) void |
unReadToken(java.lang.String tok)
Push back the last token read from the input source. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final java.lang.String REV
int m_lineNo
int m_nErrors
int m_nWarnings
Constructor Detail |
---|
CommandParser(java.io.Reader in)
in
- Command script input stream.CommandParser(java.io.Reader in, java.io.Writer out)
in
- Command script input stream.out
- Error/warning message output stream.Method Detail |
---|
void setSourceName(java.lang.String name)
name
- Name of the input stream, typically a filename.CommandNode parse() throws java.text.ParseException, java.io.IOException
in
- Input stream containing the contents of the command script.
java.text.ParseException
java.io.IOException
CommandNode parseAnExpr() throws java.text.ParseException, java.io.IOException
java.text.ParseException
java.io.IOException
java.lang.String readToken() throws java.io.IOException
m_lineNo
to reflect the source line number of
the returned token.
Tokens are composed of simple keywords (e.g., get), or quoted literals (e.g., "*.txt", 'get.*'). Tokens may contain embedded variable sequences (e.g., "${name}").
Blank lines are ignored. Comments start with # and end at the end of the line (newline), and are ignored.
Tokens cannot be longer than 2,000 characters.
CommandTokens.TOK__NL
if an end-of-line (newline) was
read, or null if the end of the source stream was reached. Note that the
stream is not closed after the end is reached.
java.io.IOException
void unReadToken(java.lang.String tok)
readToken()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |