Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser dev #4

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion source/fnc/treegen/ast_types.d
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ class AstNode
AstNode voidableType;
}
static AstNode VOID_NAMED_UNIT(){
AstNode voidNamedUnit = new AstNode;
AstNode voidNamedUnit = new AstNode();
voidNamedUnit.action = AstAction.NamedUnit;
import fnc.tokenizer.tokens : makeUnicodeString;
voidNamedUnit.namedUnit = NamedUnit(["void".makeUnicodeString]);
return voidNamedUnit;
}
Expand Down
7 changes: 6 additions & 1 deletion source/fnc/treegen/scope_parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ LineVarietyTestResult parseLine(const(VarietyTestPair[]) scopeParseMethod, Token
auto nodes = lineVariety.tokenMatches[DECLARATION_EXPRESSION]
.assertAs(TokenGrepMethod.Glob)
.tokens.expressionNodeFromTokens();

lineVariety.tokenMatches[DECLARATION_EXPRESSION]
.assertAs(TokenGrepMethod.Glob)
.tokens.writeln;
if (nodes.length != 1)
throw new SyntaxError(
"Expression node tree could not be parsed properly (Not reducable into single node)",
Expand All @@ -321,6 +323,9 @@ LineVarietyTestResult parseLine(const(VarietyTestPair[]) scopeParseMethod, Token
parent.instructions ~= assignment;
break;
case LineVariety.TaggedUntypedItem:
size_t endingIndex = index + lineVariety.length;
scope (exit)
index = endingIndex;
NamedUnit name = lineVariety.tokenMatches[0].assertAs(TokenGrepMethod.NamedUnit).name;
parent.declaredVariables ~= DeclaredVariable(name, AstNode.VOID_NAMED_UNIT);
break;
Expand Down
44 changes: 21 additions & 23 deletions source/fnc/treegen/utils.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,31 @@ NamedUnit genNamedUnit(Token[] tokens, ref size_t index)
{
dchar[][] nameData = new dchar[][0];
// NamedUnit ret = NamedUnit(new dchar[][]);
Nullable!Token tokenNullable = tokens.nextNonWhiteToken(index);

Token token;

// An attempt to generate a name at an EOF
if (tokenNullable.ptr == null)
return NamedUnit(nameData);
index--;
token = tokenNullable;

while (token.tokenVariety == TokenType.Letter || token.tokenVariety == TokenType.Number || token.tokenVariety == TokenType
.Period)
bool hasLastPeriod = true;
while (1)
{

if (token.tokenVariety != TokenType.Period)
Nullable!Token tokenNullable = tokens.nextNonWhiteToken(index);
if (tokenNullable == null)
return NamedUnit(nameData);
Token token = tokenNullable;
if (token.tokenVariety == TokenType.Period){
hasLastPeriod = true;
continue;
}
if (token.tokenVariety == TokenType.Letter)
{
if (!hasLastPeriod)
{
index--;
return NamedUnit(nameData);
}
nameData ~= token.value;
hasLastPeriod = false;
continue;
}

Nullable!Token tokenNullable2 = tokens.nextToken(index);

// We hit an EOF
if (!tokenNullable2.ptr)
return NamedUnit(nameData);
token = tokenNullable2;

index--;
return NamedUnit(nameData);
}
return NamedUnit(nameData);


}
3 changes: 2 additions & 1 deletion source/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ void main()
private tagged Element{
kind;
idk;
int anElmentWithNumber;
}
int main(){
return => add(y : 1, x : 1, offset : 3);
const Element e = Element.idk;
}
");

Expand Down
Loading