Lua language support

SyntaxEditor for WPF Forum

Posted 10 years ago by John Dunn
Version: 9.1.0504
Avatar
According to the SyntaxEditor Overview in the documentation
Quote:
Free sample language definitions for common languages like Assembly, Batch files, C#, CSS, HTML, INI files, Java, JScript, Lua, MSIL, Pascal, Perl, PHP, PowerShell, Python, SQL, VB.NET, VBScript, and XML.

I can't seem to find the lua language sample definition anywhere in my trial installation. Where should these be located?

Comments (5)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
They are in this folder under the Sample Browser project:
\ProductSamples\SyntaxEditorSamples\Languages\Dynamic\ActiproSoftware.Lua.xml

Note that it is currently in our SyntaxEditor for WinForms format, which is temporary. In the next WPF Studio build we hope to have the newer XML definition completed. We'll have a tool that will convert this old format to the new one for you though.


Actipro Software Support

Posted 10 years ago by John Dunn
Avatar
Thanks. I assume the following code is the minimum requirement to load and use the language?

using (FileStream fs = new FileStream("c:\\test\\ActiproSoftware.Lua.xml", FileMode.Open))
{
  SyntaxLanguage language = new SyntaxLanguage("Dynamic");
  language.RegisterService<ILexer>(DynamicLexer.LoadFromXml(fs, 0));
  language.RegisterService<ITokenClassifierFactory>(new TokenClassifierFactory(typeof(MergableLexerClassifier)));
  _Editor.Document.Language = (ISyntaxLanguage)language;
}
What will be the difference between using this version of the format and when you have the newer XML definition completed? It appears to work ( keywords are colored, etc ).

On a side note, I'm not sure that using a lot of extension methods in your sample code is a good practice. When I was copying code from SyntaxEditorHelper.cs to load in the language xml, I had to either track down the extension methods for RegisterLexer and RegisterClassifierFactory or replace them with the actual calls, which I did for clarity sake.
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Our newer format will be more generic and flexible. So it could end up using less lines of code than what you pasted. You can check the samples again once we make the change to ensure you tweak your language loading code appropriately.

What you pasted should work fine for now.

For the extension methods, you can just copy that entire SyntaxEditorHelper class to your code. That is easiest. Right now we target .NET 3.0 so we can't have it in our code. However later this year, we are going to move to target .NET 3.5, at which point it will be part of our library. At that time, the copying of the class won't be needed.


Actipro Software Support

Posted 10 years ago by John Dunn
Avatar
I've just updated to .507 and LoadFromXml method has been removed from DynamicLexer. From the sample code, it now looks like the correct thing to do is to embed lua.langdef as a resource and load it with the following code

using (Stream s = Util.Resource.LoadResourceStream("resources/lua.langdef"))
{
  SyntaxLanguageDefinitionSerializer serializer = new SyntaxLanguageDefinitionSerializer();
  editor.Document.Language = serializer.LoadFromStream(stream);
}
Is that correct?
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

Yes that should be right. The old WinForms dynamic language format was temporary carryover until the newer language definition format was complete. Now that it is, the use of SyntaxLanguageDefinitionSerializer is the correct way to load a language definition.


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.