com.aptana.ide.parsing
Class AbstractParser

java.lang.Object
  extended by com.aptana.ide.parsing.AbstractParser
All Implemented Interfaces:
IParser
Direct Known Subclasses:
AbstractUnifiedParser

public abstract class AbstractParser
extends java.lang.Object
implements IParser

Author:
Kevin Lindsey

Field Summary
protected  Lexeme currentLexeme
          The current lexeme being considered in the parse
protected static Lexeme EOS
          End of stream lexeme.
 
Constructor Summary
protected AbstractParser(java.lang.String language)
          Creates a parser for the language specified and from the resource specified by the stream.
 
Method Summary
protected  void addChildParser(IParser child)
          addChildParser
protected  void addChildParsers()
          addChildParsers
protected  void addGrammars(ILexerBuilder lexerBuilder)
          addGrammars
protected  void addLexeme(Lexeme lexeme)
          addLexeme
abstract  void addLexerGrammar(ILexerBuilder builder)
          This method loads the parser's lexer grammar using the specified builder.
protected  void advance()
          Advance to the next lexeme in the lexeme stream
protected  void assertAndAdvance(int type, java.lang.String errorKey)
          Advance to the next lexeme if the current one is of the specified name
protected  void assertInSet(int[] set, java.lang.String errorKey)
          Make sure the current token is in the specified set
protected  void assertType(int type, java.lang.String errorKey)
          Make sure the current token is of the specified type
 void changeLanguage(java.lang.String mimeType, int offset, IParseNode parentNode)
          changeLanguage
protected abstract  ITokenList createLanguageTokenList()
          createLanguageTokenList
abstract  IParseState createParseState(IParseState parent)
          Create a single parse state for this language.
protected  void flushCache(java.lang.String delimiterGroupName)
          Clear the lexeme cache up to and including the specified delimiter.
 int getEndingOffset()
          getEndingOffset
 java.lang.String getLanguage()
          Get this parser's language type
 ILanguageChangeListener getLanguageChangeListener()
          getChangeLanguageEventHandler
protected  LexemeList getLexemeList()
          getLexemList
 ILexer getLexer()
          Get the lexer associated with this parser
protected  Lexeme getNextLexemeInLanguage()
          getNextLexemeInLanguage
protected  IParseNodeFactory getParseNodeFactory()
          getParseNodeFactory
 IParser getParserForMimeType(java.lang.String language)
          getParserForLanguage
protected  IParseState getParseState()
          getParseState
protected  boolean hasParent()
          hasParent
abstract  void initializeLexer()
          Perform any initializations on the lexer now that it has been created
protected  void initializeLexers()
          initializeLexers
protected  boolean inSet(int[] set)
          Determine if the current lexeme is in the specified set
protected  boolean isEOS()
          Determine if we are at the end of the source we are currently parsing
protected  boolean isType(int type)
          Determine if the current lexeme is of the given type
 IParseNode parse(IParseState parseState)
          Parse the edit to the source document encapsulated within the IParseState
abstract  void parseAll(IParseNode parentNode)
          parseOneStatement
protected  void removeLexeme(Lexeme lexeme)
          removeLexeme
 void setLanguageChangeListener(ILanguageChangeListener eventHandler)
          setChangeLanguageEventHandler
protected  void throwParseError(java.lang.String message)
          Throw a parse exception
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOS

protected static final Lexeme EOS
End of stream lexeme. Used internally


currentLexeme

protected Lexeme currentLexeme
The current lexeme being considered in the parse

Constructor Detail

AbstractParser

protected AbstractParser(java.lang.String language)
                  throws ParserInitializationException
Creates a parser for the language specified and from the resource specified by the stream.

Parameters:
language - - language mime type
Throws:
ParserInitializationException
Method Detail

addChildParser

protected void addChildParser(IParser child)
addChildParser

Parameters:
child -

addChildParsers

protected void addChildParsers()
                        throws ParserInitializationException
addChildParsers

Throws:
ParserInitializationException

addGrammars

protected void addGrammars(ILexerBuilder lexerBuilder)
                    throws LexerException
addGrammars

Parameters:
lexerBuilder -
Throws:
LexerException

addLexeme

protected void addLexeme(Lexeme lexeme)
addLexeme

Parameters:
lexeme -

addLexerGrammar

public abstract void addLexerGrammar(ILexerBuilder builder)
                              throws LexerException
This method loads the parser's lexer grammar using the specified builder. This allows multiple languages to share a single lexer.

Specified by:
addLexerGrammar in interface IParser
Parameters:
builder - The lexer builder being used to generate this language's lexer
Throws:
LexerException

advance

protected void advance()
                throws LexerException
Advance to the next lexeme in the lexeme stream

Throws:
LexerException

assertAndAdvance

protected void assertAndAdvance(int type,
                                java.lang.String errorKey)
                         throws LexerException,
                                java.text.ParseException
Advance to the next lexeme if the current one is of the specified name

Parameters:
type - The name index to test against the current lexeme
errorKey - A key used to look up an error message from our error property list
Throws:
LexerException
java.text.ParseException

assertInSet

protected void assertInSet(int[] set,
                           java.lang.String errorKey)
                    throws java.text.ParseException
Make sure the current token is in the specified set

