We use Iro for generating syntax grammars for multiple text editors in one go.
See Lama2.iro for the source syntax grammar.
Source file: textmate.plist
Iro generates a Textmate syntax file in the Plist format. We
must convert the Plist file into JSON using wtools. If the converted output is wrapped up in a list [], then remove that part. After removing
unnecessary junk, we will have a nice syntax JSON of the form {}. See the VSCode plugin, particularly package.json and syntaxes/lama2.tmGrammar.json
UPDATE: After adding request chaining, the generated plist doesn't work as is (with the above minor mods). It took a difficult 5h debugging session to find many issues with how textmate syntax handles line-ends. The present grammar json file in VSCode is heavily modified from the original.
Learnings:
- "Chaining begin/end" so that "end" tokens are properly consumed ref1
- Exploiting oniguruma regex implementation (particularly lookbehind). Iro doesn't support lookbehind. But VSCode-oniguruma does thankfully. ref2
For interative usage, head over to iro web.
Post the source file lama2.iro into the editor.
Load up a sample lama2 doc, and hit the play button.
Following are some other useful resources related to Iro:
- Open source CLI version: https://github.com/c272/iro4cli
- Tutorial from author: https://medium.com/@model_train/creating-universal-syntax-highlighters-with-iro-549501698fd2
- Iro Documentation: https://eeyo.io/iro/documentation/