當前位置: 首頁>>代碼示例>>C#>>正文


C# CSharp.CSharpParser類代碼示例

本文整理匯總了C#中Mono.CSharp.CSharpParser的典型用法代碼示例。如果您正苦於以下問題:C# CSharpParser類的具體用法?C# CSharpParser怎麽用?C# CSharpParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CSharpParser類屬於Mono.CSharp命名空間,在下文中一共展示了CSharpParser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ParseString

		//
		// Parses the string @input and returns a CSharpParser if succeeful.
		//
		// if @silent is set to true then no errors are
		// reported to the user.  This is used to do various calls to the
		// parser and check if the expression is parsable.
		//
		// @partial_input: if @silent is true, then it returns whether the
		// parsed expression was partial, and more data is needed
		//
		static CSharpParser ParseString (bool silent, string input, out bool partial_input)
		{
			partial_input = false;
			Reset ();
			queued_fields.Clear ();

			Stream s = new MemoryStream (Encoding.Default.GetBytes (input));
			SeekableStreamReader seekable = new SeekableStreamReader (s, Encoding.Default);

			InputKind kind = ToplevelOrStatement (seekable);
			if (kind == InputKind.Error){
				if (!silent)
					Report.Error (-25, "Detection Parsing Error");
				partial_input = false;
				return null;
			}

			if (kind == InputKind.EOF){
				if (silent == false)
					Console.Error.WriteLine ("Internal error: EOF condition should have been detected in a previous call with silent=true");
				partial_input = true;
				return null;
				
			}
			seekable.Position = 0;

			CSharpParser parser = new CSharpParser (seekable, (CompilationUnit) Location.SourceFiles [0]);
			parser.ErrorOutput = Report.Stderr;

			if (kind == InputKind.StatementOrExpression){
				parser.Lexer.putback_char = Tokenizer.EvalStatementParserCharacter;
				RootContext.StatementMode = true;
			} else {
				//
				// Do not activate EvalCompilationUnitParserCharacter until
				// I have figured out all the limitations to invoke methods
				// in the generated classes.  See repl.txt
				//
				parser.Lexer.putback_char = Tokenizer.EvalUsingDeclarationsParserCharacter;
				//parser.Lexer.putback_char = Tokenizer.EvalCompilationUnitParserCharacter;
				RootContext.StatementMode = false;
			}

			if (silent)
				Report.DisableReporting ();
			try {
				parser.parse ();
			} finally {
				if (Report.Errors != 0){
					if (silent && parser.UnexpectedEOF)
						partial_input = true;

					parser.undo.ExecuteUndo ();
					parser = null;
				}

				if (silent)
					Report.EnableReporting ();
			}
			return parser;
		}
開發者ID:lewurm,項目名稱:benchmarker,代碼行數:71,代碼來源:eval.cs

示例2: Simple

		public void Simple ()
		{
			//string content = @"class A { }";
			string content = @"

class Foo
{
	void Bar ()
	{
completionList.Add (""delegate"" + sb, ""md-keyword"", GettextCatalog.GetString (""Creates anonymous delegate.""), ""delegate"" + sb + "" {"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent + TextEditorProperties.IndentString + ""|"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent +""};"");
	}
}"
	;


			var stream = new MemoryStream (Encoding.UTF8.GetBytes (content));

			var ctx = new CompilerContext (new CompilerSettings (), new AssertReportPrinter ());

			ModuleContainer module = new ModuleContainer (ctx);
			var file = new SourceFile ("test", "asdfas", 0);
			CSharpParser parser = new CSharpParser (
				new SeekableStreamReader (stream, Encoding.UTF8),
				new CompilationSourceFile (module, file),
				ctx.Report,
				new ParserSession ());

			RootContext.ToplevelTypes = module;
			Location.Initialize (new List<SourceFile> { file });
			parser.parse ();

			Assert.AreEqual (0, ctx.Report.Errors);

			module.Accept (new TestVisitor ());
		}
開發者ID:ItsVeryWindy,項目名稱:mono,代碼行數:35,代碼來源:ASTVisitorTest.cs

示例3: Parse

        public static void Parse(SeekableStreamReader reader, SourceFile sourceFile, ModuleContainer module, ParserSession session, Report report)
        {
            var file = new CompilationSourceFile(module, sourceFile);
            module.AddTypeContainer(file);

            CSharpParser parser = new CSharpParser(reader, file, report, session);
            parser.parse();
        }
開發者ID:Nystul-the-Magician,項目名稱:daggerfall-unity,代碼行數:8,代碼來源:CustomDynamicDriver.cs

示例4: Simple

		public void Simple ()
		{
			//string content = @"class A { }";
			string content = @"

class Foo
{
	void Bar ()
	{
completionList.Add (""delegate"" + sb, ""md-keyword"", GettextCatalog.GetString (""Creates anonymous delegate.""), ""delegate"" + sb + "" {"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent + TextEditorProperties.IndentString + ""|"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent +""};"");
	}
}"
	;


			var stream = new MemoryStream (Encoding.UTF8.GetBytes (content));

			var ctx = new CompilerContext (new CompilerSettings (), new Report (new AssertReportPrinter ()));

			ModuleContainer module = new ModuleContainer (ctx);
			CSharpParser parser = new CSharpParser (
				new SeekableStreamReader (stream, Encoding.UTF8),
				new CompilationUnit ("name", "path", 0),
				module);

			RootContext.ToplevelTypes = module;
			Location.AddFile (ctx.Report, "asdfas");
			Location.Initialize ();
			parser.LocationsBag = new LocationsBag ();
			parser.parse ();

			var m = module.Types[0].Methods[0] as Method;
			var s = m.Block.FirstStatement;
			var o = s.loc.Column;
			

			module.Accept (new TestVisitor ());
		}
開發者ID:nlhepler,項目名稱:mono,代碼行數:38,代碼來源:ASTVisitorTest.cs

示例5: ParseSnippet

		/*
		/// <summary>
		/// Parses a file snippet; guessing what the code snippet represents (whole file, type members, block, type reference, expression).
		/// </summary>
		public AstNode ParseSnippet (string code)
		{
			// TODO: add support for parsing a part of a file
			throw new NotImplementedException ();
		}
		 */
		public DocumentationReference ParseDocumentationReference(string cref)
		{
			// see Mono.CSharp.DocumentationBuilder.HandleXrefCommon
			if (cref == null)
				throw new ArgumentNullException("cref");
			
			// Additional symbols for < and > are allowed for easier XML typing
			cref = cref.Replace('{', '<').Replace('}', '>');
			
			lock (parseLock) {
				errorReportPrinter = new ErrorReportPrinter("");
				var ctx = new CompilerContext(compilerSettings.ToMono(), errorReportPrinter);
				ctx.Settings.TabSize = 1;
				var reader = new SeekableStreamReader(new StringTextSource(cref));
				var file = new SourceFile("", "", 0);
				Location.Initialize(new List<SourceFile>(new [] { file }));
				var module = new ModuleContainer(ctx);
				module.DocumentationBuilder = new DocumentationBuilder(module);
				var source_file = new CompilationSourceFile(module);
				var report = new Report(ctx, errorReportPrinter);
				var session = new ParserSession();
				session.LocationsBag = new LocationsBag();
				var parser = new Mono.CSharp.CSharpParser(reader, source_file, report, session);
				parser.Lexer.Line += initialLocation.Line - 1;
				parser.Lexer.Column += initialLocation.Column - 1;
				parser.Lexer.putback_char = Tokenizer.DocumentationXref;
				parser.Lexer.parsing_generic_declaration_doc = true;
				parser.parse();
				if (report.Errors > 0) {
//					Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
//					                mc.GetSignatureForError (), cref);
				}
				
				var conversionVisitor = new ConversionVisitor(false, session.LocationsBag);
				var docRef = conversionVisitor.ConvertXmlDoc(module.DocumentationBuilder);
				CompilerCallableEntryPoint.Reset();
				return docRef;
			}
		}
開發者ID:0xb1dd1e,項目名稱:NRefactory,代碼行數:49,代碼來源:CSharpParser.cs

示例6: ParseString

		//
		// Parses the string @input and returns a CSharpParser if succeeful.
		//
		// if @silent is set to true then no errors are
		// reported to the user.  This is used to do various calls to the
		// parser and check if the expression is parsable.
		//
		// @partial_input: if @silent is true, then it returns whether the
		// parsed expression was partial, and more data is needed
		//
		CSharpParser ParseString (ParseMode mode, string input, out bool partial_input)
		{
			partial_input = false;
			Reset ();

			var enc = ctx.Settings.Encoding;
			var s = new MemoryStream (enc.GetBytes (input));
			SeekableStreamReader seekable = new SeekableStreamReader (s, enc);

			InputKind kind = ToplevelOrStatement (seekable);
			if (kind == InputKind.Error){
				if (mode == ParseMode.ReportErrors)
					ctx.Report.Error (-25, "Detection Parsing Error");
				partial_input = false;
				return null;
			}

			if (kind == InputKind.EOF){
				if (mode == ParseMode.ReportErrors)
					Console.Error.WriteLine ("Internal error: EOF condition should have been detected in a previous call with silent=true");
				partial_input = true;
				return null;
				
			}
			seekable.Position = 0;

			source_file.DeclarationFound = false;
			CSharpParser parser = new CSharpParser (seekable, source_file);

			if (kind == InputKind.StatementOrExpression){
				parser.Lexer.putback_char = Tokenizer.EvalStatementParserCharacter;
				ctx.Settings.StatementMode = true;
			} else {
				parser.Lexer.putback_char = Tokenizer.EvalCompilationUnitParserCharacter;
				ctx.Settings.StatementMode = false;
			}

			if (mode == ParseMode.GetCompletions)
				parser.Lexer.CompleteOnEOF = true;

			ReportPrinter old_printer = null;
			if ((mode == ParseMode.Silent || mode == ParseMode.GetCompletions))
				old_printer = ctx.Report.SetPrinter (new StreamReportPrinter (TextWriter.Null));

			try {
				parser.parse ();
			} finally {
				if (ctx.Report.Errors != 0){
					if (mode != ParseMode.ReportErrors  && parser.UnexpectedEOF)
						partial_input = true;

					if (parser.undo != null)
						parser.undo.ExecuteUndo ();

					parser = null;
				}

				if (old_printer != null)
					ctx.Report.SetPrinter (old_printer);
			}
			return parser;
		}
開發者ID:KAW0,項目名稱:Alter-Native,代碼行數:72,代碼來源:eval.cs

