org.antlr.codegen.templates.ObjC.Dbg.stg Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of antlr-complete Show documentation
Show all versions of antlr-complete Show documentation
Complete distribution for ANTLR 3
/*
[The "BSD license"]
Copyright (c) 2006 Kay Roepke 2010 Alan Condit
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** Template overrides to add debugging to normal Objective-C output;
* If ASTs are built, then you'll also get ASTDbg.stg loaded.
*/
@headerFile.imports() ::= <<
<@super.imports()>
#import \
>>
@parserHeaderFile.memVars() ::= <<
NSInteger ruleLevel;
NSArray *ruleNames;
>>
@parserHeaderFile.methodsDecl() ::= <<
-(BOOL) evalPredicate:(NSString *)predicate matched:(BOOL)result;<\n>
>>
@genericParser.methods() ::= <<
AMutableArray *ruleNames = [AMutableArray arrayWithArray:{
@"invalidRule", "}; wrap=@"\n ", separator=", ">
};<\n>
ruleLevel = 0;
- (NSInteger) getRuleLevel { return ruleLevel; }
- (void) incRuleLevel { ruleLevel++; }
- (void) decRuleLevel { ruleLevel--; }
- (NSInteger) getRuleLevel
{
return }>.getRuleLevel();
}<\n>
- (void) incRuleLevel
{
}>.incRuleLevel();
}<\n>
- (void) decRuleLevel
{
}>.decRuleLevel();
}<\n>
- (BOOL) alreadyParsedRule:(id) input Index:(NSInteger) ruleIndex
{
[(Profiler)dbg examineRuleMemoization:input, ruleIndex, .ruleNames objectAtIndex:ruleIndex];
return super.alreadyParsedRule(input, ruleIndex);
}<\n>
- (void) memoize:(id)input RuleIndex:(NSInteger)ruleIndex StartIndex:(NSInteger)ruleStartIndex
{
[((Profiler)dbg) memoize:input RuleIndex:ruleIndex StartIndex:ruleStartIndex [ ruleNames[ruleIndex]];
[super memoize:input RuleIndex:ruleIndex StartIndex:ruleStartIndex];
}<\n>
- (BOOL) evalPredicate:(BOOL)result Pred:(NSString *)predicate
{
[dbg semanticPredicate:result Pred:predicate];
return result;
}<\n>
>>
@genericParser.init() ::= <<
ruleNames = [NSArray arrayWithObjects:"}; separator=", ", wrap="\n ">, nil];<\n>
>>
@genericParser.dealloc() ::= <<
[ruleNames release];<\n>
>>
@genericParser.methods() ::= <<
-(BOOL) evalPredicate:(NSString *)predicate matched:(BOOL)result
{
[debugListener semanticPredicate:predicate matched:result];
return result;
}<\n>
>>
/* bug: can't use @super.superClassName()> */
@parserHeaderFile.superClassName() ::= "DebugTreeParser"
@rule.preamble() ::= <<
@try { [debugListener enterRule:@""];
if ( ruleLevel==0 ) [debugListener commence];
ruleLevel++;
[debugListener locationLine: column:];<\n>
>>
@rule.postamble() ::= <<
[debugListener locationLine: column:];<\n>
}
@finally {
[debugListener exitRule:@""];
ruleLevel--;
if ( ruleLevel==0 ) [debugListener terminate];
}<\n>
>>
/* these are handled in the runtime for now.
* stinks, but that's the easiest way to avoid having to generate two
* methods for each synpred
@synpred.start() ::= "[debugListener beginBacktrack:state.backtracking];"
@synpred.stop() ::= "[debugListener endBacktrack:state.backtracking wasSuccessful:success];"
*/
// Common debug event triggers used by region overrides below
enterSubRule() ::=
"@try { [debugListener enterSubRule:];<\n>"
exitSubRule() ::=
"} @finally { [debugListener exitSubRule:]; }<\n>"
enterDecision() ::=
"@try { [debugListener enterDecision:];<\n>"
exitDecision() ::=
"} @finally { [debugListener exitDecision:]; }<\n>"
enterAlt(n) ::= "[debugListener enterAlt:];<\n>"
// Region overrides that tell various constructs to add debugging triggers
@block.predecision() ::= ""
@block.postdecision() ::= ""
@block.postbranch() ::= ""
@ruleBlock.predecision() ::= ""
@ruleBlock.postdecision() ::= ""
@ruleBlockSingleAlt.prealt() ::= ""
@blockSingleAlt.prealt() ::= ""
@positiveClosureBlock.preloop() ::= ""
@positiveClosureBlock.postloop() ::= ""
@positiveClosureBlock.predecision() ::= ""
@positiveClosureBlock.postdecision() ::= ""
@positiveClosureBlock.earlyExitException() ::=
"[debugListener recognitionException:eee];<\n>"
@closureBlock.preloop() ::= ""
@closureBlock.postloop() ::= ""
@closureBlock.predecision() ::= ""
@closureBlock.postdecision() ::= ""
@altSwitchCase.prealt() ::= ""
@element.prematch() ::=
"[debugListener locationLine: column:];"
@matchSet.mismatchedSetException() ::=
"[debugListener recognitionException:mse];"
@dfaState.noViableAltException() ::= "[debugListener recognitionException:nvae];"
@dfaStateSwitch.noViableAltException() ::= "[debugListener recognitionException:nvae];"
dfaDecision(decisionNumber,description) ::= <<
@try {
// isCyclicDecision is only necessary for the Profiler. Which I didn't do, yet.
// isCyclicDecision = YES;
}
@catch (NoViableAltException *nvae) {
[debugListener recognitionException:nvae];
@throw nvae;
}
>>
@cyclicDFA.errorMethod() ::= <<
-(void) error:(NoViableAltException *)nvae
{
[[recognizer debugListener] recognitionException:nvae];
}
>>
/** Force predicate validation to trigger an event */
evalPredicate(pred,description) ::= <<
[self evalPredicate:@"" result:];
>>
© 2015 - 2024 Weber Informatics LLC | Privacy Policy