Generate TextMate language grammar from PEG.js grammar
Asked Answered
Z

1

17

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?

Zumwalt answered 2/2, 2013 at 18:39 Comment(3)
github.com/alexstrat/PEGjs.tmbundleBottali
This bundle only adds syntax highlighting for PEG.js grammar files. What I want is syntax highlighting for files that are written in a language defined by a PEG.js grammar.Zumwalt
Unfortunately this would be hard - TextMate uses patterns whereas PEG.js uses byte-based comparisons.Sarisarid
M
4

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

Mutinous answered 2/2, 2013 at 18:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.