Is there a CSharpSourceReader ?

May 26, 2010 at 12:50 PM

I see in the tests there is a CSharpSourceEmitter and I can see a .felt file which appears to be a grammar for reading C# but I don't see any classes for actually doing the parsing? Does this exist in the codebase anywhere?

Coordinator
May 26, 2010 at 5:27 PM

The grammar file was created for a parser generator that hasn't quite seen the light of day as far as I know.

There is a partially complete parser for C# that produces CCI AST nodes, lurking in http://specsharp.codeplex.com under the SpecSharp2 directory.

May 26, 2010 at 6:02 PM

Sweet! And it looks like it's using the Cci already so that is perfect. Even if it's not totally complete, mostly working is probably good enough for me at this point... assuming it will be improved over time.

Specifically I'm trying to update my project MetaSharp to use the Cci. One of the things I have had to do was to create AST nodes for common compiler constructs and a matching language so I could do text templating and dynamic compilation. It's just a ton of work and overlaps directly with the Cci (I believe). So I'd much rather piggy back on the work you're doing here but one of the things I need is the ability to parse code into an AST! 

MetaSharp has done a lot of changing overtime but the primary part of it right now is the Pattern Matching library and grammar right now. I would love it if what it generated was Cci compatible AST nodes and parsers. Then I could use all of the libraries down the chain instead of doing it myself. 

One of the scenarios I have is like this:

  1. Author a DSL Grammar.
  2. Compile grammar into a parser.
  3. Parse DSL Code into AST using that grammar.
  4. Use a text template (like T4) to transform the DSL AST into code.
  5. Parse that code into an AST (which is what I need the CSharp parser for, and other languages eventually).
  6. Transform the Code AST into Linq Expression AST.
  7. Compile the linq AST into a delegate (aka IL).
  8. Execute!

I actually have this working right now but in order to do it I had to write my own Language, Code AST and Text Templating tool (yikes!). I would like to drop my custom language and use a C# parser, drop my AST and use the Cci and drop my templating tool and just use T4. One of the things I would really like to do with the Cci is to take the assembly created with it and load that assembly using the RunAndCollect flag. That would allow me to do anything dynamically. The linq expressions allow you to do things dynamically but they're very constrained. You cannot create dynamic types for example.

So if you have any thoughts or helpful hints about what I should know about the Cci to help me here I would appreciate it! Thanks.