An encoded abstract syntax tree is an in-memory JavaScript object that represents abstract syntax tree concepts and settings. Software can inspect, alter, and traverse this representation, making it suitable for the Domain IDE codebase. section 3.0
An AST object contains a concept and settings. Settings may hold strings, arrays, or reference objects whose ref property points to another encoded AST object. section 3.2.2
Recognize encoded AST values by testing their JavaScript shape:
- Use typeof together with a truthiness check and !Array.isArray(value) to identify ordinary objects. section 3.2.2
- Identify AST objects by requiring concept and settings properties. section 3.2.2
- Identify reference objects through ref, then confirm that ref targets an AST object. section 3.2.2
Recognizing a rental AST
For a rental object, typeof returns object; its attributes setting is an array; and its individual attribute entries can satisfy isAstObject. An attribute reference satisfies isAstReference when its ref target is an AST object. section 3.2.2
Listing 3.8 Initial contents of the src/common/ast.js file
const isObject = (value) => (!!value) && (typeof value === "object")
&& !Array.isArray(value)
const isAstObject = (value) => isObject(value) && ("concept" in value)
&& ("settings" in value)
module.exports.isAstObject = isAstObject #1
const isAstReferenceObject = (value) => isObject(value) && ("ref" in value)
const isAstReference = (value) => isAstReferenceObject(value)
&& isAstObject(value.ref)
module.exports.isAstReference = isAstReference
The implementation listing consolidates the object, AST-object, and AST-reference predicates into the initial ast.js module. section 3.2.2
