Document parsers
A document parser is an editor extension that interacts with a document to improve editing and 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 base editor comes with a selection of parsers for common programming languages. Additional document parsers and language-sensitive functionality may be provided by LPEX-based editor applications.
Use a Parser
When you open a file, the editor checks whether its file name extension is associated with a parser. For example, the editor comes configured to recognize and parse C/C++ program source files. If you open a file called sample.c, the editor invokes a C/C++ document parser. If you open a file called sample.cbl, the editor invokes a COBOL document parser.
Typically, the parser will:
- Set default fonts and colors
- Color and emphasize the data being displayed
- Set up special actions for keys
- Set up language-specific additions to the menus of the editor view.
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 usually the same length as the text of the element. The editor draws each character of the 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, punctuation, identifier, operator, quoted string literal, 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 document parser may add its own selections to the editor view'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 Filter view > Functions from the pop-up menu to display only function headers in a C/C++ document.
parser parameter
updateProfile.extensions parameter
updateProfile.noParser parameter
updateProfile.parserAssociation parameter
updateProfile.parserClass parameter
updateProfile.parsers parameter
updateProfile.parser parameter