public override IValue interpret(Context context) { if (declaration is ConcreteMethodDeclaration) { ConcreteMethodDeclaration method = (ConcreteMethodDeclaration)(object)declaration; context.registerDeclaration(method); MethodType type = new MethodType(method); context.registerValue(new Variable(method.GetName(), type)); context.setValue(method.GetName(), new ClosureValue(context, type)); return(null); } else { throw new SyntaxError("Unsupported:" + declaration.GetType().Name); } }
public void parsesMethod1Parameter1Statement() { String statement = "method printName ( Person p ) { print ( value = \"person\" + p.name); }"; OTestParser parser = new OTestParser(statement); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); Assert.IsTrue(ad.getParameters().Contains(new CategoryParameter(new CategoryType("Person"), "p"))); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print(value = \"person\" + p.name)", generate(ad.getStatements()[0])); }
public void testMethod1Parameter1Statement() { String statement = "define printName as method receiving Person p doing:\r\n" + "\tprint with \"person\" + p.name as value"; ETestParser parser = new ETestParser(statement, false); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); Assert.IsTrue(ad.getParameters().Contains(new CategoryParameter(new CategoryType("Person"), "p"))); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print with \"person\" + p.name as value", generate(ad.getStatements()[0])); }
public void parsesMethod1Array1Statement() { String statement = "method printName ( Option[] options ) { print ( value = \"array\" + options ); }"; OTestParser parser = new OTestParser(statement); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); IParameter expected = new CategoryParameter(new ListType(new CategoryType("Option")), "options"); Assert.IsTrue(ad.getParameters().Contains(expected)); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print(value = \"array\" + options)", generate(ad.getStatements()[0])); }
public void parsesMethod1Extended1Statement() { String statement = "method printName ( Object(name) o ) { print ( value = \"object\" + o.name ); }"; OTestParser parser = new OTestParser(statement); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); IParameter expected = new ExtendedParameter(new CategoryType("Object"), "o", new IdentifierList("name")); Assert.IsTrue(ad.getParameters().Contains(expected)); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print(value = \"object\" + o.name)", generate(ad.getStatements()[0])); }
public void testMethod1Array1Statement() { String statement = "define printName as method receiving Option[] options doing:\r\n" + "\tprint with \"array\" + args as value"; ETestParser parser = new ETestParser(statement, false); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); IParameter expected = new CategoryParameter(new ListType(new CategoryType("Option")), "options"); Assert.IsTrue(ad.getParameters().Contains(expected)); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print with \"array\" + args as value", generate(ad.getStatements()[0])); }
public void testMethod1Extended1Statement() { String statement = "define printName as method receiving Object o with attribute name doing:\r\n" + "\tprint with \"object\" + o.name as value"; ETestParser parser = new ETestParser(statement, false); ConcreteMethodDeclaration ad = parser.parse_concrete_method_declaration(); Assert.IsNotNull(ad); Assert.AreEqual("printName", ad.GetName()); Assert.IsNotNull(ad.getParameters()); IParameter expected = new ExtendedParameter(new CategoryType("Object"), "o", new IdentifierList("name")); Assert.IsTrue(ad.getParameters().Contains(expected)); Assert.IsNotNull(ad.getStatements()); Assert.AreEqual("print with \"object\" + o.name as value", generate(ad.getStatements()[0])); }