Parsers

A parser is an editor extension that acts interactively on a document to improve the presentation of the data in that document.  A parser uses colors and fonts to highlight different items in a programming language source document.  For example, language keywords are highlighted in one color, variable names in another, and string literals in yet another.  The original indentation of the program code is maintained.  The editor comes with a selection of parsers for common programming languages.

Using a Parser

When you open a file, the editor checks whether the file name extension of that file is associated with a parser.  For example, the editor comes configured to recognize and parse C/C++ program files.  If you open a file called sample.c, the editor invokes the C/C++ parser.  If you open a file called sample.asm, the editor invokes the HLASM parser.

Typically, the parser will:

Elements, Classes, and Styles

In a programming language source document, each line is an element.  An element class definition describes the type of data the element contains.  An element may contain more than one element class.  The element displayed below includes the code and comment classes.

The style of an element determines the way an element will be displayed.  The parser sets a string of style characters that is equal in length to the text of the element.  The editor draws each character of an element text with the attributes of the style character that is in the corresponding position in the element style string.  The style of the element displayed below includes keyword, layout blank, punctuation, identifier, operator, quoted string, and comment style characters.

  code class comment class
Line of C code, element text
Element style
 if (x == "test")  
 kk_pi_oo_qqqqqqp_ 
/*test for x*/
cccccccccccccc

Live Parsing

The editor monitors and records all the changes that you make to a document.  As you complete each line, the editor examines that line for constructs specific to the type of document being edited.  For example, in a C program, the parser recognizes the text between an open-comment marker (/*) and a close-comment marker (*/) as being comments.  It displays those comments in the color specified for the comment style character, and marks the lines with the comment element class.

Using a Parser's Pop-up Menu

A parser may add its own selections to the editing pane's pop-up menu, specifying which elements are displayed in the document or adding actions specific to the type of document being edited.  For example, you can select the Filter view->Functions selection from the pop-up menu to display only function headers in a C/C++ document.