567 lines
15 KiB
YAML
567 lines
15 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:
|
|
# Top level
|
|
NodeDefinition:
|
|
type: object
|
|
additionalProperties: false
|
|
description: |
|
|
A definition of a node type. The main key in this hash determines the type of node: `children` for Struct node,
|
|
`members` for Leaf-Struct node, `rules` for Enum node, `leaf_rules` for Leaf-Enum node, and `produce` for a
|
|
translate rule.
|
|
|
|
A Struct node has child nodes and other properties, and is built by looping through all the inner pairs of the
|
|
given Parser Pair.
|
|
|
|
A Leaf-Struct node does not have child nodes, but does have members. The members are built by some kind of parsing
|
|
of the string value of the the given Parser Pair (i.e., no looping through inner pairs).
|
|
|
|
An Enum node maps Parser Rules to an enum of node types. Each enum member may have a child, or not. By default, a
|
|
Rule name maps to the node type-name of a single child.
|
|
|
|
A Leaf-Enum node is like a regular enum node, but no children are allowed. Rather, the Parser Rule maps to a bare
|
|
enum member.
|
|
|
|
A translate rule simply translates the Parser rule into some kind of arbitrary type, such as a string, int, etc.
|
|
oneOf:
|
|
- $ref: "#/$defs/StructNodeDefinition"
|
|
- $ref: "#/$defs/LeafStructNodeDefinition"
|
|
- $ref: "#/$defs/EnumNodeDefinition"
|
|
- $ref: "#/$defs/LeafEnumNodeDefinition"
|
|
- $ref: "#/$defs/ProductionDefinition"
|
|
- $ref: "#/$defs/NodeProductionDefinition"
|
|
- $ref: "#/$defs/PolymorphicTypeDefinition"
|
|
- $ref: "#/$defs/PolymorphicEnumLoopBuildDefinition"
|
|
- $ref: "#/$defs/PolymorphicPassThroughDefinition"
|
|
|
|
# Struct
|
|
StructNodeDefinition:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
struct:
|
|
$ref: "#/$defs/StructProps"
|
|
required:
|
|
- struct
|
|
StructProps:
|
|
type: object
|
|
additionalProperties: false
|
|
description: A description of a Struct node to be built.
|
|
properties:
|
|
children:
|
|
type: array
|
|
description: Ordered child fields for this node.
|
|
items:
|
|
$ref: "#/$defs/StructChild"
|
|
derive:
|
|
type: array
|
|
description: Traits to derive.
|
|
items:
|
|
type: string
|
|
required:
|
|
- children
|
|
StructChild:
|
|
description: |
|
|
A definition of a Struct node's child. Either a bare child name (string) in snake case, or an object. The former
|
|
is a shorthand where the child name and built type are the same; casing is automatically done. The latter allows
|
|
further customization of the built child.
|
|
oneOf:
|
|
- type: string
|
|
- $ref: "#/$defs/StructChildHash"
|
|
StructChildHash:
|
|
type: object
|
|
description: Single-key object mapping the child-name to its advanced definition.
|
|
minProperties: 1
|
|
maxProperties: 1
|
|
additionalProperties: false
|
|
patternProperties:
|
|
"^[a-z][a-z0-9_]*$":
|
|
$ref: "#/$defs/StructChildProps"
|
|
StructChildProps:
|
|
type: object
|
|
description: One of skip/vec/single child specs.
|
|
oneOf:
|
|
- $ref: "#/$defs/StructChildSkipHash"
|
|
- $ref: "#/$defs/StructChildVecHash"
|
|
- $ref: "#/$defs/StructChildMemberHash"
|
|
StructChildSkipHash:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
skip:
|
|
$ref: "#/$defs/StructChildSkipProps"
|
|
required:
|
|
- skip
|
|
StructChildSkipProps:
|
|
type: object
|
|
additionalProperties: false
|
|
description: A definition for a child rule that does nothing, i.e., is skipped.
|
|
properties:
|
|
rule:
|
|
type: string
|
|
required:
|
|
- rule
|
|
StructChildVecHash:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
vec:
|
|
$ref: "#/$defs/StructChildVecProps"
|
|
StructChildVecProps:
|
|
type: object
|
|
additionalProperties: false
|
|
description: A definition for a child rule that can be matched multiple times.
|
|
properties:
|
|
rule:
|
|
type: string
|
|
kind:
|
|
type: string
|
|
required:
|
|
- rule
|
|
StructChildMemberHash:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
member:
|
|
$ref: "#/$defs/StructChildMemberProps"
|
|
required:
|
|
- member
|
|
StructChildMemberProps:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
rule:
|
|
type: string
|
|
description: The rule to match.
|
|
optional:
|
|
type: boolean
|
|
description: If true, this child will be stored as an Option.
|
|
build:
|
|
$ref: "#/$defs/StructChildMemberBuildProps"
|
|
StructChildMemberBuildProps:
|
|
type: object
|
|
additionalProperties: false
|
|
oneOf:
|
|
- $ref: "#/$defs/StructChildMemberBuildNodeHash"
|
|
- $ref: "#/$defs/StructChildMemberBuildBooleanHash"
|
|
StructChildMemberBuildNodeHash:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
node:
|
|
$ref: "#/$defs/StructChildMemberBuildNodeProps"
|
|
required:
|
|
- node
|
|
StructChildMemberBuildNodeProps:
|
|
type: object
|
|
additionalProperties: false
|
|
description: A definition of a single-type child to build.
|
|
properties:
|
|
kind:
|
|
type: string
|
|
with:
|
|
type: string
|
|
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.
|
|
StructChildMemberBuildBooleanHash:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
boolean:
|
|
$ref: "#/$defs/StructChildMemberBuildBooleanProps"
|
|
required:
|
|
- boolean
|
|
StructChildMemberBuildBooleanProps:
|
|
type: object
|
|
additionalProperties: false
|
|
description: A boolean member to be built.
|
|
properties:
|
|
on:
|
|
type: string
|
|
enum:
|
|
- rule_present
|
|
required:
|
|
- on
|
|
|
|
# Leaf Struct Node
|
|
LeafStructNodeDefinition:
|
|
type: object
|
|
additionalProperties: false
|
|
description: A description of a Leaf-Struct node to be built.
|
|
properties:
|
|
leaf_struct:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
members:
|
|
type: array
|
|
description: Ordered members for this node.
|
|
items:
|
|
$ref: "#/$defs/LeafStructMemberDefinition"
|
|
derive:
|
|
type: array
|
|
description: Traits to derive.
|
|
items:
|
|
type: string
|
|
required:
|
|
- members
|
|
required:
|
|
- leaf_struct
|
|
LeafStructMemberDefinition:
|
|
type: object
|
|
description: Single-key object mapping the member-name to what is to be built by parsing the Parser Pair.
|
|
minProperties: 1
|
|
maxProperties: 1
|
|
additionalProperties: false
|
|
patternProperties:
|
|
"^[a-z][a-z0-9_]*$":
|
|
oneOf:
|
|
- $ref: "#/$defs/LeafStructBuildMember"
|
|
LeafStructBuildMember:
|
|
type: object
|
|
description: A specification for a member to build.
|
|
additionalProperties: false
|
|
properties:
|
|
kind:
|
|
enum:
|
|
- string
|
|
- file_id
|
|
- range
|
|
required:
|
|
- kind
|
|
|
|
# Enum node
|
|
EnumNodeDefinition:
|
|
type: object
|
|
additionalProperties: false
|
|
description: A description of an Enum node to be built.
|
|
properties:
|
|
tree_enum:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
rules:
|
|
type: array
|
|
description: Alternative parse rules that build this node.
|
|
items:
|
|
$ref: "#/$defs/EnumChildDefinition"
|
|
required:
|
|
- rules
|
|
required:
|
|
- tree_enum
|
|
EnumChildDefinition:
|
|
oneOf:
|
|
- type: string
|
|
description: Shorthand where child name, var, build, and with are inferred from the given Pascal-case rule name.
|
|
- $ref: "#/$defs/LongEnumChildWrapper"
|
|
LongEnumChildWrapper:
|
|
type: object
|
|
minProperties: 1
|
|
maxProperties: 1
|
|
additionalProperties: false
|
|
patternProperties:
|
|
"^([A-Z][a-z]*)*$":
|
|
properties:
|
|
child:
|
|
type: boolean
|
|
kind:
|
|
enum:
|
|
- int
|
|
- long
|
|
- double
|
|
- string
|
|
- boolean
|
|
|
|
# Leaf Enum
|
|
LeafEnumNodeDefinition:
|
|
type: object
|
|
additionalProperties: false
|
|
description: A description of a leaf-enum node to be built.
|
|
properties:
|
|
leaf_enum:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
rules:
|
|
type: array
|
|
description: Alternative parse rules that build this node.
|
|
items:
|
|
type: string
|
|
required:
|
|
- rules
|
|
required:
|
|
- leaf_enum
|
|
|
|
# Polymorphic Type
|
|
PolymorphicTypeDefinition:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
polymorphic_type:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
variants:
|
|
type: array
|
|
items:
|
|
$ref: "#/$defs/PolymorphicTypeVariantHash"
|
|
build:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
kind:
|
|
type: string
|
|
required:
|
|
- kind
|
|
required:
|
|
- variants
|
|
- build
|
|
required:
|
|
- polymorphic_type
|
|
PolymorphicTypeVariantHash:
|
|
type: object
|
|
additionalProperties: false
|
|
minProperties: 1
|
|
maxProperties: 1
|
|
patternProperties:
|
|
"^([A-Z][a-z]*)*$":
|
|
properties:
|
|
inner:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
kind:
|
|
type: string
|
|
required:
|
|
- kind
|
|
|
|
# Polymorphic Enum Loop Build
|
|
PolymorphicEnumLoopBuildDefinition:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
polymorphic_enum_loop_build:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
kind:
|
|
type: string
|
|
reverse:
|
|
type: boolean
|
|
rules:
|
|
type: array
|
|
items:
|
|
$ref: "#/$defs/PolymorphicEnumLoopBuildRule"
|
|
required:
|
|
- kind
|
|
- rules
|
|
required:
|
|
- polymorphic_enum_loop_build
|
|
PolymorphicEnumLoopBuildRule:
|
|
type: object
|
|
additionalProperties: false
|
|
minProperties: 1
|
|
maxProperties: 1
|
|
patternProperties:
|
|
"^([A-Z][a-z]*)*$":
|
|
type: object
|
|
oneOf:
|
|
- $ref: "#/$defs/PolymorphicEnumLoopBuildPassThrough"
|
|
- $ref: "#/$defs/PolymorphicEnumLoopBuildBuild"
|
|
PolymorphicEnumLoopBuildPassThrough:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
pass_through:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
kind:
|
|
type: string
|
|
with:
|
|
type: string
|
|
required:
|
|
- kind
|
|
- with
|
|
required:
|
|
- pass_through
|
|
PolymorphicEnumLoopBuildBuild:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
build:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
variant:
|
|
type: string
|
|
children:
|
|
type: array
|
|
items:
|
|
$ref: "#/$defs/PolymorphicEnumLoopBuildBuildChild"
|
|
required:
|
|
- variant
|
|
- children
|
|
required:
|
|
- build
|
|
PolymorphicEnumLoopBuildBuildChild:
|
|
type: object
|
|
additionalProperties: false
|
|
minProperties: 1
|
|
maxProperties: 1
|
|
patternProperties:
|
|
"^[a-z][a-z_]*$":
|
|
type: object
|
|
oneOf:
|
|
- $ref: "#/$defs/PolymorphicEnumLoopBuildBuildUseCurrent"
|
|
- $ref: "#/$defs/PolymorphicEnumLoopBuildBuildOnEach"
|
|
PolymorphicEnumLoopBuildBuildUseCurrent:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
use_current:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
kind:
|
|
type: string
|
|
required:
|
|
- kind
|
|
required:
|
|
- use_current
|
|
PolymorphicEnumLoopBuildBuildOnEach:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
on_each:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
rule:
|
|
type: string
|
|
required:
|
|
- rule
|
|
required:
|
|
- on_each
|
|
|
|
# Polymorphic Pass Through
|
|
PolymorphicPassThroughDefinition:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
polymorphic_pass_through:
|
|
$ref: "#/$defs/PolymorphicPassThroughProps"
|
|
required:
|
|
- polymorphic_pass_through
|
|
PolymorphicPassThroughProps:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
build:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
kind:
|
|
type: string
|
|
required:
|
|
- kind
|
|
variants:
|
|
type: array
|
|
items:
|
|
$ref: "#/$defs/PolymorphicPassThroughVariantHash"
|
|
required:
|
|
- build
|
|
- variants
|
|
PolymorphicPassThroughVariantHash:
|
|
type: object
|
|
additionalProperties: false
|
|
minProperties: 1
|
|
maxProperties: 1
|
|
patternProperties:
|
|
"^([A-Z][a-z]*)*$":
|
|
$ref: "#/$defs/PolymorphicPassThroughVariantProps"
|
|
PolymorphicPassThroughVariantProps:
|
|
type: object
|
|
additionalProperties: false
|
|
oneOf:
|
|
- $ref: "#/$defs/PolymorphicPassThroughVariantInner"
|
|
- $ref: "#/$defs/PolymorphicPassThroughVariantPassThrough"
|
|
PolymorphicPassThroughVariantInner:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
inner:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
kind:
|
|
type: string
|
|
required:
|
|
- kind
|
|
required:
|
|
- inner
|
|
PolymorphicPassThroughVariantPassThrough:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
pass_through:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
kind:
|
|
type: string
|
|
required:
|
|
- kind
|
|
required:
|
|
- pass_through
|
|
|
|
# Production
|
|
ProductionDefinition:
|
|
type: object
|
|
properties:
|
|
production:
|
|
type: object
|
|
properties:
|
|
kind:
|
|
enum:
|
|
- int
|
|
- long
|
|
- double
|
|
- string
|
|
- boolean
|
|
from:
|
|
enum:
|
|
- string_inner
|
|
- whole_pair
|
|
- parse_whole_pair
|
|
required:
|
|
- kind
|
|
required:
|
|
- production
|
|
|
|
# Node Production
|
|
NodeProductionDefinition:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
node_production:
|
|
type: object
|
|
additionalProperties: false
|
|
properties:
|
|
kind:
|
|
type: string
|
|
with:
|
|
type: string
|
|
required:
|
|
- kind
|
|
- with
|
|
required:
|
|
- node_production |