New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rethink quoting in user-facing messages #127
Comments
I think only control characters should be escaped, though it might be an idea to make this an option, to make it possible to determine visibly ambiguous character. In the case of |
Now that |
I agree that Anyway, if the user wants to make the Then localization of the message can look somehow so: catch (e) {// SyntaxError or GrammarError
if (e.userMessage) {// generated by |error| function
format(
"Строка %1, столбец %2: %3",
e.location.start.line, e.location.start.column,
e.userMessage
);
// e.message === "<|error| argument>";
// e.expected === null;
} else {
format(
"Строка %1, столбец %2: Ожидается %3, но найдено '%4'",
e.location.start.line, e.location.start.column,
formatExpected(e.expected), buildFound(input, e.location)
);
// e.message === "Expected <e.expected> but '...' found";
}
} Thus, |
Just noting that I’m considering reverting changes done in 69a0f76 and 25ab980. The main reason is that raw literal texts probably aren’t the right thing to display to users. For example, it doesn’t feel right that a choice between single and double quotes when writing literals in a grammar influences error messages. As for the @Mingun Exceptions created by |
No, this quite normal solution, however, this not documented. |
I reverted the change done in 69a0f76 and implemented a better solution. |
If users use non-ASCII characters in string literals in the grammar, they get ugly error messages from the generated parser. For example, a parser generated from this grammar:
will produce the following error message on empty input:
The generated parser probably shouldn't escape non-ASCII characters in user-facing messages.
There is also a question how to represent control characters line newline or tab. Currently we use JacaScript string representation (e.g.
Expected "\n"...
) but maybe saying something likeExpected newline...
would be more user-friendly.This is a spin-off from #120.
The text was updated successfully, but these errors were encountered: