From 4cacdcba70a18db127f8cfa299c7e85b1e91efc8 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 13 Jan 2014 12:57:12 -0800 Subject: [PATCH] Fix parser position in parse error messages --- include/parser.h | 2 ++ src/runtime/parse_config.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/parser.h b/include/parser.h index 82bb5d37..1368d466 100644 --- a/include/parser.h +++ b/include/parser.h @@ -99,6 +99,7 @@ static void TSParserReduce(TSParser *parser, TSSymbol symbol, int child_count) { static void TSParserError(TSParser *parser, size_t count, const char **expected_inputs) { TSParseError *error = &parser->result.error; error->type = TSParseErrorTypeSyntactic; + error->position = parser->position; error->expected_input_count = count; error->expected_inputs = expected_inputs; error->lookahead_sym = TSParserLookaheadSym(parser); @@ -107,6 +108,7 @@ static void TSParserError(TSParser *parser, size_t count, const char **expected_ static void TSParserLexError(TSParser *parser, size_t count, const char **expected_inputs) { TSParseError *error = &parser->result.error; error->type = TSParseErrorTypeLexical; + error->position = parser->position; error->expected_input_count = count; error->expected_inputs = expected_inputs; error->lookahead_sym = TSParserLookaheadSym(parser); diff --git a/src/runtime/parse_config.cpp b/src/runtime/parse_config.cpp index f0e4521a..bc5d9f62 100644 --- a/src/runtime/parse_config.cpp +++ b/src/runtime/parse_config.cpp @@ -19,7 +19,7 @@ const char * TSParseErrorToString(const TSParseError *error, const char *input_s result += "Expected: "; for (int i = 0; i < error->expected_input_count; i++) - result += string(" '") + error->expected_inputs[i] + "'"; + result += error->expected_inputs[i]; char *stuff = (char *)malloc(result.size() * sizeof(char)); strcpy(stuff, result.c_str());