public SyntaxItem Find(string key) { foreach (var value in values) { SyntaxItem item = value as SyntaxItem; if (item == null) { continue; } if (item.key == key) { return(item); } } return(null); }
public static SyntaxItem RootParse(String raw) { line = 0; List <Value> synatxNodes = new List <Value>(); var trim = Regex.Replace(raw, @"[\f\r\t\v ]+", ""); int charIndex = 0; while (charIndex < trim.Length) { var node = new SyntaxItem(trim, ref charIndex); synatxNodes.Add(node); } return(new SyntaxItem("root", synatxNodes)); }
public IEnumerable <SyntaxItem> Finds(string key) { var rslt = new List <SyntaxItem>(); foreach (var value in values) { SyntaxItem item = value as SyntaxItem; if (item == null) { continue; } if (item.key == key) { rslt.Add(item); } } return(rslt); }
protected static List <Value> LoadList(string raw, ref int charIndex) { List <Value> rslt = new List <Value>(); int start = charIndex; int end = start; while (end < raw.Length) { var elemType = RegexMatch(raw, start, out end); switch (elemType) { case ELEM_TYPE.KEY: { var node = new SyntaxItem(raw, ref start); rslt.Add(node); } break; case ELEM_TYPE.CR: { start = end; continue; } case ELEM_TYPE.STRING: { var substr = raw.Substring(start, end - start); double dbValue; bool bValue; if (double.TryParse(substr, out dbValue)) { rslt.Add(new DigitValue() { digit = dbValue }); } else if (bool.TryParse(substr, out bValue)) { rslt.Add(new BoolValue() { data = bValue }); } else { rslt.Add(new StringValue() { data = substr }); } start = end; } break; case ELEM_TYPE.COMMA: { if (rslt.Count == 0) { throw new Exception(); } start = end; } break; case ELEM_TYPE.BRACE_CLOSE: { charIndex = end; return(rslt); } default: throw new Exception(); } } return(rslt); }