org.eclipse.xtext.parser.antlr
Class AbstractInternalAntlrParser

java.lang.Object
  extended by org.antlr.runtime.BaseRecognizer
      extended by org.antlr.runtime.Parser
          extended by org.eclipse.xtext.parser.antlr.AbstractInternalAntlrParser

public abstract class AbstractInternalAntlrParser
extends org.antlr.runtime.Parser

Base class for Xtext's generated parsers. It is reasonable customizable by means of object composition, e.g. error messages can be tailored to specific needs with an ISyntaxErrorMessageProvider, objects construction is subject to an IAstFactory.


Nested Class Summary
protected  class AbstractInternalAntlrParser.ErrorContext
           
protected  class AbstractInternalAntlrParser.LexerErrorContext
           
protected  class AbstractInternalAntlrParser.ParserErrorContext
           
protected  class AbstractInternalAntlrParser.UnorderedGroupErrorContext
           
protected  class AbstractInternalAntlrParser.ValueConverterErrorContext
           
 
Field Summary
 
Fields inherited from class org.antlr.runtime.Parser
input
 
Fields inherited from class org.antlr.runtime.BaseRecognizer
DEFAULT_TOKEN_CHANNEL, HIDDEN, INITIAL_FOLLOW_STACK_SIZE, MEMO_RULE_FAILED, MEMO_RULE_UNKNOWN, NEXT_TOKEN_RULE_NAME, state
 
Constructor Summary
protected AbstractInternalAntlrParser(org.antlr.runtime.TokenStream input)
           
protected AbstractInternalAntlrParser(org.antlr.runtime.TokenStream input, org.antlr.runtime.RecognizerSharedState state)
           
 
Method Summary
protected  void add(org.eclipse.emf.ecore.EObject _this, java.lang.String feature, java.lang.Object value, java.lang.String lexerRule)
           
protected  void add(org.eclipse.emf.ecore.EObject _this, java.lang.String feature, java.lang.Object value, java.lang.String lexerRule, INode node)
           
protected  void addWithLastConsumed(org.eclipse.emf.ecore.EObject _this, java.lang.String feature, java.lang.Object value, java.lang.String lexerRule)
           
protected  void afterParserOrEnumRuleCall()
           
protected  void appendAllTokens()
           
protected  void appendError(INode node)
           
protected  java.util.List<ILeafNode> appendSkippedTokens()
           
protected  void appendTrailingHiddenTokens()
           
protected  void associateNodeWithAstElement(ICompositeNode node, org.eclipse.emf.ecore.EObject astElement)
           
protected  ISyntaxErrorMessageProvider.IParserErrorContext createErrorContext(org.antlr.runtime.RecognitionException e)
           
protected  org.eclipse.emf.ecore.EObject createModelElement(AbstractRule rule)
           
protected  org.eclipse.emf.ecore.EObject createModelElement(org.eclipse.emf.ecore.EClassifier classifier)
           
protected  org.eclipse.emf.ecore.EObject createModelElement(org.eclipse.emf.ecore.EClassifier classifier, ICompositeNode compositeNode)
           
protected  org.eclipse.emf.ecore.EObject createModelElementForParent(AbstractRule rule)
           
protected  org.eclipse.emf.ecore.EObject createModelElementForParent(org.eclipse.emf.ecore.EClassifier classifier)
           
protected  ISyntaxErrorMessageProvider.IValueConverterErrorContext createValueConverterErrorContext(ValueConverterException vce)
           
 void displayRecognitionError(java.lang.String[] tokenNames, org.antlr.runtime.RecognitionException e)
           
 void emitErrorMessage(java.lang.String msg)
          Override this method to change where error messages go
protected  void enterRule()
           
protected  org.eclipse.emf.ecore.EObject forceCreateModelElement(Action action, org.eclipse.emf.ecore.EObject value)
           
protected  org.eclipse.emf.ecore.EObject forceCreateModelElementAndAdd(Action action, org.eclipse.emf.ecore.EObject value)
           
protected  org.eclipse.emf.ecore.EObject forceCreateModelElementAndSet(Action action, org.eclipse.emf.ecore.EObject value)
           
 java.lang.String getErrorMessage(org.antlr.runtime.RecognitionException e, java.lang.String[] tokenNames)
          What error message should be generated for the various exception types?
protected abstract  java.lang.String getFirstRuleName()
           
protected abstract  IGrammarAccess getGrammarAccess()
           
 org.antlr.runtime.TokenStream getInput()
           
protected  INode getLastLeafNode()
           
 NodeModelBuilder getNodeModelBuilder()
           
 IAstFactory getSemanticModelBuilder()
           
 SyntaxErrorMessage getSyntaxErrorMessage(org.antlr.runtime.RecognitionException e, java.lang.String[] tokenNames)
           
 ISyntaxErrorMessageProvider getSyntaxErrorProvider()
           
 IUnorderedGroupHelper getUnorderedGroupHelper()
           
protected  java.lang.String getValueConverterExceptionMessage(ValueConverterException vce)
           
protected  void handleValueConverterException(ValueConverterException vce)
           
protected  void insertCompositeNode(Action action)
           
protected  void leaveRule()
           
protected  void newCompositeNode(org.eclipse.emf.ecore.EObject grammarElement)
           
protected  void newLeafNode(org.antlr.runtime.Token token, org.eclipse.emf.ecore.EObject grammarElement)
           
 IParseResult parse()
           
 IParseResult parse(java.lang.String entryRuleName)
           
 void recover(org.antlr.runtime.IntStream input, org.antlr.runtime.RecognitionException re)
          Recover from an error found on the input stream.
protected  java.lang.Object recoverFromMismatchedToken(org.antlr.runtime.IntStream input, int ttype, org.antlr.runtime.BitSet follow)
          Attempt to recover from a single missing or extra token.
protected  void registerRules(Grammar grammar)
           
 void reportError(org.antlr.runtime.RecognitionException e)
          Report a recognition problem.
protected  void set(org.eclipse.emf.ecore.EObject _this, java.lang.String feature, java.lang.Object value, java.lang.String lexerRule)
           
protected  void set(org.eclipse.emf.ecore.EObject _this, java.lang.String feature, java.lang.Object value, java.lang.String lexerRule, INode node)
           
 void setNodeModelBuilder(NodeModelBuilder nodeModelBuilder)
           
 void setSemanticModelBuilder(IAstFactory semanticModelBuilder)
           
 void setSyntaxErrorProvider(ISyntaxErrorMessageProvider syntaxErrorProvider)
           
 void setTokenTypeMap(java.util.Map<java.lang.Integer,java.lang.String> tokenTypeMap)
           
 void setUnorderedGroupHelper(IUnorderedGroupHelper unorderedGroupHelper)
           
protected  void setWithLastConsumed(org.eclipse.emf.ecore.EObject _this, java.lang.String feature, java.lang.Object value, java.lang.String lexerRule)
           
protected  java.lang.String superGetErrorMessage(org.antlr.runtime.RecognitionException e, java.lang.String[] tokenNames)
           
 
Methods inherited from class org.antlr.runtime.Parser
getCurrentInputSymbol, getMissingSymbol, getSourceName, getTokenStream, reset, setTokenStream, traceIn, traceOut
 
Methods inherited from class org.antlr.runtime.BaseRecognizer
alreadyParsedRule, beginResync, combineFollows, computeContextSensitiveRuleFOLLOW, computeErrorRecoverySet, consumeUntil, consumeUntil, endResync, failed, getBacktrackingLevel, getErrorHeader, getGrammarFileName, getNumberOfSyntaxErrors, getRuleInvocationStack, getRuleInvocationStack, getRuleMemoization, getRuleMemoizationCacheSize, getTokenErrorDisplay, getTokenNames, match, matchAny, memoize, mismatchIsMissingToken, mismatchIsUnwantedToken, pushFollow, recoverFromMismatchedSet, setBacktrackingLevel, toStrings, traceIn, traceOut
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractInternalAntlrParser

protected AbstractInternalAntlrParser(org.antlr.runtime.TokenStream input)

AbstractInternalAntlrParser

protected AbstractInternalAntlrParser(org.antlr.runtime.TokenStream input,
                                      org.antlr.runtime.RecognizerSharedState state)
Method Detail

registerRules

protected void registerRules(Grammar grammar)

getInput

public org.antlr.runtime.TokenStream getInput()

getGrammarAccess

protected abstract IGrammarAccess getGrammarAccess()

associateNodeWithAstElement

protected void associateNodeWithAstElement(ICompositeNode node,
                                           org.eclipse.emf.ecore.EObject astElement)

setTokenTypeMap

public void setTokenTypeMap(java.util.Map<java.lang.Integer,java.lang.String> tokenTypeMap)

setSyntaxErrorProvider

public void setSyntaxErrorProvider(ISyntaxErrorMessageProvider syntaxErrorProvider)

getSyntaxErrorProvider

