org.drools.lang
Class ParserHelper

java.lang.Object
  extended by org.drools.lang.ParserHelper

public class ParserHelper
extends Object

This is a class to hold all the helper functions/methods used by the DRL parser


Field Summary
 LinkedList<DroolsSentence> editorInterface
           
 List<DroolsParserException> errors
           
 boolean isEditorInterfaceEnabled
           
 boolean lookaheadTest
           
 String[] statementKeywords
           
 
Constructor Summary
ParserHelper(org.antlr.runtime.TokenStream input, org.antlr.runtime.RecognizerSharedState state)
           
 
Method Summary
 void beginSentence(DroolsSentenceType sentenceType)
           
 String buildStringFromTokens(List<org.antlr.runtime.Token> tokenList)
          Helper method that creates a string from a token list.
 void checkTrailingSemicolon(String text, org.antlr.runtime.Token token)
           
 void disableEditorInterface()
           
 void emit(boolean forceEmit, int activeContext)
           
 void emit(int activeContext)
           
 void emit(List<?> tokens, DroolsEditorType editorType)
           
 void emit(org.antlr.runtime.Token token, DroolsEditorType editorType)
           
 void enableEditorInterface()
           
<T extends DescrBuilder<?,?>>
T
end(Class<T> clazz, DescrBuilder<?,?> builder)
           
 DroolsSentence getActiveSentence()
           
 LinkedList<DroolsSentence> getEditorInterface()
           
 List<String> getErrorMessages()
          Return a list of pretty strings summarising the errors
 List<DroolsParserException> getErrors()
          return the raw DroolsParserException errors
 boolean getHasOperator()
           
 int getLastIntegerValue(LinkedList<?> list)
           
 DroolsToken getLastTokenOnList(LinkedList<?> list)
           
 String getLeftMostExpr()
           
 String[] getStatementKeywords()
           
 boolean hasErrors()
          return true if any parser errors were accumulated
 boolean isPluggableEvaluator(boolean negated)
           
 boolean isPluggableEvaluator(int offset, boolean negated)
           
 Map<DroolsParaphraseTypes,String> popParaphrases()
           
 void pushParaphrases(DroolsParaphraseTypes type)
          Method that adds a paraphrase type into paraphrases stack.
 void reportError(Exception e)
           
 void reportError(org.antlr.runtime.RecognitionException ex)
           
 String retrieveLT(int LTNumber)
           
 String safeSubstring(String text, int start, int end)
           
 void setHasOperator(boolean hasOperator)
           
 void setLeftMostExpr(String value)
           
 void setParaphrasesValue(DroolsParaphraseTypes type, String value)
          Method that sets paraphrase value for a type into paraphrases stack.
<T extends DescrBuilder<?,?>>
T
start(DescrBuilder<?,?> ctxBuilder, Class<T> clazz, String param)
           
protected  void syncToSet()
          Use the current stacked followset to work out the valid tokens that can follow on from the current point in the parse, then recover by eating tokens that are not a member of the follow set we compute.
protected  void syncToSet(org.antlr.runtime.BitSet follow)
           
 boolean validateAttribute(int index)
           
 boolean validateCEKeyword(int index)
           
 boolean validateIdentifierKey(String text)
           
 boolean validateIdentifierSufix()
           
 boolean validateKeyword(int i)
           
 boolean validateLT(int LTNumber, String text)
           
 boolean validateSpecialID(int index)
           
 boolean validateStatement(int index)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

statementKeywords

public final String[] statementKeywords

errors

public List<DroolsParserException> errors

editorInterface

public LinkedList<DroolsSentence> editorInterface

isEditorInterfaceEnabled

public boolean isEditorInterfaceEnabled

lookaheadTest

public boolean lookaheadTest
Constructor Detail

ParserHelper

public ParserHelper(org.antlr.runtime.TokenStream input,
                    org.antlr.runtime.RecognizerSharedState state)
Method Detail

getEditorInterface

public LinkedList<DroolsSentence> getEditorInterface()

setLeftMostExpr

