//
// Parses the string @input and returns a CSharpParser if succeeful.
//
// if @silent is set to true then no errors are
// reported to the user. This is used to do various calls to the
// parser and check if the expression is parsable.
//
// @partial_input: if @silent is true, then it returns whether the
// parsed expression was partial, and more data is needed
//
static CSharpParser ParseString (bool silent, string input, out bool partial_input)
{
partial_input = false;
Reset ();
queued_fields.Clear ();
Stream s = new MemoryStream (Encoding.Default.GetBytes (input));
SeekableStreamReader seekable = new SeekableStreamReader (s, Encoding.Default);
InputKind kind = ToplevelOrStatement (seekable);
if (kind == InputKind.Error){
if (!silent)
Report.Error (-25, "Detection Parsing Error");
partial_input = false;
return null;
}
if (kind == InputKind.EOF){
if (silent == false)
Console.Error.WriteLine ("Internal error: EOF condition should have been detected in a previous call with silent=true");
partial_input = true;
return null;
}
seekable.Position = 0;
CSharpParser parser = new CSharpParser (seekable, (CompilationUnit) Location.SourceFiles [0]);
parser.ErrorOutput = Report.Stderr;
if (kind == InputKind.StatementOrExpression){
parser.Lexer.putback_char = Tokenizer.EvalStatementParserCharacter;
RootContext.StatementMode = true;
} else {
//
// Do not activate EvalCompilationUnitParserCharacter until
// I have figured out all the limitations to invoke methods
// in the generated classes. See repl.txt
//
parser.Lexer.putback_char = Tokenizer.EvalUsingDeclarationsParserCharacter;
//parser.Lexer.putback_char = Tokenizer.EvalCompilationUnitParserCharacter;
RootContext.StatementMode = false;
}
if (silent)
Report.DisableReporting ();
try {
parser.parse ();
} finally {
if (Report.Errors != 0){
if (silent && parser.UnexpectedEOF)
partial_input = true;
parser.undo.ExecuteUndo ();
parser = null;
}
if (silent)
Report.EnableReporting ();
}
return parser;
}