Skip to content

Commit

Permalink
Merge pull request #5 from poolofthought/option-to-supress-singleton-…
Browse files Browse the repository at this point in the history
…warnings-during-consult

ability to prevent reporting of Singletons during consult
  • Loading branch information
poolofthought committed Apr 20, 2018
2 parents 874fff8 + ae896e2 commit f5365ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CSProlog/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ public bool varhasvalue (string name)
bool findFirstClause; // find the first clause of predicate that matches the current goal goal (-last head)
bool csharpStrings = ConfigSettings.CSharpStrings;
bool userSetShowStackTrace = ConfigSettings.OnErrorShowStackTrace; // default value
bool showSingletonWarnings = true; // want to be able to turn off singleton warnings at the file level (default to true and will need to add to reset code to make sure it isn't persisting across files)

#region unique number generators
static int unifyCount; // total number of unifications - for tabling ('cost calculation') only
Expand Down Expand Up @@ -2026,7 +2027,7 @@ public void RegisterVarNonSingleton (string s)
}

public void ReportSingletons (ClauseNode c, int lineNo, ref bool firstReport)
{
{
solution.ReportSingletons (c, lineNo, ref firstReport);
}
#endregion Named variables
Expand Down
6 changes: 5 additions & 1 deletion CSProlog/PG/PL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,11 @@ private void ClauseNode (TerminalSet _TS, ref bool firstReport)
}
}
c = new ClauseNode (head, body);
engine.ReportSingletons (c, lineNo - 1, ref firstReport);

if (engine.showSingletonWarnings)
{
engine.ReportSingletons(c, lineNo - 1, ref firstReport);
}
ps.AddClause (c);
}
else if (symbol.TerminalId == PromptSym)
Expand Down
21 changes: 16 additions & 5 deletions CSProlog/PredStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ public int Consult (Stream stream, string streamName = null)
PrologParser parser = Globals.CurrentParser = new PrologParser (engine);
allDiscontiguous = false;

try
{
try
{
prevIndex = null;
definedInCurrFile.Clear ();
isDiscontiguous.Clear ();
Expand All @@ -276,7 +276,9 @@ public int Consult (Stream stream, string streamName = null)
}
finally
{
Globals.CurrentParser = consultParserStack.Pop (); ;
engine.showSingletonWarnings = true; // set it back to the default value of true

Globals.CurrentParser = consultParserStack.Pop (); ;
//Globals.ConsultModuleName = null; // Currently not used
}

Expand Down Expand Up @@ -355,7 +357,15 @@ public void HandleSimpleDirective (PrologParser p, string directive, string argu
else
IO.Error (":- stacktrace: illegal argument '{0}'; use 'on' or 'off' instead", argument);
break;
case "initialization":
case "style_check_singleton_warning":
if (argument == "on")
engine.showSingletonWarnings = true;
else if (argument == "off")
engine.showSingletonWarnings = false;
else
IO.Error(":- style_check_singleton_warning: illegal argument '{0}'; use 'on' or 'off' instead. It is 'on' by default.", argument);
break;
case "initialization":
IO.Warning ("':- initialization' directive not implemented -- ignored");
break;
default:
Expand Down Expand Up @@ -857,7 +867,8 @@ public bool ShowHelp (string functor, int arity, out string suggestion)
IO.WriteLine ("\r\n (*) contains the description of a feature rather than a predicate.");
IO.WriteLine ("\r\n Usage: help <predicate>[/<arity>] or help( <predicate>[/<arity>]).");
IO.WriteLine ("\r\n File CsPrologHelp.txt contains the help texts and a description of how to re-create help."); //TODO: I can't seem to find this file. Eliminate the line or create the file???

IO.WriteLine("\r\n Facts must be read from a file before they can be queried. try help(consult). to see how to read in from a file.");

return true;
}
else if (functor == "history")
Expand Down

0 comments on commit f5365ad

Please sign in to comment.