deimos-lang/src/parser/ast.schema.yaml
2025-09-04 11:08:23 -05:00

138 lines
4.2 KiB
YAML

$schema: https://json-schema.org/draft/2020-12/schema
title: Deimos AST generation spec
type: object
description: Top level is a map of node names in Pascal case (e.g., CompilationUnit) to node definitions.
additionalProperties:
$ref: "#/$defs/NodeDefinition"
$defs:
NodeDefinition:
type: object
additionalProperties: false
description: A definition of a node type.
properties:
children:
type: array
description: Ordered child fields for this node.
items:
$ref: "#/$defs/StructChildDefinition"
rules:
type: array
description: Alternative parse rules that build this node.
items:
$ref: "#/$defs/EnumChildDefinition"
oneOf:
- required:
- "children"
- required:
- "rules"
StructChildDefinition:
description: A definition of a node's child. Either a bare child name (string) in snake case, or an object.
oneOf:
- type: string
description: Shorthand where child name, var, build, and with are inferred from the given snake-case child name.
- $ref: "#/$defs/ChildDefinitionWrapper"
ChildDefinitionWrapper:
type: object
description: Single-key object mapping the child-name to its spec.
minProperties: 1
maxProperties: 1
additionalProperties: false
patternProperties:
"^[a-z][a-z0-9_]*$":
$ref: "#/$defs/ChildDefinition"
ChildDefinition:
type: object
description: One of skip/vec/single child specs.
oneOf:
- $ref: "#/$defs/SkipChildDefinition"
- $ref: "#/$defs/VecChildDefinition"
- $ref: "#/$defs/SingleChildDefinition"
SkipChildDefinition:
type: object
additionalProperties: false
description: A definition for a child rule that does nothing, i.e., is skipped.
properties:
rule:
type: string
skip:
type: boolean # note: must be true
required:
- rule
- skip
VecChildDefinition:
type: object
additionalProperties: false
description: A definition for a child rule that can be matched multiple times.
properties:
rule:
type: string
vec:
type: boolean
required:
- rule
- vec
SingleChildDefinition:
type: object
additionalProperties: false
description: A definition for a child rule that builds one item.
properties:
rule:
type: string
description: The type to build, in Pascal case.
optional:
type: boolean
description: If true, this child will be stored as an Option.
build:
oneOf:
- type: string
- $ref: "#/$defs/SingleChildBuildDefinition"
SingleChildBuildDefinition:
type: object
additionalProperties: false
description: A definition of what exactly to build for a given child rule.
oneOf:
- $ref: "#/$defs/BuildSingleTypeChild"
- $ref: "#/$defs/BuildBooleanChild"
BuildSingleTypeChild:
type: object
additionalProperties: false
description: A definition of a single-type child to build.
properties:
or_else:
type: string
description: The method name to call upon the built-type if the rule is not found. Takes precedence over "or_else_default".
or_else_default:
type: boolean
description: Whether to call the default method on the built-type if the rule is not found.
BuildBooleanChild:
type: object
additionalProperties: false
description: A definition for building a boolean child.
properties:
type:
type: string
enum:
- boolean
on:
type: string
enum:
- rule_present
EnumChildDefinition:
description: A definition of an enum node's child. Either a bare rule (string) in Pascal case, or an object.
oneOf:
- type: string
description: Shorthand where child name, var, build, and with are inferred from the given Pascal-case rule name.
- $ref: "#/$defs/LongEnumChildDefinition"
LongEnumChildDefinition:
type: object
additionalProperties: false
description: A format for specifying more specific information for an enum child.
properties:
rule:
type: string
build:
type: string
required:
- rule
- build