IKDLObject ParseArgOrProp(KDLParseContext context) // throws IOException { IKDLObject obj; bool isBare = false; int c = context.Peek(); if (c == '"') { obj = new KDLString(ParseEscapedString(context)); } else if (IsValidNumericStart(c)) { obj = ParseNumber(context); } else if (IsValidBareIdStart(c)) { string strVal; if (c == 'r') { context.Read(); int next = context.Peek(); context.Unread('r'); if (next == '"' || next == '#') { strVal = ParseRawString(context); } else { isBare = true; strVal = ParseBareIdentifier(context); } } else { isBare = true; strVal = ParseBareIdentifier(context); } if (isBare) { if ("true" == strVal) { obj = KDLBoolean.True; } else if ("false" == strVal) { obj = KDLBoolean.False; } else if ("null" == strVal) { obj = KDLNull.Instance; } else { obj = new KDLString(strVal); } } else { obj = new KDLString(strVal); } } else { throw new KDLParseException(string.Format("Unexpected character: '{0}'", (char)c)); } if (obj is KDLString kdlString) { c = context.Peek(); if (c == '=') { context.Read(); var value = ParseValue(context); return(new KDLProperty(kdlString.Value, value)); } else if (isBare) { throw new KDLParseException("Arguments may not be bare"); } else { return(obj); } } else { return(obj); } }
public KDLString AsString() => KDLString.From(Value.ToString());