示例#1
0
        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");
        }
示例#2
0
        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
            });
        }
示例#3
0
        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);
        }
示例#4
0
        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");
            }
        }
示例#5
0
 public PListAttribute(PListString key, PListString value)
 {
     this.Key   = key;
     this.Value = value;
 }
示例#6
0
 public PListNode(PListString key, PListValue val)
 {
     Key   = key;
     Value = val;
 }