public ISyntaxErrorMessageProvider getSyntaxErrorProvider()

set

protected void set(org.eclipse.emf.ecore.EObject _this,
                   java.lang.String feature,
                   java.lang.Object value,
                   java.lang.String lexerRule,
                   INode node)

set

protected void set(org.eclipse.emf.ecore.EObject _this,
                   java.lang.String feature,
                   java.lang.Object value,
                   java.lang.String lexerRule)

setWithLastConsumed

protected void setWithLastConsumed(org.eclipse.emf.ecore.EObject _this,
                                   java.lang.String feature,
                                   java.lang.Object value,
                                   java.lang.String lexerRule)

add

protected void add(org.eclipse.emf.ecore.EObject _this,
                   java.lang.String feature,
                   java.lang.Object value,
                   java.lang.String lexerRule,
                   INode node)

add

protected void add(org.eclipse.emf.ecore.EObject _this,
                   java.lang.String feature,
                   java.lang.Object value,
                   java.lang.String lexerRule)

addWithLastConsumed

protected void addWithLastConsumed(org.eclipse.emf.ecore.EObject _this,
                                   java.lang.String feature,
                                   java.lang.Object value,
                                   java.lang.String lexerRule)

appendError

protected void appendError(INode node)

appendAllTokens

protected void appendAllTokens()

getLastLeafNode

protected INode getLastLeafNode()

appendSkippedTokens

protected java.util.List<ILeafNode> appendSkippedTokens()

appendTrailingHiddenTokens

protected void appendTrailingHiddenTokens()

recover

public void recover(org.antlr.runtime.IntStream input,
                    org.antlr.runtime.RecognitionException re)
Description copied from class: org.antlr.runtime.BaseRecognizer
Recover from an error found on the input stream. This is for NoViableAlt and mismatched symbol exceptions. If you enable single token insertion and deletion, this will usually not handle mismatched symbol exceptions but there could be a mismatched token that the match() routine could not recover from.

Overrides:
recover in class org.antlr.runtime.BaseRecognizer

getValueConverterExceptionMessage

protected java.lang.String getValueConverterExceptionMessage(ValueConverterException vce)

handleValueConverterException

protected void handleValueConverterException(ValueConverterException vce)

createValueConverterErrorContext

protected ISyntaxErrorMessageProvider.IValueConverterErrorContext createValueConverterErrorContext(ValueConverterException vce)

getErrorMessage

public java.lang.String getErrorMessage(org.antlr.runtime.RecognitionException e,
                                        java.lang.String[] tokenNames)
Description copied from class: org.antlr.runtime.BaseRecognizer
What error message should be generated for the various exception types? Not very object-oriented code, but I like having all error message generation within one method rather than spread among all of the exception classes. This also makes it much easier for the exception handling because the exception classes do not have to have pointers back to this object to access utility routines and so on. Also, changing the message for an exception type would be difficult because you would have to subclassing exception, but then somehow get ANTLR to make those kinds of exception objects instead of the default. This looks weird, but trust me--it makes the most sense in terms of flexibility. For grammar debugging, you will want to override this to add more information such as the stack frame with getRuleInvocationStack(e, this.getClass().getName()) and, for no viable alts, the decision description and state etc... Override this to change the message generated for one or more exception types.

Overrides:
getErrorMessage in class org.antlr.runtime.BaseRecognizer

displayRecognitionError

public void displayRecognitionError(java.lang.String[] tokenNames,
                                    org.antlr.runtime.RecognitionException e)
Overrides:
displayRecognitionError in class org.antlr.runtime.BaseRecognizer

reportError

public void reportError(org.antlr.runtime.RecognitionException e)
Description copied from class: org.antlr.runtime.BaseRecognizer
Report a recognition problem. This method sets errorRecovery to indicate the parser is recovering not parsing. Once in recovery mode, no errors are generated. To get out of recovery mode, the parser must successfully match a token (after a resync). So it will go: 1. error occurs 2. enter recovery mode, report error 3. consume until token found in resynch set 4. try to resume parsing 5. next match() will reset errorRecovery mode If you override, make sure to update syntaxErrors if you care about that.

Overrides:
reportError in class org.antlr.runtime.BaseRecognizer

recoverFromMismatchedToken

protected java.lang.Object recoverFromMismatchedToken(org.antlr.runtime.IntStream input,
                                                      int ttype,
                                                      org.antlr.runtime.BitSet follow)
                                               throws org.antlr.runtime.RecognitionException
