LPEX
4.4.0

com.ibm.lpex.core
Class LpexCommonParser

java.lang.Object
  extended by com.ibm.lpex.core.LpexCommonParser
All Implemented Interfaces:
LpexConstants, LpexParser
Direct Known Subclasses:
CobolParser, CppParser, FortranParser, HtmlParser, JavaParser, JclParser, PliParser, PropertiesParser, RexxParser, SqlParser, TestParser1, TestParser2, XmlParser, XslParser

public abstract class LpexCommonParser
extends Object
implements LpexParser, LpexConstants

LpexCommonParser is a base, abstract class for document parsers. It adds several services to the LpexParser interface, simplifying document-parser development, and provides methods for a common look-and-feel to the parsers extending it. Certain methods in the basic LpexParser interface are not used by parsers extending LpexCommonParser.

A document parser is associated with one particular view of a document. Different views of the same document may be handled by different parsers. There is up to one instance of this class for each document view.

Constructor

The parser must have a constructor whose parameter is the associated document view, as shown below:

 
 public class MyLpexParser extends LpexCommonParser 
 {
  public MyLpexParser(LpexView lpexView)
  {
   super(lpexView);
   // rest of MyLpexParser constructor...
  }
  // rest of MyLpexParser...
 } 

The document view associated with this parser instance can be retrieved with lpexView().

Life cycle

This is the life cycle of an LPEX document parser:

The process above takes place for each edit session of a document view, whenever there is a parser associated with that document type or a parser is explicitly specified.  It also takes place any time the updateProfile command is run in a view, either called explicitly or as a result of other actions (such as a document reload).

This makes it important to handle the parser termination and reinstantiation correctly, especially when there are other resources and tools initiated from, or associated with, the document parser.  Document models that are updated solely on the basis of information provided by the parser calls, should be refreshed when a document parser is (re)instantiated.

Total and incremental parse

There are two main callback methods in a document parser:

Changes to the document carried out during parsing are not recorded in the parse-pending list of elements.

Styles

The basic tokenization of the document text is done by setting styles. The style of an element determines the way the element is 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. This provides syntax coloring of the document, and delimits tokens for other purposes, such as word selection.

The styles also break the line of text into separate segments for painting. These discrete segments override the default behaviour of text layout algorithms. For example, bidirectional reordering can happen within a token, but not between two adjacent tokens.

Editor actions

Several default editor actions are modified by parsers that extend LpexCommonParser:

Action and its assigned key added by LpexCommonParser-based parsers:

Keys already defined (for example, by the active base profile) to an action different from nullAction are not redefined in here.

The proto action expands a prototype word at the current document location using the template defined in the active document parser. The cursor is set to the position of the first '?' encountered in the expansion, if any. The expansion string is obtained through a call to getProperty(), with the prototype word found at the cursor (and delimited by white space or token-delimiter characters), prefixed by "proto.", as the key argument. For example, if the cursor is located on the word "if" in a C/C++ source document, the value of the CppParser property "proto.if" is used for the expansion. Argument substitution(s) required in the expansion string should be carried out by the parser, and the final string should be returned by its implementation of method getProperty(). When the document is empty, the proto action uses the key PROTOKEY_EMPTY, if an expansion value is defined for it, to set up an initial text to serve as the basic structure for the document.

Embedded messages

The API for accessing the contents of the view being parsed, and in general the operation of most document parsers, use element ordinal numbers exclusively. Therefore, special care should be taken when modifying the contents of the document while processing the parseAll() and parseElement() calls. In general, this should be avoided. See Lines and elements.

During parsing, embedded error and informational messages (which use show lines) should only be added and removed with LpexCommonParser's addMessage(), removeMessages(), addDocumentMessage(), and removeDocumentMessages(), methods. Outside parsing, these methods should not be used.

See also Multiple document views for additional considerations when several views are opened on a document.

Parser properties

Parser properties are parser-specific settings. Certain common parser properties are used by LpexCommonParser and are, therefore, in effect in all the parsers that extend it:

The default scope of a parser property is the document parser for which it is defined. Any instance of the parser in any document view will use the same property value, unless overridden by a document- or view-scoped setting. Document-scoped parser properties are prefixed with "document.". View-scoped parser properties are prefixed with "view.". For example, the value of the autoIndent setting used by a specific instance of a document parser may be changed by the view.autoIndent parser property.

Parser properties may be defined at several levels.

Most parser properties are also accessible through the parserProperty editor parameter. A parser may listen to changes effected to any of its properties by extending propertySet().

See getProperty() and setProperty() for additional information on parser properties.

Multiple document views

As there may be several views opened on the same document, each view being associated with a different parser instance, but most commonly document parsers of the same type, several features should be carefully considered. Remember, the incremental parse callback will be invoked in all the parsers associated with the document, on every completed change to the text of the document.

Related method: isPrimaryParser(). Related editor parameters: documentId, documentViews, multipleViews, viewId.

Language-sensitive help

LpexCommonParser provides a few basic services for the implementation of language-sensitive help (LSH) on any platform:

Mixed content documents

Source files opened in the editor may contain several distinct content types. Examples of mixed content documents, in which there is a main language and one or more secondary languages or scripts include: C/C++ source code with embedded SQL and/or CICS statements, Java source code with embedded SQL, and HTML code with JavaScript sections.

In these cases, the parser for the main language (normally installed through the file name extension - parser association mechanism) invokes the appropriate subparsers (secondary parsers) for those sections of the document that contain other types of content. Several document parsers shipped with LPEX are designed in this manner: C/C++, COBOL, PL/I, and Java document parsers support embedded SQL and CICS statements. The full set of context-sensitive services which is ordinarily provided by a document parser written specifically for a language as the main, or unique, document language becomes thus available for all the different sections of the document.

Being done under the full control of the main document parser, a well-integrated functionality and look is achieved. The document parser defines and registers with the editor the styles and the element classes for use by all the subparsers in the document context supported. A subparser can query the main document language to determine, for example, the end-of-construct it must detect, the type of comments which should be accepted, etc. For example, the SQL subparser may detect the end of embedded SQL by a semicolon ';' in a C/C++ and PL/I document, and an "END-EXEC" token in a COBOL document. Comments acceptable in the main language, preprocessed (removed) before the source is passed on to the secondary language compilers or interpreters, must also be accepted by the secondary document parsers.

LpexCommonParser defines a generic set of return codes which may be used for communication between the main parser and the subparsers: LEXER_RC_OK, LEXER_RC_EOF, LEXER_RC_END, and LEXER_RC_MORE. Each parser may contribute its own items to the pop-up menu. Method getLanguage(LpexDocumentLocation) is provided to query the document content type at a specific location.

