The following reg expression does exactly what I need it to do:
^(LASTRUN)*$
It matches the literal "LASTRUN" exactly and doesn't allow whitespace or any other characters anywhere(beginning, middle, or end of word).
Here is the error I get when implementing -
The regular expression value is invalid: ^ - Start of line matching is not supported $ - End of line matching is not supported
Is there a way to get around this or is there alternative regex to make this work?
Thanks,
Andy
Hello Andy,
Have you tried using predefined brushes? When does the exception occur? I ran your sample but nothing happened other than the main window and the syntax editor opening as expected.
Hey Michael,
Thanks for following up. After more experimentation, we have come up with a solution, but have found another problem in the process.
The following code is working exactly how we would like it to:
NonTerminalSymbol identifierResolved; if (grammar.NonTerminalSymbols.TryGetSymbol("_identifierResolved", out identifierResolved) == false) { Debug.Fail("Cannot find the _identifierResolved symbol."); return null; } var alternateRule = identifierResolved.Rule as AlternationSyntaxRule; if (alternateRule == null) { Debug.Fail("The _identifierResolved symbol does not have an alternation at the root level rule, as expected."); return null; } #endregion var defaultLexerState = grammar.LexerStates.DefaultLexerState; var languageName = "Custom"; int j = 0; // Not sure of exactly how many of these cause an out of memory exception, but 750 will definitely cause the // out of memory exception JobVariables.ForEach(var => { var validVar = defaultLexerState.Symbols.Insert(0, "ValidVar" + j++.ToString(), "%" + var + "%", TerminalSymbolComparison.LiteralIgnoreCase); validVar.LanguageElementName = languageName; alternateRule.Rules.Add(validVar); }); if (ClassificationAppearanceMap == null) ClassificationAppearanceMap = new ClassificationAppearanceMap(); ClassificationAppearanceMap.AddMapEntry( new ClassificationType(languageName, languageName, "The keyword for the Custom name"), new TextDocumentAppearance() { Foreground = new SolidColorBrush(Colors.DarkOrange), FontBold = true }); return grammar;
Only issue with this code is if we add 750 or more ("defaultLexerState.Symbols"), we get an out of memory exception. The attached sample project is set up to display the issue. Please review and let me know what you think.
Thanks
8358.XamSyntaxEditorInvalidVars.zip
Thank you for following up. I wasn't able to decipher exactly what might be happening with white spaces. I do know we have a property that might help you called WhitespaceIndicatorVisibility. Setting this to Visible causes a "dot" to appear in place of every white space. Unfortunately there is an exception happening when setting this property in your sample because of the ClassificationAppearanceMap binding.
A development issue has been created to investigate this in depth regarding the exception and the behavior with applying "% LASTRUN %" in the XamSyntaxEditor with tracking number 257885.
I also created a private support case to follow up with you CAS-198135-M1N6W2. You can access this case when signed into your Infragistics account and clicking Support Activity and view what is marked "In Development".
Let me know if you have any questions.
Hi Michael,
Thanks for the response. I've put together a sample project which will hopefully show you what exactly I'm trying to accomplish.
I'm trying to show invalid match when "LASTRUN" (has to be inside % signs) does not exactly match the word LASTRUN(whitespace before or after % signs should be invalid - see Doesn't work! in picture below). The regular expression I'm testing that works -> ^(LASTRUN)$ cannot be used in the code snippet out of my sample project below:
var daVarContent = lexerState.Symbols.Add("DaVarContent", @"(LASTRUN)", TerminalSymbolComparison.RegularExpression); daVarContent.LanguageElementName = languageElementName; //daVarContent.LookaheadPattern = @"[^\S]"; //daVarContent.IsLookaheadNegative = true;
So, the main portion of the sample I'd like for you to take a look at is inside this method -
public void DAVariableLanguage2(Grammar grammar). Maybe there is a way to accomplish what I am trying to do by using a LookaheadPattern. I've done a lot of experimentation but haven't been able to make this work.
XamSyntaxEditorInvalidVars.zip
Please let me know if you need clarification or have any questions.
Thank you for contacting Infragistics. Are you loading in a custom EBNF file alongside using the Syntax Parsing Engine in addition to using the XamSyntaxEditor? Please isolate the behavior in the sample attached below and I will investigate this further for you.
xamSyntaxEditor_regularexpressions.zip