All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cassandraunit.shaded.org.antlr.codegen.templates.Python.Dbg.stg Maven / Gradle / Ivy

There is a newer version: 4.3.1.0
Show newest version
/*
 [The "BSD license"]
 Copyright (c) 2005-2009 Terence Parr
 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 Python output;
 *  If ASTs are built, then you'll also get ASTDbg.stg loaded.
 */

@outputFile.imports() ::= <<
<@super.imports()>
from antlr3.debug import *
>>

@genericParser.args() ::= <<
debug_socket = kwargs.pop('debug_socket', None)
port = kwargs.pop('port', None)
>>

@genericParser.init() ::= <<
self.ruleLevel = 0

if self._dbg is None:
    

>>

createListenerAndHandshake() ::= <<

proxy = DebugEventSocketProxy(self, adaptor=self.input.getTreeAdaptor(),
                              debug=debug_socket, port=port)<\n>

proxy = DebugEventSocketProxy(self, debug=debug_socket, port=port)<\n>

self.setDebugListener(proxy)
proxy.handshake()

>>

@genericParser.members() ::= <<

ruleNames = [
    "invalidRule", "}; wrap="\n    ", separator=", ">
    ]<\n>

decisionCanBacktrack = [
    False, # invalid decision
    TrueFalse}; wrap="\n    ", separator=", ">
    ]
 
def getRuleLevel(self):
    return self.ruleLevel

def incRuleLevel(self):
    self.ruleLevel += 1

def decRuleLevel(self):
    self.ruleLevel -= 1


    

    


 
def getRuleLevel(self):
    return }>.getRuleLevel()

def incRuleLevel(self):
    }>.incRuleLevel()

def decRuleLevel(self):
    }>.decRuleLevel()




FIXME(2)
public boolean alreadyParsedRule(IntStream input, int ruleIndex) {
    ((Profiler)self._dbg).examineRuleMemoization(input, ruleIndex, .ruleNames[ruleIndex]);
    return super.alreadyParsedRule(input, ruleIndex);
}<\n>
FIXME(3)
public void memoize(IntStream input,
                    int ruleIndex,
                    int ruleStartIndex)
{
    ((Profiler)self._dbg).memoize(input, ruleIndex, ruleStartIndex, .ruleNames[ruleIndex]);
    super.memoize(input, ruleIndex, ruleStartIndex);
}<\n>

def evalPredicate(self, result, predicate):
    self._dbg.semanticPredicate(result, predicate)
    return result
<\n>
>>

ctorForRootGrammar() ::= <<
 cut-n-paste instead !>

( input) {
    this(input, DebugEventSocketProxy.DEFAULT_DEBUGGER_PORT, new RecognizerSharedState());
}
public ( input, int port, RecognizerSharedState state) {
    super(input, state);
    
    
     = new (input, self._dbg, this.state, this}>);}; separator="\n">
    <@finally()>
}<\n>
!>
>>

ctorForProfilingRootGrammar() ::= <<
 cut-n-paste instead !>
public ( input) {
    this(input, new Profiler(null), new RecognizerSharedState());
}
public ( input, DebugEventListener self.dbg, RecognizerSharedState state) {
    super(input, self.dbg, state);
    Profiler p = (Profiler)self.dbg;
    p.setParser(this);
    
     = new (input, self.dbg, this.state, this}>);}; separator="\n">
    <@finally()>
}
<\n>
>>

/** Basically we don't want to set any dbg listeners are root will have it. */
ctorForDelegateGrammar() ::= <<
( input, DebugEventListener self.dbg, RecognizerSharedState state }>) {
    super(input, dbg, state);
    
     = new (input, this, this.state}>);}; separator="\n">
}<\n>
!>
>>

ctorForPredefinedListener() ::= <<
( input, DebugEventListener dbg) {
    <@superClassRef>super(input, dbg, new RecognizerSharedState());<@end>

    Profiler p = (Profiler)dbg;
    p.setParser(this);

    
     = new (input, self._dbg, this.state, this}>);}; separator="\n">
    <@finally()>
}<\n>
!>
>>

