Parse comments

This commit is contained in:
Wilson Lin 2018-07-20 22:39:37 +12:00
parent 6080451453
commit cbc837978d
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,29 @@
#ifndef _HDR_HYPERBUILD_STREAM_COMMENT
#define _HDR_HYPERBUILD_STREAM_COMMENT
#include "../util/hbchar.h"
#include "../util/pipe.c"
void hbs_comment(hbu_pipe_t pipe)
{
hbu_pipe_require(pipe, '<');
hbu_pipe_require(pipe, '!');
hbu_pipe_require(pipe, '-');
hbu_pipe_require(pipe, '-');
while (1)
{
if (hbu_pipe_peek_offset(pipe, 1) == '-' &&
hbu_pipe_peek_offset(pipe, 2) == '-' &&
hbu_pipe_peek_offset(pipe, 3) == '>')
{
break;
}
hbu_pipe_skip(pipe);
}
hbu_pipe_skip_amount(pipe, 3);
}
#endif // _HDR_HYPERBUILD_STREAM_COMMENT

View File

@ -9,6 +9,7 @@ void hbs_content(hbu_pipe_t pipe);
#include "./tag.c"
#include "./bang.c"
#include "./comment.c"
void hbs_content(hbu_pipe_t pipe) {
while (1) {
@ -23,6 +24,9 @@ void hbs_content(hbu_pipe_t pipe) {
// Callee is responsible for requiring close tag (or not, if root)
return;
} else if (hbu_pipe_peek_offset(pipe, 2) == '!' && hbu_pipe_peek_offset(pipe, 3) == '-') {
hbs_comment(pipe);
} else if (hbu_pipe_peek_offset(pipe, 2) == '!') {
// Check after comment
hbs_bang(pipe);