Package org.drools.compiler.lang
Class DRL6StrictParser
- java.lang.Object
-
- org.drools.compiler.lang.AbstractDRLParser
-
- org.drools.compiler.lang.DRL6StrictParser
-
- All Implemented Interfaces:
DRLParser
public class DRL6StrictParser extends AbstractDRLParser implements DRLParser
-
-
Field Summary
-
Fields inherited from class org.drools.compiler.lang.AbstractDRLParser
helper, input, state
-
-
Constructor Summary
Constructors Constructor Description DRL6StrictParser(org.antlr.runtime.TokenStream input)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AttributeDescrattribute(AttributeSupportBuilder<?> as)attribute := salience | enabled | ( NO-LOOP | AUTO-FOCUS | LOCK-ON-ACTIVE | REFRACT | DIRECT ) BOOLEAN?Stringchunk(int leftDelimiter, int rightDelimiter, int location)Matches a chunk started by the leftDelimiter and ended by the rightDelimiter.protected PackageDescrcompilationUnit(PackageDescrBuilder pkg)StringconditionalExpression()Matches a conditional expressionStringconditionalOrExpression()Matches a conditional || expressionBaseDescrdeclare(PackageDescrBuilder pkg)declare := DECLARE | (ENTRY-POINT) => entryPointDeclaration | (WINDOW) => windowDeclaration | (TRAIT) => typeDeclaration (trait) | (ENUM) => enumDeclaration | typeDeclaration (class) ENDvoiddefaultConsequence(RuleDescrBuilder rule)defaultConsequence := THEN chunkEntryPointDeclarationDescrentryPointDeclaration(DeclareDescrBuilder ddb)entryPointDeclaration := annotation* ENTRY-POINT stringId ENDEnumDeclarationDescrenumDeclaration(DeclareDescrBuilder ddb)FunctionDescrfunction(PackageDescrBuilder pkg)function := FUNCTION type?protected StringgetConsequenceCode(int first)protected org.kie.internal.builder.conf.LanguageLevelOptiongetLanguageLevel()GlobalDescrglobalStatement(PackageDescrBuilder pkg)globalStatement := GLOBAL type IDImportDescrimportStatement(PackageDescrBuilder pkg)importStatement := IMPORT ((FUNCTION|STATIC)?protected BaseDescrlhsExists(CEDescrBuilder<?,?> ce, boolean allowOr)lhsExists := EXISTS ( (LEFT_PAREN (or_key|and_key))=> lhsOr // prevents '((' for prefixed and/or | LEFT_PAREN lhsOr RIGHT_PAREN | lhsPatternBind )protected BaseDescrlhsForall(CEDescrBuilder<?,?> ce)lhsForall := FORALL LEFT_PAREN lhsPatternBind+ RIGHT_PARENprotected BaseDescrlhsNot(CEDescrBuilder<?,?> ce, boolean allowOr)lhsNot := NOT ( (LEFT_PAREN (or_key|and_key))=> lhsOr // prevents '((' for prefixed and/or | LEFT_PAREN lhsOr RIGHT_PAREN | lhsPatternBind )booleanmismatchIsMissingToken(org.antlr.runtime.TokenStream input, int[] follow)booleanmismatchIsUnwantedToken(org.antlr.runtime.TokenStream input, int ttype, String text)voidnamedConsequence(RuleDescrBuilder rule)namedConsequence := THEN LEFT_SQUARE ID RIGHT_SQUARE chunkStringpackageStatement(PackageDescrBuilder pkg)Parses a package statement and returns the name of the package or null if none is defined.StringqualifiedIdentifier()Matches a qualified identifier qualifiedIdentifier := ID ( DOT ID )*RuleDescrquery(PackageDescrBuilder pkg)query := annotation* QUERY stringId parameters?protected org.antlr.runtime.TokenrecoverFromMismatchedToken(org.antlr.runtime.TokenStream input, int ttype, String text, int[] follow)Attempt to recover from a single missing or extra token.RuleDescrrule(PackageDescrBuilder pkg)rule := annotation* RULE stringId (EXTENDS stringId)?BaseDescrstatement(PackageDescrBuilder pkg)statement := importStatement | globalStatement | declare | rule | ruleAttribute | function | query ;Stringtype()Matches a type name type := ID typeArguments?StringtypeArgument()Matches a type argument typeArguments := QUESTION (( EXTENDS | SUPER ) type )?StringtypeArguments()Matches type arguments typeArguments := LESS typeArgument (COMMA typeArgument)* GREATERTypeDeclarationDescrtypeDeclaration(DeclareDescrBuilder ddb, boolean isTrait)typeDeclaration := annotation* [TYPE] qualifiedIdentifier (EXTENDS qualifiedIdentifier)?UnitDescrunitStatement(PackageDescrBuilder pkg)unitStatement := UNIT qualifiedIdentifier SEMICOLON?WindowDeclarationDescrwindowDeclaration(DeclareDescrBuilder ddb)windowDeclaration := annotation* WINDOW ID lhsPatternBind END-
Methods inherited from class org.drools.compiler.lang.AbstractDRLParser
compilationUnit, compilationUnit, disableEditorInterface, enableEditorInterface, getEditorInterface, getErrorMessages, getErrors, getHelper, hasErrors, reportError, reportError
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.drools.compiler.lang.DRLParser
compilationUnit, compilationUnit, disableEditorInterface, enableEditorInterface, getEditorInterface, getErrorMessages, getErrors, hasErrors, reportError, reportError
-
-
-
-
Method Detail
-
getLanguageLevel
protected org.kie.internal.builder.conf.LanguageLevelOption getLanguageLevel()
- Specified by:
getLanguageLevelin classAbstractDRLParser
-
compilationUnit
protected final PackageDescr compilationUnit(PackageDescrBuilder pkg) throws org.antlr.runtime.RecognitionException
- Specified by:
compilationUnitin classAbstractDRLParser- Throws:
org.antlr.runtime.RecognitionException
-
packageStatement
public String packageStatement(PackageDescrBuilder pkg) throws org.antlr.runtime.RecognitionException
Parses a package statement and returns the name of the package or null if none is defined. packageStatement := PACKAGE qualifiedIdentifier SEMICOLON?- Returns:
- the name of the package or null if none is defined
- Throws:
org.antlr.runtime.RecognitionException
-
unitStatement
public UnitDescr unitStatement(PackageDescrBuilder pkg) throws org.antlr.runtime.RecognitionException
unitStatement := UNIT qualifiedIdentifier SEMICOLON?- Throws:
org.antlr.runtime.RecognitionException
-
statement
public BaseDescr statement(PackageDescrBuilder pkg) throws org.antlr.runtime.RecognitionException
statement := importStatement | globalStatement | declare | rule | ruleAttribute | function | query ;- Throws:
org.antlr.runtime.RecognitionException
-
importStatement
public ImportDescr importStatement(PackageDescrBuilder pkg) throws org.antlr.runtime.RecognitionException
importStatement := IMPORT ((FUNCTION|STATIC)? qualifiedIdentifier ((DOT STAR)? |(ACC|ACCUMULATE) qualifiedIdentifier ID)- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
globalStatement
public GlobalDescr globalStatement(PackageDescrBuilder pkg) throws org.antlr.runtime.RecognitionException
globalStatement := GLOBAL type ID- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
declare
public BaseDescr declare(PackageDescrBuilder pkg) throws org.antlr.runtime.RecognitionException
declare := DECLARE | (ENTRY-POINT) => entryPointDeclaration | (WINDOW) => windowDeclaration | (TRAIT) => typeDeclaration (trait) | (ENUM) => enumDeclaration | typeDeclaration (class) END- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
entryPointDeclaration
public EntryPointDeclarationDescr entryPointDeclaration(DeclareDescrBuilder ddb) throws org.antlr.runtime.RecognitionException
entryPointDeclaration := annotation* ENTRY-POINT stringId END- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
windowDeclaration
public WindowDeclarationDescr windowDeclaration(DeclareDescrBuilder ddb) throws org.antlr.runtime.RecognitionException
windowDeclaration := annotation* WINDOW ID lhsPatternBind END- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
enumDeclaration
public EnumDeclarationDescr enumDeclaration(DeclareDescrBuilder ddb) throws org.antlr.runtime.RecognitionException
- Throws:
org.antlr.runtime.RecognitionException
-
typeDeclaration
public TypeDeclarationDescr typeDeclaration(DeclareDescrBuilder ddb, boolean isTrait) throws org.antlr.runtime.RecognitionException
typeDeclaration := annotation* [TYPE] qualifiedIdentifier (EXTENDS qualifiedIdentifier)? field* END- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
function
public FunctionDescr function(PackageDescrBuilder pkg) throws org.antlr.runtime.RecognitionException
function := FUNCTION type? ID parameters(typed) chunk_{_}- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
query
public RuleDescr query(PackageDescrBuilder pkg) throws org.antlr.runtime.RecognitionException
query := annotation* QUERY stringId parameters? lhsExpression END- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
rule
public RuleDescr rule(PackageDescrBuilder pkg) throws org.antlr.runtime.RecognitionException
rule := annotation* RULE stringId (EXTENDS stringId)? attributes? lhs? rhs END- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
attribute
public AttributeDescr attribute(AttributeSupportBuilder<?> as)
attribute := salience | enabled | ( NO-LOOP | AUTO-FOCUS | LOCK-ON-ACTIVE | REFRACT | DIRECT ) BOOLEAN? | ( AGENDA-GROUP | ACTIVATION-GROUP | RULEFLOW-GROUP | DATE-EFFECTIVE | DATE-EXPIRES | DIALECT ) STRING | CALENDARS STRING (COMMA STRING)* | TIMER ( DECIMAL | chunk_(_) ) | DURATION ( DECIMAL | chunk_(_) ) The above syntax is not quite how this is parsed, because the soft keyword is determined by look-ahead and passed on to one of the x-Attribute methods (booleanAttribute, stringAttribute, stringListAttribute, intOrChunkAttribute) which will actually gobble the tokens.- Returns:
-
lhsExists
protected BaseDescr lhsExists(CEDescrBuilder<?,?> ce, boolean allowOr) throws org.antlr.runtime.RecognitionException
lhsExists := EXISTS ( (LEFT_PAREN (or_key|and_key))=> lhsOr // prevents '((' for prefixed and/or | LEFT_PAREN lhsOr RIGHT_PAREN | lhsPatternBind )- Parameters:
ce-- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
lhsNot
protected BaseDescr lhsNot(CEDescrBuilder<?,?> ce, boolean allowOr) throws org.antlr.runtime.RecognitionException
lhsNot := NOT ( (LEFT_PAREN (or_key|and_key))=> lhsOr // prevents '((' for prefixed and/or | LEFT_PAREN lhsOr RIGHT_PAREN | lhsPatternBind )- Parameters:
ce-- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
lhsForall
protected BaseDescr lhsForall(CEDescrBuilder<?,?> ce) throws org.antlr.runtime.RecognitionException
lhsForall := FORALL LEFT_PAREN lhsPatternBind+ RIGHT_PAREN- Parameters:
ce-- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
defaultConsequence
public void defaultConsequence(RuleDescrBuilder rule)
defaultConsequence := THEN chunk- Parameters:
rule-
-
namedConsequence
public void namedConsequence(RuleDescrBuilder rule)
namedConsequence := THEN LEFT_SQUARE ID RIGHT_SQUARE chunk- Parameters:
rule-
-
getConsequenceCode
protected String getConsequenceCode(int first)
-
type
public String type() throws org.antlr.runtime.RecognitionException
Matches a type name type := ID typeArguments? ( DOT ID typeArguments? )* (LEFT_SQUARE RIGHT_SQUARE)*- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
typeArguments
public String typeArguments() throws org.antlr.runtime.RecognitionException
Matches type arguments typeArguments := LESS typeArgument (COMMA typeArgument)* GREATER- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
typeArgument
public String typeArgument() throws org.antlr.runtime.RecognitionException
Matches a type argument typeArguments := QUESTION (( EXTENDS | SUPER ) type )? | type ;- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
qualifiedIdentifier
public String qualifiedIdentifier() throws org.antlr.runtime.RecognitionException
Matches a qualified identifier qualifiedIdentifier := ID ( DOT ID )*- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
conditionalExpression
public String conditionalExpression() throws org.antlr.runtime.RecognitionException
Matches a conditional expression- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
conditionalOrExpression
public String conditionalOrExpression() throws org.antlr.runtime.RecognitionException
Matches a conditional || expression- Returns:
- Throws:
org.antlr.runtime.RecognitionException
-
chunk
public String chunk(int leftDelimiter, int rightDelimiter, int location)
Matches a chunk started by the leftDelimiter and ended by the rightDelimiter.
-
recoverFromMismatchedToken
protected org.antlr.runtime.Token recoverFromMismatchedToken(org.antlr.runtime.TokenStream input, int ttype, String text, int[] follow) throws org.antlr.runtime.RecognitionExceptionAttempt 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 ')'.- Throws:
org.antlr.runtime.RecognitionException
-
mismatchIsUnwantedToken
public boolean mismatchIsUnwantedToken(org.antlr.runtime.TokenStream input, int ttype, String text)
-
mismatchIsMissingToken
public boolean mismatchIsMissingToken(org.antlr.runtime.TokenStream input, int[] follow)
-
-