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/EnumNodeDefinition"
- $ref: "#/$defs/LeafEnumNodeDefinition" - $ref: "#/$defs/LeafEnumNodeDefinition"
- $ref: "#/$defs/ProductionDefinition" - $ref: "#/$defs/ProductionDefinition"
- $ref: "#/$defs/NodeProductionDefinition"
- $ref: "#/$defs/PolymorphicTypeDefinition"
- $ref: "#/$defs/PolymorphicBuildDefinition" # deprecated
- $ref: "#/$defs/PolymorphicEnumLoopBuildDefinition"
# Four main types of nodes # Struct
StructNodeDefinition: StructNodeDefinition:
type: object
additionalProperties: false
properties:
struct:
$ref: "#/$defs/StructProps"
required:
- struct
StructProps:
type: object type: object
additionalProperties: false additionalProperties: false
description: A description of a Struct node to be built. description: A description of a Struct node to be built.
@ -44,56 +56,18 @@ $defs:
type: array type: array
description: Ordered child fields for this node. description: Ordered child fields for this node.
items: items:
$ref: "#/$defs/StructChildDefinition" $ref: "#/$defs/StructChild"
required: required:
- children - children
LeafStructNodeDefinition: StructChild:
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:
description: | description: |
A definition of a Struct node's child. Either a bare child name (string) in snake case, or an object. The former 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 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. further customization of the built child.
oneOf: oneOf:
- type: string - type: string
- $ref: "#/$defs/StructChildDefinitionWrapper" - $ref: "#/$defs/StructChildHash"
StructChildDefinitionWrapper: StructChildHash:
type: object type: object
description: Single-key object mapping the child-name to its advanced definition. description: Single-key object mapping the child-name to its advanced definition.
minProperties: 1 minProperties: 1
@ -101,28 +75,38 @@ $defs:
additionalProperties: false additionalProperties: false
patternProperties: patternProperties:
"^[a-z][a-z0-9_]*$": "^[a-z][a-z0-9_]*$":
$ref: "#/$defs/StructChildAdvancedDefinition" $ref: "#/$defs/StructChildProps"
StructChildAdvancedDefinition: StructChildProps:
type: object type: object
description: One of skip/vec/single child specs. description: One of skip/vec/single child specs.
oneOf: oneOf:
- $ref: "#/$defs/StructChildSkipChildDefinition" - $ref: "#/$defs/StructChildSkipHash"
- $ref: "#/$defs/StructChildVecChildDefinition" - $ref: "#/$defs/StructChildVecHash"
- $ref: "#/$defs/StructChildMemberDefinition" - $ref: "#/$defs/StructChildMemberHash"
StructChildSkipChildDefinition: StructChildSkipHash:
type: object
additionalProperties: false
properties:
skip:
$ref: "#/$defs/StructChildSkipProps"
required:
- skip
StructChildSkipProps:
type: object type: object
additionalProperties: false additionalProperties: false
description: A definition for a child rule that does nothing, i.e., is skipped. description: A definition for a child rule that does nothing, i.e., is skipped.
properties: properties:
rule: rule:
type: string type: string
skip:
type: boolean
const: true
required: required:
- rule - rule
- skip StructChildVecHash:
StructChildVecChildDefinition: type: object
additionalProperties: false
properties:
vec:
$ref: "#/$defs/StructChildVecProps"
StructChildVecProps:
type: object type: object
additionalProperties: false additionalProperties: false
description: A definition for a child rule that can be matched multiple times. description: A definition for a child rule that can be matched multiple times.
@ -131,16 +115,17 @@ $defs:
type: string type: string
kind: kind:
type: string type: string
enum:
- node # default
- string
vec:
type: boolean
const: true
required: required:
- rule - rule
- vec StructChildMemberHash:
StructChildMemberDefinition: type: object
additionalProperties: false
properties:
member:
$ref: "#/$defs/StructChildMemberProps"
required:
- member
StructChildMemberProps:
type: object type: object
additionalProperties: false additionalProperties: false
properties: properties:
@ -151,18 +136,71 @@ $defs:
type: boolean type: boolean
description: If true, this child will be stored as an Option. description: If true, this child will be stored as an Option.
build: build:
oneOf: $ref: "#/$defs/StructChildMemberBuildProps"
- type: string StructChildMemberBuildProps:
- $ref: "#/$defs/StructChildMemberBuildDefinition"
StructChildMemberBuildDefinition:
type: object type: object
additionalProperties: false additionalProperties: false
description: A definition of what exactly to build for a given child rule.
oneOf: oneOf:
- $ref: "#/$defs/BuildNode" - $ref: "#/$defs/StructChildMemberBuildNodeHash"
- $ref: "#/$defs/BuildBoolean" - $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: LeafStructMemberDefinition:
type: object type: object
description: Single-key object mapping the member-name to what is to be built by parsing the Parser Pair. 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: patternProperties:
"^[a-z][a-z0-9_]*$": "^[a-z][a-z0-9_]*$":
oneOf: oneOf:
- $ref: "#/$defs/BuildMember" - $ref: "#/$defs/LeafStructBuildMember"
BuildMember: LeafStructBuildMember:
type: object type: object
description: A specification for a member to build. description: A specification for a member to build.
additionalProperties: false additionalProperties: false
@ -188,7 +226,25 @@ $defs:
- kind - kind
- from - 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: EnumChildDefinition:
oneOf: oneOf:
- type: string - type: string
@ -201,20 +257,266 @@ $defs:
additionalProperties: false additionalProperties: false
patternProperties: patternProperties:
"^([A-Z][a-z]*)*$": "^([A-Z][a-z]*)*$":
type: string properties:
enum: child:
- int type: boolean
- long kind:
- double enum:
- usize - int
- string - long
- boolean - 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: ProductionDefinition:
type: object type: object
properties: properties:
produce: production:
type: object type: object
properties: properties:
kind: kind:
@ -229,28 +531,26 @@ $defs:
- string_inner - string_inner
- whole_pair - whole_pair
- parse_whole_pair - parse_whole_pair
required:
- kind
required:
- production
# Common things to build # Node Production
BuildNode: NodeProductionDefinition:
type: object type: object
additionalProperties: false additionalProperties: false
description: A definition of a single-type child to build.
properties: properties:
or_else: node_production:
type: string type: object
description: The method name to call upon the built-type if the rule is not found. Takes precedence over "or_else_default". additionalProperties: false
or_else_default: properties:
type: boolean kind:
description: Whether to call the default method on the built-type if the rule is not found. type: string
BuildBoolean: with:
type: object type: string
additionalProperties: false required:
description: A boolean member to be built. - kind
properties: - with
kind: required:
type: string - node_production
const: boolean
on:
type: string
enum:
- rule_present

File diff suppressed because it is too large Load Diff

View File

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