Skip to content

Latest commit

 

History

History
 
 

csharp

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

##Summary

C# grammar with full support of C# 6 features and below. CSharpLexer.g4 and CSharpPreprocessor.g4 are .NET runtime dependent (contains specific actions), because of directive preprocessors and string interpolation (these things make grammar context-sensitive). 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 uncompilied 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 (http://www.eclipse.org/legal/epl-v10.html)