VBSyntaxLanguage

SyntaxEditor for WPF Forum

Posted 9 years ago by Dude4
Version: 11.1.0541
Avatar
I am using the VBSyntaxLanguage() class for my language. The syntax checker complains that "an Imports, Assembly, Module, or Namespace declaration is expected". I understand why, because in my code editor I simply started typing statements that would normally be found in a Sub(). Although in a normal code file this would not be allowed, in my application the code window represents the contents of a Sub() and the application is responsible for glueing the code together into a Sub(), Class, Namespace and so on. How can I let the SyntaxEditor know that the typed code is actually in a method without wrapping the code in all the required constructs?


Second, is there a code example on how I can get the editor to auto capitalize the first letter of each key word as I type similar to what VS2010 does for VB?

Comments (6)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Check out this documentation topic:
.NET Languages Add-on - Visual Basic Language / Parsing and Parse Data

The last section in it talks about Grammar Options where you can change the root non-terminal. You'd want to use the DotNetGrammarRootNonTerminal.StatementList option in your case, which would allow for zero or more statements.

Sorry we don't yet have a service for supporting case auto-correct. That is something on our TODO list though, and I'll mark down your request with that item.


Actipro Software Support

Posted 9 years ago by Dude4
Avatar
First the example in the documentation has this line

language.RegisterParser(New CSharpParser(grammar))
But VBSyntaxLanguage has no RegisterParser method so I used RegisterService thinking that maybe the documentation has not been updated. This is what I got:

Dim objGramOpt As New VBGrammarOptions()
objGramOpt.RootNonTerminal = DotNetGrammarRootNonTerminal.Expression

Dim objLang As New VBSyntaxLanguage()
objLang.RegisterService(New VBParser(New VBGrammar(objGramOpt)))

SyntaxEditor.Document.Language = objLang
SyntaxEditor.Text = String.Format("For x = 1 To 5{0}{1}x = 2{0}Next ", vbCrLf, vbTab)
However I still get the error.
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
RegisterParser is an extension method that comes in if you import the ActiproSoftware.Text namespace. We'll add a note on that. If you don't do that, you still need to change your code to register the service as type IParser or else it won't be used. Our code looks for a service registered as an IParser. To do this, do something like:
objLang.RegisterService(Of IParser)(New VBParser(New VBGrammar(objGramOpt)))
Also you specified the wrong root non-terminal option (Expression). You want StatementList per our previous reply.


Actipro Software Support

Posted 9 years ago by Dude4
Avatar
Got the "StatementList" option to work except it fails the syntax check with error "document end expected" in this code:

For x = 1 to 5
Next

Dim a as string 'error occurs on the Dim but only if there is a blank line above it
I also have another code window that hosts the contents of a hidden class. For example:

'hidden glue code
Public Shared Class GlobalFunctions

'nothing above this line is shown in edit box

    'here a user can enter a Sub, Function, or Class definition
    Public Shared Sub MySubName()
        'user code
    End Sub

    Public Shared Function MyFuncName() as Object
        'user code
    End Function

    Public Class MyClassName
        'user code
    End Class

'nothing below this line is shown in edit box

End Class
'hidden glue code
I tried all the other DotNetGrammarRootNonTerminal members and none fit this scenario. They all complain of syntax errors.

[Modified at 03/01/2011 05:14 PM]

[Modified at 03/01/2011 05:17 PM]

[Modified at 03/01/2011 05:18 PM]
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks for the sample, it appears there is a bug in the VB grammar's StatementListRoot non-terminal where it doesn't currently allow empty lines between statements. We've fixed it for the next maintenance release. Your first snippet in the previous post will work fine with that change.


Actipro Software Support

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Just a quick FYI... per this blog post, auto-case correct is coming in the next 2013.1 maintenance release:

http://blog.actiprosoftware.com/post.aspx?id=b8a854f0-3097-43ab-8cd1-a698a31ebe31


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.