public override TestResult <bool> Validate(ref string input, bool consume) { TestResult <bool> result = new TestResult <bool>(false, TestResultType.Failed); string temp = input; if (!_delimiters.Contains(" ")) { temp = temp.Replace(" ", "[space]"); } bool check = true; ParseTreeNode leaf = new ParseTreeNode(); if (this.Name == null || this.Name.Length == 0) { leaf.Name = "__SYSTEM_GRAMMAR_CMPGE"; } else { leaf.Name = this.Name; } foreach (GrammarElement g in Terminals) { temp = temp.Trim(_delimiters.ToArray()).Replace("[space]", " "); TestResult <bool> terminalcheck = g.Validate(ref temp, true); check = check && terminalcheck.Result; if (terminalcheck.Result == false) { break; } if (g.Name != null) { if (g.Name.Equals("SemiColon")) { Console.Write(""); } } if (terminalcheck.Data.ContainsKey("$PARSETREE.NODE$") && !g.IsInterim) { leaf.Children.Add((ParseTreeNode)terminalcheck.Data["$PARSETREE.NODE$"]); } if (!_delimiters.Contains(" ")) { temp = temp.Replace(" ", "[space]"); } } if (check) { if (consume) { input = temp.Trim(_delimiters.ToArray()).Replace("[space]", " "); } result.Result = true; result.Type = TestResultType.Complete; GrammarPath gpa = new GrammarPath(); gpa.Put(this.Name); result.Data.Add("PATH", gpa); result.Data.Add("$PARSETREE.NODE$", leaf); } return(result); }
public override TestResult <bool> Validate(ref string input, bool consume) { string temp = input; if (_type == VariableLengthGrammarElementType.Star && input.Length == 0) { TestResult <bool> res = new TestResult <bool>(true, TestResultType.Complete); GrammarPath gp = new GrammarPath(); gp.Put(this.Name); res.Data.Add("PATH", gp); ParseTreeNode leaf = new ParseTreeNode(); if (this.Name == null || this.Name.Length == 0) { leaf.Name = "__SYSTEM_GRAMMAR_VARGE"; } else { leaf.Name = this.Name; } leaf.Value = ""; res.Data.Add("$PARSETREE.NODE$", leaf); return(res); } TestResult <bool> result = Sets.SatisfiedBy(ref input, consume, true); if (result.Result == false && _type == VariableLengthGrammarElementType.Star) { result.Result = true; result.Type = TestResultType.Failed; GrammarPath gp = new GrammarPath(); gp.Put(this.Name); result.Data.Add("PATH", gp); return(result); } if (temp.Length == 0) { if (input.Length != 0) { result.Type = TestResultType.Complete; result.Result = true; result.Data.Clear(); } else if (_type == VariableLengthGrammarElementType.Plus) { result.Type = TestResultType.Failed; result.Result = false; result.Data.Clear(); } } else if (temp.Length == input.Length) { result.Type = TestResultType.Failed; result.Result = false; result.Data.Clear(); } else { result.Type = TestResultType.Partial; result.Result = true; result.Data.Clear(); } if (!consume && result.Result) { input = temp; } if (result.Result) { GrammarPath gp = new GrammarPath(); gp.Put(this.Name); result.Data.Add("PATH", gp); if (input.Length != 0) { int indx = temp.Length - input.Length; temp = temp.Remove(indx).Trim(); } ParseTreeNode leaf = new ParseTreeNode(); if (this.Name == null || this.Name.Length == 0) { leaf.Name = "$SYSTEM.STRING$"; } else { leaf.Name = this.Name; } leaf.Value = temp; result.Data.Add("$PARSETREE.NODE$", leaf); return(result); } return(new TestResult <bool>(false, TestResultType.Failed)); }