Updates to ast and schema.

This commit is contained in:
Jesse Brault 2025-09-20 17:50:51 -05:00
parent fe2fff5882
commit dad25dcbf2
3 changed files with 1414 additions and 952 deletions

View File

@ -33,9 +33,21 @@ $defs:
- $ref: "#/$defs/EnumNodeDefinition"
- $ref: "#/$defs/LeafEnumNodeDefinition"
- $ref: "#/$defs/ProductionDefinition"
- $ref: "#/$defs/NodeProductionDefinition"
- $ref: "#/$defs/PolymorphicTypeDefinition"
- $ref: "#/$defs/PolymorphicBuildDefinition" # deprecated
- $ref: "#/$defs/PolymorphicEnumLoopBuildDefinition"
# Four main types of nodes
# 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.
@ -44,56 +56,18 @@ $defs:
type: array
description: Ordered child fields for this node.
items:
$ref: "#/$defs/StructChildDefinition"
$ref: "#/$defs/StructChild"
required:
- children
LeafStructNodeDefinition:
type: object
additionalProperties: false
description: A description of a Leaf-Struct node to be built.
properties:
members:
type: array
description: Ordered members for this node.
items:
$ref: "#/$defs/LeafStructMemberDefinition"
required:
- members
EnumNodeDefinition:
type: object
additionalProperties: false
description: A description of an Enum node to be built.
properties:
rules:
type: array
description: Alternative parse rules that build this node.
items:
$ref: "#/$defs/EnumChildDefinition"
required:
- rules
LeafEnumNodeDefinition:
type: object
additionalProperties: false
description: A description of a leaf-enum node to be built.
properties:
leaf_rules:
type: array
description: Alternative parse rules that build this node.
items:
type: string
required:
- leaf_rules
# Struct node children
StructChildDefinition:
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/StructChildDefinitionWrapper"
StructChildDefinitionWrapper:
- $ref: "#/$defs/StructChildHash"
StructChildHash:
type: object
description: Single-key object mapping the child-name to its advanced definition.
minProperties: 1
@ -101,28 +75,38 @@ $defs:
additionalProperties: false
patternProperties:
"^[a-z][a-z0-9_]*$":
$ref: "#/$defs/StructChildAdvancedDefinition"
StructChildAdvancedDefinition:
$ref: "#/$defs/StructChildProps"
StructChildProps:
type: object
description: One of skip/vec/single child specs.
oneOf:
- $ref: "#/$defs/StructChildSkipChildDefinition"
- $ref: "#/$defs/StructChildVecChildDefinition"
- $ref: "#/$defs/StructChildMemberDefinition"
StructChildSkipChildDefinition:
- $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
skip:
type: boolean
const: true
required:
- rule
- skip
StructChildVecChildDefinition:
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.
@ -131,16 +115,17 @@ $defs:
type: string
kind:
type: string
enum:
- node # default
- string
vec:
type: boolean
const: true
required:
- rule
- vec
StructChildMemberDefinition:
StructChildMemberHash:
type: object
additionalProperties: false
properties:
member:
$ref: "#/$defs/StructChildMemberProps"
required:
- member
StructChildMemberProps:
type: object
additionalProperties: false
properties:
@ -151,18 +136,71 @@ $defs:
type: boolean
description: If true, this child will be stored as an Option.
build:
oneOf:
- type: string
- $ref: "#/$defs/StructChildMemberBuildDefinition"
StructChildMemberBuildDefinition:
$ref: "#/$defs/StructChildMemberBuildProps"
StructChildMemberBuildProps:
type: object
additionalProperties: false
description: A definition of what exactly to build for a given child rule.
oneOf:
- $ref: "#/$defs/BuildNode"
- $ref: "#/$defs/BuildBoolean"
- $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"
StructChildMemberBuildBooleanProps:
type: object
additionalProperties: false
description: A boolean member to be built.
properties:
on:
type: string
enum:
- rule_present
# Leaf Struct children
# 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"
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.
@ -172,8 +210,8 @@ $defs:
patternProperties:
"^[a-z][a-z0-9_]*$":
oneOf:
- $ref: "#/$defs/BuildMember"
BuildMember:
- $ref: "#/$defs/LeafStructBuildMember"
LeafStructBuildMember:
type: object
description: A specification for a member to build.
additionalProperties: false
@ -188,7 +226,25 @@ $defs:
- kind
- from
# Enum children
# 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
@ -201,20 +257,266 @@ $defs:
additionalProperties: false
patternProperties:
"^([A-Z][a-z]*)*$":
type: string
enum:
- int
- long
- double
- usize
- string
- boolean
properties:
child:
type: boolean
kind:
enum:
- int
- long
- double
- string
- boolean
# Production definition
# 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 Build
PolymorphicBuildDefinition:
type: object
additionalProperties: false
properties:
polymorphic_build:
type: object
$ref: "#/$defs/PolymorphicBuildProps"
required:
- polymorphic_build
PolymorphicBuildProps:
type: object
additionalProperties: false
properties:
return_type:
type: string
alternatives:
type: array
items:
$ref: "#/$defs/PolymorphicBuildAlternative"
required:
- return_type
- alternatives
PolymorphicBuildAlternative:
type: object
additionalProperties: false
properties:
test:
type: object
additionalProperties: false
properties:
number_of_pairs:
type: string
required:
- number_of_pairs
action:
type: object
additionalProperties: false
oneOf:
- $ref: "#/$defs/PolymorphicBuildAlternativeBuild"
- $ref: "#/$defs/PolymorphicBuildAlternativeReturnBuild"
required:
- test
- action
PolymorphicBuildAlternativeBuild:
type: object
additionalProperties: false
properties:
build:
type: object
properties:
enum_variant:
type: string
children:
type: array
items:
$ref: "#/$defs/StructChildHash"
required:
- build
PolymorphicBuildAlternativeReturnBuild:
type: object
additionalProperties: false
properties:
return_build:
type: object
additionalProperties: false
properties:
kind:
type: string
required:
- kind
required:
- return_build
# Polymorphic Enum Loop Build
PolymorphicEnumLoopBuildDefinition:
type: object
additionalProperties: false
properties:
polymorphic_enum_loop_build:
type: object
additionalProperties: false
properties:
kind:
type: string
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
# Production
ProductionDefinition:
type: object
properties:
produce:
production:
type: object
properties:
kind:
@ -229,28 +531,26 @@ $defs:
- string_inner
- whole_pair
- parse_whole_pair
required:
- kind
required:
- production
# Common things to build
BuildNode:
# Node Production
NodeProductionDefinition:
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.
BuildBoolean:
type: object
additionalProperties: false
description: A boolean member to be built.
properties:
kind:
type: string
const: boolean
on:
type: string
enum:
- rule_present
node_production:
type: object
additionalProperties: false
properties:
kind:
type: string
with:
type: string
required:
- kind
- with
required:
- node_production

File diff suppressed because it is too large Load Diff

View File

@ -641,7 +641,7 @@ ComparisonExpression = {
ComparisonRhs = {
ComparisonOperator
~ Expression
~ ShiftExpression
}
ComparisonOperator = {
@ -700,14 +700,10 @@ MultiplicativeOperator = {
}
PrefixExpression = {
PrefixOperators?
PrefixOperator*
~ SuffixExpression
}
PrefixOperators = {
PrefixOperator+
}
PrefixOperator = {
Spread
| Not
@ -716,11 +712,7 @@ PrefixOperator = {
SuffixExpression = {
PrimaryExpression
~ SuffixOperators?
}
SuffixOperators = {
SuffixOperator+
~ SuffixOperator*
}
SuffixOperator = {