working on adding traits

This commit is contained in:
Andrew Segavac
2021-07-01 12:29:00 -06:00
parent 97ba007943
commit 31479329d5
2 changed files with 40 additions and 5 deletions

View File

@@ -47,6 +47,7 @@ This language is under active development, progress will be marked here as the l
- [ ] Imports - [ ] Imports
- [ ] Visibility - [ ] Visibility
- [ ] Const / Mut - [ ] 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. 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.

View File

@@ -154,9 +154,14 @@ class VariableDeclaration:
@dataclass @dataclass
class Function: class Function:
declaration: "FunctionDeclaration"
type: TypeUsage
@dataclass
class FunctionDeclaration:
name: str name: str
arguments: List[VariableDeclaration] arguments: List[VariableDeclaration]
block: Block
return_type: TypeUsage return_type: TypeUsage
type: TypeUsage type: TypeUsage
@@ -189,6 +194,27 @@ class Impl:
functions: List[Function] 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 @dataclass
class Module: class Module:
functions: List[Function] functions: List[Function]
@@ -264,13 +290,14 @@ boring_grammar = r"""
variable_declaration : identifier ":" type_usage 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_declaration : function_declaration_with_return
| function_without_return | function_declaration_without_return
function : function_declaration block
struct_definition_field : identifier ":" type_usage struct_definition_field : identifier ":" type_usage
@@ -278,10 +305,17 @@ boring_grammar = r"""
type_alias_declaration : "type" identifier "=" type_usage ";" 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_declaration : struct_type_declaration
| type_alias_declaration | type_alias_declaration
impl : "impl" identifier "{" function* "}" impl : "impl" identifier "{" function* "}"
| "impl" identifier "for" identifier "{" function* "}"
module : (function|type_declaration|impl)* module : (function|type_declaration|impl)*