LPEX
4.4.0

com.ibm.lpex.cpp
Class CppParser

java.lang.Object
  extended by com.ibm.lpex.core.LpexCommonParser
      extended by com.ibm.lpex.cpp.CppParser
All Implemented Interfaces:
LpexConstants, LpexParser
Direct Known Subclasses:
CppCicsParser, CppParserAIX, CppParserOS2, CppParserWIN, CppSqlParser

public class CppParser
extends LpexCommonParser

Document parser for C/C++. This class is extended by various C/C++ document parsers for specific systems/platforms and embedded SQL/CICS/DLI support.

Editor actions and assigned keys added by this document parser:

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

Editor action modified by this document parser:

Parser properties handled directly by this parser:

See Also:
CppParserOS2, CppParserWIN, CppParserAIX, CppSqlParser, CppSqlParserOS2, CppSqlParserWIN, CppSqlParserAIX

Field Summary
protected static String CLASS_BRACE
          C/C++ parser element class.
protected static String CLASS_BWDLINK
          C/C++ parser element class.
protected static String CLASS_CASE
          C/C++ parser element class.
protected static String CLASS_CICS
          C/C++ parser element class.
protected static String CLASS_CLASS
          C/C++ parser element class.
protected static String CLASS_CODE
          C/C++ parser element class.
protected static String CLASS_COMMENT
          C/C++ parser element class.
protected static String CLASS_COMMENTTASK
          C/C++ parser element class.
protected static String CLASS_CONTROL
          C/C++ parser element class.
protected static String CLASS_DEBUGGABLE
          C/C++ parser element class.
protected static String CLASS_DLI
          C/C++ parser element class.
protected static String CLASS_ERROR
          C/C++ parser element class.
protected static String CLASS_FUNCTION
          C/C++ parser element class.
protected static String CLASS_FWDLINK
          C/C++ parser element class.
protected static String CLASS_INCLUDE
          C/C++ parser element class.
protected static String CLASS_SEMICOLON
          C/C++ parser element class.
protected static String CLASS_SPACE
          C/C++ parser element class.
protected static String CLASS_SQL
          C/C++ parser element class.
 
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
CppParser(LpexView lpexView)
          Constructor for the parser.
 
Method Summary
protected  void addErrorMessage(int element, String message)
          Displays an embedded error message for an element.
 LpexSubparser getCicsLexer(LpexCharStream lexerStream)
          Returns the CICS lexer.
 String getCommentStyleCharacters()
          Returns the style characters used for styling comments ("c$").
protected  LpexSubparser getDliLexer(LpexCharStream lexerStream)
          Returns the DLI lexer.
 String getLanguage()
          Returns "CPP", the language supported by this parser (C/C++).
 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 getPopupItem(String key)
           
protected  String getPopupItems(int popupLocation)
          Returns this parser's contribution to the popup.
 ResourceBundle getProfile()
          Returns this parser's profile resource bundle.
 SqlLexer getSqlLexer(LpexCharStream lexerStream)
          Returns the SQL lexer.
protected  LpexCharStream getStream()
          Returns the character stream used by the parser.
protected  void initParser()
          Initializes the parser.
 boolean isCLibraryFunction(Token token)
          Returns whether the specified token is a C library function.
 boolean isDebuggable(int line)
          Returns whether the specified document line is debuggable.
 boolean isExtensionKeyword(Token token)
          Returns whether the specified token is an extension keyword.
 boolean isTokenDelimiter(char ch)
          Returns whether the specified character is a token delimiter.
 boolean isWordCharacter(int element, int position)
          Redefines word characters for adequate word navigation in C/C++ documents.
 void parseAll()
          Total parse of the entire document.
 void parseElement(int element)
          Incremental parse.
protected  void propertySet(String key)
          Listens to changes to the taskTags parser property in this view.
protected  boolean setLexer(int newLexer)
          Sets or changes the active lexer.
 void setStyleAttributes()
          Defines this parser's style attributes.
 
Methods inherited from class com.ibm.lpex.core.LpexCommonParser
addDocumentMessage, addMessage, addMessage, addMessage, blockMarkWord, copyDocumentMessages, cursorIndent, defineFilterAction, defineFilterAction, expandProtoKeyword, getInstallStyleAttributes, getProperty, getStyleName, getStyles, getTextIndent, getToken, getTokenLocation, indentText, indentText, indentText, isPrimaryParser, lineComment, lpexView, matchToken, newLine, openLine, parse, 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
 

Field Detail

CLASS_CODE

protected static final String CLASS_CODE
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_DEBUGGABLE

protected static final String CLASS_DEBUGGABLE
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_SPACE

protected static final String CLASS_SPACE
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_FWDLINK

protected static final String CLASS_FWDLINK
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_BWDLINK

protected static final String CLASS_BWDLINK
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_SEMICOLON

protected static final String CLASS_SEMICOLON
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_FUNCTION

protected static final String CLASS_FUNCTION
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_BRACE

protected static final String CLASS_BRACE
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_ERROR

protected static final String CLASS_ERROR
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_COMMENT

protected static final String CLASS_COMMENT
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_COMMENTTASK

protected static final String CLASS_COMMENTTASK
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_INCLUDE

protected static final String CLASS_INCLUDE
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_CASE

protected static final String CLASS_CASE
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_CONTROL

protected static final String CLASS_CONTROL
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_CLASS

protected static final String CLASS_CLASS
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_SQL

protected static final String CLASS_SQL
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_CICS

protected static final String CLASS_CICS
C/C++ parser element class.

See Also:
Constant Field Values

CLASS_DLI

protected static final String CLASS_DLI
C/C++ parser element class.

See Also:
Constant Field Values
Constructor Detail

CppParser

public CppParser(LpexView lpexView)
Constructor for the parser.

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

initParser

protected void initParser()
Initializes the parser. Sets up the parser for the associated document view: sets style attributes, registers element classes, creates editor actions, redefines the popup, etc. for the language-sensitive edit features supported.

Overrides:
initParser in class LpexCommonParser
See Also:
Life cycle

parseAll

public void parseAll()
Total parse of the entire document. Done initially, after a document has been loaded in the editor, after an updateProfile command, and after a change to the taskTags parser property.

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

parseElement

public void parseElement(int element)
Incremental parse.

Specified by:
parseElement in class LpexCommonParser
Parameters:
element - an element affected by a committed change in this view
See Also:
LpexView.parsePending(int), LpexView.elementParsed(int), Total and incremental parse

getProfile

public ResourceBundle getProfile()
Returns this parser's profile resource bundle.

Overrides:
getProfile in class LpexCommonParser
See Also:
LpexCommonParser.getProperty(java.lang.String), Parser properties

getLanguage

public String getLanguage()
Returns "CPP", the language supported by this parser (C/C++).

Overrides:
getLanguage in class LpexCommonParser
See Also:
LpexCommonParser.LANGUAGE_CCPP

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. The method assumes that no parse is pending for this location's element.

Overrides:
getLanguage in class LpexCommonParser
Parameters:
loc - document location
Returns:
one of: LpexCommonParser.LANGUAGE_CCPP, LpexCommonParser.LANGUAGE_SQL, LpexCommonParser.LANGUAGE_CICS, LpexCommonParser.LANGUAGE_DLI
See Also:
LpexCommonParser.getLanguage(), Mixed content documents

propertySet

protected void propertySet(String key)
Listens to changes to the taskTags parser property in this view.

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

getPopupItems

protected String getPopupItems(int popupLocation)
Returns this parser's contribution to the popup. This parser contributes to the Filter view submenu (Functions, Logic outline, Errors, Tasks) and to the Source submenu (Comment, Uncomment).

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

getPopupItem

protected String getPopupItem(String key)

setStyleAttributes

public void setStyleAttributes()
Defines this parser's style attributes. The following style characters are set: '_' (layout blanks), 'k' (keyword), 'r' (keyword return), 'x' (extension keyword), 'i' (identifier), 'n' (integer/character literal), 'l' (floating-point literal), 'q' (string literal), 'o' (operator), 'p' (punctuation), 't' (continuation character), 'c' (comment), '$' (comment task tag), 'f' (C library function), 'b' (brace), 'h' (CPP directive), 'e' (error).


getCommentStyleCharacters

public String getCommentStyleCharacters()
Returns the style characters used for styling comments ("c$").

Overrides:
getCommentStyleCharacters in class LpexCommonParser

isDebuggable

public boolean isDebuggable(int line)
Returns 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.

Overrides:
isDebuggable in class LpexCommonParser
Parameters:
line - a line inside the document section that is currently loaded in the editor

isTokenDelimiter

public boolean isTokenDelimiter(char ch)
Returns whether the specified character is a token delimiter.

Overrides:
isTokenDelimiter in class LpexCommonParser
Parameters:
ch - character queried, for example ')'
See Also:
LpexCommonParser.getToken(com.ibm.lpex.core.LpexDocumentLocation), LpexCommonParser.tokenBegin(com.ibm.lpex.core.LpexDocumentLocation), LpexCommonParser.tokenEnd(com.ibm.lpex.core.LpexDocumentLocation)

isWordCharacter

public boolean isWordCharacter(int element,
                               int position)
Redefines word characters for adequate word navigation in C/C++ documents.

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

getStream

protected final LpexCharStream getStream()
Returns the character stream used by the parser.


addErrorMessage

protected void addErrorMessage(int element,
                               String message)
Displays an embedded error message for an element.

Parameters:
element - the text element in error
message - error message key in LPEX's Resources.properties

isExtensionKeyword

public boolean isExtensionKeyword(Token token)
Returns whether the specified token is an extension keyword.

A document parser subclassing CppParser may extend this method to check for extension keywords available on its target system / platform. Other extensions (such as for a particular project or compiler) may also be supported in this manner.

CppParser has no particular system or platform flavour, therefore it always returns false.

Parameters:
token - the token being queried: token.beginLine, token.beginColumn, token.endLine, and token.endColumn identify its location (ONE-based elements and positions in the associated document view)

isCLibraryFunction

public boolean isCLibraryFunction(Token token)
Returns whether the specified token is a C library function.

A document parser subclassing CppParser may extend this method to check for C library and extension C library functions available on its target system / platform.

The implementation of this method in CppParser returns true for the ANSI C library functions.

Parameters:
token - the token being queried: token.beginLine, token.beginColumn, token.endLine, and token.endColumn identify its location (ONE-based elements and positions in the associated document view)

setLexer

protected boolean setLexer(int newLexer)
Sets or changes the active lexer.

Parameters:
newLexer - the new lexer, one of: LEXER_CPP, LEXER_SQL, LEXER_CICS, or LEXER_DLI
Returns:
true = new lexer has been set as the active lexer, and initialized in its DEFAULT lexical state

getSqlLexer

public SqlLexer getSqlLexer(LpexCharStream lexerStream)
Returns the SQL lexer. A document parser extending CppParser to support embedded EXEC SQL statements must override this method to construct and return an SqlLexer object.

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

Parameters:
lexerStream - input character stream for the lexer

getCicsLexer

public LpexSubparser getCicsLexer(LpexCharStream lexerStream)
Returns the CICS lexer. A document parser extending CppParser to support embedded EXEC CICS statements must override this method to construct and return a CicsLexer object.

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

Parameters:
lexerStream - input character stream for the lexer

getDliLexer

protected LpexSubparser getDliLexer(LpexCharStream lexerStream)
Returns the DLI lexer. A document parser extending CppParser to support embedded EXEC DLI statements must override this method to construct and return a DliLexer object.

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

Parameters:
lexerStream - input character stream for the lexer

getLshToken

public String getLshToken()
Returns the current token for language-sensitive help (LSH). The token returned will serve (in common LSH implementations) as a key into the mapping table to the appropriate help panel. When null is returned, the LSH implementation should display a default language help panel.

In addition to language keywords, this parser generates the following LSH 'tokens' for special situations:

Overrides:
getLshToken in class LpexCommonParser
See Also:
Language-sensitive help

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.