From 9f6dd813c82f63213bf8862368186d75d2f22f02 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sun, 21 Mar 2021 09:45:40 +0200 Subject: [PATCH] Added support for class inheritance parsing --- source/tlang/compiler/parser.d | 40 +++++++++++++++++++++++++++++++--- source/tlang/testing/basic1.t | 2 +- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/source/tlang/compiler/parser.d b/source/tlang/compiler/parser.d index 368a192..4f7ab1a 100644 --- a/source/tlang/compiler/parser.d +++ b/source/tlang/compiler/parser.d @@ -507,10 +507,44 @@ public final class Parser expect(SymbolType.IDENTIFIER, getCurrentToken()); string className = getCurrentToken().getToken(); gprintln("parseClass(): Class name found '" ~ className ~ "'"); - - /* Expect a `{` */ nextToken(); - expect(SymbolType.OCURLY, getCurrentToken()); + + + /* TODO: If we have the inherit symbol `:` */ + if(getSymbolType(getCurrentToken()) == SymbolType.INHERIT_OPP) + { + /* TODO: Loop until `}` */ + + /* Consume the inheritance operator `:` */ + nextToken(); + + while(true) + { + /* Check if it is an identifier */ + expect(SymbolType.IDENTIFIER, getCurrentToken()); + nextToken(); + + /* Check if we have ended with a `{` */ + if(getSymbolType(getCurrentToken()) == SymbolType.OCURLY) + { + /* Exit */ + break; + } + /* If we get a comma */ + else if(getSymbolType(getCurrentToken()) == SymbolType.COMMA) + { + /* Consume */ + nextToken(); + } + /* Error out if we get anything else */ + else + { + expect("Expected either { or ,"); + } + } + } + + /* TODO: Go through all classes comma seperated */ /* Parse a body */ parseBody(); diff --git a/source/tlang/testing/basic1.t b/source/tlang/testing/basic1.t index 651ccdb..20ca140 100644 --- a/source/tlang/testing/basic1.t +++ b/source/tlang/testing/basic1.t @@ -8,7 +8,7 @@ class clazz1 print("Hello world"); } -class clazz_2_1 +class clazz_2_1 : bruh { class clazz_2_2 {