Bidi support

For general information on multicultural support in LPEX, see LpexNls. Some considerations for bidirectional language support in document parsers are detailed in here.

Example

An example of developing a simple document parser is available in the samples package.  See TestParser1 and TestParser2.


Field Summary
static String ATTRIBUTES_COMMENT
          Style attributes for comment/remark tokens.
static String ATTRIBUTES_COMMENT_KEYWORD
          Style attributes for special keywords inside comments.
static String ATTRIBUTES_COMMENT1
          Additional style attributes for comment/remark tokens.
 String ATTRIBUTES_DEFAULT
          Common default style attributes.
static String ATTRIBUTES_DIRECTIVE
          Style attributes for compiler directives.
static String ATTRIBUTES_ERROR
          Style attributes for errors (white background red squiggle underline, like other eclipse editors).
static String ATTRIBUTES_ERROR1
          A less intrusive style attributes for errors (red squiggle).
static String ATTRIBUTES_KEYWORD
          Style attributes for language keywords.
static String ATTRIBUTES_KEYWORD1
          Additional style attributes for language keywords.
static String ATTRIBUTES_LIBRARY
          Style attributes for library-related tokens.
static String ATTRIBUTES_NONSOURCE
          Style attributes for text which does not constitute part of the source proper.
static String ATTRIBUTES_NUMERAL
          Style attributes for numerals.
static String ATTRIBUTES_STRING
          Style attributes for quoted strings.
static String ATTRIBUTES_STRING1
          Additional style attributes for quoted strings.
static String BACKGROUND_COLOR
          Common background color.
static String CLASS_MESSAGE
          Common element class reserved for error messages.
static String LANGUAGE_CCPP
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_CICS
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_CL
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_COBOL
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_COBOL400
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_COBOLILE
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_DDS
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_DLI
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_FORTRAN
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_HLASM
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_HTML
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_JAVA
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_JCL
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_LISP
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_PERL
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_PLI
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_REXX
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_RPG
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_RPGLEFIXED
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_RPGLEFREE
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_SABRETALK
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_SQL
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_XMI
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_XML
          Predefined string for the language or document type supported by a parser.
static String LANGUAGE_XSL
          Predefined string for the language or document type supported by a parser.
static int LEXER_RC_END
          Return code from a subparser's token processing indicating the end of its job.
static int LEXER_RC_EOF
          EOF (end-of-file) flag in the return code from a subparser's token processing.
static int LEXER_RC_MORE
          More-input flag in the return code from a subparser's token processing.
static int LEXER_RC_OK
          Successful return code from a subparser's token processing.
static int POPUP_END
          Indication for parser items at the end of the popup.
static int POPUP_FILTERVIEW
          Indication for parser items in the "Filter view" submenu of the popup.
static int POPUP_SOURCE
          Indication for parser items in the "Source" submenu of the popup.
static int POPUP_TOP
          Indication for parser items at the top of the popup.
static String PROTOKEY_EMPTY
          Key for action proto in an empty document.
static char STYLE_MESSAGE
          Common style reserved for parser messages.
static String STYLE_NAME
          Prefix for the styleName.styleCharacter parser properties.
protected  LpexView view
          The view with which this document parser is associated.
 
Fields inherited from interface com.ibm.lpex.core.LpexConstants
HELP_COMMAND_MAP, LPEX_VERSION, MSG_POPUP_COMMENT, MSG_POPUP_ERRORS, MSG_POPUP_EXCLUDESELECTION, MSG_POPUP_FILTERVIEWMENU, MSG_POPUP_INSERTMENU, MSG_POPUP_SELECTEDMENU, MSG_POPUP_SHOWALL, MSG_POPUP_SOURCEMENU, MSG_POPUP_TASKS, MSG_POPUP_UNCOMMENT, PARSE_PENDING_CHANGE_MASK, PARSE_PENDING_INSERT_MASK, PARSE_PENDING_NEXT_DELETED_MASK, PARSE_PENDING_NEXT_SHOW_DELETED_MASK, PARSE_PENDING_PREV_DELETED_MASK, PARSE_PENDING_PREV_SHOW_DELETED_MASK, PARSE_PENDING_UNDO_MASK, PLATFORM_AWT, PLATFORM_SWT, PLATFORM_SWT_KEY, SHOW_ALL, SHOW_DOCUMENT, SHOW_NONE, SHOW_VIEW, STATUS_FIELDS_NOINSERT, STATUS_FIELDS_TRUNCATE, STATUS_FILE_ERRORREADING, STATUS_FILE_INCORRECTENCODING, STATUS_FILE_NOTFOUND, STATUS_FINDTEXT_INVALIDPATTERN, STATUS_FINDTEXT_NOTFOUND, STATUS_FINDTEXT_ONLYOCCURRENCE, STATUS_FINDTEXT_READONLY, STATUS_FINDTEXT_WRAPPED, STATUS_LOCATE_NOSEQUENCETEXT, STATUS_LOCATE_NOTFOUND, STATUS_LOCATE_WRAPPED, STATUS_SAVE_CANCELLED, STATUS_SAVE_FAILED, STATUS_TEXTLIMIT_ENFORCED, STATUS_TEXTLIMIT_OVERFLOW, STATUS_UNDO_NOTHINGUNDONE
 
Constructor Summary
protected LpexCommonParser(LpexView lpexView)
          LpexCommonParser constructor.
 
Method Summary
protected  void addDocumentMessage(int element, String text, String messageClass, char messageStyle)
          Displays an embedded error or informational message for an element in all the views of the document.
protected  void addMessage(int element, String text)
          Displays an embedded parser error or informational message for an element.
protected  void addMessage(int element, String text, long messageClass)
          Displays an embedded parser error or informational message for an element.
protected  void addMessage(int element, String text, long messageClass, char messageStyle)
          Displays an embedded parser error or informational message for an element.
protected  void blockMarkWord()
          Implements the redefined editor action blockMarkWord.
static boolean copyDocumentMessages(LpexView targetView, int sourceViewId, String messageClass)
          Convenience method to copy the document messages from an existing view.
 int cursorIndent(int element)
          Returns the indent display column of the cursor in the element.
protected  boolean defineFilterAction(String actionName, String includedClasses)
          Convenience method to define an action for the "Filter view" menu.
protected  boolean defineFilterAction(String actionName, String includedClasses, String excludedClasses)
          Convenience method to define an action for the "Filter view" menu.
