SolsNode stores line info
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
#define SOLSNODE_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <groundvm.h>
|
||||
|
||||
#include "../include/error.h"
|
||||
|
||||
#include "../lexer/SolsType.h"
|
||||
#include "../lexer/SolsLiteral.h"
|
||||
#include "../lexer/SolsToken.h"
|
||||
|
||||
typedef enum SolsNodeType {
|
||||
SNT_IDENTIFIER, SNT_LITERAL, SNT_TYPE, SNT_CODE_BLOCK, SNT_OP_ADD, SNT_OP_SUB, SNT_OP_MUL, SNT_OP_DIV, SNT_OP_ADDTO, SNT_OP_SUBTO, SNT_OP_MULTO, SNT_OP_DIVTO, SNT_OP_INCREMENT, SNT_OP_DECREMENT, SNT_OP_SET, SNT_OP_GREATER, SNT_OP_LESSER, SNT_OP_EQUAL, SNT_OP_INEQUAL, SNT_OP_EQGREATER, SNT_OP_EQLESSER, SNT_DEF, SNT_STRUCT, SNT_PUTS, SNT_IF, SNT_WHILE, SNT_NEW, SNT_GROUND, SNT_ROOT
|
||||
@@ -35,6 +37,10 @@ typedef struct SolsNode {
|
||||
size_t capacity;
|
||||
struct SolsNode* at;
|
||||
} children;
|
||||
LineInfo line;
|
||||
|
||||
// Used by the code generator, do not use in the parser!
|
||||
GroundArg accessArg;
|
||||
} SolsNode;
|
||||
|
||||
Result(SolsNode, charptr);
|
||||
|
||||
@@ -138,6 +138,7 @@ static inline ResultType(Nothing, charptr) parseIdentifier(SolsParser* parser) {
|
||||
APPEND_ESTR(err, " (in parseLiteral() function)");
|
||||
return Error(Nothing, charptr, err.str);
|
||||
}
|
||||
node.as.success.line = peek.as.success.line;
|
||||
addChildToSolsNode(parser->currentParent, node.as.success);
|
||||
return Success(Nothing, charptr, {});
|
||||
}
|
||||
@@ -153,6 +154,7 @@ static inline ResultType(Nothing, charptr) parseLiteral(SolsParser* parser) {
|
||||
APPEND_ESTR(err, " (in parseLiteral() function)");
|
||||
return Error(Nothing, charptr, err.str);
|
||||
}
|
||||
node.as.success.line = peek.as.success.line;
|
||||
addChildToSolsNode(parser->currentParent, node.as.success);
|
||||
return Success(Nothing, charptr, {});
|
||||
}
|
||||
@@ -165,6 +167,9 @@ static inline ResultType(Nothing, charptr) parsePuts(SolsParser* parser) {
|
||||
return Error(Nothing, charptr, tokens.as.error);
|
||||
}
|
||||
|
||||
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 0);
|
||||
if (peek.error) return Error(Nothing, charptr, "ruh roh");
|
||||
|
||||
for (;;) {
|
||||
ResultType(SolsToken, Nothing) peek = parserPeek(parser, 1);
|
||||
if (peek.error) break;
|
||||
@@ -178,6 +183,7 @@ static inline ResultType(Nothing, charptr) parsePuts(SolsParser* parser) {
|
||||
// Create node
|
||||
ResultType(SolsNode, charptr) node = createSolsNode(SNT_PUTS);
|
||||
if (node.error) return Error(Nothing, charptr, node.as.error);
|
||||
node.as.success.line = peek.as.success.line;
|
||||
|
||||
// Parse selected tokens
|
||||
ResultType(SolsParser, charptr) putsParser = createSolsParser(&tokens.as.success);
|
||||
|
||||
Reference in New Issue
Block a user