Add schema and function declaration.

This commit is contained in:
Jesse Brault 2025-08-29 20:24:35 -05:00
parent 8b310ad5d4
commit 673a008e16
2 changed files with 142 additions and 0 deletions

123
src/parser/ast.schema.yaml Normal file
View File

@ -0,0 +1,123 @@
$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
build:
oneOf:
- type: string
- $ref: "#/$defs/SingleChildBuildDefinition"
required:
- rule
SingleChildBuildDefinition:
type: object
additionalProperties: false
description: A definition of what exactly to build for a given child rule.
oneOf:
- $ref: "#/$defs/BuildBooleanChild"
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

View File

@ -63,3 +63,22 @@ Class:
- class_level_declarations:
rule: ClassLevelDeclaration
vec: true
FunctionDeclaration:
children:
- is_public:
rule: Pub
build:
type: boolean
on: rule_present
- modifier:
rule: Modifier
build: FunctionModifier
- fn_kw:
rule: Fn
skip: true
- generics:
rule: GenericParameters
- identifier
- parameters
- return_type
- function_body