private static bool ParseFile(this SourceContext context, FileInfo file, bool validate) { var success = context.Parse <SourceScope>(Preprocess(File.ReadAllText(file.FullName)), out var sourceScope); if (success) { context.GlobalScope[file] = sourceScope; context.GlobalScope.InitializeItems(); if (validate) { success &= context.GlobalScope.ValidateScope(context); } } return(success); }
public static bool ValidateIdentifier(this SourceContext context, Identifier identifier, Identifier[] blacklist = null, Identifier[] whitelist = null) { if (string.IsNullOrEmpty(identifier)) { context.LogError(15, "Null or empty identifier is invalid"); return(false); } bool Predicate(Identifier reserved) => string.Equals(identifier, reserved, StringComparison.OrdinalIgnoreCase); if (GloballyReservedIdentifiers.Where(id => !(whitelist?.Contains(identifier) ?? false)).Any(Predicate) || (blacklist?.Any(Predicate) ?? false)) { context.LogError(15, $"'{identifier}' is a reserved identifier"); return(false); } return(true); }
public static bool TryCreate(CompilationInput compilationInput, out SourceContext sourceContext) { sourceContext = new SourceContext(compilationInput); return(sourceContext.LoadPackagesAndExtraSourceFiles()); }
/// <summary> /// Parses all the given files as Element source files into the compilation context /// </summary> public static (bool OverallSuccess, IEnumerable <(bool Success, FileInfo FileInfo)> Results) ParseFiles(this SourceContext context, IEnumerable <FileInfo> files) { (bool Success, FileInfo File)[] fileResults = files.Where(file => context.GlobalScope[file] == null).Select(file => (context.ParseFile(file, false), file)).ToArray();
/// <summary> /// Parses the given file as an Element source file and adds it's contents to a source context /// </summary> public static bool ParseFile(this SourceContext context, FileInfo file) => ParseFile(context, file, true);