Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Attempting to make a Cosmic C Language Extension

After reading, I'm trying to make a new language extension for the Cosmic dialect of C. Mostly the problem is "@" keywords such as @far. I've looked at bug #237028, and I also went off Mike Kucera's message to this group, "Re: [cdt-dev] How to extend the C99 / GCC LR Parser." on 11-Jul-2011 in which he suggests using an ILanguage extension point and providing my own configuration that implements IScannerExtensionConfiguration and defines supportAtSignInIdentifiers().

I've made the language plugin consisting of, CosmicCLanguage.Java, and I can choose my new language under Language Mappings in the CDT. However the parser still trips up over @far. Here's my parser log (I've deleted some lines to make it smaller):

===== BEGIN parser.log =====
Project:               Foo
File:                  file:/C:/Documents%20and%20Settings/watkinsp/runtime-EclipseApplication/Foo/foo.c
Language:              Cosmic C
Index Version:         132.0
Build Configuration:   Debug
Context:               none
Versions in Index:     1
   C: {}; 0 macros, 0 includes, 1 names;

Include Search Path (option -I):

Macro definitions (option -D):

Macro definitions (from language + headers in index):
   __builtin_offsetof(T,m)=((size_t) &((T *)0)->m)
   __builtin_va_arg(ap,type)=*(typeof(type) *)ap
   __DATE__="Mar 21 2013"
   __null=(void *)0

Scanner problems:
   Bad character sequence encountered: @ in file: C:\Documents and Settings\watkinsp\runtime-EclipseApplication\Foo\foo.c:13

Parser problems:
   Syntax error in file: C:\Documents and Settings\watkinsp\runtime-EclipseApplication\Foo\foo.c:13

Written on Thu Mar 21 14:46:09 PDT 2013
===== END parser.log =====

Here's my foo.c:
===== BEGIN foo.c =====
void main(int argc, char **argv) {


void @far bar(int baz) {
        baz = 2;
===== END foo.c =====

Notice the @far on bar() (line 13). Also notice "Cosmic C" in my parser log for "Language: ". Here are the source files for my plugin:

===== BEGIN =====
package com.msei.plugin.cdtextensions;

import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;

 * @author Peter Watkins
public class CosmicCLanguage extends GCCLanguage {
        protected static final CosmicCScannerExtensionConfiguration
        COSMIC_C_SCANNER_EXTENSION = new CosmicCScannerExtensionConfiguration();

        public String getId() {
                return "com.msei.plugin.cdtextensions.cosmicc";
        protected IScannerExtensionConfiguration getScannerExtensionConfiguration() {
                return COSMIC_C_SCANNER_EXTENSION;
===== END =====

===== BEGIN =====
package com.msei.plugin.cdtextensions;

import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;

public class CosmicCScannerExtensionConfiguration extends
                GCCScannerExtensionConfiguration {
        private static CosmicCScannerExtensionConfiguration sInstance = new CosmicCScannerExtensionConfiguration();
        public static CosmicCScannerExtensionConfiguration getInstance() {
                return sInstance;

        public CosmicCScannerExtensionConfiguration() {
                addMacro("@far", "");

        public CosmicCScannerExtensionConfiguration(int version) {
                // TODO Auto-generated constructor stub
        public boolean supportAtSignInIdentifiers() {
                return true;
===== END =====

===== BEGIN =====
package com.msei.plugin.cdtextensions;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {

        private static BundleContext context;

        static BundleContext getContext() {
                return context;

         * (non-Javadoc)
         * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
        public void start(BundleContext bundleContext) throws Exception {
                Activator.context = bundleContext;

         * (non-Javadoc)
         * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
        public void stop(BundleContext bundleContext) throws Exception {
                Activator.context = null;
===== END =====

Does anything obvious stand out to you? I'm I even going in the right direction? I'm not entirely sure what I'm doing in the first place :). I'm just trying to adapt what I've already seen.



Back to the top