Exemplo n.º 1
0
        public static SyntaxTree Parse(ITextSource textSource, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            var parser = new AlParser(settings);

            return(parser.Parse(textSource, fileName));
        }
Exemplo n.º 2
0
        protected SyntaxTree ParseStub(string continuation, bool appendSemicolon = true, string afterContinuation = null)
        {
            var mt = GetMemberTextToCaret();

            if (mt == null)
            {
                return(null);
            }

            string memberText      = mt.Item1;
            var    memberLocation  = mt.Item2;
            int    closingBrackets = 1;
            int    generatedLines  = 0;
            var    wrapper         = CreateWrapper(continuation, appendSemicolon, afterContinuation, memberText, memberLocation, ref closingBrackets, ref generatedLines);
            var    parser          = new AlParser();

            foreach (var sym in CompletionContextProvider.ConditionalSymbols)
            {
                parser.CompilerSettings.ConditionalSymbols.Add(sym);
            }
            parser.InitialLocation = new TextLocation(memberLocation.Line - generatedLines, 1);
            var result = parser.Parse(wrapper.ToString());

            return(result);
        }
Exemplo n.º 3
0
		public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested,
		                              IProject parentProject, CancellationToken cancellationToken)
		{
			var csharpProject = parentProject as AlProject;
			
			AlParser parser = new AlParser(csharpProject != null ? csharpProject.CompilerSettings : null);
			
			SyntaxTree cu = parser.Parse(fileContent, fileName);
			cu.Freeze();
			
			AlUnresolvedFile file = cu.ToTypeSystem();
			ParseInformation parseInfo;
			
			if (fullParseInformationRequested)
				parseInfo = new AlFullParseInformation(file, fileContent.Version, cu);
			else
				parseInfo = new ParseInformation(file, fileContent.Version, fullParseInformationRequested);
			
			IDocument document = fileContent as IDocument;
			AddCommentTags(cu, parseInfo.TagComments, fileContent, parseInfo.FileName, ref document);
			if (fullParseInformationRequested) {
				if (document == null)
					document = new ReadOnlyDocument(fileContent, parseInfo.FileName);
				((AlFullParseInformation)parseInfo).newFoldings = CreateNewFoldings(cu, document);
			}
			
			return parseInfo;
		}
Exemplo n.º 4
0
        // could depend just on IDocument
        SyntaxTree ParseDocument(ITextEditor editor, out IList <AstNode> parsedSpecials)
        {
            parsedSpecials = null;
            CompilerSettings compilerSettings = new CompilerSettings();
            var parser = new AlParser();

            if (parser == null)
            {
                return(null);
            }
            var syntaxTree = parser.Parse(editor.Document.CreateReader());

            if (syntaxTree == null)
            {
                return(null);
            }
            parsedSpecials = new List <AstNode>(syntaxTree.Descendants.OfType <Comment>());
            return(syntaxTree);
        }
Exemplo n.º 5
0
		public ResolveResult ResolveSnippet(ParseInformation parseInfo, TextLocation location, string codeSnippet, ICompilation compilation, CancellationToken cancellationToken)
		{
			var csParseInfo = parseInfo as AlFullParseInformation;
			if (csParseInfo == null)
				throw new ArgumentException("Parse info does not have SyntaxTree");
			AlAstResolver contextResolver = new AlAstResolver(compilation, csParseInfo.SyntaxTree, csParseInfo.UnresolvedFile);
			var node = csParseInfo.SyntaxTree.GetNodeAt(location);
			AlResolver context;
			if (node != null)
				context = contextResolver.GetResolverStateAfter(node, cancellationToken);
			else
				context = new AlResolver(compilation);
			AlParser parser = new AlParser();
			var expr = parser.ParseExpression(codeSnippet);
			if (parser.HasErrors)
				return new ErrorResolveResult(SpecialType.UnknownType, PrintErrorsAsString(parser.Errors), TextLocation.Empty);
			AlAstResolver snippetResolver = new AlAstResolver(context, expr);
			return snippetResolver.Resolve(expr, cancellationToken);
		}
        public static AlCompletionContext Get(ITextEditor editor, ICodeContext context, TextLocation currentLocation, ITextSource fileContent)
        {
            IDocument document = new ReadOnlyDocument(fileContent);

            var projectContent = context.Compilation.MainAssembly.UnresolvedAssembly as IProjectContent;

            if (projectContent == null)
            {
                return(null);
            }

            AlParser parser = new AlParser();

            parser.GenerateTypeSystemMode = false;

            SyntaxTree cu = parser.Parse(fileContent, Path.GetRandomFileName() + ".al");

            cu.Freeze();

            AlUnresolvedFile unresolvedFile = cu.ToTypeSystem();
            ICompilation     compilation    = projectContent.AddOrUpdateFiles(unresolvedFile).CreateCompilation(SD.ParserService.GetCurrentSolutionSnapshot());

            return(new AlCompletionContext(editor, EmptyList <string> .Instance, compilation, projectContent, document, unresolvedFile, currentLocation));
        }