Package wyvern.tools.typedAST.interfaces

Examples of wyvern.tools.typedAST.interfaces.TypedAST


        "  class def create():T\n" +
        "    new\n" +
        "  def bar():Int\n" +
        "    9\n" +
        "C.create().bar()";
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");
    Assert.assertEquals(res.typecheck(Globals.getStandardEnv(), Optional.empty()), Int.getInstance());
    Assert.assertEquals(res.evaluate(Globals.getStandardEnv()).toString(), "IntegerConstant(9)");
  }
View Full Code Here


  public void testDSL2() throws IOException, CopperParserException {
    String input =
        "val test = ~\n" +
            "  hello\n" +
            "7\n";
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");
    String parsed = ((DSLLit)((ValDeclaration) ((Sequence) res).getDeclIterator().iterator().next()).getDefinition()).getText().get();
    Assert.assertEquals("hello", parsed);
  }
View Full Code Here

        "val test:Int = ~\n" +
            "  hello\n" +
            "  world\n" +
            "    today\n" +
            "7\n";
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");
    String parsed = ((DSLLit)((ValDeclaration) ((Sequence) res).getDeclIterator().iterator().next()).getDefinition()).getText().get();
    Assert.assertEquals("hello\nworld\n\ttoday", parsed);

  }
View Full Code Here

            "  hello\n" +
            "  world\n" +
            "    today\n" +
            "  today\n" +
            "7\n";
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");
    String parsed = ((DSLLit)((ValDeclaration) ((Sequence) res).getDeclIterator().iterator().next()).getDefinition()).getText().get();
    Assert.assertEquals("hello\nworld\n\ttoday\ntoday", parsed);
  }
View Full Code Here

    String input =
        "val test = new\n" +
            "  val d = 4\n" +
            "  def x():Int = 7\n" +
            "7\n";
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");

  }
View Full Code Here

    String input =
        "val test = (new.x())+9/3-3\n" +
            "  val d = 4\n" +
            "  def x():Int = 7\n" +
            "test\n";
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");
    res.typecheck(Globals.getStandardEnv(), Optional.empty());
    Assert.assertEquals("IntegerConstant(7)",res.evaluate(Globals.getStandardEnv()).toString());
  }
View Full Code Here

        "val test = (new.d.k)+9/3-3\n" +
            "  val d = new\n" +
            "    val k = 19\n" +
            "  def x():Int = 7\n" +
            "test\n";
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");
    res.typecheck(Globals.getStandardEnv(), Optional.empty());
    Assert.assertEquals("IntegerConstant(19)",res.evaluate(Globals.getStandardEnv()).toString());
  }
View Full Code Here

    String input =
        "val x = 3\n" +
        "val test = new\n" +
        "  val x = x\n" +
        "test.x\n";
    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");
    res.typecheck(Globals.getStandardEnv(), Optional.empty());
    Assert.assertEquals("IntegerConstant(3)",res.evaluate(Globals.getStandardEnv()).toString());
  }
View Full Code Here

            "  def getValue():Int\n" +
            "  metadata:HasParser = myNumMetadata\n" +
            "val n:MyNum = { 5 }\n" +
            "n.getValue()";

    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");

    Type parserType = Util.javaToWyvType(ExtParser.class);
    Type metaType = Util.javaToWyvType(HasParser.class);


    final ExtParser parseri = str -> {
      New newv = new New(new HashMap<>(), null);
      TypedAST dbody = new IntegerConstant(Integer.parseInt(str.getSrcString().trim()));
      newv.setBody(new DeclSequence(Arrays.asList(new DefDeclaration("getValue", new Arrow(Unit.getInstance(), Int.getInstance()), new ArrayList<>(), dbody, false))));
      return newv;
    };

    HasParser inner = new HasParser() {
View Full Code Here

            "  metadata:HasParser = new\n" +
            "    def getParser():ExtParser = TrivDSLParser.create()\n" +
            "val n:MyNum = { 5 }\n" +
            "n.getValue()";

    TypedAST res = (TypedAST)new Wyvern().parse(new StringReader(input), "test input");

    Assert.assertEquals(res.typecheck(Globals.getStandardEnv(), Optional.empty()), Int.getInstance());
    res = new DSLTransformer().transform(res);
    Assert.assertEquals(res.evaluate(Globals.getStandardEnv()).toString(), "IntegerConstant(5)");
  }
View Full Code Here

TOP

Related Classes of wyvern.tools.typedAST.interfaces.TypedAST

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.