Parsing Expression Grammar for syntax highlighting
Asked Answered
P

1

6

First... Would it be possible to accomplish simple syntax highlighting using a PEG.

I'm only looking for it to be able to recognize and highlight basic things that are common to c style languages

Second... If there are any examples of this or something similar please let me know

Third... If I'm going about this the wrong way and there are more common and proven ways to do this then also let me know

Pyrophosphate answered 8/10, 2013 at 18:42 Comment(0)
S
0

Using parsing expression grammars for syntax highlighting is definitely possible. Scintillua for example provides PEG-based syntax highlighting for Scintilla-based text editors. Textadept is an example for a text editor that uses Scintillua.

There is also the more recent flare library built by Zachary Yedidia that comes with a scientific paper on incremental PEG parsing. The goal of flare is to use it for syntax highlighting in the Micro text editor.

One of the difficulties of using parsing expression grammars for syntax highlighting is that you need some way to incrementally reparse the file in order to avoid the slowdown of doing a complete reparse of the whole file for every change.

Another difficulty is that some syntactic elements cannot be parsed with PEGs. For example raw strings in C++ use the form R"abc(hello)abc" where abc can be an arbitrary delimiter.

Solicitor answered 30/3 at 10:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.