JavaScript-based Ruby lexer/parser for CSS syntax highlighting?

Discussion in 'Ruby' started by Phrogz, Feb 27, 2007.

  1. Phrogz

    Phrogz Guest

    I'm looking for a JS library that will find <code class="ruby"> (or
    otherwise-specified) elements on an HTML page and wrap bits in <span
    class="keyword">...</span> type elements for CSS syntax coloring of
    the original source.

    I've found two JS-based syntax highlighters ([1] and [2]), but both
    fail on Ruby code like:
    foo = "Hello #{ "World" }"

    They're both regexp-based, which is the problem. I'm happy to use them
    for quick-n-dirty highlighting, but I'm hoping that someone has
    written a lexer/parser that handles more complex situations like this
    (even if it doesn't cover every single edge case).
     
    Phrogz, Feb 27, 2007
    #1
    1. Advertising

  2. Phrogz

    Phrogz Guest

    Phrogz, Feb 27, 2007
    #2
    1. Advertising

  3. On Wed, Feb 28, 2007 at 04:50:05AM +0900, Phrogz wrote:
    > On Feb 27, 12:43 pm, "Phrogz" <> wrote:
    > [snip]
    > > I've found two JS-based syntax highlighters ([1] and [2]), but both

    > [/snip]
    >

    Does it have to be JS? You gonna do client side lexing of ruby in JS? (I
    guess it has to be, else you wouldn't have asked.)

    * forges on anyway *

    Sure you can't use http://coderay.rubychan.de/ instead?
    > Oops, forgot to attach the references:
    > [1] http://www.dreamprojections.com/SyntaxHighlighter/
    > [2] http://softwaremaniacs.org/soft/highlight/en/
    >
     
    Logan Capaldo, Feb 27, 2007
    #3
  4. Phrogz

    Phrogz Guest

    On Feb 27, 3:44 pm, Logan Capaldo <> wrote:
    > Does it have to be JS? You gonna do client side lexing of ruby in JS? (I
    > guess it has to be, else you wouldn't have asked.)
    >
    > * forges on anyway *
    >
    > Sure you can't usehttp://coderay.rubychan.de/instead?


    I could, for sure. That trades bytes over the wire for user's cpu
    time. Sometimes I just really like having code syntax highlighted by
    the page, particularly when it's a tiny snippet as part of a larger
    page, and not an entire source file.

    I hacked the second library I found to do what I want. Although I'm
    annoyed with its speed, it's working reasonably OK for now. It looks
    like I was wrong, that is has some form of 'real' lexing applied via a
    very incomplete idea about Ruby syntax. If no one has a premade JS
    library for this, and if it bothers me enough, I'll spend some time
    understanding its scoping and lexing rules and see if it can make the
    jump from string mode back into code mode. My quick hackery to add
    some features makes it look possible.
     
    Phrogz, Feb 27, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Foster

    Assembler Parser/Lexer in Python

    Simon Foster, Nov 6, 2003, in forum: Python
    Replies:
    4
    Views:
    2,369
    Simon Burton
    Nov 10, 2003
  2. Replies:
    0
    Views:
    398
  3. Replies:
    5
    Views:
    124
    Eric Mahurin
    Nov 20, 2005
  4. Anatol Pomozov
    Replies:
    0
    Views:
    117
    Anatol Pomozov
    Dec 21, 2005
  5. Artur Merke

    ruby lexer/parser

    Artur Merke, Nov 3, 2006, in forum: Ruby
    Replies:
    2
    Views:
    133
    Artur Merke
    Nov 3, 2006
Loading...

Share This Page