Overview

 
Package  Use  Tree  Serialized  Deprecated  Index  Help 
SWT LPEX
v3.0.0
 PREV CLASS   NEXT CLASS FRAMES    NO FRAMES  
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD


 

com.ibm.lpex.core
Class LpexCommonParser

java.lang.Object
  extended bycom.ibm.lpex.core.LpexCommonParser

All Implemented Interfaces:
LpexConstants, LpexParser

Direct Known Subclasses:
CobolParser, CppParser, FortranParser, HLAsmParser, 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...
 } 

Total and incremental parse

There are two main callback methods in a document parser:

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.

Parser properties

Parser properties are parser-specific settings. Certain common parser properties are used by LpexCommonParser:

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 view scoped setting. 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.

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

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

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 commonly 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 imbedded SQL and/or CICS statements, Java source code with imbedded 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 imbedded 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. A method is provided to query the document content type at a specific location.

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, both the total and incremental parse callbacks will be invoked in all the parsers associated with the document, on every change to the text of the document.

Related editor parameters: documentId, multipleViews, viewId.

Example

An example of developing a simple document parser is available in the com.ibm.lpex.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.
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_DDS
          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_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_ERRORS, MSG_POPUP_EXCLUDESELECTION, MSG_POPUP_FILTERVIEWMENU, MSG_POPUP_INSERTMENU, MSG_POPUP_SELECTEDMENU, MSG_POPUP_SHOWALL, MSG_POPUP_SOURCEMENU, PARSE_PENDING_CHANGE_MASK, PARSE_PENDING_NEXT_DELETED_MASK, PARSE_PENDING_NEXT_SHOW_DELETED_MASK, PARSE_PENDING_PREV_DELETED_MASK, PARSE_PENDING_PREV_SHOW_DELETED_MASK, PLATFORM_AWT, PLATFORM_SWT, PLATFORM_SWT_KEY, 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
 
Constructor Summary
protected LpexCommonParser(LpexView lpexView)
          LpexCommonParser constructor.
 
Method Summary
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()
          Overrides the default editor action blockMarkWord.
 int cursorIndent(int element)
          Returns the indent display column of the cursor in the element.
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 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.
 String getPopupParserItems()
          Deprecated. Return the same string in getPopupItems(POPUP_END).
 String getPopupViewItems()
          Deprecated. Return the same string in getPopupItems(POPUP_FILTERVIEW).
 ResourceBundle getProfile()
          Returns the document parser profile.
 String getProperty(String key)
          Returns a parser property.
 String getStyleName(char styleCharacter)
          Returns the 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 location of the language token as defined and returned by getToken().
 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.
 boolean isDebuggable(int line)
          Query whether the specified document line is debuggable.
 boolean isTokenDelimiter(char c)
          Query whether the specified character is a token delimiter.
 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()
          Overrides the default editor action newLine.
protected  void openLine()
          Overrides the default editor action openLine.
 void parse(int element)
          N/A - Method in the LpexParser interface; a document parser extending LpexCommonParser only implements parseElement().
abstract  void parseAll()
          Total parse.
abstract  void parseElement(int element)
          Incremental parse.
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 given element class(es), for the given range of 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()
          Overrides the default editor action splitLine.
 String styleString(char style, int len)
          Utility method to return a style string for a len-long token.
 void terminateParser()
          Remove all of the parser specifics from the document view.
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_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_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 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.

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 to a common colour and font emphasis. This style is used by the C/C++ document parser for C library functions; it could also be used, as an example, by a Java document parser for classes provided in the java.lang package.

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 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 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 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 Java, at the end of the SQL executable clause. The host document parser must switch to the host language's subparser (the Java 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 know 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. This must be called first in the constructor of the document parser that extends LpexCommonParser, for example:

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

It initializes support for the common services provided.

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.


 

 

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

See Also:
terminateParser()


 

 

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

See Also:
parseAll()


 

 

parse

public final void parse(int element)

N/A - Method in the LpexParser interface; a document parser extending LpexCommonParser only implements parseElement().

Specified by:
parse in interface LpexParser

Parameters:
element - the element whose committed change triggered the parse, or the element that precedes / follows a deleted block; the parser may identify other neighbouring elements that will have to be reparsed as a unit
See Also:
parseElement(int)


 

 

getLanguage

public String getLanguage()