protected  void expandProtoKeyword(int s, int e, String p)
          Carries out the keyword expansion for the proto action.
 String getCommentStyleCharacters()
          Returns the style character(s) used by this parser for comments.
 ArrayList<String> getInstallStyleAttributes()
          Returns the install attributes for the style characters defined by this document parser.
 String getLanguage()
          Returns a string identifying the language or document type supported by this document parser.
 String getLanguage(LpexDocumentLocation loc)
          Returns a string identifying the language segment at the specified location.
 String getLshToken()
          Returns the current token for language-sensitive help (LSH).
protected  String getPopupItems(int popupLocation)
          Returns this parser's items for the pop-up (context) menu.
 ResourceBundle getProfile()
          Returns this document parser's profile.
 String getProperty(String key)
          Returns a parser property.
 String getStyleName(char styleCharacter)
          Returns the locale-sensitive description of a style defined by this document parser.
 String getStyles()
          Returns the style characters defined by this document parser.
 String getTextIndent(int element)
          Returns the desired indent string for the text in the specified element.
 String getToken(LpexDocumentLocation loc)
          Returns the language token at the specified document location.
 LpexDocumentLocation getTokenLocation(LpexDocumentLocation loc)
          Returns the start of the language token at the specified document location.
 int indentText(int element)
          Positions the text of an element to the correct indent value.
 int indentText(int element, int desiredIndent)
          Positions the text of an element to the specified indent value, given as the column position of the text indented by leading blanks.
 int indentText(int element, String desiredIndent)
          Positions the text of an element to the specified indentation.
protected  void initParser()
          This parser is being initialized.
 boolean isDebuggable(int line)
          Query whether the specified document line is debuggable.
 boolean isPrimaryParser()
          Convenience method to determine whether this is considered the primary parser for the document.
 boolean isTokenDelimiter(char c)
          Returns whether the specified character is a token delimiter.
 boolean isWordCharacter(int element, int position)
          Returns whether the character at the given position in the given element is to be considered part of a word.
 void lineComment(String text, boolean comment)
          Generic utility method to comment / uncomment lines.
 LpexView lpexView()
          Returns the document view with which this parser is associated.
protected  LpexDocumentLocation matchToken(LpexDocumentLocation loc)
          Matches the token found at the specified document location.
protected  void newLine()
          Implements the redefined editor action newLine.
protected  void openLine()
          Implements the redefined editor action openLine.
 void parse(int element)
          N/A - Method in the LpexParser interface; a document parser extending LpexCommonParser only implements parseElement(int).
abstract  void parseAll()
          Total parse.
abstract  void parseElement(int element)
          Incremental parse.
protected  void propertySet(String key)
          The named parser property was set in the scope of this document parser instance.
protected  void removeDocumentMessages(int fromElement, int toElement, String messageClass)
          Removes from all the views of the document the embedded messages of the specified element class(es) for the given range of text elements.
protected  void removeMessages(int fromElement, int toElement)
          Removes this parser's default messages for a given range of elements.
protected  void removeMessages(int fromElement, int toElement, long messageClass)
          Removes this parser's embedded messages of the specified element class(es), for the given range of text elements.
 void resetParser()
          N/A - Method in the LpexParser interface; a document parser extending LpexCommonParser only implements, if needed, terminateParser().
 void setProperty(String key, String value)
          Sets, updates, or restores a parser property.
 void setStyle(String styles, String installAttributes)
          Defines the styles used by the parser for a token or set of tokens.
protected  void splitLine()
          Implements the redefined editor action splitLine.
 String styleString(char style, int len)
          Utility method to return a style string for a len-long token.
protected  void terminateParser()
          This parser is being terminated and disposed.
protected  LpexDocumentLocation tokenBegin(LpexDocumentLocation loc)
          Returns the start of a token at the specified document location.
protected  LpexDocumentLocation tokenEnd(LpexDocumentLocation loc)
          Returns the end of a token at the specified document location.
 void totalParse()
          N/A - Method in the LpexParser interface; a document parser extending LpexCommonParser only implements parseAll().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

view

protected LpexView view
The view with which this document parser is associated.

See Also:
lpexView()

CLASS_MESSAGE

public static final String CLASS_MESSAGE
Common element class reserved for error messages. Embedded error and informational messages displayed (as show elements) in the edit view will be by default assigned this element class.

It is defined as "Message". The parser should not define an element class with this name.

See Also:
Constant Field Values

STYLE_MESSAGE

public static final char STYLE_MESSAGE
Common style reserved for parser messages. Embedded error and informational messages displayed (as show elements) in the edit view will be by default assigned this style.

Defined as 'M'. The parser should not define this style for tokens.

See Also:
Constant Field Values

LANGUAGE_CCPP

public static final String LANGUAGE_CCPP
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_CICS

public static final String LANGUAGE_CICS
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_CL

public static final String LANGUAGE_CL
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_COBOL

public static final String LANGUAGE_COBOL
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_COBOL400

public static final String LANGUAGE_COBOL400
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_COBOLILE

public static final String LANGUAGE_COBOLILE
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_DLI

public static final String LANGUAGE_DLI
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_DDS

public static final String LANGUAGE_DDS
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_FORTRAN

public static final String LANGUAGE_FORTRAN
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_HLASM

public static final String LANGUAGE_HLASM
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_HTML

public static final String LANGUAGE_HTML
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_JAVA

public static final String LANGUAGE_JAVA
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_JCL

public static final String LANGUAGE_JCL
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_LISP

public static final String LANGUAGE_LISP
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_PERL

public static final String LANGUAGE_PERL
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_PLI

public static final String LANGUAGE_PLI
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_REXX

public static final String LANGUAGE_REXX
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_RPG

public static final String LANGUAGE_RPG
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_RPGLEFIXED

public static final String LANGUAGE_RPGLEFIXED
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_RPGLEFREE

public static final String LANGUAGE_RPGLEFREE
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_SABRETALK

public static final String LANGUAGE_SABRETALK
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_SQL

public static final String LANGUAGE_SQL
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_XMI

public static final String LANGUAGE_XMI
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_XML

public static final String LANGUAGE_XML
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

LANGUAGE_XSL

public static final String LANGUAGE_XSL
Predefined string for the language or document type supported by a parser.

See Also:
getLanguage(), Constant Field Values

PROTOKEY_EMPTY

public static final String PROTOKEY_EMPTY
Key for action proto in an empty document. Defined as "proto.%EMPTY%".

See Also:
Constant Field Values

STYLE_NAME

public static final String STYLE_NAME
Prefix for the styleName.styleCharacter parser properties. Defined as "styleName.".

See Also:
getStyleName(char), Constant Field Values

BACKGROUND_COLOR

