Make error printy thingy work
This commit is contained in:
@@ -27,30 +27,31 @@ ResultType(SolsParser, charptr) createSolsParser(SolsTokens* input) {
|
||||
|
||||
void createParserError(SolsParser* parser, char* what) {
|
||||
|
||||
ResultType(SolsToken, Nothing) prevToken;
|
||||
ResultType(SolsToken, Nothing) prevToken = Error(SolsToken, Nothing, {});
|
||||
SolsToken token = parserPeek(parser, 0).as.success;
|
||||
ResultType(SolsToken, Nothing) nextToken;
|
||||
ResultType(SolsToken, Nothing) nextToken = Error(SolsToken, Nothing, {});
|
||||
|
||||
// Find tokens for previous line and next line
|
||||
for (size_t i = parser->current; i > 0; i--) {
|
||||
prevToken = parserLookAt(parser, i);
|
||||
if (prevToken.error || prevToken.as.success.line.num != token.line.num) {
|
||||
break;
|
||||
// Find tokens for previous line
|
||||
if (parser->current > 1) {
|
||||
for (size_t i = parser->current - 1; i > 0; i--) {
|
||||
ResultType(SolsToken, Nothing) check = parserLookAt(parser, i - 1);
|
||||
if (check.error) break;
|
||||
if (check.as.success.line.num != token.line.num) {
|
||||
prevToken = check;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prevToken.error || prevToken.as.success.line.num == token.line.num) {
|
||||
prevToken = Error(SolsToken, Nothing, {});
|
||||
}
|
||||
|
||||
for (size_t i = parser->current; i <= parser->input->count; i++) {
|
||||
nextToken = parserLookAt(parser, i);
|
||||
if (nextToken.error || nextToken.as.success.line.num != token.line.num) {
|
||||
// Find tokens for next line
|
||||
for (size_t i = parser->current; i < parser->input->count; i++) {
|
||||
ResultType(SolsToken, Nothing) check = parserLookAt(parser, i);
|
||||
if (check.error) break;
|
||||
if (check.as.success.line.num != token.line.num) {
|
||||
nextToken = check;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nextToken.error || nextToken.as.success.line.num == token.line.num) {
|
||||
nextToken = Error(SolsToken, Nothing, {});
|
||||
}
|
||||
|
||||
if (parser->errors.count + 1 >= parser->errors.capacity) {
|
||||
parser->errors.capacity *= 2;
|
||||
|
||||
Reference in New Issue
Block a user