Skip to content

Commit

Permalink
Merge pull request #4 from fern-pl/parserDev
Browse files Browse the repository at this point in the history
Parser dev
  • Loading branch information
HeronErin authored May 13, 2024
2 parents 4f13149 + 1a867d9 commit 1e1b4b0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
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

0 comments on commit 1e1b4b0

Please sign in to comment.