Sumarry :

  1. Creating a custom syntax file

Syntax files

Syntax file creation is rather straightforward once you know how they are structured. The purpose of this small example is to cover that topic as extensively as possible.

Core concepts

There are two fundamental notions in QCE syntax files : contexts and "regular" matches.

The concept of context is extremely powerful while remaining extremely simple. The syntax engine enters a context when a given start token is matched and it leaves it when a stop token is matched. Within a context there can be any number of contexts and "regular" matches. contexts are typically used to match comments, strings or other special blocks of code.

"Regular" matches are what one would expect them to be : simple tokens. They can be matched from either regular expressions or plain strings. Start and stop tokens of context are "regular" matches in a way, except that they also trigger the context enter/leave event.

Syntax file structure

Now, on to the analysis of the structure of a syntax file.

The root element of the document is a <QNFA> tag. It provides various informations in its attributes.

The QNFA tag represents the root context of the language. It can contain any number of the following tags :

Additionally, the following tags are valid inside a context block (and, again, their number isn't limited). Also note that, while ordering of all tags above within a context DO matter, ordering of the tags below DO NOT matter.

All these tags, except embed, support the following attributes :

Additionally all tags, except context and list, support the following extra attributes :

The context tag however supports the following extra attributes :

Regexp format

The regexp format used by QCE is near to that used by QRegExp but with some slight variations.

First of all, a list of QRegExp features not supported in syntax files :

Then, character classes (word, space, digit and their negation) use the same "specific character" (respectively w, s, d and uppercase) but a different prefix character ($ instead of \).

C-style escaping is used. Simple C escapes (for newlines and tab) are converted properly and C-style escaping is used to escape control characters.

Sets and negated sets are supported, using the same syntax as QRegExp.

Regular regexp operator '?', '*' and '+' are supported.

A revision of the syntax format may bring grouping and alternation support (and possibly other niceties) in a future version but as this would break backward compat (due to escaping issues among other things) and require a rewrite of the syntax engine a new (but very similar) syntax file format would be used.

Getting your hands dirty (coming soon)

Now that the fundamentals have been covered, let's use them to create a small syntax file for an imaginary language.

More examples availables in the qxs/ directory where all syntax files reside.

Generated on Sun Feb 15 22:50:19 2009 for QCodeEdit by  doxygen