readme-thing/main.c

100 lines
1.9 KiB
C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "main.h"
#include "token.h"
#include "lexer.h"
#include "node.h"
/*
* RawText ""
* LineNumber 0
* NodeType NT_Root
* ChildNodes
* RawText "# Header1"
* LineNumber 1
* NodeType NT_Header1
* ChildNodes
* {"Some text."}
*
* RawText "## Header2"
*/
/*
* NodeType NT_Root
* ChildNodes
* RawText "## Header2"
* ChildNodes
* paragraph
* ChildNodes
* {*bold text*}
* {_underlined text_}
* paragraph
*
*
*/
//Node* ParseLine(char *buffer);
void writeTokenFile(TokenList* tl);
int
main(int argc, const char** argv)
{
Lexer* l = NewLexer("sample.md");
TokenList* current = malloc(sizeof(TokenList));
TokenList* tl = current;//= malloc(sizeof(TokenList));
current->token = NULL;
TokenType tt;
do
{
Token* t = NextToken(l);
tt = t->type;
current = TokenListAdd(current, t);
}
while(tt != TT_EOF);
writeTokenFile(tl);
ParseNodes(tl);
printf("rawLen: %d position: %d readPosition: %d ch: %c line: %d column: %d\n",
l->rawLen,
l->position,
l->readPosition,
l->ch,
l->line,
l->column
);
return 0;
}
void
writeTokenFile(TokenList* tl)
{
int count;
FILE* fp = fopen("tokens.txt", "w");
if (fp == NULL)
{
printf("unable to open output.txt\n");
return;
}
TokenList* current = tl;
for(count = 0; current->next != NULL; count++) {
if (count == 0 && current->token == NULL)
{
printf("first token null\n");
}
else if (count == 0)
{
printf("%s\n", TokenString(current->token));
}
fprintf(fp, "%s\n", TokenString(current->token));
current = current->next;
}
fclose(fp);
printf("Token count: %d\n", count);
}