Multiple Language Variants in Language Definition

SyntaxEditor for WPF Forum

Posted 10 years ago by SvenG - VIPA
Version: 11.2.0552
Avatar

Hi Guys,

I have a special scenario I need to solve:

I have a custom pogramming language based on a dynamic lexer with lots of pattern groups and a grammar. So far so good.
Now I need to support different spoken languages in that programming language (e.g. german and english, more variants possible).
Some patterns are identical because they are the same in every language, some can differ, The grammar is identical.

Example english:

if (a==5) load b;
set status;

Example german:

wenn (a==5) lade b;
setze status;

I could just copy the entire Language definition and change my regexes in the Dynamic lexer, but hoped there is a more elegant solution, where I could just change the ones that differ and just produce different lexers.
To just change the regexes that they recognize both variants is not feasible as I want to prevent mixing the two language variants.

Hope you got my issue, Have searched the documentation and the Sample Browser but haven't found anything helpful.

Thanks in advance

Sven

Comments (2)

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

Hi Sven,

Your two options for this scenario would be:

1) Make separate copies of the entire language definition, as you said.  The downside there is that anytime you change common patterns, you'd have to update each copy.

2) Make a single copy of the language definition and put keys on some empty pattern groups that will receive language-specific words.  This way you could load up your stub language definition.  Then via code, navigate down the DynamicLexer object model into the appropriate DynamicLexicalState and  find the pattern groups that need updating.  Then add the appropriate language words to each of the pattern groups.  By doing this, you would only have to maintain a single language definition and then you would have a separate language-specific word list.

The "Text/Parsing Framework / Lexing / Basic Concepts" has a section in it about how to change mergable lexers.  You need to wrap all the changes mentioned above with the using statement discussed there.

I hope that helps.


Actipro Software Support

Posted 10 years ago by SvenG - VIPA
Avatar

Works like a charm, thank you very much !!

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.