// // Helper for registering a weak type alias. // public void RegisterWeakAlias(Token nametoken, WeakAlias alias) { if (!WeakAliases.ContainsKey(nametoken.Text)) { WeakAliases.Add(nametoken.Text, alias); } }
internal static ParsedWeakAlias Parse(ParseSession parser) { if (!parser.CheckToken(0, "alias")) { return(null); } var nametoken = parser.PeekToken(1); if (nametoken == null) { return(null); } if (!parser.CheckToken(2, "=")) { return(null); } parser.ConsumeTokens(4); var aliastype = new WeakAlias { }; return(new ParsedWeakAlias { Name = nametoken, Type = aliastype }); }
// // Parse the code that was provided in construction, and stash the results // in the given Project instance. This routine should do its best to avoid // leaking exceptions generated by the parsing process itself, since those // errors will propagate upward until VS detects them and turns off future // operations by the VSIX package (until restarted). // public bool AugmentProject(Project project) { try { while (!Lexer.Empty) { var sumtype = SumType.Parse(this); if (sumtype != null) { project.RegisterSumType(sumtype.Name, sumtype.Object); continue; } var strongalias = StrongAlias.Parse(this); if (strongalias != null) { project.RegisterStrongAlias(strongalias.Name, strongalias.Object); continue; } var weakalias = WeakAlias.Parse(this); if (weakalias != null) { project.RegisterWeakAlias(weakalias.Name, weakalias.Object); continue; } var structure = Structure.Parse(this); if (structure != null) { project.RegisterStructureType(structure.Name, structure.Object); continue; } var globals = GlobalBlock.Parse(this); if (globals != null) { globals.AugmentProject(project); continue; } var function = FunctionSignature.Parse(this); if (function != null) { project.RegisterFunction(function); continue; } if (!Lexer.Empty) { throw new SyntaxError("Syntax error", PeekToken(0)); } } } catch (SyntaxError ex) { var errorTask = new ErrorTask(); errorTask.Text = ex.Message; errorTask.Category = TaskCategory.CodeSense; errorTask.ErrorCategory = TaskErrorCategory.Error; errorTask.Document = Lexer.FileName; errorTask.Line = (ex.Origin != null) ? (ex.Origin.Line) : 0; errorTask.Column = (ex.Origin != null) ? (ex.Origin.Column) : 0; errorTask.Navigate += project.NavigationHandler; ErrorProvider.Tasks.Add(errorTask); return(false); } return(true); }