Skip to content

Commit

Permalink
String parsing works now as literal units
Browse files Browse the repository at this point in the history
  • Loading branch information
PsychedelicPalimpsest committed Apr 25, 2024
1 parent c06f5ee commit 328a09f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
40 changes: 22 additions & 18 deletions source/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ module main;

import parsing.tokenizer.tokens;
import parsing.tokenizer.make_tokens;
import tern.typecons.common : Nullable, nullable;
import parsing.treegen.scopeParser;
import parsing.treegen.tokenRelationships;
import std.stdio;

void main()
{
// Token[] tokens = tokenizeText("
// int x, y;
// x = 5;
// y = 1;
// x = 3;
// void x, y;
// int tv = x++ + y;
// float floaty = tv / 2;
// int xx;
// int xxx;
// ");
// import tern.typecons.common : Nullable, nullable;
// import parsing.treegen.scopeParser;
// import parsing.tokenizer.make_tokens;
// size_t index = 0;
// auto scope_ = tokens.parseMultilineScope(index, nullable!ScopeData(null));
// import std.stdio;
// scope_.declaredVariables.writeln;
size_t index = 0;

auto newScope = parseMultilineScope(FUNCTION_SCOPE_PARSE, "
string axolotl, frog = `Hello world` * 2 + 1;
int constant = 69 /* nice!!! */ ;
".tokenizeText(), index, nullable!ScopeData(null));
foreach (instruction; newScope.instructions)
{
instruction.tree;
}
"\n\nDeclared variables: ".writeln;
foreach (var; newScope.declaredVariables)
{
var.writeln;
}
}
3 changes: 2 additions & 1 deletion source/parsing/treegen/astTypes.d
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class AstNode
}
sink("}");
}

void tree() => tree(-1);

void tree(size_t tabCount)
{
import std.stdio;
Expand Down
2 changes: 1 addition & 1 deletion source/parsing/treegen/expressionParser.d
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public AstNode[] phaseOne(Token[] tokens)
if (old_index != index)
index--;
}
else if (token.tokenVariety == TokenType.Number)
else if (token.tokenVariety == TokenType.Number || token.tokenVariety == TokenType.Quotation)
{
tokenToBeParsedLater.action = AstAction.LiteralUnit;
tokenToBeParsedLater.literalUnitCompenents = [token];
Expand Down

0 comments on commit 328a09f

Please sign in to comment.