Skip to main content

Create a new Rascal project

rascal-0.34.0

Rascal projects, generally, work the same in all three IDE contexts:

  • Eclipse
  • VScode
  • Commandline

To create an empty project to get started, follow these instructions:

rascal>import util::Reflective;
ok
rascal>newRascalProject(|home:///my-project-name|)
ok

The Eclipse plugin has a "New Project Wizard" you can use as well.

The next step is to import the new project into VScode or Eclipse, or to cd to the project's root directory. From there on Running Rascal with the new project's source and library settings is trivial.

Rascal Project Layout

Let's describe the anatomy of what is generated by New Rascal Project, in case you need to reproduce it manually for some reason.

rascal>import util::FileSystem;
ok

there are these files in the newly create project

rascal>[ l | /file(l) := crawl(|home:///my-project-name|) ]
list[loc]: [
|home:///my-project-name/META-INF/RASCAL.MF|,
|home:///my-project-name/src/main/rascal/Main.rsc|,
|home:///my-project-name/pom.xml|
]

The pom.xml file is the basic setup that names the project and defines its dependencies. It defines:

  • project name (artifactId and groupId)
  • project version
  • where to find Rascal library packages (repositories)
  • where to find Rascal maven plugins (pluginRepositories)
  • a list of dependencies (by default only Rascal, but find more packages
  • minimal configurations for the required maven plugins (Java and Rascal)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.rascalmpl</groupId>
<artifactId>my-project-name</artifactId>
<version>0.1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>usethesource</id>
<url>https://releases.usethesource.io/maven/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>usethesource</id>
<url>https://releases.usethesource.io/maven/</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.rascalmpl</groupId>
<artifactId>rascal</artifactId>
<version>0.34.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<compilerArgument>-parameters</compilerArgument>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.rascalmpl</groupId>
<artifactId>rascal-maven-plugin</artifactId>
<version>0.8.2</version>
<configuration>
<errorsAsWarnings>true</errorsAsWarnings>
<bin>${project.build.outputDirectory}</bin>
<srcs>
<src>${project.basedir}/src/main/rascal</src>
</srcs>
</configuration>
</plugin>
</plugins>
</build>
</project>

Next to that RASCAL.MF is required to configure the development environment for the project. Some information from the pom.xml is repeated here, because this file is common between Eclipse, VScode and empty commandline projects, and such projects could work with a pom.xml:

Manifest-Version: 0.0.1
Project-Name: my-project-name
Source: src/main/rascal
Require-Libraries:

And finally in src/main/rascal you'll find the Rascal source files, as configured in RASCAL.MF. In this case it's only Main.rsc:

module Main

import IO;

int main(int testArgument=0) {
println("argument: <testArgument>");
return testArgument;
}