HasTypedView but no HasTypedList

Posts   
 
    
jeffkararo
User
Posts: 76
Joined: 06-Jan-2004
# Posted on: 22-Jun-2005 19:57:04   

Are there any plans to add a HasTypedList token? I see the HasTypedView token but wanted to check if any Typed Lists exists before generating some code. Anyone know how I can check if any Typed Lists exists?

Thanks, Jeff

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 23-Jun-2005 11:47:44   

That token is absent. I can add it for you if you want. Perhaps a foreach over the typedlists also is sufficient in your situation?

Frans Bouma | Lead developer LLBLGen Pro
jeffkararo
User
Posts: 76
Joined: 06-Jan-2004
# Posted on: 23-Jun-2005 21:27:06   

That would be great. I appreciate your help.

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 24-Jun-2005 12:51:57   

Ok, I'll add it to the 1.0.2005.1 upgrade currently in development.

If you want to use it NOW, it's not hard to add it yourself, but I can do that for you, just let me know (it won't be in the code until 1.0.2005.1)

Frans Bouma | Lead developer LLBLGen Pro
jeffkararo
User
Posts: 76
Joined: 06-Jan-2004
# Posted on: 29-Jun-2005 23:51:22   

I can wait but out of curiosity what is the code fix that i can implement myself

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 30-Jun-2005 09:37:02   

jeffkararo wrote:

I can wait but out of curiosity what is the code fix that i can implement myself

Thanks

Not that hard simple_smile - in TDLParser, EnumsConstants.cs, to the Token enum, add HasTypedList, right above HasTypedView, and to the NonTerminalType enum, you add IfHasTypedListStart right above IfHasTypedViewStart. - in TDLParser, Parser.cs, first create the regex for the token: scroll down and add this line right above the HasTypedView line:


// 'HasTypedList'
_tokenDefinitions.Add(new TDLTokenDefinition((int)Token.HasTypedList, @"HasTypedList", RegexOptions.Compiled | RegexOptions.IgnoreCase));

  • in TDLParser, Parser.cs, go to the routine HandleIfStart(), and to the switch case statement, add:

case Token.HasTypedList:
    // pop it
    tokensInStatement.Add(_tokenStream.Dequeue());
    toReturn = new NonTerminal(NonTerminalType.IfHasTypedListStart);
    break;

The parser now recogizes the statement. We now have to add some code to the interpreter to get things done. - in TDLInterpreter, Interpreter.cs: go to InnerIfHandler, and add:


case NonTerminalType.IfHasTypedListStart:

to the switch/case statement - in TDLInterpreter, Interpreter.cs, go to HandleNonTerminal. Add to the if statements section of the switch/case statement:


case NonTerminalType.IfHasTypedListStart:
    HandleIfHasTypedListStart();
    break;

  • in TDLInterpreter, Interpreter.cs, go to HandleIfHasTypedViewStart and place below it a copy of that routine and alter it so it handles typed lists. I've altered it for you below:

/// <summary>
/// Handles an if start of type 'IfHasTypedListStart'. Will walk the statements between the start and IfEnd statement, if
/// the expression resolves to true, otherwise all statements are skipped. Will keep track of nested ifs when skipping the
/// inner if body.
/// </summary>
private void HandleIfHasTypedListStart()
{
    NonTerminal current = (NonTerminal)_parseTree[_nonTerminalIndex];

    // negate the expression if a NOT is present.
    bool negate = (((Token)((IToken)current.Tokens[2]).TokenID)==Token.Not);

    bool executeIfBody = ((_typedLists.Count > 0)^negate);

    if(executeIfBody)
    {
        // execute if statement
        _nonTerminalIndex++;
        InnerIfHandler();
    }
    else
    {
        // move current index to corresponding EndIf statement.
        _nonTerminalIndex = current.CorrespondingEndNTIndex;
    }
}

That's it simple_smile Recompile the parser and interpreter, then place the compiled versions in the taskperformers folder of LLBLGen Pro (backup the originals first), and restart llblgen pro to use your new parser/interpreter simple_smile

Frans Bouma | Lead developer LLBLGen Pro