Created
May 4, 2015 07:54
-
-
Save fge/45c7e4cce487f55c62cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package es.litesolutions.sonar.objectscript.ast.grammars; | |
import es.litesolutions.sonar.objectscript.ast.tokens.flowctl.FlowCtl; | |
import es.litesolutions.sonar.objectscript.ast.tokens.identifiers.Identifiers; | |
import es.litesolutions.sonar.objectscript.ast.tokens.operators.Symbols; | |
import org.sonar.sslr.grammar.GrammarRuleKey; | |
import org.sonar.sslr.grammar.LexerfulGrammarBuilder; | |
public enum FlowctlGrammar | |
implements GrammarRuleKey | |
{ | |
/* | |
* IF/ELSEIF/ELSE | |
*/ | |
IF_STATEMENT, | |
ELSEIF, | |
ELSE, | |
/* | |
* WHILE | |
*/ | |
WHILE_STATEMENT, | |
/* | |
* TRY/CATCH | |
*/ | |
TRYCATCH_STATEMENT, | |
TRYBLOCK, | |
CATCHARG, | |
CATCHBLOCK, | |
/* | |
* Flow control in general | |
*/ | |
FLOWCTL, | |
; | |
public static void injectInto(final LexerfulGrammarBuilder builder) | |
{ | |
builder.rule(ELSE).is( | |
FlowCtl.ELSE, | |
ObjectScriptGrammar.CODE_BLOCK | |
).skip(); | |
builder.rule(ELSEIF).is( | |
FlowCtl.ELSEIF, | |
ObjectScriptGrammar.BOOLEAN_EXPRESSION, | |
ObjectScriptGrammar.CODE_BLOCK | |
).skip(); | |
builder.rule(IF_STATEMENT).is(FlowCtl.IF, | |
ObjectScriptGrammar.BOOLEAN_EXPRESSION, | |
ObjectScriptGrammar.CODE_BLOCK, builder.zeroOrMore(ELSEIF), | |
builder.optional(ELSE)); | |
builder.rule(WHILE_STATEMENT).is( | |
FlowCtl.WHILE, | |
ObjectScriptGrammar.BOOLEAN_EXPRESSION, | |
ObjectScriptGrammar.CODE_BLOCK | |
); | |
builder.rule(TRYBLOCK).is(FlowCtl.TRY, ObjectScriptGrammar.CODE_BLOCK); | |
builder.rule(CATCHARG).is( | |
builder.firstOf( | |
builder.sequence( | |
Symbols.LPAREN, | |
Identifiers.LOCAL, | |
Symbols.RPAREN | |
), | |
Identifiers.LOCAL | |
) | |
); | |
builder.rule(CATCHBLOCK).is( | |
FlowCtl.CATCH, | |
CATCHARG, | |
ObjectScriptGrammar.CODE_BLOCK | |
); | |
builder.rule(TRYCATCH_STATEMENT).is(TRYBLOCK, CATCHBLOCK); | |
builder.rule(FLOWCTL).is( | |
builder.firstOf( | |
IF_STATEMENT, | |
WHILE_STATEMENT, | |
TRYCATCH_STATEMENT | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment