/// <summary> /// Create a ModuleParser /// </summary> /// <param name="tokenStream"></param> /// <param name="exceptionList"></param> public ModuleParser(TokenIterator tokenStream) : base(tokenStream) { //Create parsers for sub elements in a module siteParser = new SiteParser(tokenStream); functionParser = new FunctionParser(tokenStream); }
private static void ProcessTokens(int lineNumber) { try { Debug.Assert(_tokens.Count > 0); string actionType = GetActionType(); switch (actionType) { case "#import": LoadImportScript(_tokens[1]); return; case "const": case "var": VariableParser.Parse(lineNumber, _LoadedFiles.Peek(), _script, _tokens); return; } ActionBase act = CreateActionObject(actionType); switch (actionType) { case "function": { string name = FunctionParser.Parse((Actionfunction)act, _tokens); if (!_script.AddFunction(name)) { string msg = "Function [" + name + "] already exists." + Environment.NewLine + "Unable to load script."; throw new Exception(msg); } } break; case "call": CallParser.Parse((Actioncall)act, _tokens); break; case "for": ParseForLoop((Actionfor)act, _tokens); break; default: act.AddParams(_tokens); break; } act.LineNumber = lineNumber; act.Path2Script = _LoadedFiles.Peek(); _script.AddAction(act); } catch { _vm.ParseError(_LoadedFiles.Pop(), lineNumber); throw; } }
public void ParseFormalsTest() { FunctionParser functionParser = new FunctionParser(Init("(param1, param2)")); FunctionDefinition functionDefinition = new FunctionDefinition(); functionParser.ParseFormals(functionDefinition); //Test formals Assert.AreEqual(2, functionDefinition.GetFormals().Count); Formal[] formalArray = (Formal[]) functionDefinition.GetFormals().ToArray(); Assert.AreEqual("param1", formalArray[0].ToString()); Assert.AreEqual("param2", formalArray[1].ToString()); }
public void ParseEmptyFunctionDefinitionTest() { FunctionParser functionParser = new FunctionParser(Init("home(param1, param2) \n end")); FunctionDefinition parsedFunctionDefinition = functionParser.ParseFunctionDefinition(); //Test FunctionDefinition Assert.AreEqual("home", parsedFunctionDefinition.GetIdentifier()); Assert.AreEqual(2, parsedFunctionDefinition.GetFormals().Count); //Check formals Formal[] formalArray = (Formal[]) parsedFunctionDefinition.GetFormals().ToArray(); Assert.AreEqual("param1", formalArray[0].ToString()); Assert.AreEqual("param2", formalArray[1].ToString()); }
/// <summary> /// Create a ModuleParser /// </summary> /// <param name="tokenStream"></param> /// <param name="exceptionList"></param> public ModuleParser(TokenIterator tokenStream) : base(tokenStream) { //Create parsers for sub elements in a module siteParser = new SiteParser(tokenStream); functionParser = new FunctionParser(tokenStream); }
public void ParseFormalTest() { FunctionParser functionParser = new FunctionParser(Init("param1")); Formal parsedFormal = functionParser.ParseFormal(); //Test identifier Assert.AreEqual("param1", parsedFormal.ToString()); }