diff --git a/src/parser/ast.schema.yaml b/src/parser/ast.schema.yaml index d8081f7..8f794b5 100644 --- a/src/parser/ast.schema.yaml +++ b/src/parser/ast.schema.yaml @@ -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 \ No newline at end of file diff --git a/src/parser/ast.yaml b/src/parser/ast.yaml index 4ce0f2a..6854b31 100644 --- a/src/parser/ast.yaml +++ b/src/parser/ast.yaml @@ -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 diff --git a/src/parser/deimos.pest b/src/parser/deimos.pest index 2022614..be03141 100644 --- a/src/parser/deimos.pest +++ b/src/parser/deimos.pest @@ -823,11 +823,7 @@ IntLiteral = { NumberBase } LongLiteral = ${ NumberBase ~ "L" } -DoubleLiteral = ${ DoubleWhole ~ "." ~ DoubleFractional } - -DoubleWhole = { DecimalBase } - -DoubleFractional = { DecimalBase } +DoubleLiteral = @{ DecimalBase ~ "." ~ DecimalBase} NumberBase = { BinaryBase