Posted 14 years ago by Nassim Farhat
Version: 4.0.0276
Avatar

Q1-
I don t know how to define a token recognition for a text that looks like this "__variableA"
everytime i come to tokenize it I get "variableA" instead?

Can you help me to determine where and how i can change the token recognition pattern using dynamic language?

Q2-
Also, I would like to trigger the _TriggerActivated event on every character typed (just liek VS studio). All i saw where examples of triggering with characters ex: ".", but I want to trigger on Character="Any typed character". Is this possible to achieve? Or should i just place my intelliprompt list generation code directly inside the keydown event?


Q3-
Plus... can you give me more help on understanding PatternValues like the following :
"[\+\-]? {DigitMacro}+" LookAhead="{NonWordMacro}|\z"

Is there a document that can help me understandign this better because I cannot seem to find to many examples concerning this inside the SyntaxEditor.chm? So far, Wikipedia has been a good helper for regular expressions but maybe you know where the official info lies?


Thank you
NF.

[Modified at 01/29/2010 08:17 AM]

Comments (10)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Nassim,

Pattern groups can either be "explicit", which means exactly as specified, or "regex", which means they are defined using a regular expression. For regex pattern groups, you can look at the documentation topic "SyntaxEditor Regular Expression Guide / Language Elements". That lists all the available regular expression constructs you can use in your pattern.

Identifier tokens are usually defined using this sort of regex pattern:
<RegexPatternGroup TokenKey="IdentifierToken" PatternValue="(_ | {AlphaMacro})({WordMacro})*" />

Which says either an underscore or alpha char can start the token and then it is followed by any number of underscore, alpha, or digit chars. {WordMacro} means underscore, alpha, or digit. The built-in macros are listed in the "SyntaxEditor Regular Expression Guide / Dynamic Language Lexical Macros" topic.

For this pattern:
"[\+\-]? {DigitMacro}+" LookAhead="{NonWordMacro}|\z"

That means:
1) Starts with an optional + or - character
2) Then there must be one or more digits
3) The look-ahead then says the end of the digits must be followed by either a non-word character or the end of file... if the look-ahead fails, no token match is made. The look-ahead does not consume characters into the token though like the main pattern part does.

As for showing the member list after any new word is starting to be typed, that's not something we have right now in the WinForms version built-in. But all you'd have to do is handle the SyntaxEditor.KeyTyped event and if it's a letter, do some text scanning in the document to see if it is the start of a word. If so, show the member list.

Hope this helps.


Actipro Software Support

Posted 14 years ago by Nassim Farhat
Avatar
Thank you very much for this little briefing, I can understand a little more how things work dynamically. These pattern based parsing technics are very powerfu, especially the "regex" construct.

In any case, I have done as you suggested and i included the intelliprompt on certain keydown conditions, but for the heck of it, i also kept the TriggerActivated event on typing ".".

Q1-
Now I get my intelliprompt poping up when I wish it to! But there is still one condition where I do not want it to pop-up and I don't know how to check for it. This is when the typing occurs when the curson (caret) is inside the token (ex: 'varia|ble1' the '|' character represents the cursor or present location). Basically I want to add another condition that checks for when there is a character directly on the right or on the left of the cursor, then if characters are found, I would not trigger the intelliprompt. I'm sure this is pretty easy to accomplish by parsing the string of the document according to the present position, but would you have a code example for this? Or tell me where the features are located?

Q2-
This question is a little related to the last one. I was wondering how I could parse the document token by token form A to Z and insert text programmatically right at the end of some special selected tokens?

Regards
Nassim
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You can get a text stream at any time. So you'd call editor.Document.GetTextStream(offset) where the offset is the caret's offset (editor.Caret.Offset). Then you can read backwards by character, token, etc. by using the text stream.

You can programmatically insert text with the Document.InsertText method.


Actipro Software Support

Posted 14 years ago by Nassim Farhat
Avatar
Thank you for your message.

1 last question related to intelliprompt.

Is it possible for the intelliprompt to automatically remove the items and filter itself down depending on the entered text or would I absolutely need to manage the items in the intelliprompt list myself depending on the typed tokens?
I have tried it myself and I noticed that this is not an easy task to accomplish, intelliprompt needs to be initialized in a special way and if I don't respect the order of initialization I often get exception thrown back at me (such as index out of bounds) during my filtering and reseting of the intelliprompt process, and also i find it very difficult to readjust the size of the intelliprompt window dialog everytime a filtering on the items is applied.

Thank you for your time.
NF

[Modified at 02/03/2010 07:21 AM]
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Nassim,

Sorry but that is something that the WinForms version doesn't currently support.

It is something we support in the newer WPF version of SyntaxEditor though. We eventually hope to port our newer designs back to the WinForms version once the WPF version has all the same feature areas covered that are already in the WinForms version.


Actipro Software Support

Posted 14 years ago by Nassim Farhat
Avatar
Hello,

I have a question concerning my desired pattern in the RegEx IdentifierToken group.

I want for the following patterns to be part of the IdentifierToken group:

1- includes names with "%" and "." such as "%QD3.3".
2- includes names with "[" and "]" such as "abc[33]"
3- includes names with [0-9] and [a-z] such as "ABC123def"
4- includes names with "#" such as "t#123def"

Here is what i have so far defined:

<RegexPatternGroup TokenKey="IdentifierToken" Style="IdentifierStyle" PatternValue="(%)? (_)? (#)? {AlphaMacro}({WordMacro})* (\. {DigitMacro}+)?" />
For some reason, everytime I type # or % inside a name such as "t#123def" or "t%123def" the characters "#" and "%" appear under the "DefaultToken" group and not the "IdentifierToken".
What am i doing wrong in my pattern evaluation?

Thank you for your time
Nassim

[Modified at 02/09/2010 11:29 AM]
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Nassim,

This should work fine for you:
<RegexPatternGroup TokenKey="IdentifierToken" PatternValue="[_\w\%\.\[\]\#]+" />


Actipro Software Support

Posted 14 years ago by Nassim Farhat
Avatar
Thank you for the feedback.

The problem with the pattern you gave me is that my numerical pattern groups are now recognized as "IdentifierToken":

<RegexPatternGroup TokenKey="RealNumberToken" Style="NumberStyle" LookAhead="{NonWordMacro}|\z">
                    <RegexPattern Value="[\+\-]? {DigitMacro}+ \. {DigitMacro}+ (e [\+\-]? {DigitMacro}+)?" />
                    <RegexPattern Value="[\+\-]? {DigitMacro}+ e [\+\-]? {DigitMacro}+" />
                </RegexPatternGroup>
<RegexPatternGroup TokenKey="IntegerNumberToken" Style="NumberStyle" PatternValue="[\+\-]? {DigitMacro}+" LookAhead="{NonWordMacro}|\z" />
So when i type 123.123 it sees it as an "IdentifierToken". But i found another way to get the pattern i needed. Given that possible values of standard "IdentifierToken" could be the following:

bool1[9] (IdentifierToken)
%ID0.9 (IdentifierToken)
t#1ms (IdentifierToken)
asdasd2 (IdentifierToken)

But that the following should not be (IdentifierToken):

2var1
123.123 (NumericalToken)

I fixed my pattern value to look like the following:
<RegexPatternGroup TokenKey="IdentifierToken" PatternValue="(\%)? (\_)? {AlphaMacro} (\%)? (\_)? (#)? ({WordMacro})* (\[ {DigitMacro}+ \])? (\. {DigitMacro}+)? " />
I know it looks horrible, but It does the 95% of the work except for the case of the "2var1" where it splits that word into 2 tokens "2" and "var1". "2" is seen as a defaultToken and "var1" as an IdentifierToken?

How can i tell the dynamic parser to see "2var1" as a (defaultToken)?

Thanks for your time.

[Modified at 02/11/2010 09:08 AM]
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nassim,

You really should spend some time reading the documentation on regular expression syntax because it will help you out a lot in the long run. Make use of character classes where you define a ranges of characters that are valid like we did with the square braces. They make everything more concise and run faster than using a bunch of options (?).

For instance this will probably work for you:
<RegexPatternGroup TokenKey="IdentifierToken" PatternValue="[_a-zA-Z\%] [_\w\%\.\[\]\#]*" />


Actipro Software Support

Posted 14 years ago by Nassim Farhat
Avatar
Thank you.

And yes, I have the read the documentation concerning this.... I just needed a little more pratice.

Thank you for your time and patience.
Regards
Nassim
The latest build of this product (v24.1.0) 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.