Pest and ast syntax changes.

This commit is contained in:
Jesse Brault 2025-09-03 16:39:31 -05:00
parent e79c22db72
commit 4dcb5ee783
5 changed files with 144 additions and 38 deletions

View File

@ -0,0 +1,5 @@
use math::add
fn main()
println add(1, 2) // 3
end

View File

@ -0,0 +1,3 @@
mod math
pub fn add(a: Int, b: Int) = a + b

View File

@ -78,12 +78,14 @@ $defs:
properties: properties:
rule: rule:
type: string type: string
description: The type to build, in Pascal case.
optional:
type: boolean
description: If true, this child will be stored as an Option.
build: build:
oneOf: oneOf:
- type: string - type: string
- $ref: "#/$defs/SingleChildBuildDefinition" - $ref: "#/$defs/SingleChildBuildDefinition"
required:
- rule
SingleChildBuildDefinition: SingleChildBuildDefinition:
type: object type: object
additionalProperties: false additionalProperties: false

View File

@ -1,19 +1,21 @@
# $schema: ./ast.schema.yaml # $schema: ./ast.schema.yaml
# Top-level constructs
CompilationUnit: CompilationUnit:
children: children:
- namespace - parent_mod
- use_statements: - use_statements:
rule: UseStatement rule: UseStatement
vec: true vec: true
- module_level_declarations: - module_level_declarations:
rule: ModuleLevelDeclaration rule: ModuleLevelDeclaration
Namespace: vec: true
ParentMod:
children: children:
- ns_kw: - mod_kw:
rule: Ns rule: Mod
skip: true skip: true
- fqn: - fqn:
rule: Fqn rule: FullyQualifiedName
UseStatement: UseStatement:
children: children:
- use_kw: - use_kw:
@ -24,17 +26,49 @@ UseStatement:
vec: true vec: true
- suffix: - suffix:
rule: UseStatementSuffix rule: UseStatementSuffix
UseStatementPrefix:
children:
- identifier
UseStatementSuffix:
rules:
- Identifier
- rule: Star
build: UseStatementStarSuffix
- UseList
UseList:
children:
- identifiers:
rule: Identifier
vec: true
# Level declarations
ModuleLevelDeclaration: ModuleLevelDeclaration:
rules: rules:
- rule: Module - Module
build: ModuleDeclaration - Interface
- rule: Interface - Class
build: InterfaceDeclaration - Function
- rule: Class
build: ClassDeclaration
- FunctionDefinition
- PlatformFunction - PlatformFunction
ModuleDeclaration: InterfaceLevelDeclaration:
rules:
- CompanionModule
- Interface
- Class
- InterfaceFunction
- InterfaceDefaultFunction
- InterfaceOperatorFunction
- InterfaceDefaultOperatorFunction
ClassLevelDeclaration:
children:
- CompanionModule
- Interface
- Class
- Function
- OperatorFunction
- PlatformFunction
# Main organizational constructs
Module:
children: children:
- is_public: - is_public:
rule: Pub rule: Pub
@ -49,7 +83,45 @@ ModuleDeclaration:
- declarations: - declarations:
rule: ModuleLevelDeclaration rule: ModuleLevelDeclaration
vec: true vec: true
ClassDeclaration: - end_kw:
rule: End
skip: true
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
Interface:
children:
- is_public:
rule: Pub
build:
type: boolean
on: rule_present
- int_kw:
rule: IntKw
skip: true
- identifier
- generic_parameters:
optional: true
- implements_list:
optional: true
- declarations:
rule: InterfaceLevelDeclaration
vec: true
- end_kw:
rule: End
skip: true
Class:
children: children:
- is_public: - is_public:
rule: Pub rule: Pub
@ -60,13 +132,18 @@ ClassDeclaration:
rule: ClassKw rule: ClassKw
skip: true skip: true
- identifier - identifier
- generic_parameters - generic_parameters:
- class_constructor optional: true
- implements_list - class_constructor:
optional: true
- implements_list:
optional: true
- class_level_declarations: - class_level_declarations:
rule: ClassLevelDeclaration rule: ClassLevelDeclaration
vec: true vec: true
FunctionDeclaration:
# Function constructs
Function:
children: children:
- is_public: - is_public:
rule: Pub rule: Pub

View File

@ -30,6 +30,8 @@ Alias = { "alias" }
True = { "true" } True = { "true" }
False = { "false" } False = { "false" }
Use = { "use" } Use = { "use" }
End = { "end" }
Companion = { "comp" }
// Keywords: primitive types // Keywords: primitive types
Byte = { "Byte" } Byte = { "Byte" }
@ -322,22 +324,31 @@ RefList = {
CompilationUnit = { CompilationUnit = {
SOI SOI
~ ( Namespace ~ Semicolon )? ~ ParentMod?
~ ( UseStatement ~ Semicolon )* ~ ( UseStatement | ModuleLevelDeclaration )*
~ ModuleLevelDeclaration*
~ EOI ~ EOI
} }
Namespace = { ParentMod = {
Ns Mod
~ FullyQualifiedName ~ FullyQualifiedName
} }
UseStatement = { UseStatement = {
Use Use
~ Identifier ~ UseStatementPrefix*
~ ( "::" ~ Identifier )* ~ UseStatementSuffix
~ ( "::" ~ ( Star | UseList ) )? }
UseStatementPrefix = {
Identifier
~ "::"
}
UseStatementSuffix = {
Identifier
| Star
| UseList
} }
UseList = { UseList = {
@ -353,12 +364,12 @@ ModuleLevelDeclaration = {
Module Module
| Interface | Interface
| Class | Class
| FunctionDefinition | Function
| PlatformFunction | PlatformFunction
} }
InterfaceLevelDeclaration = { InterfaceLevelDeclaration = {
Module CompanionModule
| Interface | Interface
| Class | Class
| InterfaceFunction | InterfaceFunction
@ -368,14 +379,12 @@ InterfaceLevelDeclaration = {
} }
ClassLevelDeclaration = { ClassLevelDeclaration = {
Module CompanionModule
| Interface | Interface
| Class | Class
| FunctionDefinition | Function
| OperatorFunctionDefinition | OperatorFunction
| PlatformFunction | PlatformFunction
| Property
| Field
} }
// Main organizational constructs // Main organizational constructs
@ -384,7 +393,15 @@ Module = {
Pub? Pub?
~ Mod ~ Mod
~ Identifier ~ Identifier
~ "{" ~ ModuleLevelDeclaration* ~ "}" ~ ModuleLevelDeclaration*
~ End
}
CompanionModule = {
Companion
~ Mod
~ ModuleLevelDeclaration*
~ End
} }
Interface = { Interface = {
@ -393,7 +410,8 @@ Interface = {
~ Identifier ~ Identifier
~ GenericParameters? ~ GenericParameters?
~ ImplementsList? ~ ImplementsList?
~ ( "{" ~ InterfaceLevelDeclaration* ~ "}" )? ~ InterfaceLevelDeclaration*
~ End
} }
Class = { Class = {
@ -403,7 +421,8 @@ Class = {
~ GenericParameters? ~ GenericParameters?
~ ClassConstructor? ~ ClassConstructor?
~ ImplementsList? ~ ImplementsList?
~ ( "{" ~ ClassLevelDeclaration* ~ "}" )? ~ ClassLevelDeclaration*
~ End
} }
// Function constructs // Function constructs