Commit 6d64f5aa authored by Paul Asmuth's avatar Paul Asmuth
Browse files

plist: parse 'enum' style values

parent d16a80a2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ struct Property;
using PropertyList = std::vector<Property>;

enum class PropertyKind {
  MAP, TUPLE, LIST, VALUE, VALUE_LITERAL
  MAP, TUPLE, LIST, ENUM, VALUE, VALUE_LITERAL
};

struct Property {
+37 −1
Original line number Diff line number Diff line
@@ -135,6 +135,9 @@ bool PropertyListParser::parsePropertyListOrTuple(PropertyList* plist) {
      case T_SEMICOLON:
        return true;

      case T_RPAREN:
        return true;

      case T_COMMA:
        consumeToken();
        continue;
@@ -160,6 +163,7 @@ bool PropertyListParser::parsePropertyTupleOrValue(Property* prop) {
  if (args.size() == 1) {
    prop->kind = args[0].kind;
    prop->value = args[0].value;
    prop->next = std::move(args[0].next);
  } else {
    prop->kind = PropertyKind::TUPLE;
    prop->next = std::make_unique<PropertyList>(std::move(args));
@@ -176,7 +180,7 @@ bool PropertyListParser::parsePropertyTuple(PropertyList* plist) {
      case T_STRING_QUOTED:
      case T_STRING: {
        Property prop;
        if (!parsePropertyValue(&prop)) {
        if (!parsePropertyValueOrEnum(&prop)) {
          return false;
        }

@@ -184,6 +188,9 @@ bool PropertyListParser::parsePropertyTuple(PropertyList* plist) {
        break;
      }

      case T_RPAREN:
        return true;

      case T_COMMA:
        return true;

@@ -200,6 +207,35 @@ bool PropertyListParser::parsePropertyTuple(PropertyList* plist) {
  return true;
}

bool PropertyListParser::parsePropertyValueOrEnum(Property* prop) {
  if (!parsePropertyValue(prop)) {
    return false;
  }

  if (prop->kind != PropertyKind::VALUE_LITERAL) {
    return true;
  }

  TokenType ttype;
  std::string tbuf;
  if (!getToken(&ttype, &tbuf) || ttype != T_LPAREN) {
    return true;
  }

  prop->kind = PropertyKind::ENUM;
  prop->next = std::make_unique<PropertyList>();

  expectAndConsumeToken(T_LPAREN);

  if (!parsePropertyListOrTuple(prop->next.get())) {
    return false;
  }

  expectAndConsumeToken(T_RPAREN);

  return true;
}

bool PropertyListParser::parsePropertyValue(Property* prop) {
  TokenType ttype;
  std::string tbuf;
+3 −1
Original line number Diff line number Diff line
@@ -73,7 +73,9 @@ protected:
  bool parsePropertyListOrTuple(PropertyList* plist);
  bool parsePropertyTupleOrValue(Property* prop);
  bool parsePropertyTuple(PropertyList* plist);
  bool parsePropertyValue(Property* plist);
  bool parsePropertyValueOrEnum(Property* prop);
  bool parsePropertyEnum(Property* prop);
  bool parsePropertyValue(Property* prop);
  bool parsePropertyMap(const std::string& pname, PropertyList* plist);

  bool getToken(