diff --git a/src/parser/ast.schema.yaml b/src/parser/ast.schema.yaml index 36cdc36..cf16fb5 100644 --- a/src/parser/ast.schema.yaml +++ b/src/parser/ast.schema.yaml @@ -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 \ No newline at end of file + node_production: + type: object + additionalProperties: false + properties: + kind: + type: string + with: + type: string + required: + - kind + - with + required: + - node_production \ No newline at end of file diff --git a/src/parser/ast.yaml b/src/parser/ast.yaml index 792c26a..58debfc 100644 --- a/src/parser/ast.yaml +++ b/src/parser/ast.yaml @@ -1,576 +1,688 @@ # $schema: ./ast.schema.yaml # Operators Operator: - leaf_rules: - - Or - - And - - EqualTo - - NotEqualTo - - Greater - - Less - - GreaterEqual - - LessEqual - - Add - - Subtract - - Multiply - - Divide - - Modulo - - LeftShift - - RightShift - - Spread - - Star - - Not - - Negative - - PlusPlus - - MinusMinus - - CallOp - - Index + leaf_enum: + rules: + - Or + - And + - EqualTo + - NotEqualTo + - Greater + - Less + - GreaterEqual + - LessEqual + - Add + - Subtract + - Multiply + - Divide + - Modulo + - LeftShift + - RightShift + - Spread + - Star + - Not + - Negative + - PlusPlus + - MinusMinus + - CallOp + - Index # Names Identifier: - members: - - name: - kind: string - from: whole_pair + leaf_struct: + members: + - name: + kind: string + from: whole_pair FullyQualifiedName: - children: - - identifiers: - rule: Identifier - vec: true + struct: + children: + - identifiers: + vec: + rule: Identifier # Lists TypeUseList: - children: - - type_uses: - rule: TypeUse - vec: true + struct: + children: + - type_uses: + vec: + rule: TypeUse IdentifierList: - children: - - identifiers: - rule: Identifier - vec: true + struct: + children: + - identifiers: + vec: + rule: Identifier ParenthesesOptionalTypeUseList: - children: - - type_use_list: - optional: true + struct: + children: + - type_use_list: + member: + optional: true # Type Use TypeUse: - rules: - - PrimitiveType - - InterfaceOrClassTypeUse - - TupleTypeUse - - FunctionTypeUse + tree_enum: + rules: + - PrimitiveType + - InterfaceOrClassTypeUse + - TupleTypeUse + - FunctionTypeUse PrimitiveType: - leaf_rules: - - Byte - - Short - - Char - - Int - - Long - - Double - - Bool - - String - - TypedArray - - Any - - Void + leaf_enum: + rules: + - Byte + - Short + - Char + - Int + - Long + - Double + - Bool + - String + - TypedArray + - Any + - Void TypedArray: - children: - - array_kw: - rule: Array - skip: true - - generic_arguments + struct: + children: + - array_kw: + skip: + rule: Array + - generic_arguments InterfaceOrClassTypeUse: - children: - - fully_qualified_name - - generic_arguments: - build: - or_else_default: true + struct: + children: + - fully_qualified_name + - generic_arguments: + member: + rule: GenericArguments + build: + node: + or_else_default: true TupleTypeUse: - children: - - tuple_arguments + struct: + children: + - tuple_arguments FunctionTypeUse: - children: - - fn_kw: - rule: Fn - skip: true - - generic_parameters: - build: - or_else_default: true - - parameters: - build: - or_else_default: true - - return_type + struct: + children: + - fn_kw: + skip: + rule: Fn + - generic_parameters: + member: + rule: GenericParameters + build: + node: + or_else_default: true + - parameters: + member: + rule: Parameters + build: + node: + or_else_default: true + - return_type # Generic Arguments GenericArguments: - children: - - type_use_list + struct: + children: + - type_use_list # Generic Parameters GenericParameters: - children: - - identifier_list + struct: + children: + - identifier_list # Tuple Arguments TupleArguments: - children: - - parentheses_optional_type_use_list + struct: + children: + - parentheses_optional_type_use_list # Implements List ImplementsList: - children: - - type_uses: - rule: TypeUse - vec: true + struct: + children: + - type_uses: + vec: + rule: TypeUse # Parameters Parameters: - children: - - parameters: - rule: Parameter - vec: true + struct: + children: + - parameters: + vec: + rule: Parameter Parameter: - children: - - identifier - - type_use + struct: + children: + - identifier + - type_use # Return Type ReturnType: - children: - - type_use + struct: + children: + - type_use # Top-level constructs CompilationUnit: - children: - - parent_mod: - optional: true - - use_statements: - rule: UseStatement - vec: true - - module_level_declarations: - rule: ModuleLevelDeclaration - vec: true - - eoi: - rule: EOI - skip: true + struct: + children: + - parent_mod: + member: + optional: true + - use_statements: + vec: + rule: UseStatement + - module_level_declarations: + vec: + rule: ModuleLevelDeclaration + - eoi: + skip: + rule: EOI ParentMod: - children: - - mod_kw: - rule: Mod - skip: true - - fqn: - rule: FullyQualifiedName + struct: + children: + - mod_kw: + skip: + rule: Mod + - fqn: + member: + rule: FullyQualifiedName UseStatement: - children: - - use_kw: - rule: Use - skip: true - - prefixes: - rule: UseStatementPrefix - vec: true - - suffix: - rule: UseStatementSuffix + struct: + children: + - use_kw: + skip: + rule: Use + - prefixes: + vec: + rule: UseStatementPrefix + - suffix: + member: + rule: UseStatementSuffix UseStatementPrefix: - children: - - identifier + struct: + children: + - identifier UseStatementSuffix: - rules: - - Identifier - - Star: - child: false - - UseList + tree_enum: + rules: + - Identifier + - Star: + child: false + - UseList UseList: - children: - - identifiers: - rule: Identifier - vec: true + struct: + children: + - identifiers: + vec: + rule: Identifier # Level declarations ModuleLevelDeclaration: - rules: - - Module - - Interface - - Class - - Function - - PlatformFunction + tree_enum: + rules: + - Module + - Interface + - Class + - Function + - PlatformFunction InterfaceLevelDeclaration: - rules: - - CompanionModule - - Interface - - Class - - InterfaceFunction - - InterfaceDefaultFunction - - InterfaceOperatorFunction - - InterfaceDefaultOperatorFunction + tree_enum: + rules: + - CompanionModule + - Interface + - Class + - InterfaceFunction + - InterfaceDefaultFunction + - InterfaceOperatorFunction + - InterfaceDefaultOperatorFunction ClassLevelDeclaration: - children: - - CompanionModule - - Interface - - Class - - Function - - OperatorFunction - - PlatformFunction + tree_enum: + rules: + - CompanionModule + - Interface + - Class + - Function + - OperatorFunction + - PlatformFunction # Main organizational constructs Module: - children: - - is_public: - rule: Pub - build: - kind: boolean - on: rule_present - - mod_kw: - rule: Mod - skip: true - - identifier: - rule: Identifier - - declarations: - rule: ModuleLevelDeclaration - vec: true - - end_kw: - rule: End - skip: true + struct: + children: + - is_public: + member: + rule: Pub + build: + boolean: + on: rule_present + - mod_kw: + skip: + rule: Mod + - identifier + - declarations: + vec: + rule: ModuleLevelDeclaration + - end_kw: + skip: + rule: End CompanionModule: - children: - - companion_kw: - rule: Companion - skip: true - - mod_kw: - rule: Mod - skip: true - - declarations: - rule: ModuleLevelDeclaration - vec: true - - end_kw: - rule: End - skip: true + struct: + children: + - companion_kw: + skip: + rule: Companion + - mod_kw: + skip: + rule: Mod + - declarations: + vec: + rule: ModuleLevelDeclaration + - end_kw: + skip: + rule: End Interface: - children: - - is_public: - rule: Pub - build: - kind: boolean - on: rule_present - - int_kw: - rule: IntKw - skip: true - - identifier - - generic_parameters: - build: - or_else_default: true - - implements_list: - build: - or_else_default: true - - declarations: - rule: InterfaceLevelDeclaration - vec: true - - end_kw: - rule: End - skip: true + struct: + children: + - is_public: + member: + rule: Pub + build: + boolean: + on: rule_present + - int_kw: + skip: + rule: IntKw + - identifier + - generic_parameters: + member: + build: + node: + or_else_default: true + - implements_list: + member: + build: + node: + or_else_default: true + - declarations: + vec: + rule: InterfaceLevelDeclaration + - end_kw: + skip: + rule: End Class: - children: - - is_public: - rule: Pub - build: - kind: boolean - on: rule_present - - class_kw: - rule: ClassKw - skip: true - - identifier - - generic_parameters: - build: - or_else_default: true - - class_constructor: - build: - or_else_default: true - - implements_list: - build: - or_else_default: true - - class_level_declarations: - rule: ClassLevelDeclaration - vec: true - - end_kw: - rule: End - skip: true + struct: + children: + - is_public: + member: + rule: Pub + build: + boolean: + on: rule_present + - class_kw: + skip: + rule: ClassKw + - identifier + - generic_parameters: + member: + build: + node: + or_else_default: true + - class_constructor: + member: + build: + node: + or_else_default: true + - implements_list: + member: + build: + node: + or_else_default: true + - class_level_declarations: + vec: + rule: ClassLevelDeclaration + - end_kw: + skip: + rule: End # Function constructs Function: - children: - - is_public: - rule: Pub - build: - kind: boolean - on: rule_present - - fn_kw: - rule: Fn - skip: true - - generics: - rule: GenericParameters - build: - or_else_default: true - - identifier - - parameters - - return_type: - build: - or_else: void - - function_body + struct: + children: + - is_public: + member: + rule: Pub + build: + boolean: + on: rule_present + - fn_kw: + skip: + rule: Fn + - generics: + member: + rule: GenericParameters + build: + node: + or_else_default: true + - identifier + - parameters + - return_type: + member: + build: + node: + or_else: void + - function_body OperatorFunction: - children: - - is_public: - rule: Pub - build: - kind: boolean - on: rule_present - - op_kw: - rule: Op - skip: true - - generics: - rule: GenericParameters - build: - or_else_default: true - - operator - - parameters - - return_type: - build: - or_else: void - - function_body + struct: + children: + - is_public: + member: + rule: Pub + build: + boolean: + on: rule_present + - op_kw: + skip: + rule: Op + - generics: + member: + rule: GenericParameters + build: + node: + or_else_default: true + - operator + - parameters + - return_type: + member: + build: + node: + or_else: void + - function_body PlatformFunction: - children: - - is_public: - rule: Pub - build: - kind: boolean - on: rule_present - - platform_kw: - rule: Platform - skip: true - - fn_kw: - rule: Fn - skip: true - - generics: - rule: GenericParameters - build: - or_else_default: true - - identifier - - parameters - - return_type + struct: + children: + - is_public: + member: + rule: Pub + build: + boolean: + on: rule_present + - platform_kw: + skip: + rule: Platform + - fn_kw: + skip: + rule: Fn + - generics: + member: + rule: GenericParameters + build: + node: + or_else_default: true + - identifier + - parameters + - return_type InterfaceFunction: - children: - - fn_kw: - rule: Fn - skip: true - - generics: - rule: GenericParameters - build: - or_else_default: true - - identifier - - parameters - - return_type + struct: + children: + - fn_kw: + skip: + rule: Fn + - generics: + member: + rule: GenericParameters + build: + node: + or_else_default: true + - identifier + - parameters + - return_type InterfaceDefaultFunction: - children: - - def_kw: - rule: Def - skip: true - - fn_kw: - rule: Fn - skip: true - - generics: - rule: GenericParameters - build: - or_else_default: true - - identifier - - parameters - - return_type: - build: - or_else: void - - function_body + struct: + children: + - def_kw: + skip: + rule: Def + - fn_kw: + skip: + rule: Fn + - generics: + member: + rule: GenericParameters + build: + node: + or_else_default: true + - identifier + - parameters + - return_type: + member: + build: + node: + or_else: void + - function_body InterfaceOperatorFunction: - children: - - op_kw: - rule: Op - skip: true - - generics: - rule: GenericParameters - build: - or_else_default: true - - operator - - parameters - - return_type + struct: + children: + - op_kw: + skip: + rule: Op + - generics: + member: + rule: GenericParameters + build: + node: + or_else_default: true + - operator + - parameters + - return_type InterfaceDefaultOperatorFunction: - children: - - def_kw: - rule: Def - skip: true - - op_kw: - rule: Op - skip: true - - generics: - rule: GenericParameters - build: - or_else_default: true - - operator - - parameters - - return_type: - build: - or_else: void - - function_body - + struct: + children: + - def_kw: + skip: + rule: Def + - op_kw: + skip: + rule: Op + - generics: + member: + rule: GenericParameters + build: + node: + or_else_default: true + - operator + - parameters + - return_type: + member: + build: + node: + or_else: void + - function_body + # Function Bodies FunctionBody: - rules: - - FunctionAliasBody - - FunctionEqualsBody - - FunctionBlockBody + tree_enum: + rules: + - FunctionAliasBody + - FunctionEqualsBody + - FunctionBlockBody FunctionEqualsBody: - children: - - expression + struct: + children: + - expression FunctionAliasBody: - children: - - alias_kw: - rule: Alias - skip: true - - identifier + struct: + children: + - alias_kw: + skip: + rule: Alias + - identifier FunctionBlockBody: - children: - - statements: - rule: Statement - vec: true - - end_kw: - rule: End - skip: true + struct: + children: + - statements: + vec: + rule: Statement + - end_kw: + skip: + rule: End # Class constructs ClassConstructor: - children: - - members: - rule: Member - vec: true + struct: + children: + - members: + vec: + rule: Member Member: - children: - - is_public: - rule: Pub - build: - kind: boolean - on: rule_present - - is_mut: - rule: Mut - build: - kind: boolean - on: rule_present - - identifier - - type_use + struct: + children: + - is_public: + member: + rule: Pub + build: + boolean: + on: rule_present + - is_mut: + member: + rule: Mut + build: + boolean: + on: rule_present + - identifier + - type_use # Statements Statement: - rules: - - VariableDeclaration - - AssignmentStatement - - ExpressionStatement - - UseStatement - - IfStatement - - WhileStatement - - ForStatement + tree_enum: + rules: + - VariableDeclaration + - AssignmentStatement + - ExpressionStatement + - UseStatement + - IfStatement + - WhileStatement + - ForStatement VariableDeclaration: - children: - - let_kw: - rule: Let - skip: true - - is_mut: - rule: Mut - build: - kind: boolean - on: rule_present - - identifier - - type_use: - optional: true - - expression: - optional: true + struct: + children: + - let_kw: + skip: + rule: Let + - is_mut: + member: + rule: Mut + build: + boolean: + on: rule_present + - identifier + - type_use: + member: + optional: true + - expression: + member: + optional: true AssignmentStatement: - children: - - left: - rule: Expression - - right: - rule: Expression + struct: + children: + - left: + member: + rule: Expression + - right: + member: + rule: Expression ExpressionStatement: - children: - - expression + struct: + children: + - expression IfStatement: - children: - - if_clause - - if_else_ifs: - rule: IfElseIf - vec: true - - if_else - - end_kw: - rule: End - skip: true + struct: + children: + - if_clause + - if_else_ifs: + vec: + rule: IfElseIf + - if_else + - end_kw: + skip: + rule: End IfClause: - children: - - if_kw: - rule: If - skip: true - - expression - - then_kw: - rule: Then - skip: true - - statements: - rule: Statement - vec: true + struct: + children: + - if_kw: + skip: + rule: If + - expression + - then_kw: + skip: + rule: Then + - statements: + skip: + rule: Statement IfElseIf: - children: - - else_kw: - rule: Else - skip: true - - if_clause + struct: + children: + - else_kw: + skip: + rule: Else + - if_clause IfElse: - children: - - else_kw: - rule: Else - skip: true - - statements: - rule: Statement - vec: true + struct: + children: + - else_kw: + skip: + rule: Else + - statements: + vec: + rule: Statement WhileStatement: - children: - - while_kw: - rule: While - skip: true - - expression - - do_kw: - rule: Do - skip: true - - statements: - rule: Statement - vec: true - - end_kw: - rule: End - skip: true + struct: + children: + - while_kw: + skip: + rule: While + - expression + - do_kw: + skip: + rule: Do + - statements: + vec: + rule: Statement + - end_kw: + skip: + rule: End ForStatement: - children: - - for_kw: - rule: For - skip: true - - identifier - - in_kw: - rule: In - skip: true - - expression - - do_kw: - rule: Do - skip: true - - statement: - rule: Statement - vec: true - - end_kw: - rule: End - skip: true + struct: + children: + - for_kw: + skip: + rule: For + - identifier + - in_kw: + skip: + rule: In + - expression + - do_kw: + skip: + rule: Do + - statement: + vec: + rule: Statement + - end_kw: + skip: + rule: End # Expressions Expression: polymorphic_type: - enum_members: + variants: - Ternary: inner: kind: TernaryExpression @@ -612,413 +724,471 @@ Expression: kind: ListExpression build: kind: TernaryExpression + +# Ternary TernaryExpression: - polymorphic_build: - return_type: Expression - alternatives: - - test: - number_of_pairs: 1 - action: - return_build: - kind: OrExpression - - test: - number_of_pairs: 3 - action: + polymorphic_enum_loop_build: + kind: Expression + rules: + - OrExpression: + pass_through: + kind: Expression + with: OrExpression + - TernaryRhs: build: - enum_variant: Ternary + variant: Ternary children: - test: - kind: Expression - rule: OrExpression - - on_true: - kind: Expression - rule: TernaryTrueAlternative - - on_false: - kind: Expression - rule: TernaryFalseAlternative + use_current: + kind: Expression + - right: + on_each: + rule: TernaryRhs +TernaryRhs: + struct: + children: + - true_alternative: + member: + rule: TernaryTrueAlternative + build: + node: + kind: Expression + with: TernaryTrueAlternative + - false_alternative: + member: + rule: TernaryFalseAlternative + build: + node: + kind: Expression + with: TernaryFalseAlternative TernaryTrueAlternative: - produce: - kind: - node: Expression + node_production: + kind: Expression + with: OrExpression TernaryFalseAlternative: - produce: - kind: - node: Expression + node_production: + kind: Expression + with: OrExpression + +# Or OrExpression: - polymorphic_build: - return_type: Expression - alternatives: - - test: - number_of_pairs: 1 - action: - return_build: - kind: AndExpression - - test: - number_of_pairs: 3 - action: - build: - enum_variant: Or - children: - - left: - kind: Expression - rule: AndExpression - - or_sym: - rule: Or - skip: true - - right: - kind: Expression - rule: Expression -AndExpression: - polymorphic_build: - return_type: Expression - alternatives: - - test: - number_of_pairs: 1 - action: - return_build: - kind: ComparisonExpression - - test: - number_of_pairs: 3 - action: - build: - enum_variant: And - children: - - left: - kind: Expression - rule: ComparisonExpression - - and_sym: - rule: And - skip: true - - right: - kind: Expression - rule: Expression -ComparisonExpression: - polymorphic_build: - return_type: Expression - alternatives: - - test: - number_of_pairs: 1 - action: - return_build: - kind: ShiftExpression - - test: - number_of_pairs: 3 - action: - build: - enum_variant: Comparison - children: - - left: - kind: Expression - rule: ShiftExpression - - operator: - kind: ComparisonOperator - rule: ComparisonOperator - - right: - kind: Expression - rule: Expression -ComparisonOperator: - leaf_rules: - - Greater - - Less - - GreaterEqual - - LessEqual - - EqualTo - - NotEqualTo -ShiftExpression: - polymorphic_build: - return_type: Expression - alternatives: - - test: - number_of_pairs: 1 - action: - return_build: - kind: AdditiveExpression - - test: - number_of_pairs: 3 - action: - build: - enum_variant: Shift - children: - - left: - kind: Expression - rule: AdditiveExpression - - operator: - kind: ShiftOperator - rule: ShiftOperator - - right: - kind: Expression - rule: Expression -ShiftOperator: - leaf_rules: - - LeftShift - - RightShift -AdditiveExpression: - polymorphic_build: - return_type: Expression - alternatives: - - test: - number_of_pairs: 1 - action: - return_build: - kind: MultiplicativeExpression - - test: - number_of_pairs: 3 - action: - build: - enum_variant: Additive - children: - - left: - kind: Expression - rule: MultiplicativeExpression - - operator: - kind: AdditiveOperator - rule: AdditiveOperator - - right: - kind: Expression - rule: Expression -AdditiveOperator: - leaf_rules: - - Add - - Subtract -MultiplicativeExpression: - polymorphic_build: - return_type: Expression - alternatives: - - test: - number_of_pairs: 1 - action: - return_build: - kind: PrefixExpression - - test: - number_of_pairs: 3 - action: - build: - enum_variant: Multiplicative - children: - - left: - kind: Expression - rule: PrefixExpression - - operator: - kind: MultiplicativeOperator - rule: MultiplicativeOperator - - right: - kind: Expression - rule: Expression -MultiplicativeOperator: - leaf_rules: - - Multiply - - Divide - - Modulo -PrefixExpression: - polymorphic_build: - return_type: Expression - alternatives: - - test: - number_of_pairs: 1 - action: - return_build: - kind: SuffixExpression - - test: - number_of_pairs: 2 - action: - build: - enum_variant: Prefix - children: - - prefix_operators: - kind: PrefixOperators - rule: PrefixOperators - - right: - kind: Expression - rule: SuffixExpression -PrefixOperators: - children: - - operators: - rule: PrefixOperator - vec: true -PrefixOperator: - leaf_rules: - - Spread - - Not - - Negative -SuffixExpression: - polymorphic_build: - return_type: Expression - alternatives: - - test: - number_of_pairs: 1 - action: - return_build: - kind: PrimaryExpression - - test: - number_of_pairs: 2 - action: - build: - enum_variant: Suffix - children: - - left: - kind: Expression - rule: PrimaryExpression - - suffix_operators: - kind: SuffixOperators - rule: SuffixOperators -SuffixOperators: - children: - - operators: - rule: SuffixOperator - vec: true -SuffixOperator: - rules: - - PlusPlus: - child: false - - MinusMinus: - child: false - - ObjectProperty - - ObjectIndex - - Call -ObjectProperty: - children: - - identifier -ObjectIndex: - children: - - expression -PrimaryExpression: - polymorphic_enum: - return_type: Expression + polymorphic_enum_loop_build: + kind: Expression rules: + - AndExpression: + pass_through: + kind: Expression + with: AndExpression + - AndRhs: + build: + variant: Or + children: + - left: + use_current: + kind: Expression + - right: + on_each: + rule: OrRhs +OrRhs: + struct: + children: + - or_kw: + skip: + rule: Or + - expression: + member: + rule: AndExpression + build: + node: + kind: Expression + +# And +AndExpression: + polymorphic_enum_loop_build: + kind: Expression + rules: + - ComparisonExpression: + pass_through: + kind: Expression + with: ComparisonExpression + - AndRhs: + build: + variant: And + children: + - left: + use_current: + kind: Expression + - right: + on_each: + rule: AndRhs +AndRhs: + struct: + children: + - and_kw: + skip: + rule: And + - expression: + member: + rule: ComparisonExpression + build: + node: + kind: Expression + with: ComparisonExpression + +# Comparison +ComparisonExpression: + polymorphic_enum_loop_build: + kind: Expression + rules: + - ShiftExpression: + pass_through: + kind: Expression + with: ShiftExpression + - ComparisonRhs: + build: + variant: Comparison + children: + - left: + use_current: + kind: Expression + - rhs: + on_each: + rule: ComparisonRhs +ComparisonRhs: + struct: + children: + - operator: + member: + rule: ComparisonOperator + - expression: + member: + rule: ShiftExpression +ComparisonOperator: + leaf_enum: + rules: + - Greater + - Less + - GreaterEqual + - LessEqual + - EqualTo + - NotEqualTo +ShiftExpression: + polymorphic_enum_loop_build: + kind: Expression + rules: + - AdditiveExpression: + pass_through: + kind: Expression + with: AdditiveExpression + - ShiftRhs: + build: + variant: Shift + children: + - left: + use_current: + kind: Expression + - right: + on_each: + rule: ShiftRhs +ShiftRhs: + struct: + children: + - operator: + member: + rule: ShiftOperator + - expression: + member: + rule: AdditiveExpression +ShiftOperator: + leaf_enum: + rules: + - LeftShift + - RightShift +AdditiveExpression: + polymorphic_enum_loop_build: + kind: Expression + rules: + - MultiplicativeExpression: + pass_through: + kind: Expression + - AdditiveRhs: + build: + variant: Additive + children: + - left: + use_current: + kind: Expression + - rhs: + on_each: + rule: AdditiveRhs +AdditiveRhs: + struct: + children: + - operator: + member: + rule: AdditiveOperator + - expression: + member: + rule: MultiplicativeExpression +AdditiveOperator: + leaf_enum: + rules: + - Add + - Subtract +MultiplicativeExpression: + polymorphic_enum_loop_build: + kind: Expression + rules: + - PrefixExpression: + pass_through: + kind: Expression + - MultiplicativeRhs: + build: + variant: Multiplicative + children: + - left: + use_current: + kind: Expression + - rhs: + on_each: + rule: MultiplicativeRhs +MultiplicativeRhs: + struct: + children: + - operator: + member: + rule: MultiplicativeOperator + - expression: + member: + rule: PrefixExpression +MultiplicativeOperator: + leaf_enum: + rules: + - Multiply + - Divide + - Modulo +PrefixExpression: + polymorphic_enum_loop_build: + kind: Expression + rules: + - PrefixOperator: + build: + variant: Prefix + children: + - operator: + use_current: + kind: Expression + - expression: + on_each: + rule: SuffixExpression + - SuffixExpression: + pass_through: + kind: Expression + with: SuffixExpression +PrefixOperator: + leaf_enum: + rules: + - Spread + - Not + - Negative +SuffixExpression: + polymorphic_enum_loop_build: + kind: Expression + rules: + - PrimaryExpression: + pass_through: + kind: Expression + with: PrimaryExpression + - SuffixOperator: + build: + variant: Suffix + children: + - expression: + use_current: + kind: Expression + - operator: + on_each: + rule: SuffixExpression +SuffixOperator: + tree_enum: + rules: + - PlusPlus: + child: false + - MinusMinus: + child: false + - ObjectProperty + - ObjectIndex + - Call +ObjectProperty: + struct: + children: + - identifier +ObjectIndex: + struct: + children: + - expression +PrimaryExpression: + polymorphic_type: # TODO: polymorphic pass through + build: + kind: Expression + variants: - Literal: - wrap: - enum_variant: Literal - - FullyQualifiedName: - wrap: - enum_variant: Fqn + inner: + kind: Literal + - Fqn: + inner: + kind: FullyQualifiedName - Closure: - wrap: - enum_variant: Closure + inner: + kind: Closure - ListExpression: - wrap: - enum_variant: List + inner: + kind: ListExpression - ParenthesizedExpression: - return_build: + pass_through: kind: Expression ListExpression: - children: - - expression_list + struct: + children: + - expression_list ParenthesizedExpression: - children: - - expression + struct: + children: + - expression # Calls Call: - rules: - - ParenthesesCall - - NonParenthesesCall + tree_enum: + rules: + - ParenthesesCall + - NonParenthesesCall ParenthesesCall: - children: - - turbo_fish: - optional: true - - expression_list: - optional: true - - closure: - optional: true + struct: + children: + - turbo_fish: + member: + optional: true + - expression_list: + member: + optional: true + - closure: + member: + optional: true NonParenthesesCall: - children: - - turbo_fish: - optional: true - - expression_list: - optional: true - - closure: - optional: true + struct: + children: + - turbo_fish: + member: + optional: true + - expression_list: + member: + optional: true + - closure: + member: + optional: true TurboFish: - children: - - generic_arguments + struct: + children: + - generic_arguments ExpressionList: - children: - - expressions: - rule: Expression - vec: true + struct: + children: + - expressions: + vec: + rule: Expression # Closure Closure: - children: - - closure_parameters: - build: - or_else_default: true - - statements: - rule: Statement - vec: true + struct: + children: + - closure_parameters: + member: + build: + node: + or_else_default: true + - statements: + vec: + rule: Statement ClosureParameters: - children: - - parameters: - rule: ClosureParameters - vec: true + struct: + children: + - parameters: + vec: + rule: ClosureParameter ClosureParameter: - children: - - identifier - - type_use: - optional: true + struct: + children: + - identifier + - type_use: + member: + optional: true # Literals Literal: - rules: - - IntLiteral: - kind: int - - LongLiteral: - kind: long - - DoubleLiteral: - kind: double - - SingleQuoteString: - kind: string - - DString - - BacktickString - - BooleanLiteral: - kind: boolean + tree_enum: + rules: + - IntLiteral: + kind: int + - LongLiteral: + kind: long + - DoubleLiteral: + kind: double + - SingleQuoteString: + kind: string + - DString + - BacktickString + - BooleanLiteral: + kind: boolean # Numbers IntLiteral: - produce: + production: kind: int LongLiteral: - produce: + production: kind: long DoubleLiteral: - produce: + production: kind: double # Strings SingleQuoteString: - produce: + production: kind: string from: string_inner DString: - children: - - inners: - rule: DStringInner - kind: string - vec: true - - expressions: - rule: DStringExpression - vec: true + struct: + children: + - inners: + vec: + rule: DStringInner + kind: string + - expressions: + vec: + rule: DStringExpression DStringInner: - produce: + production: kind: string from: whole_pair DStringExpression: - children: - - expression + struct: + children: + - expression BacktickString: - children: - - inners: - rule: BacktickInner - kind: string - vec: true - - expressions: - rule: DStringExpression - vec: true + struct: + children: + - inners: + vec: + rule: BacktickInner + kind: string + - expressions: + vec: + rule: DStringExpression BacktickInner: - produce: + production: kind: string from: whole_pair BooleanLiteral: - produce: + production: kind: boolean from: parse_whole_pair \ No newline at end of file diff --git a/src/parser/deimos.pest b/src/parser/deimos.pest index 7819b6b..aba0983 100644 --- a/src/parser/deimos.pest +++ b/src/parser/deimos.pest @@ -620,7 +620,7 @@ OrExpression = { } OrRhs = { - Or + Or ~ AndExpression } @@ -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 = {