Find file History

README.md

Summary

C# grammar with full support of C# 6 features and below. CSharpLexer.g4 and CSharpPreprocessor.g4 are runtime dependent (contains specific actions), because of directive preprocessors and string interpolation (these things make grammar context-sensitive). C# and Java versions supported. But CSharpParser.g4 is runtime independent. This ANTLR 4 C# grammar is based on the C# ANTLR 3 grammar from ChristianWulf/CSharpGrammar.

Using

Due to uncompiled code can be placed after such preprocessor directives:

#if SILVERLIGHT && WINDOWS_PHONE || DEBUG || foo == true
// Some code
#endif

at first stage it's necessary to calculate whether condition satisfied in directive. This step performed by runtime code in gist: CSharpAntlrParser.

Testing

I put into repository AllInOne.cs file (from Roslyn) with most common syntax and also I tested this grammar on the following most popular .NET projects:

There are some problems with deep recursion (TestData.g.cs in CoreFx), unicode chars (sjis.cs in Roslyn) and preprocessor directives.

ANTLR parser from this grammar approximately ~5-7 slowly than Roslyn parser.

License

Eclipse Public License - v 1.0