public static final String BACKGROUND_COLOR
Common background color. Defined as "255 255 255" (white). A document parser should normally define its style attributes with this background color (like most ATTRIBUTES_xxx defined in here), and use LpexPaletteAttributes to convert them to the active palette.

See Also:
setStyle(java.lang.String, java.lang.String), LpexPaletteAttributes, Constant Field Values

ATTRIBUTES_DEFAULT

public final String ATTRIBUTES_DEFAULT
Common default style attributes. These are also the style attributes set for all style characters when the parser property tokenHighlight is "off".

See Also:
setStyle(java.lang.String, java.lang.String)

ATTRIBUTES_COMMENT

public static final String ATTRIBUTES_COMMENT
Style attributes for comment/remark tokens.

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_COMMENT1

public static final String ATTRIBUTES_COMMENT1
Additional style attributes for comment/remark tokens.

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_COMMENT_KEYWORD

public static final String ATTRIBUTES_COMMENT_KEYWORD
Style attributes for special keywords inside comments. These attributes are used, for example, by the Java document parser for javadoc comment tags.

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_ERROR

public static final String ATTRIBUTES_ERROR
Style attributes for errors (white background red squiggle underline, like other eclipse editors).

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_ERROR1

public static final String ATTRIBUTES_ERROR1
A less intrusive style attributes for errors (red squiggle).

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_KEYWORD

public static final String ATTRIBUTES_KEYWORD
Style attributes for language keywords.

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_KEYWORD1

public static final String ATTRIBUTES_KEYWORD1
Additional style attributes for language keywords. Can be used, for example, for language-extension keywords.

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_LIBRARY

public static final String ATTRIBUTES_LIBRARY
Style attributes for library-related tokens. These attributes are used for tokens related to a library or some other base language-support. This style is used, for example, by the C/C++ document parser for C library functions.

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_NUMERAL

public static final String ATTRIBUTES_NUMERAL
Style attributes for numerals. Other numeric constants, such as hexadecimal strings in REXX and character literals in Java and C/C++, also use this style.

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_STRING

public static final String ATTRIBUTES_STRING
Style attributes for quoted strings. These attributes are used for string literals in the C/C++, Java, and other document parsers.

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_STRING1

public static final String ATTRIBUTES_STRING1
Additional style attributes for quoted strings. These attributes are used, for example, by the Java properties parser for ampersands in values (which some applications use to identify mnemonic characters in menus and labels).

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_DIRECTIVE

public static final String ATTRIBUTES_DIRECTIVE
Style attributes for compiler directives. These attributes are used, for example, by the C/C++ document parser for C preprocessor directives such as "#include".

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

ATTRIBUTES_NONSOURCE

public static final String ATTRIBUTES_NONSOURCE
Style attributes for text which does not constitute part of the source proper. These attributes are used, for example, by the JCL document parser for the "//" statement prefix, and by the PL/I document parser for text located outside the margins.

See Also:
setStyle(java.lang.String, java.lang.String), Constant Field Values

LEXER_RC_OK

public static final int LEXER_RC_OK
Successful return code from a subparser's token processing.

See Also:
Constant Field Values

LEXER_RC_EOF

public static final int LEXER_RC_EOF
EOF (end-of-file) flag in the return code from a subparser's token processing. This flag indicates that EOF was returned by the active character input stream. Flag LEXER_RC_MORE may indicate that the subparser is asking for more input to complete a parse unit.

See Also:
LEXER_RC_MORE, Constant Field Values

LEXER_RC_END

public static final int LEXER_RC_END
Return code from a subparser's token processing indicating the end of its job. For example, this flag will be returned by the SQL lexer processing embedded-SQL statements in a C/C++ source, at the end of the SQL executable clause (a semicolon was encountered). The host document parser must switch to the host language's subparser (the C/C++ lexer in this example).

See Also:
Constant Field Values

LEXER_RC_MORE

public static final int LEXER_RC_MORE
More-input flag in the return code from a subparser's token processing. This flag indicates that the subparser is asking for more input to complete a parse unit. This flag must be raised when EOF is encountered, to inform the host document parser that the parse range must be extended if possible.

See Also:
LEXER_RC_EOF, Constant Field Values

POPUP_TOP

public static final int POPUP_TOP
Indication for parser items at the top of the popup.

See Also:
getPopupItems(int), Constant Field Values

POPUP_FILTERVIEW

public static final int POPUP_FILTERVIEW
Indication for parser items in the "Filter view" submenu of the popup.

See Also:
getPopupItems(int), Constant Field Values

POPUP_SOURCE

public static final int POPUP_SOURCE
Indication for parser items in the "Source" submenu of the popup.

See Also:
getPopupItems(int), Constant Field Values

POPUP_END

public static final int POPUP_END
Indication for parser items at the end of the popup.

See Also:
getPopupItems(int), Constant Field Values
Constructor Detail

LpexCommonParser

protected LpexCommonParser(LpexView lpexView)
LpexCommonParser constructor. The constructor of the extending document parser must first call the super constructor in order to initialize support for the common services provided, for example:

 
 public MyLpexParser(LpexView lpexView)
 {
  super(lpexView);
  // rest of MyLpexParser's constructor code... 
 } 

You cannot instantiate a document parser directly. Its entire life cycle must be controlled by the editor.

Parameters:
lpexView - the document view associated with this parser
See Also:
lpexView()
Method Detail

parseAll

public abstract void parseAll()
Total parse. Parse the entire document.

See Also:
Total and incremental parse

parseElement

public abstract void parseElement(int element)
Incremental parse. Parse change(s) to a document.

Parameters:
element - the element whose committed change triggered the parse, or the element that precedes or follows a deleted block. The parser may identify other neighboring elements that will have to be reparsed as a unit
See Also:
LpexView.parsePending(int), LpexView.elementParsed(int), Total and incremental parse

lpexView

public final LpexView lpexView()
Returns the document view with which this parser is associated.


totalParse

public final void totalParse()
N/A - Method in the LpexParser interface; a document parser extending LpexCommonParser only implements parseAll().

Specified by:
totalParse in interface LpexParser

parse

public final void parse(int element)
N/A - Method in the LpexParser interface; a document parser extending LpexCommonParser only implements parseElement(int).

Specified by:
parse in interface LpexParser
Parameters:
element - an element affected by a committed change in this view

resetParser

public final void resetParser()
N/A - Method in the LpexParser interface; a document parser extending LpexCommonParser only implements, if needed, terminateParser().

Specified by:
resetParser in interface LpexParser

getLanguage

