readme-thing/node.h

93 lines
1.5 KiB
C
Raw Permalink Normal View History

2021-07-14 08:15:46 -07:00
#include <stdlib.h>
#include "token.h"
#ifndef NODE_H
#define NODE_H
typedef enum {
// Stand-alone elements
// cannot contain text modifiers
2021-07-14 08:15:46 -07:00
NT_Header1,
NT_Header2,
NT_Header3,
NT_Header4,
NT_BlockCode,
// Container elements
// can contain text modifiers
2021-07-14 08:15:46 -07:00
NT_Paragraph,
NT_List,
// Contained elements (cannot be bare)
// text modifiers
NT_InlineCode,
2021-07-14 08:15:46 -07:00
NT_Bold,
NT_Underline,
// something went wrong
NT_Error,
2021-07-14 08:15:46 -07:00
} NodeType;
typedef enum {
LT_Unordered,
LT_NumericOrdered,
LT_AlphaOrdered, // a) b) c) etc.
} ListType;
2021-07-14 08:15:46 -07:00
typedef struct Node {
NodeType type;
struct Node* next;
2021-07-14 08:15:46 -07:00
} Node;
typedef struct {
NodeType type;
struct Node* next;
char* rawText;
} HeaderNode;
typedef struct {
NodeType type;
struct Node* next;
char* rawText;
} CodeBlockNode;
typedef struct {
NodeType type;
struct Node* next;
char* error;
} ErrorNode;
typedef struct {
NodeType type;
struct Node* next;
ListType ltype;
char* rawText;
struct ListNode* nextItem;
struct ListNode* children;
} ListNode;
typedef enum {
PT_Standard,
PT_Quote,
PT_Code,
} ParagraphType;
typedef struct {
NodeType type;
struct Node* next;
ParagraphType ptype;
struct Token* content;
} ParagraphNode;
Node* ParseNodes(Token* firstToken);
char* NodeTypeString(NodeType t);
char* ParagraphTypeString(ParagraphType t);
char* ListTypeString(ListType t);
Node* FreeNode(Node* node);
void ListDebugPrint(ListNode* lnode, int currentLevel);
2021-07-14 08:15:46 -07:00
#endif