2021-07-14 08:15:46 -07:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "token.h"
|
|
|
|
|
|
|
|
#ifndef NODE_H
|
|
|
|
#define NODE_H
|
|
|
|
|
|
|
|
typedef enum {
|
2023-10-15 17:55:12 -07:00
|
|
|
// Stand-alone elements
|
|
|
|
// cannot contain text modifiers
|
2021-07-14 08:15:46 -07:00
|
|
|
NT_Header1,
|
|
|
|
NT_Header2,
|
|
|
|
NT_Header3,
|
|
|
|
NT_Header4,
|
2023-10-15 17:55:12 -07:00
|
|
|
NT_BlockCode,
|
|
|
|
|
|
|
|
// Container elements
|
|
|
|
// can contain text modifiers
|
2021-07-14 08:15:46 -07:00
|
|
|
NT_Paragraph,
|
|
|
|
NT_UnorderedList,
|
|
|
|
NT_OrderedList,
|
|
|
|
NT_BlockQuote,
|
2023-10-15 17:55:12 -07:00
|
|
|
|
|
|
|
// Contained elements (cannot be bare)
|
|
|
|
// text modifiers
|
|
|
|
NT_InlineCode,
|
2021-07-14 08:15:46 -07:00
|
|
|
NT_Bold,
|
|
|
|
NT_Underline,
|
2023-10-15 17:55:12 -07:00
|
|
|
|
|
|
|
// something went wrong
|
|
|
|
NT_Error,
|
2021-07-14 08:15:46 -07:00
|
|
|
} NodeType;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct Node {
|
|
|
|
NodeType type;
|
2023-10-15 15:30:59 -07:00
|
|
|
struct Node* next;
|
2021-07-14 08:15:46 -07:00
|
|
|
} Node;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
NodeType type;
|
|
|
|
struct Node* next;
|
|
|
|
char* rawText;
|
|
|
|
} HeaderNode;
|
|
|
|
|
2023-10-15 17:55:12 -07:00
|
|
|
typedef struct {
|
|
|
|
NodeType type;
|
|
|
|
struct Node* next;
|
|
|
|
char* rawText;
|
|
|
|
} CodeBlockNode;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
NodeType type;
|
|
|
|
struct Node* next;
|
|
|
|
char* error;
|
|
|
|
} ErrorNode;
|
|
|
|
|
2023-10-22 19:29:38 -07:00
|
|
|
typedef enum {
|
|
|
|
PT_Standard,
|
|
|
|
PT_Quote,
|
|
|
|
PT_Code,
|
|
|
|
} ParagraphType;
|
|
|
|
|
2023-10-15 15:30:59 -07:00
|
|
|
typedef struct {
|
|
|
|
NodeType type;
|
|
|
|
struct Node* next;
|
2023-10-22 19:29:38 -07:00
|
|
|
ParagraphType ptype;
|
|
|
|
struct Token* content;
|
2023-10-15 15:30:59 -07:00
|
|
|
} ParagraphNode;
|
|
|
|
|
2023-10-22 13:50:18 -07:00
|
|
|
Node* ParseNodes(Token* firstToken);
|
2023-10-15 15:30:59 -07:00
|
|
|
char* NodeTypeString(NodeType t);
|
2023-10-22 19:29:38 -07:00
|
|
|
char* ParagraphTypeString(ParagraphType t);
|
2021-07-14 08:15:46 -07:00
|
|
|
|
|
|
|
#endif
|