public String getLanguage()
Returns a string identifying the language or document type supported by this document parser. This string is used by getProperty() and setProperty() as a prefix for retrieving and setting parser properties in both the editor defaults profile and in the view settings, as a prefix for parser messages in LPEX's resources, and can be used by a command (such as a code assistant) to identify the language handled by this parser.

The document parser extending LpexCommonParser should override this method to return the language it supports. Strings for the most common programming languages are defined in LpexCommonParser (for example, LANGUAGE_JAVA). The implementation of this method provided by the LpexCommonParser class returns null.

See Also:
getProperty(java.lang.String), setProperty(java.lang.String, java.lang.String)

getLanguage

public String getLanguage(LpexDocumentLocation loc)
Returns a string identifying the language segment at the specified location. In mixed-content documents, this may differ from the main language of the document. This string may be used by context-sensitive utilities that must take into consideration the active language segment, such as code-assist presenters.

The document parser extending LpexCommonParser may override this method to return the particular language segment. Strings for the most common programming languages are defined in LpexCommonParser. The implementation of this method provided by the LpexCommonParser class returns getLanguage().

Parameters:
loc - document location
See Also:
getLanguage(), Mixed content documents

getProfile

public ResourceBundle getProfile()
Returns this document parser's profile. A document parser may define a profile to hold the installation settings of its parser properties. For example, the Java document parser holds its installation settings in Profile.properties, which is part of its package, and which is instantiated like this:

 
 private static ResourceBundle resource =
    ResourceBundle.getBundle("com.ibm.lpex.java.Profile");  

The document parser extending LpexCommonParser should override this method to return its own resource bundle. The implementation of this method provided by the LpexCommonParser class does nothing, except return null.

See Also:
getProperty(java.lang.String), Parser properties

getProperty