public void setLeftMostExpr(String value)

getLeftMostExpr

public String getLeftMostExpr()

enableEditorInterface

public void enableEditorInterface()

disableEditorInterface

public void disableEditorInterface()

setHasOperator

public void setHasOperator(boolean hasOperator)

getHasOperator

public boolean getHasOperator()

beginSentence

public void beginSentence(DroolsSentenceType sentenceType)

getActiveSentence

public DroolsSentence getActiveSentence()

emit

public void emit(List<?> tokens,
                 DroolsEditorType editorType)

emit

public void emit(org.antlr.runtime.Token token,
                 DroolsEditorType editorType)

emit

public void emit(boolean forceEmit,
                 int activeContext)

emit

public void emit(int activeContext)

getLastTokenOnList

public DroolsToken getLastTokenOnList(LinkedList<?> list)

getLastIntegerValue

public int getLastIntegerValue(LinkedList<?> list)

retrieveLT

public String retrieveLT(int LTNumber)

validateLT

public boolean validateLT(int LTNumber,
                          String text)

isPluggableEvaluator

public boolean isPluggableEvaluator(int offset,
                                    boolean negated)

isPluggableEvaluator

public boolean isPluggableEvaluator(boolean negated)

validateIdentifierKey

public boolean validateIdentifierKey(String text)

validateSpecialID

public boolean validateSpecialID(int index)

validateCEKeyword

public boolean validateCEKeyword(int index)

validateStatement

public boolean validateStatement(int index)

validateAttribute

public boolean validateAttribute(int index)

validateIdentifierSufix

public boolean validateIdentifierSufix()

checkTrailingSemicolon

public void checkTrailingSemicolon(String text,
                                   org.antlr.runtime.Token token)

safeSubstring

public String safeSubstring(String text,
                            int start,
                            int end)

reportError

public void reportError(org.antlr.runtime.RecognitionException ex)

reportError

public void reportError(Exception e)

getErrors

public List<DroolsParserException> getErrors()
return the raw DroolsParserException errors


getErrorMessages

public List<String> getErrorMessages()
Return a list of pretty strings summarising the errors


hasErrors

public boolean hasErrors()
return true if any parser errors were accumulated


pushParaphrases

public void pushParaphrases(DroolsParaphraseTypes type)
Method that adds a paraphrase type into paraphrases stack.

Parameters:
type - paraphrase type

popParaphrases

public Map<DroolsParaphraseTypes,String> popParaphrases()

setParaphrasesValue

public void setParaphrasesValue(DroolsParaphraseTypes type,
                                String value)
Method that sets paraphrase value for a type into paraphrases stack.

Parameters:
type - paraphrase type
value - paraphrase value

buildStringFromTokens

public String buildStringFromTokens(List<org.antlr.runtime.Token> tokenList)
Helper method that creates a string from a token list.

Parameters:
tokenList - token list
Returns:
string

syncToSet

protected void syncToSet()
Use the current stacked followset to work out the valid tokens that can follow on from the current point in the parse, then recover by eating tokens that are not a member of the follow set we compute. This method is used whenever we wish to force a sync, even though the parser has not yet checked LA(1) for alt selection. This is useful in situations where only a subset of tokens can begin a new construct (such as the start of a new statement in a block) and we want to proactively detect garbage so that the current rule does not exit on on an exception. We could override recover() to make this the default behavior but that is too much like using a sledge hammer to crack a nut. We want finer grained control of the recovery and error mechanisms.


syncToSet

protected void syncToSet(org.antlr.runtime.BitSet follow)

start

public <T extends DescrBuilder<?,?>> T start(DescrBuilder<?,?> ctxBuilder,
                                             Class<T> clazz,
                                             String param)

end

public <T extends DescrBuilder<?,?>> T end(Class<T> clazz,
                                           DescrBuilder<?,?> builder)

getStatementKeywords

public String[] getStatementKeywords()

validateKeyword

public boolean validateKeyword(int i)


Copyright © 2001-2013 JBoss Inc.. All Rights Reserved.