public void Consult(string path)
{
var directoryPath = Prolog.LoadDirectoryPath(path);
if (Path.GetExtension(directoryPath) == string.Empty && Directory.Exists(directoryPath))
{
foreach (var file in Directory.GetFiles(directoryPath))
if (IsSourceFile(file))
Consult(file);
}
else
{
path = DefaultExtension(Prolog.LoadFilePath(path), ".prolog");
using (var stream = File.OpenText(path))
{
string savedFileName = Prolog.CurrentSourceFile;
int savedLineNumber = Prolog.CurrentSourceLineNumber;
try
{
Prolog.CurrentSourceFile = path;
Prolog.CurrentSourceLineNumber = 0;
var textReader = new PositionTrackingTextReader(stream, path);
if (Path.GetExtension(path) == ".csv")
{
var functor = Symbol.Intern(Path.GetFileNameWithoutExtension(path));
this.IsTrue(new Structure("begin_csv_loading", functor)); // Ignore return value
new CSVParser(functor, ',', textReader).Read(this.LoadCSVRow);
this.IsTrue(new Structure("end_csv_loading", functor)); // Ignore return value
}
else
Consult(textReader);
}
finally
{
Prolog.CurrentSourceFile = savedFileName;
Prolog.CurrentSourceLineNumber = savedLineNumber;
}
}
}
}