From: Ben Pfaff Date: Sat, 5 Nov 2011 23:34:56 +0000 (-0700) Subject: lexer: New functions lex_spec_missing(), lex_spec_only_once(). X-Git-Tag: v0.7.9~105 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c0c7dab25469d36b7dcee5df45e1f5767cccb5b;p=pspp-builds.git lexer: New functions lex_spec_missing(), lex_spec_only_once(). These functions don't have many users yet but they make logical sense to me. --- diff --git a/src/language/dictionary/mrsets.c b/src/language/dictionary/mrsets.c index 621cdc88..2f7c8f6d 100644 --- a/src/language/dictionary/mrsets.c +++ b/src/language/dictionary/mrsets.c @@ -205,14 +205,12 @@ parse_group (struct lexer *lexer, struct dictionary *dict, if (mrset->name == NULL) { - msg (SE, _("Required %s specification missing from %s subcommand."), - "NAME", subcommand_name); + lex_spec_missing (lexer, subcommand_name, "NAME"); goto error; } else if (mrset->n_vars == 0) { - msg (SE, _("Required %s specification missing from %s subcommand."), - "VARIABLES", subcommand_name); + lex_spec_missing (lexer, subcommand_name, "VARIABLES"); goto error; } @@ -221,8 +219,7 @@ parse_group (struct lexer *lexer, struct dictionary *dict, /* Check that VALUE is specified and is valid for the VARIABLES. */ if (!has_value) { - msg (SE, _("Required %s specification missing from %s subcommand."), - "VALUE", subcommand_name); + lex_spec_missing (lexer, subcommand_name, "VALUE"); goto error; } else if (var_is_alpha (mrset->vars[0])) diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c index e3725681..bbb00593 100644 --- a/src/language/lexer/lexer.c +++ b/src/language/lexer/lexer.c @@ -362,6 +362,24 @@ lex_sbc_missing (const char *sbc) msg (SE, _("Required subcommand %s was not specified."), sbc); } +/* Reports an error to the effect that specification SPEC may only be specified + once within subcommand SBC. */ +void +lex_spec_only_once (struct lexer *lexer, const char *sbc, const char *spec) +{ + lex_error (lexer, _("%s may only be specified once within subcommand %s"), + spec, sbc); +} + +/* Reports an error to the effect that specification SPEC is missing within + subcommand SBC. */ +void +lex_spec_missing (struct lexer *lexer, const char *sbc, const char *spec) +{ + lex_error (lexer, _("Required %s specification missing from %s subcommand"), + sbc, spec); +} + /* Prints a syntax error message containing the current token and given message MESSAGE (if non-null). */ void diff --git a/src/language/lexer/lexer.h b/src/language/lexer/lexer.h index 2a7055a5..17129c2b 100644 --- a/src/language/lexer/lexer.h +++ b/src/language/lexer/lexer.h @@ -160,6 +160,11 @@ void lex_error_expecting (struct lexer *, const char *, ...) SENTINEL(0); void lex_sbc_only_once (const char *); void lex_sbc_missing (const char *); +void lex_spec_only_once (struct lexer *, const char *subcommand, + const char *specification); +void lex_spec_missing (struct lexer *, const char *subcommand, + const char *specification); + void lex_error_valist (struct lexer *, const char *, va_list) PRINTF_FORMAT (2, 0); void lex_next_error_valist (struct lexer *lexer, int n0, int n1, diff --git a/tests/language/dictionary/mrsets.at b/tests/language/dictionary/mrsets.at index 04abfc7d..edff6ae2 100644 --- a/tests/language/dictionary/mrsets.at +++ b/tests/language/dictionary/mrsets.at @@ -239,7 +239,7 @@ AT_DATA([mrsets.sps], MRSETS /MCGROUP VARIABLES=a b c. ]) AT_CHECK([pspp -O format=csv mrsets.sps], [1], - [mrsets.sps:6: error: MRSETS: Required NAME specification missing from MCGROUP subcommand. + [mrsets.sps:6.32: error: MRSETS: Syntax error at end of command: Required MCGROUP specification missing from NAME subcommand. ]) AT_CLEANUP @@ -249,7 +249,7 @@ AT_DATA([mrsets.sps], MRSETS /MCGROUP NAME=$Mcgroup. ]) AT_CHECK([pspp -O format=csv mrsets.sps], [1], - [mrsets.sps:6: error: MRSETS: Required VARIABLES specification missing from MCGROUP subcommand. + [mrsets.sps:6.30: error: MRSETS: Syntax error at end of command: Required MCGROUP specification missing from VARIABLES subcommand. ]) AT_CLEANUP