Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public static bool TryCreate(CompilationInput compilationInput, out SourceContext sourceContext)
 {
     sourceContext = new SourceContext(compilationInput);
     return(sourceContext.LoadPackagesAndExtraSourceFiles());
 }
Esempio n. 4
0
 /// <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();
Esempio n. 5
0
 /// <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);