Skip to main content
Version: Next

Code Generation

Add Dependencies

repositories {
mavenLocal()
mavenCentral()
flatDir {
dirs("deps")
}
}

dependencies {
implementation(files("deps/sas-code-generator-with-dependencies-1.7.0-all.jar"))
}

Output code

The SAS parser has a module that allows to output code, i.e., to format an AST and create the corresponding text. This module is in an early stage of development. All you need to do is to pass an AST to the method printToString and you will the textual representation of the code. You might want to use it to format some code or to generate a code file from an AST that you created.

import com.strumenta.kolasu.traversing.walk
import com.strumenta.sas.ast.SourceFile
import com.strumenta.kolasu.commercial.LicenseManager
import com.strumenta.sas.parser.SASLanguage
import java.io.File
import com.strumenta.sas.generator.SASPrinter

fun formatAst((sasFile: File, license: File)) {
LicenseManager.registerLicense(File("licenses/strumenta.SAS.license"))
val sas = SASLanguage()
sas.parseNativeSQL = true
sas.parseComments = true
val result = sas.parse(File("example.sas"))
val root = result.root
val formattedCode = sasPrinter.printToString(result.root!!)
}