X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Flexer%2Fscan.c;h=0c922105407ab9dad66001b9d17f4ef2ab918df9;hb=ddf2365f2c3b8924f37cb0c96b2093cceaa64cb9;hp=86ebb7d00675cd6c89d223d49b1924cb278473e9;hpb=16b2dde0f4b7dd966d9b8271a1428387f1b4d7f3;p=pspp diff --git a/src/language/lexer/scan.c b/src/language/lexer/scan.c index 86ebb7d006..0c92210540 100644 --- a/src/language/lexer/scan.c +++ b/src/language/lexer/scan.c @@ -25,11 +25,15 @@ #include "language/lexer/token.h" #include "libpspp/assertion.h" #include "libpspp/cast.h" +#include "libpspp/i18n.h" #include "gl/c-ctype.h" #include "gl/c-strtod.h" #include "gl/xmemdup0.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) + enum { S_START, @@ -421,6 +425,48 @@ is_scan_type (enum scan_type type) return type > SCAN_FIRST && type < SCAN_LAST; } +/* If TOKEN has the type of a scan error (a subset of those identified by + is_scan_type()), returns an appropriate error message. Otherwise, returns + NULL. */ +char * +scan_token_to_error (const struct token *token) +{ + switch (token->type) + { + case SCAN_BAD_HEX_LENGTH: + return xasprintf (_("String of hex digits has %d characters, which " + "is not a multiple of 2."), (int) token->number); + + case SCAN_BAD_HEX_DIGIT: + case SCAN_BAD_UNICODE_DIGIT: + return xasprintf (_("`%c' is not a valid hex digit."), + (int) token->number); + + case SCAN_BAD_UNICODE_LENGTH: + return xasprintf (_("Unicode string contains %d bytes, which is " + "not in the valid range of 1 to 8 bytes."), + (int) token->number); + + case SCAN_BAD_UNICODE_CODE_POINT: + return xasprintf (_("U+%04X is not a valid Unicode code point."), + (int) token->number); + + case SCAN_EXPECTED_QUOTE: + return xasprintf (_("Unterminated string constant.")); + + case SCAN_EXPECTED_EXPONENT: + return xasprintf (_("Missing exponent following `%s'."), + token->string.string); + + case SCAN_UNEXPECTED_CHAR: + char c_name[16]; + return xasprintf (_("Bad character %s in input."), + uc_name (token->number, c_name)); + } + + return NULL; +} + static enum scan_result scan_start__ (struct scanner *scanner, enum segment_type type, struct substring s, struct token *token)