|
Jatha Software | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jatha.read.LispParser
public class LispParser
A parser that reads LISP-syntax text from a text stream or string. It recognizes all standard LISP datatypes, although not structured ones. This function is designed to fulfill the function of the reader in a LISP read-eval-print loop. Once the LISP parser is instantiated, the parse() function can be used to read from a string or stream. It is best not to instantiate the LispParser yourself. Instead, do the following:
1. LispParser parser = Jatha.getParser(); 2. parser.setInputString(myString); 3. parser.setCaseSensitivity(LispParser.PRESERVE); 4. LispValue result = parser.parse();Normal usage is to parse a string. If you want to use a Reader, do:
new PushbackReader(myReader)
.
LispValue
Field Summary | |
---|---|
(package private) static char |
AT_SIGN
|
(package private) static char |
BACK_QUOTE
|
private int |
BackQuoteLevel
|
(package private) static char |
BACKSLASH
|
(package private) static char |
COLON
|
(package private) static char |
COMMA
|
(package private) static char |
DECIMAL
|
(package private) static char |
DOUBLE_QUOTE
|
static int |
DOWNCASE
|
(package private) static char |
EQUAL_SIGN
|
private int |
f_caseSensitivity
|
private Jatha |
f_lisp
|
private static LispParser |
f_myParser
|
(package private) static char |
HYPHEN
|
private PushbackReader |
inputReader
|
(package private) static char |
LEFT_ANGLE_BRACKET
|
(package private) static char |
LEFT_PAREN
|
(package private) static char |
OR_BAR
|
(package private) static char |
PERIOD
|
(package private) static char |
POUND
|
static int |
PRESERVE
|
(package private) static int |
READING_BACKQUOTED_LIST
|
(package private) static int |
READING_CHARACTER
|
(package private) static int |
READING_MIXED_CASE_SYMBOL
|
(package private) static int |
READING_NOTHING
|
(package private) static int |
READING_STRING
|
(package private) static int |
READING_SYMBOL
|
(package private) static char |
RIGHT_ANGLE_BRACKET
|
(package private) static char |
RIGHT_PAREN
|
(package private) static char |
SEMICOLON
|
(package private) static char |
SINGLE_QUOTE
|
(package private) static char |
UNDERSCORE
|
static int |
UPCASE
|
Constructor Summary | |
---|---|
LispParser(Jatha lisp,
Reader inStream)
|
|
LispParser(Jatha lisp,
Reader inStream,
int caseSensitivity)
Allows you to create a parser that handles input case conversion as you like. |
|
LispParser(Jatha lisp,
String inString)
|
|
LispParser(Jatha lisp,
String inString,
int caseSensitivity)
Allows you to create a parser that handles input case conversion as you like. |
Method Summary | |
---|---|
LispValue |
applyReaderMacro(PushbackReader stream)
This routine is called by parse when it encounters a pound (#) mark. |
static int |
firstCharNotInSet(int startIndex,
String str,
String charSet)
The equivalent of the C function 'strspn'. |
int |
getCaseSensitivity()
Retrieves the current case-sensitivity of the parser. |
PushbackReader |
getInputReader()
Gets the current reader to be parsed. |
static boolean |
hasBalancedParentheses(Jatha lisp,
LispValue input)
Returns true if the input expression has balanced parentheses |
static boolean |
hasBalancedParentheses(Jatha lisp,
String input)
Returns true if the input expression has balanced parentheses |
(package private) boolean |
INTEGER_token_p(String str)
|
(package private) boolean |
isAtSign(char x)
|
(package private) boolean |
isBackQuote(char x)
|
(package private) boolean |
isBackSlash(char x)
|
(package private) boolean |
isColon(char x)
|
(package private) boolean |
isComma(char x)
|
(package private) boolean |
isDoubleQuote(char x)
|
(package private) boolean |
isLeftAngleBracket(char x)
|
(package private) boolean |
isLparen(char x)
|
(package private) boolean |
isOrBar(char x)
|
(package private) boolean |
isPeriod(char x)
|
(package private) boolean |
isPound(char x)
|
(package private) boolean |
isQuote(char x)
|
(package private) boolean |
isRightAngleBracket(char x)
|
(package private) boolean |
isRparen(char x)
|
(package private) boolean |
isSemi(char x)
|
(package private) boolean |
isSpace(char x)
|
(package private) boolean |
isTerminator(char x)
|
(package private) boolean |
NIL_token_p(String str)
|
LispValue |
parse()
Parse() assumes that there is only one expression in the input string or file. |
LispValue |
read_backquoted_list_token(PushbackReader stream)
This library can't read backquotes yet. |
LispValue |
read_backquoted_token(PushbackReader stream)
This routine is called by parse when it encounters a backquote mark. |
(package private) LispValue |
read_comma_token(PushbackReader stream)
This routine is called by parse when it encounters a comma, which is only legal inside a backquote. |
LispValue |
read_list_token(PushbackReader stream)
Reads one list expression from the input stream and returns it. |
(package private) LispValue |
read_quoted_token(PushbackReader stream)
This routine is called by parse when it encounters a quote mark. |
LispValue |
read()
Reads one s-expression from the input stream (a string or file). |
(package private) boolean |
REAL_token_p(String str)
Does NOT recognize an isolated '+' or '-' as a real number. |
void |
setCaseSensitivity(int caseSensitivity)
Sets the current case-sensitivity of the parser. |
void |
setInputReader(PushbackReader inputReader)
Sets the input reader for the Parser. |
void |
setInputString(String s)
Sets the input string for the parser. |
void |
simple_parser_test()
|
(package private) boolean |
STRING_token_p(String str)
|
(package private) boolean |
SYMBOL_token_p(String str)
|
(package private) boolean |
T_token_p(String str)
|
void |
test_parser_loop()
|
void |
test_parser(String s)
|
LispValue |
tokenToLispValue(String token)
Converts a string to a LISP value such as NIL, T, an integer, a real number, a string or a symbol. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int UPCASE
public static final int DOWNCASE
public static final int PRESERVE
static final char AT_SIGN
static final char BACK_QUOTE
static final char BACKSLASH
static final char COLON
static final char COMMA
static final char DECIMAL
static final char DOUBLE_QUOTE
static final char EQUAL_SIGN
static final char LEFT_ANGLE_BRACKET
static final char LEFT_PAREN
static final char HYPHEN
static final char OR_BAR
static final char POUND
static final char PERIOD
static final char RIGHT_PAREN
static final char SEMICOLON
static final char RIGHT_ANGLE_BRACKET
static final char SINGLE_QUOTE
static final char UNDERSCORE
static final int READING_NOTHING
static final int READING_SYMBOL
static final int READING_MIXED_CASE_SYMBOL
static final int READING_CHARACTER
static final int READING_STRING
static final int READING_BACKQUOTED_LIST
private int BackQuoteLevel
private PushbackReader inputReader
private int f_caseSensitivity
private static LispParser f_myParser
private Jatha f_lisp
Constructor Detail |
---|
public LispParser(Jatha lisp, Reader inStream)
public LispParser(Jatha lisp, String inString)
public LispParser(Jatha lisp, Reader inStream, int caseSensitivity)
inStream
- public LispParser(Jatha lisp, String inString, int caseSensitivity)
Method Detail |
---|
public int getCaseSensitivity()
public void setCaseSensitivity(int caseSensitivity)
public PushbackReader getInputReader()
public void setInputReader(PushbackReader inputReader)
public void setInputString(String s)
public LispValue parse() throws EOFException
EOFException
read()
public LispValue read() throws EOFException
EOFException
public LispValue read_list_token(PushbackReader stream) throws EOFException
EOFException
LispValue read_quoted_token(PushbackReader stream) throws EOFException
EOFException
public LispValue read_backquoted_token(PushbackReader stream) throws EOFException
EOFException
LispValue read_comma_token(PushbackReader stream) throws EOFException
EOFException
public LispValue applyReaderMacro(PushbackReader stream) throws EOFException
EOFException
public LispValue read_backquoted_list_token(PushbackReader stream)
public LispValue tokenToLispValue(String token)
boolean isLparen(char x)
boolean isRparen(char x)
boolean isAtSign(char x)
boolean isBackQuote(char x)
boolean isBackSlash(char x)
boolean isColon(char x)
boolean isComma(char x)
boolean isDoubleQuote(char x)
boolean isOrBar(char x)
boolean isPound(char x)
boolean isPeriod(char x)
boolean isQuote(char x)
boolean isSemi(char x)
boolean isLeftAngleBracket(char x)
boolean isRightAngleBracket(char x)
boolean isSpace(char x)
boolean isTerminator(char x)
public static int firstCharNotInSet(int startIndex, String str, String charSet)
boolean REAL_token_p(String str)
boolean INTEGER_token_p(String str)
boolean NIL_token_p(String str)
boolean STRING_token_p(String str)
boolean SYMBOL_token_p(String str)
boolean T_token_p(String str)
public void test_parser(String s)
public void test_parser_loop() throws EOFException
EOFException
public static boolean hasBalancedParentheses(Jatha lisp, LispValue input)
input
- a String
public static boolean hasBalancedParentheses(Jatha lisp, String input)
input
- a String
public void simple_parser_test()
|
Jatha Software | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |