Month: February 2011

Lex and Yacc syntax highlighting for Nano

There’s not a lot to them, but it’s better than anything I could find on the Internet. The real key feature is a line in the yacc syntax highlighting file that marks whitespace at the end of lines. Since yacc/bison are sensitive to that, it’s good to be able to see it.

Nano syntax highlighting for yacc or bison:

## Syntax highlighting for yacc/bison input files
syntax "yacc" ".y$"
color red "%[a-zA-Z0-9]*"
## String highlighting.  You will in general want your comments and
## strings to come last, because syntax highlighting rules will be
## applied in the order they are read in.
color brightyellow "<[^=        ]*>" ""(\.|[^"])*""
## This string is VERY resource intensive!
color brightyellow start=""(\.|[^"])*\[[:space:]]*$" end="^(\.|[^"])*""
## Comments
color brightblue start="/*" end="*/"
## Visible space at line ends
color green,green "[[:space:]]+$"

Nano syntax highlighting for Lex or Flex:

## Syntax highlighting for lex/flex input files
syntax "lex" ".l$"
color red "%[^[[:space:]]]*"
## String highlighting.  You will in general want your comments and
## strings to come last, because syntax highlighting rules will be
## applied in the order they are read in.
color brightyellow "<[^=        ]*>" ""(\.|[^"])*""
## This string is VERY resource intensive!
color brightyellow start=""(\.|[^"])*\[[:space:]]*$" end="^(\.|[^"])*""
## Comments
color brightblue start="/*" end="*/"