Extending a Language


#1

Is there a decent way to extend a language based on another?

I’d like to develop “language” backends for a few formats that rely on JSON or YAML.


#2

I’m not super savvy on how to do it, but it is possible.

Take a look at the language-gfm package: https://github.com/atom/language-gfm/blob/master/grammars/gfm.cson

There are patterns that match codeblocks, and the lines within those codeblocks are syntaxhighlighted, with something like 'patterns': ['include': 'source.js'].


#3

@gjtorikian Is essentially correct, but the syntax is wrong. To find out specifically what you need is to lookup the language package you want to extend and find the scopeName. So for JSON the scope name is source.json and YAML is source.yaml. You need to make sure patterns is an array of objects.

'patterns': [
      {
        'include': 'source.json'
      }
      {
        'include': 'source.yaml'
      }
]

Edit: After looking at other packages, the syntax @gjtorikian posted may be correct. However, when I read the docs about syntax highlighting it always uses an object ad that’s what I used (which works 100%). I am not very savvy with Coffee script, so maybe it compiles into the same thing. Others can chime if I am incorrect.


#4

@objectivehtml, @gjtorikian - That’s exactly what I was hoping for! I went ahead and released language support for IPython notebooks via language-ipynb.

I’m a javascript and coffeescript novice, so hopefully this makes me beef up some skills.


#5

I need some help extending from another language.

I’m trying to fix a special case for a language that is very similar to Java, (Salesforce APEX); if someone could give me a hand I’ll be very grateful, I don’t quite understand how to fix it.

Main issue is reported here but it seems that project has been abandoned.

The problem seems to be that in Java, the new keyword is only used for object instantiation, in Apex it’s also used for the purpose mentioned in the issue.