Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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.


Back to the top