Ejemplo n.º 1
0
  private static List<Object> elementList(Text t, DataType type) {
    final List<Object> result = new ArrayList<>();

    // elementList: ( WS? value ( WS? ',' WS? value )* WS? )?
    if (t.ws() && value(t, type, result)) {
      while (true) {
        final int save = t.cursor();
        if (t.ws() && t.consume(',') && t.ws() && value(t, type, result)) {
          continue;
        }
        t.setCursor(save);
        break;
      }
    }

    return result;
  }
Ejemplo n.º 2
0
  private static boolean datetime(Text t, List<Object> valueList) {
    final boolean result;

    final int start = t.cursor();
    if (t.consume('@') && date(t) && t.ws() && time(t)) {
      final String string = t.getString(start + 1); // Jump the'@'
      final LocalDateTime value = DateU.parseStandardDatetime(string);
      valueList.add(value);
      result = true;
    } else {
      result = false;
    }

    return result;
  }
Ejemplo n.º 3
0
  /**
   * Parse a string into a list of data values. White space is supported only in between the [square
   * brackets].
   *
   * @param string A string representation of an Oak property array, e.g. [ true, null, false ]
   * @param type The type of the array, may be 'any'.
   * @return A potentially empty but not null list of values.
   */
  @SuppressWarnings("unchecked")
  public static <T> List<T> parseArray(String string, DataType type) {
    final List<?> result;

    final Text t = new Text();
    t.append(string);
    if (t.consume('[')
        && (result = elementList(t, type)) != null
        && (t.ws() && t.consume(']'))
        && t.isEof()) {
      // OK
    } else {
      throw new ParsingException("Invalid array: " + string);
    }

    return (List<T>) result;
  }
Ejemplo n.º 4
0
  /**
   * There's a bug in this as it requires seconds in the string whereas the time() function does
   * not. It seems to be in the Java parser.
   *
   * @param tb Source to parse.
   * @return A Temporal or null if none found.
   */
  @Nullable
  private static Temporal temporal(Text t) {
    Temporal result;

    final int save = t.cursor();
    t.consume('@');
    final int start = save + 1;

    // yyyy/MM/dd HH:mm:ss

    try {
      if (date(t)) {
        final int save2 = t.cursor();
        t.ws();
        if (time(t)) {
          final String string = t.getString(start);
          result = DateU.parseStandardDatetime(string);
        } else {
          t.setCursor(save2);
          final String string = t.getString(start);
          result = DateU.parseStandardDate(string);
        }
      } else if (time(t)) {
        final String string = t.getString(start);
        result = DateU.parseStandardTime(string);
      } else {
        result = null;
        t.setCursor(save);
      }
    } catch (final DateTimeParseException e) {
      result = null;
      t.setCursor(save);
    }

    return result;
  }