private bool IsFunctionCall(string line, out List<string> paramaters, out FreshScriptFunction functionMatch) { functionMatch = null; paramaters = null; string functionName = null; int paramaterCount = 0; if (ProcessFuncionDefinition(line, out functionName, out paramaterCount)) { foreach (FreshScriptFunction f in functions) { if (String.Compare(f.Name, functionName, !caseSensitive) == 0) { functionMatch = f; if (paramaters == null) { //TODO add paramaters to this code //first function with this name - define paramaters if (true) { //if number of paramaters matches - same funciton signatues return true; } } } } } return false; }
private List<string> LoadFile(string fileName, int loadRecursionDepth) { //working here - make this load only - imports only - move function definisitons to another pass/method initialize - dont add loads to line List const int recursiveLoadMax = 10; List<string> loadLines = new List<string>(); Profiler.Start(); StreamReader streamReader = null; if (File.Exists(fileName)) streamReader = new StreamReader(fileName); //BufferedReader stream = null;// = new BufferedReader(new Reader(Reader(MyMethods.ShowOpenWindow(panel); if (streamReader == null) { ReportError("Failed to Load/Read file \""+fileName+"\"."); } else { string fileText = streamReader.ReadToEnd(); if (fileText != null) { fileText = fileText.Trim(); string fileTextWithoutQuotes = GetLineWithoutQuotes(fileText); string codeLine = "not null"; while (codeLine!=null) { codeLine = NextCodeLineFromInput(ref fileText, ref fileTextWithoutQuotes); if(codeLine!=null) loadLines.Add(codeLine); } if (fileText.Trim().Length > 0) { ReportError("There is loose code at the end of the file. Probably missing semi colin or brace.",fileName,-1,""); } } streamReader.Close(); int braceDepth = 0; bool funtionStart = false; bool inFunctionDefinition = false; FreshScriptFunction activeFunction = null; int lineNo = -1; //interpret lines - predefine functions mostly foreach (string line in loadLines) { lineNo++; string remainingLine; Keywords keywordMatch; if (HasLeadingKeyword(line, out remainingLine, out keywordMatch)) { switch (keywordMatch) { case Keywords.comment: //do nothing break; case Keywords.var: //this will be handled in the process line break; case Keywords.import: { //should preserver this files path so a sibling file can use relative pathing if (loadRecursionDepth < recursiveLoadMax) { List<string> importLines = LoadFile(remainingLine, loadRecursionDepth + 1); } else { //XXX test this ReportError("Attempting to import file past inport depth limit. Possibly a recursive Load problem. If this is intentional contact Fresh.", fileName, lineNo, loadLines[lineNo - 1]); } break; } case Keywords.function: { if (inFunctionDefinition) { ReportError("Already defining a function", fileName, lineNo, loadLines[lineNo - 1]); } else { funtionStart = true; //create a dummy function definition that will get redefined when the end of funciton is found int paramaterCount; string functionName; if (ProcessFuncionDefinition(remainingLine, out functionName, out paramaterCount)) { activeFunction = new FreshScriptFunction(functionName, paramaterCount, lineNo + 1, 0, caseSensitive); } } break; } case Keywords.openBrace: if (funtionStart) { if (braceDepth != 0) { ReportError("Cannot start a function definition within another code block", fileName, lineNo, loadLines[lineNo - 1]); } funtionStart = false; activeFunction.StartLine = lineNo + 1; inFunctionDefinition = true; braceDepth++; } break; case Keywords.closeBrace: braceDepth--; if (braceDepth < 0) { ReportError("Attempting to close non existant block", fileName, lineNo, loadLines[lineNo - 1]); } else { if (braceDepth == 0 & inFunctionDefinition) { activeFunction.EndLine = lineNo - 1; if (activeFunction.LineCount <= 0) { ReportError("Warning: function " + activeFunction.Name + " has invalid line count(" + activeFunction.LineCount + ")", fileName, lineNo, loadLines[lineNo - 1]); } functions.Add(activeFunction); } } funtionStart = false; break; } } } if (braceDepth >0) { ReportError("Not all braces are closed. - Final load check", fileName, -1, ""); } } Profiler.Stop(); return loadLines; }