multiple parsing fixes
- comment in pipeline throwing an error - heredocument tries to parse quotes - split pipeline/condlist combined with heredocuments don't parse correctly
This commit is contained in:
parent
c6c224bd12
commit
38845e8652
2 changed files with 37 additions and 2 deletions
|
|
@ -79,6 +79,13 @@ uint32_t skip_unread(const char* in, uint32_t size, uint32_t start);
|
||||||
inline uint32_t skip_unread(parse_context const& ct) {
|
inline uint32_t skip_unread(parse_context const& ct) {
|
||||||
return skip_unread(ct.data, ct.size, ct.i);
|
return skip_unread(ct.data, ct.size, ct.i);
|
||||||
}
|
}
|
||||||
|
uint32_t skip_unread_noline(const char* in, uint32_t size, uint32_t start);
|
||||||
|
inline uint32_t skip_unread_noline(parse_context const& ct) {
|
||||||
|
return skip_unread_noline(ct.data, ct.size, ct.i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// heredocument
|
||||||
|
parse_context parse_heredocument(parse_context ctx);
|
||||||
|
|
||||||
// list
|
// list
|
||||||
// std::pair<list*, parse_context> parse_list_until(parse_context ct, char end_c, const char* expecting=NULL);
|
// std::pair<list*, parse_context> parse_list_until(parse_context ct, char end_c, const char* expecting=NULL);
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,18 @@ uint32_t skip_unread(const char* in, uint32_t size, uint32_t start)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t skip_unread_noline(const char* in, uint32_t size, uint32_t start)
|
||||||
|
{
|
||||||
|
uint32_t i=start;
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
i = skip_chars(in, size, i, SPACES);
|
||||||
|
if(in[i] != '#') // not a comment
|
||||||
|
return i;
|
||||||
|
i = skip_until(in, size, i, "\n"); //skip to endline
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t word_eq(const char* word, const char* in, uint32_t size, uint32_t start, const char* end_set)
|
uint32_t word_eq(const char* word, const char* in, uint32_t size, uint32_t start, const char* end_set)
|
||||||
{
|
{
|
||||||
uint32_t i=start;
|
uint32_t i=start;
|
||||||
|
|
@ -611,8 +623,9 @@ parse_context parse_heredocument(parse_context ctx)
|
||||||
// std::string tmpparse=std::string(ctx.data+j, ctx.i-j);
|
// std::string tmpparse=std::string(ctx.data+j, ctx.i-j);
|
||||||
parse_context newctx = make_context(ctx, j);
|
parse_context newctx = make_context(ctx, j);
|
||||||
newctx.size = ctx.i;
|
newctx.size = ctx.i;
|
||||||
auto pval = parse_arg(newctx , NULL, NULL);
|
auto pval = parse_arg(newctx , NULL, NULL, false);
|
||||||
ctx.i = pval.second.i;
|
ctx.i = pval.second.i;
|
||||||
|
ctx.has_errored = pval.second.has_errored;
|
||||||
ctx.here_document->here_document = pval.first;
|
ctx.here_document->here_document = pval.first;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -898,6 +911,14 @@ std::pair<pipeline*, parse_context> parse_pipeline(parse_context ctx)
|
||||||
return std::make_pair(ret, ctx);
|
return std::make_pair(ret, ctx);
|
||||||
}
|
}
|
||||||
ctx.i++;
|
ctx.i++;
|
||||||
|
if(ctx.here_document != nullptr)
|
||||||
|
{
|
||||||
|
ctx.i = skip_unread_noline(ctx);
|
||||||
|
if(ctx[ctx.i] == '\n')
|
||||||
|
ctx = parse_heredocument(ctx+1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ctx.i = skip_unread(ctx);
|
||||||
}
|
}
|
||||||
return std::make_pair(ret, ctx);
|
return std::make_pair(ret, ctx);
|
||||||
}
|
}
|
||||||
|
|
@ -942,7 +963,14 @@ std::pair<condlist*, parse_context> parse_condlist(parse_context ctx)
|
||||||
parse_error( unexpected_token(ctx[ctx.i]), ctx);
|
parse_error( unexpected_token(ctx[ctx.i]), ctx);
|
||||||
return std::make_pair(ret, ctx);
|
return std::make_pair(ret, ctx);
|
||||||
}
|
}
|
||||||
ctx.i = skip_unread(ctx);
|
if(ctx.here_document != nullptr)
|
||||||
|
{
|
||||||
|
ctx.i = skip_unread_noline(ctx);
|
||||||
|
if(ctx[ctx.i] == '\n')
|
||||||
|
ctx = parse_heredocument(ctx+1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ctx.i = skip_unread(ctx);
|
||||||
if(ctx.i>=ctx.size)
|
if(ctx.i>=ctx.size)
|
||||||
{
|
{
|
||||||
parse_error( "Unexpected end of file", ctx );
|
parse_error( "Unexpected end of file", ctx );
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue