Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate TextMate language grammar from PEG.js grammar

Is there a tool that translates a PEG.js grammar to a TextMate grammar?

I am building my own language and would like to have syntax highlighting for it in my preferred editor, TextMate. The grammar of my language is built with PEG.js. According to the TextMate documentation for this use-case, I have to write the TextMate grammar in a form that is incompatible with PEG.js.

I started writing a new TextMate grammar, but I quickly noticed that it takes quite a while to translate the whole grammar, or even the subset relevant for an acceptable syntax highlighting. Since I am incredibly lazy and don't want to do all this tedious work, I thought about automating this task.

Can anyone give me any clues how to automate, or at least speed up, the generation of TextMate grammar from a PEG.js grammar?

like image 788
Manuel Leuenberger Avatar asked Feb 02 '13 18:02

Manuel Leuenberger


1 Answers

Can anyone give me any clues how to automate, or at least speed up, the generation of TextMate grammar from a PEG.js grammar?

Use the following process:

  • Understand Regular Expressions
  • Understand Parsing Expression Grammars
  • Create a mapping table based on the similarities
  • Create functions based on the differences

References

  • Problems with an ambiguous grammar and PEG.js (no examples found)

  • What is the best way to define grammars for a text editor?

  • What are the differences between PEGs and CFGs?

like image 192
3 revs Avatar answered Oct 21 '22 02:10

3 revs