mirror of https://github.com/icsharpcode/ILSpy.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
62 lines
1.9 KiB
// <file> |
|
// <copyright see="prj:///doc/copyright.txt"/> |
|
// <license see="prj:///doc/license.txt"/> |
|
// <owner name="none" email=""/> |
|
// <version>$Revision$</version> |
|
// </file> |
|
|
|
using System; |
|
using System.IO; |
|
using System.Text; |
|
|
|
namespace ICSharpCode.NRefactory |
|
{ |
|
public enum SupportedLanguage { |
|
CSharp, |
|
VBNet |
|
} |
|
|
|
/// <summary> |
|
/// Static helper class that constructs lexer and parser objects. |
|
/// </summary> |
|
public static class ParserFactory |
|
{ |
|
public static Parser.ILexer CreateLexer(SupportedLanguage language, TextReader textReader) |
|
{ |
|
switch (language) { |
|
case SupportedLanguage.CSharp: |
|
return new ICSharpCode.NRefactory.Parser.CSharp.Lexer(textReader); |
|
case SupportedLanguage.VBNet: |
|
return new ICSharpCode.NRefactory.Parser.VB.Lexer(textReader); |
|
} |
|
throw new System.NotSupportedException(language + " not supported."); |
|
} |
|
|
|
public static IParser CreateParser(SupportedLanguage language, TextReader textReader) |
|
{ |
|
Parser.ILexer lexer = CreateLexer(language, textReader); |
|
switch (language) { |
|
case SupportedLanguage.CSharp: |
|
return new ICSharpCode.NRefactory.Parser.CSharp.Parser(lexer); |
|
case SupportedLanguage.VBNet: |
|
return new ICSharpCode.NRefactory.Parser.VB.Parser(lexer); |
|
} |
|
throw new System.NotSupportedException(language + " not supported."); |
|
} |
|
|
|
public static IParser CreateParser(string fileName) |
|
{ |
|
return CreateParser(fileName, Encoding.UTF8); |
|
} |
|
|
|
public static IParser CreateParser(string fileName, Encoding encoding) |
|
{ |
|
string ext = Path.GetExtension(fileName); |
|
if (ext.Equals(".cs", StringComparison.InvariantCultureIgnoreCase)) |
|
return CreateParser(SupportedLanguage.CSharp, new StreamReader(fileName, encoding)); |
|
if (ext.Equals(".vb", StringComparison.InvariantCultureIgnoreCase)) |
|
return CreateParser(SupportedLanguage.VBNet, new StreamReader(fileName, encoding)); |
|
return null; |
|
} |
|
} |
|
}
|
|
|