7 Implementing persistence and transportation of ASTs

 

This chapter covers

  • Implementing a simple web backend with a REST API to persist an AST
  • Serializing an AST to JSON
  • Deserializing an AST from its serialized JSON form
  • Fixing the reference problem we encountered in chapters 5 and 6

In chapters 4 through 6, you learned how to create a projectional editor that allows domain experts to edit DSL content that’s internally represented as an AST. We haven’t implemented any persistence for that DSL content so far. The AST that our editor works on only exists on the frontend. It’s constructed in-memory by code that’s part of the bundled frontend code. When the AST is altered, the changes aren’t stored.

In this chapter, we’re going to implement AST persistence as illustrated in figure 7.1. First, we’re going to implement an extremely simple REST web backend, which will store one JSON file on disk. (The implementation will be as simple as possible—maybe even naive.) This might seem limiting, but it will suffice for our purposes, and it will keep things simple. Frontends can GET this JSON file and also PUT a new version of it, which replaces the previous version on disk.

Figure 7.1 Architecture of the frontend and backend for implementing AST persistence
figure

7.1 Implementing and using a simple backend

7.2 Serializing an AST

7.3 Deserializing an AST

7.4 Making an AST observable during deserialization

7.5 Implementing save functionality

Summary

sitemap