com.objexcel.util
Class Alias

java.lang.Object
  |
  +--com.objexcel.util.Alias

public final class Alias
extends java.lang.Object

Alias complies and expands input strings against an alias. /aliasname text [$index[="variable name"]] text variable name:refers to a named variable you supply. If no variable is found, you'll be prompted for one. $index :the index refers to the n'th token on the command line supplied when expanding the alis $2- :indicates that everything following and including parameter 2 should be appended to the command line $2-4 : indicated user token 2 through four are substituted $-4 : indicated user token 0 (the alias name) through four are substituted $$1 : indicates this parameter is mandatory and the user will be prompted for a value if they don't enter one.

llr: ALIASNAME = (~whitespace)+ alias = ( input)* INPUT = (text | parameter | null)* PARAMETER = $[$](number | from | to | range)[="paramter_name"] FROM = number- TO = -number RANGE = number-number I know its a funny place for it, but Alias also has a bunch of useful parsing methods that other code can make use of.


Inner Class Summary
static interface Alias.IFetchInput
          IFetchInput specifies the interface for getting values to fill in from a set of arguments.
static class Alias.ParsedAlias
          ParsedAlias is the 'compiled' form of an alias (faster to expand this way)
 
Constructor Summary
Alias()
           
 
Method Summary
static char[] convertToCharArray(java.lang.String s)
          turn the string into an array of chars
static java.lang.String dollarDelimitedText(char[] input, int[] current)
          null | anything but $ (\$ ok)
static java.lang.String[] expand(java.lang.String[] tokens, Alias.ParsedAlias parsedAlias, java.lang.String target, java.lang.String me, Alias.IFetchInput inputFetcher)
          use the compiled alias to expand a set of user tokens
static java.lang.String[] getLines(char[] input, int[] current)
          split some text into lines.
static java.lang.String[] nameValuePair(char[] input, int[] current)
          name=[value] returns String[] {name, value}
static int number(char[] input, int[] current)
          (digit)*
static int[] numberParameter(char[] input, int[] current)
          n-n -n n-
static java.lang.Object[] parameter(char[] input, int[] current)
          $[$](numberParamter())[=quotedString()]
static Alias.ParsedAlias parseAlias(java.lang.String name, char[] input, int[] current)
          create a compiled alias out of the input
static java.lang.String quotedString(char[] input, int[] current, char escape)
          "quoted\"String"
static java.lang.String readLine(char[] input, int[] current)
          return the next line of text.
static java.lang.String remainder(char[] input, int[] current)
          return everthing from the current position on as a string null if nothing
static java.lang.String slashName(char[] input, int[] current)
          [space]'/'name as in /j fred returns j
static void space(char[] input, int[] current)
          
static java.lang.String specialDelimitedToken(char[] input, int[] current, char escape, char special, boolean throwIfDelimiterNotFound, boolean eatDelimiter)
          returns the next special delimited token.
static java.lang.String spRemainder(char[] input, int[] current)
          same as remainder but eats spaces first
static java.lang.String spWord(char[] input, int[] current)
          spWord: [space()]word same as word but is ok if we have spaces leading in null if no token
static java.lang.String[] tokenize(char[] input, int[] current, boolean isQuotedTextOneToken)
          return a array of tokens.
static java.lang.String word(char[] input, int[] current)
          word: ~' '(char ~[ ])*
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Alias

public Alias()
Method Detail

convertToCharArray

public static char[] convertToCharArray(java.lang.String s)
turn the string into an array of chars

expand

public static java.lang.String[] expand(java.lang.String[] tokens,
                                        Alias.ParsedAlias parsedAlias,
                                        java.lang.String target,
                                        java.lang.String me,
                                        Alias.IFetchInput inputFetcher)
                                 throws java.text.ParseException
use the compiled alias to expand a set of user tokens
Parameters:
tokens - are user entered tokens (0 = alias name, 1 = arg1, etc)
alias - a parsed alias to expand against
target - who the command is aimed at (person, room or null)
me - the person making the command.
inputFetcher - gathers any missing arguments
Returns:
null if the user cancels on user input, else the alias expanded with the users tokens

getLines

public static java.lang.String[] getLines(char[] input,
                                          int[] current)
split some text into lines.

tokenize

public static java.lang.String[] tokenize(char[] input,
                                          int[] current,
                                          boolean isQuotedTextOneToken)
                                   throws java.text.ParseException
return a array of tokens. tokens delimited by space or "..." pair

parseAlias

public static Alias.ParsedAlias parseAlias(java.lang.String name,
                                           char[] input,
                                           int[] current)
                                    throws java.text.ParseException
create a compiled alias out of the input

slashName

public static java.lang.String slashName(char[] input,
                                         int[] current)
                                  throws java.text.ParseException
[space]'/'name as in /j fred returns j

space

public static void space(char[] input,
                         int[] current)
                  throws java.text.ParseException

word

public static java.lang.String word(char[] input,
                                    int[] current)
                             throws java.text.ParseException
word: ~' '(char ~[ ])*

spWord

public static java.lang.String spWord(char[] input,
                                      int[] current)
spWord: [space()]word same as word but is ok if we have spaces leading in null if no token

remainder

public static java.lang.String remainder(char[] input,
                                         int[] current)
return everthing from the current position on as a string null if nothing

spRemainder

public static java.lang.String spRemainder(char[] input,
                                           int[] current)
same as remainder but eats spaces first

dollarDelimitedText

public static java.lang.String dollarDelimitedText(char[] input,
                                                   int[] current)
                                            throws java.text.ParseException
null | anything but $ (\$ ok)

parameter

public static java.lang.Object[] parameter(char[] input,
                                           int[] current)
                                    throws java.text.ParseException
$[$](numberParamter())[=quotedString()]
Returns:
Object[] {paramName, lowerParamName, int[] positions}

numberParameter

public static int[] numberParameter(char[] input,
                                    int[] current)
                             throws java.text.ParseException
n-n -n n-

quotedString

public static java.lang.String quotedString(char[] input,
                                            int[] current,
                                            char escape)
                                     throws java.text.ParseException
"quoted\"String"

number

public static int number(char[] input,
                         int[] current)
                  throws java.text.ParseException
(digit)*

nameValuePair

public static java.lang.String[] nameValuePair(char[] input,
                                               int[] current)
                                        throws java.text.ParseException
name=[value] returns String[] {name, value}

readLine

public static java.lang.String readLine(char[] input,
                                        int[] current)
return the next line of text. null if at end of stream

specialDelimitedToken

public static java.lang.String specialDelimitedToken(char[] input,
                                                     int[] current,
                                                     char escape,
                                                     char special,
                                                     boolean throwIfDelimiterNotFound,
                                                     boolean eatDelimiter)
                                              throws java.text.ParseException
returns the next special delimited token. ignore if escape then special e.g. test1\$test2 =>test1$test2 e.g. test$test2 => test e.g. test\xtest2 => test\xtest2