- Posts: 18
- Thank you received: 0
Syntax Highlighting for HAL in Nano
3 years 4 months ago #273660
by MrRekt
Syntax Highlighting for HAL in Nano was created by MrRekt
I made this as a learning exercise as I read through the HAL man pages. I figured someone here might make use of it - perhaps even help me improve it.
Of course, it'll look different depending on how you have your terminal set up, but on mine it looks like this:
If you haven't already, you'll need to enable syntax highlighting for Nano. One way to do this is by opening /etc/nanorc and finding and un-commenting the second line below:
Then save the following to /usr/share/nano/hal.nanorc :
As you can see, Nano's highlighting rules are limited to regex, but this should be fine for the purposes of a declarative language.
All feedback is welcome - even if it's telling me I'm barking up the wrong tree.
Of course, it'll look different depending on how you have your terminal set up, but on mine it looks like this:
Attachment not found
If you haven't already, you'll need to enable syntax highlighting for Nano. One way to do this is by opening /etc/nanorc and finding and un-commenting the second line below:
Code:
## To include most of the existing syntax definitions, you can do:
# include "/usr/share/nano/*.nanorc"
Code:
## Syntax highlighting for HAL files.
# Note if editing: Precedence of regex impacts how highlighting is displayed.
syntax hal "\.[hH]{1}[aA]{1}[lL]{1}$"
comment "#"
# Formatting for precedence.
color italic,normal "^loadrt.*"
# Read/write names.
color lightmagenta "(read|write)"
# Thread names.
color blue "(servo|base)\-thread"
# Commands.
color italic,blue "^(addf|alias|delf|delsig|getp|gets|ptype|stype|help|linkpp|linkps|inksp|list|loadrt|loadusr|lock|net|newsig|save|setp|ets|show|source|start|status|stop|unalias|unlinkp|unload|nloadrt|unloadusr|unlock|waitusr)"
# Components.
color lightred "([[:space:]]|\,|=)(motion|iocontrol|classicladder|halui|stepgen|encoder|pid|siggen|supply)"
# Axis labels and numaric IDs.
color lightblue "(\.|-|[[:space:]])(x|y|z|a|b|c|u|v|w|[[:digit:]]{1,2})(\.|\,|-|[[:space:]]|$)"
# Formatting for precedence/correction.
color normal "(\.|-|_|,|=)"
# INI references.
color italic,lightyellow "\[\S+]\(\S+\)"
color italic,lightgreen "\[\S+\]"
color lightyellow "\][A-Z0-9\_]+"
color cyan "(\[|\]|\(|\))"
# Thread names.
color blue "(servo|base)\-thread"
# Strings.
color lightcyan start="\"" end="\""
# Numbers and booleans.
color lightmagenta "\s\-?[[:digit:]]+(\.[[:digit:]]+)?"
color lightmagenta "(true|false)"
# Comments.
color lightblack "\#.*"
# Reminders.
color bold,brightblack,yellow "\<FIXME|TODO|XXX)\>"
As you can see, Nano's highlighting rules are limited to regex, but this should be fine for the purposes of a declarative language.
All feedback is welcome - even if it's telling me I'm barking up the wrong tree.
Please Log in to join the conversation.
3 years 4 months ago #273815
by beefy
Replied by beefy on topic Syntax Highlighting for HAL in Nano
That's very good to know.
I often increase the spacing so it's much clearer to my eye.
With this syntax highlighting there won't be as much need to do this.
I often increase the spacing so it's much clearer to my eye.
With this syntax highlighting there won't be as much need to do this.
Please Log in to join the conversation.
- tommylight
-
- Away
- Administrator
-
Less
More
- Posts: 22010
- Thank you received: 3
3 years 4 months ago #273817
by tommylight
Replied by tommylight on topic Syntax Highlighting for HAL in Nano
OK, i juts gave it a try and it works:
Thank you.
Attachment not found
Thank you.
Please Log in to join the conversation.
3 years 4 months ago #273952
by MrRekt
Replied by MrRekt on topic Syntax Highlighting for HAL in Nano
A couple of quick fixes:
- Regex fix where "unload" would match before "unloadrt", which wouldn't highlight the whole word (and similar cases)
- Highlighted axis/numeric parts of names will now be highlighted if only separated by a "." (as in tommylight's screenshot)
- Everything following commands starting with "load" or "unload" will now be italicized unless otherwise formatted (as opposed to just "loadrt")
- Added a couple more components I missed.
Code:## Syntax highlighting for HAL files. # Note if editing: Precedence of regex impacts how highlighting is displayed. syntax hal "\.[hH]{1}[aA]{1}[lL]{1}$" comment "#" # Formatting for precedence. color italic,normal "^(un)?load.*" # Read/write names. color lightmagenta "(read|write)" # Thread names. color blue "(servo|base)\-thread" # Commands. color italic,blue "^(unalias|unlinkp|unload|unloadrt|unloadusr|unlock|addf|alias|delf|delsig|getp|gets|ptype|stype|help|linkpp|linkps|inksp|list|loadrt|loadusr|lock|net|newsig|save|setp|sets|show|source|start|status|stop|waitusr)" # Components. color lightred "([[:space:]]|\.|\,|=)(motion|iocontrol|classicladder|halui|stepgen|encoder|parport|pid|siggen|spindle|stepgen|supply)" # add hal_.+[[:space:]] ? # Axis labels and numaric IDs. color lightblue "((\.|-|[[:space:]])(x|y|z|a|b|c|u|v|w|s|[[:digit:]]{1,2}))+(\.|\,|-|[[:space:]]|$)" # Formatting for precedence/correction. color normal "(\.|-|_|,|=)" # INI references. color italic,lightyellow "\[\S+]\(\S+\)" color italic,lightgreen "\[\S+\]" color lightyellow "\][A-Z0-9\_]+" color cyan "(\[|\]|\(|\))" # Thread names. color blue "(servo|base)\-thread" # Strings. color lightcyan start="\"" end="\"" # Numbers and booleans. color lightmagenta "\s\-?[[:digit:]]+(\.[[:digit:]]+)?" color lightmagenta "(true|false)" # Comments. color lightblack "\#.*" # Reminders. color bold,brightblack,yellow "\<;(FIXME|TODO|XXX)\>"
Let me know as you find other things to be improved.
Please Log in to join the conversation.
Time to create page: 0.101 seconds
