diff --git a/parser.c b/parser.c index fc40274..bc3454e 100644 --- a/parser.c +++ b/parser.c @@ -315,13 +315,16 @@ static void token_expect(enum token_id token_id, struct token *tok) } } -static const char *parse_package() +static void qmi_package_parse(void) { struct token tok; token_expect(TOK_ID, &tok); token_expect(';', NULL); - return tok.str; + + if (qmi_package) + yyerror("package may only be specified once"); + qmi_package = tok.str; } static void qmi_const_parse() @@ -482,7 +485,7 @@ void qmi_parse(void) token_init(); while (!token_accept(TOK_EOF, NULL)) { if (token_accept(TOK_PACKAGE, NULL)) { - qmi_package = parse_package(); + qmi_package_parse(); } else if (token_accept(TOK_CONST, NULL)) { qmi_const_parse(); } else if (token_accept(TOK_STRUCT, NULL)) { @@ -495,4 +498,8 @@ void qmi_parse(void) break; } } + + /* The package name must have been specified */ + if (!qmi_package) + yyerror("package not specified"); } diff --git a/tests/no_package.qmi b/tests/no_package.qmi new file mode 100644 index 0000000..97684d5 --- /dev/null +++ b/tests/no_package.qmi @@ -0,0 +1,16 @@ +struct qmi_result { + u16 result; + u16 error; +}; + +request test_request { + required u8 test_number = 0x12; +} = 0x23; + +response test_response { + required qmi_result r = 2; +} = 043; + +indication test_indication { + optional u64 value = 0x99; +} = 0x7; diff --git a/tests/two_packages.qmi b/tests/two_packages.qmi new file mode 100644 index 0000000..3f1619e --- /dev/null +++ b/tests/two_packages.qmi @@ -0,0 +1,19 @@ +package test; +package test2; + +struct qmi_result { + u16 result; + u16 error; +}; + +request test_request { + required u8 test_number = 0x12; +} = 0x23; + +response test_response { + required qmi_result r = 2; +} = 043; + +indication test_indication { + optional u64 value = 0x99; +} = 0x7;