• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CSharp.ParserSession类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Mono.CSharp.ParserSession的典型用法代码示例。如果您正苦于以下问题:C# ParserSession类的具体用法?C# ParserSession怎么用?C# ParserSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ParserSession类属于Mono.CSharp命名空间,在下文中一共展示了ParserSession类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: GenerateDynamicPartialClasses

		public static void GenerateDynamicPartialClasses(ModuleContainer module, ParserSession session, Report report)
		{
			List<Class> classes = new List<Class>();
			FindDynamicClasses(module, classes);

			if (classes.Count == 0)
				return;

			var os = new StringWriter();

			os.Write (@"
// Generated dynamic class partial classes

");

			foreach (var cl in classes) {
				os.Write (@"
namespace {1} {{

	partial class {2} : PlayScript.IDynamicClass {{

		private PlayScript.IDynamicClass __dynamicProps;

		dynamic PlayScript.IDynamicClass.__GetDynamicValue(string name) {{
			object value = null;
			if (__dynamicProps != null) {{
				value = __dynamicProps.__GetDynamicValue(name);
			}}
			return value;
		}}

		bool PlayScript.IDynamicClass.__TryGetDynamicValue(string name, out object value) {{
			if (__dynamicProps != null) {{
				return __dynamicProps.__TryGetDynamicValue(name, out value);
			}} else {{
				value = null;
				return false;
			}}
		}}
			
		void PlayScript.IDynamicClass.__SetDynamicValue(string name, object value) {{
			if (__dynamicProps == null) {{
				__dynamicProps = new PlayScript.DynamicProperties(this);
			}}
			__dynamicProps.__SetDynamicValue(name, value);
		}}

		bool PlayScript.IDynamicClass.__DeleteDynamicValue(object name) {{
			if (__dynamicProps != null) {{
				return __dynamicProps.__DeleteDynamicValue(name);
			}}
			return false;
		}}
			
		bool PlayScript.IDynamicClass.__HasDynamicValue(string name) {{
			if (__dynamicProps != null) {{
				return __dynamicProps.__HasDynamicValue(name);
			}}
			return false;
		}}

		System.Collections.IEnumerable PlayScript.IDynamicClass.__GetDynamicNames() {{
			if (__dynamicProps != null) {{
				return __dynamicProps.__GetDynamicNames();
			}}
			return null;
		}}
	}}
}}

", PsConsts.PsRootNamespace, ((ITypeDefinition)cl).Namespace, cl.MemberName.Basename);
			}

			string fileStr = os.ToString();
			var path = System.IO.Path.Combine (System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(module.Compiler.Settings.OutputFile)), "dynamic.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,代码行数:87,代码来源:ps-codegen.cs


示例17: ParseStartupFiles

		void ParseStartupFiles ()
		{
			Driver d = new Driver (ctx);

			Location.Initialize (ctx.SourceFiles);

			var parser_session = new ParserSession ();
			for (int i = 0; i < startup_files; ++i) {
				var sf = ctx.SourceFiles [i];
				d.Parse (sf, module, parser_session, ctx.Report);
			}
		}
开发者ID:FrancisVarga,项目名称:mono,代码行数:12,代码来源:eval.cs


示例18: ParseFiles

        private void ParseFiles([NotNull] ModuleContainer container)
        {
            Location.Initialize(container.Compiler.SourceFiles);
            var session = new ParserSession
            {
                UseJayGlobalArrays = true,
                LocatedTokens = new LocatedToken[15000]
            };

            foreach (var sourceFile in container.Compiler.SourceFiles)
            {
                using (var stream = new FileStream(sourceFile.FullPathName, FileMode.Open))
                {
                    var compilationSourceFile = new CompilationSourceFile(container, sourceFile);
                    container.AddTypeContainer(compilationSourceFile);
                    using (var seekStream = new SeekableStreamReader(stream, Encoding.UTF8))
                    {
                        new CSharpParser(seekStream, compilationSourceFile, _report, session).parse();
                    }
                }
            }
        }
开发者ID:Tauron1990,项目名称:Radio-Streamer,代码行数:22,代码来源:Compiler.cs



注:本文中的Mono.CSharp.ParserSession类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CSharp.PendingImplementation类代码示例发布时间:2022-05-26
下一篇:
C# CSharp.ParenthesizedExpression类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap