Exemple #1
0
    string Lex(string src)
    {
        ElaLexer lexer = new ElaLexer();
        IEnumerable <StyledToken> tokens = lexer.Parse(src);

        if (tokens != null)
        {
            StringBuilder sb     = new StringBuilder(src);
            int           offset = 0;

            foreach (StyledToken t in tokens)
            {
                string span    = String.Format("<span class='lexer_{0}'>", t.StyleKey);
                string endSpan = "</span>";
                sb.Insert(t.Position + offset, span);
                offset += span.Length;
                sb.Insert(t.Position + offset + t.Length, endSpan);
                offset += endSpan.Length;
            }

            return(sb.ToString());
        }

        return(src);
    }
Exemple #2
0
        private string Lex(string src)
        {
            var lexer  = new ElaLexer();
            var tokens = lexer.Parse(src);

            if (tokens != null)
            {
                var sb     = new StringBuilder(src);
                var offset = 0;

                tokens.ToList().ForEach(t =>
                {
                    var span    = String.Format("<span class='lexer_{0}'>", t.StyleKey);
                    var endSpan = "</span>";
                    sb.Insert(t.Position + offset, span);
                    offset += span.Length;
                    sb.Insert(t.Position + offset + t.Length, endSpan);
                    offset += endSpan.Length;
                });

                return(sb.ToString());
            }

            return(src);
        }