tribble.net.ftp.shell
Class CommandLexer

java.lang.Object
  extended by tribble.net.ftp.shell.CommandLexer
All Implemented Interfaces:
CommandTokens

 class CommandLexer
extends java.lang.Object
implements CommandTokens

FTP command script lexical analyzer.

See the package summary for details about syntax and lexicon.

Since:
API 1.0, 2007-03-14
Version:
$Revision: 1.20 $ $Date: 2007/08/12 19:48:51 $
Author:
David R. Tribble (david@tribble.com).

Copyright ©2007 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.

See Also:
CommandParser

Field Summary
(package private)  int m_lineNo
          Source line number of the last token read.
(package private) static java.lang.String REV
          Revision information.
 
Fields inherited from interface tribble.net.ftp.shell.CommandTokens
TOK__NL, TOK_ADD, TOK_AMPER, TOK_AND, TOK_APP, TOK_APPEND, TOK_ASC, TOK_ASCII, TOK_BANG, TOK_BEGIN, TOK_BIN, TOK_BINARY, TOK_BREAK, TOK_BYE, TOK_CALL, TOK_CD, TOK_CDUP, TOK_CENT, TOK_CHDIR, TOK_CLOSE, TOK_COLON, TOK_COMMA, TOK_CONCAT, TOK_CONNECT, TOK_CONTINUE, TOK_DEL, TOK_DELETE, TOK_DIR, TOK_DISC, TOK_DISCONNECT, TOK_DIV, TOK_DIVIDE, TOK_DO, TOK_DOLLAR, TOK_ECHO, TOK_ELSE, TOK_END, TOK_EQ, TOK_EQ2, TOK_ERROR, TOK_EXEC, TOK_EXIT, TOK_FALSE, TOK_FOR, TOK_FOREACH, TOK_FORMAT, TOK_FUNC, TOK_GE, TOK_GET, TOK_GLOB, TOK_GOTO, TOK_GT, TOK_GT2, TOK_HELP, TOK_IF, TOK_IN, TOK_INDEX, TOK_LABEL, TOK_LB, TOK_LC, TOK_LCASE, TOK_LCD, TOK_LCHDIR, TOK_LE, TOK_LEN, TOK_LOCAL, TOK_LP, TOK_LS, TOK_LT, TOK_MATCH, TOK_MAX, TOK_MGET, TOK_MKDIR, TOK_MOD, TOK_MPUT, TOK_MUL, TOK_NE, TOK_NEG, TOK_NMATCH, TOK_NO_N, TOK_NOP, TOK_NORM, TOK_NOT, TOK_OPEN, TOK_OR, TOK_PING, TOK_PLUS, TOK_PORT, TOK_PRINT, TOK_PROC, TOK_PROMPT, TOK_PUT, TOK_PWD, TOK_QUES, TOK_QUIT, TOK_RB, TOK_RC, TOK_READ, TOK_REMOTE, TOK_REN, TOK_RENAME, TOK_REPEAT, TOK_REPL, TOK_RETURN, TOK_RINDEX, TOK_RMDIR, TOK_RP, TOK_SECT, TOK_SET, TOK_SHELL, TOK_SHIFT, TOK_SLEEP, TOK_STATUS, TOK_SUB, TOK_SUBSTR, TOK_SYSTEM, TOK_TEST_D, TOK_TEST_DIR, TOK_TEST_E, TOK_TEST_EXEC, TOK_TEST_EXISTS, TOK_TEST_F, TOK_TEST_FILE, TOK_TEST_M, TOK_TEST_MTIME, TOK_TEST_R, TOK_TEST_READ, TOK_TEST_SIZE, TOK_TEST_W, TOK_TEST_WRITE, TOK_TEST_X, TOK_TEST_Z, TOK_TIMEOUT, TOK_TIMES, TOK_TRIM, TOK_TRUE, TOK_UCASE, TOK_UP, TOK_USER, TOK_VAR, TOK_WHILE, TOK_WRITE, TOK_X_INTERRUPT, TOK_X_SESSIONS, TOK_X_STACK, TOK_X_STOP, TOK_X_VARS, TOK_X_VERBOSE
 
Constructor Summary
CommandLexer(java.io.Reader in, java.io.PrintWriter out)
          Constructor.
 
Method Summary
(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 this source stream (the command script).
(package private)  void splitWordTokens(boolean flag)
          Establish whether or not token words in the current source input line are to be split or not.
(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

REV

static final java.lang.String REV
Revision information.

See Also:
Constant Field Values

m_lineNo

int m_lineNo
Source line number of the last token read.

Constructor Detail

CommandLexer

CommandLexer(java.io.Reader in,
             java.io.PrintWriter out)
Constructor.

Parameters:
in - Command script input stream.
out - Error/warning message output stream.
Since:
1.1, 2007-03-14
Method Detail

setSourceName

void setSourceName(java.lang.String name)
Establish the name of this source stream (the command script).

Parameters:
name - Name of the input stream. This is usually a filename, but it can be any kind of identification for the source stream.
Since:
1.6, 2007-03-27

splitWordTokens

void splitWordTokens(boolean flag)
Establish whether or not token words in the current source input line are to be split or not.

Note: This is something of a kludge, adding dirt to an otherwise fairly clean lexer implementation.

Parameters:
flag - True if subsequent token words are to be split into individual tokens, false otherwise.
Since:
1.18, 2007-05-31

readToken

java.lang.String readToken()
                     throws java.io.IOException
Read the next input token from the source script. This also updates 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}"). Tokens may be delimited by whitespace (spaces, tabs, and newlines), or are expressions enclosed within parentheses ('(').

Tokens cannot be longer than 2,000 characters.

Blank lines are ignored. Comments start with # and end at the end of the line (newline), and are ignored.

Source lines can be split and continued on subsequent lines by preceding the newline with a '`' (accent) escape character. Leading spaces on the next line are ignored.

Examples

    *.txt                  -> *.txt
    /bin/foo.ext           -> /bin/foo.ext
    $file.$ext             -> $file.$ext
    ($file.$ext)           -> ( $file . $ext )
    a#bc #xyz              -> a#bc nl
    'abc'.'def'            -> "abc" .'def'
    ('abc'.'def')          -> "abc" . "def"
    x+y/z*2                -> 'x+y/z*2'
    (x+y/z*2)              -> ( x + y / z * 2 )
    (a/b)+c/d              -> ( a / b ) +c/d
    &($s+1)                -> & ( $s + 1 )
    "&($s+1)"              -> "&($s+1)"
    drt@foo.com            -> drt@foo.com
    (drt@foo.com)          -> ( drt @foo . com )
    -123+45 +$foo          -> - 123 + 45 + $foo
    don`'t                 -> don`'t
    'foo`$bar`$'           -> 'foo`$bar`$'
    c: cd c:               -> c : cd c:

Returns:
The next token text, or CommandTokens.TOK__NL if an end-of-line (newline) was read, or null if the end of the source stream was reached.
Throws:
java.io.IOException
Since:
1.1, 2007-03-11

unReadToken

void unReadToken(java.lang.String tok)
Push back the last token read from the input source.

Since:
1.1, 2007-03-13
See Also:
readToken()