generifying language parser

I'm looking at writing a C# parser for IntelliJ. The reason is I need a proper C# editor on OSX. I could live with C# 2.0. My initial thought is to take the java implementations and just copy them, and this is probably what I will do at first. However, that leaves me with the classic fork problems: as the java code is updated, I have to manually update the C# code (ok git will help a lot, but I've so been-there-done-that).

My quesion is this:

How much copying do I need to do? Or, "where do I stop?"

Would I be correct in thinking that if I generate PsiClasses and PsiLocalVariables etc, that inspections such as ClassNamePrefixedWithPackageNameInspection will work on the C# source?

Thanks,

James

3 comments

The amount of code (copied or newly written) you need to do really depends on how much functionality you want to have; this could be anything from a couple hundred classes to several thousands. Note that C# differs from Java significantly enough that simple copying won't do; you would need to have custom implementations for a lot of stuff. The API allows you to re-use some Java PSI classes for non-Java languages (for example, our Groovy and Scala plugins express their classes as PsiClass), but I'm not sure you would want to do that - as a simplest example, there's no way to express an "internal" or "protected internal" visibility modifier on a PsiClass.

If I were you, I'd simply use SharpDevelop running under Mono.

0

I'm using Resharper via vmware Fusion at the moment :-) You guys have completely changed the way I write code. Not even the great refactoring in Eclipse is good enough. The biggest single thing I do, that doesn't have an analog anywhere else, is write method calls before they exist, and then use quick fix to generate them, with R#/IJ infering the argument types. Priceless. So, some more questions:

Are the PSI classes meant to be Java (or Java derived) only? Are they JVM specific?
If not, I could add the extra stuff, like internal. Java has package-only classes, though they are not assembly specific. Worst case, I could live without internal. I could also live with C# 2.0.

I'm not afraid to right a RDP, though I prefer antlr - got lazy in my old age :-)

Jamie

0

Hello James,

I'm using Resharper via vmware Fusion at the moment :) You guys have
completely changed the way I write code. Not even the great
refactoring in Eclipse is good enough. The biggest single thing I do,
that doesn't have an analog anywhere else, is write method calls
before they exist, and then use quick fix to generate them, with R#/IJ
infering the argument types. Priceless. So, some more questions:

Are the PSI classes meant to be Java (or Java derived) only? Are they
JVM specific?


The PSI classes were originally designed to represent Java only. Later some
of higher-level classes (PsiClass/PsiMethod) were adapted to be compatible
with other JVM-based languages, but all the lower-level PSI (statements,
expressions etc.) is still meant to be Java-only.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.