private void SyntaxColorRange(int startLine, int startColumn, int endLine, int endColumn)
        {
            var firstLine = startLine;

            m_editor.ClearStyles(startLine, startColumn, endLine, endColumn);

            if (startLine != endLine || startColumn != endColumn)
            {
                ITokenSource lexer  = new Lexer(this.GetParserStream(startLine, startColumn, endLine, endColumn));
                var          tokens = new CommonTokenStream(lexer);
                tokens.Fill();
                foreach (var token in tokens.GetTokens())
                {
                    EditorTextStyles style = EditorTextStyles.Normal;
                    if (token.Type >= 0 && m_tokenStyles.Count > token.Type)
                    {
                        style = m_tokenStyles[token.Type];
                    }
                    if (style != EditorTextStyles.Normal)
                    {
                        m_editor.SetStyle(
                            style,
                            (token.Line - 1) + firstLine,
                            token.Column,
                            (token.Line - 1) + firstLine,
                            token.Column + (token.StopIndex - token.StartIndex) + 1);
                    }
                }
            }
        }
        public TextRange Parse(TextSnapshotRange snapshotRange, ActiproLex.ILexerTarget parseTarget)
        {
            //System.Diagnostics.Debug.WriteLine("LexParse " + snapshotRange.ToString());
            int index = snapshotRange.StartOffset;
            int ix    = index;

            parseTarget.OnPreParse(ref ix);

            if (parseTarget.HasInitialContext)
            {
            }
            else
            {
                int l = snapshotRange.EndOffset - index;
                ITextSnapshotReader reader = snapshotRange.Snapshot.GetReader(index);
                if (reader.Offset != index)
                {
                    throw new System.Exception("What??!!?");
                }
                StringBuilder text = new StringBuilder();
                var           read = reader.ReadText(l);
                text.Append(read);
                //System.Diagnostics.Debug.WriteLine($"Parse read {read.Length} chars: {text.ToString()}");

                var lexer  = new SBLexer(new Antlr.AntlrInputStream(text.ToString()));
                var tokens = new Antlr.CommonTokenStream(lexer);
                tokens.Fill();
                foreach (var token in tokens.GetTokens())
                {
                    if (token.Type >= 0)
                    {
                        parseTarget.OnTokenParsed(new SyntaxEditorAntlrToken(token, index, snapshotRange.StartLine.Index), null);
                    }
                }
            }

            parseTarget.OnPostParse(snapshotRange.EndOffset);

            return(snapshotRange.TextRange);
        }
        public override void ExitDatatableRowCell([NotNull] SBP.DatatableRowCellContext context)
        {
            var           text  = context.GetText().Trim();
            TypeReference type  = null;
            object        value = null;

            if (!String.IsNullOrEmpty(text))
            {
                // TODO: It MUST be possible to make this simpler... (e.g. re-use tokens)
                Antlr4.Runtime.ITokenSource lexer  = new Lexer(new Antlr4.Runtime.AntlrInputStream(text));
                Antlr4.Runtime.ITokenStream tokens = new Antlr4.Runtime.CommonTokenStream(lexer);
                var parser = new SBP(tokens);
                parser.RemoveErrorListeners();
                parser.AddErrorListener(m_errors);
                parser.BuildParseTree = true;
                var cellContext = parser.datatableRowCellContent();
                var walker      = new Antlr4.Runtime.Tree.ParseTreeWalker();
                m_expressionData.PushStackLevel("VariableType");
                walker.Walk(this, cellContext);
                var stack           = m_expressionData.PopStackLevel();
                var expressionValue = stack.Pop();
                if (expressionValue.IsConstant)
                {
                    type  = expressionValue.DataType;
                    value = expressionValue.Value;
                }
                else if (expressionValue.IsUnresolvedIdentifier)
                {
                    type  = new TypeReference(typeof(StepBro.Core.Data.Identifier));
                    value = expressionValue.Value;
                }
                else
                {
                    m_errors.SymanticError(context.Start.Line, context.Start.Column, false, "Error parsing cell value.");
                }
            }

            m_currentDatatableRowData.Add(new Tuple <string, TypeReference, object>(text, type, value));
        }