示例#1
0
	public bool ParseLine(Scanner scanner, int line)
	{
		var numErrors = scanner.ErrorMessage != null ? 1 : 0;
		while (scanner.CurrentLine() - 1 <= line)
		{
		/*	if (scanner.CurrentGrammarNode == EOF)
			{
			//	Debug.LogError("EOF expected at line " + (line + 1));
				return false;
			}
			else*/ if (!parser.ParseStep(scanner))
				return false;
			
			if (scanner.ErrorMessage != null)
			{
				++numErrors;
			}
			else
			{
				numErrors = 0;
			}
		}
		//if (numErrors > 0)
		//	Debug.Log(numErrors + " error steps on line " + line);
		return numErrors < 10;
	}
示例#2
0
	public void Parse(FGTextBuffer.FormatedLine[] lines, string bufferName)
	{
	//	var s = new Stopwatch();
	//	s.Start();

		//FGGramar.GoalDebugger.debug = new StringBuilder();

		var scanner = new Scanner(this, lines, bufferName);
		try
		{
			/*ParseTree parseTree =*/ parser.ParseAll(scanner);
		//	Debug.Log(parseTree);
		}
		catch (Exception e)
		{
			Debug.LogError("Parsing crashed at line: " + scanner.CurrentLine() + ", token " + scanner.CurrentTokenIndex() + " with:\n    " + e + " at " + e.StackTrace);
			Debug.Log("Current token: " + scanner.Current.tokenKind + " '" + scanner.Current.text + "'");
		}

	//	Debug.Log(FGGramar.GoalDebugger.debug.ToString());

	//	s.Stop();
	//	Debug.Log("Parsing " + System.IO.Path.GetFileName(bufferName) + " (" + lines.Length + " lines) took " + s.ElapsedMilliseconds + " ms.");

		//var sb = new StringBuilder();
		//foreach (var node in scanner.numLookaheads.Keys)
		//    sb.AppendLine(node + ": " + scanner.numLookaheads[node] + " times in " + scanner.timeLookaheads[node] + " ticks (" + scanner.timeLookaheads[node] * 1000 / Stopwatch.Frequency + " ms)");
		//Debug.Log(sb);
	}