Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typeVariableValues grammar. Print typeVars in grammar serialization. #903

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
/.h2Start.sh.swp

**/.DS_Store
**/pure-duckDB-test-Db
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ buildMilestoningVariableExpression: LATEST_DATE | DATE | variable

expressionInstance: NEW_SYMBOL
(variable | qualifiedName)
(typeVariableValues)?
(LESSTHAN typeArguments? (PIPE multiplicityArguments)? GREATERTHAN)? (identifier)?
(typeVariableValues)?
GROUP_OPEN
expressionInstanceParserPropertyAssignment? (COMMA expressionInstanceParserPropertyAssignment)*
GROUP_CLOSE
Expand Down Expand Up @@ -461,7 +461,7 @@ booleanPart: AND expression
functionVariableExpression: identifier COLON type multiplicity
;

type: ( qualifiedName typeVariableValues? (LESSTHAN (typeArguments? (PIPE multiplicityArguments)?) GREATERTHAN)? )
type: ( qualifiedName (LESSTHAN (typeArguments? (PIPE multiplicityArguments)?) GREATERTHAN)?) typeVariableValues?
|
(
CURLY_BRACKET_OPEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ public static <T extends Appendable> T print(T appendable, CoreInstance cls, boo
{
ListIterable<? extends CoreInstance> typeParameters = cls.getValueForMetaPropertyToMany(M3Properties.typeParameters);
ListIterable<? extends CoreInstance> multiplicityParameters = cls.getValueForMetaPropertyToMany(M3Properties.multiplicityParameters);
ListIterable<? extends CoreInstance> typeVariables = cls.getValueForMetaPropertyToMany(M3Properties.typeVariables);
boolean hasTypeParams = typeParameters.notEmpty();
boolean hasMultParams = multiplicityParameters.notEmpty();
boolean hasTypeVariables = typeVariables.notEmpty();

SafeAppendable safeAppendable = SafeAppendable.wrap(appendable);
if (fullPaths)
Expand Down Expand Up @@ -181,6 +183,12 @@ public static <T extends Appendable> T print(T appendable, CoreInstance cls, boo
}
safeAppendable.append('>');
}
if (hasTypeVariables)
{
safeAppendable.append("(");
safeAppendable.append(typeVariables.collect(x -> x.getValueForMetaPropertyToOne("name").getName() + ":" + x.getValueForMetaPropertyToOne(M3Properties.genericType).getValueForMetaPropertyToOne(M3Properties.rawType).getValueForMetaPropertyToOne(M3Properties.name).getName()).makeString(","));
safeAppendable.append(")");
}
return appendable;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ public void testClassVariable()
" ret(){$x} :Integer[1];" +
" values : U[1];" +
"}" +
"Class meta::pure::metamodel::path::test::ListStringMax200 extends List(200)<String>\n" +
"Class meta::pure::metamodel::path::test::ListStringMax200 extends List<String>(200)\n" +
"{\n" +
"}" +
"" +
"function meta::pure::metamodel::path::test::testFunc():Boolean[1]" +
"{" +
" ^List(200)<String>(values = [1,2,3]);" +
" ^List<String>(200)(values = [1,2,3]);" +
" true;" +
"}";
new M3AntlrParser(null).parse(code, "test" + i++, true, 0, repository, this.newInstances, this.stateListener, context, 0, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void testPrimitiveWithVariable()
"{\n" +
" 2->cast(@test::IntCap(1));\n" +
"}",
"Compilation error at (resource:fromString.pure line:6 column:26), \"Type variable mismatch for the class IntCap (expected 2, got 1): IntCap(1)\"");
"Compilation error at (resource:fromString.pure line:6 column:26), \"Type variable mismatch for the class IntCap(x:Integer,z:String) (expected 2, got 1): IntCap(1)\"");
}

@Test
Expand All @@ -101,7 +101,7 @@ public void testPrimitiveWrongVariableType()
"{\n" +
" [];\n" +
"}",
"Compilation error at (resource:fromString.pure line:6 column:26), \"Type variable type mismatch for the class IntCap (expected Integer, got String): \"");
"Compilation error at (resource:fromString.pure line:6 column:26), \"Type variable type mismatch for the class IntCap(x:Integer) (expected Integer, got String): \"");
}

@Test
Expand Down Expand Up @@ -171,7 +171,7 @@ public void testPrimitiveWithParameterInClassError()
"{" +
" v : test::IntCap()[1];" +
"}",
"Compilation error at (resource:fromString.pure line:1 column:88), \"Type variable mismatch for the class IntCap (expected 1, got 0): IntCap\"");
"Compilation error at (resource:fromString.pure line:1 column:88), \"Type variable mismatch for the class IntCap(x:Integer) (expected 1, got 0): IntCap\"");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Objects;

public class ValCoreInstance extends AbstractCompiledCoreInstance
{
Expand All @@ -44,6 +45,23 @@ public ValCoreInstance(String val, String type)
this.type = type;
}

@Override
public boolean equals(Object o)
{
if (!(o instanceof ValCoreInstance))
{
return false;
}
ValCoreInstance that = (ValCoreInstance) o;
return Objects.equals(val, that.val) && Objects.equals(type, that.type);
}

@Override
public int hashCode()
{
return Objects.hash(super.hashCode(), val, type);
}

public Object getValue()
{
switch (this.type)
Expand Down
Loading