7 Implementing persistence and transportation of ASTs

 

This chapter covers

  • Implementing a simple Web backend with a REST API for basic persistence of 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, we learned how to create a projectional editor for domain experts to visualize and edit DSL content that’s represented as an AST. We didn’t implement 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.

Figure 7.1. Architecture of frontend + backend to implement AST persistence
architecture AST persistence

In this chapter, we’re going to implement AST persistence. First, we’re going to implement an extremely simple REST Web backend, which is going to store one (1!) JSON file on disk. (The implementation will be as simple as possible—maybe even naive.) This might seem limiting, but it suffices for our purposes, and keeps 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.2. What serialization and deserialization do, and how they relate to each other. (Details will be explained later.)
de serialization

7.1 Implementing and using a simple backend

7.2 Serializing an AST

7.3 Deserializing ASTs

7.4 Making an AST observable during deserialization

7.5 Implementing save functionality

7.6 Summary

sitemap