@genericParser.superClassName() ::= "Debug<@super.superClassName()>"

@rule.body() ::= <<
try:
    self._dbg.enterRule(self.getGrammarFileName(), "")
    if self.getRuleLevel() == 0:
        self._dbg.commence();
    self.incRuleLevel()
    
    self._dbg.location(, +1)

    <@super.body()>

    self._dbg.location(, +1)
finally:
    self._dbg.exitRule(self.getGrammarFileName(), "")
    self.decRuleLevel()
    if self.getRuleLevel() == 0:
         self._dbg.terminate()

>>

@synpred.start() ::= "self._dbg.beginBacktrack(self._state.backtracking)"

@synpred.stop() ::= "self._dbg.endBacktrack(self._state.backtracking, success)"

// Common debug event triggers used by region overrides below

enterSubRule() ::=
    "try { self._dbg.enterSubRule();<\n>"

exitSubRule() ::=
    "} finally {self._dbg.exitSubRule();}<\n>"

enterDecision() ::=
    "try { self._dbg.enterDecision();<\n>"

exitDecision() ::=
    "} finally {self._dbg.exitDecision();}<\n>"

enterAlt(n) ::= "self._dbg.enterAlt()<\n>"

// Region overrides that tell various constructs to add debugging triggers

@block.body() ::= <<
try:
    self._dbg.enterSubRule()
    <@super.body()>
finally:
    self._dbg.exitSubRule()
>>

@blockBody.decision() ::= <<
try:
    self._dbg.enterDecision(
        , self.decisionCanBacktrack[])
    <@super.decision()>
finally:
    self._dbg.exitDecision()
>>

@ruleBlock.decision() ::= <<
try:
    self._dbg.enterDecision(
        , self.decisionCanBacktrack[])
    <@super.decision()>
finally:
    self._dbg.exitDecision()
>>

@ruleBlockSingleAlt.prealt() ::= ""

@blockSingleAlt.prealt() ::= ""

@positiveClosureBlock.loopBody() ::= <<
try:
    self._dbg.enterSubRule()
    <@super.loopBody()>
finally:
    self._dbg.exitSubRule()<\n>
>>

@positiveClosureBlockLoop.decisionBody() ::= <<
try:
    self._dbg.enterDecision(
        , self.decisionCanBacktrack[])
    <@super.decisionBody()>
finally:
    self._dbg.exitDecision()
>>

@positiveClosureBlockLoop.earlyExitException() ::=
    "self._dbg.recognitionException(eee)<\n>"

@closureBlock.loopBody() ::= <<
try:
    self._dbg.enterSubRule()
    <@super.loopBody()>
finally:
    self._dbg.exitSubRule()<\n>
>>

@closureBlockLoop.decisionBody() ::= <<
try:
    self._dbg.enterDecision(
        , self.decisionCanBacktrack[])
    <@super.decisionBody()>
finally:
    self._dbg.exitDecision()
>>

@altSwitchCase.prealt() ::= ""

@element.prematch() ::=
    "self._dbg.location(, )"

@matchSet.mismatchedSetException() ::=
    "self._dbg.recognitionException(mse)"

@dfaState.noViableAltException() ::= "self._dbg.recognitionException(nvae)"

@dfaStateSwitch.noViableAltException() ::= "self._dbg.recognitionException(nvae)"

dfaDecision(decisionNumber,description) ::= <<
try:
    self.isCyclicDecision = True
    

except NoViableAltException, nvae:
    self._dbg.recognitionException(nvae)
    raise

>>

@cyclicDFA.errorMethod() ::= <<
def error(self, nvae):
    self._dbg.recognitionException(nvae)

>>

/** Force predicate validation to trigger an event */
evalPredicate(pred,description) ::= <<
self.evalPredicate(,"")
>>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy