Search code examples
rascal

Save/load AST and M3 from/to file


Creating an AST, or a M3 can take some time depending on the size of the project you are trying to load. So is there a way to store the AST or M3 in a file? So next time you need it, you don't have to create it again since you can just load the complete thing from a file.


Solution

  • You can read and write any value from/to disk using ValueIO, like so:

    rascal>writeBinaryValueFile(|home:///myFile.txt|, myValue)
    ok
    rascal>readBinaryValueFile(#myType, |home:///myFile.txt|)
    myType: myValue
    

    Or in a more readable textual format:

    rascal>writeTextValueFile(|home:///myFile.txt|, myValue)
    ok
    rascal>readTextValueFile(#myType, |home:///myFile.txt|)
    myType: myValue
    

    There also exist JSON and CSV (de)serializers for other formats, to be found in lang::json::IO and lang::csv::IO