private TolerantTokenizer tokenize(string queryStr) { Log.Debug(queryStr); var parser = new MtgTolerantTokenizer(queryStr); parser.Parse(); if (parser.SyntaxErrors.Count > 0) { Log.Debug("Errors:"); } foreach (string error in parser.SyntaxErrors) { Log.Debug(error); } Log.Debug("Tokens:"); foreach (var token in parser.Tokens) { Log.Debug(token); } return(parser); }
public void Highlight() { if (Runtime.IsMono) { return; } var start = _findEditor.SelectionStart; var len = _findEditor.SelectionLength; var tokenizer = new MtgTolerantTokenizer(_findEditor.Text); tokenizer.Parse(); _findEditor.BeginUpdate(); try { setColor(0, _findEditor.TextLength, SystemColors.WindowText); foreach (var token in tokenizer.Tokens) { if (token.Type.IsAny(TokenType.FieldValue)) { setColor(token.Position, token.Value.Length, null); } else if (token.Type.IsAny(TokenType.Field | TokenType.Colon)) { setColor(token.Position, token.Value.Length, SystemColors.HotTrack.TransformHsv(h: _ => _ + Color.RoyalBlue.RotationTo(Color.DarkCyan))); } else if (token.Type.IsAny(TokenType.RegexBody)) { setColor(token.Position, token.Value.Length, SystemColors.HotTrack.TransformHsv(h: _ => _ + Color.RoyalBlue.RotationTo(Color.DarkRed))); } else { setColor(token.Position, token.Value.Length, SystemColors.Highlight); } } _findEditor.SelectionStart = start; _findEditor.SelectionLength = len; } finally { _findEditor.EndUpdate(); } }
public void Highlight() { bool hasFocus = _findEditor.Focused; HighlightingInProgress = true; _findEditor.Parent.SuspendLayout(); _findEditor.Visible = false; var start = _findEditor.SelectionStart; var len = _findEditor.SelectionLength; var tokenizer = new MtgTolerantTokenizer(_findEditor.Text); tokenizer.Parse(); setColor(0, _findEditor.TextLength, Color.Black, false); foreach (var token in tokenizer.Tokens) { if (token.Type.IsAny(TokenType.FieldValue)) { setColor(token.Position, token.Value.Length, null, true); } else if (token.Type.IsAny(TokenType.Field | TokenType.Colon)) { setColor(token.Position, token.Value.Length, Color.Teal, false); } else if (token.Type.IsAny(TokenType.RegexBody)) { setColor(token.Position, token.Value.Length, Color.DarkRed, false); } else { setColor(token.Position, token.Value.Length, Color.MediumBlue, false); } } _findEditor.SelectionStart = start; _findEditor.SelectionLength = len; _findEditor.Visible = true; _findEditor.Parent.ResumeLayout(false); if (hasFocus) { _findEditor.Focus(); } HighlightingInProgress = false; }
public void Highlight() { bool hasFocus = _findEditor.Focused; _findEditor.Parent.SuspendLayout(); _findEditor.Visible = false; var start = _findEditor.SelectionStart; var len = _findEditor.SelectionLength; var tokenizer = new MtgTolerantTokenizer(_findEditor.Text); tokenizer.Parse(); setColor(0, _findEditor.TextLength, SystemColors.WindowText); foreach (var token in tokenizer.Tokens) { if (token.Type.IsAny(TokenType.FieldValue)) { setColor(token.Position, token.Value.Length, null); } else if (token.Type.IsAny(TokenType.Field | TokenType.Colon)) { setColor(token.Position, token.Value.Length, SystemColors.HotTrack.TransformHsv(h: _ => _ + Color.RoyalBlue.RotationTo(Color.DarkCyan))); } else if (token.Type.IsAny(TokenType.RegexBody)) { setColor(token.Position, token.Value.Length, SystemColors.HotTrack.TransformHsv(h: _ => _ + Color.RoyalBlue.RotationTo(Color.DarkRed))); } else { setColor(token.Position, token.Value.Length, SystemColors.Highlight); } } _findEditor.SelectionStart = start; _findEditor.SelectionLength = len; _findEditor.Visible = true; _findEditor.Parent.ResumeLayout(false); if (hasFocus) { _findEditor.Focus(); } }