Examples of FactParseError


Examples of org.eclipse.imp.pdb.facts.exceptions.FactParseError

      System.err
          .println("Parse:" + expected + " " + reader.getLastChar());
    start = reader.getPosition();
    switch (reader.getLastChar()) {
    case -1:
      throw new FactParseError("premature EOF encountered.", start);
    case '{':
      result = parseMap(reader, expected);
      break;
    case '[':
      if (expected.isTuple()) {
        result = parseTuple(reader, expected);
      } else
        result = parseList(reader, expected);
      break;
    case 't':
    case 'f':
      result = parseBoolean(reader);
      break;
    case 'n':
      result = parseNull(reader);
      break;
    case '"':
      result = parseString(reader, expected);
      break;
    case '-':
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      result = parseNumber(reader, expected);
      break;
    default:
      throw new FactParseError("Illegal symbol", reader.getPosition());
    }
    return result;
  }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.exceptions.FactParseError

      throws IOException {
    if (debug)
      System.err.println("ParseTuple:" + expected);
    final int c = reader.readSkippingWS();
    if (c == -1) {
      throw new FactParseError("premature EOF encountered.",
          reader.getPosition());
    }
    IValue[] a = new IValue[expected.getArity()];
    Iterator<Type> it = expected.iterator();
    int i = 0;
    if (it.hasNext()) {
      Type typ = it.next();
      IValue term = parse(reader, typ);
      a[i] = term;
      if (debug)
        System.err.println("ParseTuple:" + a[i] + " " + i);
      i++;
    }
    while (reader.getLastChar() == ',' && it.hasNext()) {
      reader.readSkippingWS();
      IValue term = parse(reader, it.next());
      a[i] = term;
      if (debug)
        System.err.println("ParseTuple:" + a[i] + " " + i);
      i++;
    }
    IValue result = vf.tuple(a);
    if (debug)
      System.err.println("result=" + result);
    if (reader.getLastChar() != ']') {
      throw new FactParseError("expected ']' but got '"
          + (char) reader.getLastChar() + "'", reader.getPosition());
    }
    reader.readSkippingWS();
    return result;
  }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.exceptions.FactParseError

            + mapType.getValueType());
      array[1] = parse(reader, mapType.getValueType());
      if (debug)
        System.err.println("ParseEntry4:" + array[1]);
    } else
      throw new FactParseError("In map ':' expected",
          reader.getPosition());
    Type t = tf.tupleType(mapType.getKeyType(), mapType.getValueType());
    return vf.tuple(t, array[0], array[1]);
  }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.exceptions.FactParseError

      expected = tf.mapType(tf.stringType(), tf.valueType());
    if (debug)
      System.err.println("ParseMap2:" + expected);
    IMapWriter w = vf.mapWriter(expected);
    if (c == -1) {
      throw new FactParseError("premature EOF encountered.",
          reader.getPosition());
    }
    if (reader.getLastChar() == '}') {
      reader.readSkippingWS();
      return w.done();
    }
    ITuple term = parseEntry(reader, expected);
    w.put(term.get(0), term.get(1));
    while (reader.getLastChar() == ',') {
      reader.readSkippingWS();
      term = parseEntry(reader, expected);
      w.put(term.get(0), term.get(1));
    }
    if (reader.getLastChar() != '}') {
      throw new FactParseError("expected '}' but got '"
          + (char) reader.getLastChar() + "'", reader.getPosition());
    }
    reader.readSkippingWS();
    return w.done();
  }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.exceptions.FactParseError

    else if(expected.isSourceLocation()){
      try {
        URI uri = new URI(str);
        result = vf.sourceLocation(uri);
      } catch (URISyntaxException e) {
        throw new FactParseError("malformed source location:" + str, reader.getPosition());
      }
    } else {
      result = vf.string(str);
    }
    reader.readSkippingWS(); /* " */
 
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.exceptions.FactParseError

  private IValue parseBoolean(JSonStream reader) throws IOException {
    IValue result;
    String str = parseBooleanLiteral(reader);
    if (!str.equalsIgnoreCase("true") && !str.equalsIgnoreCase("false"))
      throw new FactParseError("true or false expected but found:" + str
          + ".", reader.getPosition());
    result = vf.bool(str.equalsIgnoreCase("true") ? true : false);
    reader.readSkippingWS(); /* e */
    return result;
  }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.exceptions.FactParseError

  private IValue parseNull(JSonStream reader) throws IOException {
    IValue result;
    String str = parseNullLiteral(reader);
    if (!str.equalsIgnoreCase("null"))
      throw new FactParseError("null expected but found:" + str + ".",
          reader.getPosition());
    result = vf.string(str);
    reader.readSkippingWS(); /* l */
    return result;
  }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.exceptions.FactParseError

    IValue result;
    if (debug)
      System.err.println("ParseList:" + expected);
    final int c = reader.readSkippingWS();
    if (c == -1) {
      throw new FactParseError("premature EOF encountered.",
          reader.getPosition());
    }
    if (c == ']') {
      reader.readSkippingWS();
      if (expected.isList()) {
        result = vf.list(expected.getElementType());
      } else if (expected.isSet()) {
        result = vf.set(expected.getElementType());
      } else if (expected.isTuple()) {
        result = vf.tuple();
      } else if (expected.isTop()) {
        result = vf.list(tf.valueType());
      } else {
        throw new FactParseError("Did not expect a list, rather a "
            + expected, reader.getPosition());
      }
    } else {
      result = parseTerms(reader, expected);
      if (reader.getLastChar() != ']' && reader.getLastChar() != '}') {
        throw new FactParseError("expected ']' or '}' but got '"
            + (char) reader.getLastChar() + "'",
            reader.getPosition());
      }
      reader.readSkippingWS();
    }
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.exceptions.FactParseError

        && reader.getLastChar() != 'L') {
      int val;
      try {
        val = Integer.parseInt(str.toString());
      } catch (NumberFormatException e) {
        throw new FactParseError("malformed int:" + str,
            reader.getPosition());
      }
      result = vf.integer(val);
    } else if (reader.getLastChar() == 'l' || reader.getLastChar() == 'L') {
      reader.read();
      throw new FactParseError("No support for longs",
          reader.getPosition());
    } else {
      if (reader.getLastChar() == '.') {
        str.append('.');
        reader.read();
        if (!Character.isDigit(reader.getLastChar()))
          throw new FactParseError("digit expected",
              reader.getPosition());
        do {
          str.append((char) reader.getLastChar());
        } while (Character.isDigit(reader.read()));
      }
      if (reader.getLastChar() == 'e' || reader.getLastChar() == 'E') {
        str.append((char) reader.getLastChar());
        reader.read();
        if (reader.getLastChar() == '-' || reader.getLastChar() == '+') {
          str.append((char) reader.getLastChar());
          reader.read();
        }
        if (!Character.isDigit(reader.getLastChar()))
          throw new FactParseError("digit expected!",
              reader.getPosition());
        do {
          str.append((char) reader.getLastChar());
        } while (Character.isDigit(reader.read()));
      }
      double val;
      try {
        val = Double.valueOf(str.toString()).doubleValue();
        result = vf.real(val);
      } catch (NumberFormatException e) {
        throw new FactParseError("malformed real",
            reader.getPosition(), e);
      }
    }
    reader.skipWS();
    return result;
View Full Code Here

Examples of org.eclipse.imp.pdb.facts.exceptions.FactParseError

      for (int i = terms.length - 1; i >= 0; i--) {
        w.put(((ITuple) terms[i]).get(0), ((ITuple)terms[i]).get(1));
      }
      return w.done();
    }
    throw new FactParseError("Unexpected type " + expected,
        reader.getPosition());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.