示例#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));
        }
示例#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);
        }
示例#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;
		}
示例#4
0
 public static void LoadBaseType(IProjectContent prj)
 {
     try
     {
         if (BaseTypeFile == null)
         {
             var source      = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "ALBASE.al");
             var asyntaxTree = parser.Parse(source, AppDomain.CurrentDomain.BaseDirectory + "ALBASE.al");
             asyntaxTree.Freeze();
             BaseTypeFile = asyntaxTree.ToTypeSystem();
         }
         prj.AddOrUpdateFiles(BaseTypeFile);
     }
     catch
     {
         BaseTypeFile = null;
     }
 }
示例#5
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);
        }
        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));
        }