Пример #1
0
        public CodeDirectory(Context context, string path)
        {
            _context = context;
            Path     = new NormalizedPath(path);

            if (Directory.Exists(path))
            {
                Files = Directory.GetFiles(path, "*.php", SearchOption.AllDirectories)
                        .Select(p => new CodeScriptFile(context, this, p))
                        .ToImmutableArray();
            }
        }
Пример #2
0
        public void RequireFile(Scope scope, params NormalizedPath [] possible_paths)
        {
            CodeScriptFile file = null;

            foreach (NormalizedPath possible_path in possible_paths)
            {
                if (file != null)
                {
                    break;
                }

                foreach (var d in RootDirectories)
                {
                    file = d.Files.FirstOrDefault(f => f.FullPath == possible_path);
                    if (file != null)
                    {
                        break;
                    }
                }

                if (file == null)
                {
                    foreach (var d in RootDirectories)
                    {
                        NormalizedPath relative_combined = Path.GetFullPath(Path.Combine(d.Path.Original, possible_path.Original));
                        file = d.Files.FirstOrDefault(f => f.FullPath == relative_combined);
                        if (file != null)
                        {
                            break;
                        }
                    }
                }
            }

            if (file == null)
            {
                throw new InterpreterException($"File {possible_paths.Join ("|")} could not be found. Root directories are: {RootDirectories.Join (", ")}.\n{scope.StackTrace}");
            }

            if (IncludedFiles.Contains(file))
            {
                Log.Debug($"File already included: {file}");
                return;
            }
            IncludedFiles.Add(file);

            file.GetContent().Run(scope, Options);
        }
Пример #3
0
        public void RunFile(NormalizedPath value)
        {
            CodeScriptFile file = null;

            foreach (var d in RootDirectories)
            {
                file = d.Files.FirstOrDefault(f => f.FullPath == value);
                if (file != null)
                {
                    break;
                }
            }

            if (file == null)
            {
                foreach (var d in RootDirectories)
                {
                    NormalizedPath relative_combined = Path.GetFullPath(Path.Combine(d.Path.Original, value.Original));
                    file = d.Files.FirstOrDefault(f => f.FullPath == relative_combined);
                    if (file != null)
                    {
                        break;
                    }
                }
            }

            if (file == null)
            {
                throw new InterpreterException($"File {value} could not be found. Root directories are: {RootDirectories.Join (", ")}");
            }

            if (IncludedFiles.Contains(file))
            {
                Log.Debug($"File already included: {file}");
                return;
            }
            IncludedFiles.Add(file);

            file.GetContent().Run(RootScope, Options);
        }
Пример #4
0
        public string Eval(string code, List <string> diagnostics = null, NormalizedPath base_directory = default, NormalizedPath relative_path = default)
        {
            base_directory = base_directory != default ? base_directory : NormalizedPath.DEFAULT_DOT;
            relative_path  = relative_path != default ? relative_path : NormalizedPath.DEFAULT_DOT;

            CodeScriptEval file = new CodeScriptEval(this, base_directory, relative_path, code);

            return(file.GetContent().Eval(RootScope, Options, diagnostics));
        }
Пример #5
0
 public CodeScriptFile(Context context, CodeDirectory base_directory, string full_path)
     : base(context)
 {
     FullPath      = new NormalizedPath(full_path);
     BaseDirectory = base_directory.Path;
 }