Returns a string identifying the language or document type supported by this document parser. This string is used by getProperty(java.lang.String) and setProperty(java.lang.String, java.lang.String) as a prefix for retrieving and setting parser properties in the editor defaults profile, as a prefix for parser messages in LPEX's resources, and can be used by a command (such as a code navigator) 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. 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), LANGUAGE_CCPP, LANGUAGE_CICS, LANGUAGE_CL, LANGUAGE_COBOL, LANGUAGE_DDS, LANGUAGE_FORTRAN, LANGUAGE_HLASM, LANGUAGE_HTML, LANGUAGE_JAVA, LANGUAGE_JCL, LANGUAGE_LISP, LANGUAGE_PERL, LANGUAGE_PLI, LANGUAGE_REXX, LANGUAGE_RPG, LANGUAGE_SABRETALK, LANGUAGE_SQL, LANGUAGE_XMI, LANGUAGE_XML, LANGUAGE_XSL


 

 

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().

See Also:
getLanguage()


 

 

getProfile

public ResourceBundle getProfile()

Returns the document parser 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. Default properties are defined in the parser profile, and are

  • properties common to LpexCommonParser parsers: tokenHighlight, errorMessages, and autoIndent
  • parser-specific properties, such as keyword expansions for the proto action.

Other properties may be set, for example to override the default style attributes used by the document parser for syntax highlighting.

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.

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()


 

 

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 starts with "view.", then only the instance scoped setting of the parser property is set.

If value is null, the specified 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.

A parser may 'listen' to changes effected to any of its properties by extending this method. The implementation of this method in LpexCommonParser listens to changes to the autoIndent and errorMessages properties.

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)


 

 

getPopupViewItems

public String getPopupViewItems()

Deprecated. Return the same string in getPopupItems(POPUP_FILTERVIEW).

Retrieve parser's items for the popup "Filter view" submenu. The document parser extending LpexCommonParser should override this method to return its own filtered-view menu items and associated actions.

See Also:
getPopupItems(int)


 

 

getPopupParserItems

public String getPopupParserItems()

Deprecated. Return the same string in getPopupItems(POPUP_END).

Retrieve parser's items for the popup menu. A document parser extending LpexCommonParser may override this method to return its own specific menu items and associated actions.

See Also:
getPopupItems(int)


 

 

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 imbedded 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 popup menu of the items requested, one of:
POPUP_TOP, POPUP_FILTERVIEW, POPUP_SOURCE, POPUP_END
Returns:
this parser's contribution to the popup menu, or
null if none


 

 

terminateParser

public void terminateParser()

Remove all of the parser specifics from the document view. Note that classes, style attributes, commands, and actions 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 invokes the undo check command after modifying the source code; it should now restore any such settings, so that the editor may continue to operate properly without the parser.

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


 

 

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 the style character(s) it uses for document comments and remarks. The implementation of this method provided by the LpexCommonParser class returns null.


 

 

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 location of the language token as defined and returned by getToken(). If no token is identifiable, loc is returned.


 

 

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(view.documentLocation()).

See Also:
Language-sensitive help


 

 

blockMarkWord

protected void blockMarkWord()

Overrides the default 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. 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". This is used by the findMatch and match actions, with loc being the current document location.

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 false. A parser which supports 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)

Query 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.

See Also:
getToken(com.ibm.lpex.core.LpexDocumentLocation)


 

 

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()

Overrides the default 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()

Overrides the default 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()

Overrides the default 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 is 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)


 

 

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


 

 

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(view);
 // 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 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 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 NLS resources in there, for convenience).

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


 

 

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


 

 

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.

See Also:
CLASS_MESSAGE, STYLE_MESSAGE, 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).

See Also:
STYLE_MESSAGE, 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 imbedded 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).

All the addMessage() methods should only be invoked 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 that they were added.

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

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


 

 

removeMessages

protected final void removeMessages(int fromElement,
                                    int toElement)

Removes this parser's default messages for a given range of elements.

See Also:
removeMessages(int,int,long), addMessage(int,String), addMessage(int,String,long), addMessage(int,String,long,char)


 

 

removeMessages

protected final void removeMessages(int fromElement,
                                    int toElement,
                                    long messageClass)

Removes this parser's embedded messages of the given element class(es), for the given range of elements.

A 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).

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

   removeMessages(fromElement, toElement,
                  lpexView().classMask(CLASS_MESSAGE) | myMessageClassesBitMask); 

All the removeMessages() methods should only be invoked during the parseAll and parseElement calls. The actual removal of embedded error 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 - message class(es) bit-mask
See Also:
removeMessages(int,int), addMessage(int,String), addMessage(int,String,long), addMessage(int,String,long,char)


 

Overview

 
Package  Use  Tree  Serialized  Deprecated  Index  Help 
SWT LPEX
v3.0.0
 PREV CLASS   NEXT CLASS FRAMES    NO FRAMES  
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD