Syntax highlighting

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Syntax highlighting

George
I'm using Parboiled for Scala to implement a DSL and finding it very good but I really need to implement syntax highlighting/coloring for it.

Is there any documentation available on the best approach to take to implement syntax highlighting (eg. via HTML and/or Eclipse) for a parboiled DSL?

Otherwise do you have any advice in implementing this?  Are there any plans to add features to parboiled to assist in implementing syntax highlighting in the future?

Regards

George
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax highlighting

mathias
Administrator
George,

syntax highlighting is one of many possible applications for a parser.
The way to implement it greatly depends on the environment that you'd like to see it it.
For example, the implementation of syntax highlighting for an IDE plugin will likely differ quite a bit from one that is supposed to generate HTML output (like pygments).

Still, there will probably be shared parts, like using the parser to somehow constructing an AST with positional information, that can later be used to generate the output "coloring".

I know of at least one application that already uses parboiled for syntax highlighting: the `idea-markdown` plugin, that, among other things, provides syntax highlighting for markdown files. It relies on pegdown, a markdown parser built with parboiled.

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 26.09.2012, at 08:54, George [via parboiled users] wrote:

> I'm using Parboiled for Scala to implement a DSL and finding it very good but I really need to implement syntax highlighting/coloring for it.
>
> Is there any documentation available on the best approach to take to implement syntax highlighting (eg. via HTML and/or Eclipse) for a parboiled DSL?
>
> Otherwise do you have any advice in implementing this?  Are there any plans to add features to parboiled to assist in implementing syntax highlighting in the future?
>
> Regards
>
> George
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Syntax-highlighting-tp4024070.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.
> NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax highlighting

George
Hi Mathias,

Thanks for the response.  I've had a look at pegdown and I've also had a quick look at idea-markdown.

I think that pegdown is probably what I'm after.  I thought that perhaps the simplest way to start off would be to pass some source that can be successfully processed by parboiled for Scala into pegdown and then convert it to HTML.

I see that the PegDownProcessor appears to be the main entry point into pegdown.  It has a method markdownToHtml that takes a String (presumably in the format expected by my parboiled parser?) and returns HTML as a String.  One of the constructors takes a Parser.  But this is a pegdown Parser - not a parboiled for Scala or even a core parboiled Parser.

Given that I already have a parser that extends org.parboiled.scala.Parser, what steps would I need to follow to get source that can be processed by that parser (to generate a custom AST) to be formatted in HTML by pegdown?

To my mind, I need some way of associating different rule definitions within the parboiled parser to be recognised in different ways by pegdown.  eg. literals might be red while function names might be blue.  To me, the logical place to do (at least some of) this association is within the parboiled parser/rules somewhere (otherwise I'm going to have to duplicate a lot of rule logic in pegdown).

Maybe an example of using pegdown to process one of the parboiled for Scala samples (eg. JASON) would be useful.

Cheers

George

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Syntax highlighting

mathias
Administrator
George,

pegdown is a markdown-to-html converter, based on parboiled.

> Given that I already have a parser that extends org.parboiled.scala.Parser, what steps would I need to follow to get source that can be processed by that parser (to generate a custom AST) to be formatted in HTML by pegdown?

You can't and using pegdown directly is very likely not the way to achieve what you are after.
When I pointed you to pegdown I meant that idea-markdown performs syntax highlighting using the pegdown parser.
So pegdown+idea-markdown could serve as an implementation example of how one might go about implementing syntax highlighting with parboiled.
It is not a ready to use solution that provides syntax-highlighting for _your_ parser!

> Maybe an example of using pegdown to process one of the parboiled for Scala samples (eg. JASON) would be useful.

pegdown can only read markdown source. It cannot process scala source or JSON or anything else.

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 27.09.2012, at 05:51, George [via parboiled users] wrote:

> Hi Mathias,
>
> Thanks for the response.  I've had a look at pegdown and I've also had a quick look at idea-markdown.
>
> I think that pegdown is probably what I'm after.  I thought that perhaps the simplest way to start off would be to pass some source that can be successfully processed by parboiled for Scala into pegdown and then convert it to HTML.
>
> I see that the PegDownProcessor appears to be the main entry point into pegdown.  It has a method markdownToHtml that takes a String (presumably in the format expected by my parboiled parser?) and returns HTML as a String.  One of the constructors takes a Parser.  But this is a pegdown Parser - not a parboiled for Scala or even a core parboiled Parser.
>
> Given that I already have a parser that extends org.parboiled.scala.Parser, what steps would I need to follow to get source that can be processed by that parser (to generate a custom AST) to be formatted in HTML by pegdown?
>
> To my mind, I need some way of associating different rule definitions within the parboiled parser to be recognised in different ways by pegdown.  eg. literals might be red while function names might be blue.  To me, the logical place to do (at least some of) this association is within the parboiled parser/rules somewhere (otherwise I'm going to have to duplicate a lot of rule logic in pegdown).
>
> Maybe an example of using pegdown to process one of the parboiled for Scala samples (eg. JASON) would be useful.
>
> Cheers
>
> George
>
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Syntax-highlighting-tp4024070p4024076.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.
> NAML

Loading...