示例7: HandleXrefCommon

		//
		// Processes "see" or "seealso" elements from cref attribute.
		//
		void HandleXrefCommon (MemberCore mc, TypeContainer ds, XmlElement xref)
		{
			string cref = xref.GetAttribute ("cref");
			// when, XmlReader, "if (cref == null)"
			if (!xref.HasAttribute ("cref"))
				return;

			// Nothing to be resolved the reference is marked explicitly
			if (cref.Length > 2 && cref [1] == ':')
				return;

			// Additional symbols for < and > are allowed for easier XML typing
			cref = cref.Replace ('{', '<').Replace ('}', '>');

			var encoding = module.Compiler.Settings.Encoding;
			var s = new MemoryStream (encoding.GetBytes (cref));
			SeekableStreamReader seekable = new SeekableStreamReader (s, encoding);

			var source_file = new CompilationSourceFile (doc_module);
			var report = new Report (doc_module.Compiler, new NullReportPrinter ());

			var parser = new CSharpParser (seekable, source_file, report);
			ParsedParameters = null;
			ParsedName = null;
			ParsedBuiltinType = null;
			ParsedOperator = null;
			parser.Lexer.putback_char = Tokenizer.DocumentationXref;
			parser.Lexer.parsing_generic_declaration_doc = true;
			parser.parse ();
			if (report.Errors > 0) {
				Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
					mc.GetSignatureForError (), cref);

				xref.SetAttribute ("cref", "!:" + cref);
				return;
			}

			MemberSpec member;
			string prefix = null;
			FullNamedExpression fne = null;

			//
			// Try built-in type first because we are using ParsedName as identifier of
			// member names on built-in types
			//
			if (ParsedBuiltinType != null && (ParsedParameters == null || ParsedName != null)) {
				member = ParsedBuiltinType.Type;
			} else {
				member = null;
			}

			if (ParsedName != null || ParsedOperator.HasValue) {
				TypeSpec type = null;
				string member_name = null;

				if (member == null) {
					if (ParsedOperator.HasValue) {
						type = mc.CurrentType;
					} else if (ParsedName.Left != null) {
						fne = ResolveMemberName (mc, ParsedName.Left);
						if (fne != null) {
							var ns = fne as Namespace;
							if (ns != null) {
								fne = ns.LookupTypeOrNamespace (mc, ParsedName.Name, ParsedName.Arity, LookupMode.Probing, Location.Null);
								if (fne != null) {
									member = fne.Type;
								}
							} else {
								type = fne.Type;
							}
						}
					} else {
						fne = ResolveMemberName (mc, ParsedName);
						if (fne == null) {
							type = mc.CurrentType;
						} else if (ParsedParameters == null) {
							member = fne.Type;
						} else if (fne.Type.MemberDefinition == mc.CurrentType.MemberDefinition) {
							member_name = Constructor.ConstructorName;
							type = fne.Type;
						}
					}
				} else {
					type = (TypeSpec) member;
					member = null;
				}

				if (ParsedParameters != null) {
					var old_printer = mc.Module.Compiler.Report.SetPrinter (new NullReportPrinter ());
					foreach (var pp in ParsedParameters) {
						pp.Resolve (mc);
					}
					mc.Module.Compiler.Report.SetPrinter (old_printer);
				}

				if (type != null) {
					if (member_name == null)
//.........這裏部分代碼省略.........
開發者ID:royleban,項目名稱:mono,代碼行數:101,代碼來源:doc.cs

示例8: ParseString

		//
		// Parses the string @input and returns a CSharpParser if succeeful.
		//
		// if @silent is set to true then no errors are
		// reported to the user.  This is used to do various calls to the
		// parser and check if the expression is parsable.
		//
		// @partial_input: if @silent is true, then it returns whether the
		// parsed expression was partial, and more data is needed
		//
		static CSharpParser ParseString (ParseMode mode, string input, out bool partial_input)
		{
			partial_input = false;
			Reset ();
			queued_fields.Clear ();
			Tokenizer.LocatedToken.Initialize ();

			Stream s = new MemoryStream (Encoding.Default.GetBytes (input));
			SeekableStreamReader seekable = new SeekableStreamReader (s, Encoding.Default);

			InputKind kind = ToplevelOrStatement (seekable);
			if (kind == InputKind.Error){
				if (mode == ParseMode.ReportErrors)
					ctx.Report.Error (-25, "Detection Parsing Error");
				partial_input = false;
				return null;
			}

			if (kind == InputKind.EOF){
				if (mode == ParseMode.ReportErrors)
					Console.Error.WriteLine ("Internal error: EOF condition should have been detected in a previous call with silent=true");
				partial_input = true;
				return null;
				
			}
			seekable.Position = 0;

			CSharpParser parser = new CSharpParser (seekable, (CompilationUnit) Location.SourceFiles [0], ctx);

			if (kind == InputKind.StatementOrExpression){
				parser.Lexer.putback_char = Tokenizer.EvalStatementParserCharacter;
				RootContext.StatementMode = true;
			} else {
				//
				// Do not activate EvalCompilationUnitParserCharacter until
				// I have figured out all the limitations to invoke methods
				// in the generated classes.  See repl.txt
				//
				parser.Lexer.putback_char = Tokenizer.EvalUsingDeclarationsParserCharacter;
				//parser.Lexer.putback_char = Tokenizer.EvalCompilationUnitParserCharacter;
				RootContext.StatementMode = false;
			}

			if (mode == ParseMode.GetCompletions)
				parser.Lexer.CompleteOnEOF = true;

			ReportPrinter old_printer = null;
			if ((mode == ParseMode.Silent || mode == ParseMode.GetCompletions) && CSharpParser.yacc_verbose_flag == 0)
				old_printer = SetPrinter (new StreamReportPrinter (TextWriter.Null));

			try {
				parser.parse ();
			} finally {
				if (ctx.Report.Errors != 0){
					if (mode != ParseMode.ReportErrors  && parser.UnexpectedEOF)
						partial_input = true;

					parser.undo.ExecuteUndo ();
					parser = null;
				}

				if (old_printer != null)
					SetPrinter (old_printer);
			}
			return parser;
		}
開發者ID:silk,項目名稱:monodevelop,代碼行數:76,代碼來源:eval.cs

示例9: ParseFile

		public static CompilerCompilationUnit ParseFile (string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
		{
			lock (parseLock) {
				try {
					Driver d = Driver.Create (args, false, reportPrinter);
					if (d == null)
						return null;
	
					Location.AddFile (null, inputFile);
					Location.Initialize ();
	
					// TODO: encoding from driver
					SeekableStreamReader reader = new SeekableStreamReader (input, Encoding.Default);
	
					CompilerContext ctx = new CompilerContext (new ReflectionMetaImporter (), new Report (reportPrinter));
					
					RootContext.ToplevelTypes = new ModuleCompiled (ctx, false /* isUnsafe */);
					CompilationUnit unit = null;
					try {
						unit = (CompilationUnit) Location.SourceFiles [0];
					} catch (Exception) {
						string path = Path.GetFullPath (inputFile);
						unit = new CompilationUnit (inputFile, path, 0);
					}
					CSharpParser parser = new CSharpParser (reader, unit, ctx);
					parser.Lexer.TabSize = 1;
					parser.Lexer.sbag = new SpecialsBag ();
					parser.LocationsBag = new LocationsBag ();
					parser.UsingsBag = new UsingsBag ();
					parser.parse ();
					
					return new CompilerCompilationUnit () { ModuleCompiled = RootContext.ToplevelTypes, LocationsBag = parser.LocationsBag, UsingsBag = parser.UsingsBag, SpecialsBag = parser.Lexer.sbag };
				} finally {
					Reset ();
				}
			}
		}
開發者ID:Ein,項目名稱:monodevelop,代碼行數:37,代碼來源:driver.cs

示例10: Parse

 public void Parse(SeekableStreamReader reader, CompilationUnit file, ModuleContainer module)
 {
     CSharpParser parser = new CSharpParser (reader, file, module);
     parser.parse ();
 }
開發者ID:RainsSoft,項目名稱:MonoCompilerAsAService,代碼行數:5,代碼來源:driver.cs

示例11: ParseFile

		public static CompilerCompilationUnit ParseFile (string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
		{
			lock (parseLock) {
				try {
					//                                     Driver d = Driver.Create (args, false, null, reportPrinter);
					//                                     if (d == null)
					//                                             return null;
       
					var r = new Report (reportPrinter);
					CommandLineParser cmd = new CommandLineParser (r, Console.Out);
					var setting = cmd.ParseArguments (args);
					if (setting == null || r.Errors > 0)
						return null;

					CompilerContext ctx = new CompilerContext (setting, r);
					
					var files = new List<CompilationSourceFile> ();
					var unit = new CompilationSourceFile (inputFile, inputFile, 0);
					var module = new ModuleContainer (ctx);
					unit.NamespaceContainer = new NamespaceContainer (null, module, null, unit);
					files.Add (unit);
					Location.Initialize (files);

					// TODO: encoding from driver
					SeekableStreamReader reader = new SeekableStreamReader (input, Encoding.Default);
				
					RootContext.ToplevelTypes = module;
					
					CSharpParser parser = new CSharpParser (reader, unit);
					parser.Lexer.TabSize = 1;
					parser.Lexer.sbag = new SpecialsBag ();
					parser.LocationsBag = new LocationsBag ();
					parser.UsingsBag = new UsingsBag ();
					parser.parse ();
					
					return new CompilerCompilationUnit () { 
						ModuleCompiled = RootContext.ToplevelTypes,
						LocationsBag = parser.LocationsBag, 
						UsingsBag = parser.UsingsBag, 
						SpecialsBag = parser.Lexer.sbag,
						LastYYValue = parser.LastYYVal
					};
				} finally {
					Reset ();
				}
			}
		}
開發者ID:severinh,項目名稱:monodevelop-vala-afrodite-update,代碼行數:47,代碼來源:driver.cs

示例12: Parse

		void Parse (SeekableStreamReader reader, CompilationUnit file)
		{
			CSharpParser parser = new CSharpParser (reader, file, ctx);
			parser.parse ();
		}
開發者ID:Ein,項目名稱:monodevelop,代碼行數:5,代碼來源:driver.cs

示例13: ParseFile

		public static CompilerCompilationUnit ParseFile (string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
		{
			lock (parseLock) {
				try {
//                                     Driver d = Driver.Create (args, false, null, reportPrinter);
//                                     if (d == null)
//                                             return null;
       
                                       var r = new Report (reportPrinter);
                                       CommandLineParser cmd = new CommandLineParser (r, Console.Out);
                                       var setting = cmd.ParseArguments (args);
                                       if (setting == null || r.Errors > 0)
						return null;

                                       CompilerContext ctx = new CompilerContext (setting, r);
                                       var d = new Driver (ctx);

					Location.AddFile (null, inputFile);
					Location.Initialize ();
	
					// TODO: encoding from driver
					SeekableStreamReader reader = new SeekableStreamReader (input, Encoding.Default);
					
					RootContext.ToplevelTypes = new ModuleContainer (ctx);
					CompilationUnit unit = null;
					try {
						unit = (CompilationUnit) Location.SourceFiles [0];
					} catch (Exception) {
						string path = Path.GetFullPath (inputFile);
						unit = new CompilationUnit (inputFile, path, 0);
					}
					CSharpParser parser = new CSharpParser (reader, unit, RootContext.ToplevelTypes);
					parser.Lexer.TabSize = 1;
					parser.Lexer.sbag = new SpecialsBag ();
					parser.LocationsBag = new LocationsBag ();
					parser.UsingsBag = new UsingsBag ();
					parser.parse ();
					
					return new CompilerCompilationUnit () { ModuleCompiled = RootContext.ToplevelTypes, LocationsBag = parser.LocationsBag, UsingsBag = parser.UsingsBag, SpecialsBag = parser.Lexer.sbag };
				} finally {
					Reset ();
				}
			}
		}
開發者ID:sandyarmstrong,項目名稱:monodevelop,代碼行數:44,代碼來源:driver.cs

示例14: Parse

		public void Parse (SeekableStreamReader reader, CompilationSourceFile file, ModuleContainer module)
		{
			file.NamespaceContainer = new NamespaceContainer (null, module, null, file);

			CSharpParser parser = new CSharpParser (reader, file);
			parser.parse ();
		}
開發者ID:severinh,項目名稱:monodevelop-vala-afrodite-update,代碼行數:7,代碼來源:driver.cs

示例15: Parse

		void Parse (SeekableStreamReader reader, CompilationUnit file)
		{
			CSharpParser parser = new CSharpParser (reader, file);
			parser.ErrorOutput = Report.Stderr;
			try {
				parser.parse ();
			} catch (Exception ex) {
				Report.Error(589, parser.Lexer.Location,
					"Compilation aborted in file `{0}', {1}", file.Name, ex);
			}
		}
開發者ID:lewurm,項目名稱:benchmarker,代碼行數:11,代碼來源:driver.cs


注:本文中的Mono.CSharp.CSharpParser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。