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

Hello everybody. 
I want to try my luck and revive this very old thread. I have a few
questions regarding this very useful, but old post from Sebastian Wagner-2.
I have not much hope that Sebastian will answer me, as his last post is from
2015, but I hope someone else can help here.

I am trying to add Keywords to CDT Parser as well, and it's already working,
somehow. But it's somehow "luck" and not based on deep understanding. I also
want to extend the parser so that I don't get errors for my new keywords and
I can't find any working examples for this task. 

Questions:
1.) In his language, which extends GCCLanguage, Sebastian uses a getID
method. My language extends GPPLanguage, which already has that method, but
it's overriden in my Language class. Is this method important for eclipse's
plugin system? Is eclipse looking for that ID?

2.) In the language class the method createParser is implemented. It uses a
Scanner (IARCScanner). Unfortunately this has not been shown to us. So I
created a class that implements IScanner. At the moment it looks like this:

public class RTTLScanner implements IScanner {
	private IScanner scanner = null;

	public RTTLScanner(IScanner scanner) {
		this.scanner = scanner;
	}
 ...

and all methods just call the method from "scanner". The question is: What
can I do with this class? Is it important to have an own implementation of
one of its methods? 

3.)
Sebastian shows us his implementation of the scanner extension
configuration, but not the parser extension configuration. As far as I
understand, this is sufficient for adding keywords (the original question is
about adding keywords only).
Can anyone show me an example for the parser extension configuration?

4.) I often get a warning in eclipse when using some CDT classes. For
example: In my Scanner class, there is a method
	@Override
	public ILocationResolver getLocationResolver() {
		return scanner.getLocationResolver();
	}

ILocationResolver is underlined and it says "Discouraged access: The type
'ILocationResolver' is not API"
Can I ignore this?

5.)

Sebastian Wagner-2 wrote
> Furthermore you need to map the content type to your language. I did this
> using the org.eclipse.cdt.core.language and
> org.eclipse.core.contenttype.contentTypes extension points.

I added a content-type to the extension point
*org.eclipse.core.contenttype.contentTypes*. It looks like this:
   <extension
         point="org.eclipse.core.contenttype.contentTypes">
      <content-type
            file-extensions="rts, rtt, ext"
            id="de.blub.contenttype.rts"
            name="RTS"
            priority="high">
      </content-type>
   </extension>

I hoped that all files with the specified extensions would be associated
with the language.

For the language I added another entry:

   <extension
         point="org.eclipse.cdt.core.language">
      <language
            class="de.blub.ide.editors.rts.RTSLanguage"
            id="de.blub.language.rttl"
            name="Really totally special Language">
         <contentType
               id="de.blub.contenttype.rts">
         </contentType>
      </language>
   </extension>

I also created an editorContentTypeBinding entry in the extension point
"org.eclipse.ui.editors"

    <editorContentTypeBinding
        contentTypeId="de.blub.contenttype.rts"
        editorId="de.blub.ide.rttleditor">
    </editorContentTypeBinding>

So when I start my plugin and open a file with the extension "rts", I can
see that my new keywords are not recognized.

But the other approach....
I can go ti Window->Preferences->General->Content Types
There I can see my Content Type "RTS" listed. I can also see the File
associations and in the third part of the settings page I can see the
correct editor. I cannot edit or remove the existing File associations,
probably because they have been added by the Plugin (there is a lock icon
next to the entries). But I can add a new one, say "*.grasp", associate it
with the RTS content type and my editor. So basically everything is the
same, but I did it manually.
And then it's working, but only for the manually added file association. My
new keywords get highlighted.
What am I missing?

Thanks
Sadik



Sebastian Wagner-2 wrote
> This is my implementation:
> 
> public class IARCScannerExtensionConfiguration extends
> AbstractScannerExtensionConfiguration {
> 
>     private static IARCScannerExtensionConfiguration instance;
>     
>     public static synchronized IARCScannerExtensionConfiguration
> getInstance() {
>         if(instance == null)
>             instance = new IARCScannerExtensionConfiguration();
>         return instance;
>     }
>     
>     private IARCScannerExtensionConfiguration() {
>         /*
>            add part of GNU configuration
>         */
>         addKeyword(GCCKeywords.cp__ASM, IToken.t_asm); 
>         addKeyword(GCCKeywords.cp__ASM__, IToken.t_asm); 
>         addKeyword(GCCKeywords.cp__CONST, IToken.t_const); 
>         addKeyword(GCCKeywords.cp__CONST__, IToken.t_const); 
>         addKeyword(GCCKeywords.cp__INLINE, IToken.t_inline); 
>         addKeyword(GCCKeywords.cp__INLINE__, IToken.t_inline); 
>         addKeyword(GCCKeywords.cp__VOLATILE, IToken.t_volatile); 
>         addKeyword(GCCKeywords.cp__VOLATILE__, IToken.t_volatile); 
>         addKeyword(GCCKeywords.cp__SIGNED, IToken.t_signed); 
>         addKeyword(GCCKeywords.cp__SIGNED__, IToken.t_signed); 
>         addKeyword(GCCKeywords.cp__TYPEOF, IGCCToken.t_typeof); 
>         addKeyword(GCCKeywords.cp__TYPEOF__, IGCCToken.t_typeof); 
>         addKeyword(GCCKeywords.cpTYPEOF, IGCCToken.t_typeof );        
>         
>         /*
>            add IAR C specific configuration
>         */        
>         addKeyword("__bitvar".toCharArray(), IGCCToken.tIDENTIFIER );        
>         
>         /*
>            add general keywords configuration
>         */    
>         addKeyword("double".toCharArray(), IGCCToken.tIDENTIFIER );
>         
>         addMacro("__bitvar", "");
> }
> 
> In addition find here the definition of the language:
> public class IARCLanguage extends GCCLanguage {
>     
>     public static final String ID =
> "com.valeo.vws.cdt.iartoolchain.iarclanguage"; //$NON-NLS-1$ 
> 
>     private static IARCLanguage DEFAULT = new IARCLanguage();
>     
>     public static IARCLanguage getDefault() {
>         return DEFAULT;
>     }
>     
>     public String getId() {
>         return ID; 
>     }
> 
>     @Override
>     protected ISourceCodeParser createParser(IScanner scanner,
>             IParserLogService log, IIndex index, boolean forCompletion,
>             int options) {
>         if (!(scanner instanceof IARCScanner)) {
>             scanner = new IARCScanner(scanner);
>         }
>         return super.createParser(scanner, log, index, forCompletion,
> options);
>     }
>     
>     @Override
>     protected IScannerExtensionConfiguration
> getScannerExtensionConfiguration(IScannerInfo info) {
>         return IARCScannerExtensionConfiguration.getInstance();
>     }
>     
>     @Override
>     protected ICParserExtensionConfiguration
> getParserExtensionConfiguration() {
>         return IARCParserExtensionConfiguration.getInstance();
>     }
> 
> }
> 
> Furthermore you need to map the content type to your language. I did this
> using the org.eclipse.cdt.core.language and
> org.eclipse.core.contenttype.contentTypes extension points. In addition I
> added a languate mapping in the project properties->C/C++
> General->Language Mappings.
> 
> Hope this helps.
> 
> Regards, Sebastian





--
Sent from: http://eclipse.1072660.n5.nabble.com/Eclipse-CDT-Development-f46177.html


Back to the top