Skip to content

Commit

Permalink
added todos and a make(Production) function to mirror getConstructor …
Browse files Browse the repository at this point in the history
…and added missing cases to \data modifier in Type

and regenerated the Rascal parser with Arnold's bugfixes
  • Loading branch information
jurgenvinju committed Apr 9, 2024
1 parent c570d35 commit b4e0f11
Show file tree
Hide file tree
Showing 7 changed files with 4,607 additions and 4,557 deletions.
9 changes: 8 additions & 1 deletion src/org/rascalmpl/library/ParseTree.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ Symbol \data(\lexical(Symbol s)) = \data(s);
Symbol \data(\keyword(Symbol s)) = \data(s);
Symbol \data(\layout(Symbol s)) = \data(s);
Symbol \data(a:adt(n, ps)) = a;
Symbol \data(sort(n)) = \adt(n, []);
Symbol \data(\parameterized-sort(n, ps)) = \adt(n, ps);
Symbol \data(lex(n)) = \adt(n, []);
Symbol \data(\parameterized-lex(n, ps)) = \adt(n, ps);
Symbol \data(\keywords(n)) = \adt(n, []);
Symbol \data(\layouts(n)) = \adt(n, []);
Symbol \syntax(\data(Symbol s)) = \syntax(s);
Symbol \syntax(\syntax(Symbol s)) = \syntax(s);
Symbol \syntax(\lexical(Symbol s)) = \syntax(s);
Expand Down Expand Up @@ -776,7 +784,6 @@ data Exp = add(Exp, Exp);
}
java &T<:value implode(type[&T<:value] t, Tree tree);
@synopsis{Annotate a parse tree node with an (error) message.}
anno Message Tree@message;
Expand Down
40 changes: 40 additions & 0 deletions src/org/rascalmpl/library/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,45 @@ public IValue make(IValue type, IString name, IList args, IMap keywordParameters
throw RuntimeExceptionFactory.illegalArgument(type, null, null);
}
}

public IValue make(IConstructor cons, IList args, IMap keywordParameters) {
io.usethesource.vallang.type.Type constructor = new TypeReifier(vf).productionToConstructorType(cons);

Check warning on line 125 in src/org/rascalmpl/library/Type.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/library/Type.java#L125

Added line #L125 was not covered by tests

assert constructor != null;

IValue[] children = new IValue[args.length()];
io.usethesource.vallang.type.Type[] argsTypes = new io.usethesource.vallang.type.Type[args.length()];

Check warning on line 130 in src/org/rascalmpl/library/Type.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/library/Type.java#L129-L130

Added lines #L129 - L130 were not covered by tests

for (int i = 0; i < args.length(); i++) {
children[i] = args.get(i);
argsTypes[i] = children[i].getType();

Check warning on line 134 in src/org/rascalmpl/library/Type.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/library/Type.java#L133-L134

Added lines #L133 - L134 were not covered by tests
}

Map<String, IValue> kwmap;

if(keywordParameters.size() == 0){
kwmap = Collections.emptyMap();

Check warning on line 140 in src/org/rascalmpl/library/Type.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/library/Type.java#L140

Added line #L140 was not covered by tests
} else {
Iterator<Entry<IValue, IValue>> iter = keywordParameters.entryIterator();
kwmap = new HashMap<String, IValue>();

Check warning on line 143 in src/org/rascalmpl/library/Type.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/library/Type.java#L142-L143

Added lines #L142 - L143 were not covered by tests
while(iter.hasNext()){
Entry<IValue, IValue> entry = iter.next();
kwmap.put(((IString) entry.getKey()).getValue(), entry.getValue());
}

Check warning on line 147 in src/org/rascalmpl/library/Type.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/library/Type.java#L145-L147

Added lines #L145 - L147 were not covered by tests
}

try {
if (constructor == null) {
// TODO: improve error messaging, using specialized exception
throw RuntimeExceptionFactory.illegalArgument(cons, null, null);

Check warning on line 153 in src/org/rascalmpl/library/Type.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/library/Type.java#L153

Added line #L153 was not covered by tests
}
return vf.constructor(constructor, children, kwmap);

Check warning on line 155 in src/org/rascalmpl/library/Type.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/library/Type.java#L155

Added line #L155 was not covered by tests

}
catch (FactTypeUseException e) {

Check warning on line 158 in src/org/rascalmpl/library/Type.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/library/Type.java#L158

Added line #L158 was not covered by tests
// TODO: improve error messaging, using specialized exception
throw RuntimeExceptionFactory.illegalArgument(cons, null, null);

Check warning on line 160 in src/org/rascalmpl/library/Type.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/library/Type.java#L160

Added line #L160 was not covered by tests
}
}

}
6 changes: 5 additions & 1 deletion src/org/rascalmpl/library/Type.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,11 @@ public java &T make(type[&T] typ, str name, list[value] args);

@javaClass{org.rascalmpl.library.Type}
public java &T make(type[&T] typ, str name, list[value] args, map[str,value] keywordArgs);


@javaClass{org.rascalmpl.library.Type}
@synopsis{Instantiate a constructor value by first declaring the given constructor and then applying it to the given parameters}
public java &T make(Production cons, list[value] args, map[str,value] keywordArgs);

@synopsis{Returns the dynamic type of a value as a ((Type-Symbol)).}
@description{
As opposed to the # operator, which produces the type of a value statically, this
Expand Down
2 changes: 1 addition & 1 deletion src/org/rascalmpl/library/lang/rascal/syntax/Rascal.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ syntax Type
| modifier: SyntaxRoleModifier modifier
;

syntax SyntaxRoleModifier
syntax SyntaxRoleModifier // TODO @rodin zegt dat dit Type moet zijn en niet TypeArg
= \syntax: "syntax" "[" TypeArg arg "]"
| \lexical: "lexical" "[" TypeArg arg "]"
| \layout: "layout" "[" TypeArg arg "]"
Expand Down
Loading

0 comments on commit b4e0f11

Please sign in to comment.