Semantic parsing in MergableSyntaxLanguage

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Nik Verkhovtseff
Version: 4.0.0234
Avatar
Hi,

Could you please describe an approximate scenario for semantic parsing of child language in MergableSyntaxLanguage? After invocation of PerformSemanticParse for root language, PerformSemanticParse for child language is invoked only one time - for first child language block.

Thanks,
Nik

Comments (9)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nik,

I'm not sure exactly what you are asking. Could you give some more detail? Thanks!


Actipro Software Support

Posted 13 years ago by Nik Verkhovtseff
Avatar
Hi,

I merge two languages: a root language is derived from DynamicSyntaxLanguage (HTML) and child language derived from CSharpSyntaxLanguage. I write a primitive semantic parsers for both languages and override the PerformSemanticParse(MergableLexicalParserManager manager) methods on both classes.

protected override object PerformSemanticParse(MergableLexicalParserManager manager)
{
 MyRecursiveDescentLexicalParser lexicalParser = new MyRecursiveDescentLexicalParser(this, manager);
 lexicalParser.InitializeTokens();
 MySemanticParser semanticParser = new MySemanticParser(lexicalParser);
            
 semanticParser.Parse();
 return semanticParser.CompilationUnit;
}
When I print a text in SyntaxEditor:

<html>
<body>

<%
int a = 0;
%>

<%
 a = a + 1;
%>

</body>
</html>

method PerformSemanticParse of CSharpSyntaxLanguage derived class is not called.

How should I invoke semantic parsing for child language (C#)?


Thanks,
Nik
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hmm... it looks like you are doing it correctly. Could you throw together a tiny project that shows this and email the ZIP of it over so we can have a look?


Actipro Software Support

Posted 13 years ago by Nik Verkhovtseff
Avatar
Hi,

I was wrong - PerformSemanticParse for child language is called! - I've found a error in my code.

But I got another issues:

1. If the first token in document text is ASPDirectiveStartToken (i.e. <% - direct lexical state transition to child language) PerformSemanticParse for child language isn't called. When I change GetNextTokenCore() in LexicalParser for root language to:

protected override IToken GetNextTokenCore()
{
    int startOffset = this.TextBufferReader.Offset;

    while (!this.IsAtEnd)
    {
        // Get the next token
        IToken token = this.Manager.GetNextToken();

        if (token.HasFlag(LexicalParseFlags.LanguageStart))
        {
            return this.Manager.ProcessChildLanguage(token);
        }
        
        return token;
    }

    // Return an end of document token
    if (this.Token != null)
        return this.Language.CreateDocumentEndToken(startOffset, this.Token.LexicalState);
    else
        return this.Language.CreateDocumentEndToken(startOffset, this.Language.DefaultLexicalState);
}
PerformSemanticParse for child language is called! Am I right to do a such trick or it's a bug?

2. When I parse a text like this:

<html>
<body>

<%
if(someCondition)
{
%>

<%
}
%>

</body>
</html>
PerformSemanticParse for child language is called 2 times. In first C# block I got a syntax error, since *If* block has no close brace. Does any workaround exist to parse all child language blocks one time as one block?


Thanks,
Nik
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nik,

Thanks, I'll mark #1 as a bug.

For #2, SyntaxEditor is performing as it is currently designed and parses each block independently. We do have plans to make enhancements for other child language support options in the future that would handle your situation better and "merge" all the code in the child language before parsing it.


Actipro Software Support

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
#1 is fixed for the next maintenance release.


Actipro Software Support

Posted 13 years ago by Nik Verkhovtseff
Avatar
Hi,

It will be a nice enhancement - to "merge" all child blocks into one. As it's not implemented yet, could you give me any suggestion how can I to parse all child language blocks one time as one block. I guess that it should be some trick with MergableRecursiveDescentLexicalParser or MergableLexicalParserManager.

Thanks,
Nik
Posted 13 years ago by Justin Stenning - Manager, Research & Development, netcat.biz Pty Ltd
Avatar
Hi,

I also think it would be a nice enhancement and have a use for it.

Cheers,
J
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Unfortunately I don't believe there is a way for you to plug into the mergable manager right now so that you can manipulate the child languages yourself. But like I said, this sort of merging is something that we would like to add into SyntaxEditor.


Actipro Software Support

The latest build of this product (v2018.1 build 0342) was released 11 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.