This is the cheatsheat for a Rascal workshop
|
String
|
str
|
|
Boolean
|
bool
|
|
Array
|
list[T]
|
|
Location
|
loc
|
|
Map / set
|
map[T, T]
|
|
Integer
|
int
|
|
Set (unique array)
|
set[T]
|
|
String
|
import String
|
|
Boolean
|
import Boolean
|
|
List
|
import List
|
|
Location
|
import Location
|
|
Map
|
import Map
|
|
Integer
|
import util::Math
|
|
Set
|
import Set
|
|
M3 AST
|
import analysis::m3::AST
|
|
IO
|
import IO
|
createAstsFromDirectory(loc project, true);
|
Print to console (one line)
|
println(value)
|
|
Print to console (formatted)
|
iprintln(value)
|
|
File
|
|file:///home/rascal/rascal.rsc|
|
|
Project
|
|project://android-project/|
|
|
URL
|
|http://www.google.nl|
|
|
Folder
|
|file:///home/rascal/|
|
|
String - append
|
str : "str" + "str"
|
|
String - compare
|
bool : "str == "str"
|
|
String - interpolation
|
"value: <str>"
|
|
List - assignment
|
list[int] : [3,2,1];
|
|
List - append
|
list[int] : [3,2] + 1;
|
|
Set - assignment
|
set[int]: {3,2,1}
|
|
Set - append
|
set[int]: {3,2} + 1;
|
// data Game = game(list[Player] players);
// Game game = getGame();
// Access players:
game.players
// Overwrite players:
game.players = []
// Add player:
game.players = game.players + player
if("str" == "str") {
iprintln("true");
} else {
iprintln("false");
}
list[int] numbers = [1, 2, 3, 4, 5];
for (number <- numbers) {
iprintln(number);
}
map[str, int] numbers = ["one" : 1, "two" : 2,
"three" : 3, "four" : 4, "five" : 5];
for (numberText <- numbers) {
int numberValue = numbers[numberText];
iprintln(numberValue);
}
|
Read file
|
readFile(location)
|
|
Write file
|
writeFile(location, value)
|
public str getString() {
return "String";
}
|
wildcard
|
_
|
|
Value check
|
"exact value"
|
|
Assignment
|
method
|
|
Block assignment
|
block:
|
visit (ast) {
case \import(importName): {
iprintln(importName);
}
}
visit (ast) {
case \import(_): {
iprintln("Found an import");
}
}
visit (ast) {
case \import("ImportedClass"): {
iprintln("found ImportedClass");
}
}
visit (ast) {
case \field(simpleType(simpleName(name)), _): {
iprintln("found a field: <name>");
}
}
|
layout
|
The layout of the syntax. Is the syntax separated by spaces or new lines.
|
|
lexical
|
Definition for a block of the input, which is separated by the layout.
|
|
start syntax
|
The global syntax definition of the input
|
|
syntax
|
The global syntax can be separated into smaller pieces, which can be defined with a syntax.
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.