static LinkedList <CmdDecl> ParseLocals(Context Context, Tokenizer.Token m_Params, LinkedList <CmdDecl> ListIn) { if (ListIn == null) { ListIn = new LinkedList <CmdDecl>(); } LinkedList <Tokenizer.Token> .Enumerator Params = m_Params.GetEnumerator(); while (Params.MoveNext()) { if (Params.Current.GetTopNodeType().Equals(typeof(Tokenizer.RuleDecl))) { CmdDecl x = new CmdDecl(); if (x.TryParse(Context, Params.Current)) { ListIn.AddLast(x); } //more Params - go deeper into the tree //Todo /* LinkedList<Tokenizer.Token>.Enumerator ParamsNext = Params.Current.GetEnumerator(); * if (ParamsNext.MoveNext()) { //Todo ?? * ListIn = ParseLocals(Context, ParamsNext.Current, ListIn); * }*/ // TODO else Param is missing } //Console.WriteLine(Params.Current.GetValue(false)); } return(ListIn); }
override public void Visit(Tokenizer.Token Token) { if (m_IsRoot) //processing Root Node { m_IsRoot = false; LinkedList <Tokenizer.Token> .Enumerator x = Token.GetEnumerator(); while (x.MoveNext()) { x.Current.InspectNodes(this); } } else //inspecting a cmd token { m_Context.m_ActualCmd = Token.GetTopNodeType(); LinkedList <CmdBase> .Enumerator y = m_Evaluators.GetEnumerator(); while (y.MoveNext()) { if (y.Current.TryParse(this.m_Context, Token)) { CmdBase _x = y.Current.Copy(); m_Context.AddCmd(m_Scope, _x); break; } else //no cmd for this Token { } } } }
override public Boolean TryParse(Context Context, Tokenizer.Token Token) { ClearState(); Boolean _Ret = true; if (Token.GetTopNodeType().Equals(typeof(Tokenizer.RuleInclude))) { this.m_StartPos = Token.GetPosStart(); this.m_Length = Token.GetPosEnd() - Token.GetPosStart(); LinkedList <Tokenizer.Token> .Enumerator m_Subs = Token.GetEnumerator(); while (m_Subs.MoveNext()) { if (m_Subs.Current.GetNodeType().Equals(typeof(Tokenizer.RuleString))) { this.m_Path = m_Subs.Current.GetValue(false); m_Path = m_Path.Replace("\"", ""); break; } this.m_Length = m_Subs.Current.GetPosEnd() - Token.GetPosStart(); } if (this.m_Path.Equals("\"\"")) { Context.AddLog(1, " missing path", this); } return(_Ret); } else { return(false); } }
override public Boolean TryParse(Context Context, Tokenizer.Token Token) { ClearState(); Boolean _Ret = true; if (Context.m_ActualCmd.Equals(typeof(Tokenizer.RuleFunctionDecl))) { LinkedList <Tokenizer.Token> .Enumerator m_Subs = Token.GetEnumerator(); this.m_StartPos = Token.GetPosStart(); this.m_Length = Token.GetPosEnd() - Token.GetPosStart(); bool _ParseBody = false; while (m_Subs.MoveNext()) { if (m_Subs.Current.GetNodeType().Equals(typeof(Tokenizer.RuleName))) { this.m_Name = m_Subs.Current.GetValue(false); } if (m_Subs.Current.GetNodeType().Equals(typeof(Tokenizer.RuleParamDecl))) { this.m_Params = ParseParams(Context, m_Subs.Current.GetEnumerator(), null); //this is the first node in the params fe. string from (string sText,int Wolf)) } if (m_Subs.Current.GetNodeType().Equals(typeof(Tokenizer.RuleRetDecl))) { this.m_Returns = ParseReturns(Context, m_Subs.Current.GetEnumerator(), null); //this is the first node in the params fe. string from (string sText,int Wolf)) } this.m_Length = m_Subs.Current.GetPosEnd() - Token.GetPosStart(); //length without following body if (_ParseBody == true) { if (!m_Subs.Current.GetNodeType().Equals(typeof(Tokenizer.RuleRCurlPar))) { this.m_Vars = ParseLocals(Context, m_Subs.Current, null); } } if (m_Subs.Current.GetNodeType().Equals(typeof(Tokenizer.RuleLCurlPar))) { _ParseBody = true; //The next token is either a body-line or } } } //Todo missing name return(_Ret); } else { return(false); } }
override public Boolean TryParse(Context Context, Tokenizer.Token Token) { ClearState(); Boolean _Ret = true; if (Token.GetTopNodeType().Equals(typeof(Tokenizer.RuleComment))) { this.m_StartPos = Token.GetPosStart(); this.m_Length = Token.GetPosEnd() - Token.GetPosStart(); m_Comment = Token.GetValue(false); return(_Ret); } else { return(false); } }
override public Boolean TryParse(Context Context, Tokenizer.Token Token) { ClearState(); Boolean _Ret = true; if (Token.GetTopNodeType().Equals(typeof(Tokenizer.RuleParamDecl)) || Token.GetTopNodeType().Equals(typeof(Tokenizer.RuleDecl)) || Context.m_ActualCmd.Equals(typeof(Tokenizer.RuleDecl)) || Token.GetTopNodeType().Equals(typeof(Tokenizer.RuleRetDecl))) { if (Token.GetNodeType().Equals(typeof(Tokenizer.RuleBaseType))) { this.m_Type = Token.GetValue(false); this.m_StartPos = Token.GetPosStart(); this.m_Length = Token.GetPosEnd() - Token.GetPosStart(); } LinkedList <Tokenizer.Token> .Enumerator m_Subs = Token.GetEnumerator(); while (m_Subs.MoveNext()) { if (m_Subs.Current.GetNodeType().Equals(typeof(Tokenizer.RuleBaseType))) { this.m_Type = m_Subs.Current.GetValue(false); this.m_StartPos = m_Subs.Current.GetPosStart(); this.m_Length = m_Subs.Current.GetPosEnd() - m_Subs.Current.GetPosStart(); } if (m_Subs.Current.GetNodeType().Equals(typeof(Tokenizer.RuleName))) { this.m_Name = m_Subs.Current.GetValue(false); break; } this.m_Length = m_Subs.Current.GetPosEnd() - Token.GetPosStart(); } if (this.m_Name.Equals("") && !Token.GetTopNodeType().Equals(typeof(Tokenizer.RuleRetDecl))) { this.m_Error += " missing name"; } //Todo missing name return(_Ret); } else { return(false); } }
abstract public Boolean TryParse(Parser2.Context Context, Tokenizer.Token Token);
override public Boolean TryParse(Context Context, Tokenizer.Token Token) { ClearState(); Boolean _Ret = true; if (Token.GetTopNodeType().Equals(typeof(Tokenizer.RuleUsing))) { LinkedList <Tokenizer.Token> .Enumerator m_Subs = Token.GetEnumerator(); this.m_StartPos = Token.GetPosStart(); this.m_Length = Token.GetPosEnd() - Token.GetPosStart(); while (m_Subs.MoveNext()) { if (m_Subs.Current.GetNodeType().Equals(typeof(Tokenizer.RuleString))) { this.m_Path = m_Subs.Current.GetValue(false); m_Path = m_Path.Replace("\"", ""); //"UserMgr.lvlibp:UserManager.lvclass" -> Name=UserManager //"UserMgr.lvlibp" -> Name=UserMgr Match m = m_RegEx.Match(this.m_Path, 0); if (m.Success && m.Groups.Count == 5) { this.m_Name = m.Groups[3].Value; } else { m = m_RegEx2.Match(this.m_Path, 0); if (m.Success && m.Groups.Count == 3) { this.m_Name = m.Groups[1].Value; } else { this.m_Error += " invalid Path"; } } } if (m_Subs.Current.GetNodeType().Equals(typeof(Tokenizer.RuleUsing))) { Tokenizer.Token AS = m_Subs.Current.First.Value; if (AS.GetNodeType().Equals(typeof(Tokenizer.RuleName))) { this.m_Name = AS.GetValue(false); } } if (m_Subs.Current.GetNodeType().Equals(typeof(Tokenizer.RuleName))) //optional Name is hidden behind "as" { this.m_Name = m_Subs.Current.First.Value.GetValue(false); } this.m_Length = m_Subs.Current.GetPosEnd() - Token.GetPosStart(); } if (this.m_Path.Equals("")) { this.m_Error += " missing path"; } return(_Ret); } else { return(false); } }
/// <summary> /// returns true if the token was successfully converted to Cmd /// even if there are errors in the cmd /// </summary> /// <param name="Context"></param> /// <param name="Token"></param> /// <returns></returns> override public Boolean TryParse(Context Context, Tokenizer.Token Token) { ClearState(); this.m_Error = "unknown Cmd " + Token.GetValue(true); return(true); }