|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectai.krr.LispSymbolAdaptor
public class LispSymbolAdaptor
This class is an adaptor between the Symbol
class that can be used as
an internal representation for reasoning and its external form as defined by
the LISP syntax described below and in more detail in Guy L Steele's book
"Common Lisp the Language".
The type of the Symbol determines how exactly it is written out. Most Symbol
types are straight forward to write. NamedSymbol
s depend on the given
properties. If the case-sensitive property is set to false, lower case
letters will be escaped. The namespace-aware property determines whether the
NameSpace URI is written before the symbol name.
The syntax of LISP Symbols can be defined as follows:
<Symbol> ::= TRUE | FALSE | <double> | <int> | #\<char> | "<string>" | <NamedSymbol> <NamedSymbol> ::= [<URI>\#]<word> | '|'[<URI>\#]<string>'|'
NamedSymbol
s can be written in one of two ways: either as a word
containing only a limited set of characters (and other characters being
escaped), or as a string of arbitrary characters between vertical bars.
Parsing is performed using an underlying LexicalAnalyzer and is based on the
same syntax as writing (see above). The different regular expressions
defining the different Symbol types are tested and the one that matches is
returned. For NamedSymbol
s, the token must adhere to the LISP syntax
for words. Escaped characters will be un-escaped and the result will be
capitalized (unless the value of the case-sensitive property is set to true).
If the value of the namespace-aware property is false, an internal
NamedSymbol with the given name will be returned. Otherwise the
NameSpace
is extracted from the word and a NamedSymbol from that
NameSpace will be returned.
property | possible values | default |
---|---|---|
case-sensitive | true, false | false |
namespace-aware | true, false | false |
indent-string | any string | " " |
Field Summary | |
---|---|
static inf.compilers.LexicalAnalyzer.TokenType |
bwordTT
the token types used |
static inf.compilers.LexicalAnalyzer.TokenType |
charrefTT
the token types used |
static inf.compilers.LexicalAnalyzer.TokenType |
falseTT
the token types used |
static inf.compilers.LexicalAnalyzer.TokenType |
integerTT
the token types used |
protected java.util.Properties |
props
the properties used for reading and writing |
static inf.compilers.LexicalAnalyzer.TokenType |
realnumTT
the token types used |
protected static java.util.Set<java.lang.String> |
reservedSet
|
protected inf.compilers.LexicalAnalyzer |
scanner
the lexical analyzer used for tokenizing the input |
static inf.compilers.LexicalAnalyzer.TokenType |
stringTT
the token types used |
static inf.compilers.LexicalAnalyzer.TokenType |
trueTT
the token types used |
static inf.compilers.LexicalAnalyzer.TokenType |
wordTT
the token types used |
Constructor Summary | |
---|---|
LispSymbolAdaptor()
This constructor creates a SyntaxAdaptor that can be used to read symbols in a KIF syntax and create a Symbol for it, or it can be used to write out a Symbol in KIF syntax. |
Method Summary | |
---|---|
protected LispSymbolAdaptor |
clone()
This class does not support cloning and an Exception will be thrown if this method is called. |
protected static java.lang.String |
escapeString(java.lang.String str)
This function escapes certain characters in the given String by inserting a backslash ('\') just before them. |
java.lang.Class<SyntaxAdaptableSymbol> |
getInternalClass()
This function returns the Class that holds the internal representation this adaptor translates to and from. |
java.util.Properties |
getProperties()
This function returns all the Properties used by this SyntaxAdaptor. |
java.lang.String |
getProperty(java.lang.String key)
This function gets the property that is associated with the given key. |
java.lang.String |
getSyntaxName()
This function returns the name that should identify the syntactical language that this adaptor translates to and from. |
static NamedSymbol |
parseNamedSymbol(inf.compilers.LexicalAnalyzer scanner,
java.util.Properties props)
This function attempts to parse a NamedSymbol from the underlying LexicalAnalyzer. |
static SyntaxAdaptableSymbol |
parseSymbol(inf.compilers.LexicalAnalyzer scanner,
java.util.Properties props)
This function attempts to parse a Symbol from the underlying
LexicalAnalyzer. |
void |
prettyPrint(int indent,
SyntaxAdaptableSymbol sy,
java.io.Writer w)
This function takes a logical Symbol which is a Java Object in
the internal representation, and writes it to the given Writer as a
string conforming to the LISP syntax. |
SyntaxAdaptableSymbol |
read(java.io.Reader r)
This function attempts to parse characters from the given Reader until a Symbol that represents an object in the internal representation
has been parsed. |
void |
setProperty(java.lang.String key,
java.lang.String value)
This function sets the property associated with the given key to the given value. |
protected static java.lang.String |
unescapeString(java.lang.String str)
This function removes backslash characters from the given String. |
void |
write(SyntaxAdaptableSymbol sy,
java.io.Writer w)
This function takes a logical Symbol which is a Java Object in
the internal representation, and writes it to the given Writer as a
String conforming to the LISP syntax. |
static void |
writeIndent(int indent,
java.lang.String indentStr,
java.io.Writer w)
This function writes white space for indentation of a line to the given Writer. |
static void |
writeNamedSymbol(NamedSymbol nSy,
java.io.Writer w,
java.util.Properties props)
This function writes the given NamedSymbol to the given Writer. |
static void |
writeSymbol(Symbol sy,
java.io.Writer w,
java.util.Properties props)
This function writes the given Symbol to the given Writer. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static java.util.Set<java.lang.String> reservedSet
public static inf.compilers.LexicalAnalyzer.TokenType trueTT
public static inf.compilers.LexicalAnalyzer.TokenType falseTT
public static inf.compilers.LexicalAnalyzer.TokenType charrefTT
public static inf.compilers.LexicalAnalyzer.TokenType stringTT
public static inf.compilers.LexicalAnalyzer.TokenType integerTT
public static inf.compilers.LexicalAnalyzer.TokenType realnumTT
public static inf.compilers.LexicalAnalyzer.TokenType wordTT
public static inf.compilers.LexicalAnalyzer.TokenType bwordTT
protected java.util.Properties props
protected inf.compilers.LexicalAnalyzer scanner
Constructor Detail |
---|
public LispSymbolAdaptor()
This constructor creates a SyntaxAdaptor that can be used to read symbols in a KIF syntax and create a Symbol for it, or it can be used to write out a Symbol in KIF syntax.
Method Detail |
---|
protected LispSymbolAdaptor clone() throws java.lang.CloneNotSupportedException
This class does not support cloning and an Exception will be thrown if this method is called.
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- will be thrownpublic java.lang.Class<SyntaxAdaptableSymbol> getInternalClass()
This function returns the Class that holds the internal representation this adaptor translates to and from.
getInternalClass
in interface inf.compilers.SyntaxAdaptor<SyntaxAdaptableSymbol>
public java.lang.String getSyntaxName()
This function returns the name that should identify the syntactical language that this adaptor translates to and from.
getSyntaxName
in interface inf.compilers.SyntaxAdaptor<SyntaxAdaptableSymbol>
public void write(SyntaxAdaptableSymbol sy, java.io.Writer w) throws inf.compilers.ExpressivenessException, java.io.IOException
This function takes a logical Symbol
which is a Java Object in
the internal representation, and writes it to the given Writer as a
String conforming to the LISP syntax.
write
in interface inf.compilers.SyntaxAdaptor<SyntaxAdaptableSymbol>
sy
- a Symbol in the internal representationw
- the Writer to which the syntactical translation is written
inf.compilers.ExpressivenessException
- if the syntactical language cannot
represent the given statement
java.io.IOException
- if writing to the given Writer failspublic void prettyPrint(int indent, SyntaxAdaptableSymbol sy, java.io.Writer w) throws inf.compilers.ExpressivenessException, java.io.IOException
This function takes a logical Symbol
which is a Java Object in
the internal representation, and writes it to the given Writer as a
string conforming to the LISP syntax.
prettyPrint
in interface inf.compilers.SyntaxAdaptor<SyntaxAdaptableSymbol>
indent
- the amount of indentation for the first linew
- the Writer to which the syntactical translation is written
inf.compilers.ExpressivenessException
- if the syntactical language cannot
represent the given statement
java.io.IOException
- if writing to the given Writer failspublic SyntaxAdaptableSymbol read(java.io.Reader r) throws inf.compilers.ExpressivenessException, java.text.ParseException, java.io.IOException
This function attempts to parse characters from the given Reader until a
Symbol
that represents an object in the internal representation
has been parsed.
read
in interface inf.compilers.SyntaxAdaptor<SyntaxAdaptableSymbol>
r
- the Reader from which the representation is to be parsed
inf.compilers.ExpressivenessException
- if the internal representation class is
not expressive enough for the given symbol
java.text.ParseException
- if there is a syntax error in the given string
java.io.IOException
- if reading from the Reader failspublic java.lang.String getProperty(java.lang.String key)
This function gets the property that is associated with the given key. Note that the key should not be null.
getProperty
in interface inf.compilers.SyntaxAdaptor<SyntaxAdaptableSymbol>
public void setProperty(java.lang.String key, java.lang.String value)
This function sets the property associated with the given key to the given value. The given key must not be null, but the value may be.
setProperty
in interface inf.compilers.SyntaxAdaptor<SyntaxAdaptableSymbol>
key
- the key with which the value is associatedvalue
- the associated valuepublic java.util.Properties getProperties()
This function returns all the Properties used by this SyntaxAdaptor.
public static void writeSymbol(Symbol sy, java.io.Writer w, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.io.IOException
This function writes the given Symbol
to the given Writer. The
type of the Symbol determines how exactly it is written out.
sy
- the Symbol to be written outw
- the Writer to which the Symbol will be writtenprops
- the Properties used for writing
inf.compilers.ExpressivenessException
- if namespace-aware is true but sy is an
internal isNamedSymbol
java.io.IOException
- if writing to the Writer failspublic static void writeNamedSymbol(NamedSymbol nSy, java.io.Writer w, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.io.IOException
This function writes the given NamedSymbol
to the given Writer.
If the case-sensitive property is set to false, lower case letters will
be escaped. The namespace-aware property determines whether the NameSpace
URI is written before the symbol name. If this property is set to true an
attempt to write an internal NamedSymbol (which does not have an
associated NameSpace) will cause an ExpressivenessException.
nSy
- the NamedSymbol to be written outw
- the Writer to which the NamedSymbol will be writtenprops
- the Properties used for writing
inf.compilers.ExpressivenessException
- if namespace-aware is true but nSy is
internal
java.io.IOException
- if writing to the Writer failspublic static void writeIndent(int indent, java.lang.String indentStr, java.io.Writer w) throws java.io.IOException
This function writes white space for indentation of a line to the given Writer. The given integer determines the amount of indent, where the String associated with the property indent-string represents a single indent.
indent
- the number of times the indent-string is to be writtenindentStr
- the String defining a single indentationw
- the Writer to which the indent-strings will be written
java.io.IOException
- if writing to the Writer failspublic static SyntaxAdaptableSymbol parseSymbol(inf.compilers.LexicalAnalyzer scanner, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.text.ParseException, java.io.IOException
This function attempts to parse a Symbol
from the underlying
LexicalAnalyzer. The different regular expressions defining the different
Symbol types are tested and the one that matches is returned. The syntax
for Symbols is as follows:
<Symbol> ::= TRUE | FALSE | <double> | <int> | #\<char> | "<string>" | <NamedSymbol>
scanner
- the LexicalAnalyzer from which character input is readprops
- the properties used for reading
inf.compilers.ExpressivenessException
- if a named symbol cannot be expressed
java.text.ParseException
- if the LISP syntax for Symbols is violated
java.io.IOException
- if reading from the LexicalAnalyzer failspublic static NamedSymbol parseNamedSymbol(inf.compilers.LexicalAnalyzer scanner, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.text.ParseException, java.io.IOException
This function attempts to parse a NamedSymbol from the underlying LexicalAnalyzer. Thus, the next token must adhere to the LISP syntax for words or a ParseException will be thrown. Escaped characters will be un-escaped and the result will be capitalized (unless the value of the case-sensitive property is set to true). If the word is a reserved word in LISP a ParseException will be thrown. If the value of the namespace-aware property is false, an internal NamedSymbol with the given name will be returned. Otherwise the NameSpace is extracted from the word and a NamedSymbol from that NameSpace will be returned. The syntax for NamedSymbols is as follows:
<NamedSymbol> ::= [<URI>\#]<word> | '|'[<URI>\#]<string>'|'
scanner
- the LexicalAnalyzer from which character input is readprops
- the properties used for reading
inf.compilers.ExpressivenessException
- not thrown here
java.text.ParseException
- if the KIF syntax for words is violated
java.io.IOException
- if reading from the LexicalAnalyzer failsprotected static java.lang.String escapeString(java.lang.String str)
str
- the String that is to be escaped for writing
protected static java.lang.String unescapeString(java.lang.String str)
str
- the String that is to be un-escaped for reading
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |