Syntax Highlighting for MATRIXx

Publish Date: Jan 23, 2007 | 0 Ratings | 0.00 out of 5 |  PDF

Overview

MATRIXx has two text-based programming languages: MathScript and Template Programming Language (TPL). MathScript is used in Xmath and TPL is used by AutoCode and DocumentIt. Syntax highlighting can be used in either language to make it more readable. Through syntax highlighting, writing and understanding code becomes easier. This application note will describe what you need to know to configure a syntax highlighter for use with MATRIXx. Each program has a different way of specifying the information, so consult the documentation for the text editor for help.

Table of Contents

  1. Introduction to Syntax Highlighting
  2. MathScript and TPL Rules
  3. MathScript and TPL Keywords
  4. Common Limitations

1. Introduction to Syntax Highlighting

Instead of giving all the text the same color, syntax highlighting colors different parts of the code in different colors. For example one color can be assigned to comments, another to strings, and a third color to keywords that correspond to function names. The color makes it easy, for example, to identify the beginning and end of a comment.


Syntax highlighting programs look for a set of rules that define the structure of the language and a set of keywords. The rules define things such as what marks the beginning and ends of a single line comment, multi-line comments and strings. The keywords can be functions, commands, and operators that have special meaning in the language.

Back to Top

2. MathScript and TPL Rules


Syntax highlighters use rules to identify standard parts of the code. The character combination to mark the beginning of a comment is different in different programming languages. Syntax highlighters will look for the characters that mark single line comments, multi-line comments, strings, and escape characters in strings. It also will need to know if keywords are case-sensitive or not.

The following table give the rules for MathScript and TPL.
Description MathScript TPL
Single line comment # @/
Multi-line comment - begin #{ @*
Multi-line comment - end }# *@
String " "
String Escape Character " \
Multi-line String no no
Code Start/End not used @
EOL Escape Character not used @
Case Sensitive no* yes

*MathScript is case sensitive for variable names but not for built-in function names. For the purposes of syntax highlighting MathScript is not case sensitive, since case sensitivity determines if a word is a keyword.

Back to Top

3. MathScript and TPL Keywords


In addition to identifying blocks of code, the syntax highlighter can identify specific keywords. Usually several sets of keywords can be specified, with each set having a different color. For example programming constructs such as for, while, and if can be given one color and functions a different color.

The keywords for MathScript are given below as four files. The first file contains intrinsic functions, programming constructs, and built-in variable names. The second file contains functions that only require Xmath. The third contains functions that require a license for one of the Xmath modules. The fourth file requires a license for SystemBuild, a SystemBuild module, AutoCode, or DocumentIt.

The keywords for TPL are given below as three files. The first file contains programming constructs. The second file contains built-in tokens, such a currentdate_s for the current date. The third file contains built-in functions.

Back to Top

4. Common Limitations


Each syntax highlighting program will have its own limitations, so it may not be possible to perfectly implement the MathScript or TPL rules.

Many syntax highlighters do not handle the use of a quote (“) for the beginning and end of a string as well as it’s escape character. Most syntax highlighters will interpret the string “Line one”nLine two” as ending after one. Because MathScript strings are limited to a single line, the error in coloring should be limited to the rest of the line, provided the program has an option to limit strings to a single line. MATRIXx allows functions and commands to be abbreviated. This is not encouraged for MathScript functions and commands and most syntax highlighters will only recognize the name of the function or keyword when it is spelled out completely.

The use of the at symbol (@) in TPL was chosen because @ is not common in other languages. However the repeated use of @ confuses most syntax highlighters. TPL has three main types of text: comments, plain text, and TPL code. Ideally each one should be assigned a different color. Usually highlighting comments in one color and ignoring the difference between plain text and code gives the best results. Because most TPL statements consist of a combination of functions and tokens and very little additional code, the TPL code will still stand out.

Back to Top

Bookmark & Share

Ratings

Rate this document

Answered Your Question?
Yes No

Submit