Package wyil.lang

Examples of wyil.lang.Type$EffectiveRecord


  public Type parseBraceTerm(HashSet<String> typeVariables) {
    skipWhiteSpace();
    char lookahead = str.charAt(index);
    if(lookahead == '(') {
      match("(");
      Type t = parse(typeVariables);
      skipWhiteSpace();
      lookahead = str.charAt(index);
      if(lookahead == ',') {
        // this is a tuple, not a bracketed type.
        ArrayList<Type> elems = new ArrayList();
View Full Code Here


      match("string");
      return T_STRING;
    case '[':
    {
      match("[");
      Type elem = parse(typeVariables);
      match("]");
      return List(elem, false);
    }
    case '{':
    {
      match("{");
      Type elem = parse(typeVariables);
      skipWhiteSpace();
      if(index < str.length() && str.charAt(index) == '-') {
        // dictionary
        match("->");
        Type value = parse(typeVariables);
        match("}");
        return Map(elem,value);

      } else if(index < str.length() && str.charAt(index) != '}') {
        // record
        HashMap<String,Type> fields = new HashMap<String,Type>();
        String id = parseIdentifier();
        fields.put(id, elem);
        skipWhiteSpace();
        boolean isOpen = false;
        while(index < str.length() && str.charAt(index) == ',') {
          match(",");
          if(str.charAt(index) == '.') {
            match("...");
            isOpen=true;
            break;
          }
          elem = parse(typeVariables);
          id = parseIdentifier();
          fields.put(id, elem);
          skipWhiteSpace();
        }
        match("}");
        return Record(isOpen,fields);
      }
      match("}");
      return Set(elem,false);
    }
    default:
    {
      String typeVariable = parseIdentifier();
      if(typeVariables.contains(typeVariable)) {
        return Nominal(new NameID(Trie.fromString("$"),
            typeVariable));
      } else {
        typeVariables = new HashSet<String>(typeVariables);
        typeVariables.add(typeVariable);
        match("<");
        Type t = parse(typeVariables);
        match(">");
        NameID label = new NameID(Trie.fromString("$"),
            typeVariable);
        return Recursive(label, t);
      }
View Full Code Here

  public Type parse() {
    return parse(new HashSet<String>());
  }

  public Type parse(HashSet<String> typeVariables) {
    Type term = parseFunctionTerm(typeVariables);
    skipWhiteSpace();
    while (index < str.length()
        && (str.charAt(index) == '|')) {
      // union type
      match("|");
View Full Code Here

    }
    return term;
  }

  public Type parseFunctionTerm(HashSet<String> typeVariables) {
    Type t = parseNotTerm(typeVariables);
    if(index >= str.length()) { return t; }
    char lookahead = str.charAt(index);
    if(lookahead == '(') {
      // this is a tuple, not a bracketed type.
      match("(");
View Full Code Here

  public Type parseBraceTerm(HashSet<String> typeVariables) {
    skipWhiteSpace();
    char lookahead = str.charAt(index);
    if(lookahead == '(') {
      match("(");
      Type t = parse(typeVariables);
      skipWhiteSpace();
      lookahead = str.charAt(index);
      if(lookahead == ',') {
        // this is a tuple, not a bracketed type.
        ArrayList<Type> elems = new ArrayList();
View Full Code Here

      match("string");
      return T_STRING;
    case '[':
    {
      match("[");
      Type elem = parse(typeVariables);
      match("]");
      return List(elem, false);
    }
    case '{':
    {
      match("{");
      Type elem = parse(typeVariables);
      skipWhiteSpace();
      if(index < str.length() && str.charAt(index) == '-') {
        // dictionary
        match("->");
        Type value = parse(typeVariables);
        match("}");
        return Map(elem,value);

      } else if(index < str.length() && str.charAt(index) != '}') {
        // record
        HashMap<String,Type> fields = new HashMap<String,Type>();
        String id = parseIdentifier();
        fields.put(id, elem);
        skipWhiteSpace();
        boolean isOpen = false;
        while(index < str.length() && str.charAt(index) == ',') {
          match(",");
          if(str.charAt(index) == '.') {
            match("...");
            isOpen=true;
            break;
          }
          elem = parse(typeVariables);
          id = parseIdentifier();
          fields.put(id, elem);
          skipWhiteSpace();
        }
        match("}");
        return Record(isOpen,fields);
      }
      match("}");
      return Set(elem,false);
    }
    default:
    {
      String typeVariable = parseIdentifier();
      if(typeVariables.contains(typeVariable)) {
        return Nominal(new NameID(Trie.fromString("$"),
            typeVariable));
      } else {
        typeVariables = new HashSet<String>(typeVariables);
        typeVariables.add(typeVariable);
        match("<");
        Type t = parse(typeVariables);
        match(">");
        NameID label = new NameID(Trie.fromString("$"),
            typeVariable);
        return Recursive(label, t);
      }
View Full Code Here

    System.out.println();
    System.out.println("public class SimplifyTests {");
    int count = 1;
    for (int i = 0; i != types.size(); ++i) {
      Automaton a1 = types.get(i);
      Type t1 = Type.construct(types.get(i));
      if (t1 == Type.T_VOID) {
        continue;
      }
      count++;
      System.out.println("\t@Test public void test_" + count++ + "() {");
View Full Code Here

    System.out.println();
    System.out.println("public class SubtypeTests {");
    int count = 1;
    for(int i=0;i!=types.size();++i) {
      Automaton a1 = types.get(i);
      Type t1 = Type.construct(types.get(i));
      if(t1 == Type.T_VOID) { continue; }
      for(int j=0;j<types.size();++j) {
        Automaton a2 = types.get(j);
        Type t2 = Type.construct(types.get(j));
        if(t2 == Type.T_VOID) { continue; }
        System.out.print("\t@Test public void test_" + count++ + "() { ");
        if(isModelSubtype(a1,a2,model)) {
          System.out.println("checkIsSubtype(\"" + t1 + "\",\"" + t2 + "\"); }");
        } else {
View Full Code Here

    public BinaryTypeWriter(BinaryOutputStream output) {
      super(output);
    }

    public void write(Automaton automaton) throws IOException {
      Type t = Type.construct(new Automaton(automaton));
      if (t != Type.T_VOID) {
        super.write(automaton);
        count++;
        if (verbose) {
          System.err.print("\rWrote " + count + " types.");
View Full Code Here

    public TextTypeWriter(PrintStream output) {
      this.output = output;
    }

    public void write(Automaton automaton) throws IOException {
      Type t = Type.construct(Automata.extract(automaton,0));
      if (t != Type.T_VOID) {
        output.println(t);
        count++;
        if (verbose) {
          System.err.print("\rWrote " + count + " types.");
View Full Code Here

TOP

Related Classes of wyil.lang.Type$EffectiveRecord

Copyright © 2018 www.massapicom. 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.