updated to fix breaking recusrion when a good tag was found, it now segfaults though
This commit is contained in:
parent
58986021de
commit
963b99c6bd
2 changed files with 15 additions and 6 deletions
|
|
@ -47,7 +47,7 @@ void ARC_Parser_Destroy(ARC_Parser *parser){
|
||||||
}
|
}
|
||||||
|
|
||||||
//private recusive function to parse a tag
|
//private recusive function to parse a tag
|
||||||
void ARC_Parser_ParseTag(ARC_Parser *parser, uint32_t *lexerIndex, uint32_t tagId){
|
ARC_Bool ARC_Parser_ParseTag(ARC_Parser *parser, uint32_t *lexerIndex, uint32_t tagId){
|
||||||
//get the current tag
|
//get the current tag
|
||||||
ARC_ParserLanguageTag *tag = NULL;
|
ARC_ParserLanguageTag *tag = NULL;
|
||||||
for(uint32_t index = 0; index < parser->language.size; index++){
|
for(uint32_t index = 0; index < parser->language.size; index++){
|
||||||
|
|
@ -62,7 +62,7 @@ void ARC_Parser_ParseTag(ARC_Parser *parser, uint32_t *lexerIndex, uint32_t tagI
|
||||||
if(tag == NULL){
|
if(tag == NULL){
|
||||||
arc_errno = ARC_ERRNO_NULL;
|
arc_errno = ARC_ERRNO_NULL;
|
||||||
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_Parser_ParseTag(parser, subdata, tagId), could not find tag with id: %u", tagId);
|
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_Parser_ParseTag(parser, subdata, tagId), could not find tag with id: %u", tagId);
|
||||||
return;
|
return ARC_False;
|
||||||
}
|
}
|
||||||
|
|
||||||
//loop through each or section of the tags and tokens
|
//loop through each or section of the tags and tokens
|
||||||
|
|
@ -71,12 +71,20 @@ void ARC_Parser_ParseTag(ARC_Parser *parser, uint32_t *lexerIndex, uint32_t tagI
|
||||||
uint32_t lexerCheckIndex = *lexerIndex;
|
uint32_t lexerCheckIndex = *lexerIndex;
|
||||||
ARC_Bool foundRule = ARC_True;
|
ARC_Bool foundRule = ARC_True;
|
||||||
for(uint32_t tokenOrTagIndex = 1; tokenOrTagIndex < tag->tokensOrTags[orIndex][0] + 1; tokenOrTagIndex++){
|
for(uint32_t tokenOrTagIndex = 1; tokenOrTagIndex < tag->tokensOrTags[orIndex][0] + 1; tokenOrTagIndex++){
|
||||||
|
//check if it is lambda (can return safely)
|
||||||
|
if(tag->tokensOrTags[orIndex][tokenOrTagIndex] == 0){
|
||||||
|
return ARC_True;
|
||||||
|
}
|
||||||
|
|
||||||
//if the value isn't a token it is a tag, so recurs if it isn't a token
|
//if the value isn't a token it is a tag, so recurs if it isn't a token
|
||||||
ARC_Bool isToken = ARC_Lexer_IsTokenId(parser->lexer, tag->tokensOrTags[orIndex][tokenOrTagIndex]);
|
ARC_Bool isToken = ARC_Lexer_IsTokenId(parser->lexer, tag->tokensOrTags[orIndex][tokenOrTagIndex]);
|
||||||
uint32_t nextTagId = tag->tokensOrTags[orIndex][tokenOrTagIndex];
|
uint32_t nextTagId = tag->tokensOrTags[orIndex][tokenOrTagIndex];
|
||||||
if(isToken == ARC_False){
|
if(isToken == ARC_False){
|
||||||
ARC_Parser_ParseTag(parser, lexerIndex, nextTagId);
|
//check if the tag works if not break to continue checking next or
|
||||||
return;
|
ARC_Bool tagFound = ARC_Parser_ParseTag(parser, lexerIndex, nextTagId);
|
||||||
|
if(tagFound == ARC_False){
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the next token in the lexer and increment the lexers index
|
//get the next token in the lexer and increment the lexers index
|
||||||
|
|
@ -94,13 +102,14 @@ void ARC_Parser_ParseTag(ARC_Parser *parser, uint32_t *lexerIndex, uint32_t tagI
|
||||||
if(foundRule == ARC_True){
|
if(foundRule == ARC_True){
|
||||||
*lexerIndex = lexerCheckIndex;
|
*lexerIndex = lexerCheckIndex;
|
||||||
//TODO: set tag into datastructure
|
//TODO: set tag into datastructure
|
||||||
return;
|
return ARC_True;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//no rule was found, so set an error and log
|
//no rule was found, so set an error and log
|
||||||
arc_errno = ARC_ERRNO_DATA;
|
arc_errno = ARC_ERRNO_DATA;
|
||||||
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_Parser_ParseTag(parser, lexerIndex, tagId), tag id: %u could not find a matching rule at token index %u", tagId, *lexerIndex);
|
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_Parser_ParseTag(parser, lexerIndex, tagId), tag id: %u could not find a matching rule at token index %u", tagId, *lexerIndex);
|
||||||
|
return ARC_False;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC_Parser_Parse(ARC_Parser *parser, ARC_String **data){
|
void ARC_Parser_Parse(ARC_Parser *parser, ARC_String **data){
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#include "arc/std/parser.h"
|
#include "arc/std/parser.h"
|
||||||
|
|
||||||
//TODO: fix lambda
|
//TODO: fix lambda
|
||||||
#define LAMBDA 20
|
#define LAMBDA 0
|
||||||
#define CHAR ARC_LEXER_TOKEN_ALPHALOWERCHAR
|
#define CHAR ARC_LEXER_TOKEN_ALPHALOWERCHAR
|
||||||
#define NUM ARC_LEXER_TOKEN_NUMBER
|
#define NUM ARC_LEXER_TOKEN_NUMBER
|
||||||
#define CHAR_OR_NUM 23
|
#define CHAR_OR_NUM 23
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue