org.millscript.millscript.syntax
Class SpiceClassParserDelegate

java.lang.Object
  extended by org.millscript.millscript.syntax.SpiceClassParserDelegate
All Implemented Interfaces:
org.millscript.commons.alert.AlertOrigin, Parser, Tokenizer

public final class SpiceClassParserDelegate
extends java.lang.Object
implements Parser

This class provides a parser for use when parsing a Spice class.


Field Summary
 
Fields inherited from interface org.millscript.millscript.syntax.Parser
ARITH_PREC, COMMA_PREC, COMMA_PREC1, LOW_PREC, NOT_PREC, RELOP_PREC, TIGHT_PREC
 
Constructor Summary
SpiceClassParserDelegate(Parser p, NameExpr name)
          Constructs a new SpiceClassParserDelegate to parse a class with the specified name, using the specified parser.
 
Method Summary
 boolean checkWhere(char ch)
          Check if the tokenzier is using the specified strategy for reading names and strings.
 void dropToken()
          Drops the current token, ready to read the next one.
 boolean equals(java.lang.Object obj)
           
 java.lang.String getAttributeName()
          Returns the current token, checking it is a valid XML element attribute name.
 NameExpr getEnclosingClass()
          Returns the enclosing class for this parser.
 java.lang.String getErrorString()
          Returns the current token for use as an error message.
 int getInt()
          Returns the current token as an int.
 int getLineNumber()
          Returns the line number of the current token.
 java.lang.String getName()
          Returns the current token as a name, or interned string.
 java.lang.String getOrigin()
          Returns the origin of this tokenizers character source.
 char getQuoteChar()
          Returns the first character of the current token, which will be the quote character for a string token.
 java.lang.String getString()
          Returns the current token as a string.
 java.lang.String getStringNoQuotes()
          Returns the current token as a string, without the surrounding quotes.
 java.lang.String getStringNoQuotes(int a, int b)
          Returns the current token as a string, with the specified number of characters removed from the start and end.
 java.lang.String getTagName()
          Returns the current token, checking it is a valid XML element name.
 int hashCode()
           
 Expr makeInterpolatedExpr()
          Returns the current string, as an application of the format function with the current interpolation map values as arguments.
 java.util.regex.Pattern makePattern()
          Returns a new tradition regular expression Pattern, made from the contents of the current buffer.
 void markReader()
          Marks the current position in the reader, so we can jump back to the marked position if required.
 void mustRead(java.lang.String sym)
          Tests if the next token is the same as the specified string.
 TokenType nextToken()
          Returns the type of the next token.
 boolean peekRead(java.lang.String sym)
          Peeks a look at the next token and compares it to the specified value.
 TokenType peekToken()
          Peeks a look at the type of the next token to be returned by nextToken.
 java.lang.String readAttributeName()
          Reads the next token from the source as an attribute name and returns it.
 Expr readBlock()
          Reads a sequence of expressions from the source as a Block.
 Expr readBlockTo(java.lang.String sym)
          Reads a sequence of expressions, followed by the specified symbol, from the source as a Block.
 Expr readExpr()
          Reads the next expression from the source.
 Expr readExprComma()
          Reads the next expression from the source at the COMMA_PREC1 precedence level.
 Expr readExprPrec(int prec)
          Reads the next expression from the source at the specified precedence level.
 Expr readExprTo(java.lang.String sym)
          Reads the next expression from the source, which must be followed by the specified symbol.
 NameExpr readName()
          Reads the next token from the source as a name and returns a name expression for it.
 Expr readOptExpr()
          Reads the optional next expression from the source.
 Expr readOptExprPrec(int prec)
          Reads the optional next expression from the source at the specified precedence level.
 Expr readOptPrimary()
          Reads the next token from the source as the optional primary expression in a potential sequence of expressions.
 Expr readPrimary()
          Reads the next token from the source as the primary expression in a potential sequence of expressions.
 Expr readStmnts()
          Reads a sequence of expressions from the source.
 Expr readStmntsTo(java.lang.String sym)
          Reads a sequence of expressions from the source, which must be followed by the specified symbol.
 java.lang.String readSymbol()
          Reads the next token from the source as a symbol and returns it.
 java.lang.String readTagName()
          Reads the next token from the source as a tag name and returns it.
 void resetReader()
          Resets the reader to the previously marked position.
 void setContext(java.lang.String s, int n)
           
 void setLineNumber(int n)
           
 void setOrigin(java.lang.String o)
           
 void setWhere(char ch)
          Sets the tokenizers current strategy for reading names and strings.
 java.lang.String toString()
           
 boolean tryRead(java.lang.String sym)
          Tests if the next token is the same as the specified string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SpiceClassParserDelegate

public SpiceClassParserDelegate(Parser p,
                                NameExpr name)
Constructs a new SpiceClassParserDelegate to parse a class with the specified name, using the specified parser.

Parameters:
p - the parser to delegate
name - the name of the class we are parsing
Method Detail

checkWhere

public boolean checkWhere(char ch)
Description copied from interface: Tokenizer
Check if the tokenzier is using the specified strategy for reading names and strings.

Specified by:
checkWhere in interface Tokenizer
Parameters:
ch - the test strategy
Returns:
true if the test and current strategy are the same, otherwise false
See Also:
Tokenizer.checkWhere(char)

dropToken

public void dropToken()
Description copied from interface: Tokenizer
Drops the current token, ready to read the next one.

Specified by:
dropToken in interface Tokenizer
See Also:
Tokenizer.dropToken()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

getAttributeName

public java.lang.String getAttributeName()
Description copied from interface: Tokenizer
Returns the current token, checking it is a valid XML element attribute name.

Specified by:
getAttributeName in interface Tokenizer
Returns:
a string holding the current token, which will be a valid XML element attribute name
See Also:
Tokenizer.getAttributeName()

getEnclosingClass

public NameExpr getEnclosingClass()
Description copied from interface: Parser
Returns the enclosing class for this parser.

Specified by:
getEnclosingClass in interface Parser
Returns:
a NameExpr for the enclosing class
See Also:
Parser.getEnclosingClass()

getErrorString

public java.lang.String getErrorString()
Description copied from interface: Tokenizer
Returns the current token for use as an error message. As such it will be the current token, or a special message if the end of file has been reached.

Specified by:
getErrorString in interface Tokenizer
Returns:
a string holding the current token as an error message
See Also:
Tokenizer.getErrorString()

getInt

public int getInt()
Description copied from interface: Tokenizer
Returns the current token as an int.

Specified by:
getInt in interface Tokenizer
Returns:
the int value of the current token
See Also:
Tokenizer.getInt()

getLineNumber

public int getLineNumber()
Description copied from interface: Tokenizer
Returns the line number of the current token.

Specified by:
getLineNumber in interface org.millscript.commons.alert.AlertOrigin
Specified by:
getLineNumber in interface Tokenizer
Returns:
the line number of the current token
See Also:
Tokenizer.getLineNumber()

getName

public java.lang.String getName()
Description copied from interface: Tokenizer
Returns the current token as a name, or interned string.

Specified by:
getName in interface Tokenizer
Returns:
an interned string for the current token
See Also:
Tokenizer.getName()

getOrigin

public java.lang.String getOrigin()
Description copied from interface: Tokenizer
Returns the origin of this tokenizers character source.

Specified by:
getOrigin in interface org.millscript.commons.alert.AlertOrigin
Specified by:
getOrigin in interface Tokenizer
Returns:
this tokenziers character source origin
See Also:
Tokenizer.getOrigin()

getQuoteChar

public char getQuoteChar()
Description copied from interface: Tokenizer
Returns the first character of the current token, which will be the quote character for a string token.

Specified by:
getQuoteChar in interface Tokenizer
Returns:
the first character of the current token
See Also:
Tokenizer.getQuoteChar()

getString

public java.lang.String getString()
Description copied from interface: Tokenizer
Returns the current token as a string.

Specified by:
getString in interface Tokenizer
Returns:
a string holding the current token
See Also:
Tokenizer.getString()

getStringNoQuotes

public java.lang.String getStringNoQuotes()
Description copied from interface: Tokenizer
Returns the current token as a string, without the surrounding quotes.

Specified by:
getStringNoQuotes in interface Tokenizer
Returns:
a String with the current token, leading and trailing characters removed
See Also:
Tokenizer.getStringNoQuotes()

getStringNoQuotes

public java.lang.String getStringNoQuotes(int a,
                                          int b)
Description copied from interface: Tokenizer
Returns the current token as a string, with the specified number of characters removed from the start and end.

Specified by:
getStringNoQuotes in interface Tokenizer
Parameters:
a - the number of character to remove from the start of the current token
b - the number of character to remove from the end of the current token
Returns:
a String with the current token, with the specified number of characters removed from the start and end
See Also:
Tokenizer.getStringNoQuotes(int, int)

getTagName

public java.lang.String getTagName()
Description copied from interface: Tokenizer
Returns the current token, checking it is a valid XML element name.

Specified by:
getTagName in interface Tokenizer
Returns:
a string holding the current token, which will be a valid XML element name
See Also:
Tokenizer.getTagName()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

makeInterpolatedExpr

public Expr makeInterpolatedExpr()
Description copied from interface: Parser
Returns the current string, as an application of the format function with the current interpolation map values as arguments. The values in the interpolation map will be parsed into expressions.

Specified by:
makeInterpolatedExpr in interface Parser
Returns:
an ApplyExpr, applying the format function to format the current string
See Also:
Parser.makeInterpolatedExpr()

makePattern

public java.util.regex.Pattern makePattern()
Description copied from interface: Tokenizer
Returns a new tradition regular expression Pattern, made from the contents of the current buffer. It looks for the last / in the string to see if there are any flags specified.

Specified by:
makePattern in interface Tokenizer
Returns:
a new Pattern for the current buffer
See Also:
Tokenizer.makePattern()

markReader

public void markReader()
Description copied from interface: Tokenizer
Marks the current position in the reader, so we can jump back to the marked position if required.

Specified by:
markReader in interface Tokenizer
See Also:
Tokenizer.markReader()

mustRead

public void mustRead(java.lang.String sym)
Description copied from interface: Tokenizer
Tests if the next token is the same as the specified string. If successful, the token will be dropped, otherwise an alert will be raised.

Specified by:
mustRead in interface Tokenizer
Parameters:
sym - the token we want to try and read
See Also:
Tokenizer.mustRead(String)

nextToken

public TokenType nextToken()
Description copied from interface: Tokenizer
Returns the type of the next token. It's unlikely that the TokenType.NEED_NEW token will be returned by this method.

Specified by:
nextToken in interface Tokenizer
Returns:
the TokenType of the next token
See Also:
Tokenizer.nextToken()

peekRead

public boolean peekRead(java.lang.String sym)
Description copied from interface: Tokenizer
Peeks a look at the next token and compares it to the specified value.

Specified by:
peekRead in interface Tokenizer
Parameters:
sym - the token we want to try and read
Returns:
true if the next token is the same as the one specified, false otherwise
See Also:
Tokenizer.peekRead(String)

peekToken

public TokenType peekToken()
Description copied from interface: Tokenizer
Peeks a look at the type of the next token to be returned by nextToken.

Specified by:
peekToken in interface Tokenizer
Returns:
the TokenType of the next token to be returned by a call to Tokenizer.nextToken()
See Also:
Tokenizer.peekToken()

readAttributeName

public java.lang.String readAttributeName()
Description copied from interface: Parser
Reads the next token from the source as an attribute name and returns it. An alert will be generated if the next token is not a name.

Specified by:
readAttributeName in interface Parser
Returns:
a String containing a tag name
See Also:
Parser.readAttributeName()

readBlock

public Expr readBlock()
Description copied from interface: Parser
Reads a sequence of expressions from the source as a Block.

Specified by:
readBlock in interface Parser
Returns:
a Block wrapping the sequence of expressions read
See Also:
Parser.readBlock()

readBlockTo

public Expr readBlockTo(java.lang.String sym)
Description copied from interface: Parser
Reads a sequence of expressions, followed by the specified symbol, from the source as a Block.

Specified by:
readBlockTo in interface Parser
Parameters:
sym - the symbol which must follow the block
Returns:
a Block wrapping the sequence of expressions read
See Also:
Parser.readBlockTo(String)

readExpr

public Expr readExpr()
Description copied from interface: Parser
Reads the next expression from the source.

Specified by:
readExpr in interface Parser
Returns:
an Expr for the next token in the source
See Also:
Parser.readExpr()

readExprComma

public Expr readExprComma()
Description copied from interface: Parser
Reads the next expression from the source at the COMMA_PREC1 precedence level. Hence this will read up to the next comma.

Specified by:
readExprComma in interface Parser
Returns:
an Expr for the next token in the source
See Also:
Parser.readExprComma()

readExprPrec

public Expr readExprPrec(int prec)
Description copied from interface: Parser
Reads the next expression from the source at the specified precedence level.

Specified by:
readExprPrec in interface Parser
Parameters:
prec - the precedence level to read the next expression at
Returns:
an Expr for the next token in the source
See Also:
Parser.readExprPrec(int)

readExprTo

public Expr readExprTo(java.lang.String sym)
Description copied from interface: Parser
Reads the next expression from the source, which must be followed by the specified symbol.

Specified by:
readExprTo in interface Parser
Parameters:
sym - the symbol which must follow the expression
Returns:
an Expr for the next token in the source
See Also:
Parser.readExprTo(String)

readName

public NameExpr readName()
Description copied from interface: Parser
Reads the next token from the source as a name and returns a name expression for it. A name is a symbol that is not a keyword. An alert will be generated if the next token is a built in identifier.

Specified by:
readName in interface Parser
Returns:
a NameExpr for the next token
See Also:
Parser.readName()

readOptExpr

public Expr readOptExpr()
Description copied from interface: Parser
Reads the optional next expression from the source. Optional means that there doesn't have to be another expression in the source.

Specified by:
readOptExpr in interface Parser
Returns:
an Expr for the next token in the source
See Also:
Parser.readOptExpr()

readOptExprPrec

public Expr readOptExprPrec(int prec)
Description copied from interface: Parser
Reads the optional next expression from the source at the specified precedence level. Optional means that there doesn't have to be another expression in the source.

Specified by:
readOptExprPrec in interface Parser
Parameters:
prec - the precedence level to read the next expression at
Returns:
an Expr for the next token in the source
See Also:
Parser.readOptExprPrec(int)

readOptPrimary

public Expr readOptPrimary()
Description copied from interface: Parser
Reads the next token from the source as the optional primary expression in a potential sequence of expressions.

Specified by:
readOptPrimary in interface Parser
Returns:
an Expr for the next token in the source
See Also:
Parser.readOptPrimary()

readPrimary

public Expr readPrimary()
Description copied from interface: Parser
Reads the next token from the source as the primary expression in a potential sequence of expressions.

Specified by:
readPrimary in interface Parser
Returns:
an Expr for the next token in the source
See Also:
Parser.readPrimary()

readStmnts

public Expr readStmnts()
Description copied from interface: Parser
Reads a sequence of expressions from the source. The sequence of expressions are wrapped as a comma expression. This method will read up to the end of file, or a built-in keyword.

Specified by:
readStmnts in interface Parser
Returns:
an Expr for the sequence of expressions read
See Also:
Parser.readStmnts()

readStmntsTo

public Expr readStmntsTo(java.lang.String sym)
Description copied from interface: Parser
Reads a sequence of expressions from the source, which must be followed by the specified symbol.

Specified by:
readStmntsTo in interface Parser
Parameters:
sym - the symbol which must follow the statements
Returns:
an Expr for the sequence of expressions read
See Also:
Parser.readStmntsTo(String)

readSymbol

public java.lang.String readSymbol()
Description copied from interface: Parser
Reads the next token from the source as a symbol and returns it. An alert will be generated if the next token is not a name.

Specified by:
readSymbol in interface Parser
Returns:
a String containing the next symbol
See Also:
Parser.readSymbol()

readTagName

public java.lang.String readTagName()
Description copied from interface: Parser
Reads the next token from the source as a tag name and returns it. An alert will be generated if the next token is not a name.

Specified by:
readTagName in interface Parser
Returns:
a String containing a tag name
See Also:
Parser.readTagName()

resetReader

public void resetReader()
Description copied from interface: Tokenizer
Resets the reader to the previously marked position.

Specified by:
resetReader in interface Tokenizer
See Also:
Tokenizer.resetReader()

setContext

public void setContext(java.lang.String s,
                       int n)
Specified by:
setContext in interface org.millscript.commons.alert.AlertOrigin
See Also:
AlertOrigin.setContext(java.lang.String, int)

setLineNumber

public void setLineNumber(int n)
Specified by:
setLineNumber in interface org.millscript.commons.alert.AlertOrigin
See Also:
AlertOrigin.setLineNumber(int)

setOrigin

public void setOrigin(java.lang.String o)
Specified by:
setOrigin in interface org.millscript.commons.alert.AlertOrigin
See Also:
AlertOrigin.setOrigin(java.lang.String)

setWhere

public void setWhere(char ch)
Description copied from interface: Tokenizer
Sets the tokenizers current strategy for reading names and strings. This is used to let the tokenizer know when it's reading an XML tag name, attribute name or comment.

Specified by:
setWhere in interface Tokenizer
Parameters:
ch - the new strategy
See Also:
Tokenizer.setWhere(char)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

tryRead

public boolean tryRead(java.lang.String sym)
Description copied from interface: Tokenizer
Tests if the next token is the same as the specified string. If successful, the token will be dropped.

Specified by:
tryRead in interface Tokenizer
Parameters:
sym - the token we want to try and read
Returns:
true if the next token is the same as the one specified, false otherwise
See Also:
Tokenizer.tryRead(String)


Copyright © 2001-2007 Open World Ltd. All Rights Reserved.