Skip to content

Commit

Permalink
Merge branch 'main' into syntax-role-modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Apr 9, 2024
2 parents 806a5a9 + ce87697 commit c570d35
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 94 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.rascalmpl</groupId>
<artifactId>rascal</artifactId>
<version>0.37.0-BOOT2-SNAPSHOT</version>
<version>0.38.1-BOOT2-SNAPSHOT</version>
<packaging>jar</packaging>

<scm>
Expand Down
3 changes: 1 addition & 2 deletions src/org/rascalmpl/debug/IRascalMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import org.rascalmpl.interpreter.ConsoleRascalMonitor;
import org.rascalmpl.interpreter.NullRascalMonitor;
import org.rascalmpl.repl.IsTTY;
import org.rascalmpl.repl.TerminalProgressBarMonitor;

import io.usethesource.vallang.ISourceLocation;
Expand Down Expand Up @@ -159,7 +158,7 @@ default void jobStep(String name, String message) {
* @return
*/
public static IRascalMonitor buildConsoleMonitor(InputStream in, OutputStream out) {
return IsTTY.isTTY()
return System.console() != null
? new TerminalProgressBarMonitor(out, in, TerminalFactory.get())
: new ConsoleRascalMonitor(new PrintStream(out))
;
Expand Down
42 changes: 12 additions & 30 deletions src/org/rascalmpl/library/lang/rascal/syntax/tests/ImplodeTests.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,14 @@ import lang::rascal::\syntax::tests::ImplodeTestGrammar;
import ParseTree;
import Exception;

public data Num = \int(str n);
public data Exp = id(str name) | eq(Exp e1, Exp e2) | number(Num n);
public data Num(loc src=|unknown:///|, map[int,list[str]] comments = ()) = \int(str n);
public data Exp(loc src=|unknown:///|, map[int,list[str]] comments = ()) = id(str name) | eq(Exp e1, Exp e2) | number(Num n);
public Exp number(Num::\int("0")) = Exp::number(Num::\int("01"));

public anno loc Num@location;
public anno loc Exp@location;
public anno map[int,list[str]] Num@comments;
public anno map[int,list[str]] Exp@comments;

public data Number = \int(str n);
public data Expr = id(str name) | eq(Expr e1, Expr e2) | number(Number n);
public data Number(loc src=|unknown:///|, map[int,list[str]] comments = ()) = \int(str n);
public data Expr(loc src=|unknown:///|, map[int,list[str]] comments = ()) = id(str name) | eq(Expr e1, Expr e2) | number(Number n);
public Expr number(Number::\int("0")) = Expr::number(Number::\int("02"));

public anno loc Number@location;
public anno loc Expr@location;
public anno map[int,list[str]] Number@comments;
public anno map[int,list[str]] Expr@comments;

public Exp implodeExp(str s) = implode(#Exp, parseExp(s));
public Exp implodeExpLit1() = implode(#Exp, expLit1());
public Exp implodeExpLit2() = implode(#Exp, expLit2());
Expand All @@ -43,31 +33,23 @@ public Expr implodeExprLit2() = implode(#Expr, exprLit2());

test bool test11() { try return Exp::id(_) := implodeExp("a"); catch ImplodeError(_): return false;}

@IgnoreCompiler{
TODO
}
test bool test12() { try return Exp::number(Num::\int("01")) := implodeExp("0"); catch ImplodeError(_): return false;}
@IgnoreCompiler{TODO}
test bool test12() { try return Exp::number(Num::\int("0")) := implodeExp("0"); catch ImplodeError(_): return false;}

test bool test13() { try return Exp::eq(Exp::id(_),Exp::id(_)) := implodeExp("a == b"); catch ImplodeError(_): return false;}

@IgnoreCompiler{
TODO
}
test bool test14() { try return Exp::eq(Exp::number(Num::\int("01")), Exp::number(Num::\int("1"))) := implodeExp("0 == 1"); catch ImplodeError(_): return false;}
@IgnoreCompiler{TODO}
test bool test14() { try return Exp::eq(Exp::number(Num::\int("0")), Exp::number(Num::\int("1"))) := implodeExp("0 == 1"); catch ImplodeError(_): return false;}

test bool test15() { try return Expr::id(_) := implodeExpr("a"); catch ImplodeError(_): return false;}

@IgnoreCompiler{
TODO
}
test bool test16() { try return Expr::number(Number::\int("02")) := implodeExpr("0"); catch ImplodeError(_): return false;}
@IgnoreCompiler{TODO}
test bool test16() { try return Expr::number(Number::\int("0")) := implodeExpr("0"); catch ImplodeError(_): return false;}

test bool test17() { try return Expr::eq(Expr::id(_),Expr::id(_)) := implodeExpr("a == b"); catch ImplodeError(_): return false;}

@IgnoreCompiler{
TODO
}
test bool test18() { try return Expr::eq(Expr::number(Number::\int("02")), Expr::number(Number::\int("1"))) := implodeExpr("0 == 1"); catch ImplodeError(_): return false;}
@IgnoreCompiler{TODO}
test bool test18() { try return Expr::eq(Expr::number(Number::\int("0")), Expr::number(Number::\int("1"))) := implodeExpr("0 == 1"); catch ImplodeError(_): return false;}

// ---- test2 ----

Expand Down
6 changes: 3 additions & 3 deletions src/org/rascalmpl/library/resource/jdbc/JDBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class JDBC {
public static final Type table = TF.constructor(TS, Table, "table", TF.stringType(), "tableName", TF.listType(Column), "columns");

public static final Type nullableT = TF.parameterType("T");
public static final Type Nullable = TF.abstractDataType(TS, "Nullable", nullableT);
public static final Type Nullable = TF.abstractDataType(TS, "NULLable", nullableT);

private final IValueFactory vf;
private final ClassLoader loader;
Expand Down Expand Up @@ -705,10 +705,10 @@ public static IValue jdbc2pdbValue(ResultSet rs, int idx, IValueFactory vf) {
Type resType = jdbc2pdbType(jdbcColumnType, true);

if (rs.wasNull()) {
Type nullT = TF.constructor(TS, resType, "null");
Type nullT = TF.constructor(TS, resType, "NULL");
res = vf.constructor(nullT);
} else {
Type notnullT = TF.constructor(TS, resType, "notnull", resType, "item");
Type notnullT = TF.constructor(TS, resType, "notNULL", resType, "item");
res = vf.constructor(notnullT, res);
}
}
Expand Down
74 changes: 41 additions & 33 deletions src/org/rascalmpl/library/resource/jdbc/JDBC.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
@contributor{Mark Hills - [email protected] (CWI)}
module resource::jdbc::JDBC

import Exception;
import Type;
import Map;
import String;
import List;
import Set;
import IO;
import lang::rascal::types::AbstractType;

@synopsis{Given the name of a JDBC driver class, register it so it can be used in connections.}
@javaClass{org.rascalmpl.library.resource.jdbc.JDBC}
Expand Down Expand Up @@ -120,7 +117,6 @@ public java set[Table] getViews(Connection connection);
public java Table getTable(Connection connection, str tableName);

@synopsis{Get the Table metadata for a named view.}
@javaClass{org.rascalmpl.library.resource.jdbc.JDBC}
public Table getView(Connection connection, str viewName) = getTable(connection, viewName);

@synopsis{An exception thrown when we try to translate (or otherwise use) a JDBC type with no Rascal equivalent.}
Expand Down Expand Up @@ -165,39 +161,50 @@ public Symbol jdbc2RascalType(varBinary()) = \list(\int());
public Symbol jdbc2RascalType(varChar()) = \str();

@synopsis{Represents values which may or may not be null.}
data Nullable[&T] = null() | notnull(&T item);
data NULLable[&T] = NULL() | notNULL(&T item);

@synopsis{Load the contents of a table. This will turn the contents into a set, which by its nature will remove any
duplicates and discard any order. To maintain duplicates, or the order inherent in the table,
use loadTableOrdered instead.}
@synopsis{Load the contents of a table.}
@description{
This will turn the contents into a set, which by its nature will remove any
duplicates and discard any order. To maintain duplicates, or the order inherent in the table,
use loadTableOrdered instead.
}
@javaClass{org.rascalmpl.library.resource.jdbc.JDBC}
public java set[&T] loadTable(type[&T] resType, Connection connection, str tableName);

@synopsis{Load the contents of a table. This will turn the contents into a set, which by its nature will remove any
duplicates and discard any order. To maintain duplicates, or the order inherent in the table, use
loadTableOrdered instead. This versions uses no type information, meaning that it returns a set of values.}
@synopsis{Load the contents of a table.}
@description{
This will turn the contents into a set, which by its nature will remove any
duplicates and discard any order. To maintain duplicates, or the order inherent in the table, use
loadTableOrdered instead. This versions uses no type information, meaning that it returns a set of values.
}
@javaClass{org.rascalmpl.library.resource.jdbc.JDBC}
public java set[value] loadTable(Connection connection, str tableName);

@synopsis{Load the contents of a table. This maintains order and duplicates, but does not provide access to the
relational operations provided by loadTable.}
@synopsis{Load the contents of a table.}
@description{
This maintains order and duplicates, but does not provide access to the
relational operations provided by loadTable.
}
@javaClass{org.rascalmpl.library.resource.jdbc.JDBC}
public java list[&T] loadTableOrdered(type[&T] resType, Connection connection, str tableName);

@synopsis{Load the contents of a table. This maintains order and duplicates, but does not provide access to the
relational operations provided by loadTable. Also, with no type information, this version returns a list
of values.}
@synopsis{Load the contents of a table.}
@description{
This maintains order and duplicates, but does not provide access to the
relational operations provided by loadTable. Also, with no type information, this version returns a list
of values.
}
@javaClass{org.rascalmpl.library.resource.jdbc.JDBC}
public java list[value] loadTableOrdered(Connection connection, str tableName);

@resource{
jdbctables
@resource{jdbctables}
@synopsis{Prints all available schemas.}
@description{
The JDBC tables schema should be given as: `jdbctables+connect-string`
where `connect-string` is the database-specific information needed to connect,
encoded as a URI, for instance: `jdbctables+mysql://localhost/bugs?user=my_user_name&password=my_password`
}
@synopsis{The JDBC tables schema should be given as:
jdbctables+connect-string
where connect-string is the database-specific information needed to connect,
encoded as a URI, for instance:
jdbctables+mysql://localhost/bugs?user=my_user_name&password=my_password}
public str allTableSchemas(str moduleName, loc uri) {
// This indicates which driver we need (MySQL, Oracle, etc)
driverType = uri.scheme;
Expand Down Expand Up @@ -228,16 +235,16 @@ public str allTableSchemas(str moduleName, loc uri) {
// Then, generate the accessor function for each
list[str] tfuns = [ ];
for (Table t <- ts) {
columnTypes = [ nullable ? \label("\\<cn>",\adt("Nullable",[rt])) : \label("\\<cn>",rt) | table(tn,cl) := t, column(cn,ct,nullable) <- cl, rt := jdbc2RascalType(ct) ];
columnTypes = [ nullable ? \label("\\<cn>",\adt("NULLable",[rt])) : \label("\\<cn>",rt) | table(_tn,cl) := t, column(cn,ct,nullable) <- cl, rt := jdbc2RascalType(ct) ];
columnTuple = \tuple(columnTypes);

tfun = "alias \\<t.tableName>RowType = <prettyPrintType(columnTuple)>;
'alias \\<t.tableName>Type = rel[<intercalate(",",[prettyPrintType(ct) | ct <- columnTypes])>];
tfun = "alias \\<t.tableName>RowType = <format(columnTuple)>;
'alias \\<t.tableName>Type = rel[<intercalate(",",[format(ct) | ct <- columnTypes])>];
'
'public \\<t.tableName>Type \\<t.tableName>() {
' registerJDBCClass(\"<drivers[driverType]>\");
' con = createConnection(\"<connectString>\");
' \\<t.tableName>Type res = loadTable(#<prettyPrintType(columnTuple)>,con,\"<t.tableName>\");
' \\<t.tableName>Type res = loadTable(#<format(columnTuple)>,con,\"<t.tableName>\");
' closeConnection(con);
' return res;
'}
Expand All @@ -260,8 +267,7 @@ public str allTableSchemas(str moduleName, loc uri) {
return mbody;
}

@resource{
jdbctable
@resource{jdbctable
}
public str tableSchema(str moduleName, loc uri) {
// This indicates which driver we need (MySQL, Oracle, etc)
Expand Down Expand Up @@ -297,25 +303,27 @@ public str tableSchema(str moduleName, loc uri) {
con = createConnection(connectString);
t = getTable(con,tableName);

columnTypes = [ nullable ? \label("\\<cn>",\adt("Nullable",[rt])) : \label("\\<cn>",rt) | table(tn,cl) := t, column(cn,ct,nullable) <- cl, rt := jdbc2RascalType(ct) ];
columnTypes = [ nullable ? \label("\\<cn>",\adt("Nullable",[rt])) : \label("\\<cn>",rt) | table(_tn,cl) := t, column(cn,ct,nullable) <- cl, rt := jdbc2RascalType(ct) ];
columnTuple = \tuple(columnTypes);

closeConnection(con);

mbody = "module <moduleName>
'import resource::jdbc::JDBC;
'
'alias \\<tableName>RowType = <prettyPrintType(columnTuple)>;
'alias \\<tableName>Type = rel[<intercalate(",",[prettyPrintType(ct) | ct <- columnTypes])>];
'alias \\<tableName>RowType = <format(columnTuple)>;
'alias \\<tableName>Type = rel[<intercalate(",",[format(ct) | ct <- columnTypes])>];
'
'public \\<tableName>Type <funname>() {
' registerJDBCClass(\"<drivers[driverType]>\");
' con = createConnection(\"<connectString>\");
' \\<tableName>Type res = loadTable(#<prettyPrintType(columnTuple)>,con,\"<tableName>\");
' \\<tableName>Type res = loadTable(#<format(columnTuple)>,con,\"<tableName>\");
' closeConnection(con);
' return res;
'}
'";

return mbody;
}

private str format(Symbol s) = "<type(s, ())>";
25 changes: 0 additions & 25 deletions src/org/rascalmpl/repl/IsTTY.java

This file was deleted.

0 comments on commit c570d35

Please sign in to comment.