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


C# CSharp.ParserSession類代碼示例

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


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

示例1: tokenize_file

		void tokenize_file (SourceFile sourceFile, ModuleContainer module, ParserSession session)
		{
			Stream input;

			try {
				input = File.OpenRead (sourceFile.Name);
			} catch {
				Report.Error (2001, "Source file `" + sourceFile.Name + "' could not be found");
				return;
			}

			using (input){
				SeekableStreamReader reader = new SeekableStreamReader (input, ctx.Settings.Encoding);
				var file = new CompilationSourceFile (module, sourceFile);

				Tokenizer lexer = new Tokenizer (reader, file, session, ctx.Report);
				int token, tokens = 0, errors = 0;

				while ((token = lexer.token ()) != Token.EOF){
					tokens++;
					if (token == Token.ERROR)
						errors++;
				}
				Console.WriteLine ("Tokenized: " + tokens + " found " + errors + " errors");
			}
			
			return;
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:28,代碼來源:driver.cs

示例2: 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

示例3: GenerateCode

		public static void GenerateCode (ModuleContainer module, ParserSession session, Report report)
		{
			GenerateDynamicPartialClasses(module, session, report);
			if (report.Errors > 0)
				return;

			GenerateEmbedClasses(module, session, report);
			if (report.Errors > 0)
				return;

		}
開發者ID:rlfqudxo,項目名稱:playscript-mono,代碼行數:11,代碼來源:ps-codegen.cs

示例4: Parse

		void Parse (ModuleContainer module)
		{
			bool tokenize_only = module.Compiler.Settings.TokenizeOnly;
			var sources = module.Compiler.SourceFiles;

			Location.Initialize (sources);

			var session = new ParserSession {
				UseJayGlobalArrays = true,
				LocatedTokens = new LocatedToken[15000]
			};

			for (int i = 0; i < sources.Count; ++i) {
				if (tokenize_only) {
					tokenize_file (sources[i], module, session);
				} else {
					Parse (sources[i], module, session, Report);
				}
			}
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:20,代碼來源:driver.cs

示例5: tokenize_file

		void tokenize_file (SourceFile sourceFile, ModuleContainer module, ParserSession session)
		{
			Stream input;

			try {
				input = File.OpenRead (sourceFile.Name);
			} catch {
				Report.Error (2001, "Source file `" + sourceFile.Name + "' could not be found");
				return;
			}

			using (input) {
				SeekableStreamReader reader = new SeekableStreamReader (input, ctx.Settings.Encoding);
				var file = new CompilationSourceFile (module, sourceFile);

				if (sourceFile.FileType == SourceFileType.CSharp) {
					Tokenizer lexer = new Tokenizer (reader, file, session);
					int token, tokens = 0, errors = 0;
	
					while ((token = lexer.token ()) != Token.EOF){
						tokens++;
						if (token == Token.ERROR)
							errors++;
					}
				} else {
					Mono.PlayScript.Tokenizer lexer = new Mono.PlayScript.Tokenizer (reader, file, session);
					lexer.ParsingPlayScript = sourceFile.PsExtended;
					int token, tokens = 0, errors = 0;
	
					while ((token = lexer.token ()) != Mono.PlayScript.Token.EOF){
						tokens++;
						if (token == Mono.PlayScript.Token.ERROR)
							errors++;
					}
				}
			}
			
			return;
		}
開發者ID:robterrell,項目名稱:playscript-mono,代碼行數:39,代碼來源:driver.cs

示例6: CSharpParser

public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
	: this (reader, file, file.Compiler.Report, session)
{
}
開發者ID:segaman,項目名稱:NRefactory,代碼行數:4,代碼來源:cs-parser.cs

示例7: ParseParallel

		void ParseParallel (ModuleContainer module)
		{
			var sources = module.Compiler.SourceFiles;

			Location.Initialize (sources);

			var pcount = Environment.ProcessorCount;
			var threads = new Thread[System.Math.Max (2, pcount - 1)];

			for (int i = 0; i < threads.Length; ++i) {
				var t = new Thread (l => {
					var session = new ParserSession () {
						//UseJayGlobalArrays = true,
					};

					var report = new Report (ctx, Report.Printer); // TODO: Implement flush at once printer

					for (int ii = (int) l; ii < sources.Count; ii += threads.Length) {
						Parse (sources[ii], module, session, report);
					}

					// TODO: Merge warning regions
				});

				t.Start (i);
				threads[i] = t;
			}

			for (int t = 0; t < threads.Length; ++t) {
				threads[t].Join ();
			}
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:32,代碼來源:driver.cs

示例8: CSharpParser

public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session, bool returnAtSignInVerbatimIdentifiers)
	: this (reader, file, file.Compiler.Report, session, returnAtSignInVerbatimIdentifiers)
{
}
開發者ID:erik-kallen,項目名稱:NRefactory,代碼行數:4,代碼來源:cs-parser.cs

示例9: 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

示例10: GenerateEmbedClasses

		public static void GenerateEmbedClasses(ModuleContainer module, ParserSession session, Report report)
		{
			List<EmbedData> embeds = new List<EmbedData>();
			FindEmbedClasses(module, module, embeds);
			if (embeds.Count == 0)
				return;

			var os = new StringWriter();
			
			os.Write (@"
// Generated embed loader classes

");

			foreach (var e in embeds) {

				var loc = e._field.Location;

				e._field.Initializer = new TypeOf(new MemberAccess(new SimpleName("_embed_loaders", loc), e._className), loc);

				os.Write (@"
namespace _embed_loaders {{

	internal class {1} : PlayScript.EmbedLoader {{

		public {1}() : base({2}, {3}, {4}, {5}, {6}) {{
		}}
	}}
}}

", PsConsts.PsRootNamespace, e._className, e.source, e.mimeType, e.embedAsCFF, e.fontFamily, e.symbol);
			}
			
			string fileStr = os.ToString();
			var path = System.IO.Path.Combine (System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(module.Compiler.Settings.OutputFile)), "embed.g.cs");
			System.IO.File.WriteAllText(path, fileStr);
			
			byte[] byteArray = Encoding.ASCII.GetBytes( fileStr );
			var input = new MemoryStream( byteArray, false );
			var reader = new SeekableStreamReader (input, System.Text.Encoding.UTF8);
			
			SourceFile file = new SourceFile(path, path, 0);
			file.FileType = SourceFileType.CSharp;
			
			Driver.Parse (reader, file, module, session, report);
		}
開發者ID:rlfqudxo,項目名稱:playscript-mono,代碼行數:46,代碼來源:ps-codegen.cs

示例11: Parse

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

            CSharpParser parser = new CSharpParser (reader, file, report, session);
            parser.Lexer.Line += lineModifier;
            parser.Lexer.Column += colModifier;
            parser.Lexer.sbag = new SpecialsBag ();
            parser.parse ();
            return parser;
        }
開發者ID:riviti,項目名稱:NRefactory,代碼行數:12,代碼來源:driver.cs

示例12: Parse

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

			if (sourceFile.FileType == SourceFileType.CSharp) {
				CSharpParser parser = new CSharpParser (reader, file, session);
				parser.parse ();
			} else {
				PlayScriptParser parser = new PlayScriptParser (reader, file, session);
				parser.parsing_playscript = sourceFile.PsExtended;
				parser.parse ();
			}
		}
開發者ID:robterrell,項目名稱:playscript-mono,代碼行數:14,代碼來源:driver.cs

示例13: Parse

		void Parse (ModuleContainer module)
		{
			bool tokenize_only = module.Compiler.Settings.TokenizeOnly;
			var sources = module.Compiler.SourceFiles;

			Location.Initialize (sources);

			var session = new ParserSession () {
				UseJayGlobalArrays = true,
				LocatedTokens = new Tokenizer.LocatedToken[15000],
				AsLocatedTokens = new Mono.PlayScript.Tokenizer.LocatedToken[15000]
			};

			bool has_playscript_files = false;

			for (int i = 0; i < sources.Count; ++i) {
				if (tokenize_only) {
					tokenize_file (sources[i], module, session);
				} else {
					Parse (sources[i], module, session, Report);
				}
				if (sources[i].FileType == SourceFileType.PlayScript) {
					has_playscript_files = true;
				}
			}

			// PlayScript needs to add generated code after parsing.
			if (has_playscript_files) {
				Mono.PlayScript.CodeGenerator.GenerateCode(module, session, Report);
			}
		}
開發者ID:bbqchickenrobot,項目名稱:playscript-mono,代碼行數:31,代碼來源:driver.cs

示例14: 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));

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

			if (session == null)
				session = new ParserSession () {
					UseJayGlobalArrays = true
				};

			SeekableStreamReader seekable = new SeekableStreamReader (s, encoding, session.StreamReaderBuffer);

			var parser = new CSharpParser (seekable, source_file, report, session);
			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 ());
					try {
						var context = new DocumentationMemberContext (mc, ParsedName ?? MemberName.Null);
//.........這裏部分代碼省略.........
開發者ID:adisik,項目名稱:simple-assembly-explorer,代碼行數:101,代碼來源:doc.cs

示例15: Parse

		SyntaxTree Parse(ITextSource program, string fileName, int initialLine, int initialColumn)
		{
			lock (parseLock) {
				errorReportPrinter = new ErrorReportPrinter("");
				var ctx = new CompilerContext(compilerSettings.ToMono(), errorReportPrinter);
				ctx.Settings.TabSize = 1;
				var reader = new SeekableStreamReader(program);
				var file = new SourceFile(fileName, fileName, 0);
				Location.Initialize(new List<SourceFile>(new [] { file }));
				var module = new ModuleContainer(ctx);
				var session = new ParserSession();
				session.LocationsBag = new LocationsBag();
				var report = new Report(ctx, errorReportPrinter);
				var parser = Driver.Parse(reader, file, module, session, report, initialLine - 1, initialColumn - 1);
				var top = new CompilerCompilationUnit {
					ModuleCompiled = module,
					LocationsBag = session.LocationsBag,
					SpecialsBag = parser.Lexer.sbag,
					Conditionals = parser.Lexer.SourceFile.Conditionals
				};
				var unit = Parse(top, fileName);
				unit.Errors.AddRange(errorReportPrinter.Errors);
				CompilerCallableEntryPoint.Reset();
				return unit;
			}
		}
開發者ID:0xb1dd1e,項目名稱:NRefactory,代碼行數:26,代碼來源:CSharpParser.cs


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