natl / language-geant4-macro

Atom syntax highlighting for Geant4 macros
MIT License
5 stars 3 forks source link

Highlight {aliases} #13

Open janpipek opened 8 years ago

janpipek commented 8 years ago

Sorry for another feature idea...

It would be nice to have the {aliases} (as defined by /control/alias) highlighted. Is it a difficult pattern-matching task?

P.S. Actually, I am thinking about digging into the code myself now that I am coming with so many requests ;-)

natl commented 8 years ago

I haven't considered aliases too much in the past. It might be possible, I think you need to build a dictionary of your current aliases and then add a grammar rule that matches them.

But currently all the grammar rules are defined statically just by matching certain regex expressions. See: https://github.com/natl/language-geant4-macro/blob/master/grammars/geant4-macro.cson for example.

If you can recognise an alias by a distinct regular expression, it is very easy. If you need a dictionary of aliases to be built as you type, things could get significantly harder.

As for contributing, feel free to. Coffescript is actually quite nice once you get used to how it looks. Check out http://coffeescript.org/ for a primer.

janpipek commented 8 years ago

Aliases are recognized quite easily, based on reg.exp. - it's just {alias_name}, What is questionable, is what exactly is allowed to be in the braces (just letters? spaces? underscores? numbers?). I will check on this and update the .cson file accordingly. But sounds like something to be best done at work :-)

janpipek commented 8 years ago

The parsing of alias names in Geant4 is really weird:

So from that point of view, the highlighting is not perfectly matching Geant4 - I kept it simple, highlighting only "reasonable" aliases.