Skip to content

Commit

Permalink
working on syntax roles
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Sep 28, 2023
1 parent 79804b4 commit 06f10c5
Show file tree
Hide file tree
Showing 9 changed files with 1,173 additions and 3 deletions.
410 changes: 410 additions & 0 deletions src/org/rascalmpl/ast/SyntaxRoleModifier.java

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions src/org/rascalmpl/semantics/dynamic/SyntaxRoleModifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2009-2013 CWI
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* * Jurgen J. Vinju - [email protected] - CWI
* * Mark Hills - [email protected] (CWI)
*******************************************************************************/
package org.rascalmpl.semantics.dynamic;

import org.rascalmpl.ast.Name;
import org.rascalmpl.interpreter.IEvaluator;
import org.rascalmpl.interpreter.env.Environment;
import org.rascalmpl.interpreter.result.Result;
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.ISourceLocation;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.type.Type;

public abstract class SyntaxRoleModifier extends org.rascalmpl.ast.SyntaxRoleModifier {

static public class Syntax extends org.rascalmpl.ast.SyntaxRoleModifier.Syntax {
public Syntax(ISourceLocation __param1, IConstructor tree, org.rascalmpl.ast.TypeArg __param2) {
super(__param1, tree, __param2);
}

@Override
public Type typeOf(Environment __eval, IEvaluator<Result<IValue>> eval, boolean instantiateTypeParameters) {
return RTF.modifyToSyntax(getArg().typeOf(__eval, eval, instantiateTypeParameters));
}
}

static public class Lexical extends org.rascalmpl.ast.SyntaxRoleModifier.Lexical {
public Lexical(ISourceLocation __param1, IConstructor tree, org.rascalmpl.ast.TypeArg __param2) {
super(__param1, tree, __param2);
}

@Override
public Type typeOf(Environment __eval, IEvaluator<Result<IValue>> eval, boolean instantiateTypeParameters) {
return RTF.modifyToLexical(getArg().typeOf(__eval, eval, instantiateTypeParameters));
}
}

static public class Layout extends org.rascalmpl.ast.SyntaxRoleModifier.Layout {
public Layout(ISourceLocation __param1, IConstructor tree, org.rascalmpl.ast.TypeArg __param2) {
super(__param1, tree, __param2);
}

@Override
public Type typeOf(Environment __eval, IEvaluator<Result<IValue>> eval, boolean instantiateTypeParameters) {
return RTF.modifyToLayout(getArg().typeOf(__eval, eval, instantiateTypeParameters));
}
}

static public class Keyword extends org.rascalmpl.ast.SyntaxRoleModifier.Keyword {
public Keyword(ISourceLocation __param1, IConstructor tree, org.rascalmpl.ast.TypeArg __param2) {
super(__param1, tree, __param2);
}

@Override
public Type typeOf(Environment __eval, IEvaluator<Result<IValue>> eval, boolean instantiateTypeParameters) {
return RTF.modifyToKeyword(getArg().typeOf(__eval, eval, instantiateTypeParameters));
}
}

static public class Data extends org.rascalmpl.ast.SyntaxRoleModifier.Data {
public Data(ISourceLocation __param1, IConstructor tree, org.rascalmpl.ast.TypeArg __param2) {
super(__param1, tree, __param2);
}

@Override
public Type typeOf(Environment __eval, IEvaluator<Result<IValue>> eval, boolean instantiateTypeParameters) {
return RTF.modifyToData(getArg().typeOf(__eval, eval, instantiateTypeParameters));
}
}



public SyntaxRoleModifier(ISourceLocation __param1, IConstructor tree) {
super(__param1, tree);
}
}
14 changes: 13 additions & 1 deletion src/org/rascalmpl/semantics/dynamic/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.rascalmpl.ast.FunctionType;
import org.rascalmpl.ast.StructuredType;
import org.rascalmpl.ast.Sym;
import org.rascalmpl.ast.SyntaxRoleModifier;
import org.rascalmpl.ast.TypeVar;
import org.rascalmpl.ast.UserType;
import org.rascalmpl.interpreter.IEvaluator;
Expand Down Expand Up @@ -105,7 +106,7 @@ public io.usethesource.vallang.type.Type typeOf(Environment env, IEvaluator<Resu
}

}

static public class User extends org.rascalmpl.ast.Type.User {
public User(ISourceLocation __param1, IConstructor tree, UserType __param2) {
super(__param1, tree, __param2);
Expand Down Expand Up @@ -137,6 +138,17 @@ public io.usethesource.vallang.type.Type typeOf(Environment env, IEvaluator<Resu
}
}

static public class Modifier extends org.rascalmpl.ast.Type.Modifier {
public Modifier(ISourceLocation src, IConstructor node, SyntaxRoleModifier modifier) {
super(src, node, modifier);
}

@Override
public io.usethesource.vallang.type.Type typeOf(Environment env, IEvaluator<Result<IValue>> eval, boolean instantiateTypeParameters) {
return getModifier().typeOf(env, eval, instantiateTypeParameters);
}
}

public Type(ISourceLocation __param1, IConstructor tree) {
super(__param1, tree);
}
Expand Down
5 changes: 5 additions & 0 deletions src/org/rascalmpl/types/DefaultRascalTypeVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public T visitReified(RascalType type) throws E {
public T visitNonTerminal(RascalType type) throws E {
return def;
}

@Override
public T visitRoleModifier(RascalType type) throws E {
return def;
}
}
5 changes: 3 additions & 2 deletions src/org/rascalmpl/types/IRascalTypeVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.usethesource.vallang.type.ITypeVisitor;

public interface IRascalTypeVisitor<T,E extends Throwable> extends ITypeVisitor<T, E> {
T visitReified(RascalType type) throws E;
T visitNonTerminal(RascalType type) throws E;
T visitReified(RascalType THIS) throws E;
T visitNonTerminal(RascalType THIS) throws E;
T visitRoleModifier(RascalType THIS) throws E;
}
Loading

0 comments on commit 06f10c5

Please sign in to comment.