예제 #1
0
        private void SourceText_Changed(object sender, TextChangedEventArgs e)
        {
            if (SourceTextBox.Decorations.Count != 0)
            {
                SourceTextBox.Decorations.Clear();
                SourceTextBox.InvalidateVisual();
            }

            _nextRescanTime = DateTime.Now + TimeSpan.FromSeconds(1.0);
            _modified       = true;
        }
예제 #2
0
        private void PresentColoredTokens(IEnumerable <Token> tokens, IEnumerable <Error> errors)
        {
            SourceTextBox.Decorations.Clear();
            SourceTextBox.InvalidateVisual();

            foreach (var token in tokens)
            {
                if (_colorMap.ContainsKey(token.Type))
                {
                    ExplicitDecoration ed = new ExplicitDecoration();

                    ed.Start          = token.Position.Value.Offset;
                    ed.Length         = token.Value.Length;
                    ed.Brush          = _colorMap[token.Type];
                    ed.DecorationType = EDecorationType.TextColor;

                    SourceTextBox.Decorations.Add(ed);
                }
            }

            foreach (var error in errors)
            {
                if (error.Token != null)
                {
                    if (error.Kind == ErrorKind.Syntax)
                    {
                        ExplicitDecoration ed  = new ExplicitDecoration();
                        ExplicitDecoration ed2 = new ExplicitDecoration();

                        ed.Start  = ed2.Start = error.Token.Position.Value.Offset;
                        ed.Length = ed2.Length = error.Token.Value.Length;

                        ed.DecorationType = EDecorationType.Hilight;
                        ed.Brush          = new SolidColorBrush(Color.FromArgb(200, 255, 0, 0));

                        ed2.DecorationType = EDecorationType.TextColor;
                        ed2.Brush          = new SolidColorBrush(Colors.White);

                        SourceTextBox.Decorations.Add(ed);
                        SourceTextBox.Decorations.Add(ed2);
                    }
                    else if (error.Kind == ErrorKind.Lexical)
                    {
                        ExplicitDecoration ed = new ExplicitDecoration();

                        ed.Start  = error.Token.Position.Value.Offset;
                        ed.Length = error.Token.Value.Length;

                        ed.DecorationType = EDecorationType.Underline;
                        ed.Brush          = Brushes.Red;

                        SourceTextBox.Decorations.Add(ed);
                    }
                    else if (error.Kind == ErrorKind.Semantic)
                    {
                        ExplicitDecoration ed = new ExplicitDecoration();

                        ed.Start  = error.Token.Position.Value.Offset;
                        ed.Length = error.Token.Value.Length;

                        ed.DecorationType = EDecorationType.Hilight;
                        ed.Brush          = new SolidColorBrush(Color.FromArgb(200, 0, 255, 0));

                        SourceTextBox.Decorations.Add(ed);
                    }
                }
            }

            SourceTextBox.InvalidateVisual();
        }