📄 objc.stg
字号:
* 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> { <ruleBacktrackFailure()> ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException exceptionWithDecision:<decisionNumber> state:<stateNumber> stream:input]; <@noViableAltException()> @throw nvae;<\n> }<endif>}>>dfaOptionalBlockStateSwitch(k,edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<switch ([input LA:<k>]) { <edges; separator="\n">}<\n>>>dfaLoopbackStateSwitch(k, edges,eotPredictsAlt,description,stateNumber,semPredState) ::= <<switch ([input LA:<k>]) { <edges; separator="\n"><if(eotPredictsAlt)>default: alt<decisionNumber> = <eotPredictsAlt> break;<\n><endif>}<\n>>>dfaEdgeSwitch(labels, targetState) ::= <<<labels:{case <it>:}; separator="\n"> <targetState> break;>>// C y c l i c D F A/** The code to initiate execution of a cyclic DFA; this is used * in the rule to predict an alt just like the fixed DFA case. * The <name> attribute is inherited via the parser, lexer, ... */dfaDecision(decisionNumber,description) ::= <<alt<decisionNumber> = [dfa<decisionNumber> predict];>>/** Used in headerFile */cyclicDFAInterface(dfa) ::= <<@interface <name>DFA<dfa.decisionNumber> : ANTLRDFA {} @end<\n>>>/** Used in lexer/parser implementation files */cyclicDFA(dfa) ::= <<@implementation <name>DFA<dfa.decisionNumber>const static int <name>dfa<dfa.decisionNumber>_eot[<dfa.numberOfStates>] = {<dfa.eot; wrap="\n ", separator=",", null="-1">};const static int <name>dfa<dfa.decisionNumber>_eof[<dfa.numberOfStates>] = {<dfa.eof; wrap="\n ", separator=",", null="-1">};const static unichar <name>dfa<dfa.decisionNumber>_min[<dfa.numberOfStates>] = {<dfa.min; wrap="\n ", separator=",", null="0">};const static unichar <name>dfa<dfa.decisionNumber>_max[<dfa.numberOfStates>] = {<dfa.max; wrap="\n ", separator=",", null="0">};const static int <name>dfa<dfa.decisionNumber>_accept[<dfa.numberOfStates>] = {<dfa.accept; wrap="\n ", separator=",", null="-1">};const static int <name>dfa<dfa.decisionNumber>_special[<dfa.numberOfStates>] = {<dfa.special; wrap="\n ", separator=",", null="-1">};const static int <name>dfa<dfa.decisionNumber>_transition[] = {};<dfa.edgeTransitionClassMap.keys:{ table |const static int <name>dfa<dfa.decisionNumber>_transition<i0>[] = {<table; separator=", ", wrap="\n ", null="-1">};}; null="">- (id) initWithRecognizer:(ANTLRBaseRecognizer *) theRecognizer{ if ((self = [super initWithRecognizer:theRecognizer]) != nil) { eot = <name>dfa<dfa.decisionNumber>_eot; eof = <name>dfa<dfa.decisionNumber>_eof; min = <name>dfa<dfa.decisionNumber>_min; max = <name>dfa<dfa.decisionNumber>_max; accept = <name>dfa<dfa.decisionNumber>_accept; special = <name>dfa<dfa.decisionNumber>_special; if (!(transition = calloc(<dfa.numberOfStates>, sizeof(void*)))) { [self release]; return nil; } <dfa.transitionEdgeTables:{whichTable|transition[<i0>] = <name>dfa<dfa.decisionNumber>_transition<whichTable>;}; separator="\n", null=""> } return self;}<if(dfa.specialStateSTs)>- (int) specialStateTransition:(int) s{ int _s = s; switch ( s ) { <dfa.specialStateSTs:{state | case <i0> : <! compressed special state numbers 0..n-1 !> <state>}; separator="\n"> }<if(backtracking)> if ([recognizer isBacktracking]) { [recognizer setIsFailed:YES]; return -1; }<\n><endif> ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException exceptionWithDecision:<dfa.decisionNumber> state:_s stream:[recognizer input]]; <! [self error:nvae]; !> <! for debugger - do later !> @throw nvae;}<\n><endif>- (void) dealloc{ free(transition); [super dealloc];}- (NSString *) description{ return @"<dfa.description>";}<@errorMethod()>@end<\n>>>cyclicDFAState(decisionNumber, stateNumber,edges,needErrorClause,semPredState) ::= <<<if(semPredState)>[[recognizer input] rewind];<\n><else>int LA<decisionNumber>_<stateNumber> = [input LA:1];<\n><endif>s = -1;<edges; separator="\nelse ">if ( s>=0 ) return s;break;>>/** Just like a fixed DFA edge, test the lookahead and indicate what * state to jump to next if successful. */cyclicDFAEdge(labelExpr, targetStateNumber, edgeNumber, predicates) ::= <<if ( (<labelExpr>) <if(predicates)>&& (<predicates>)<endif>) {s = <targetStateNumber>;}<\n>>>/** An edge pointing at end-of-token; essentially matches any char; * always jump to the target. */eotDFAEdge(targetStateNumber,edgeNumber, predicates) ::= <<s = <targetStateNumber>;<\n>>>// D F A E X P R E S S I O N SandPredicates(left,right) ::= "(<left>&&<right>)"orPredicates(operands) ::= "(first(operands)<rest(operands):{o | ||<o>}>)"notPredicate(pred) ::= "!(<evalPredicate(...)>)"evalPredicate(pred,description) ::= "<pred>"/** synpreds are b0rken in cyclic DFA special states * Damn! For now, work around with using the selectors directly, and by providing a trampoline evalSynPred method in * ANTLRDFA *//* evalSynPredicate(pred,description) ::= "[self evaluateSyntacticPredicate:<pred>SyntacticPredicate stream:input]" */evalSynPredicate(pred,description) ::= "[self evaluateSyntacticPredicate:@selector(<pred>)]"lookaheadTest(atom,k,atomAsInt) ::= "LA<decisionNumber>_<stateNumber>==<atom>"/** Sometimes a lookahead test cannot assume that LA(k) is in a temp variable * somewhere. Must ask for the lookahead directly. */isolatedLookaheadTest(atom,k,atomAsInt) ::= "[input LA:<k>]==<atom>"lookaheadRangeTest(lower,upper,k,rangeNumber,lowerAsInt,upperAsInt) ::= <<(LA<decisionNumber>_<stateNumber>\>=<lower> && LA<decisionNumber>_<stateNumber>\<=<upper>)>>isolatedLookaheadRangeTest(lower,upper,k,rangeNumber,lowerAsInt,upperAsInt) ::= "([input LA:<k>]\>=<lower> && [input LA:<k>]\<=<upper>)"setTest(ranges) ::= "<ranges; separator=\"||\">"// A T T R I B U T E SglobalAttributeScopeDecl(scope) ::= <<@interface <name><scope.name>Scope : NSObject { <scope.attributes:{<it.decl>;}; separator="\n">}// use KVC to access attributes!@end>>globalAttributeScopeIVar(scope) ::= <<NSMutableArray *<name>_<scope.name>_stack;>>globalAttributeScopeImpl(scope) ::= <<@implementation <name><scope.name>Scope@end>>globalAttributeScopeInit(scope) ::= <<<name>_<scope.name>_stack = [[NSMutableArray alloc] init];>>globalAttributeScopeDealloc(scope) ::= <<[<name>_<scope.name>_stack release];>>ruleAttributeScopeDecl(scope) ::= <<<if(scope.attributes)>@interface <name><scope.name>Scope : NSObject { <scope.attributes:{<it.decl>;}; separator="\n">}// use KVC to access attributes!@end<endif>>>ruleAttributeScopeIVar(scope) ::= <<NSMutableArray *<name>_<scope.name>_stack;>>ruleAttributeScopeImpl(scope) ::= <<<if(scope.attributes)>@implementation <name><scope.name>Scope@end<endif>>>ruleAttributeScopeInit(scope) ::= <<<name>_<scope.name>_stack = [[NSMutableArray alloc] init];>>ruleAttributeScopeDealloc(scope) ::= <<[<name>_<scope.name>_stack release];>>returnTypeName() ::= <<<if(!ruleDescriptor.isSynPred)><if(ruleDescriptor.hasMultipleReturnValues)><className()>_<ruleDescriptor.name>_return<else><if(ruleDescriptor.hasSingleReturnValue)><ruleDescriptor.singleValueReturnType><else>void<endif><endif><else>void<! for synpreds this is always void !><endif>>>returnType() ::= <<<returnTypeName()><if(!ruleDescriptor.isSynPred)><if(ruleDescriptor.hasMultipleReturnValues)> *<endif><endif>>>/** Generate the Objective-C type associated with a single or multiple return * values. */ruleLabelType(referencedRule) ::= <<<if(referencedRule.hasMultipleReturnValues)><className()>_<referencedRule.name>_return *<else><if(referencedRule.hasSingleReturnValue)><referencedRule.singleValueReturnType><else>void<endif><endif>>>/** Using a type to init value map, try to init a type; if not in table * must be an object, default value is "null". */initValue(typeName) ::= <<<objcTypeInitMap.(typeName)>>>/** Define a rule label including default value */ruleLabelDef(label) ::= <<<ruleLabelType(referencedRule=label.referencedRule)> _<label.label.text> = <initValue(typeName=ruleLabelType(referencedRule=label.referencedRule))>;<\n>>>/** Define a return struct for a rule if the code needs to access its * start/stop tokens, tree stuff, attributes, ... Leave a hole for * subgroups to stick in members. */returnScopeInterface(ruleDescriptor) ::= <<<if(!ruleDescriptor.isSynPred)><if(ruleDescriptor.hasMultipleReturnValues)>@interface <returnTypeName()> : ANTLR<if(TREE_PARSER)>Tree<endif>ParserRuleReturnScope { <ruleDescriptor.returnScope.attributes:{<it.decl>;}; separator="\n"> <@ivars()>}<@methods()>@end<endif><endif>>>returnScope(ruleDescriptor) ::= <<<if(!ruleDescriptor.isSynPred)><if(ruleDescriptor.hasMultipleReturnValues)>@implementation <returnTypeName()><@methods()>@end<endif><endif>>>parameterScope(scope) ::= <<<scope.attributes:{:(<it.type>)<it.name>}; separator=" ">>>parameterAttributeRef(attr) ::= "<attr.name>"parameterSetAttributeRef(attr,expr) ::= "<attr.name> =<expr>;"scopeAttributeRef(scope,attr,index,negIndex) ::= <<[<scopeAttributeRefStack()> valueForKey:@"<attr.name>"]>>scopeSetAttributeRef(scope,attr,expr,index,negIndex) ::= <<[<scopeAttributeRefStack()> setValue:<expr> forKey:@"<attr.name>"];>>scopeAttributeRefStack() ::= <<<if(negIndex)>[<name>_<scope>_stack objectAtIndex:[<name>_<scope>_stack count]-<negIndex>-1]<else><if(index)>[<name>_<scope>_stack objectAtIndex:<index>]<else>[<name>_<scope>_stack lastObject]<endif><endif>>>/** $x is either global scope or x is rule with dynamic scope; refers * to stack itself not top of stack. This is useful for predicates * like {$function.size()>0 && $function::name.equals("foo")}? */isolatedDynamicScopeRef(scope) ::= "<name>_<scope>_stack"/** reference an attribute of rule; might only have single return value */ruleLabelRef(referencedRule,scope,attr) ::= <<<if(referencedRule.hasMultipleReturnValues)>[<scope> valueForKey:@"<attr.name>"]<else>_<scope><endif>>>returnAttributeRef(ruleDescriptor,attr) ::= <<<if(ruleDescriptor.hasMultipleReturnValues)>[_retval setValue: forKey:@"<attr.name>"];<else>_<attr.name><endif>>>returnSetAttributeRef(ruleDescriptor,attr,expr) ::= <<<if(ruleDescriptor.hasMultipleReturnValues)>[_retval setValue:<expr> forKey:@"<attr.name>"];<else>_<attr.name> =<expr>;// double check this after beta release![_<attr.name> retain];<endif>>>/** How to translate $tokenLabel */tokenLabelRef(label) ::= "_<label>"/** ids+=ID {$ids} or e+=expr {$e} */listLabelRef(label) ::= "_list_<label>"// not sure the next are the right approach; and they are evaluated early;// they cannot see TREE_PARSER or PARSER attributes for example. :(tokenLabelPropertyRef_text(scope,attr) ::= "[_<scope> text]"tokenLabelPropertyRef_type(scope,attr) ::= "[_<scope> type]"tokenLabelPropertyRef_line(scope,attr) ::= "[_<scope> line]"tokenLabelPropertyRef_pos(scope,attr) ::= "[_<scope> charPositionInLine]"tokenLabelPropertyRef_channel(scope,attr) ::= "[_<scope> channel]"tokenLabelPropertyRef_index(scope,attr) ::= "[_<scope> tokenIndex]"tokenLabelPropertyRef_tree(scope,attr) ::= "_<scope>_tree"ruleLabelPropertyRef_start(scope,attr) ::= "[_<scope> start]"ruleLabelPropertyRef_stop(scope,attr) ::= "[_<scope> stop]"ruleLabelPropertyRef_tree(scope,attr) ::= "[_<scope> tree]"ruleLabelPropertyRef_text(scope,attr) ::= "[input substringWithRange:NSMakeRange([_<scope> start], [_<scope> stop]-[_<scope> start])]"ruleLabelPropertyRef_st(scope,attr) ::= "[_<scope> st]"/** Isolated $RULE ref ok in lexer as it's a Token */lexerRuleLabel(label) ::= "_<label>"lexerRuleLabelPropertyRef_type(scope,attr) ::= "[_<scope> type]"lexerRuleLabelPropertyRef_line(scope,attr) ::= "[_<scope> line]"lexerRuleLabelPropertyRef_pos(scope,attr) ::= "[_<scope> charPositionInLine]"lexerRuleLabelPropertyRef_channel(scope,attr) ::= "[_<scope> channel]"lexerRuleLabelPropertyRef_index(scope,attr) ::= "[_<scope> tokenIndex]"lexerRuleLabelPropertyRef_text(scope,attr) ::= "[_<scope> text]"// Somebody may ref $template or $tree or $stop within a rule:rulePropertyRef_start(scope,attr) ::= "[_retval start]"rulePropertyRef_stop(scope,attr) ::= "[_retval stop]"rulePropertyRef_tree(scope,attr) ::= "[_retval tree]"rulePropertyRef_text(scope,attr) ::= "[input substringWithRange:NSMakeRange(_start, [input index]-_start)]"rulePropertyRef_st(scope,attr) ::= "[_retval st]"ruleSetPropertyRef_tree(scope,attr,expr) ::= "[_retval setValue:<expr> forKey:@\"tree\"]"ruleSetPropertyRef_st(scope,attr,expr) ::= "<\n>#error StringTemplates are unsupported<\n>"lexerRulePropertyRef_text(scope,attr) ::= "[self text]"lexerRulePropertyRef_type(scope,attr) ::= "_type"lexerRulePropertyRef_line(scope,attr) ::= "_line"lexerRulePropertyRef_pos(scope,attr) ::= "_charPosition"lexerRulePropertyRef_index(scope,attr) ::= "-1" // undefined token index in lexerlexerRulePropertyRef_channel(scope,attr) ::= "_channel"/** How to execute an action */execAction(action) ::= <<<if(backtracking)><if(actions.(actionScope).synpredgate)>if ( <actions.(actionScope).synpredgate> ) { <action>}<else>if ( backtracking==0 ) { <action>}<endif><else><action><endif>>>// L E X E R A C T I O N Semit(type) ::= "[self emit:<type>];"setType(type) ::= "[self setType:<type>];"// M I S C (properties, etc...)bitset(name, words64) ::= <<const static unsigned long long <name>_data[] = {<words64:{<it>LL};separator=",">};static ANTLRBitSet *<name>;<! ANTLRBitSet *<name> = [[ANTLRBitSet alloc] initWithBits:<name>_data count:<length(words64)>];<\n> !>>>bitsetInit(name, words64) ::= <<<name> = [[ANTLRBitSet alloc] initWithBits:<name>_data count:<length(words64)>];<\n>>>codeFileExtension() ::= ".m"true() ::= "YES"false() ::= "NO"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -