From 31479329d50166f4dbcde41d719fbd8d78457f73 Mon Sep 17 00:00:00 2001 From: Andrew Segavac Date: Thu, 1 Jul 2021 12:29:00 -0600 Subject: [PATCH] working on adding traits --- README.md | 1 + boring/parse.py | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2fd86f0..5932c86 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ This language is under active development, progress will be marked here as the l - [ ] Imports - [ ] Visibility - [ ] Const / Mut +- [ ] Macros This project is actively looking for contributors, so if you're interested in programming language design or have experience working with LLVM, don't hesitate to contact. diff --git a/boring/parse.py b/boring/parse.py index 6e586a4..005a872 100644 --- a/boring/parse.py +++ b/boring/parse.py @@ -154,9 +154,14 @@ class VariableDeclaration: @dataclass class Function: + declaration: "FunctionDeclaration" + type: TypeUsage + + +@dataclass +class FunctionDeclaration: name: str arguments: List[VariableDeclaration] - block: Block return_type: TypeUsage type: TypeUsage @@ -189,6 +194,27 @@ class Impl: functions: List[Function] +@dataclass +class FunctionDeclartation: + name: str + arguments: List[VariableDeclaration] + return_type: TypeUsage + type: TypeUsage + + +@dataclass +class TraitTypeDeclaration: + struct: str + functions: List[Function] + + +@dataclass +class TraitImpl: + struct: str + trait: str + functions: List[Function] + + @dataclass class Module: functions: List[Function] @@ -264,13 +290,14 @@ boring_grammar = r""" variable_declaration : identifier ":" type_usage - function_without_return : "fn" identifier "(" [variable_declaration ("," variable_declaration)*] ")" block + function_declaration_without_return : "fn" identifier "(" [variable_declaration ("," variable_declaration)*] ")" - function_with_return : "fn" identifier "(" [variable_declaration ("," variable_declaration)*] ")" ":" type_usage block + function_declaration_with_return : "fn" identifier "(" [variable_declaration ("," variable_declaration)*] ")" ":" type_usage - function : function_with_return - | function_without_return + function_declaration : function_declaration_with_return + | function_declaration_without_return + function : function_declaration block struct_definition_field : identifier ":" type_usage @@ -278,10 +305,17 @@ boring_grammar = r""" type_alias_declaration : "type" identifier "=" type_usage ";" + + trait_item : function_declaration ";" + | function + + trait_declaration : "type" identifier "trait" "{" trait_item* "}" + type_declaration : struct_type_declaration | type_alias_declaration impl : "impl" identifier "{" function* "}" + | "impl" identifier "for" identifier "{" function* "}" module : (function|type_declaration|impl)*