Remove NodeList

Removed the NodeList struct as it only had a "first" field and didn't
really serve any purpose outside of that.  ParseNodes() now just returns
a pointer to the first Node.
This commit is contained in:
Zorchenhimer 2023-10-20 20:19:34 -04:00
parent d855df380b
commit da1ad03661
3 changed files with 8 additions and 22 deletions

4
main.c
View File

@ -44,9 +44,7 @@ main(int argc, const char** argv)
while(tt != TT_EOF);
writeTokenFile(tl);
NodeList* nl = ParseNodes(tl);
Node* node = nl->first;
Node* node = ParseNodes(tl);
printf("nodes:\n");
while(node != NULL)

16
node.c
View File

@ -10,15 +10,11 @@ static char stringBuff[STRING_BUFF_SIZE];
Node* parseHeader(TokenList** list);
Node* parseCodeBlock(TokenList** list);
NodeList*
Node*
ParseNodes(TokenList* list)
{
printf("ParseNodes() start\n");
NodeList* nl = malloc(sizeof(NodeList));
nl->first = NULL;
/*currentNode->next = NULL;*/
/*currentNode->node = NULL;*/
Node* first = NULL;
TokenList* currentToken = list;
Node* prevNode = NULL;
@ -42,7 +38,7 @@ ParseNodes(TokenList* list)
case TT_EOF:
printf("EOF found\n");
return nl;
return first;
default: // paragraph start?
break;
@ -61,14 +57,14 @@ ParseNodes(TokenList* list)
prevNode->next = currentNode;
}
if (nl->first == NULL) {
nl->first = currentNode;
if (first == NULL) {
first = currentNode;
}
prevNode = currentNode;
}
return nl;
return first;
}
Node*

10
node.h
View File

@ -31,20 +31,12 @@ typedef enum {
NT_Error,
} NodeType;
struct NodeList;
typedef struct Node {
NodeType type;
struct Node* next;
/*struct NodeList* children;*/
} Node;
typedef struct NodeList {
struct Node* first;
/*struct Node* node;
struct Node* next;*/
} NodeList;
typedef struct {
NodeType type;
struct Node* next;
@ -70,7 +62,7 @@ typedef struct {
} ParagraphNode;
*/
NodeList* ParseNodes(TokenList* list);
Node* ParseNodes(TokenList* list);
char* NodeTypeString(NodeType t);
#endif