Language and projects
Project structure
Folders
myproject/
ras.toml
src/ *.ras (standard modules. One per file)
objects/ Sheet and ThisWorkbook modules (<code name>.ras, ThisWorkbook.ras)
forms/ User form designs (*.form.json) and code-behind (*.ras)
types/ Additional type definitions (*.d.ras)
test/ Tests (*.test.ras) and test helpers and fixtures. Not included in the workbook
vba/ Handwritten VBA extracted from the workbook
build/ Generated output (.bas / .cls / .rasmap, JavaScript for debugging and tests, result workbooks, backups)
Files in build/ are regenerated by ras build / ras run / ras test, so do not edit them directly.
Files and modules
RAS files and VBA modules correspond one to one.
| File | VBA module |
|---|---|
src/main.ras |
Standard module Main (from the file name. mod_util.ras → ModUtil) |
A class declaration (in any file) |
A class module for each class (<class name>.cls. You can write several in one file) |
objects/Sheet1.ras |
The module of the sheet with code name Sheet1 (Sheet and workbook code) |
objects/ThisWorkbook.ras |
ThisWorkbook |
forms/frmInput.ras and forms/frmInput.form.json |
User form frmInput (User forms) |
| RAS standard library | RAS_Range, RAS_Fs, etc., only when used |
No VBA module is generated from a .ras file that has no functions, variables, or code.
import
exports of other modules are imported by a path from the project folder. Standard modules in src/ can also be called by module name without import, just like sheet code names (Main.hello()).
// src/report.ras
import { formatYen } from "src/util";
import * as fs from "fs"; // RAS standard library
export function writeReport(p: string) {
fs.writeText(p, formatYen(1200));
}
// src/util.ras
export function formatYen(n: int): string {
return format(n, "#,##0") + " yen";
}
Modules of the RAS standard library are imported like import * as fs from "fs" (path, csv, json, xml) and import { Dialog } from "dialog". Extension methods for Range, sheets, workbooks, strings, and arrays can be used without importing.
ras.toml
[project]
name = "SalesReport"
workbook = "SalesReport.xlsm" # Workbook used for writing and for running without Excel
[build]
opt-level = 1 # 0: no inlining / 1: automatic inlining in loops / 2: aggressive
erl = true # Add line numbers (the .ras location of errors)
[pack]
backup-generations = 5
[sync]
pull-unmanaged = true # On sync and ras pack, convert handwritten VBA in the workbook to RAS and import it
sheet-files = true # On sync, create objects/ files for sheets and ThisWorkbook that have no file
[lint]
stand-in = false # true: always warn about APIs that cannot be used when running without Excel
[test]
include = ["test/**/*.test.ras"]
timeout-ms = 10000
All the settings are in §15.2 of the language specification.
Adding type definitions (types/)
Declare in types/*.d.ras the sheet code names used when workbook is not specified in ras.toml, as well as the types of handwritten VBA and external libraries (types/sheets.d.ras in examples/sales-report). The bundled type definitions are in Type definitions (Excel and VBA).