microsoft / SqlScriptDOM

ScriptDOM/SqlDOM is a .NET library for parsing T-SQL statements and interacting with its abstract syntax tree
MIT License
133 stars 16 forks source link

EndConversationStatement object has wrong FirstTokenIndex value #90

Open IVNSTN opened 3 weeks ago

IVNSTN commented 3 weeks ago

ScriptDom version: 161.9123 Parser compatibility level: 150

Code example

END CONVERSATION @handle;

Actually, I noticed it on a longer IF-ELSE-END CONVERSATION piece of code, but here is the problem: FirstTokenIndex points not to END keyword but to @handle variable reference which is wrong. On screenshot below FirstTokenIndex should be 178, not 182.

image

LastTokenIndex points here to semicolon position which is correct.

vemoo commented 2 weeks ago

I think the issue is that

https://github.com/microsoft/SqlScriptDOM/blob/d84cc30809b29cc5497809c2b0432bf23c412c69/SqlScriptDom/Parser/TSql/TSql90.g#L13602-L13612

is missing a UpdateTokenInfo for End and vResult.

it should be:

endConversationStatement returns [EndConversationStatement vResult = FragmentFactory.CreateFragment<EndConversationStatement>()]
{
    ScalarExpression vConv;
}
    : tEnd:End tConversation:Identifier vConv = expression 
        {
            UpdateTokenInfo(vResult,tEnd);
            Match(tConversation,CodeGenerationSupporter.Conversation);
            vResult.Conversation = vConv;
        }
        endConversationArgumentsOpt[vResult]
    ;

It's a similar issue to #91, and from looking at the grammar files I feel it probably happens in a few other places.