Parameters:
set - The target set of lexeme type indexes to test against
errorKey - A key used to look up an error message from our error property list
Throws:
java.text.ParseException

assertType

protected void assertType(int type,
                          java.lang.String errorKey)
                   throws java.text.ParseException
Make sure the current token is of the specified type

Parameters:
type - The type index to compare against the current token
errorKey - A key used to look up an error message from our error property list
Throws:
java.text.ParseException

changeLanguage

public void changeLanguage(java.lang.String mimeType,
                           int offset,
                           IParseNode parentNode)
                    throws LexerException,
                           java.text.ParseException
Description copied from interface: IParser
changeLanguage

Specified by:
changeLanguage in interface IParser
parentNode - TODO
Throws:
LexerException
java.text.ParseException
See Also:
IParser.changeLanguage(java.lang.String, int, IParseNode)

createLanguageTokenList

protected abstract ITokenList createLanguageTokenList()
createLanguageTokenList

Returns:
ITokenList

createParseState

public abstract IParseState createParseState(IParseState parent)
Description copied from interface: IParser
Create a single parse state for this language. Note that sub-language parse states will be included in the returned parse state

Specified by:
createParseState in interface IParser
Returns:
IParseState
See Also:
IParser.createParseState(com.aptana.ide.parsing.IParseState)

flushCache

protected void flushCache(java.lang.String delimiterGroupName)
                   throws LexerException
Clear the lexeme cache up to and including the specified delimiter. This method is called when it has been determined that the lexer's cache (the lexeme list) has returned a faulty lexeme. A faulty lexeme is generally considered to be a lexeme whose language is of an unexpected type.

Parameters:
delimiterGroupName -
Throws:
LexerException

getEndingOffset

public int getEndingOffset()
getEndingOffset

Returns:
int

getLanguage

public java.lang.String getLanguage()
Get this parser's language type

Specified by:
getLanguage in interface IParser
Returns:
Returns the name of the language this parser targets

getLanguageChangeListener

public ILanguageChangeListener getLanguageChangeListener()
Description copied from interface: IParser
getChangeLanguageEventHandler

Specified by:
getLanguageChangeListener in interface IParser
Returns:
IChangeLanguageEventHandler
See Also:
IParser.getLanguageChangeListener()

getLexemeList

protected LexemeList getLexemeList()
getLexemList

Returns:
_lexemeList

getLexer

public ILexer getLexer()
Get the lexer associated with this parser

Specified by:
getLexer in interface IParser
Returns:
Returns the lexer used by this parser

getNextLexemeInLanguage

protected Lexeme getNextLexemeInLanguage()
                                  throws LexerException
getNextLexemeInLanguage

Returns:
Lexeme
Throws:
LexerException

getParseNodeFactory

protected IParseNodeFactory getParseNodeFactory()
getParseNodeFactory

Returns:
IParseNodeFactory

getParserForMimeType

public IParser getParserForMimeType(java.lang.String language)
getParserForLanguage

Specified by:
getParserForMimeType in interface IParser
Parameters:
language -
Returns:
IParser

getParseState

protected IParseState getParseState()
getParseState

Returns:
IParseState

hasParent

protected boolean hasParent()
hasParent

Returns:
boolean

initializeLexer

public abstract void initializeLexer()
                              throws LexerException
Perform any initializations on the lexer now that it has been created

Specified by:
initializeLexer in interface IParser
Throws:
LexerException

initializeLexers

protected void initializeLexers()
                         throws LexerException
initializeLexers

Throws:
LexerException

inSet

protected boolean inSet(int[] set)
Determine if the current lexeme is in the specified set

Parameters:
set - The target set of lexeme name indexes to test against
Returns:
Returns true if the current lexeme exists in the specified set

isEOS

protected boolean isEOS()
Determine if we are at the end of the source we are currently parsing

Returns:
Returns true if we are past the end of the source

isType

protected boolean isType(int type)
Determine if the current lexeme is of the given type

Parameters:
type - The type to test against the current lexeme
Returns:
Returns true if the current lexeme is of the specified type

parse

public IParseNode parse(IParseState parseState)
                 throws LexerException
Description copied from interface: IParser
Parse the edit to the source document encapsulated within the IParseState

Specified by:
parse in interface IParser
Returns:
IParseNode
Throws:
LexerException
See Also:
IParser.parse(com.aptana.ide.parsing.IParseState)

parseAll

public abstract void parseAll(IParseNode parentNode)
                       throws java.text.ParseException,
                              LexerException
parseOneStatement

Specified by:
parseAll in interface IParser
Parameters:
parentNode -
Throws:
java.text.ParseException
LexerException

removeLexeme

protected void removeLexeme(Lexeme lexeme)
removeLexeme

Parameters:
lexeme -

setLanguageChangeListener

public void setLanguageChangeListener(ILanguageChangeListener eventHandler)
Description copied from interface: IParser
setChangeLanguageEventHandler

Specified by:
setLanguageChangeListener in interface IParser
See Also:
IParser.setLanguageChangeListener(com.aptana.ide.parsing.ILanguageChangeListener)

throwParseError

protected void throwParseError(java.lang.String message)
                        throws java.text.ParseException
Throw a parse exception

Parameters:
message - The exception message
Throws:
java.text.ParseException