Angel \”Java\” Lopez on Blog

March 13, 2012

Acquarella Syntax Highlighter

Filed under: .NET, Acquarella, C Sharp, Open Source Projects — ajlopez @ 2:15 pm

Past weekend, I was coding a simple and configurable syntax highlighter, in C#, named Acquarella. You can see the result at:

https://github.com/ajlopez/Acquarella

The current solution has a class library project, a console program and a test project:

The idea is to have a library you can reference and use from your projects, in case you need some syntax highlighting functionality. The library takes a text (an string) and, giving the source code language and style name, transform it to another text, using configuration files. There is a more detailes information at project README.md.

Dog fooding, the Token.cs class transformed by Acquarella:

namespace Acquarella.Lexers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Token
    {
        private string text;
        private int start;
        private int length;
        private TokenType type;

        public Token(TokenType type, string text, int start, int length)
        {
            this.type = type;
            this.text = text;
            this.start = start;
            this.length = length;
        }

        public string Value
        {
            get
            {
                return this.text.Substring(this.start, this.length);
            }
        }

        public TokenType Type { get { return this.type; } }

        public int Start { get { return this.start; } }

        public int Length { get { return this.length; } }
    }
}

Nice :-)

Pending work: Recognize comments, more styles (maybe using css files), more language configurations, extending Lexer (maybe RubyLexer, CSharpLexer, etc.)

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

1 Comment »

  1. Angel,
    Necesitaría contactarte para ver si nos podes dar una capacitación a la Empresa pero el link de contacto de tu sitio .com no funciona. Como es tu email ? el mío es: dmerlo75@yahoo.com

    Gracias,
    Damián.

    Comment by Damián — April 4, 2012 @ 1:55 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Shocking Blue Green Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 56 other followers

%d bloggers like this: