Skip to content

Commit

Permalink
Merge 0efa269 into e1d034c
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan B. Velloza Kildaire authored Aug 27, 2023
2 parents e1d034c + 0efa269 commit f24e1b4
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 64 deletions.
32 changes: 32 additions & 0 deletions source/tlang/compiler/parsing/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,32 @@ public final class Parser
return externStmt;
}

/**
* Parses an `import <moduleName>;` statement
*/
private void parseImport()
{
gprintln("parseImport(): Enter", DebugType.WARNING);

/* Consume the `import` keyword */
lexer.nextToken();

/* Get the module's name */
expect(SymbolType.IDENT_TYPE, lexer.getCurrentToken());
string moduleName = lexer.getCurrentToken().getToken();

/* Consume the token */
lexer.nextToken();

/* Expect a semi-colon and consume it */
expect(SymbolType.SEMICOLON, lexer.getCurrentToken());
lexer.nextToken();

// TODO: Add support for multi-imports on one line (i.e. `import <module1>, <module2>;`)

gprintln("parseImport(): Leave", DebugType.WARNING);
}


/* Almost like parseBody but has more */
/**
Expand Down Expand Up @@ -2303,6 +2329,12 @@ public final class Parser

modulle.addStatement(externStatement);
}
/* If it is an import */
else if(symbol == SymbolType.IMPORT)
{
// TODO: Figure out exactly what to do
parseImport();
}
else
{
expect("parse(): Unknown '" ~ tok.getToken() ~ "'");
Expand Down
10 changes: 10 additions & 0 deletions source/tlang/compiler/symbols/check.d
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ public enum SymbolType
*/
GENERIC_TYPE_DECLARE,

/**
* `import` keyword
*/
IMPORT,

/**
* Unknown symbol
*/
Expand Down Expand Up @@ -695,6 +700,11 @@ public SymbolType getSymbolType(Token tokenIn)
{
return SymbolType.GENERIC_TYPE_DECLARE;
}
/* import keyword */
else if(cmp(token, "import") == 0)
{
return SymbolType.IMPORT;
}
/* An identifier/type (of some sorts) - further inspection in parser is needed */
else if(isPathIdentifier(token) || isIdentifier(token))
{
Expand Down
81 changes: 17 additions & 64 deletions source/tlang/compiler/symbols/data.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,31 @@ import gogga;
// AST manipulation interfaces
import tlang.compiler.symbols.mcro : MStatementSearchable, MStatementReplaceable, MCloneable;

/**
* TODO: Implement the blow and use them
*
* These are just to use for keeping track of what
* valid identifiers are.
*
* Actually it might be, yeah it will
*/

/**
* Represents a program made up of one or more
* module(s)
*/
public class Program
{
private string moduleName;
private Program[] importedModules;

private Statement[] statements;

this(string moduleName)
{
this.moduleName = moduleName;
}

public void addStatement(Statement statement)
{
statements ~= statement;
}

public static StatementType[] getAllOf(StatementType)(StatementType, Statement[] statements)
{
StatementType[] statementsMatched;

foreach(Statement statement; statements)
{
/* TODO: Remove null, this is for unimpemented */
if(statement !is null && cast(StatementType)statement)
{
statementsMatched ~= cast(StatementType)statement;
}
}

return statementsMatched;
}
/**
* Modules this program is made up of
*/
private Module[] modules;

public Variable[] getGlobals()
this()
{
Variable[] variables;

foreach(Statement statement; statements)
{
if(typeid(statement) == typeid(Variable))
{
variables ~= cast(Variable)statement;
}
}

return variables;
}

/* TODO: Make this use weights */
public Statement[] getStatements()
/**
* Adds a new `Module` to this program
*
* Params:
* newModule = the new `Module` to add
*/
public void addModule(Module newModule)
{
/* Re-ordered by lowest wieght first */
Statement[] stmntsRed;

bool wCmp(Statement lhs, Statement rhs)
{
return lhs.weight < rhs.weight;
}
import std.algorithm.sorting;
stmntsRed = sort!(wCmp)(statements).release;


return stmntsRed;
this.modules ~= newModule;
}
}

Expand Down
3 changes: 3 additions & 0 deletions source/tlang/testing/modules/a.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module a;

import b;
2 changes: 2 additions & 0 deletions source/tlang/testing/modules/b.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module b;

0 comments on commit f24e1b4

Please sign in to comment.