📄 java.stg
字号:
<else> int _type = <ruleName>; <ruleMemoization(name=ruleName)> <lexerRuleLabelDefs()> <ruleDescriptor.actions.init> <block> <ruleCleanUp()> this.type = _type; <(ruleDescriptor.actions.after):execAction()><endif> } finally { <if(trace)>traceOut("<ruleName>", <ruleDescriptor.index>);<endif> <memoize()> }}// $ANTLR end <ruleName>>>/** How to generate code for the implicitly-defined lexer grammar rule * that chooses between lexer rules. */tokensRule(ruleName,nakedBlock,args,block,ruleDescriptor) ::= <<public void mTokens() throws RecognitionException { <block><\n>}>>// S U B R U L E S/** A (...) subrule with multiple alternatives */block(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<// <fileName>:<description>int alt<decisionNumber>=<maxAlt>;<decls><@predecision()><decision><@postdecision()><@prebranch()>switch (alt<decisionNumber>) { <alts:altSwitchCase()>}<@postbranch()>>>/** A rule block with multiple alternatives */ruleBlock(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<// <fileName>:<description>int alt<decisionNumber>=<maxAlt>;<decls><@predecision()><decision><@postdecision()>switch (alt<decisionNumber>) { <alts:altSwitchCase()>}>>ruleBlockSingleAlt(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,description) ::= <<// <fileName>:<description><decls><@prealt()><alts><@postalt()>>>/** A special case of a (...) subrule with a single alternative */blockSingleAlt(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,description) ::= <<// <fileName>:<description><decls><@prealt()><alts><@postalt()>>>/** A (..)+ block with 1 or more alternatives */positiveClosureBlock(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<// <fileName>:<description>int cnt<decisionNumber>=0;<decls><@preloop()>loop<decisionNumber>:do { int alt<decisionNumber>=<maxAlt>; <@predecision()> <decision> <@postdecision()> switch (alt<decisionNumber>) { <alts:altSwitchCase()> default : if ( cnt<decisionNumber> >= 1 ) break loop<decisionNumber>; <ruleBacktrackFailure()> EarlyExitException eee = new EarlyExitException(<decisionNumber>, input); <@earlyExitException()> throw eee; } cnt<decisionNumber>++;} while (true);<@postloop()>>>positiveClosureBlockSingleAlt ::= positiveClosureBlock/** A (..)* block with 1 or more alternatives */closureBlock(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<// <fileName>:<description><decls><@preloop()>loop<decisionNumber>:do { int alt<decisionNumber>=<maxAlt>; <@predecision()> <decision> <@postdecision()> switch (alt<decisionNumber>) { <alts:altSwitchCase()> default : break loop<decisionNumber>; }} while (true);<@postloop()>>>closureBlockSingleAlt ::= closureBlock/** Optional blocks (x)? are translated to (x|) by before code generation * so we can just use the normal block template */optionalBlock ::= blockoptionalBlockSingleAlt ::= block/** A case in a switch that jumps to an alternative given the alternative * number. A DFA predicts the alternative and then a simple switch * does the jump to the code that actually matches that alternative. */altSwitchCase() ::= <<case <i> : <@prealt()> <it> break;<\n>>>/** An alternative is just a list of elements; at outermost level */alt(elements,altNum,description,autoAST,outerAlt) ::= <<// <fileName>:<description>{<@declarations()><elements:element()><@cleanup()>}>>// E L E M E N T S/** Dump the elements one per line */element() ::= <<<@prematch()><it.el><\n>>>/** match a token optionally with a label in front */tokenRef(token,label,elementIndex) ::= <<<if(label)><label>=(<labelType>)input.LT(1);<\n><endif>match(input,<token>,FOLLOW_<token>_in_<ruleName><elementIndex>); <checkRuleBacktrackFailure()>>>/** ids+=ID */tokenRefAndListLabel(token,label,elementIndex) ::= <<<tokenRef(...)><listLabel(elem=label,...)>>>listLabel(label,elem) ::= <<if (list_<label>==null) list_<label>=new ArrayList();list_<label>.add(<elem>);<\n>>>/** match a character */charRef(char,label) ::= <<<if(label)><label> = input.LA(1);<\n><endif>match(<char>); <checkRuleBacktrackFailure()>>>/** match a character range */charRangeRef(a,b,label) ::= <<<if(label)><label> = input.LA(1);<\n><endif>matchRange(<a>,<b>); <checkRuleBacktrackFailure()>>>/** For now, sets are interval tests and must be tested inline */matchSet(s,label,elementIndex,postmatchCode="") ::= <<<if(label)><if(LEXER)><label>= input.LA(1);<\n><else><label>=(<labelType>)input.LT(1);<\n><endif><endif>if ( <s> ) { input.consume(); <postmatchCode><if(!LEXER)> errorRecovery=false;<endif> <if(backtracking)>failed=false;<endif>}else { <ruleBacktrackFailure()> MismatchedSetException mse = new MismatchedSetException(null,input); <@mismatchedSetException()><if(LEXER)> recover(mse);<else> recoverFromMismatchedSet(input,mse,FOLLOW_set_in_<ruleName><elementIndex>);<endif> throw mse;}<\n>>>matchSetAndListLabel(s,label,elementIndex,postmatchCode) ::= <<<matchSet(...)><listLabel(elem=label,...)>>>/** Match a string literal */lexerStringRef(string,label) ::= <<<if(label)>int <label>Start = getCharIndex();match(<string>); <checkRuleBacktrackFailure()><labelType> <label> = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, <label>Start, getCharIndex()-1);<else>match(<string>); <checkRuleBacktrackFailure()><\n><endif>>>wildcard(label,elementIndex) ::= <<<if(label)><label>=(<labelType>)input.LT(1);<\n><endif>matchAny(input); <checkRuleBacktrackFailure()>>>wildcardAndListLabel(label,elementIndex) ::= <<<wildcard(...)><listLabel(elem=label,...)>>>/** Match . wildcard in lexer */wildcardChar(label, elementIndex) ::= <<<if(label)><label> = input.LA(1);<\n><endif>matchAny(); <checkRuleBacktrackFailure()>>>wildcardCharListLabel(label, elementIndex) ::= <<<wildcardChar(...)><listLabel(elem=label,...)>>>/** Match a rule reference by invoking it possibly with arguments * and a return value or values. */ruleRef(rule,label,elementIndex,args) ::= <<pushFollow(FOLLOW_<rule>_in_<ruleName><elementIndex>);<if(label)><label>=<rule>(<args; separator=", ">);<\n><else><rule>(<args; separator=", ">);<\n><endif>_fsp--;<checkRuleBacktrackFailure()>>>/** ids+=r */ruleRefAndListLabel(rule,label,elementIndex,args) ::= <<<ruleRef(...)><listLabel(elem=label,...)>>>/** A lexer rule reference */lexerRuleRef(rule,label,args,elementIndex) ::= <<<if(label)>int <label>Start<elementIndex> = getCharIndex();m<rule>(<args; separator=", ">); <checkRuleBacktrackFailure()><label> = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.DEFAULT_CHANNEL, <label>Start<elementIndex>, getCharIndex()-1);<else>m<rule>(<args; separator=", ">); <checkRuleBacktrackFailure()><endif>>>/** i+=INT in lexer */lexerRuleRefAndListLabel(rule,label,args,elementIndex) ::= <<<lexerRuleRef(...)><listLabel(elem=label,...)>>>/** EOF in the lexer */lexerMatchEOF(label,elementIndex) ::= <<<if(label)>int <label>Start<elementIndex> = getCharIndex();match(EOF); <checkRuleBacktrackFailure()><labelType> <label> = new CommonToken(input, EOF, Token.DEFAULT_CHANNEL, <label>Start<elementIndex>, getCharIndex()-1);<else>match(EOF); <checkRuleBacktrackFailure()><endif>>>/** match ^(root children) in tree parser */tree(root, actionsAfterRoot, children, nullableChildList) ::= <<<root:element()><actionsAfterRoot:element()><if(nullableChildList)>if ( input.LA(1)==Token.DOWN ) { match(input, Token.DOWN, null); <checkRuleBacktrackFailure()> <children:element()> match(input, Token.UP, null); <checkRuleBacktrackFailure()>}<else>match(input, Token.DOWN, null); <checkRuleBacktrackFailure()><children:element()>match(input, Token.UP, null); <checkRuleBacktrackFailure()><endif>>>/** Every predicate is used as a validating predicate (even when it is * also hoisted into a prediction expression). */validateSemanticPredicate(pred,description) ::= <<if ( !(<evalPredicate(...)>) ) { <ruleBacktrackFailure()> throw new FailedPredicateException(input, "<ruleName>", "<description>");}>>// F i x e d D F A (if-then-else)dfaState(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<int LA<decisionNumber>_<stateNumber> = input.LA(<k>);<\n><edges; separator="\nelse ">else {<if(eotPredictsAlt)> alt<decisionNumber>=<eotPredictsAlt>;<else> <ruleBacktrackFailure()> NoViableAltException nvae = new NoViableAltException("<description>", <decisionNumber>, <stateNumber>, input);<\n> <@noViableAltException()> throw nvae;<\n><endif>}>>/** Same as a normal DFA state except that we don't examine lookahead * for the bypass alternative. It delays error detection but this * is faster, smaller, and more what people expect. For (X)? people * expect "if ( LA(1)==X ) match(X);" and that's it. */dfaOptionalBlockState(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<int LA<decisionNumber>_<stateNumber> = input.LA(<k>);<\n><edges; separator="\nelse ">>>/** A DFA state that is actually the loopback decision of a closure * loop. If end-of-token (EOT) predicts any of the targets then it * should act like a default clause (i.e., no error can be generated). * This is used only in the lexer so that for ('a')* on the end of a rule * anything other than 'a' predicts exiting. */dfaLoopbackState(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<int LA<decisionNumber>_<stateNumber> = input.LA(<k>);<\n><edges; separator="\nelse "><\n><if(eotPredictsAlt)><if(!edges)>alt<decisionNumber>=<eotPredictsAlt>; <! if no edges, don't gen ELSE !><else>else { alt<decisionNumber>=<eotPredictsAlt>;}<\n><endif><endif>>>/** An accept state indicates a unique alternative has been predicted */dfaAcceptState(alt) ::= "alt<decisionNumber>=<alt>;"/** A simple edge with an expression. If the expression is satisfied, * enter to the target state. To handle gated productions, we may * have to evaluate some predicates for this edge. */dfaEdge(labelExpr, targetState, predicates) ::= <<if ( (<labelExpr>) <if(predicates)>&& (<predicates>)<endif>) { <targetState>}>>// F i x e d D F A (switch case)/** A DFA state where a SWITCH may be generated. The code generator * decides if this is possible: CodeGenerator.canGenerateSwitch(). */dfaStateSwitch(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<switch ( input.LA(<k>) ) {<edges; separator="\n">default:<if(eotPredictsAlt)> alt<decisionNumber>=<eotPredictsAlt>;<else>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -