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); while(tt != TT_EOF);
writeTokenFile(tl); writeTokenFile(tl);
NodeList* nl = ParseNodes(tl); Node* node = ParseNodes(tl);
Node* node = nl->first;
printf("nodes:\n"); printf("nodes:\n");
while(node != NULL) while(node != NULL)

16
node.c
View File

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

10
node.h
View File

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