private PListValue ReadValue() { while (token != null) { if (token.Type == LexemType.Delimiter) { switch (token.Value) { case ("{"): return(ParseDict()); case ("["): return(ParseIndexedDict()); case ("("): return(ParseTuple()); default: throw new Exception(String.Format("Unexpected token {0}", token)); } } else if (token.Type == LexemType.String) { PListString str = new PListString(token.Value); Next(); return(str); } Next(); } throw new Exception("error"); }
private PListNode ReadNode() { if (token.Type != LexemType.String) { throw new Exception("Node key expected"); } PListString key = (PListString)ReadValue(); List <PListAttribute> Attrs = null; if (token.Value == "{") { Attrs = ReadAttributes(); } if (token.Value != "=") { throw new Exception("'=' expected"); } Next(); PListValue val = null; if (token.Value != ";") { val = ReadValue(); if (token.Value != ";") { throw new Exception("';' expected"); } Next(); } return(new PListNode(key, val) { Attributes = Attrs }); }
private PListValue ParseTuple() { PListTuple tuple = new PListTuple(); Next(); while (token != null) { if (token.Value == ")") { Next(); break; } PListString strVal = (PListString)ReadValue(); tuple.Items.Add(strVal); if (token.Value == ",") { Next(); } } return(tuple); }
private PListAttribute ReadAttribute() { if (token.Type != LexemType.String) { throw new Exception("Attribute key expected"); } PListString key = (PListString)ReadValue(); if (token.Value != "=") { throw new Exception("'=' expected"); } Next(); PListValue val = ReadValue(); if (val is PListString) { return(new PListAttribute(key, val as PListString)); } else { throw new Exception("invalid attribute value"); } }
public PListAttribute(PListString key, PListString value) { this.Key = key; this.Value = value; }
public PListNode(PListString key, PListValue val) { Key = key; Value = val; }