Exemplo n.º 1
0
		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 ();
			}
		}
		/*
		/// <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.CSharpPs.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);
				ParserSession session = new ParserSession ();
				session.LocationsBag = new LocationsBag ();
				var parser = new Mono.PlayScript.PlayScriptParser (reader, source_file, report, session);
				parser.parsing_playscript = (source_file.SourceFile != null) ? source_file.SourceFile.PsExtended : true;
				parser.Lexer.Line += initialLocation.Line - 1;
				parser.Lexer.Column += initialLocation.Column - 1;
				parser.Lexer.putback_char = Mono.PlayScript.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);
				}
				
				ConversionVisitor conversionVisitor = new ConversionVisitor (false, session.LocationsBag);
				DocumentationReference docRef = conversionVisitor.ConvertXmlDoc(module.DocumentationBuilder);
				CompilerCallableEntryPoint.Reset();
				return docRef;
			}
		}
Exemplo n.º 3
0
		public static object 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);

			object parser = null;
			
			if (sourceFile.FileType == SourceFileType.CSharp) {
				CSharpParser csParser = new CSharpParser (reader, file, report, session);
				csParser.Lexer.Line += lineModifier;
				csParser.Lexer.Column += colModifier;
				csParser.Lexer.sbag = new SpecialsBag ();
				csParser.parse ();
				parser = csParser;
			} else {
				PlayScriptParser psParser = new PlayScriptParser (reader, file, report, session);
				psParser.parsing_playscript = sourceFile.PsExtended;
				psParser.Lexer.Line += lineModifier;
				psParser.Lexer.Column += colModifier;
				psParser.Lexer.sbag = new SpecialsBag ();
				psParser.parse ();
				parser = psParser;
			}
			
			return parser;
		}