Description copied from class: org.antlr.runtime.BaseRecognizer
Attempt to recover from a single missing or extra token. EXTRA TOKEN LA(1) is not what we are looking for. If LA(2) has the right token, however, then assume LA(1) is some extra spurious token. Delete it and LA(2) as if we were doing a normal match(), which advances the input. MISSING TOKEN If current token is consistent with what could come after ttype then it is ok to "insert" the missing token, else throw exception For example, Input "i=(3;" is clearly missing the ')'. When the parser returns from the nested call to expr, it will have call chain: stat -> expr -> atom and it will be trying to match the ')' at this point in the derivation: => ID '=' '(' INT ')' ('+' atom)* ';' ^ match() will see that ';' doesn't match ')' and report a mismatched token error. To recover, it sees that LA(1)==';' is in the set of tokens that can follow the ')' token reference in rule atom. It can assume that you forgot the ')'.

Overrides:
recoverFromMismatchedToken in class org.antlr.runtime.BaseRecognizer
Throws:
org.antlr.runtime.RecognitionException

getSyntaxErrorMessage

public SyntaxErrorMessage getSyntaxErrorMessage(org.antlr.runtime.RecognitionException e,
                                                java.lang.String[] tokenNames)

superGetErrorMessage

protected java.lang.String superGetErrorMessage(org.antlr.runtime.RecognitionException e,
                                                java.lang.String[] tokenNames)

createErrorContext

protected ISyntaxErrorMessageProvider.IParserErrorContext createErrorContext(org.antlr.runtime.RecognitionException e)

parse

public final IParseResult parse()
                         throws org.antlr.runtime.RecognitionException
Throws:
org.antlr.runtime.RecognitionException

parse

public final IParseResult parse(java.lang.String entryRuleName)
                         throws org.antlr.runtime.RecognitionException
Throws:
org.antlr.runtime.RecognitionException

emitErrorMessage

public void emitErrorMessage(java.lang.String msg)
Description copied from class: org.antlr.runtime.BaseRecognizer
Override this method to change where error messages go

Overrides:
emitErrorMessage in class org.antlr.runtime.BaseRecognizer

getFirstRuleName

protected abstract java.lang.String getFirstRuleName()
Returns:
the name of the entry rule.

setUnorderedGroupHelper

public void setUnorderedGroupHelper(IUnorderedGroupHelper unorderedGroupHelper)

getUnorderedGroupHelper

public IUnorderedGroupHelper getUnorderedGroupHelper()

afterParserOrEnumRuleCall

protected void afterParserOrEnumRuleCall()

createModelElementForParent

protected org.eclipse.emf.ecore.EObject createModelElementForParent(AbstractRule rule)

createModelElement

protected org.eclipse.emf.ecore.EObject createModelElement(AbstractRule rule)

createModelElementForParent

protected org.eclipse.emf.ecore.EObject createModelElementForParent(org.eclipse.emf.ecore.EClassifier classifier)

createModelElement

protected org.eclipse.emf.ecore.EObject createModelElement(org.eclipse.emf.ecore.EClassifier classifier)

createModelElement

protected org.eclipse.emf.ecore.EObject createModelElement(org.eclipse.emf.ecore.EClassifier classifier,
                                                           ICompositeNode compositeNode)

forceCreateModelElementAndSet

protected org.eclipse.emf.ecore.EObject forceCreateModelElementAndSet(Action action,
                                                                      org.eclipse.emf.ecore.EObject value)

forceCreateModelElementAndAdd

protected org.eclipse.emf.ecore.EObject forceCreateModelElementAndAdd(Action action,
                                                                      org.eclipse.emf.ecore.EObject value)

forceCreateModelElement

protected org.eclipse.emf.ecore.EObject forceCreateModelElement(Action action,
                                                                org.eclipse.emf.ecore.EObject value)

insertCompositeNode

protected void insertCompositeNode(Action action)

enterRule

protected void enterRule()

leaveRule

protected void leaveRule()

newCompositeNode

protected void newCompositeNode(org.eclipse.emf.ecore.EObject grammarElement)

newLeafNode

protected void newLeafNode(org.antlr.runtime.Token token,
                           org.eclipse.emf.ecore.EObject grammarElement)

setNodeModelBuilder

public void setNodeModelBuilder(NodeModelBuilder nodeModelBuilder)

getNodeModelBuilder

public NodeModelBuilder getNodeModelBuilder()

setSemanticModelBuilder

public void setSemanticModelBuilder(IAstFactory semanticModelBuilder)

getSemanticModelBuilder

public IAstFactory getSemanticModelBuilder()