Skip to content

Automatically generate VIM and emacs coloring from BNF grammars (Automatically exported from https://code.google.com/p/autohighlight)

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING
Notifications You must be signed in to change notification settings

zoonfafer/autohighlight

 
 

Repository files navigation

autohighlight

Python package

Introduction

(copied and adapted from https://code.google.com/archive/p/autohighlight/)

Of course, converting a context-free grammar to a regular grammar is not possible in the general case; however, practical languages are highly regular (otherwise regex-based syntax highlighting systems like Vim and Emacs wouldn't work at all!)

Autohighlight generates vim and emacs syntax highlighting from a BNF grammar and a description of which terms should be highlighted which colors.

This project originated from a student collaboration between Scotty Allen and Scott Williams at the University of Colorado in 2006.

Overview

To use autohighlighter, first you must generate an autohighlighter file. This file specifies not only the specifics of the language you wish to color, but how you would like that language to be colored.

Syntax

There are three main sections to the autohighlighter file: the gla section, which contains regular expressions for terminal symbols, the concrete syntax tree section, which contains the BNF grammar for the language, and the coloring section, which provides definitions of custom colors, and dictates which portions of the language will be colored which color.

The gla section should consist of lines of the following format:

  identifier: $regularexpression .

The BNF grammar section should consist of lines of the following format:

  symbol: symbol 'literal' symbol .

where the right hand side may be any combination of symbols and literals, with literals enclosed in single quotes.

The coloring section should consist of color definitions, and color mappings. Color definitions are of the form:

  colorname {
      color: red;
      background: blue;
      text-decoration: underline;
  }

The complete list of attributes, with possible values are:

  font-family: <fontname>
  font-style: normal, italic
  font-weight: bold, normal
  font-size: <points>
  text-decoration: underline, overline, line-through, inverse
  color: Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, Brown, DarkYellow, LightGray, LightGrey, Gray, Grey, DarkGray, DarkGrey, Blue, LightBlue, Green, LightGreen, Cyan, LightCyan, Red, LightRed, Magenta, LightMagenta, Yellow, LightYellow, White
  background-color: Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, Brown, DarkYellow, LightGray, LightGrey, Gray, Grey, DarkGray, DarkGrey, Blue, LightBlue, Green, LightGreen, Cyan, LightCyan, Red, LightRed, Magenta, LightMagenta, Yellow, LightYellow, White

Color mappings are of the form:

  colorname: symbol 'literal' symbol .

Usage

Once the autohighlighter file has been generated, it should be given a .ah file suffix. Then, the compiler should be run. The full command line syntax is as follows:

Usage: ./autohighlight [--vim|--emacs] [OPTION]... [FILE]
Generates the specified syntax highlighting files from the given input FILE.

Mandatory arguments:
      --vim            Generate a Vim syntax highlighting file
      --emacs          Generate an Emacs font locking file

Options:
  -h, --help           Print this help
      --error-checking Highlight all symbols not currently being colored as
                       errors (currently works for Vim only)

Advanced options:
      --memoize        Reduce run time for certain tests
      --profile        Print out profiling info

This will yield filename.vim and filename.el files for Vim and Emacs respectively, named with respect to the input file.

Installing the Vim syntax file

To install the generated Vim syntax file, place it in the .vim/syntax directory in your home directory. To activate it, run :set filetype=filename in Vim, where filename is the filename without the .vim ending.

Credits

License

GNU Lesser General Public License 3.0 (See COPYING and COPYING.LESSER)

About

Automatically generate VIM and emacs coloring from BNF grammars (Automatically exported from https://code.google.com/p/autohighlight)

Topics

Resources

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 94.6%
  • Makefile 2.7%
  • Shell 1.4%
  • Nix 1.3%