About .langdef's and language XML files

SyntaxEditor for WPF Forum

Posted 8 years ago by James Deadman
Version: 11.1.0543
Avatar
Hello,

I have been reading the Syntax Editor (WPF) help file regarding syntax lanuage definitions and creation.

May i ask some questions please.

1. Previously i used to load a language XML file (e.g. "CSharp.XML") which Syntax Editor used to provide (SE4). However i cant seem to find any reference to filenames with 'XML' file extension in the help. So are .langdef files the new version of those XML files please?

2. Lastly, once we have loaded in a syntax language into an ISyntaxLanguage object, how might we add extra keywords to it please? This is important because there extra keywords over-and-above the basic keywords which can only be retrieved at run-time (e.g. SFR keywords).

3. From the help file, i understand that the Language Designer loads in a .langproj and from this creates a .landef file. I noticed that the contents of these two files are identical except the "langdef" and "langproj" words. It probably makes no difference really, but just wondered what the difference was please? (perhaps there is none).

Thank you in advance for any help.

Regards,
James

Comments (4)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi James,

1) Yes, in WPF/Silverlight we have new language projects (.langproj) and language definitions (.langdef). You can edit .langproj files in the Language Designer application and can design your dynamic lexer and some other language feature services there. Then that tool can code generate .langdef files and other C#/VB code-behind files for the .langproj, which you can include in your project. The .langdef file is basically equivalent to the SE4 .xml files.

The Language Designer application can import SE4 dynamic language .xml files to convert them to .langproj files too.

2) In the newer WPF/Silverlight designer, languages consist of services. So the ILexer service is what tokenizes code. If you used a dynamic language in SE4, then it's likely your language in WPF has a DynamicLexer instance for its ILexer service. The "Text/Parsing Framework - Lexing / Basic Concepts" documentation topic has a section on how to change lexers. You'd do those things and change your DynamicLexer similar to how you did in SE4.

3) The differences depend on the language. The .langproj file may contain design-time items that the deployable .langdef doesn't need. For instance, if you define type-specific AST nodes in the Language Designer, those are something the Language Designer code generates but isn't something that end users need to see. Thus those don't get exported to a .langdef file. They just stay in the .langproj file. There are some other instances of things like that, but in general they will contain similar information.


Actipro Software Support

Posted 8 years ago by James Deadman
Avatar
Hello,

Thanks a lot for your help and quick reply.

Sorry could i just confirm on question 2 please. You mention about changing lexers from the Dynamic Lexer. Is this required in order to be able to add more keywords at run-time? If so which lexer to change to in order to allow additional keywords please?

I was hoping that which ever lexer i used (ideally the Dynamic Lexer as i already use this), that once i loaded in the .langdef into a Syntax Language object (ISyntaxLanguage) that i could just add extra keywords to it via an API. Is this possible please?

Thanks,

James
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi James,

You can change lexers however you need at run-time, however as mentioned in the doc topic you need to wrap the changes with the code listed in the topic so that SyntaxEditor knows something was changed.

For DynamicLexers, they have a similar object model to the WinForms dynamic languages, where you have multiple lexical states and each state has multiple pattern groups. You could add/remove patterns to pattern groups as you see fit to alter recognized keywords. Just be aware of adding them in a pattern group near the start of the lexical state to make sure they receive highest priority.


Actipro Software Support

Posted 8 years ago by James Deadman
Avatar
Hi,

Thanks again for your help.

Probably we'd stick with the Dynamic Lexer, and would only really add keywords to existing patterns rather than creating new patterms. We would also add these keywords on startup, before using it in any editor views. Hopefully that will simply things :-)

Regards,
James
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.