|
LPEX 4.4.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ibm.lpex.core.LpexCommonParser
public abstract class LpexCommonParser
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:
parseAll()
- total parse:
parse the entire document.
This method is normally called when a new document has been loaded in
the editor, whenever the updateProfile command was run and the parser
has been reinstantiated, and when a total parse is activated directly (with,
for example, the parse all editor command).parseElement(int element)
- incremental parse:
parse changes to the document.
This method is normally called when a change has been committed in the
editor (for example, the text on a document line was edited and then
the cursor was moved off that line), and when an incremental parse is
activated directly (with, for example, the parse editor command).parsePending()
and
elementParsed()
methods.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:
matchToken()
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:
setStyle()
getStyleName()
setStyle()
isWordCharacter()
defines,
by default all letters and digits (this method may be further extended or overridden
by the parser)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.
addDocumentMessage()
,
removeDocumentMessages()
, and
copyDocumentMessages()
.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:
getLshToken()
determines the current token in the
edit area. This is done based on the text at the current document
position (cursor), or any specific text selection in effect in the view.
The token returned may then be used as the key into a table that maps
language keywords to particular help panels.getLshToken()
to further
refine the generation of the key which will be used to access the
help-mapping table.
This is needed in those cases in which the cursor is located in
particular contexts inside the document, such as comment lines, identifiers,
embedded error messages (displayed as show lines), and so on, where
the token returned by method getLshToken()
is not a
recognized (reserved) keyword in the language. The COBOL parsers, for
example, extend getLshToken()
.getToken()
instead,
to simply retrieve the current token or selection.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.
Using effective text and style.
When the document format is smart-logical, you may find it convenient to strip the
bidi marks from the element text before
parsing it. You must then adjust the effective style string set by the parse operation
for any bidi marks in the text before setting it in the editor.
See LpexNls.stripBidiMarks(java.lang.String)
and
LpexNls.setStyleBidiMarks(int, java.lang.String)
.
Parsing after every key. By default, in order to create the least amount of 'noise' (for example, error messages caused by incomplete constructs), incremental parsing is only activated once the cursor leaves the current line (that is, the changes to the text are considered committed). In certain bidi editing scenarios, where the correct visual layout of the text relies on the tokenization of the text, this does not provide an ideal text editing experience for the user. Not only does the line appear incorrect until the parser is triggered, making it difficult to type the desired text, but once that happens (for example, when the user moves the cursor off the line or presses Enter) the text in the line may change around suddenly.
LPEX provides the option to have the parser activated after every key. Ideally,
a parser should operate in this mode when running in an active bidi environment.
A solution editor may set the parseAfterEveryKey property for those document
parsers which are safe to run in this manner and do not already have this setting as
the install value in their profile (parseAfterEveryKey set to either "on" or "bidi").
Consideration must be given to other functions activated by the parser (such as syntax
checking, source reformatting, or an associated outline view) which are generally
time consuming and may generate error messages, so that they are activated less often
than after each and every keystroke. Also, parsers may have to be modified to be
more lenient in announcing errors for incomplete constructs, or provide additional keying
support. For example, in languages such as C/C++ the parser may automatically enter the
second double-quote "
when the user types a double-quote "
,
to prevent announcing an error for the unterminated string.
Maintaining bidi marks.
The maintainBidiMarks parser property is supported by most LPEX-shipped document
parsers. Its default value is "off". It should only be activated by the solution editor
in conjunction with similar support in its workstation - remote communications layer,
and for local files with a smart-logical format.
See LpexNls.setTextStyleBidiMarks(int, java.lang.String)
.
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. |
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 |
---|
protected LpexView view
lpexView()
public static final String CLASS_MESSAGE
It is defined as "Message"
. The parser should not define
an element class with this name.
public static final char STYLE_MESSAGE
Defined as 'M'
. The parser should not define this style
for tokens.
public static final String LANGUAGE_CCPP
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_CICS
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_CL
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_COBOL
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_COBOL400
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_COBOLILE
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_DLI
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_DDS
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_FORTRAN
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_HLASM
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_HTML
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_JAVA
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_JCL
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_LISP
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_PERL
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_PLI
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_REXX
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_RPG
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_RPGLEFIXED
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_RPGLEFREE
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_SABRETALK
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_SQL
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_XMI
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_XML
getLanguage()
,
Constant Field Valuespublic static final String LANGUAGE_XSL
getLanguage()
,
Constant Field Valuespublic static final String PROTOKEY_EMPTY
"proto.%EMPTY%"
.
public static final String STYLE_NAME
"styleName."
.
getStyleName(char)
,
Constant Field Valuespublic static final String BACKGROUND_COLOR
"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.
setStyle(java.lang.String, java.lang.String)
,
LpexPaletteAttributes
,
Constant Field Valuespublic final String ATTRIBUTES_DEFAULT
setStyle(java.lang.String, java.lang.String)
public static final String ATTRIBUTES_COMMENT
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_COMMENT1
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_COMMENT_KEYWORD
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_ERROR
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_ERROR1
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_KEYWORD
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_KEYWORD1
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_LIBRARY
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_NUMERAL
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_STRING
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_STRING1
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_DIRECTIVE
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final String ATTRIBUTES_NONSOURCE
setStyle(java.lang.String, java.lang.String)
,
Constant Field Valuespublic static final int LEXER_RC_OK
public static final int LEXER_RC_EOF
LEXER_RC_MORE
,
Constant Field Valuespublic static final int LEXER_RC_END
public static final int LEXER_RC_MORE
LEXER_RC_EOF
,
Constant Field Valuespublic static final int POPUP_TOP
getPopupItems(int)
,
Constant Field Valuespublic static final int POPUP_FILTERVIEW
getPopupItems(int)
,
Constant Field Valuespublic static final int POPUP_SOURCE
getPopupItems(int)
,
Constant Field Valuespublic static final int POPUP_END
getPopupItems(int)
,
Constant Field ValuesConstructor Detail |
---|
protected LpexCommonParser(LpexView lpexView)
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.
lpexView
- the document view associated with this parserlpexView()
Method Detail |
---|
public abstract void parseAll()
public abstract void parseElement(int element)
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 unitLpexView.parsePending(int)
,
LpexView.elementParsed(int)
,
Total and incremental parsepublic final LpexView lpexView()
public final void totalParse()
parseAll()
.
totalParse
in interface LpexParser
public final void parse(int element)
parseElement(int)
.
parse
in interface LpexParser
element
- an element affected by a committed change in this viewpublic final void resetParser()
terminateParser()
.
resetParser
in interface LpexParser
public String getLanguage()
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
.
getProperty(java.lang.String)
,
setProperty(java.lang.String, java.lang.String)
public String getLanguage(LpexDocumentLocation loc)
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()
.
loc
- document locationgetLanguage()
,
Mixed content documentspublic ResourceBundle getProfile()
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
.
getProperty(java.lang.String)
,
Parser propertiespublic String getProperty(String key)
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.
getProperty
in interface LpexParser
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 parsergetLanguage()
,
getProfile()
,
Parser propertiespublic void setProperty(String key, String value)
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.
"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().
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 parservalue
- parser property value, or
null
to remove an overriding settinggetLanguage()
,
getProperty(java.lang.String)
,
propertySet(String)
,
Parser propertiesprotected void propertySet(String key)
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.
key
- base name of the parser property that was set, for example "autoIndent"setProperty(String,String)
,
getProperty(java.lang.String)
,
Parser propertiesprotected String getPopupItems(int popupLocation)
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
.
popupLocation
- the location on the pop-up menu of the items
requested, one of: POPUP_TOP
, POPUP_FILTERVIEW
,
POPUP_SOURCE
, POPUP_END
null
if nonedefineFilterAction(java.lang.String, java.lang.String)
protected void initParser()
The document parser extending LpexCommonParser may override this method to initialize itself.
The implementation of this method provided by the LpexCommonParser class does nothing.
protected void terminateParser()
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.
public boolean isPrimaryParser()
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.
protected void expandProtoKeyword(int s, int e, String p)
s
- ZERO-based keyword start offset in the current elemente
- ZERO-based keyword end offset in the current elementp
- the prototype expansion stringpublic String getToken(LpexDocumentLocation loc)
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.
loc
- document locationisTokenDelimiter(char)
,
getTokenLocation(com.ibm.lpex.core.LpexDocumentLocation)
,
getLshToken()
public LpexDocumentLocation getTokenLocation(LpexDocumentLocation loc)
getToken()
.
If no token is identifiable, loc
is returned.
loc
- document locationpublic String getLshToken()
The implementation of this method provided by the LpexCommonParser class
returns getToken(lpexView().documentLocation())
.
protected void blockMarkWord()
protected LpexDocumentLocation tokenBegin(LpexDocumentLocation loc)
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).
loc
- document location
null
tokenEnd(com.ibm.lpex.core.LpexDocumentLocation)
,
getToken(com.ibm.lpex.core.LpexDocumentLocation)
protected LpexDocumentLocation tokenEnd(LpexDocumentLocation loc)
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).
loc
- document location
null
tokenBegin(com.ibm.lpex.core.LpexDocumentLocation)
,
getToken(com.ibm.lpex.core.LpexDocumentLocation)
protected LpexDocumentLocation matchToken(LpexDocumentLocation loc)
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
.
loc
- document location
null
if nonepublic boolean isDebuggable(int line)
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.
line
- a line inside the document section that is currently loaded
in the editorpublic boolean isTokenDelimiter(char c)
... (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.
c
- character queried, for example ')'getToken(com.ibm.lpex.core.LpexDocumentLocation)
,
tokenBegin(com.ibm.lpex.core.LpexDocumentLocation)
,
tokenEnd(com.ibm.lpex.core.LpexDocumentLocation)
public boolean isWordCharacter(int element, int position)
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.
element
- an element in the document section currently loaded in the editorposition
- ONE-based position in the element textpublic int cursorIndent(int element)
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.
element
- the element for cursor indentation
public String getTextIndent(int element)
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.
element
- the element for text indentation
protected void newLine()
cursorIndent(int)
protected void openLine()
protected void splitLine()
An incremental parse may be triggered in here to ensure the text tokenization is current.
getTextIndent(int)
public int indentText(int element)
element
- the element for text indentation
getTextIndent(int)
public int indentText(int element, int desiredIndent)
element
- the element for text indentationdesiredIndent
- the desired indent column
indentText(int,String)
public int indentText(int element, String desiredIndent)
element
- the element for text indentationdesiredIndent
- the desired indentation (a String consisting of space
and / or tab characters)
indentText(int)
public String getCommentStyleCharacters()
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
.
public final void setStyle(String styles, String installAttributes)
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); |
styles
- a string of one or more style characters to setinstallAttributes
- parser's install (hard-coded) attributes for the
active paletteBACKGROUND_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
public String getStyles()
setStyle()
.
null
if nonegetInstallStyleAttributes()
public ArrayList<String> getInstallStyleAttributes()
setStyle()
.
null
if nonegetStyles()
public String getStyleName(char styleCharacter)
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).
styleCharacter
- the style character queried, for example, 'c'
null
if noneSTYLE_NAME
public String styleString(char style, int len)
len
-long token.
style
- style character for the tokenlen
- token lengthpublic void lineComment(String text, boolean comment)
text
- line-comment text,
for example, "//" for .java and .cpp, "#" for .propertiescomment
- true
= add line comments, or
false
= remove line comments from the start of the line's textprotected final boolean defineFilterAction(String actionName, String includedClasses)
LpexBaseAction
with the specified name, for the document view associated with this
instance of the parser.
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
false
on incorrect classes parameterdefineFilterAction(String,String,String)
,
getPopupItems(int)
protected final boolean defineFilterAction(String actionName, String includedClasses, String excludedClasses)
LpexBaseAction
with the specified name, for the document view associated with this
instance of the parser.
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_MESSAGEexcludedClasses
- the registered element class(es) to be excluded by this action
or null
for none,
for example, "comment"
false
on incorrect classes parametersdefineFilterAction(String,String)
,
getPopupItems(int)
protected final void addMessage(int element, String text)
CLASS_MESSAGE
element class,
and is set the default STYLE_MESSAGE
style character.
element
- the text element number this message pertains totext
- the message textremoveMessages(int,int)
,
addMessage(int,String,long)
,
addMessage(int,String,long,char)
protected final void addMessage(int element, String text, long messageClass)
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).
element
- the text element number this message pertains totext
- the message textmessageClass
- bit-mask of the registered element class for this messageremoveMessages(int,int,long)
,
addMessage(int,String)
,
addMessage(int,String,long,char)
protected final void addMessage(int element, String text, long messageClass, char messageStyle)
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.
element
- the text element number this message pertains totext
- the message textmessageClass
- bit-mask of the registered element class for this messagemessageStyle
- registered style character for this messageremoveMessages(int,int,long)
,
addMessage(int,String)
,
addMessage(int,String,long)
protected final void addDocumentMessage(int element, String text, String messageClass, char messageStyle)
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.
element
- the text element number this message pertains totext
- the message textmessageClass
- registered element class for this messagemessageStyle
- registered style character for this messageremoveDocumentMessages(int,int,String)
,
addMessage(int,String,long,char)
public static boolean copyDocumentMessages(LpexView targetView, int sourceViewId, String messageClass)
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.
targetView
- the document view in which to embed the document messagessourceViewId
- id of the source document viewmessageClass
- registered element class(es) for the document messages to copy
false
on incorrect parametersaddDocumentMessage(int,String,String,char)
,
removeDocumentMessages(int,int,String)
protected final void removeMessages(int fromElement, int toElement)
fromElement
- first text element in the rangetoElement
- last text element for which this parser's messages should be removedaddMessage(int,String)
,
removeMessages(int,int,long)
protected final void removeMessages(int fromElement, int toElement, long messageClass)
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.
fromElement
- first text element in the rangetoElement
- last text element for which this parser's messages should be removedmessageClass
- bit-mask of the registered element class(es) for the messages to removeaddMessage(int,String,long)
,
addMessage(int,String,long,char)
,
removeMessages(int,int)
protected final void removeDocumentMessages(int fromElement, int toElement, String messageClass)
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.
fromElement
- first text element in the rangetoElement
- last text element for which document messages should be removedmessageClass
- registered element class(es) for the messages to removeaddDocumentMessage(int,String,String,char)
,
removeMessages(int,int,long)
|
LPEX 4.4.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |