Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] How to add Keyword to CDT Parser

To highlight new keywords in the editor I called the "addKeyword" function in the constructor of my ScannerExtensionConfiguration like this:

addKeyword("myKeyword".toCharArray(), IGCCToken.tIDENTIFIER );

You can find an example implementation in GCCScannerExtensionConfiguration. I implemented my own ScannerExtensionConfiguration based on this, extending AbstractScannerExtensionConfiguration.

best regards, Sebastian

> Date: Sun, 9 Mar 2014 23:14:44 -0700
> From: y_anitha@xxxxxxxxx
> To: cdt-dev@xxxxxxxxxxx
> Subject: [cdt-dev] How to add Keyword to CDT Parser
>
> I have to extend CDT Parser to recognize some new Keywords and understand
> them. Ex: _c_status
>
> Towards this I have added an extension to org.eclipse.cdt.core.language in
> the plugin.xml file.
>
> <extension point="org.eclipse.cdt.core.language">
> <language
> class="com.dev.core.languages.NewCLanguage"
> id="c"
> name="NEW C">
> <contentType
> id="org.eclipse.cdt.core.cSource">
> </contentType>
> <contentType
> id="org.eclipse.cdt.core.cHeader">
> </contentType>
> </language>
> <extension>
>
> I have provided an implementation for the class as below:
>
> public class NewCLanguage extends GCCLanguage implements ICLanguageKeywords,
> ILanguage {
> private static final NewCLanguage DEFAULT_INSTANCE = new NewCLanguage();
> protected static final NCScannerExtensionConfiguration NC_SCANNER_EXTENSION
> =
> new NCScannerExtensionConfiguration();
>
> public static NewCLanguage getDefault() {
> return DEFAULT_INSTANCE;
> }
>
> public String getId() {
> return "com.dev.core.c";
> }
>
> public Object getAdapter(NewCLanguage language) {
> return getAdapter(this);
> }
>
> @Override
> public String[] getKeywords() {
> return new String[] {"_c_status"};
> }
>
>
> protected IScannerExtensionConfiguration getScannerExtensionConfiguration()
> {
> return NC_SCANNER_EXTENSION;
> }
> }
>
> And provided the implementation for the ScannerConfiguration as below:
>
> public class NCScannerExtensionConfiguration extends
> GCCScannerExtensionConfiguration {
> public static final String CSTATUS = "_c_status";
> public static final char[] extendcCSTATUS = "_c_status".toCharArray();
>
> public CharArrayIntMap getAdditionalKeywords() {
> CharArrayIntMap additionalCKeywords = new CharArrayIntMap(0, 0);
> additionalCKeywords.put( NCScannerExtensionConfiguration.extendcppCCSTATUS,
> IToken.t_class);
>
> return additionalCKeywords;
> }
> }
>
> I have also linked the source files to be associated with NewCLanguage in
> the Language Mappings under Preferences. Yet I don't think the new keywords
> are being recognized. Is there a way i could check if the keywords are
> recognized. The keyword is not highlighted in the editor. Should i also
> extend the editor?
>
> My second part of the query is how to extend the parser to provide the
> implementation for the keyword. the keyword _c_status is always associated
> with a function call. It means that the function call with this keyword need
> to follow a different syntax. Can you please help me with how I could
> achieve this. I need this on priority basis.
>
> Thanks in advance.
>
>
>
> --
> View this message in context: http://eclipse.1072660.n5.nabble.com/How-to-add-Keyword-to-CDT-Parser-tp166002.html
> Sent from the Eclipse CDT - Development mailing list archive at Nabble.com.
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev

Back to the top