|
LPEX 4.4.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.lpex.core.LpexCommonParser
com.ibm.lpex.samples.TestParser1
public class TestParser1
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
.
LpexCommonParser
Field Summary |
---|
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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TestParser1(LpexView lpexView)
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.
lpexView
- the document view associated with this parser instanceMethod Detail |
---|
public void parseAll()
Nothing is being done here right now:
public void parseAll()
{
} |
parseAll
in class LpexCommonParser
public void parseElement(int element)
Nothing is done here right now, therefore there is no visible effect on the editing:
public void parseElement(int element)
{
} |
parseElement
in class LpexCommonParser
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 unitLpexView.parsePending(int)
,
LpexView.elementParsed(int)
,
Total and incremental parse
|
LPEX 4.4.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |