2

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.

Nicasso
  • 265
  • 1
  • 7

1 Answers1

1

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

Klesun
  • 12,280
  • 5
  • 59
  • 52
Jurgen Vinju
  • 6,393
  • 1
  • 15
  • 26
  • Where can we find the reference on `|home:///myFile.txt|` format? Particularly, how to pass a path relative to current (project) directory? `home:///` seems to literaly mean OS home directory. `file:///` seems to mean an absolute path... – Klesun Oct 23 '20 at 09:13
  • @Klesun in Eclipse you can use `project://name/file` – Jurgen Vinju Oct 23 '20 at 11:50
  • Hm, thanks, now I noticed the "search path" in the eclipse project tree which hints that `project://` points to the directory one level above the project directory. – Klesun Oct 23 '20 at 12:12
  • Hmm. Not quite. The name of the project is the authority of the uri and the path relative to the project is the path part of the URI, so the project URI without an authority does not resolve to the workspace – Jurgen Vinju Oct 23 '20 at 12:19