Work on ast.schema and related.

This commit is contained in:
Jesse Brault 2025-09-08 11:57:20 -05:00
parent 29a2d77b6f
commit 41693788fc
3 changed files with 126 additions and 19 deletions

View File

@ -9,22 +9,52 @@ $defs:
type: object
additionalProperties: false
description: A definition of a node type.
oneOf:
- $ref: "#/$defs/StructNodeDefinition"
- $ref: "#/$defs/EnumNodeDefinition"
- $ref: "#/$defs/LeafEnumNodeDefinition"
StructNodeDefinition:
type: object
additionalProperties: false
description: A description of a Struct node to be built.
properties:
type:
const: struct
children:
type: array
description: Ordered child fields for this node.
items:
$ref: "#/$defs/StructChildDefinition"
required:
- children
EnumNodeDefinition:
type: object
additionalProperties: false
description: A description of an Enum node to be built.
properties:
type:
const: enum
rules:
type: array
description: Alternative parse rules that build this node.
items:
$ref: "#/$defs/EnumChildDefinition"
oneOf:
- required:
- "children"
- required:
- "rules"
required:
- rules
LeafEnumNodeDefinition:
type: object
additionalProperties: false
description: A description of a leaf-enum node to be built.
properties:
type:
const: leaf_enum
rules:
type: array
description: Alternative parse rules that build this node.
items:
$ref: "#/$defs/LeafEnumChildDefinition"
required:
- type
- rules
StructChildDefinition:
description: A definition of a node's child. Either a bare child name (string) in snake case, or an object.
oneOf:
@ -93,6 +123,10 @@ $defs:
oneOf:
- $ref: "#/$defs/BuildSingleTypeChild"
- $ref: "#/$defs/BuildBooleanChild"
- $ref: "#/$defs/BuildStringChild"
- $ref: "#/$defs/BuildDoubleChild"
- $ref: "#/$defs/BuildIntChild"
- $ref: "#/$defs/BuildLongChild"
BuildSingleTypeChild:
type: object
additionalProperties: false
@ -117,6 +151,54 @@ $defs:
type: string
enum:
- rule_present
from:
type: string
enum:
- parse_whole_pair
BuildStringChild:
type: object
additionalProperties: false
description: A definition for building a string child.
properties:
type:
const: string
from:
type: string
enum:
- whole_pair
BuildDoubleChild:
type: object
additionalProperties: false
description: A definition for building a Double child.
properties:
type:
const: f64
from:
type: string
enum:
- parse_whole_pair
BuildIntChild:
type: object
additionalProperties: false
description: A definition for building an Int child.
properties:
type:
const: i32
from:
type: string
enum:
- parse_number_base
BuildLongChild:
type: object
additionalProperties: false
description: A definition for building a Long child.
properties:
type:
const: i64
from:
type: string
enum:
- parse_number_base
EnumChildDefinition:
description: A definition of an enum node's child. Either a bare rule (string) in Pascal case, or an object.
oneOf:
@ -135,3 +217,28 @@ $defs:
required:
- rule
- build
LeafEnumChildDefinition:
description: A definition of a leaf-enum node's child. Either a bare rule-string in Pascal case, or an object.
oneOf:
- type: string
description: Shorthand where the rule name maps onto an empty enum rule.
- $ref: "#/$defs/LongLeafEnumChildDefinitionWrapper"
LongLeafEnumChildDefinitionWrapper:
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/LongLeafEnumChildDefinition"
LongLeafEnumChildDefinition:
type: object
additionalProperties: false
description: A format for specifying more specific information about a leaf-enum child.
properties:
child:
type: boolean
description: If true, a node of the same name is built as the lone member of the enum child.
required:
- child

View File

@ -622,19 +622,23 @@ NumberLiteral:
IntLiteral:
children:
- number_base
- literal:
build:
type: i32
from: parse_number_base
LongLiteral:
children:
- number_base
- literal:
build:
type: i64
from: parse_number_base
DoubleLiteral:
children:
- double_whole
- double_fractional
DoubleWhole:
children:
- decimal_base
DoubleFractional:
children:
- decimal_base
- literal:
build:
type: f64
from: parse_whole_pair
NumberBase:
rules:
- BinaryBase

View File

@ -823,11 +823,7 @@ IntLiteral = { NumberBase }
LongLiteral = ${ NumberBase ~ "L" }
DoubleLiteral = ${ DoubleWhole ~ "." ~ DoubleFractional }
DoubleWhole = { DecimalBase }
DoubleFractional = { DecimalBase }
DoubleLiteral = @{ DecimalBase ~ "." ~ DecimalBase}
NumberBase = {
BinaryBase