LPEX
4.4.0

com.ibm.lpex.samples
Class TestParser1

java.lang.Object
  extended by com.ibm.lpex.core.LpexCommonParser
      extended by com.ibm.lpex.samples.TestParser1
All Implemented Interfaces:
LpexConstants, LpexParser

public class TestParser1
extends LpexCommonParser

Sample document parser: STEP 1 - minimum code.

This is a sample skeleton for a document parser extending LpexCommonParser. It shows the minimum code needed to implement such a parser. TestParser2 will build on this foundation to carry out a simple parsing of comments in text files.

When a new file is opened, the editor normally searches for the document parser associated with that file's type (file name or file name extension). For example, opening sample.cpp may point the editor to the parser class "CppParser.class". Once found, the editor will load this class - CppParser's constructor will instantiate one object for the newly-created document view -, and then call one of its public methods to carry out a total parse on the document sample.cpp. Afterwards, each time the user modifies (edits) sample.cpp, a method in CppParser will be called to do an incremental parse on the changes in the document. See also Total and incremental parse.

Parsers may be registered with the updateProfile.parserClass, updateProfile.parserAssociation, and updateProfile.parser editor parameters. For example, to try TestParser1 on an open document view, enter these commands on the LPEX command line:

   set updateProfile.parserClass.testParser1 com.ibm.lpex.samples.TestParser1
   set updateProfile.parser testParser1
   updateProfile

Various services may be provided by a document parser. Usually, a parser will scan the document to understand its structure, and colorize the various tokens as an aid to the programmer editing that type of files: say, keywords in blue, numbers in red, and comments in green. While the user is editing the file, the parser will 'play catch-up' to maintain its model of the document (and the displayed token colors) up-to-date.

At a minimum, a parser that extends class LpexCommonParser should have a constructor, and implement two methods (declared as abstract in LpexCommonParser): parseAll() and parseElement(). LpexCommonParser handles the rest.

 
 public class TestParser1 extends LpexCommonParser
 {
  public TestParser1(LpexView lpexView) { super(lpexView); } 
  public void parseAll() {}
  public void parseElement(int element) {}
 }

See the rest of the documentation below. It shows and explains the code of this example. TestParser2 will do some real parsing, building on this framework.

Document parsers developed for LPEX may employ tools that generate Java code from a language grammar definition. One class for such tools provided by LPEX is LpexCharStream.

See Also:
LpexCommonParser

Field Summary
 
Fields inherited from class com.ibm.lpex.core.LpexCommonParser
ATTRIBUTES_COMMENT, ATTRIBUTES_COMMENT_KEYWORD, ATTRIBUTES_COMMENT1, ATTRIBUTES_DEFAULT, ATTRIBUTES_DIRECTIVE, ATTRIBUTES_ERROR, ATTRIBUTES_ERROR1, ATTRIBUTES_KEYWORD, ATTRIBUTES_KEYWORD1, ATTRIBUTES_LIBRARY, ATTRIBUTES_NONSOURCE, ATTRIBUTES_NUMERAL, ATTRIBUTES_STRING, ATTRIBUTES_STRING1, BACKGROUND_COLOR, CLASS_MESSAGE, LANGUAGE_CCPP, LANGUAGE_CICS, LANGUAGE_CL, LANGUAGE_COBOL, LANGUAGE_COBOL400, LANGUAGE_COBOLILE, LANGUAGE_DDS, LANGUAGE_DLI, LANGUAGE_FORTRAN, LANGUAGE_HLASM, LANGUAGE_HTML, LANGUAGE_JAVA, LANGUAGE_JCL, LANGUAGE_LISP, LANGUAGE_PERL, LANGUAGE_PLI, LANGUAGE_REXX, LANGUAGE_RPG, LANGUAGE_RPGLEFIXED, LANGUAGE_RPGLEFREE, LANGUAGE_SABRETALK, LANGUAGE_SQL, LANGUAGE_XMI, LANGUAGE_XML, LANGUAGE_XSL, LEXER_RC_END, LEXER_RC_EOF, LEXER_RC_MORE, LEXER_RC_OK, POPUP_END, POPUP_FILTERVIEW, POPUP_SOURCE, POPUP_TOP, PROTOKEY_EMPTY, STYLE_MESSAGE, STYLE_NAME, view
 
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
TestParser1(LpexView lpexView)
          The parser's constructor.
 
Method Summary
 void parseAll()
          Total parse.
 void parseElement(int element)
          Incremental parse.
 
Methods inherited from class com.ibm.lpex.core.LpexCommonParser
addDocumentMessage, addMessage, addMessage, addMessage, blockMarkWord, copyDocumentMessages, cursorIndent, defineFilterAction, defineFilterAction, expandProtoKeyword, getCommentStyleCharacters, getInstallStyleAttributes, getLanguage, getLanguage, getLshToken, getPopupItems, getProfile, getProperty, getStyleName, getStyles, getTextIndent, getToken, getTokenLocation, indentText, indentText, indentText, initParser, isDebuggable, isPrimaryParser, isTokenDelimiter, isWordCharacter, lineComment, lpexView, matchToken, newLine, openLine, parse, propertySet, removeDocumentMessages, removeMessages, removeMessages, resetParser, setProperty, setStyle, splitLine, styleString, terminateParser, tokenBegin, tokenEnd, totalParse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestParser1

public TestParser1(LpexView lpexView)
The parser's constructor. First thing to do in here is to call the superclass constructor, i.e., LpexCommonParser's. Next, whatever else may be needed by the parser should be initialized (more on this in the next example, when the sample document parser will actually parse).

 
 public TestParser1(LpexView lpexView) 
 {
  super(lpexView);
 }

One instance of the parser controls one LpexView of a document. When several edit views are opened on the same document, several parser objects will be instantiated, one for each view, and each will be called to parse its view.

Parameters:
lpexView - the document view associated with this parser instance
Method Detail

parseAll

public void parseAll()
Total parse. The parser is called here to parse the entire document, for example immediately after it has been loaded in the editor.

Nothing is being done here right now:

 
 public void parseAll() 
 {
 }

Specified by:
parseAll in class LpexCommonParser
See Also:
Total and incremental parse

parseElement

public void parseElement(int element)
Incremental parse. This call-back method is invoked by the editor to incrementally parse changes to the document: some new text was typed in, a line was deleted, a block operation (copy / move / delete) was performed, etc.

Nothing is done here right now, therefore there is no visible effect on the editing:

 
 public void parseElement(int element) 
 {
 }

Specified by:
parseElement in class LpexCommonParser
Parameters:
element - an element whose committed change triggered the parse, or an element that precedes or follows deleted element(s). The parser may identify other neighbouring elements that will have to be reparsed as a unit
See Also:
LpexView.parsePending(int), LpexView.elementParsed(int), Total and incremental parse

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.