public String getProperty(String key)
Returns a parser property. The implementation of this method provided by the LpexCommonParser class searches the key (prefixed with the parser's language) in the editor defaults profile (used to store persistent user settings). If not found, it searches the parser profile (installation settings of parser properties). If the property is not found, it returns null.

If the specified key starts with "view.", then the view-scoped setting of the parser property, stored in the associated document view, is searched first and, if not found, the document-scoped setting. If the specified key starts with "document.", then the document-scoped setting of the parser property, stored in the associated document, is searched first.

Specified by:
getProperty in interface LpexParser
Parameters:
key - property name, for example, "proto.doc" for this parser's expansion of the keyword "doc" by the proto action, or "view.proto.doc" for this property as defined in the current view's instance of the parser
See Also:
getLanguage(), getProfile(), Parser properties

setProperty

public void setProperty(String key,
                        String value)
Sets, updates, or restores a parser property.

The implementation of this method provided by the LpexCommonParser class sets the key (prefixed with the parser's language) and the specified value in the editor defaults profile (persistent user settings). If the specified key is prefixed with "document.", then only the document-scoped setting of the parser property is set.

If the specified key is prefixed with "view.", then only the instance-scoped setting of the parser property is set.

If value is null, the specified document, view, or default setting is removed, and the parser's higher-level definition of the property value, if any, will be returned by a subsequent getProperty() call.

Parsers that may be affected are notified with propertySet().

Parameters:
key - document parser property name, for example, "proto.doc" for this parser's expansion of the keyword "doc" by the proto action, or "view.proto.doc" to define this property in the current view's instance of the parser
value - parser property value, or null to remove an overriding setting
See Also:
getLanguage(), getProperty(java.lang.String), propertySet(String), Parser properties

propertySet

protected void propertySet(String key)
The named parser property was set in the scope of this document parser instance.

A parser may listen to changes effected to any of its properties by extending this method. LpexCommonParser only listens to changes to the autoIndent, errorMessages, maintainBidiMarks, and parseAfterEveryKey properties.

Parameters:
key - base name of the parser property that was set, for example "autoIndent"
See Also:
setProperty(String,String), getProperty(java.lang.String), Parser properties

getPopupItems

protected String getPopupItems(int popupLocation)
Returns this parser's items for the pop-up (context) menu. A document parser extending LpexCommonParser may override this method to return its own specific menu items and associated actions. This method is called several times for various locations on the popup menu where the parser may contribute, as indicated by the popupLocation parameter.

For example, the Java document parser contributes to the "Filter view" submenu three menu items, defined here by their keys in LPEX's Resources.properties, and their corresponding action names; and to the "Source" submenu four items, defined here by embedded strings, and their corresponding action names:

 
 protected String getPopupItems(int popupLocation)
 {
  switch (popupLocation)
   {
    case POPUP_FILTERVIEW:
         return getLanguage() + ".popup.methods methods " + 
                getLanguage() + ".popup.outline outline " +
                LpexConstants.MSG_POPUP_ERRORS + " errors";
    case POPUP_SOURCE:
         return "\"&Comment\" comment " +
                "\"&Uncomment\" uncomment " +
                "\"&Document\" doc " +
                "\"&Trace\" trace";
   }
  return null;
 } 

The implementation of this method provided by the LpexCommonParser class does nothing, except return null.

Parameters:
popupLocation - the location on the pop-up menu of the items requested, one of:
POPUP_TOP, POPUP_FILTERVIEW, POPUP_SOURCE, POPUP_END
Returns:
this parser's contribution to the pop-up menu, or
null if none
See Also:
defineFilterAction(java.lang.String, java.lang.String)

initParser

protected void initParser()
This parser is being initialized.

The document parser extending LpexCommonParser may override this method to initialize itself.

The implementation of this method provided by the LpexCommonParser class does nothing.

See Also:
Life cycle

terminateParser

protected void terminateParser()
This parser is being terminated and disposed. Remove all of the parser specifics from the document view. Note that the element classes, style attributes, editor commands, and editor actions registered by this parser are already automatically removed by the editor.

The document parser extending LpexCommonParser may override this method to do any additional cleanups. For example, it should remove any listeners that it has added. A parser that implements code reformatting or auto-uppercasing may have reset certain editor settings, such as the autoCheck parameter, as it explicitly issues the undo check command after modifying (that is, reformatting or uppercasing) the source code; it should now restore any such settings, so that the editor may continue to operate properly without the parser.

Similarly, the parser should disconnect from tools (such as a source line prompter or an outline view) which operate in the scope of the view, document, or application editor window. A new parser subsequently instantiated in this view, if any, may then reestablish the connection to any existing instance of such tools.

The implementation of this method provided by the LpexCommonParser class does nothing.

See Also:
Life cycle

isPrimaryParser

public boolean isPrimaryParser()
Convenience method to determine whether this is considered the primary parser for the document.

The default implementation of this method returns true when this is the parser for the lowest-numbered document view (lowest view id) which has an active parser instance. Override in order to use another scheme for your application.

See Also:
Multiple document views

expandProtoKeyword

protected void expandProtoKeyword(int s,
                                  int e,
                                  String p)
Carries out the keyword expansion for the proto action. The keyword typed by the user, if any, is in the current element, delimited by the given offset s and e. The corresponding expansion string is specified in p.

Parameters:
s - ZERO-based keyword start offset in the current element
e - ZERO-based keyword end offset in the current element
p - the prototype expansion string

getToken

public String getToken(LpexDocumentLocation loc)
Returns the language token at the specified document location.

A token is a string of a consistent style, and delimited by the boundaries of the text element, white space, and characters defined by isTokenDelimiter().

This method returns null if the document location is beyond the element text, is on white space, or loc is incorrect. Token search is restricted to one element. Styles are assumed to be set correctly (i.e., no parse is pending for this element).

If a block is selected in this view and the location points to the start or end of this block, then the selected text will be returned as the token. It is assumed in this case that the text has just been selected, and the selection is deemed intentional for the purpose for which the token is being queried. This overrides the normal definition of a token stated above.

Parameters:
loc - document location
See Also:
isTokenDelimiter(char), getTokenLocation(com.ibm.lpex.core.LpexDocumentLocation), getLshToken()

getTokenLocation

public LpexDocumentLocation getTokenLocation(LpexDocumentLocation loc)
Returns the start of the language token at the specified document location. The token is as defined and returned by getToken(). If no token is identifiable, loc is returned.

Parameters:
loc - document location

getLshToken

public String getLshToken()
Returns the current token for language-sensitive help (LSH). The current token is the word at the current document location (cursor) as determined by the parser for LSH purposes. The token returned will serve (in common LSH implementations) as a key into the mapping table to the appropriate help panel.

The implementation of this method provided by the LpexCommonParser class returns getToken(lpexView().documentLocation()).

See Also:
Language-sensitive help

blockMarkWord

protected void blockMarkWord()
Implements the redefined editor action blockMarkWord. It (re)sets the block over the token at the current document location.


tokenBegin

protected LpexDocumentLocation tokenBegin(LpexDocumentLocation loc)
Returns the start of a token at the specified document location. Returns null if the document location is beyond the element text, is on white space, or loc is incorrect.

Token search is restricted to one element. Styles are assumed to be set correctly (i.e., no parse is pending for this element).

Parameters:
loc - document location
Returns:
document location of the first character that belongs to the token, or
null
See Also:
tokenEnd(com.ibm.lpex.core.LpexDocumentLocation), getToken(com.ibm.lpex.core.LpexDocumentLocation)

tokenEnd

protected LpexDocumentLocation tokenEnd(LpexDocumentLocation loc)
Returns the end of a token at the specified document location. Returns null if the document location is beyond the element text, is white space, or loc is incorrect. Token search is restricted to one element. Styles are assumed to be set correctly (i.e., no parse is pending for this element).

Parameters:
loc - document location
Returns:
document location of the last character that belongs to the token, or
null
See Also:
tokenBegin(com.ibm.lpex.core.LpexDocumentLocation), getToken(com.ibm.lpex.core.LpexDocumentLocation)

matchToken

protected LpexDocumentLocation matchToken(LpexDocumentLocation loc)
Matches the token found at the specified document location. This method is used by the redefined findMatch and match editor actions, with loc being the current document location. A document parser extending LpexCommonParser may override this method to return a matching token to the one found at loc, such as the "end" token matching a "do".

If no matching token is returned by this method, the editor tries to match any parenthesis, brace, square bracket, or angle bracket found at loc.

The implementation of this method provided by the LpexCommonParser class does nothing, except return null.

Parameters:
loc - document location
Returns:
matching document location, or
null if none

isDebuggable

public boolean isDebuggable(int line)
Query whether the specified document line is debuggable. A line is debuggable when it contains executable code that a debugger may stop on. This method is used to identify lines on which a breakpoint may be set.

The implementation of this method provided by the LpexCommonParser class returns true. A parser which does not support debugging should override this to return correct information.

Parameters:
line - a line inside the document section that is currently loaded in the editor

isTokenDelimiter

public boolean isTokenDelimiter(char c)
Returns whether the specified character is a token delimiter. While a punctuation character, for example, will have a style different from the token adjacent to it, this method is used to identify one token inside a string of tokens of the same style which may appear in the source without any other separators, for example,
   ... (name()); 
in a Java-language source. This method is also used to identify the keyword to expand for the proto action.

The implementation of this method provided by the LpexCommonParser class returns false. The parser should override this to return its particular token delimiters.

Parameters:
c - character queried, for example ')'
See Also:
getToken(com.ibm.lpex.core.LpexDocumentLocation), tokenBegin(com.ibm.lpex.core.LpexDocumentLocation), tokenEnd(com.ibm.lpex.core.LpexDocumentLocation)

isWordCharacter

public boolean isWordCharacter(int element,
                               int position)
Returns whether the character at the given position in the given element is to be considered part of a word.

The default implementation of this method returns true if the specified character is a letter or a digit.

The default definition of a word in LPEX for the purpose of the word-navigation editor actions nextWord, prevWord, blockMarkNextWord, and blockMarkPrevWord is any segment of characters delimited by whitespace. This can be changed through the wordBreaks parser property.

Parameters:
element - an element in the document section currently loaded in the editor
position - ONE-based position in the element text

cursorIndent

public int cursorIndent(int element)
Returns the indent display column of the cursor in the element. LpexCommonParser redefines the editor action newLine, which is the default action of Shift+Enter. After the cursor was moved to the next visible element in the view, if any, this method is called to set its optimal column.

The implementation of this method provided by the LpexCommonParser class returns the display column of the beginning of text in this element, if any, or otherwise the column corresponding to the beginning of text in the preceding non-blank element, if any, or otherwise column 1; 1 is also returned if automatic indentation (the autoIndent parser property) is disabled. Show elements are ignored.

A document parser may override this method, to return a value appropriate to its auto-indentation scheme.

Parameters:
element - the element for cursor indentation
Returns:
optimal display cursor column

getTextIndent

public String getTextIndent(int element)
Returns the desired indent string for the text in the specified element. LpexCommonParser redefines the action splitLine, which is the default action of the Enter key. In splitLine, after a new element was created for the split text, this method is called to obtain the optimal indentation string for positioning its text and cursor. This method is similarly used in the LpexCommonParser's redefinition of the actions indentText and openLine (which is the default action of Ctrl+Enter).

The implementation of this method provided by the LpexCommonParser class returns the indent string to the beginning of text in the preceding non-blank element, if any, or otherwise an empty string. Show elements are ignored.

A document parser may override this method, to return a value appropriate to its auto-indentation scheme.

Parameters:
element - the element for text indentation
Returns:
optimal indent string

newLine

protected void newLine()
Implements the redefined editor action newLine. It positions the cursor (current document location) in the new element to the display column returned by cursorIndent().

See Also:
cursorIndent(int)

openLine

protected void openLine()
Implements the redefined editor action openLine. It inserts the desired indentation string in the new element and positions the cursor (current document location) after it.


splitLine

protected void splitLine()
Implements the redefined editor action splitLine. It positions the text and the cursor (current document location) in the new element to the indentation returned by getTextIndent(), or to the beginning of the line if automatic indenting is off.

An incremental parse may be triggered in here to ensure the text tokenization is current.

See Also:
getTextIndent(int)

indentText

public int indentText(int element)
Positions the text of an element to the correct indent value. The correct indentation is determined by getTextIndent(). If automatic indenting (the autoIndent parser property) is off, the text is positioned at the beginning of the line.

Parameters:
element - the element for text indentation
Returns:
the new text cursor position of the indented text
See Also:
getTextIndent(int)

indentText

public int indentText(int element,
                      int desiredIndent)
Positions the text of an element to the specified indent value, given as the column position of the text indented by leading blanks.

Parameters:
element - the element for text indentation
desiredIndent - the desired indent column
Returns:
the new text position of the indented text
See Also:
indentText(int,String)

indentText

public int indentText(int element,
                      String desiredIndent)
Positions the text of an element to the specified indentation.

Parameters:
element - the element for text indentation
desiredIndent - the desired indentation (a String consisting of space and / or tab characters)
Returns:
the new text position of the indented text
See Also:
indentText(int)

getCommentStyleCharacters

public String getCommentStyleCharacters()
Returns the style character(s) used by this parser for comments. This information is used by the compare command when the compare.ignoreComments parameter is on.

The document parser extending LpexCommonParser should override this method to return all the style character(s) it uses for document comments and remarks. The implementation of this method provided by the LpexCommonParser class returns null.


setStyle

public final void setStyle(String styles,
                           String installAttributes)
Defines the styles used by the parser for a token or set of tokens. Each style character c in the styles parameter string is set to the style attributes value (color and font emphasis) indicated by the parser property style.c. This value is assumed to have been defined in the background color indicated by the parser property styles.backgroundColor, or BACKGROUND_COLOR if no such property.

If the style.c property is not set, the style attributes specified by the installAttributes parameter are used. This is the document parser's install (hard-coded) value for the style. This parameter is assumed to be an appropriate color value for the active palette. It must be in a format suitable for the editor command set styleAttributes.c, for example, "0 128 128 255 255 255 underline".

If the parser property tokenHighlight is "off", then ATTRIBUTES_DEFAULT (converted to the active palette) is used instead.

As an example, below is how the style character for comments is defined in the Java document parser. It uses as default the common ATTRIBUTES_COMMENT style attributes, defined for BACKGROUND_COLOR, first converted to the currently active palette.

 
 // get active palette's background color
 String toBackground = LpexPaletteAttributes.background(lpexView());
 // convert style attributes from definition background to the active one 
 String attributes = LpexPaletteAttributes.convert(ATTRIBUTES_COMMENT,
                                                   BACKGROUND_COLOR,
                                                   toBackground);
 // define the style character
 setStyle("c", attributes); 

Parameters:
styles - a string of one or more style characters to set
installAttributes - parser's install (hard-coded) attributes for the active palette
See Also:
BACKGROUND_COLOR, ATTRIBUTES_DEFAULT, ATTRIBUTES_COMMENT, ATTRIBUTES_COMMENT1, ATTRIBUTES_COMMENT_KEYWORD, ATTRIBUTES_ERROR, ATTRIBUTES_KEYWORD, ATTRIBUTES_KEYWORD1, ATTRIBUTES_LIBRARY, ATTRIBUTES_NUMERAL, ATTRIBUTES_STRING, ATTRIBUTES_DIRECTIVE, ATTRIBUTES_NONSOURCE, LpexPaletteAttributes, getProperty(java.lang.String), ATTRIBUTES_DEFAULT

getStyles

public String getStyles()
Returns the style characters defined by this document parser. The style characters defined are collected during the processing of calls to the method setStyle().

Returns:
a string of all the style characters defined by this parser, or
null if none
See Also:
getInstallStyleAttributes()

getInstallStyleAttributes

public ArrayList<String> getInstallStyleAttributes()
Returns the install attributes for the style characters defined by this document parser. The install (hard-coded) style attributes are collected during the processing of calls to the method setStyle().

Returns:
an array list of the parser's install (hard-coded) style attributes used by this parser, or
null if none
See Also:
getStyles()

getStyleName

public String getStyleName(char styleCharacter)
Returns the locale-sensitive description of a style defined by this document parser.

The implementation of this method in the LpexCommonParser class returns the parser property styleName.styleCharacter. If not found, it is searched in the LPEX resources (as the LPEX-shipped document parsers define their translation resources in there, for convenience).

Parameters:
styleCharacter - the style character queried, for example, 'c'
Returns:
the name assigned to the given style character, for example, "Comment", or
null if none
See Also:
STYLE_NAME

styleString

public String styleString(char style,
                          int len)
Utility method to return a style string for a len-long token.

Parameters:
style - style character for the token
len - token length

lineComment

public void lineComment(String text,
                        boolean comment)
Generic utility method to comment / uncomment lines. Adds or removes one level of line comments in the currently selected non-show, visible elements.

Parameters:
text - line-comment text, for example, "//" for .java and .cpp, "#" for .properties
comment - true = add line comments, or false = remove line comments from the start of the line's text

defineFilterAction

protected final boolean defineFilterAction(String actionName,
                                           String includedClasses)
Convenience method to define an action for the "Filter view" menu. This method defines a checkable LpexBaseAction with the specified name, for the document view associated with this instance of the parser.

Parameters:
actionName - the name of the action, for example, "errors"
includedClasses - the registered element class(es) to be included for this action, for example, "error " + CLASS_MESSAGE
Returns:
false on incorrect classes parameter
See Also:
defineFilterAction(String,String,String), getPopupItems(int)

defineFilterAction

protected final boolean defineFilterAction(String actionName,
                                           String includedClasses,
                                           String excludedClasses)
Convenience method to define an action for the "Filter view" menu. This method defines a checkable LpexBaseAction with the specified name, for the document view associated with this instance of the parser.

Parameters:
actionName - the name of the action, for example, "errors"
includedClasses - the registered element class(es) to be included by this action or null for all, for example, "error " + CLASS_MESSAGE
excludedClasses - the registered element class(es) to be excluded by this action or null for none, for example, "comment"
Returns:
false on incorrect classes parameters
See Also:
defineFilterAction(String,String), getPopupItems(int)

addMessage

protected final void addMessage(int element,
                                String text)
Displays an embedded parser error or informational message for an element. The error message is assigned the default CLASS_MESSAGE element class, and is set the default STYLE_MESSAGE style character.

Parameters:
element - the text element number this message pertains to
text - the message text
See Also:
removeMessages(int,int), addMessage(int,String,long), addMessage(int,String,long,char)

addMessage

protected final void addMessage(int element,
                                String text,
                                long messageClass)
Displays an embedded parser error or informational message for an element. The error message is assigned the specified element class, and is set the default STYLE_MESSAGE style character.

A document-parser error is usually set with addMessage(int,String), the error message being assigned the default CLASS_MESSAGE element class. This method may be used to customize the error messages, or to allow one to manage the separate addition and removal of error messages from different sources (for example, a lexer, a grammar parser, and a compiler).

Parameters:
element - the text element number this message pertains to
text - the message text
messageClass - bit-mask of the registered element class for this message
See Also:
removeMessages(int,int,long), addMessage(int,String), addMessage(int,String,long,char)

addMessage

protected final void addMessage(int element,
                                String text,
                                long messageClass,
                                char messageStyle)
Displays an embedded parser error or informational message for an element. The error message is assigned the specified element class, and is set the specified style character. Embedded messages are set using show lines (text elements which are displayed in the text view, but not saved with the document).

No embedded messages are displayed if this feature (the errorMessages parser property) is disabled.

A document-parser error is usually set with addMessage(int,String), the error message being assigned the default CLASS_MESSAGE element class, and set the default STYLE_MESSAGE style character. This method may be used to customize the error messages, or to allow one to manage the separate addition and removal of error messages from different sources (for example, a lexer, a grammar parser, and a compiler).

Note:  All the addMessage() methods should be invoked only during the parseAll and parseElement calls. The messages to be inserted during the parse action are stacked. The actual insertion of the show-line messages will be carried out at the end of the current parse action. Several messages for one line will be displayed in the order in which they were added.

The text of the message should be obtained from a locale-sensitive resource.

Parameters:
element - the text element number this message pertains to
text - the message text
messageClass - bit-mask of the registered element class for this message
messageStyle - registered style character for this message
See Also:
removeMessages(int,int,long), addMessage(int,String), addMessage(int,String,long)

addDocumentMessage

protected final void addDocumentMessage(int element,
                                        String text,
                                        String messageClass,
                                        char messageStyle)
Displays an embedded error or informational message for an element in all the views of the document. When multiple views of a document are open, certain operations such as syntax checking are only performed by one of the view parsers, but the generated messages may be displayed in all the document views.

The message class and style character specified must have been registered in all the views of the document.

Like the addMessage() methods, this method should be invoked only during the parseAll and parseElement calls. The messages to be inserted during the parse action are stacked. The actual insertion of the show-line messages will be carried out at the end of the current parse action. Several messages for one line will be displayed in the order in which they were added.

Parameters:
element - the text element number this message pertains to
text - the message text
messageClass - registered element class for this message
messageStyle - registered style character for this message
See Also:
removeDocumentMessages(int,int,String), addMessage(int,String,long,char)

copyDocumentMessages

public static boolean copyDocumentMessages(LpexView targetView,
                                           int sourceViewId,
                                           String messageClass)
Convenience method to copy the document messages from an existing view.

When multiple views of a document are open, certain operations such as syntax checking are only performed by one of the view parsers, but the generated messages may be displayed in all the document views. This method can be used to update a new view opened on the document.

The same element class and style characters used in the source view are set for each copied message in the target view.

Parameters:
targetView - the document view in which to embed the document messages
sourceViewId - id of the source document view
messageClass - registered element class(es) for the document messages to copy
Returns:
false on incorrect parameters
See Also:
addDocumentMessage(int,String,String,char), removeDocumentMessages(int,int,String)

removeMessages

protected final void removeMessages(int fromElement,
                                    int toElement)
Removes this parser's default messages for a given range of elements.

Parameters:
fromElement - first text element in the range
toElement - last text element for which this parser's messages should be removed
See Also:
addMessage(int,String), removeMessages(int,int,long)

removeMessages

protected final void removeMessages(int fromElement,
                                    int toElement,
                                    long messageClass)
Removes this parser's embedded messages of the specified element class(es), for the given range of text elements.

A document parser normally adds error and informational embedded messages with addMessage(int,String), and removes them with removeMessages(int,int). Both these methods handle default messages. The methods that allow specifying the element class assigned to the message may be used to customize these error messages, or to allow one to manage the separate addition and removal of error messages from different sources (for example, a lexer, a grammar parser, and a compiler).

When using both qualified and default addMessage() calls, then in order to remove the messages of all types in a range you can use:

 
 String myMessageClasses = "parseError compileError";
 removeMessages(fromElement, toElement,
                lpexView().classMask(CLASS_MESSAGE + ' 'myMessageClasses); 

All the removeMessages() methods should be invoked only during the parseAll and parseElement calls. The actual removal of embedded messages will be carried out at the end of the current parse action. Several calls to this method during the course of one parse action may extend a range already set. Note that a range is assumed to be continuous.

Parameters:
fromElement - first text element in the range
toElement - last text element for which this parser's messages should be removed
messageClass - bit-mask of the registered element class(es) for the messages to remove
See Also:
addMessage(int,String,long), addMessage(int,String,long,char), removeMessages(int,int)

removeDocumentMessages

protected final void removeDocumentMessages(int fromElement,
                                            int toElement,
                                            String messageClass)
Removes from all the views of the document the embedded messages of the specified element class(es) for the given range of text elements.

When multiple views of a document are open, certain operations such as syntax checking are only performed by one of the view parsers, but the generated messages may be displayed in all the document views.

Like all the removeMessages(), this method should be invoked only during the parseAll and parseElement calls. The actual removal of embedded messages will be carried out at the end of the current parse action. Several calls to this method during the course of one parse action may extend a range already set. Note that a range is assumed to be continuous.

Parameters:
fromElement - first text element in the range
toElement - last text element for which document messages should be removed
messageClass - registered element class(es) for the messages to remove
See Also:
addDocumentMessage(int,String,String,char), removeMessages(int,int,long)

LPEX
4.4.0

Copyright � 2016 IBM Corp. All Rights Reserved.

Note: This documentation is for part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.