MORE TOKEN
This commit is contained in:
parent
56b705b741
commit
0cd1120020
76
lexer.c
76
lexer.c
|
@ -23,6 +23,7 @@ void printtoken(Token* token){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
switch (token->type) {
|
switch (token->type) {
|
||||||
case UNDEFINED_TYPE:
|
case UNDEFINED_TYPE:
|
||||||
printf("UNDEFINED_TYPE: ");
|
printf("UNDEFINED_TYPE: ");
|
||||||
|
@ -39,12 +40,6 @@ void printtoken(Token* token){
|
||||||
case END_BODY:
|
case END_BODY:
|
||||||
printf("END_BODY: ");
|
printf("END_BODY: ");
|
||||||
break;
|
break;
|
||||||
case HTML:
|
|
||||||
printf("HTML: ");
|
|
||||||
break;
|
|
||||||
case END_HTML:
|
|
||||||
printf("END_HTML: ");
|
|
||||||
break;
|
|
||||||
case A:
|
case A:
|
||||||
printf("A: ");
|
printf("A: ");
|
||||||
break;
|
break;
|
||||||
|
@ -79,6 +74,9 @@ void printtoken(Token* token){
|
||||||
printf("ERROR: UNKNOWN TOKEN: ");
|
printf("ERROR: UNKNOWN TOKEN: ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
printf("%d: ", token->type);
|
||||||
|
|
||||||
if (token->value == NULL){
|
if (token->value == NULL){
|
||||||
puts("'NO VALUE FOUND'");
|
puts("'NO VALUE FOUND'");
|
||||||
|
@ -138,18 +136,56 @@ TokenType token_by_name(const char name[HTML_BALISE_LEN]){
|
||||||
return BODY;
|
return BODY;
|
||||||
} else if (strncmp(name, "/body", HTML_BALISE_LEN) == 0){
|
} else if (strncmp(name, "/body", HTML_BALISE_LEN) == 0){
|
||||||
return END_BODY;
|
return END_BODY;
|
||||||
} else if (strncmp(name, "html", HTML_BALISE_LEN) == 0){
|
|
||||||
return HTML;
|
|
||||||
} else if (strncmp(name, "/html", HTML_BALISE_LEN) == 0){
|
} else if (strncmp(name, "/html", HTML_BALISE_LEN) == 0){
|
||||||
return END_HTML;
|
return END_HTML;
|
||||||
|
} else if (strncmp(name, "em", HTML_BALISE_LEN) == 0){
|
||||||
|
return EM;
|
||||||
|
} else if (strncmp(name, "/em", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_EM;
|
||||||
|
} else if (strncmp(name, "i", HTML_BALISE_LEN) == 0){
|
||||||
|
return I;
|
||||||
|
} else if (strncmp(name, "/i", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_I;
|
||||||
|
} else if (strncmp(name, "b", HTML_BALISE_LEN) == 0){
|
||||||
|
return B;
|
||||||
|
} else if (strncmp(name, "/b", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_B;
|
||||||
|
} else if (strncmp(name, "strong", HTML_BALISE_LEN) == 0){
|
||||||
|
return STRONG;
|
||||||
|
} else if (strncmp(name, "/strong", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_STRONG;
|
||||||
|
} else if (strncmp(name, "hr", HTML_BALISE_LEN) == 0){
|
||||||
|
return HR;
|
||||||
|
} else if (strncmp(name, "br", HTML_BALISE_LEN) == 0){
|
||||||
|
return BR;
|
||||||
} else if (strncmp(name, "a", HTML_BALISE_LEN) == 0){
|
} else if (strncmp(name, "a", HTML_BALISE_LEN) == 0){
|
||||||
return A;
|
return A;
|
||||||
} else if (strncmp(name, "/a", HTML_BALISE_LEN) == 0){
|
} else if (strncmp(name, "/a", HTML_BALISE_LEN) == 0){
|
||||||
return END_A;
|
return END_A;
|
||||||
|
} else if (strncmp(name, "ol", HTML_BALISE_LEN) == 0){
|
||||||
|
return OL;
|
||||||
|
} else if (strncmp(name, "/ol", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_OL;
|
||||||
} else if (strncmp(name, "ul", HTML_BALISE_LEN) == 0){
|
} else if (strncmp(name, "ul", HTML_BALISE_LEN) == 0){
|
||||||
return UL;
|
return UL;
|
||||||
|
} else if (strncmp(name, "/ul", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_UL;
|
||||||
} else if (strncmp(name, "li", HTML_BALISE_LEN) == 0){
|
} else if (strncmp(name, "li", HTML_BALISE_LEN) == 0){
|
||||||
return LI;
|
return LI;
|
||||||
|
} else if (strncmp(name, "/li", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_LI;
|
||||||
|
} else if (strncmp(name, "img", HTML_BALISE_LEN) == 0){
|
||||||
|
return IMG;
|
||||||
|
} else if (strncmp(name, "/img", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_IMG;
|
||||||
|
} else if (strncmp(name, "blockquote", HTML_BALISE_LEN) == 0){
|
||||||
|
return BLOCKQUOTE;
|
||||||
|
} else if (strncmp(name, "/blockquote", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_BLOCKQUOTE;
|
||||||
|
} else if (strncmp(name, "code", HTML_BALISE_LEN) == 0){
|
||||||
|
return CODE;
|
||||||
|
} else if (strncmp(name, "/code", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_CODE;
|
||||||
} else if (strncmp(name, "h1", HTML_BALISE_LEN) == 0){
|
} else if (strncmp(name, "h1", HTML_BALISE_LEN) == 0){
|
||||||
return H1;
|
return H1;
|
||||||
} else if (strncmp(name, "h2", HTML_BALISE_LEN) == 0){
|
} else if (strncmp(name, "h2", HTML_BALISE_LEN) == 0){
|
||||||
|
@ -162,6 +198,30 @@ TokenType token_by_name(const char name[HTML_BALISE_LEN]){
|
||||||
return H5;
|
return H5;
|
||||||
} else if (strncmp(name, "h6", HTML_BALISE_LEN) == 0){
|
} else if (strncmp(name, "h6", HTML_BALISE_LEN) == 0){
|
||||||
return H6;
|
return H6;
|
||||||
|
} else if (strncmp(name, "table", HTML_BALISE_LEN) == 0){
|
||||||
|
return TABLE;
|
||||||
|
} else if (strncmp(name, "/table", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_TABLE;
|
||||||
|
} else if (strncmp(name, "thead", HTML_BALISE_LEN) == 0){
|
||||||
|
return THEAD;
|
||||||
|
} else if (strncmp(name, "/thead", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_THEAD;
|
||||||
|
} else if (strncmp(name, "tbody", HTML_BALISE_LEN) == 0){
|
||||||
|
return TBODY;
|
||||||
|
} else if (strncmp(name, "/tbody", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_TBODY;
|
||||||
|
} else if (strncmp(name, "tr", HTML_BALISE_LEN) == 0){
|
||||||
|
return TR;
|
||||||
|
} else if (strncmp(name, "/tr", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_TR;
|
||||||
|
} else if (strncmp(name, "th", HTML_BALISE_LEN) == 0){
|
||||||
|
return TH;
|
||||||
|
} else if (strncmp(name, "/th", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_TH;
|
||||||
|
} else if (strncmp(name, "progress", HTML_BALISE_LEN) == 0){
|
||||||
|
return PROGRESS;
|
||||||
|
} else if (strncmp(name, "/progress", HTML_BALISE_LEN) == 0){
|
||||||
|
return END_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DONT_CARE;
|
return DONT_CARE;
|
||||||
|
|
16
lexer.h
16
lexer.h
|
@ -7,14 +7,24 @@
|
||||||
|
|
||||||
#include "page.h"
|
#include "page.h"
|
||||||
|
|
||||||
|
// 46 enum
|
||||||
typedef enum TokenType {
|
typedef enum TokenType {
|
||||||
UNDEFINED_TYPE,
|
UNDEFINED_TYPE,
|
||||||
DONT_CARE,
|
DONT_CARE,
|
||||||
TEXT,
|
TEXT, END_HTML,
|
||||||
BODY, END_BODY,
|
BODY, END_BODY,
|
||||||
HTML, END_HTML,
|
|
||||||
A, END_A,
|
A, END_A,
|
||||||
UL, LI,
|
IMG, END_IMG,
|
||||||
|
BLOCKQUOTE, END_BLOCKQUOTE,
|
||||||
|
CODE, END_CODE,
|
||||||
|
HR, BR,
|
||||||
|
PROGRESS, END_PROGRESS,
|
||||||
|
STRONG, B, I, EM,
|
||||||
|
END_STRONG, END_B, END_I, END_EM,
|
||||||
|
UL, OL, LI, END_UL, END_OL, END_LI,
|
||||||
|
TABLE, END_TABLE, THEAD,
|
||||||
|
END_THEAD, TBODY, END_TBODY,
|
||||||
|
TR, TH, END_TR, END_TH,
|
||||||
H1, H2, H3, H4, H5, H6,
|
H1, H2, H3, H4, H5, H6,
|
||||||
} TokenType;
|
} TokenType;
|
||||||
|
|
||||||
|
|
2
main.c
2
main.c
|
@ -12,7 +12,7 @@ int main(int argc, char* argv[]){
|
||||||
token = nexttoken();
|
token = nexttoken();
|
||||||
printtoken(token);
|
printtoken(token);
|
||||||
//evaluate(token);
|
//evaluate(token);
|
||||||
} while (token != NULL && token->type != END_BODY);
|
} while (token != NULL && token->type != END_HTML);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue